You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2001/07/04 12:11:27 UTC

cvs commit: xml-cocoon2/src/org/apache/cocoon/sitemap Handler.java Manager.java

cziegeler    01/07/04 03:11:26

  Modified:    src/org/apache/cocoon/components/source Tag:
                        cocoon_20_branch CocoonSourceFactory.java
                        SourceFactory.java SourceHandler.java
               src/org/apache/cocoon/environment/http Tag: cocoon_20_branch
                        HttpContext.java
               src/org/apache/cocoon/sitemap Tag: cocoon_20_branch
                        Handler.java Manager.java
  Log:
  Fixed NPE when regenerating sitemaps - Bug 2375
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.2   +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.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- CocoonSourceFactory.java	2001/07/04 07:29:43	1.1.2.1
  +++ CocoonSourceFactory.java	2001/07/04 10:10:53	1.1.2.2
  @@ -24,7 +24,7 @@
    * as it needs the current <code>Sitemap</code> as input.
    *
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  - * @version CVS $Revision: 1.1.2.1 $ $Date: 2001/07/04 07:29:43 $
  + * @version CVS $Revision: 1.1.2.2 $ $Date: 2001/07/04 10:10:53 $
    */
   
   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.1.2.2   +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.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- SourceFactory.java	2001/07/04 07:29:51	1.1.2.1
  +++ SourceFactory.java	2001/07/04 10:10:56	1.1.2.2
  @@ -17,18 +17,20 @@
   
   /**
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  - * @version $Id: SourceFactory.java,v 1.1.2.1 2001/07/04 07:29:51 cziegeler Exp $
  + * @version $Id: SourceFactory.java,v 1.1.2.2 2001/07/04 10:10:56 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.1.2.2   +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.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- SourceHandler.java	2001/07/04 07:29:55	1.1.2.1
  +++ SourceHandler.java	2001/07/04 10:10:58	1.1.2.2
  @@ -17,18 +17,20 @@
   
   /**
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  - * @version $Id: SourceHandler.java,v 1.1.2.1 2001/07/04 07:29:55 cziegeler Exp $
  + * @version $Id: SourceHandler.java,v 1.1.2.2 2001/07/04 10:10:58 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;
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.1.1.2.2 +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.1.1.1.2.1
  retrieving revision 1.1.1.1.2.2
  diff -u -r1.1.1.1.2.1 -r1.1.1.1.2.2
  --- HttpContext.java	2001/06/22 14:11:50	1.1.1.1.2.1
  +++ HttpContext.java	2001/07/04 10:11:10	1.1.1.1.2.2
  @@ -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) {
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.9.2.8   +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.9.2.7
  retrieving revision 1.9.2.8
  diff -u -r1.9.2.7 -r1.9.2.8
  --- Handler.java	2001/07/04 07:27:13	1.9.2.7
  +++ Handler.java	2001/07/04 10:11:18	1.9.2.8
  @@ -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:cziegeler@apache.org">Carsten Ziegeler</a>
    * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  - * @version CVS $Revision: 1.9.2.7 $ $Date: 2001/07/04 07:27:13 $
  + * @version CVS $Revision: 1.9.2.8 $ $Date: 2001/07/04 10:11:18 $
    */
   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.2.2.6   +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.2.2.5
  retrieving revision 1.2.2.6
  diff -u -r1.2.2.5 -r1.2.2.6
  --- Manager.java	2001/07/04 07:27:17	1.2.2.5
  +++ Manager.java	2001/07/04 10:11:21	1.2.2.6
  @@ -33,7 +33,7 @@
    * checking regeneration of the sub <code>Sitemap</code>
    *
    * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
  - * @version CVS $Revision: 1.2.2.5 $ $Date: 2001/07/04 07:27:17 $
  + * @version CVS $Revision: 1.2.2.6 $ $Date: 2001/07/04 10:11:21 $
    */
   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:     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