forrest-svn mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thors...@apache.org
Subject svn commit: r355474 - in /forrest/trunk/main: java/org/apache/forrest/locationmap/source/ java/org/apache/forrest/locationmap/source/impl/ webapp/WEB-INF/xconf/
Date Fri, 09 Dec 2005 12:51:06 GMT
Author: thorsten
Date: Fri Dec  9 04:50:57 2005
New Revision: 355474

URL: http://svn.apache.org/viewcvs?rev=355474&view=rev
Log:
Added first version of the LocationmapSourceFactory. With this it is possible to request locationmap
source via lm://my-location which makes it easier to use it without contacting a input module
in java and any other files. The problem ATM is that the mounts of the locationmap are not
resolved when using the factory. Only matches are resolved only problems.

Added:
    forrest/trunk/main/java/org/apache/forrest/locationmap/source/
    forrest/trunk/main/java/org/apache/forrest/locationmap/source/impl/
    forrest/trunk/main/java/org/apache/forrest/locationmap/source/impl/LocationmapSourceFactory.java
  (with props)
Modified:
    forrest/trunk/main/webapp/WEB-INF/xconf/forrest-core.xconf

Added: forrest/trunk/main/java/org/apache/forrest/locationmap/source/impl/LocationmapSourceFactory.java
URL: http://svn.apache.org/viewcvs/forrest/trunk/main/java/org/apache/forrest/locationmap/source/impl/LocationmapSourceFactory.java?rev=355474&view=auto
==============================================================================
--- forrest/trunk/main/java/org/apache/forrest/locationmap/source/impl/LocationmapSourceFactory.java
(added)
+++ forrest/trunk/main/java/org/apache/forrest/locationmap/source/impl/LocationmapSourceFactory.java
Fri Dec  9 04:50:57 2005
@@ -0,0 +1,102 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation or its licensors,
+ * as applicable.
+ * 
+ * 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.apache.forrest.locationmap.source.impl;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.Map;
+
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.ServiceSelector;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.components.ContextHelper;
+import org.apache.cocoon.components.modules.input.InputModule;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceException;
+import org.apache.excalibur.source.SourceFactory;
+
+public class LocationmapSourceFactory extends AbstractLogEnabled implements
+        Serviceable, SourceFactory, ThreadSafe, Contextualizable {
+
+    protected ServiceManager m_manager;
+    private Context context;
+    public static final String LM_PREFIX = "lm";
+    public static final String LM_SOURCE_SCHEME =LM_PREFIX+ ":";
+
+    public Source getSource(String location, Map parameters)
+            throws IOException, MalformedURLException {
+        Map objectModel = ContextHelper.getObjectModel( this.context );
+        if (this.getLogger().isDebugEnabled()) {
+            this.getLogger().debug("Processing " + location);
+        }
+
+        int protocolEnd = location.indexOf("://");
+        if (protocolEnd == -1) {
+            throw new MalformedURLException("URI does not contain '://' : "
+                    + location);
+        }
+        String documentName = location.substring(protocolEnd + 3, location
+                .length());
+        String lmLocation = "";
+        Source lmSource = null;
+        SourceResolver resolver = null;
+        ServiceSelector selector = null;
+        InputModule inputModule = null;
+        try {
+            selector = (ServiceSelector) m_manager.lookup(InputModule.ROLE
+                    + "Selector");
+            inputModule = (InputModule) selector.select(LM_PREFIX);
+            resolver = (SourceResolver) m_manager.lookup(SourceResolver.ROLE);
+            lmLocation = (String) inputModule.getAttribute(documentName, null,
+                    objectModel);
+            if (lmLocation==null)
+                throw new SourceException("Could not resolve locationmap location.");
+            lmSource = resolver.resolveURI(lmLocation);
+        } catch (ServiceException se) {
+            throw new SourceException("InputModule is not available.", se);
+        } catch (ConfigurationException e) {
+            throw new SourceException("SourceResolver is not available.", e);
+        } finally {
+            if (inputModule != null)
+                selector.release(inputModule);
+            m_manager.release(resolver);
+        }
+        return lmSource;
+    }
+    /**
+     * Contextualizable, get the object model
+     */
+    public void contextualize( Context context ) throws ContextException {
+        this.context = context;
+    }
+    public void release(Source source) {
+        // not necessary here
+    }
+
+    public void service(ServiceManager manager) throws ServiceException {
+        this.m_manager = manager;
+    }
+
+}

Propchange: forrest/trunk/main/java/org/apache/forrest/locationmap/source/impl/LocationmapSourceFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: forrest/trunk/main/webapp/WEB-INF/xconf/forrest-core.xconf
URL: http://svn.apache.org/viewcvs/forrest/trunk/main/webapp/WEB-INF/xconf/forrest-core.xconf?rev=355474&r1=355473&r2=355474&view=diff
==============================================================================
--- forrest/trunk/main/webapp/WEB-INF/xconf/forrest-core.xconf (original)
+++ forrest/trunk/main/webapp/WEB-INF/xconf/forrest-core.xconf Fri Dec  9 04:50:57 2005
@@ -244,6 +244,7 @@
     <component-instance class="org.apache.cocoon.components.source.impl.ContextSourceFactory"
name="context"/>
     <component-instance class="org.apache.cocoon.components.source.impl.SitemapSourceFactory"
name="cocoon"/>
     <component-instance class="org.apache.cocoon.components.source.impl.ZipSourceFactory"
name="zip"/>
+    <component-instance class="org.apache.forrest.locationmap.source.impl.LocationmapSourceFactory"
name="lm"/>
     <!-- the "*" protocol handles all uri schemes that are not explicitely specified.
This includes all
          JDK standard protocols, with special handling of the "file:" protocol which is modifiable
          (can be written to) and traversable (directory structures can be crawled). -->



Mime
View raw message