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/05/26 14:45:03 UTC
svn commit: r178628 - in /lenya/trunk/src:
java/org/apache/lenya/cms/cocoon/components/modules/input/ProxyUrlModule.java
webapp/WEB-INF/cocoon-xconf.xsl
Author: andreas
Date: Thu May 26 05:45:03 2005
New Revision: 178628
URL: http://svn.apache.org/viewcvs?rev=178628&view=rev
Log:
added ProxyUrlModule (Bug #33742), credits to Felix Roethenbacher
Added:
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/ProxyUrlModule.java
Modified:
lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl
Added: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/ProxyUrlModule.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/ProxyUrlModule.java?rev=178628&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/ProxyUrlModule.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/ProxyUrlModule.java Thu May 26 05:45:03 2005
@@ -0,0 +1,162 @@
+/*
+ * 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.PageEnvelope;
+import org.apache.lenya.cms.publication.PageEnvelopeFactory;
+import org.apache.lenya.cms.publication.Proxy;
+import org.apache.lenya.cms.publication.Publication;
+
+/**
+ * Input module for getting the proxied URL of a document.
+ *
+ * <p>
+ * Usage: <code>{proxy-url:{area}:{document-id}:{language}}</code>
+ * </p>
+ *
+ * <p>
+ * If there are no proxy settings in the file conf/publication.xconf, the values of the request
+ * parameters 'server name' and 'port' will be used to construct the URL.
+ * </p>
+ *
+ * @version $Id:$
+ */
+public class ProxyUrlModule 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 {
+
+ ServiceSelector serviceSelector = null;
+ PolicyManager policyManager = null;
+ AccessControllerResolver acResolver = null;
+ AccreditableManager accreditableManager = null;
+
+ // Get parameters
+ final String[] attributes = name.split(":");
+
+ if (attributes.length < 3) {
+ throw new ConfigurationException("Invalid number of parameters: " + attributes.length
+ + ". Expected area, document-id, language.");
+ }
+
+ final String area = attributes[0];
+ final String documentId = attributes[1];
+ final String language = attributes[2];
+
+ String value = null;
+ try {
+ DocumentIdentityMap map = new DocumentIdentityMap(this.manager, getLogger());
+ PageEnvelope envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(map,
+ objectModel);
+ Publication publication = envelope.getPublication();
+
+ Document doc = map.get(publication, area, documentId, language);
+
+ // Get proxy for document
+ serviceSelector = (ServiceSelector) this.manager.lookup(AccessControllerResolver.ROLE
+ + "Selector");
+ acResolver = (AccessControllerResolver) serviceSelector
+ .select(AccessControllerResolver.DEFAULT_RESOLVER);
+
+ String url = doc.getCanonicalWebappURL();
+ AccessController accessController = acResolver.resolveAccessController(url);
+ if (accessController instanceof DefaultAccessController) {
+ DefaultAccessController defaultAccessController = (DefaultAccessController) accessController;
+ accreditableManager = defaultAccessController.getAccreditableManager();
+ Authorizer[] authorizers = defaultAccessController.getAuthorizers();
+ for (int i = 0; i < authorizers.length; i++) {
+ if (authorizers[i] instanceof PolicyAuthorizer) {
+ PolicyAuthorizer policyAuthorizer = (PolicyAuthorizer) authorizers[i];
+ policyManager = policyAuthorizer.getPolicyManager();
+ }
+ }
+ }
+
+ Policy policy = policyManager.getPolicy(accreditableManager, url);
+
+ Proxy proxy = doc.getPublication().getProxy(doc, policy.isSSLProtected());
+
+ if (proxy != null) {
+ value = proxy.getURL(doc);
+ } else {
+ // Take server name and port from request.
+ Request request = ObjectModelHelper.getRequest(objectModel);
+ value = "http://" + request.getServerName() + ":" + request.getServerPort()
+ + request.getContextPath() + doc.getCanonicalWebappURL();
+ }
+
+ } 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
Modified: lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl?rev=178628&r1=178627&r2=178628&view=diff
==============================================================================
--- lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl (original)
+++ lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl Thu May 26 05:45:03 2005
@@ -115,7 +115,10 @@
<component-instance name="date-i18n" logger="core.modules.input" class="org.apache.cocoon.components.modules.input.DateInputModule">
<format>yyyy-M-dd HH:mm:ss Z</format>
- </component-instance>
+ </component-instance>
+
+ <component-instance name="proxy-url" logger="sitemap.modules.input.proxy-url"
+ class="org.apache.lenya.cms.cocoon.components.modules.input.ProxyUrlModule"/>
</xsl:copy>
</xsl:template>
@@ -403,6 +406,12 @@
<view template="site/paste"/>
</component-instance>
<component-instance name="site.nudge" logger="lenya.site" class="org.apache.lenya.cms.site.usecases.Nudge"/>
+ <component-instance name="site.archive" logger="lenya.site" class="org.apache.lenya.cms.site.usecases.Archive">
+ <view template="site/archive"/>
+ </component-instance>
+ <component-instance name="site.restore" logger="lenya.site" class="org.apache.lenya.cms.site.usecases.Restore">
+ <view template="workflow/restore"/>
+ </component-instance>
<component-instance name="tab.acArchive" logger="lenya.site" class="org.apache.lenya.cms.ac.usecases.AccessControl">
<view template="tab/acArchive" menu="true"/>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org