cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u..@apache.org
Subject svn commit: rev 36180 - in cocoon/branches/butterfly/src/java/org/apache/butterfly: servlet source
Date Tue, 10 Aug 2004 15:37:04 GMT
Author: ugo
Date: Tue Aug 10 08:37:04 2004
New Revision: 36180

Modified:
   cocoon/branches/butterfly/src/java/org/apache/butterfly/servlet/ButterflyServlet.java
   cocoon/branches/butterfly/src/java/org/apache/butterfly/source/SourceResolver.java
Log:
Contextualized SourceResolver by implementing ApplicationContextAware

Modified: cocoon/branches/butterfly/src/java/org/apache/butterfly/servlet/ButterflyServlet.java
==============================================================================
--- cocoon/branches/butterfly/src/java/org/apache/butterfly/servlet/ButterflyServlet.java
(original)
+++ cocoon/branches/butterfly/src/java/org/apache/butterfly/servlet/ButterflyServlet.java
Tue Aug 10 08:37:04 2004
@@ -18,7 +18,6 @@
 import groovy.lang.GroovyClassLoader;
 import groovy.lang.GroovyObject;
 
-import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.net.MalformedURLException;
@@ -32,7 +31,6 @@
 
 import org.apache.butterfly.environment.Environment;
 import org.apache.butterfly.environment.http.HttpEnvironment;
-import org.apache.butterfly.source.SourceResolver;
 import org.apache.commons.lang.BooleanUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -67,13 +65,6 @@
         */
         this.containerEncoding = "ISO-8859-1";
         this.defaultFormEncoding = "ISO-8859-1";
-        // Contextualize the source resolver
-        SourceResolver resolver = (SourceResolver) this.applicationContext.getBean("sourceResolver");
-        try {
-            resolver.setBaseURL(new File(servletContext.getRealPath("/")).toURL());
-        } catch (MalformedURLException e) {
-            throw new ServletException(e);
-        }
     }
     
     /* (non-Javadoc)

Modified: cocoon/branches/butterfly/src/java/org/apache/butterfly/source/SourceResolver.java
==============================================================================
--- cocoon/branches/butterfly/src/java/org/apache/butterfly/source/SourceResolver.java	(original)
+++ cocoon/branches/butterfly/src/java/org/apache/butterfly/source/SourceResolver.java	Tue
Aug 10 08:37:04 2004
@@ -16,22 +16,32 @@
 package org.apache.butterfly.source;
 
 import java.io.File;
+import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Map;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.FatalBeanException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+
 
 /**
  * Description of SourceResolver.
  * 
- * @version CVS $Id: SourceResolver.java,v 1.2 2004/07/25 21:55:20 ugo Exp $
+ * @version CVS $Id$
  */
-public class SourceResolver {
+public class SourceResolver implements ApplicationContextAware {
+    protected static final Log logger = LogFactory.getLog(SourceResolver.class);
     private Map factories;
-    URL baseURL;
+    private URL baseURL;
     
     public SourceResolver() {
         try {
+            // Default value
             baseURL = new File(System.getProperty("user.dir")).toURL();
         } catch (MalformedURLException e) {
             throw new SourceException(e);
@@ -121,5 +131,21 @@
         else
             systemID = SourceUtil.absolutize(baseURI, systemID);
         return systemID;
+    }
+
+    /* (non-Javadoc)
+     * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
+     */
+    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
{
+        try {
+            this.baseURL = applicationContext.getResource("/").getURL();
+            if (logger.isInfoEnabled()) {
+                logger.info("SourceResolver's base URL set to [" + baseURL + "].");
+            }
+        } catch (IOException e) {
+            logger.fatal("Cannot get base URL for Source resolver.", e);
+            throw new FatalBeanException("Cannot get base URL for Source resolver.", e);
+        }
+        
     }
 }

Mime
View raw message