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: */
018: package org.apache.lenya.cms.cocoon.source;
019:
020: import java.io.IOException;
021: import java.net.MalformedURLException;
022: import java.util.Map;
023:
024: import org.apache.avalon.framework.configuration.Configurable;
025: import org.apache.avalon.framework.configuration.Configuration;
026: import org.apache.avalon.framework.configuration.ConfigurationException;
027: import org.apache.avalon.framework.context.Context;
028: import org.apache.avalon.framework.context.ContextException;
029: import org.apache.avalon.framework.context.Contextualizable;
030: import org.apache.avalon.framework.logger.AbstractLogEnabled;
031: import org.apache.avalon.framework.service.ServiceException;
032: import org.apache.avalon.framework.service.ServiceManager;
033: import org.apache.avalon.framework.service.Serviceable;
034: import org.apache.avalon.framework.thread.ThreadSafe;
035: import org.apache.cocoon.components.ContextHelper;
036: import org.apache.cocoon.environment.ObjectModelHelper;
037: import org.apache.cocoon.environment.Request;
038: import org.apache.excalibur.source.Source;
039: import org.apache.excalibur.source.SourceException;
040: import org.apache.excalibur.source.SourceFactory;
041:
042: /**
043: * <p>
044: * This source factory allows to access documents based on their path in the site structure.
045: * </p>
046: * <p>
047: * Relative addressing refers to the current publication and area.
048: * </p>
049: * <p>
050: * Syntax:
051: * </p>
052: * <ul>
053: * <li>Absolute: <code>site://{pubId}/{area}/{language}{path}</code></li>
054: * <li>Relative: <code>site:/{language}{path}</code></li>
055: * </ul>
056: * <p>
057: * Usage examples:
058: * </p>
059: * <ul>
060: * <li><code>site://default/authoring/en/news/today</code></li>
061: * <li><code>site:/en/news/today</code></li>
062: * </ul>
063: */
064: public class SiteSourceFactory extends AbstractLogEnabled implements
065: SourceFactory, ThreadSafe, Contextualizable, Serviceable,
066: Configurable {
067:
068: protected static final String SCHEME = "site";
069:
070: private Context context;
071: private ServiceManager manager;
072:
073: /**
074: * Used for resolving the object model.
075: * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
076: */
077: public void contextualize(Context context) throws ContextException {
078: this .context = context;
079: }
080:
081: /**
082: * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
083: */
084: public void service(ServiceManager manager) throws ServiceException {
085: this .manager = manager;
086: }
087:
088: /**
089: * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
090: */
091: public void configure(Configuration configuration)
092: throws ConfigurationException {
093: }
094:
095: /**
096: * @see org.apache.excalibur.source.SourceFactory#getSource(java.lang.String, java.util.Map)
097: */
098: public Source getSource(String location, Map parameters)
099: throws MalformedURLException, IOException, SourceException {
100: Map objectModel = ContextHelper.getObjectModel(this .context);
101: Request request = ObjectModelHelper.getRequest(objectModel);
102: return new SiteSource(this .manager, request, location,
103: getLogger());
104: }
105:
106: /**
107: * @see org.apache.excalibur.source.SourceFactory#release(org.apache.excalibur.source.Source)
108: */
109: public void release(Source source) {
110: // Source will be released by delegated source factory.
111: }
112:
113: }
|