/* * 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 java.util.List; import org.wamblee.crawler.Configuration; import org.wamblee.crawler.PageRequest; import org.wamblee.crawler.PageType; /** * Implementation of the configuration for the crawler. */ public class ConfigurationImpl implements Configuration { private List _urlConfig; private List _pageTypeConfig; /** * Constructs the configuration. * @param aUrlConfig List of URL configuration elements. * @param aPageTypeConfig List of page type configuration elements. */ public ConfigurationImpl(List aUrlConfig, List aPageTypeConfig) { _urlConfig = aUrlConfig; _pageTypeConfig = aPageTypeConfig; } /* * (non-Javadoc) * * @see org.wamblee.crawler.Configuration#getRequest(java.lang.String) */ public PageRequest getRequest(String aUrl) { for (UrlConfig config : _urlConfig) { PageRequest request = config.getRequest(aUrl); if (request != null) { return request; } } throw new RuntimeException("No configuration matched the URL '" + aUrl + "'"); } /* * (non-Javadoc) * * @see org.wamblee.crawler.Configuration#getRequest(org.wamblee.crawler.PageType) */ public PageRequest getRequest(PageType aType) { for (PageTypeConfig config : _pageTypeConfig) { PageRequest request = config.getRequest(aType.getType()); if (request != null) { return request; } } throw new RuntimeException("No configuration matched type '" + aType + "'"); } }