cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gkossakow...@apache.org
Subject svn commit: r634845 - in /cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice: ServletServiceContext.java spring/ServletFactoryBean.java
Date Fri, 07 Mar 2008 22:27:47 GMT
Author: gkossakowski
Date: Fri Mar  7 14:27:46 2008
New Revision: 634845

URL: http://svn.apache.org/viewvc?rev=634845&view=rev
Log:
Moved final initialization (resolution using SourceResolver) of to the ServletFactoryBean.
It's much better place because resolution of URI for contextPath does not (and shouldn't!)
depend on the processing.
That's why it's more sane to do it in ServletFactoryBean.

Modified:
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletServiceContext.java
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletFactoryBean.java

Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletServiceContext.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletServiceContext.java?rev=634845&r1=634844&r2=634845&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletServiceContext.java
(original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletServiceContext.java
Fri Mar  7 14:27:46 2008
@@ -102,34 +102,9 @@
     }
 
     public URL getResource(String path) throws MalformedURLException {
-        // hack for getting a file protocol or other protocols that can be used as context
-        // path in the getResource method in the servlet context
-        if (!(contextPath.startsWith("file:") || contextPath.startsWith("/")
-              || contextPath.indexOf(':') == -1)) {
-            SourceResolver resolver = null;
-            Source source = null;
-            try {
-                BeanFactory factory = WebApplicationContextUtils.getRequiredWebApplicationContext(this);
-                resolver = (SourceResolver) factory.getBean(SourceResolver.ROLE);
-                source = resolver.resolveURI(contextPath);
-                contextPath = source.getURI();
-            } catch (IOException e) {
-                throw new MalformedURLException("Could not resolve " + contextPath + " due
to " + e);
-            } finally {
-                if (resolver != null) {
-                    resolver.release(source);
-                }
-            }
-        }
-
         // HACK: allow file:/ URLs for reloading of sitemaps during development
         if (this.contextPath.startsWith("file:")) {
             return new URL("file", null, this.contextPath.substring("file:".length()) + path);
-        }
-
-        if (this.contextPath.length() != 0 && this.contextPath.charAt(0) != '/')
{
-            throw new MalformedURLException("The contextPath must be empty or start with
'/' " +
-                                            this.contextPath);
         }
 
         // prefix the path with the servlet context resolve and resolve in the embedding

Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletFactoryBean.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletFactoryBean.java?rev=634845&r1=634844&r2=634845&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletFactoryBean.java
(original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletFactoryBean.java
Fri Mar  7 14:27:46 2008
@@ -16,6 +16,8 @@
  */
 package org.apache.cocoon.servletservice.spring;
 
+import java.io.IOException;
+import java.net.MalformedURLException;
 import java.util.Enumeration;
 import java.util.Map;
 
@@ -30,6 +32,8 @@
 import org.aopalliance.intercept.MethodInvocation;
 import org.apache.cocoon.servletservice.Mountable;
 import org.apache.cocoon.servletservice.ServletServiceContext;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceResolver;
 import org.springframework.aop.framework.ProxyFactory;
 import org.springframework.aop.support.DefaultIntroductionAdvisor;
 import org.springframework.aop.support.DelegatingIntroductionInterceptor;
@@ -76,7 +80,6 @@
         this.servletServiceContext.setServletContext(this.servletContext);
 
         this.servletServiceContext.setMountPath(this.mountPath);
-        this.servletServiceContext.setContextPath(this.contextPath);
 
         this.servletServiceContext.setInitParams(this.initParams);
         this.servletServiceContext.setAttributes(this.contextParams);
@@ -90,6 +93,39 @@
         if (this.parentContainer == null) {
             this.parentContainer = WebApplicationContextUtils.getRequiredWebApplicationContext(this.servletContext);
         }
+        
+        String contextPath = this.contextPath;
+        
+        //FIXME: I'm not sure if there is any better place for this code (GK)
+        //-----------------------------------------------------
+        // hack for getting a file protocol or other protocols that can be used as context
+        // path in the getResource method in the servlet context
+        int tmp = contextPath.indexOf(':');
+        boolean tmp2 = !(contextPath.startsWith("file:") || contextPath.startsWith("/") ||
contextPath.indexOf(':') == -1);
+        if (!(contextPath.startsWith("file:") || contextPath.startsWith("/") || contextPath.indexOf(':')
== -1)) {
+            SourceResolver resolver = null;
+            Source source = null;
+            try {
+                resolver = (SourceResolver) parentContainer.getBean(SourceResolver.ROLE);
+                source = resolver.resolveURI(contextPath);
+                contextPath = source.getURI();
+            } catch (IOException e) {
+                throw new MalformedURLException("Could not resolve " + contextPath + " due
to " + e);
+            } finally {
+                if (resolver != null) {
+                    resolver.release(source);
+                }
+            }
+        }
+        //----------------------------------------------------
+        
+
+        if (contextPath.length() != 0 && contextPath.charAt(0) != '/' &&
!contextPath.startsWith("file:")) {
+            throw new MalformedURLException("The contextPath must be empty or start with
'/' " +
+                                            contextPath);
+        }
+        
+        this.servletServiceContext.setContextPath(contextPath);
 
         GenericWebApplicationContext container = new GenericWebApplicationContext();
         container.setParent(this.parentContainer);



Mime
View raw message