You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by jo...@apache.org on 2006/02/02 16:58:44 UTC

svn commit: r374414 - in /lenya/trunk/src: java/org/apache/lenya/cms/cocoon/components/modules/input/ java/org/apache/lenya/cms/publication/ pubs/default/ webapp/lenya/config/cocoon-xconf/input-modules/

Author: josias
Date: Thu Feb  2 07:58:32 2006
New Revision: 374414

URL: http://svn.apache.org/viewcvs?rev=374414&view=rev
Log:
added BaseURLModule which may be used to get the base url to prepend to urls in order to construct internal links. If the publication uses proxying, it returns the proxy url. Otherwise, it returns /context-path/pubid/area

Added:
    lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/BaseURLModule.java   (with props)
    lenya/trunk/src/webapp/lenya/config/cocoon-xconf/input-modules/base-url.xconf   (with props)
Modified:
    lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java
    lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationImpl.java
    lenya/trunk/src/pubs/default/sitemap.xmap

Added: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/BaseURLModule.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/BaseURLModule.java?rev=374414&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/BaseURLModule.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/BaseURLModule.java Thu Feb  2 07:58:32 2006
@@ -0,0 +1,139 @@
+/*
+ * 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.cocoon.components.modules.input;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.ServiceSelector;
+import org.apache.cocoon.components.modules.input.AbstractInputModule;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
+import org.apache.lenya.ac.AccessController;
+import org.apache.lenya.ac.AccessControllerResolver;
+import org.apache.lenya.ac.AccreditableManager;
+import org.apache.lenya.ac.Authorizer;
+import org.apache.lenya.ac.Policy;
+import org.apache.lenya.ac.PolicyManager;
+import org.apache.lenya.ac.impl.DefaultAccessController;
+import org.apache.lenya.ac.impl.PolicyAuthorizer;
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentIdentityMap;
+import org.apache.lenya.cms.publication.Proxy;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.publication.PublicationUtil;
+import org.apache.lenya.cms.repository.RepositoryUtil;
+import org.apache.lenya.cms.repository.Session;
+
+/**
+ * Input module for getting the base URL which may be prepended to internal 
+ * URLs to construct links.
+ * The base-url contains no trailing slash.
+ * 
+ * <p>
+ * Usage: <code>{base-url:{pubid}:{area}:{ssl}}</code>
+ * </p>
+ * 
+ * <p>
+ * If the publication uses proxying, the base URL is the proxy URL defined in 
+ * the file conf/publication.xconf. If no proxying is used, 
+ * the result will be {context-path}/{pub-id}/{area}.
+ * The ssl parameter is optional, if omitted the protocol (http or https) of the current request will be used.
+ * </p>
+ * 
+ */
+public class BaseURLModule extends AbstractInputModule implements Serviceable {
+
+    private ServiceManager manager;
+
+    /**
+     * @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 {
+
+        // Get parameters
+        final String[] attributes = name.split(":");
+
+        if (attributes.length < 2) {
+            throw new ConfigurationException("Invalid number of parameters: " + attributes.length
+                    + ". Expected pubid, area, [ssl].");
+        }
+
+        Request request = ObjectModelHelper.getRequest(objectModel);
+        
+        final String pubid = attributes[0];
+        final String area = attributes[1];
+        boolean ssl = false;
+        
+        if (attributes.length == 3) {
+            ssl = Boolean.valueOf(attributes[2]).booleanValue();
+        } else if (request.getScheme().equals("https")) {
+            ssl = true;
+        }
+        
+        String value = null;
+        try {
+            Publication publication = PublicationUtil.getPublication(this.manager, pubid);
+
+            Proxy proxy = publication.getProxy(area, ssl);
+            
+            if (proxy != null) {
+                value = proxy.getUrl();
+            } else {
+                value = request.getContextPath() + "/" + pubid + "/" + area;
+            }
+            
+        } catch (Exception e) {
+            throw new ConfigurationException("Obtaining value for [" + name + "] failed: ", e);
+        }
+        return value;
+    }
+
+    /**
+     * @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 {
+        return Collections.EMPTY_SET.iterator();
+    }
+
+    /**
+     * @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) };
+        return objects;
+    }
+
+    /**
+     * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+     */
+    public void service(ServiceManager manager) throws ServiceException {
+        this.manager = manager;
+    }
+}
\ No newline at end of file

Propchange: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/BaseURLModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java?rev=374414&r1=374413&r2=374414&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java Thu Feb  2 07:58:32 2006
@@ -179,6 +179,14 @@
     Proxy getProxy(Document document, boolean isSslProtected);
 
     /**
+     * Returns the proxy which is used for the given area and the ssl parameter.
+     * @param area area
+     * @param isSslProtected A boolean value.
+     * @return A proxy or <code>null</code> if no proxy is defined for these parameters.
+     */
+    Proxy getProxy(String area, boolean isSslProtected);
+
+    /**
      * @return The templates of the publication.
      */
     String[] getTemplateIds();

Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationImpl.java?rev=374414&r1=374413&r2=374414&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationImpl.java Thu Feb  2 07:58:32 2006
@@ -359,15 +359,23 @@
      *      boolean)
      */
     public Proxy getProxy(Document document, boolean isSslProtected) {
-        loadConfiguration();
-        Object key = getProxyKey(document.getArea(), isSslProtected);
-        Proxy proxy = (Proxy) this.areaSsl2proxy.get(key);
+        Proxy proxy = getProxy(document.getArea(), isSslProtected);
 
         if (getLogger().isDebugEnabled()) {
             getLogger().debug("Resolving proxy for [" + document + "] SSL=[" + isSslProtected + "]");
             getLogger().debug("Resolved proxy: [" + proxy + "]");
         }
 
+        return proxy;
+    }
+
+    /**
+     * @see org.apache.lenya.cms.publication.Publication#getProxy(java.lang.String, boolean)
+     */
+    public Proxy getProxy(String area, boolean isSslProtected) {
+        loadConfiguration();
+        Object key = getProxyKey(area, isSslProtected);
+        Proxy proxy = (Proxy) this.areaSsl2proxy.get(key);
         return proxy;
     }
 

Modified: lenya/trunk/src/pubs/default/sitemap.xmap
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/pubs/default/sitemap.xmap?rev=374414&r1=374413&r2=374414&view=diff
==============================================================================
--- lenya/trunk/src/pubs/default/sitemap.xmap (original)
+++ lenya/trunk/src/pubs/default/sitemap.xmap Thu Feb  2 07:58:32 2006
@@ -118,7 +118,7 @@
           <map:parameter name="prefix" value="fallback://"/>
           <map:when test="xslt/page2xhtml-{4}.xsl">
             <map:transform src="fallback://xslt/page2xhtml-{4}.xsl">
-              <map:parameter name="root" value="{page-envelope:context-prefix}/{2}/{3}"/>
+              <map:parameter name="root" value="{base-url:{2}:{3}}"/>
               <map:parameter name="url" value="{5}"/>
               <map:parameter name="document-id" value="{page-envelope:document-id}"/>
               <map:parameter name="document-type" value="{page-envelope:document-type}"/>
@@ -128,7 +128,7 @@
           </map:when>
           <map:otherwise>
             <map:transform src="fallback://xslt/page2xhtml-xhtml.xsl">
-              <map:parameter name="root" value="{page-envelope:context-prefix}/{2}/{3}"/>
+              <map:parameter name="root" value="{base-url:{2}:{3}}"/>
               <map:parameter name="url" value="{5}"/>
               <map:parameter name="document-id" value="{page-envelope:document-id}"/>
               <map:parameter name="document-type" value="{page-envelope:document-type}"/>

Added: lenya/trunk/src/webapp/lenya/config/cocoon-xconf/input-modules/base-url.xconf
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/config/cocoon-xconf/input-modules/base-url.xconf?rev=374414&view=auto
==============================================================================
--- lenya/trunk/src/webapp/lenya/config/cocoon-xconf/input-modules/base-url.xconf (added)
+++ lenya/trunk/src/webapp/lenya/config/cocoon-xconf/input-modules/base-url.xconf Thu Feb  2 07:58:32 2006
@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+<!--
+  Copyright 1999-2005 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.
+-->
+
+  <xconf xpath="/cocoon/input-modules" unless="/cocoon/input-modules/component-instance[@name = 'base-url']">
+    <component-instance logger="sitemap.modules.input.base-url" name="base-url"
+      class="org.apache.lenya.cms.cocoon.components.modules.input.BaseURLModule"/>
+  </xconf>

Propchange: lenya/trunk/src/webapp/lenya/config/cocoon-xconf/input-modules/base-url.xconf
------------------------------------------------------------------------------
    svn:eol-style = native



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