/* * Copyright 2005 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.wamblee.crawler.impl; import org.dom4j.Element; import org.wamblee.crawler.Action; import org.wamblee.crawler.Crawler; import org.wamblee.crawler.Page; import org.wamblee.crawler.PageException; import org.wamblee.crawler.PageType; /** * Action implementation. */ public class ActionImpl implements Action { private Crawler _crawler; private Element _content; private String _name; private String _reference; private PageType _type; /** * Constructs the action. * * @param aCrawler * Crawler to use. * @param aContent * Content of the action element in the page where the action * occurs. * @param aName * Name of the action. * @param aReference * URL of the reference. */ public ActionImpl(Crawler aCrawler, Element aContent, String aName, String aReference) { _crawler = aCrawler; _content = aContent; _name = aName; _reference = aReference; _type = null; } /** * Constructs the action. * * @param aCrawler * Crawler to use. * @param aContent * Content of the action element in the page where the action * occurs. * @param aName * Name of the action. * @param aReference * URL of the reference. * @param aType * Type of the referenced page. */ public ActionImpl(Crawler aCrawler, Element aContent, String aName, String aReference, PageType aType) { _crawler = aCrawler; _content = aContent; _name = aName; _reference = aReference; _type = aType; } /* * (non-Javadoc) * * @see org.wamblee.crawler.Action#getName() */ public String getName() { return _name; } /* * (non-Javadoc) * * @see org.wamblee.crawler.Action#execute() */ public Page execute() throws PageException { if (_type == null) { return _crawler.getPage(_reference); } return _crawler.getPage(_reference, _type); } /* * (non-Javadoc) * * @see org.wamblee.crawler.Action#getContent() */ public Element getContent() { return _content; } }