001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.components.source.impl;
018:
019: import java.io.IOException;
020: import java.net.MalformedURLException;
021: import java.util.Map;
022:
023: import org.apache.avalon.framework.configuration.Configurable;
024: import org.apache.avalon.framework.configuration.Configuration;
025: import org.apache.avalon.framework.configuration.ConfigurationException;
026: import org.apache.avalon.framework.logger.AbstractLogEnabled;
027: import org.apache.avalon.framework.parameters.Parameters;
028: import org.apache.avalon.framework.service.ServiceException;
029: import org.apache.avalon.framework.service.ServiceManager;
030: import org.apache.avalon.framework.service.Serviceable;
031: import org.apache.avalon.framework.thread.ThreadSafe;
032: import org.apache.cocoon.components.webdav.WebDAVEventFactory;
033: import org.apache.commons.httpclient.HttpURL;
034: import org.apache.commons.httpclient.HttpsURL;
035: import org.apache.excalibur.source.Source;
036: import org.apache.excalibur.source.SourceException;
037: import org.apache.excalibur.source.SourceFactory;
038:
039: /**
040: * A factory for WebDAV sources
041: *
042: * @version $Id: WebDAVSourceFactory.java 433543 2006-08-22 06:22:54Z crossley $
043: */
044: public class WebDAVSourceFactory extends AbstractLogEnabled implements
045: SourceFactory, Serviceable, Configurable, ThreadSafe {
046:
047: private String protocol;
048: private boolean secure;
049:
050: private WebDAVEventFactory eventfactory = null;
051:
052: /**
053: * Read the scheme name.
054: */
055: public void configure(Configuration configuration)
056: throws ConfigurationException {
057: this .protocol = configuration.getAttribute("name");
058:
059: // parse parameters
060: Parameters parameters = Parameters
061: .fromConfiguration(configuration);
062: this .secure = parameters.getParameterAsBoolean("secure", false);
063: }
064:
065: /**
066: * Get a <code>Source</code> object.
067: * @param parameters This is optional.
068: */
069: public Source getSource(String location, Map parameters)
070: throws MalformedURLException, IOException, SourceException {
071:
072: if (this .getLogger().isDebugEnabled()) {
073: this .getLogger().debug(
074: "Creating source object for " + location);
075: }
076:
077: int index = location.indexOf(':');
078: if (index != -1) {
079: location = location.substring(index + 3);
080: }
081:
082: HttpURL url;
083: if (this .secure) {
084: url = new HttpsURL("https://" + location);
085: } else {
086: url = new HttpURL("http://" + location);
087: }
088:
089: return WebDAVSource.newWebDAVSource(url, this .protocol,
090: getLogger(), eventfactory);
091: }
092:
093: public void release(Source source) {
094: // do nothing
095: }
096:
097: public void service(ServiceManager manager) throws ServiceException {
098: if (manager.hasService(WebDAVEventFactory.ROLE))
099: eventfactory = (WebDAVEventFactory) manager
100: .lookup(WebDAVEventFactory.ROLE);
101: else
102: eventfactory = null;
103: }
104: }
|