You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by di...@apache.org on 2001/05/25 19:15:47 UTC

cvs commit: xml-cocoon2/src/org/apache/cocoon/components/url URLFactoryImpl.java

dims        01/05/25 10:15:47

  Modified:    src/org/apache/cocoon/components/url URLFactoryImpl.java
  Log:
  - Remove need for CONTEXT_ROOT_PATH
  - Instead try using getRealPath.
  - Fallback to getResource if getRealPath fails.
  
  Revision  Changes    Path
  1.2       +19 -10    xml-cocoon2/src/org/apache/cocoon/components/url/URLFactoryImpl.java
  
  Index: URLFactoryImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/url/URLFactoryImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- URLFactoryImpl.java	2001/05/09 20:50:02	1.1
  +++ URLFactoryImpl.java	2001/05/25 17:15:44	1.2
  @@ -23,11 +23,13 @@
   import org.apache.avalon.framework.logger.AbstractLoggable;
   import org.apache.avalon.framework.logger.Loggable;
   import org.apache.cocoon.Constants;
  +import org.apache.cocoon.environment.http.HttpContext;
   import org.apache.cocoon.util.ClassUtils;
   
  +
   /**
    * @author <a href="mailto:giacomo@apache.org">Giacomo Pati</a>
  - * @version $Id: URLFactoryImpl.java,v 1.1 2001/05/09 20:50:02 giacomo Exp $
  + * @version $Id: URLFactoryImpl.java,v 1.2 2001/05/25 17:15:44 dims Exp $
    */
   public class URLFactoryImpl extends AbstractLoggable implements URLFactory, Component, Configurable, Contextualizable {
   
  @@ -62,22 +64,29 @@
               getLogger().debug("Making URL from " + location);
               return new URL(location);
           } catch (MalformedURLException mue) {
  -            getLogger().debug("Making URL a File relative to context root", mue);
  +            getLogger().debug("Making URL - MalformedURLException in getURL:" , mue);
   
  -            String root = null;
  +            org.apache.cocoon.environment.Context envContext = null;
               try {
  -                root = (String)context.get(Constants.CONTEXT_ROOT_PATH);
  +                envContext = (org.apache.cocoon.environment.Context) 
  +                                context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);
               } catch (ContextException e){
  -                getLogger().error("ContextException in getURL",e);
  +                getLogger().error("Making URL - ContextException in getURL",e);
               }
   
  -            if (root != null) {
  -                File file = new File(root, location);
  -                if(file.exists())
  -                    return file.toURL();
  +            if(envContext instanceof HttpContext) {
  +                getLogger().debug("Making URL relative to context:" + location);
  +                String path = ((HttpContext)envContext).getRealPath(location);
  +                if(path != null)
  +                    return (new File(path)).toURL();
               }
  +
  +            getLogger().debug("Making URL a Resource:" + location);
  +            URL url = envContext.getResource(location);
  +            if(url != null)
  +                return url;
   
  -            getLogger().debug("Making URL a File (assuming that it is full path)", mue);
  +            getLogger().debug("Making URL a File (assuming that it is full path):" + location);
               return (new File(location)).toURL();
           }
       }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org