You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2005/01/10 11:34:55 UTC

svn commit: r124783 - in lenya/trunk/src/java/org/apache/lenya/cms: cocoon/components/modules/input publication

Author: andreas
Date: Mon Jan 10 02:34:54 2005
New Revision: 124783

URL: http://svn.apache.org/viewcvs?view=rev&rev=124783
Log:
added DocumentTypeResolver
Added:
   lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeResolver.java
   lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeResolverImpl.java
Modified:
   lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PageEnvelopeModule.java

Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PageEnvelopeModule.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PageEnvelopeModule.java?view=diff&rev=124783&p1=lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PageEnvelopeModule.java&r1=124782&p2=lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PageEnvelopeModule.java&r2=124783
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PageEnvelopeModule.java	(original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PageEnvelopeModule.java	Mon Jan 10 02:34:54 2005
@@ -27,13 +27,11 @@
 
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.parameters.Parameters;
 import org.apache.avalon.framework.service.ServiceException;
-import org.apache.cocoon.environment.ObjectModelHelper;
-import org.apache.cocoon.environment.Request;
 import org.apache.commons.lang.StringUtils;
-import org.apache.lenya.cms.cocoon.uriparameterizer.URIParameterizer;
 import org.apache.lenya.cms.cocoon.uriparameterizer.URIParameterizerException;
+import org.apache.lenya.cms.publication.DocumentType;
+import org.apache.lenya.cms.publication.DocumentTypeResolver;
 import org.apache.lenya.cms.publication.PageEnvelope;
 
 /**
@@ -47,10 +45,12 @@
     protected static final String URI_PARAMETER_DOCTYPE = "doctype";
 
     /**
-     * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+     * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String,
+     *      org.apache.avalon.framework.configuration.Configuration,
+     *      java.util.Map)
      */
     public Object getAttribute(String name, Configuration modeConf, Map objectModel)
-        throws ConfigurationException {
+            throws ConfigurationException {
         PageEnvelope envelope = getEnvelope(objectModel);
         Object value = null;
 
@@ -64,17 +64,16 @@
             } else if (name.equals(PageEnvelope.PUBLICATION)) {
                 value = envelope.getPublication();
             } else if (name.equals(PageEnvelope.PUBLICATION_LANGUAGES_CSV)) {
-                value =
-                    StringUtils.join(
-                        envelope.getPublication().getLanguages(),
-                        ',');
+                value = StringUtils.join(envelope.getPublication().getLanguages(), ',');
             } else if (name.equals(PageEnvelope.DOCUMENT)) {
                 value = envelope.getDocument();
             } else if (name.equals(PageEnvelope.DOCUMENT_ID)) {
                 value = envelope.getDocument().getId();
             } else if (name.equals(PageEnvelope.DOCUMENT_NAME)) {
                 value = envelope.getDocument().getName();
-            } else if (name.equals(PageEnvelope.DOCUMENT_LABEL)) { // FIXME: Why is this here?
+            } else if (name.equals(PageEnvelope.DOCUMENT_LABEL)) { // FIXME: Why
+                                                                   // is this
+                                                                   // here?
                 value = envelope.getDocument().getLabel();
             } else if (name.equals(PageEnvelope.DOCUMENT_URL)) {
                 value = envelope.getDocument().getCanonicalDocumentURL();
@@ -93,26 +92,22 @@
             } else if (name.equals(PageEnvelope.DOCUMENT_LANGUAGES)) {
                 value = envelope.getDocument().getLanguages();
             } else if (name.equals(PageEnvelope.DOCUMENT_LANGUAGES_CSV)) {
-                value =
-                    StringUtils.join(
-                        envelope.getDocument().getLanguages(),
-                        ',');
+                value = StringUtils.join(envelope.getDocument().getLanguages(), ',');
             } else if (name.equals(PageEnvelope.DOCUMENT_LASTMODIFIED)) {
                 Date date = envelope.getDocument().getLastModified();
                 value = new SimpleDateFormat(DATE_FORMAT).format(date);
             } else if (name.equals(PageEnvelope.BREADCRUMB_PREFIX)) {
                 value = envelope.getPublication().getBreadcrumbPrefix();
             } else if (name.equals(PageEnvelope.DOCUMENT_TYPE)) {
-                value = getDocumentType(objectModel, envelope);
+                value = getDocumentType(envelope);
             } else {
                 throw new ConfigurationException("The attribute [" + name + "] is not supported!");
             }
         } catch (ConfigurationException e) {
             throw e;
         } catch (Exception e) {
-            throw new ConfigurationException(
-                "Getting attribute for name [" + name + "] failed: ",
-                e);
+            throw new ConfigurationException("Getting attribute for name [" + name + "] failed: ",
+                    e);
         }
 
         if (getLogger().isDebugEnabled()) {
@@ -126,75 +121,46 @@
 
     /**
      * Returns the document type.
-     * @param objectModel The object model.
      * @param envelope The page envelope.
      * @return A string.
      * @throws ServiceException when something went wrong.
      * @throws URIParameterizerException when something went wrong.
      */
-    protected String getDocumentType(Map objectModel, PageEnvelope envelope)
-        throws ServiceException, URIParameterizerException {
+    protected String getDocumentType(PageEnvelope envelope) throws ServiceException,
+            URIParameterizerException {
         String documentType;
-        URIParameterizer parameterizer = null;
-        Map map = null;
+        DocumentTypeResolver resolver = null;
         try {
-            parameterizer = (URIParameterizer) manager.lookup(URIParameterizer.ROLE);
-
-            Parameters parameters = new Parameters();
-            parameters.setParameter(
-                URI_PARAMETER_DOCTYPE,
-                "cocoon://uri-parameter/"
-                    + envelope.getPublication().getId()
-                    + "/"
-                    + URI_PARAMETER_DOCTYPE);
-
-            String source =
-                envelope.getDocument().getArea() + envelope.getDocument().getCanonicalDocumentURL();
-
-            Request request = ObjectModelHelper.getRequest(objectModel);
-            map = parameterizer.parameterize(filterURI(request.getRequestURI()), filterURI(source), parameters);                
-            documentType = (String) map.get(URI_PARAMETER_DOCTYPE);
-            
+            resolver = (DocumentTypeResolver) this.manager.lookup(DocumentTypeResolver.ROLE);
+            DocumentType type = resolver.resolve(envelope.getDocument());
+            documentType = type.getName();
         } finally {
-            if (parameterizer != null) {
-                manager.release(parameterizer);
+            if (resolver != null) {
+                this.manager.release(resolver);
             }
         }
         return documentType;
     }
 
     /**
-     * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeNames(org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+     * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeNames(org.apache.avalon.framework.configuration.Configuration,
+     *      java.util.Map)
      */
     public Iterator getAttributeNames(Configuration modeConf, Map objectModel)
-        throws ConfigurationException {
+            throws ConfigurationException {
         return Arrays.asList(PageEnvelope.PARAMETER_NAMES).iterator();
     }
 
     /**
-     * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+     * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String,
+     *      org.apache.avalon.framework.configuration.Configuration,
+     *      java.util.Map)
      */
     public Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel)
-        throws ConfigurationException {
-        Object[] objects = { getAttribute(name, modeConf, objectModel)};
+            throws ConfigurationException {
+        Object[] objects = { getAttribute(name, modeConf, objectModel) };
 
         return objects;
     }
 
-    /**
-     * uri will be filtered by certain rules 
-     * i.e. session information encoded within the uri will be removed.
-     * @param uri The uri to be filtered
-     * @return uri filtered by certain rules i.e
-     */
-    // FIXME Maybe make this more configureable
-    private String filterURI(final String uri) 
-    {
-        final int index = uri.indexOf(";jsessionid");
-        
-        if(index >= 0)
-            return uri.substring(0, index);                        
-        else
-            return uri;        
-    }
-}
+}
\ No newline at end of file

Added: lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeResolver.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeResolver.java?view=auto&rev=124783
==============================================================================
--- (empty file)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeResolver.java	Mon Jan 10 02:34:54 2005
@@ -0,0 +1,39 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  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.lenya.cms.publication;
+
+
+/**
+ * Class to resolve the document type for a document.
+ * 
+ * @version $Id:$
+ */
+public interface DocumentTypeResolver {
+    
+    /**
+     * The Avalon component role.
+     */
+    public static final String ROLE = DocumentTypeResolver.class.getName();
+
+    /**
+     * Resolves a document type of a certain document..
+     * @param document The document.
+     * @return A document type.
+     */
+    public DocumentType resolve(Document document);
+    
+}
\ No newline at end of file

Added: lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeResolverImpl.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeResolverImpl.java?view=auto&rev=124783
==============================================================================
--- (empty file)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeResolverImpl.java	Mon Jan 10 02:34:54 2005
@@ -0,0 +1,114 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  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.lenya.cms.publication;
+
+import java.util.Map;
+
+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.parameters.Parameters;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.cocoon.components.ContextHelper;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
+import org.apache.lenya.cms.cocoon.uriparameterizer.URIParameterizer;
+
+/**
+ * Class to resolve the document type for a document.
+ * 
+ * @version $Id:$
+ */
+public class DocumentTypeResolverImpl extends AbstractLogEnabled implements Serviceable,
+        Contextualizable, DocumentTypeResolver {
+    
+
+    protected static final String URI_PARAMETER_DOCTYPE = "doctype";
+
+    private ServiceManager manager;
+
+    /**
+     * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+     */
+    public void service(ServiceManager manager) throws ServiceException {
+        this.manager = manager;
+    }
+
+    private Context context;
+
+    /**
+     * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
+     */
+    public void contextualize(Context context) throws ContextException {
+        this.context = context;
+    }
+
+    /**
+     * @see org.apache.lenya.cms.publication.DocumentTypeResolver#resolve(org.apache.lenya.cms.publication.Document)
+     */
+    public DocumentType resolve(Document document) {
+        DocumentType documentType;
+        URIParameterizer parameterizer = null;
+        Map map = null;
+        try {
+            parameterizer = (URIParameterizer) this.manager.lookup(URIParameterizer.ROLE);
+
+            Parameters parameters = new Parameters();
+            parameters.setParameter(URI_PARAMETER_DOCTYPE, "cocoon://uri-parameter/"
+                    + document.getPublication().getId() + "/" + URI_PARAMETER_DOCTYPE);
+
+            String source = document.getArea() + document.getCanonicalDocumentURL();
+
+            Map objectModel = ContextHelper.getObjectModel(this.context);
+            Request request = ObjectModelHelper.getRequest(objectModel);
+            map = parameterizer.parameterize(filterURI(request.getRequestURI()),
+                    filterURI(source),
+                    parameters);
+            String name = (String) map.get(URI_PARAMETER_DOCTYPE);
+            documentType = DocumentTypeBuilder.buildDocumentType(name, document.getPublication());
+
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            if (parameterizer != null) {
+                this.manager.release(parameterizer);
+            }
+        }
+        return documentType;
+
+    }
+
+    /**
+     * uri will be filtered by certain rules i.e. session information encoded
+     * within the uri will be removed.
+     * @param uri The uri to be filtered
+     * @return uri filtered by certain rules i.e
+     */
+    // FIXME Maybe make this more configureable
+    private String filterURI(final String uri) {
+        final int index = uri.indexOf(";jsessionid");
+
+        if (index >= 0)
+            return uri.substring(0, index);
+        else
+            return uri;
+    }
+
+}
\ No newline at end of file

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org