You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by re...@apache.org on 2008/04/23 18:15:32 UTC

svn commit: r650929 - in /cocoon/whiteboard/corona/trunk: corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/SitemapServlet.java corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/InvocationImpl.java

Author: reinhard
Date: Wed Apr 23 09:15:25 2008
New Revision: 650929

URL: http://svn.apache.org/viewvc?rev=650929&view=rev
Log:
. InvocationImpl got a method to set the base url which is used for resolving relative paths
. the base url is set by the SitemapServlet

Modified:
    cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/SitemapServlet.java
    cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/InvocationImpl.java

Modified: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/SitemapServlet.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/SitemapServlet.java?rev=650929&r1=650928&r2=650929&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/SitemapServlet.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/SitemapServlet.java Wed Apr 23 09:15:25 2008
@@ -22,6 +22,7 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.PrintWriter;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Enumeration;
 import java.util.HashMap;
@@ -62,6 +63,7 @@
     public void invoke(String requestURI, Map<String, Object> parameters, OutputStream outputStream) {
         InvocationImpl invocation = (InvocationImpl) this.beanFactory.getBean(Invocation.class.getName());
 
+        invocation.setBaseURL(this.getBaseURL());
         invocation.setRequestURI(requestURI);
         invocation.setParameters(parameters);
         invocation.setOutputStream(outputStream);
@@ -74,7 +76,8 @@
     }
 
     @Override
-    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException,
+            IOException {
         this.lazyInitialize(this.servletConfig);
 
         try {
@@ -115,10 +118,19 @@
         return invocationParameters;
     }
 
+    private URL getBaseURL() {
+        try {
+            return this.servletConfig.getServletContext().getResource("/");
+        } catch (MalformedURLException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
     private synchronized void lazyInitialize(ServletConfig servletConfig) throws ServletException {
         if (!this.initialized) {
             try {
-                SitemapBuilder sitemapBuilder = (SitemapBuilder) this.beanFactory.getBean(SitemapBuilder.class.getName());
+                SitemapBuilder sitemapBuilder = (SitemapBuilder) this.beanFactory.getBean(SitemapBuilder.class
+                        .getName());
                 URL url = servletConfig.getServletContext().getResource("/sitemap.xmap");
                 this.sitemap = sitemapBuilder.build(url);
             } catch (Exception e) {

Modified: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/InvocationImpl.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/InvocationImpl.java?rev=650929&r1=650928&r2=650929&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/InvocationImpl.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/InvocationImpl.java Wed Apr 23 09:15:25 2008
@@ -19,7 +19,7 @@
 package org.apache.cocoon.corona.sitemap;
 
 import java.io.OutputStream;
-import java.net.URI;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
@@ -29,7 +29,6 @@
 import org.apache.cocoon.corona.pipeline.Pipeline;
 import org.apache.cocoon.corona.pipeline.action.Action;
 import org.apache.cocoon.corona.pipeline.component.PipelineComponent;
-import org.apache.cocoon.corona.pipeline.resource.ClassPathResourceResolver;
 import org.apache.cocoon.corona.sitemap.expression.LanguageInterpreter;
 import org.apache.cocoon.corona.sitemap.util.ParameterHelper;
 
@@ -44,13 +43,16 @@
     private String requestURI;
     private SitemapParameters sitemapParameters = new SitemapParameters();
 
+    private URL baseURL;
+
     public InvocationImpl() {
     }
 
     /**
      * Create a {@link InvocationImpl} object using the given output stream.
      * 
-     * @param outputStream The {@link OutputStream} where the result is writen to.
+     * @param outputStream
+     *            The {@link OutputStream} where the result is writen to.
      */
     public InvocationImpl(OutputStream outputStream) {
         super();
@@ -58,10 +60,13 @@
     }
 
     /**
-     * Create a {@link InvocationImpl} object using the given output stream and requestURI.
+     * Create a {@link InvocationImpl} object using the given output stream and
+     * requestURI.
      * 
-     * @param outputStream The {@link OutputStream} where the result is writen to.
-     * @param requestURI The requested path.
+     * @param outputStream
+     *            The {@link OutputStream} where the result is writen to.
+     * @param requestURI
+     *            The requested path.
      */
     public InvocationImpl(OutputStream outputStream, String requestURI) {
         super();
@@ -70,11 +75,16 @@
     }
 
     /**
-     * Create a {@link InvocationImpl} object using the given output stream, requestURI and parameters.
+     * Create a {@link InvocationImpl} object using the given output stream,
+     * requestURI and parameters.
      * 
-     * @param outputStream The {@link OutputStream} where the result is written to.
-     * @param requestURI The requested path.
-     * @param parameters A {@link Map} of parameters that are used when the pipeline is being executed.
+     * @param outputStream
+     *            The {@link OutputStream} where the result is written to.
+     * @param requestURI
+     *            The requested path.
+     * @param parameters
+     *            A {@link Map} of parameters that are used when the pipeline is
+     *            being executed.
      */
     public InvocationImpl(OutputStream outputStream, String requestURI, Map<String, Object> parameters) {
         super();
@@ -165,7 +175,8 @@
     /**
      * {@inheritDoc}
      * 
-     * @see org.apache.cocoon.corona.sitemap.Invocation#installComponent(java.lang.String, java.util.Map)
+     * @see org.apache.cocoon.corona.sitemap.Invocation#installComponent(java.lang.String,
+     *      java.util.Map)
      */
     public void installComponent(String type, Map<String, ? extends Object> componentParameters) {
         if (this.pipeline == null) {
@@ -208,7 +219,8 @@
     /**
      * {@inheritDoc}
      * 
-     * @see org.apache.cocoon.corona.sitemap.Invocation#pushSitemapParameters(java.lang.String, java.util.Map)
+     * @see org.apache.cocoon.corona.sitemap.Invocation#pushSitemapParameters(java.lang.String,
+     *      java.util.Map)
      */
     public void pushSitemapParameters(String nodeName, Map<String, ? extends Object> sitemapParameters) {
         this.sitemapParameters.pushParameters(nodeName, sitemapParameters);
@@ -221,14 +233,8 @@
      */
     public URL resolve(String resource) {
         try {
-            URI uri = new URI(resource);
-
-            if (uri.isAbsolute()) {
-                return uri.toURL();
-            }
-
-            return ClassPathResourceResolver.getInstance().resolve(resource);
-        } catch (Exception e) {
+            return new URL(this.baseURL, resource);
+        } catch (MalformedURLException e) {
             throw new RuntimeException(e);
         }
     }
@@ -280,8 +286,8 @@
             final String language = matcher.group(1);
             final LanguageInterpreter languageInterpreter = this.getLanguageInterpreter(language);
             if (languageInterpreter == null) {
-                throw new IllegalArgumentException("Could not resolve parameter '" + parameter + "'. The language '" + language
-                        + "' is not supported.");
+                throw new IllegalArgumentException("Could not resolve parameter '" + parameter + "'. The language '"
+                        + language + "' is not supported.");
             }
 
             final String variable = matcher.group(2);
@@ -314,5 +320,9 @@
         }
 
         return resolvedParameters;
+    }
+
+    public void setBaseURL(URL baseURL) {
+        this.baseURL = baseURL;
     }
 }