You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by fl...@apache.org on 2011/02/22 00:23:03 UTC
svn commit: r1073185 - in /lenya/trunk:
org.apache.lenya.core.cocoon/src/main/java/org/apache/lenya/cms/cocoon/components/modules/input/
org.apache.lenya.core.cocoon/src/main/java/org/apache/lenya/cms/cocoon/transformation/
org.apache.lenya.core.utils/...
Author: florent
Date: Mon Feb 21 23:23:03 2011
New Revision: 1073185
URL: http://svn.apache.org/viewvc?rev=1073185&view=rev
Log:
- some lost files during all the moves
Added:
lenya/trunk/org.apache.lenya.core.cocoon/src/main/java/org/apache/lenya/cms/cocoon/components/modules/input/ProxyModule.java
lenya/trunk/org.apache.lenya.core.cocoon/src/main/java/org/apache/lenya/cms/cocoon/transformation/
lenya/trunk/org.apache.lenya.core.cocoon/src/main/java/org/apache/lenya/cms/cocoon/transformation/ProxyTransformer.java
lenya/trunk/org.apache.lenya.core.utils/src/test/java/org/apache/lenya/utils/AbstractLenyaTestCase.java
Added: lenya/trunk/org.apache.lenya.core.cocoon/src/main/java/org/apache/lenya/cms/cocoon/components/modules/input/ProxyModule.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.cocoon/src/main/java/org/apache/lenya/cms/cocoon/components/modules/input/ProxyModule.java?rev=1073185&view=auto
==============================================================================
--- lenya/trunk/org.apache.lenya.core.cocoon/src/main/java/org/apache/lenya/cms/cocoon/components/modules/input/ProxyModule.java (added)
+++ lenya/trunk/org.apache.lenya.core.cocoon/src/main/java/org/apache/lenya/cms/cocoon/components/modules/input/ProxyModule.java Mon Feb 21 23:23:03 2011
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.cocoon.components.modules.input.AbstractInputModule;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
+import org.apache.lenya.cms.linking.LinkRewriter;
+import org.apache.lenya.cms.linking.OutgoingLinkRewriter;
+import org.apache.lenya.cms.publication.Repository;
+import org.apache.lenya.cms.publication.Session;
+
+/**
+ * <p>
+ * Input module for getting the base URL which may be prepended to internal URLs to construct links.
+ * The functionality corresponds to the
+ * {@link org.apache.lenya.cms.cocoon.transformation.ProxyTransformer} with one exception: If the
+ * <em>webappUrl</em> parameter is an empty string, the root proxy URL (or the context prefix,
+ * resp.) is returned.
+ * </p>
+ * <p>
+ * Usage: <code>{proxy:{webappUrl}}</code>
+ * </p>
+ * <p>
+ * The module can be configured to use absolute or relative URLs in the same way as the
+ * {@link org.apache.lenya.cms.cocoon.transformation.ProxyTransformer}.
+ * </p>
+ */
+public class ProxyModule extends AbstractInputModule {
+
+ protected static final String ATTRIBUTE_TYPE = "type";
+ protected static final String URL_TYPE_ABSOLUTE = "absolute";
+ protected static final String URL_TYPE_RELATIVE = "relative";
+ protected static final String PARAMETER_URLS = "urls";
+
+ private boolean relativeUrls;
+ protected Repository repository;
+
+ /**
+ * @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 {
+
+ final String webappUrl = name;
+ Request request = ObjectModelHelper.getRequest(objectModel);
+
+ String value = null;
+ try {
+ if (webappUrl.equals("")) {
+ value = rewrite(request, "/");
+ if (value.endsWith("/")) {
+ value = value.substring(0, value.length() - 1);
+ }
+ } else {
+ value = rewrite(request, webappUrl);
+ }
+ } catch (ConfigurationException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new ConfigurationException("Obtaining value for [" + name + "] failed: ", e);
+ }
+ return value;
+ }
+
+ protected String rewrite(Request request, String url) throws ConfigurationException {
+ Session session = this.repository.getSession(request);
+ LinkRewriter rewriter = new OutgoingLinkRewriter(session, request.getRequestURI(), request
+ .isSecure(), false, this.relativeUrls);
+ if (!rewriter.matches(url)) {
+ throw new ConfigurationException("The URL [" + url + "] can't be rewritten!");
+ }
+ return rewriter.rewrite(url);
+ }
+
+ /**
+ * @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;
+ }
+
+ public void configure(Configuration conf) throws ConfigurationException {
+ super.configure(conf);
+ Configuration urlConfig = conf.getChild(PARAMETER_URLS, false);
+ if (urlConfig != null) {
+ String value = urlConfig.getAttribute(ATTRIBUTE_TYPE);
+ setUrlType(value);
+ }
+ }
+
+ protected void setUrlType(String value) throws ConfigurationException {
+ if (value.equals(URL_TYPE_RELATIVE)) {
+ this.relativeUrls = true;
+ } else if (value.equals(URL_TYPE_ABSOLUTE)) {
+ this.relativeUrls = false;
+ } else {
+ throw new ConfigurationException("Invalid URL type [" + value
+ + "], must be relative or absolute.");
+ }
+ }
+
+ public void setRepository(Repository repository) {
+ this.repository = repository;
+ }
+
+}
\ No newline at end of file
Added: lenya/trunk/org.apache.lenya.core.cocoon/src/main/java/org/apache/lenya/cms/cocoon/transformation/ProxyTransformer.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.cocoon/src/main/java/org/apache/lenya/cms/cocoon/transformation/ProxyTransformer.java?rev=1073185&view=auto
==============================================================================
--- lenya/trunk/org.apache.lenya.core.cocoon/src/main/java/org/apache/lenya/cms/cocoon/transformation/ProxyTransformer.java (added)
+++ lenya/trunk/org.apache.lenya.core.cocoon/src/main/java/org/apache/lenya/cms/cocoon/transformation/ProxyTransformer.java Mon Feb 21 23:23:03 2011
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.transformation;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.lenya.cms.linking.LinkRewriter;
+import org.apache.lenya.cms.linking.OutgoingLinkRewriter;
+import org.apache.lenya.cms.publication.Repository;
+import org.apache.lenya.cms.publication.Session;
+import org.xml.sax.SAXException;
+
+/**
+ * <p>
+ * Proxy transformer.
+ * </p>
+ * <p>
+ * The resulting URLs can either be absolute (default) or relative. You can either configure this
+ * when declaring the transformer:
+ * </p>
+ * <code><pre>
+ * <map:transformer ... >
+ * <urls type="relative"/>
+ * ...
+ * </map:transformer>
+ * </pre></code>
+ * <p>
+ * or pass a parameter:
+ * </p>
+ * <code><pre>
+ * <map:parameter name="urls" value="relative"/>
+ * </pre></code>
+ * @see OutgoingLinkRewriter
+ */
+public class ProxyTransformer extends AbstractLinkTransformer {
+
+ protected static final String ATTRIBUTE_TYPE = "type";
+ protected static final String URL_TYPE_ABSOLUTE = "absolute";
+ protected static final String URL_TYPE_RELATIVE = "relative";
+ protected static final String PARAMETER_URLS = "urls";
+
+ private boolean relativeUrls = false;
+ private LinkRewriter rewriter;
+ private Repository repository;
+
+ public void setup(SourceResolver resolver, Map objectModel, String source, Parameters params)
+ throws ProcessingException, SAXException, IOException {
+ super.setup(resolver, objectModel, source, params);
+ Request request = ObjectModelHelper.getRequest(objectModel);
+
+ try {
+ if (params.isParameter(PARAMETER_URLS)) {
+ setUrlType(params.getParameter(PARAMETER_URLS));
+ }
+ Session session = this.repository.getSession(request);
+ String webappUrl = getWebappUrl(params, objectModel);
+ this.rewriter = new OutgoingLinkRewriter(session, webappUrl, request.isSecure(), false,
+ this.relativeUrls);
+ } catch (final Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void configure(Configuration config) throws ConfigurationException {
+ super.configure(config);
+ Configuration urlConfig = config.getChild(PARAMETER_URLS, false);
+ if (urlConfig != null) {
+ String value = urlConfig.getAttribute(ATTRIBUTE_TYPE);
+ setUrlType(value);
+ }
+ }
+
+ protected void setUrlType(String value) throws ConfigurationException {
+ if (value.equals(URL_TYPE_RELATIVE)) {
+ this.relativeUrls = true;
+ } else if (value.equals(URL_TYPE_ABSOLUTE)) {
+ this.relativeUrls = false;
+ } else {
+ throw new ConfigurationException("Invalid URL type [" + value
+ + "], must be relative or absolute.");
+ }
+ }
+
+ protected LinkRewriter getLinkRewriter() {
+ return this.rewriter;
+ }
+
+ public void recycle() {
+ super.recycle();
+ this.rewriter = null;
+ }
+
+ public void setRepository(Repository repository) {
+ this.repository = repository;
+ }
+
+
+}
Added: lenya/trunk/org.apache.lenya.core.utils/src/test/java/org/apache/lenya/utils/AbstractLenyaTestCase.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.utils/src/test/java/org/apache/lenya/utils/AbstractLenyaTestCase.java?rev=1073185&view=auto
==============================================================================
--- lenya/trunk/org.apache.lenya.core.utils/src/test/java/org/apache/lenya/utils/AbstractLenyaTestCase.java (added)
+++ lenya/trunk/org.apache.lenya.core.utils/src/test/java/org/apache/lenya/utils/AbstractLenyaTestCase.java Mon Feb 21 23:23:03 2011
@@ -0,0 +1,186 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.utils;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.avalon.framework.context.DefaultContext;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.cocoon.AbstractTestCase;
+import org.apache.cocoon.Constants;
+import org.apache.cocoon.components.ContextHelper;
+import org.apache.cocoon.core.container.ContainerTestCase;
+import org.apache.cocoon.environment.Context;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.mock.MockEnvironment;
+import org.apache.cocoon.util.IOUtils;
+import org.apache.commons.lang.SystemUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.excalibur.source.SourceResolver;
+import org.apache.excalibur.xml.EntityResolver;
+import org.apache.lenya.utils.xml.DocumentHelper;
+
+/**
+ * Base class for Lenya tests which need the context information.
+ */
+public class AbstractLenyaTestCase extends ContainerTestCase {
+
+ private static final Log logger = LogFactory.getLog(AbstractLenyaTestCase.class);
+
+ protected DefaultContext context;
+
+/*
+ protected void addContext(DefaultContext context) {
+ super.addContext(context);
+
+ this.context = context;
+
+ String tempPath = System.getProperty("tempDir", "build/lenya/temp");
+ String contextRoot = System.getProperty("contextRoot", "build/lenya/webapp");
+ getLogger().info("Adding context root entry [" + contextRoot + "]");
+
+ File contextRootDir = new File(contextRoot);
+ context.put("context-root", contextRootDir);
+
+ String testPath = System.getProperty("testPath", "build/test");
+ File testRootDir = new File(testPath);
+ context.put("test-path", testRootDir);
+
+ Context envContext = new CommandLineContext(contextRoot);
+ ContainerUtil.enableLogging(envContext, getLogger());
+ context.put(Constants.CONTEXT_ENVIRONMENT_CONTEXT, envContext);
+
+ File tempDir = new File(tempPath);
+
+ File workDir = new File(tempDir, "work");
+ context.put("work-directory", workDir);
+
+ File cacheDir = new File(tempDir, "cache");
+ context.put(Constants.CONTEXT_CACHE_DIR, cacheDir);
+
+ File uploadDir = new File(tempDir, "upload");
+ context.put(Constants.CONTEXT_UPLOAD_DIR, uploadDir);
+
+ context.put(Constants.CONTEXT_CLASS_LOADER, LenyaTestCase.class.getClassLoader());
+ context.put(Constants.CONTEXT_CLASSPATH, getClassPath(contextRoot));
+ // context.put(Constants.CONTEXT_CONFIG_URL, conf.toURL());
+ context.put(Constants.CONTEXT_DEFAULT_ENCODING, "ISO-8859-1");
+ }
+
+ private Request request = null;
+
+ protected Request getRequest() {
+ return this.request;
+ }
+
+ protected void prepare() throws Exception {
+ File testPath = new File("build/test");
+ final String resourceName = LenyaTestCase.class.getName().replace('.', '/') + ".xtest";
+ File resourceFile = new File(testPath, resourceName.replace('/', File.separatorChar));
+
+ if (resourceFile.isFile()) {
+ getLogger().debug("Loading resource " + resourceFile.getAbsolutePath());
+ prepare(new FileInputStream(resourceFile));
+ } else {
+ getLogger().debug("Resource not found " + resourceName);
+ }
+
+ SourceResolver resolver = (SourceResolver) getManager().lookup(SourceResolver.ROLE);
+ MockEnvironment env = new MockEnvironment(resolver);
+
+ String pathInfo = getWebappUrl();
+
+ this.request = new CommandLineRequest(env,
+ "",
+ "",
+ pathInfo,
+ new HashMap(),
+ getRequestParameters());
+ context.put("object-model.request", this.request);
+
+ Map objectModel = new HashMap();
+ objectModel.put(ObjectModelHelper.REQUEST_OBJECT, request);
+ Context envContext = (Context) context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);
+ objectModel.put(ObjectModelHelper.CONTEXT_OBJECT, envContext);
+ context.put(ContextHelper.CONTEXT_OBJECT_MODEL, objectModel);
+
+ EntityResolver entityResolver = (EntityResolver) getManager().lookup(EntityResolver.ROLE);
+ DocumentHelper.setEntityResolver(entityResolver);
+
+ }
+
+ protected String getWebappUrl() {
+ return "/test/authoring/index.html";
+ }
+
+ protected Map getRequestParameters() {
+ return new HashMap();
+ }
+*/
+ /**
+ * This builds the important ClassPath used by this class. It does so in a neutral way. It
+ * iterates in alphabetical order through every file in the lib directory and adds it to the
+ * classpath.
+ *
+ * Also, we add the files to the ClassLoader for the Cocoon system. In order to protect
+ * ourselves from skitzofrantic classloaders, we need to work with a known one.
+ *
+ * @param context The context path
+ * @return a <code>String</code> value
+ */
+ protected String getClassPath(final String context) {
+ StringBuffer buildClassPath = new StringBuffer();
+
+ String classDir = context + "/WEB-INF/classes";
+ buildClassPath.append(classDir);
+
+ File root = new File(context + "/WEB-INF/lib");
+ if (root.isDirectory()) {
+ File[] libraries = root.listFiles();
+ Arrays.sort(libraries);
+ for (int i = 0; i < libraries.length; i++) {
+ if (libraries[i].getAbsolutePath().endsWith(".jar")) {
+ buildClassPath.append(File.pathSeparatorChar)
+ .append(IOUtils.getFullFilename(libraries[i]));
+ }
+ }
+ }
+
+ buildClassPath.append(File.pathSeparatorChar).append(SystemUtils.JAVA_CLASS_PATH);
+
+ // Extra class path is necessary for non-classloader-aware java compilers to compile XSPs
+ // buildClassPath.append(File.pathSeparatorChar)
+ // .append(getExtraClassPath(context));
+
+ logger.info("Context classpath: " + buildClassPath);
+ return buildClassPath.toString();
+ }
+
+ @Override
+ protected ServiceManager getManager() {
+ throw new UnsupportedOperationException("Use getBeanFactory() instead.");
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org