cziegeler    01/07/04 03:13:45

  Modified:    src/org/apache/cocoon/components/source
                        CocoonSourceFactory.java SourceFactory.java
                        SourceHandler.java
               src/org/apache/cocoon/environment/http HttpContext.java
               src/org/apache/cocoon/sitemap Handler.java Manager.java
  Log:
  Fixed NPE when regenerating sitemaps - Bug 2375
  
  Revision  Changes    Path
  1.3       +5 -1      
xml-cocoon2/src/org/apache/cocoon/components/source/CocoonSourceFactory.java
  
  Index: CocoonSourceFactory.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/org/apache/cocoon/components/source/CocoonSourceFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CocoonSourceFactory.java  2001/07/04 07:56:55     1.2
  +++ CocoonSourceFactory.java  2001/07/04 10:13:17     1.3
  @@ -24,7 +24,7 @@
    * as it needs the current <code>Sitemap</code> as input.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Carsten Ziegeler</a>
  - * @version CVS $Revision: 1.2 $ $Date: 2001/07/04 07:56:55 $
  + * @version CVS $Revision: 1.3 $ $Date: 2001/07/04 10:13:17 $
    */
   
   public final class CocoonSourceFactory
  @@ -48,6 +48,8 @@
        */
       public Source getSource(Environment environment, String location)
       throws ProcessingException, IOException, MalformedURLException {
  +        if (environment == null)
  +            throw new ProcessingException("CocoonSourceFactory: environment is 
required.");
           return new SitemapSource(environment,
                                    this.manager,
                                    this.sitemap,
  @@ -59,6 +61,8 @@
        */
       public Source getSource(Environment environment, URL base, String location)
       throws ProcessingException, IOException, MalformedURLException {
  +        if (environment == null)
  +            throw new ProcessingException("CocoonSourceFactory: environment is 
required.");
           return this.getSource(environment, base.toExternalForm() + location);
       }
   }
  
  
  
  1.3       +3 -1      
xml-cocoon2/src/org/apache/cocoon/components/source/SourceFactory.java
  
  Index: SourceFactory.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/org/apache/cocoon/components/source/SourceFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SourceFactory.java        2001/07/04 07:56:58     1.2
  +++ SourceFactory.java        2001/07/04 10:13:19     1.3
  @@ -17,18 +17,20 @@
   
   /**
    * @author <a href="mailto:[EMAIL PROTECTED]";>Carsten Ziegeler</a>
  - * @version $Id: SourceFactory.java,v 1.2 2001/07/04 07:56:58 cziegeler Exp $
  + * @version $Id: SourceFactory.java,v 1.3 2001/07/04 10:13:19 cziegeler Exp $
    */
   public interface SourceFactory extends ThreadSafe {
   
       /**
        * Get a <code>Source</code> object.
  +     * @param environment This is optional.
        */
       Source getSource(Environment environment, String location)
       throws ProcessingException, MalformedURLException, IOException;
   
       /**
        * Get a <code>Source</code> object.
  +     * @param environment This is optional.
        */
       Source getSource(Environment environment, URL base, String location)
       throws ProcessingException, MalformedURLException, IOException;
  
  
  
  1.3       +3 -1      
xml-cocoon2/src/org/apache/cocoon/components/source/SourceHandler.java
  
  Index: SourceHandler.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/org/apache/cocoon/components/source/SourceHandler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SourceHandler.java        2001/07/04 07:56:59     1.2
  +++ SourceHandler.java        2001/07/04 10:13:21     1.3
  @@ -17,18 +17,20 @@
   
   /**
    * @author <a href="mailto:[EMAIL PROTECTED]";>Carsten Ziegeler</a>
  - * @version $Id: SourceHandler.java,v 1.2 2001/07/04 07:56:59 cziegeler Exp $
  + * @version $Id: SourceHandler.java,v 1.3 2001/07/04 10:13:21 cziegeler Exp $
    */
   public interface SourceHandler extends Component {
   
       /**
        * Get a <code>Source</code> object.
  +     * @param environment This is optional.
        */
       Source getSource(Environment environment, String location)
       throws ProcessingException, MalformedURLException, IOException;
   
       /**
        * Get a <code>Source</code> object.
  +     * @param environment This is optional.
        */
       Source getSource(Environment environment, URL base, String location)
       throws ProcessingException, MalformedURLException, IOException;
  
  
  
  1.3       +11 -2     
xml-cocoon2/src/org/apache/cocoon/environment/http/HttpContext.java
  
  Index: HttpContext.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/org/apache/cocoon/environment/http/HttpContext.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- HttpContext.java  2001/06/22 14:11:06     1.2
  +++ HttpContext.java  2001/07/04 10:13:31     1.3
  @@ -40,8 +40,17 @@
       }
   
       public String getRealPath(String path)
  -      throws MalformedURLException {
  -      return servletContext.getRealPath(path);
  +    throws MalformedURLException {
  +        if (path.equals("/") == true) {
  +            String value = servletContext.getRealPath(path);
  +            if (value == null) {
  +                // Try to figure out the path of the root from that of WEB-INF
  +                value = this.servletContext.getResource("/WEB-INF").toString();
  +                value = value.substring(0,value.length()-"WEB-INF".length());
  +            }
  +            return value;
  +        }
  +        return servletContext.getRealPath(path);
       }
   
       public String getMimeType(String file) {
  
  
  
  1.14      +48 -18    xml-cocoon2/src/org/apache/cocoon/sitemap/Handler.java
  
  Index: Handler.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/sitemap/Handler.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Handler.java      2001/07/04 07:57:31     1.13
  +++ Handler.java      2001/07/04 10:13:38     1.14
  @@ -9,11 +9,16 @@
   package org.apache.cocoon.sitemap;
   
   import java.io.FileNotFoundException;
  +import java.io.IOException;
  +import java.net.URL;
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.component.Component;
   import org.apache.avalon.framework.component.ComponentException;
   import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.component.Composable;
  +import org.apache.avalon.framework.context.Context;
  +import org.apache.avalon.framework.context.ContextException;
  +import org.apache.avalon.framework.context.Contextualizable;
   import org.apache.avalon.framework.logger.AbstractLoggable;
   import org.apache.avalon.excalibur.component.RoleManager;
   import org.apache.cocoon.ProcessingException;
  @@ -27,6 +32,8 @@
   import org.apache.cocoon.components.source.SourceHandler;
   import org.apache.cocoon.environment.Environment;
   import org.apache.cocoon.environment.Source;
  +import org.apache.cocoon.environment.SourceResolver;
  +import org.xml.sax.SAXException;
   
   /**
    * Handles the manageing and stating of one <code>Sitemap</code>
  @@ -34,10 +41,10 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Carsten Ziegeler</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Giacomo Pati</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Stefano Mazzocchi</a>
  - * @version CVS $Revision: 1.13 $ $Date: 2001/07/04 07:57:31 $
  + * @version CVS $Revision: 1.14 $ $Date: 2001/07/04 10:13:38 $
    */
   public class Handler extends AbstractLoggable
  -implements Runnable, Composable, Processor, Disposable {
  +implements Runnable, Contextualizable, Composable, Processor, Disposable, 
SourceResolver {
   
       /** the component manager */
       private ComponentManager manager;
  @@ -56,8 +63,7 @@
       /** the regenerating thread */
       private Thread regeneration;
       private volatile boolean isRegenerationRunning = false;
  -    /** The environment for (re)generation the sitemap */
  -    private Environment environment;
  +    private Source contextSource;
   
       /** the sitemaps base path */
       private String basePath;
  @@ -65,17 +71,27 @@
       /** The source handler for the sitemap components */
       private SourceHandler sourceHandler;
   
  +    protected Handler(String sourceFileName, boolean check_reload) throws 
FileNotFoundException {
  +        this.check_reload = check_reload;
  +        this.sourceFileName = sourceFileName;
  +    }
  +
  +    /**
  +     * Contextualizable
  +     */
  +    public void contextualize(Context context)
  +    throws ContextException {
  +    }
  +
  +    /**
  +     * Composable
  +     */
       public void compose(ComponentManager manager)
       throws ComponentException {
           this.manager = manager;
           this.sourceHandler = (SourceHandler)manager.lookup(Roles.SOURCE_HANDLER);
       }
   
  -    protected Handler(String sourceFileName, boolean check_reload) throws 
FileNotFoundException {
  -        this.check_reload = check_reload;
  -        this.sourceFileName = sourceFileName;
  -    }
  -
       protected boolean available() {
           return (sitemap != null);
       }
  @@ -102,6 +118,7 @@
           try {
               environment.setSourceHandler(this.sourceHandler);
               this.source = environment.resolve(this.sourceFileName);
  +            this.contextSource = environment.resolve("");
           } finally {
               environment.setSourceHandler(null);
           }
  @@ -117,7 +134,6 @@
                   
regeneration.setContextClassLoader(Thread.currentThread().getContextClassLoader());
               } catch (Exception e) {
               }
  -            this.environment = environment;
   
               /* clear old exception if any */
   
  @@ -186,13 +202,8 @@
   
               XSLTFactoryLoader.setLogger(getLogger());
               programGenerator = 
(ProgramGenerator)this.manager.lookup(Roles.PROGRAM_GENERATOR);
  -            try {
  -                this.environment.setSourceHandler(this.sourceHandler);
  -                smap = (Sitemap)programGenerator.load(this.manager, 
this.sourceFileName, markupLanguage,
  -                    programmingLanguage, this.environment);
  -            } finally {
  -                this.environment.setSourceHandler(null);
  -            }
  +            smap = (Sitemap)programGenerator.load(this.manager, 
this.sourceFileName, markupLanguage,
  +                    programmingLanguage, this);
               if (this.sitemap != null) {
                   programGenerator.release((CompiledComponent)this.sitemap);
               }
  @@ -216,8 +227,8 @@
                   this.manager.release(programGenerator);
               }
               this.regeneration = null;
  -            this.environment = null;
               this.isRegenerationRunning = false;
  +            this.contextSource = null;
           }
       }
   
  @@ -243,4 +254,23 @@
               this.sourceHandler = null;
           }
       }
  +
  +    /**
  +     * Resolve an entity. Interface SourceResolver
  +     */
  +    public Source resolve(String systemId)
  +    throws ProcessingException, SAXException, IOException {
  +        if (systemId == null) throw new SAXException("Invalid System ID");
  +
  +        URL context = new URL(this.contextSource.getSystemId());
  +
  +        if (systemId.length() == 0)
  +            return this.sourceHandler.getSource(null, context, systemId);
  +        if (systemId.indexOf(":") > 1)
  +            return this.sourceHandler.getSource(null, systemId);
  +        if (systemId.charAt(0) == '/')
  +            return this.sourceHandler.getSource(null, context.getProtocol() + ":" + 
systemId);
  +        return this.sourceHandler.getSource(null, context, systemId);
  +    }
  +
   }
  
  
  
  1.5       +2 -1      xml-cocoon2/src/org/apache/cocoon/sitemap/Manager.java
  
  Index: Manager.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/sitemap/Manager.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Manager.java      2001/07/04 07:57:33     1.4
  +++ Manager.java      2001/07/04 10:13:39     1.5
  @@ -33,7 +33,7 @@
    * checking regeneration of the sub <code>Sitemap</code>
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Giacomo Pati</a>
  - * @version CVS $Revision: 1.4 $ $Date: 2001/07/04 07:57:33 $
  + * @version CVS $Revision: 1.5 $ $Date: 2001/07/04 10:13:39 $
    */
   public class Manager extends AbstractLoggable implements Component, Configurable, 
Composable, Contextualizable, ThreadSafe {
       private Context context;
  @@ -163,6 +163,7 @@
                   sitemapHandler = new Handler(source, check_reload);
                   sitemapHandler.setLogger(getLogger());
                   sitemapHandler.compose(newManager);
  +                sitemapHandler.contextualize(this.context);
                   sitemapHandler.regenerate(environment);
                   sitemaps.put(source, sitemapHandler);
               }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to