cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From giac...@locus.apache.org
Subject cvs commit: xml-cocoon/src/org/apache/cocoon/sitemap AbstractSitemap.java ResourcePipeline.java Sitemap.java SitemapHandler.java SitemapManager.java
Date Thu, 27 Jul 2000 21:49:07 GMT
giacomo     00/07/27 14:49:06

  Modified:    src/org/apache/cocoon Tag: xml-cocoon2 Cocoon.java
                        Processor.java
               src/org/apache/cocoon/components/language/generator Tag:
                        xml-cocoon2 ProgramGenerator.java
                        ProgramGeneratorImpl.java
               src/org/apache/cocoon/components/language/markup Tag:
                        xml-cocoon2 AbstractMarkupLanguage.java
                        MarkupLanguage.java
               src/org/apache/cocoon/components/language/markup/sitemap/java
                        Tag: xml-cocoon2 sitemap.xsl
               src/org/apache/cocoon/components/language/markup/xsp Tag:
                        xml-cocoon2 XSPRequestHelper.java
                        XSPResponseHelper.java
               src/org/apache/cocoon/components/language/markup/xsp/java
                        Tag: xml-cocoon2 request.xsl response.xsl xsp.xsl
               src/org/apache/cocoon/environment Tag: xml-cocoon2
                        Environment.java
               src/org/apache/cocoon/environment/http Tag: xml-cocoon2
                        HttpEnvironment.java
               src/org/apache/cocoon/generation Tag: xml-cocoon2
                        ComposerGenerator.java DirectoryGenerator.java
                        FileGenerator.java Generator.java PhpGenerator.java
                        ServerPagesGenerator.java
               src/org/apache/cocoon/matching Tag: xml-cocoon2
                        BrowserMatcherFactory.java MatcherFactory.java
                        RegexpURIMatcherFactory.java
                        WildcardURIMatcherFactory.java
               src/org/apache/cocoon/selection Tag: xml-cocoon2
                        BrowserSelectorFactory.java SelectorFactory.java
               src/org/apache/cocoon/sitemap Tag: xml-cocoon2
                        AbstractSitemap.java ResourcePipeline.java
                        Sitemap.java SitemapHandler.java
                        SitemapManager.java
  Log:
  Code adapted to new Environment and Sitemap classes
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.4.2.15  +196 -219  xml-cocoon/src/org/apache/cocoon/Cocoon.java
  
  Index: Cocoon.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Cocoon.java,v
  retrieving revision 1.4.2.14
  retrieving revision 1.4.2.15
  diff -u -r1.4.2.14 -r1.4.2.15
  --- Cocoon.java	2000/07/25 18:48:24	1.4.2.14
  +++ Cocoon.java	2000/07/27 21:48:31	1.4.2.15
  @@ -1,225 +1,202 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -package org.apache.cocoon;
  -
  -import java.io.File;
  -import java.io.FileNotFoundException;
  -import java.io.IOException;
  -import java.io.OutputStream;
  -import java.io.FileReader;
  -import java.net.URL;
  -import java.util.Enumeration;
  -import java.util.Hashtable;
  -
  -import org.apache.avalon.Component;
  -import org.apache.avalon.Composer;
  -import org.apache.avalon.ComponentManager;
  -import org.apache.avalon.ComponentNotFoundException;
  -import org.apache.avalon.ComponentNotAccessibleException;
  -import org.apache.avalon.Modifiable;
  -import org.apache.avalon.Configurable;
  -import org.apache.avalon.Configuration;
  -import org.apache.avalon.ConfigurationException;
  -import org.apache.avalon.SAXConfigurationBuilder;
  -
  -import org.apache.cocoon.components.parser.Parser;
  -import org.apache.cocoon.environment.Environment;
  -import org.apache.cocoon.serialization.Serializer;
  -import org.apache.cocoon.sitemap.SitemapManager;
  -
  -import org.xml.sax.EntityResolver;
  -import org.xml.sax.InputSource;
  -import org.xml.sax.SAXException;
  -
  -/**
  - *
  - * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
  - *         (Apache Software Foundation, Exoffice Technologies)
  - * @version CVS $Revision: 1.4.2.14 $ $Date: 2000/07/25 18:48:24 $
  - */
  -public class Cocoon
  -implements Component, Configurable, ComponentManager, Modifiable, Processor {
  -
  -    /** The table of role-class */
  -    private Hashtable components=new Hashtable();
  -    /** The table of role-configuration */
  -    private Hashtable configurations=new Hashtable();
  +/*****************************************************************************
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  + * ------------------------------------------------------------------------- *
  + * This software is published under the terms of the Apache Software License *
  + * version 1.1, a copy of which has been included  with this distribution in *
  + * the LICENSE file.                                                         *
  + *****************************************************************************/
  +package org.apache.cocoon;
  +
  +import java.io.File;
  +import java.io.FileNotFoundException;
  +import java.io.IOException;
  +import java.io.OutputStream;
  +import java.io.FileReader;
  +import java.net.URL;
  +import java.util.Enumeration;
  +import java.util.Hashtable;
  +
  +import org.apache.avalon.Component;
  +import org.apache.avalon.Composer;
  +import org.apache.avalon.ComponentManager;
  +import org.apache.avalon.ComponentNotFoundException;
  +import org.apache.avalon.ComponentNotAccessibleException;
  +import org.apache.avalon.Modifiable;
  +import org.apache.avalon.Configurable;
  +import org.apache.avalon.Configuration;
  +import org.apache.avalon.ConfigurationException;
  +import org.apache.avalon.SAXConfigurationBuilder;
  +
  +import org.apache.cocoon.components.parser.Parser;
  +import org.apache.cocoon.environment.Environment;
  +import org.apache.cocoon.serialization.Serializer;
  +import org.apache.cocoon.sitemap.SitemapManager;
  +
  +import org.xml.sax.EntityResolver;
  +import org.xml.sax.InputSource;
  +import org.xml.sax.SAXException;
  +
  +/**
  + *
  + * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
  + *         (Apache Software Foundation, Exoffice Technologies)
  + * @version CVS $Revision: 1.4.2.15 $ $Date: 2000/07/27 21:48:31 $
  + */
  +public class Cocoon
  +implements Component, Configurable, ComponentManager, Modifiable, 
  +           Processor {
  +
  +    /** The table of role-class */
  +    private Hashtable components=new Hashtable();
  +    /** The table of role-configuration */
  +    private Hashtable configurations=new Hashtable();
       /** The configuration file */ 
       private File configurationFile=null; 
       /** The sitemap file */ 
       private String sitemapFileName=null; 
  -    /** The configuration tree */
  -    private Configuration configuration=null;
  -    /** The sitemap manager */
  -    private SitemapManager sitemapManager=null;
  -    /** The root uri/path */
  -    private URL root=null;
  -        
  -    /**
  -     * Create a new <code>Cocoon</code> instance.
  -     */
  -    protected Cocoon()
  -    throws ConfigurationException {
  -        super();
  -        // Setup the default parser, for parsing configuration.
  -        // If one need to use a different parser, set the given system property
  -        String parser=null;
  -        parser=System.getProperty("org.apache.cocoon.components.parser.Parser",
  -                            "org.apache.cocoon.components.parser.XercesParser");
  -        this.components.put("parser",this.getClass(parser,null));
  -    }
  -
  -    /**
  -     * Create a new <code>Cocoon</code> object, parsing configuration from
  -     * the specified file.
  -     */
  -    public Cocoon(String configuration)
  -    throws SAXException, IOException, ConfigurationException {
  -        this();
  -        this.configurationFile=new File(configuration).getCanonicalFile();
  -        if (!this.configurationFile.isFile())
  -            throw new FileNotFoundException(configuration);
  -        Parser p=(Parser)this.getComponent("parser");
  -        SAXConfigurationBuilder b=new SAXConfigurationBuilder();
  -        p.setContentHandler(b);
  -        String path = this.configurationFile.getPath();
  -        InputSource is = new InputSource(new FileReader(path));
  -        is.setSystemId(path);
  -        p.parse(is);
  -        this.setConfiguration(b.getConfiguration());
  -        this.root=this.configurationFile.getParentFile().toURL();
  -/*
  -        try {
  -            generateSitemap ("/opt/giacomo/java/CVS/xml-cocoon2/test/xdocs/drafts/sitemap.xmap"); 
  -        } catch (org.apache.cocoon.ProcessingException pe) {
  -            throw new IOException (pe.getMessage());
  -        } */
  -    }
  -
  -    /**
  -     * Set the cocoon root.
  -     * @param root The new Cocoon root.
  -     */
  -    public void setRoot(URL root) {
  -        this.root = root;
  -    }
  - 
  -    /**
  -     * Get the <code>Component</code> associated with the given role.
  -     */
  -    public Component getComponent(String role)
  -    throws ComponentNotFoundException, ComponentNotAccessibleException {
  -        if (role==null) throw new ComponentNotFoundException("Null role");
  -        if (role.equals("cocoon")) return(this);
  -        Class c=(Class)this.components.get(role);
  -        if (c==null)
  -            throw new ComponentNotFoundException("Can't find component "+role);
  -        try {
  -            Component comp=(Component)c.newInstance();
  -            if (comp instanceof Composer)
  -                ((Composer)comp).setComponentManager(this);
  -            if (comp instanceof Configurable) {
  -                Configuration conf=(Configuration)this.configurations.get(role);
  -                if (conf!=null) ((Configurable)comp).setConfiguration(conf);
  -            }
  -            return(comp);
  -        } catch (Exception e) {
  -            throw new ComponentNotAccessibleException("Can't access class "+
  -                        c.getName()+" with role "+role+" due to a "+
  -                        e.getClass().getName()+"("+e.getMessage()+")",e);
  -        }
  -    }
  -
  -    /**
  -     * Configure this <code>Cocoon</code> instance.
  -     */
  -    public void setConfiguration(Configuration conf)
  -     throws ConfigurationException {
  -        this.configuration=conf;
  -        if (!conf.getName().equals("cocoon"))
  -            throw new ConfigurationException("Invalid configuration file",conf);
  -        if (!conf.getAttribute("version").equals("2.0"))
  -            throw new ConfigurationException("Invalid version",conf);
  -        // Set components
  -        Enumeration e=conf.getConfigurations("component");
  -        while (e.hasMoreElements()) {
  -            Configuration co=(Configuration)e.nextElement();
  -            String ro=co.getAttribute("role");
  -            String cl=co.getAttribute("class");
  -            System.out.println("Adding component: "+ro);
  -            this.components.put(ro,this.getClass(cl,co));
  -            this.configurations.put(ro,co);
  -        }
  -        // Create the sitemap
  -        Configuration sconf=conf.getConfiguration("sitemap");
  -        if (sconf==null)
  -            throw new ConfigurationException("No sitemap configuration",conf);
  -        this.sitemapManager=new SitemapManager();
  -        this.sitemapManager.setComponentManager(this);
  -        this.sitemapManager.setConfiguration(conf);
  +    /** The configuration tree */
  +    private Configuration configuration=null;
  +    /** The sitemap manager */
  +    private SitemapManager sitemapManager=null;
  +    /** The root uri/path */
  +    private URL root=null;
  +        
  +    /**
  +     * Create a new <code>Cocoon</code> instance.
  +     */
  +    protected Cocoon()
  +    throws ConfigurationException {
  +        super();
  +        // Setup the default parser, for parsing configuration.
  +        // If one need to use a different parser, set the given system property
  +        String parser=null;
  +        parser=System.getProperty("org.apache.cocoon.components.parser.Parser",
  +                            "org.apache.cocoon.components.parser.XercesParser");
  +        this.components.put("parser",this.getClass(parser,null));
  +    }
  +
  +    /**
  +     * Create a new <code>Cocoon</code> object, parsing configuration from
  +     * the specified file.
  +     */
  +    public Cocoon(String configuration)
  +    throws SAXException, IOException, ConfigurationException {
  +        this();
  +        this.configurationFile=new File(configuration).getCanonicalFile();
  +        if (!this.configurationFile.isFile())
  +            throw new FileNotFoundException(configuration);
  +        Parser p=(Parser)this.getComponent("parser");
  +        SAXConfigurationBuilder b=new SAXConfigurationBuilder();
  +        p.setContentHandler(b);
  +        String path = this.configurationFile.getPath();
  +        InputSource is = new InputSource(new FileReader(path));
  +        is.setSystemId(path);
  +        p.parse(is);
  +        this.setConfiguration(b.getConfiguration());
  +        this.root=this.configurationFile.getParentFile().toURL();
  +    }
  +
  +    /**
  +     * Set the cocoon root.
  +     * @param root The new Cocoon root.
  +     */
  +    public void setRoot(URL root) {
  +        this.root = root;
  +    }
  + 
  +    /**
  +     * Get the <code>Component</code> associated with the given role.
  +     */
  +    public Component getComponent(String role)
  +    throws ComponentNotFoundException, ComponentNotAccessibleException {
  +        if (role==null) throw new ComponentNotFoundException("Null role");
  +        if (role.equals("cocoon")) return (this);
  +        Class c=(Class)this.components.get(role);
  +        if (c==null)
  +            throw new ComponentNotFoundException("Can't find component "+role);
  +        try {
  +            Component comp=(Component)c.newInstance();
  +            if (comp instanceof Composer)
  +                ((Composer)comp).setComponentManager(this);
  +            if (comp instanceof Configurable) {
  +                Configuration conf=(Configuration)this.configurations.get(role);
  +                if (conf!=null) ((Configurable)comp).setConfiguration(conf);
  +            }
  +            return(comp);
  +        } catch (Exception e) {
  +            throw new ComponentNotAccessibleException("Can't access class "+
  +                        c.getName()+" with role "+role+" due to a "+
  +                        e.getClass().getName()+"("+e.getMessage()+")",e);
  +        }
  +    }
  +
  +    /**
  +     * Configure this <code>Cocoon</code> instance.
  +     */
  +    public void setConfiguration(Configuration conf)
  +     throws ConfigurationException {
  +        this.configuration=conf;
  +        if (!conf.getName().equals("cocoon"))
  +            throw new ConfigurationException("Invalid configuration file",conf);
  +        if (!conf.getAttribute("version").equals("2.0"))
  +            throw new ConfigurationException("Invalid version",conf);
  +        // Set components
  +        Enumeration e=conf.getConfigurations("component");
  +        while (e.hasMoreElements()) {
  +            Configuration co=(Configuration)e.nextElement();
  +            String ro=co.getAttribute("role");
  +            String cl=co.getAttribute("class");
  +            System.out.println("Adding component: "+ro);
  +            this.components.put(ro,this.getClass(cl,co));
  +            this.configurations.put(ro,co);
  +        }
  +        // Create the sitemap
  +        Configuration sconf=conf.getConfiguration("sitemap");
  +        if (sconf==null)
  +            throw new ConfigurationException("No sitemap configuration",conf);
  +        this.sitemapManager=new SitemapManager();
  +        this.sitemapManager.setComponentManager(this);
  +        this.sitemapManager.setConfiguration(conf);
           this.sitemapFileName = sconf.getAttribute("file");
           System.out.println("The root sitemap is located at \""+this.sitemapFileName+"\"");
  -    }
  -
  -    /**
  -     * Queries the class to estimate its ergodic period termination.
  -     */
  -    public boolean modifiedSince(long date) {
  -        return(date<this.configurationFile.lastModified());
  -    }
  -
  -    /**
  -     * Process the given <code>Environment</code> producing the output to the
  -     * specified <code>OutputStream</code>.
  -     */
  -    public boolean process(Environment environment, OutputStream out) 
  -    throws SAXException, IOException, ProcessingException, 
  -           InterruptedException  {
  -        return (this.sitemapManager.invoke (environment, "",
  -                                    this.sitemapFileName, true, out));
  -    }
  -
  -    /**
  -     * Resolve an entity.
  -     */
  -    private InputSource resolveEntityXXX(String systemId)
  -    throws SAXException, IOException {
  -        return(this.resolveEntityXXX(null,systemId));
  -    }
  -
  -    /**
  -     * Resolve an entity.
  -     */
  -    private InputSource resolveEntityXXX(String publicId, String systemId)
  -    throws SAXException, IOException {
  -        System.out.println ("Cocoon.resolveEntity(\""+publicId+"\",\""+systemId+"\")");
  -        if (systemId==null) throw new SAXException("Invalid System ID");
  -
  -        if (systemId.length()==0)
  -            return new InputSource(this.root.toExternalForm());
  -        if (systemId.indexOf(":/")>0)
  -            return new InputSource(systemId);
  -        if (systemId.charAt(0)=='/')
  -            return new InputSource(this.root.getProtocol()+":"+systemId);
  -        return(new InputSource(new URL(this.root,systemId).toExternalForm()));
  -    }
  -
  -    /** Get a new class */
  -    private Class getClass(String className, Configuration conf)
  -    throws ConfigurationException {
  -        // This is better than Class.forName() because components should be
  -        // loaded by the same classloader that loaded Cocoon (they should
  -        // be in the same jar file, or directory.
  -        try {
  -            return(this.getClass().getClassLoader().loadClass(className));
  -        } catch (ClassNotFoundException e) {
  -            throw new ConfigurationException("Cannot load class "+className,
  -                conf);
  -        }
  -    }
  -}
  +    }
  +
  +    /**
  +     * Queries the class to estimate its ergodic period termination.
  +     */
  +    public boolean modifiedSince(long date) {
  +        return(date<this.configurationFile.lastModified() 
  +            || sitemapManager.hasChanged());
  +    }
  +
  +    /**
  +     * Process the given <code>Environment</code> producing the output to the
  +     * specified <code>OutputStream</code>.
  +     */
  +    public boolean process(Environment environment, OutputStream out) 
  +    throws Exception  {
  +        String s = environment.resolveEntity(this.sitemapFileName).getSystemId();
  +        if (s.startsWith("file:")) {
  +            if (s.startsWith("file://")) 
  +                s = s.substring(7);
  +            else
  +                s = s.substring(5);
  +        }
  +        return this.sitemapManager.invoke (environment, "",
  +                          s, true, out);
  +    }
  +
  +    /** Get a new class */
  +    private Class getClass(String className, Configuration conf)
  +    throws ConfigurationException {
  +        // This is better than Class.forName() because components should be
  +        // loaded by the same classloader that loaded Cocoon (they should
  +        // be in the same jar file, or directory.
  +        try {
  +            return(this.getClass().getClassLoader().loadClass(className));
  +        } catch (ClassNotFoundException e) {
  +            throw new ConfigurationException("Cannot load class "+className,
  +                conf);
  +        }
  +    }
  +}
  
  
  
  1.1.2.5   +30 -30    xml-cocoon/src/org/apache/cocoon/Attic/Processor.java
  
  Index: Processor.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Attic/Processor.java,v
  retrieving revision 1.1.2.4
  retrieving revision 1.1.2.5
  diff -u -r1.1.2.4 -r1.1.2.5
  --- Processor.java	2000/07/22 20:41:29	1.1.2.4
  +++ Processor.java	2000/07/27 21:48:31	1.1.2.5
  @@ -1,30 +1,30 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -package org.apache.cocoon;
  -
  -import java.io.IOException;
  -import java.io.OutputStream;
  -
  -import org.xml.sax.SAXException;
  -
  -import org.apache.cocoon.environment.Environment;
  -
  -/**
  - *
  - * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
  - *         (Apache Software Foundation, Exoffice Technologies)
  - * @version CVS $Revision: 1.1.2.4 $ $Date: 2000/07/22 20:41:29 $
  - */
  -public interface Processor {
  -    /**
  -     * Process the given <code>Environment</code> producing the output to the
  -     * specified <code>OutputStream</code>.
  -     */
  -    public boolean process(Environment environment, OutputStream out)
  -    throws SAXException, IOException, ProcessingException, InterruptedException;
  -}
  +/*****************************************************************************
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  + * ------------------------------------------------------------------------- *
  + * This software is published under the terms of the Apache Software License *
  + * version 1.1, a copy of which has been included  with this distribution in *
  + * the LICENSE file.                                                         *
  + *****************************************************************************/
  +package org.apache.cocoon;
  +
  +import java.io.IOException;
  +import java.io.OutputStream;
  +
  +import org.xml.sax.SAXException;
  +
  +import org.apache.cocoon.environment.Environment;
  +
  +/**
  + *
  + * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
  + *         (Apache Software Foundation, Exoffice Technologies)
  + * @version CVS $Revision: 1.1.2.5 $ $Date: 2000/07/27 21:48:31 $
  + */
  +public interface Processor {
  +    /**
  +     * Process the given <code>Environment</code> producing the output to the
  +     * specified <code>OutputStream</code>.
  +     */
  +    public boolean process(Environment environment, OutputStream out)
  +    throws Exception;
  +}
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.5   +38 -36    xml-cocoon/src/org/apache/cocoon/components/language/generator/Attic/ProgramGenerator.java
  
  Index: ProgramGenerator.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/components/language/generator/Attic/ProgramGenerator.java,v
  retrieving revision 1.1.2.4
  retrieving revision 1.1.2.5
  diff -u -r1.1.2.4 -r1.1.2.5
  --- ProgramGenerator.java	2000/07/22 20:41:31	1.1.2.4
  +++ ProgramGenerator.java	2000/07/27 21:48:37	1.1.2.5
  @@ -1,36 +1,38 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -package org.apache.cocoon.components.language.generator;
  -
  -import java.io.File;
  -import org.apache.avalon.Component;
  -
  -/**
  - * This interface defines a loader for programs automatically built from XML
  - * documents writeen in a <code>MarkupLanguage</code>
  - *
  - * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
  - * @version CVS $Revision: 1.1.2.4 $ $Date: 2000/07/22 20:41:31 $
  - */
  -public interface ProgramGenerator extends Component {
  -  /**
  -   * Load a program built from an XML document written in a
  -   * <code>MarkupLanguage</code>
  -   *
  -   * @param file The input document's <code>File</code>
  -   * @param markupLanguage The <code>MarkupLanguage</code> in which the input
  -   * document is written
  -   * @param programmingLanguage The <code>ProgrammingLanguage</code> in which
  -   * the program must be written
  -   * @return The loaded object
  -   * @exception Exception If an error occurs during generation or loading
  -   */
  -  public Object load(
  -    File file, String markupLanguage, String programmingLanguage
  -  ) throws Exception;
  -}
  +/*****************************************************************************
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  + * ------------------------------------------------------------------------- *
  + * This software is published under the terms of the Apache Software License *
  + * version 1.1, a copy of which has been included  with this distribution in *
  + * the LICENSE file.                                                         *
  + *****************************************************************************/
  +package org.apache.cocoon.components.language.generator;
  +
  +import java.io.File;
  +import org.apache.avalon.Component;
  +import org.apache.cocoon.environment.Environment;
  +
  +/**
  + * This interface defines a loader for programs automatically built from XML
  + * documents writeen in a <code>MarkupLanguage</code>
  + *
  + * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
  + * @version CVS $Revision: 1.1.2.5 $ $Date: 2000/07/27 21:48:37 $
  + */
  +public interface ProgramGenerator extends Component {
  +  /**
  +   * Load a program built from an XML document written in a
  +   * <code>MarkupLanguage</code>
  +   *
  +   * @param file The input document's <code>File</code>
  +   * @param markupLanguage The <code>MarkupLanguage</code> in which the input
  +   * document is written
  +   * @param programmingLanguage The <code>ProgrammingLanguage</code> in which
  +   * the program must be written
  +   * @return The loaded object
  +   * @exception Exception If an error occurs during generation or loading
  +   */
  +  public Object load(
  +    File file, String markupLanguage, String programmingLanguage,
  +    Environment environment
  +  ) throws Exception;
  +}
  
  
  
  1.1.2.6   +222 -220  xml-cocoon/src/org/apache/cocoon/components/language/generator/Attic/ProgramGeneratorImpl.java
  
  Index: ProgramGeneratorImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/components/language/generator/Attic/ProgramGeneratorImpl.java,v
  retrieving revision 1.1.2.5
  retrieving revision 1.1.2.6
  diff -u -r1.1.2.5 -r1.1.2.6
  --- ProgramGeneratorImpl.java	2000/07/22 20:41:31	1.1.2.5
  +++ ProgramGeneratorImpl.java	2000/07/27 21:48:37	1.1.2.6
  @@ -1,220 +1,222 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -package org.apache.cocoon.components.language.generator;
  -
  -import java.io.File;
  -import java.io.FileReader;
  -
  -import org.apache.avalon.Modifiable;
  -
  -import org.apache.avalon.Composer;
  -import org.apache.avalon.ComponentManager;
  -import org.apache.avalon.Configurable;
  -import org.apache.avalon.Configuration;
  -import org.apache.avalon.ConfigurationException;
  -import org.apache.avalon.NamedComponentManager;
  -
  -import org.apache.avalon.utils.Parameters;
  -
  -import org.apache.cocoon.components.store.MemoryStore;
  -import org.apache.cocoon.components.store.FilesystemStore;
  -
  -
  -import org.apache.cocoon.components.language.LanguageException;
  -import org.apache.cocoon.components.language.markup.MarkupLanguage;
  -import org.apache.cocoon.components.language.programming.CodeFormatter;
  -import org.apache.cocoon.components.language.programming.ProgrammingLanguage;
  -
  -import org.apache.cocoon.util.IOUtils;
  -import org.apache.cocoon.util.DOMUtils;
  -
  -import org.w3c.dom.Document;
  -import org.w3c.dom.Document;
  -
  -
  -import org.xml.sax.InputSource;
  -import org.apache.avalon.Component;
  -
  -import java.io.IOException;
  -import org.xml.sax.SAXException;
  -import java.io.FileNotFoundException;
  -
  -/**
  - * The default implementation of <code>ProgramGenerator</code>
  - *
  - * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
  - * @version CVS $Revision: 1.1.2.5 $ $Date: 2000/07/22 20:41:31 $
  - */
  -public class ProgramGeneratorImpl
  -  implements ProgramGenerator, Composer, Configurable
  -{
  -  /** The in-memory store */
  -  protected MemoryStore cache = new MemoryStore();
  -
  -  /** The filesystem-based store */
  -  protected String repositoryName;
  -
  -  /** The component manager */
  -  protected ComponentManager manager;
  -
  -  /** The named component manager */
  -  protected NamedComponentManager factory;
  -
  -  /** The auto-reloading option */
  -  protected boolean autoReload = true;
  -
  -  /**
  -   * Set the global component manager. This method also sets the
  -   * <code>NamedComponentManager</code> used as language factory for both
  -   * markup and programming languages.
  -   *
  -   * @param manager The global component manager
  -   */
  -  public void setComponentManager(ComponentManager manager) {
  -    this.manager = manager;
  -
  -    this.factory =
  -      (NamedComponentManager) this.manager.getComponent("factory");
  -  }
  -
  -  /**
  -   * Set the sitemap-provided configuration. This method sets the persistent
  -   * code repository and the auto-reload option
  -   *
  -   * @param conf The configuration information
  -   * @exception ConfigurationException Not thrown here
  -   */
  -  public void setConfiguration(Configuration conf)
  -    throws ConfigurationException
  -  {
  -    Parameters params = Parameters.fromConfiguration(conf);
  -
  -    this.repositoryName = params.getParameter("repository", "./repository");
  -    this.autoReload = params.getParameterAsBoolean("auto-reload", true);
  -  }
  -
  -  /**
  -   * Load a program built from an XML document written in a
  -   * <code>MarkupLanguage</code>
  -   *
  -   * @param file The input document's <code>File</code>
  -   * @param markupLanguage The <code>MarkupLanguage</code> in which the input
  -   * document is written
  -   * @param programmingLanguage The <code>ProgrammingLanguage</code> in which
  -   * the program must be written
  -   * @return The loaded program instance
  -   * @exception Exception If an error occurs during generation or loading
  -   */
  -  public Object load(
  -    File file, String markupLanguageName, String programmingLanguageName
  -  ) throws Exception {
  -    // Get markup and programming languages
  -    MarkupLanguage markupLanguage = (MarkupLanguage)
  -      this.factory.getComponent("markup-language", markupLanguageName);
  -
  -    ProgrammingLanguage programmingLanguage = (ProgrammingLanguage)
  -      this.factory.getComponent("programming-language", programmingLanguageName);
  -
  -    // Create filesystem store
  -    FilesystemStore repository = new FilesystemStore(this.repositoryName);
  -
  -    // Set filenames
  -    String filename = IOUtils.getFullFilename(file);
  -    String normalizedName = repository.normalizedFilename(filename);
  -    String sourceExtension = programmingLanguage.getSourceExtension();
  -
  -    // Ensure no 2 requests for the same file overlap
  -    Object program = null;
  -    Object programInstance = null;
  -
  -    synchronized(filename.intern()) {
  -      // Attempt to load program object from cache
  -      program = this.cache.get(filename);
  -  
  -      try {
  -        if (program == null) {
  -          /*
  -	     FIXME: Passing null as encoding may result in invalid
  -	     recompilation under certain circumstances!
  -	  */
  -          program = programmingLanguage.load(
  -            normalizedName, this.repositoryName, null
  -          );
  -  
  -          // Store loaded program in cache
  -          this.cache.store(filename, program);
  -	}
  -
  -	// Instantiate program
  -        programInstance = programmingLanguage.instantiate(program);
  -      } catch (LanguageException e) { }
  -      
  -      /*
  -         FIXME: It's the program (not the instance) that must
  -	 be queried for changes!!!
  -      */
  -      if (
  -	  this.autoReload &&
  -          programInstance != null &&
  -	  programInstance instanceof Modifiable &&
  -	  ((Modifiable) programInstance).modifiedSince(file.lastModified())
  -      )
  -      {
  -        // Unload program
  -        programmingLanguage.unload(
  -	  program, normalizedName, this.repositoryName
  -        );
  -  
  -        // Invalidate previous program/instance pair
  -        program = null;
  -	programInstance = null;
  -      }
  -  
  -      if (program == null) {
  -        // Generate code
  -        Document document =
  -	  DOMUtils.DOMParse(new InputSource(new FileReader(file)));
  -        String encoding = markupLanguage.getEncoding(document);
  -        String code = markupLanguage.generateCode(
  -          document, normalizedName, programmingLanguage
  -        );
  -  
  -	// Format source code if applicable
  -	CodeFormatter codeFormatter = programmingLanguage.getCodeFormatter();
  -	if (codeFormatter != null) {
  -	  code = codeFormatter.format(code, encoding);
  -	}
  -  
  -        // Store generated code
  -        String sourceFilename = filename + "." + sourceExtension;
  -        repository.store(sourceFilename, code);
  -  
  -        // Verify source file generation was successful
  -        File sourceFile = (File) repository.get(sourceFilename);
  -        if (sourceFile == null) {
  -          throw new IOException(
  -	    "Error creating source file: " + sourceFilename
  -	  );
  -        }
  -  
  -        // [Compile]/Load generated program
  -        program = programmingLanguage.load(
  -	  normalizedName, this.repositoryName, encoding
  -	);
  -
  -        // Store generated program in cache
  -        this.cache.store(filename, program);
  -      }
  -
  -      // Instantiate
  -      programInstance = programmingLanguage.instantiate(program);
  -    }
  -
  -    return programInstance;
  -  }
  -}
  +/*****************************************************************************
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  + * ------------------------------------------------------------------------- *
  + * This software is published under the terms of the Apache Software License *
  + * version 1.1, a copy of which has been included  with this distribution in *
  + * the LICENSE file.                                                         *
  + *****************************************************************************/
  +package org.apache.cocoon.components.language.generator;
  +
  +import java.io.File;
  +import java.io.FileReader;
  +
  +import org.apache.avalon.Modifiable;
  +
  +import org.apache.avalon.Composer;
  +import org.apache.avalon.ComponentManager;
  +import org.apache.avalon.Configurable;
  +import org.apache.avalon.Configuration;
  +import org.apache.avalon.ConfigurationException;
  +import org.apache.avalon.NamedComponentManager;
  +
  +import org.apache.avalon.utils.Parameters;
  +
  +import org.apache.cocoon.environment.Environment;
  +
  +import org.apache.cocoon.components.store.MemoryStore;
  +import org.apache.cocoon.components.store.FilesystemStore;
  +
  +import org.apache.cocoon.components.language.LanguageException;
  +import org.apache.cocoon.components.language.markup.MarkupLanguage;
  +import org.apache.cocoon.components.language.programming.CodeFormatter;
  +import org.apache.cocoon.components.language.programming.ProgrammingLanguage;
  +
  +import org.apache.cocoon.util.IOUtils;
  +import org.apache.cocoon.util.DOMUtils;
  +
  +import org.w3c.dom.Document;
  +import org.w3c.dom.Document;
  +
  +
  +import org.xml.sax.InputSource;
  +import org.apache.avalon.Component;
  +
  +import java.io.IOException;
  +import org.xml.sax.SAXException;
  +import java.io.FileNotFoundException;
  +
  +/**
  + * The default implementation of <code>ProgramGenerator</code>
  + *
  + * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
  + * @version CVS $Revision: 1.1.2.6 $ $Date: 2000/07/27 21:48:37 $
  + */
  +public class ProgramGeneratorImpl
  +  implements ProgramGenerator, Composer, Configurable
  +{
  +  /** The in-memory store */
  +  protected MemoryStore cache = new MemoryStore();
  +
  +  /** The filesystem-based store */
  +  protected String repositoryName;
  +
  +  /** The component manager */
  +  protected ComponentManager manager;
  +
  +  /** The named component manager */
  +  protected NamedComponentManager factory;
  +
  +  /** The auto-reloading option */
  +  protected boolean autoReload = true;
  +
  +  /**
  +   * Set the global component manager. This method also sets the
  +   * <code>NamedComponentManager</code> used as language factory for both
  +   * markup and programming languages.
  +   *
  +   * @param manager The global component manager
  +   */
  +  public void setComponentManager(ComponentManager manager) {
  +    this.manager = manager;
  +
  +    this.factory =
  +      (NamedComponentManager) this.manager.getComponent("factory");
  +  }
  +
  +  /**
  +   * Set the sitemap-provided configuration. This method sets the persistent
  +   * code repository and the auto-reload option
  +   *
  +   * @param conf The configuration information
  +   * @exception ConfigurationException Not thrown here
  +   */
  +  public void setConfiguration(Configuration conf)
  +    throws ConfigurationException
  +  {
  +    Parameters params = Parameters.fromConfiguration(conf);
  +
  +    this.repositoryName = params.getParameter("repository", "./repository");
  +    this.autoReload = params.getParameterAsBoolean("auto-reload", true);
  +  }
  +
  +  /**
  +   * Load a program built from an XML document written in a
  +   * <code>MarkupLanguage</code>
  +   *
  +   * @param file The input document's <code>File</code>
  +   * @param markupLanguage The <code>MarkupLanguage</code> in which the input
  +   * document is written
  +   * @param programmingLanguage The <code>ProgrammingLanguage</code> in which
  +   * the program must be written
  +   * @return The loaded program instance
  +   * @exception Exception If an error occurs during generation or loading
  +   */
  +  public Object load(
  +    File file, String markupLanguageName, String programmingLanguageName,
  +    Environment environment
  +  ) throws Exception {
  +    // Get markup and programming languages
  +    MarkupLanguage markupLanguage = (MarkupLanguage)
  +      this.factory.getComponent("markup-language", markupLanguageName);
  +
  +    ProgrammingLanguage programmingLanguage = (ProgrammingLanguage)
  +      this.factory.getComponent("programming-language", programmingLanguageName);
  +
  +    // Create filesystem store
  +    FilesystemStore repository = new FilesystemStore(this.repositoryName);
  +
  +    // Set filenames
  +    String filename = IOUtils.getFullFilename(file);
  +    String normalizedName = repository.normalizedFilename(filename);
  +    String sourceExtension = programmingLanguage.getSourceExtension();
  +
  +    // Ensure no 2 requests for the same file overlap
  +    Object program = null;
  +    Object programInstance = null;
  +
  +    synchronized(filename.intern()) {
  +      // Attempt to load program object from cache
  +      program = this.cache.get(filename);
  +  
  +      try {
  +        if (program == null) {
  +          /*
  +	     FIXME: Passing null as encoding may result in invalid
  +	     recompilation under certain circumstances!
  +	  */
  +          program = programmingLanguage.load(
  +            normalizedName, this.repositoryName, null
  +          );
  +  
  +          // Store loaded program in cache
  +          this.cache.store(filename, program);
  +	}
  +
  +	// Instantiate program
  +        programInstance = programmingLanguage.instantiate(program);
  +      } catch (LanguageException e) { }
  +      
  +      /*
  +         FIXME: It's the program (not the instance) that must
  +	 be queried for changes!!!
  +      */
  +      if (
  +	  this.autoReload &&
  +          programInstance != null &&
  +	  programInstance instanceof Modifiable &&
  +	  ((Modifiable) programInstance).modifiedSince(file.lastModified())
  +      )
  +      {
  +        // Unload program
  +        programmingLanguage.unload(
  +	  program, normalizedName, this.repositoryName
  +        );
  +  
  +        // Invalidate previous program/instance pair
  +        program = null;
  +	programInstance = null;
  +      }
  +  
  +      if (program == null) {
  +        // Generate code
  +        Document document =
  +	  DOMUtils.DOMParse(new InputSource(new FileReader(file)));
  +        String encoding = markupLanguage.getEncoding(document);
  +        String code = markupLanguage.generateCode(
  +          document, normalizedName, programmingLanguage, environment
  +        );
  +  
  +	// Format source code if applicable
  +	CodeFormatter codeFormatter = programmingLanguage.getCodeFormatter();
  +	if (codeFormatter != null) {
  +	  code = codeFormatter.format(code, encoding);
  +	}
  +  
  +        // Store generated code
  +        String sourceFilename = filename + "." + sourceExtension;
  +        repository.store(sourceFilename, code);
  +  
  +        // Verify source file generation was successful
  +        File sourceFile = (File) repository.get(sourceFilename);
  +        if (sourceFile == null) {
  +          throw new IOException(
  +	    "Error creating source file: " + sourceFilename
  +	  );
  +        }
  +  
  +        // [Compile]/Load generated program
  +        program = programmingLanguage.load(
  +	  normalizedName, this.repositoryName, encoding
  +	);
  +
  +        // Store generated program in cache
  +        this.cache.store(filename, program);
  +      }
  +
  +      // Instantiate
  +      programInstance = programmingLanguage.instantiate(program);
  +    }
  +
  +    return programInstance;
  +  }
  +}
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.4   +530 -527  xml-cocoon/src/org/apache/cocoon/components/language/markup/Attic/AbstractMarkupLanguage.java
  
  Index: AbstractMarkupLanguage.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/components/language/markup/Attic/AbstractMarkupLanguage.java,v
  retrieving revision 1.1.2.3
  retrieving revision 1.1.2.4
  diff -u -r1.1.2.3 -r1.1.2.4
  --- AbstractMarkupLanguage.java	2000/07/22 20:41:32	1.1.2.3
  +++ AbstractMarkupLanguage.java	2000/07/27 21:48:40	1.1.2.4
  @@ -1,527 +1,530 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -package org.apache.cocoon.components.language.markup;
  -
  -import java.io.File;
  -import java.net.URL;
  -import java.util.Date;
  -import java.util.Vector;
  -import java.util.Hashtable;
  -import java.util.Enumeration;
  -
  -import org.w3c.dom.Attr;
  -import org.w3c.dom.Document;
  -import org.w3c.dom.Element;
  -import org.w3c.dom.NodeList;
  -import org.w3c.dom.NamedNodeMap;
  -
  -import org.xml.sax.InputSource;
  -import org.xml.sax.EntityResolver;
  -
  -import org.apache.avalon.Composer;
  -import org.apache.avalon.Component;
  -import org.apache.avalon.ComponentManager;
  -
  -import org.apache.avalon.utils.Parameters;
  -import org.apache.avalon.AbstractNamedComponent;
  -
  -import org.apache.avalon.Configuration;
  -import org.apache.avalon.ConfigurationException;
  -
  -import org.apache.cocoon.util.IOUtils;
  -import org.apache.cocoon.components.store.MemoryStore;
  -
  -import org.apache.cocoon.components.language.programming.ProgrammingLanguage;
  -
  -import java.io.IOException;
  -import org.xml.sax.SAXException;
  -import java.net.MalformedURLException;
  -
  -/**
  - * Base implementation of <code>MarkupLanguage</code>. This class uses
  - * logicsheets as the only means of code generation. Code generation should
  - * be decoupled from this context!!! Moreover, this class uses DOM documents
  - * (as opposed to Cocoon2's standard SAX events)
  - *
  - * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
  - * @version CVS $Revision: 1.1.2.3 $ $Date: 2000/07/22 20:41:32 $
  - */
  -public abstract class AbstractMarkupLanguage
  -  extends AbstractNamedComponent
  -  implements MarkupLanguage, Composer
  -{
  -  /**
  -   * The supported language table
  -   */
  -  protected Hashtable languages;
  -
  -  /**
  -   * The in-memory code-generation logicsheet cache
  -   */
  -  protected MemoryStore logicsheetCache;
  -
  -  /**
  -   * The markup language's namespace uri
  -   */
  -  protected String uri;
  -
  -  /**
  -   * The markup language's namespace prefix
  -   */
  -  protected String prefix;
  -
  -  /** The component manager */
  -  protected ComponentManager manager;
  -
  -  /**
  -   * Set the global component manager.
  -   *
  -   * @param manager The sitemap-specified component manager
  -   */
  -  public void setComponentManager(ComponentManager manager) {
  -    this.manager = manager;
  -  }
  -
  -  /**
  -   * The defualt constructor.
  -   */
  -  public AbstractMarkupLanguage() throws SAXException, IOException {
  -    // Initialize language table
  -    this.languages = new Hashtable();
  -
  -    // Initialize logicsheet cache
  -    this.logicsheetCache = new MemoryStore();
  -  }
  -
  -  /**
  -   * Initialize the (required) markup language namespace definition.
  -   *
  -   * @param params The sitemap-supplied parameters
  -   * @exception Exception Not actually thrown
  -   */
  -  protected void setParameters(Parameters params) throws Exception
  -  {
  -    this.uri = getRequiredParameter(params, "uri");
  -    this.prefix = getRequiredParameter(params, "prefix");
  -  }
  -
  -  /**
  -   * Process additional configuration. Load supported programming language
  -   * definitions
  -   *
  -   * @param conf The language configuration
  -   * @exception ConfigurationException If an error occurs loading logichseets
  -   */
  -  protected void setAdditionalConfiguration(Configuration conf)
  -    throws ConfigurationException
  -  {
  -    try {
  -      Enumeration l = conf.getConfigurations("target-language");
  -      while (l.hasMoreElements()) {
  -        Configuration lc = (Configuration) l.nextElement();
  -
  -        LanguageDescriptor language = new LanguageDescriptor();
  -        language.setName(lc.getAttribute("name"));
  -
  -	Parameters lcp = Parameters.fromConfiguration(lc);
  -        String logicsheetLocation =
  -	  getRequiredParameter(lcp, "core-logicsheet");
  -
  -        URL logicsheetURL = IOUtils.getURL(logicsheetLocation);
  -        String logicsheetName = logicsheetURL.toExternalForm();
  -        Logicsheet logicsheet = new Logicsheet();
  -        logicsheet.setInputSource(new InputSource(logicsheetURL.openStream()));
  -        CachedURL entry = new CachedURL(logicsheetURL, logicsheet);
  -        this.logicsheetCache.store(logicsheetName, entry);
  -        language.setLogicsheet(logicsheetName);
  -
  -        Enumeration n = lc.getConfigurations("builtin-logicsheet");
  -        while (n.hasMoreElements()) {
  -          Configuration nc = (Configuration) n.nextElement();
  -	  Parameters ncp = Parameters.fromConfiguration(nc);
  -
  -          String namedLogicsheetPrefix = getRequiredParameter(ncp, "prefix");
  -          String namedLogicsheetUri = getRequiredParameter(ncp, "uri");
  -          String namedLogicsheetLocation = getRequiredParameter(ncp, "href");
  -
  -          // FIXME: This is repetitive; add method for both cases
  -          URL namedLogicsheetURL = IOUtils.getURL(namedLogicsheetLocation);
  -          String namedLogicsheetName = namedLogicsheetURL.toExternalForm();
  -          NamedLogicsheet namedLogicsheet = new NamedLogicsheet();
  -          namedLogicsheet.setInputSource(
  -            new InputSource(namedLogicsheetURL.openStream())
  -          );
  -          namedLogicsheet.setPrefix(namedLogicsheetPrefix);
  -          namedLogicsheet.setUri(namedLogicsheetUri);
  -          CachedURL namedEntry =
  -            new CachedURL(namedLogicsheetURL, namedLogicsheet);
  -          this.logicsheetCache.store(namedLogicsheetName, namedEntry);
  -          language.addNamedLogicsheet(
  -            namedLogicsheetPrefix, namedLogicsheetName
  -          );
  -        }
  -
  -        this.languages.put(language.getName(), language);
  -      }
  -    } catch (Exception e) {
  -e.printStackTrace();
  -      throw new ConfigurationException(e.getMessage(), conf);
  -    }
  -  }
  -
  -  /**
  -   * Return the source document's encoding. This can be <code>null</code> for
  -   * the platform's default encoding. The default implementation returns
  -   * <code>null, but derived classes may override it if encoding applies to
  -   * their concrete languages. FIXME: There should be a way to get the
  -   * XML document's encoding as seen by the parser; unfortunately, this
  -   * information is not returned by current DOM or SAX parsers...
  -   *
  -   * @param document The input document
  -   * @return The document-specified encoding
  -   */
  -  public String getEncoding(Document document) {
  -    return null;
  -  }
  -
  -  /**
  -   * Prepare the document for logicsheet processing and code generation. The
  -   * default implementation does nothing, but derived classes should (at least)
  -   * use the passed programming language to quote <code>Strings</code>
  -   *
  -   * @param document The input document
  -   * @param filename The input source filename
  -   * @param language The target programming language
  -   * @return The augmented document
  -   */
  -  protected Document preprocessDocument(
  -    Document document, String filename, ProgrammingLanguage language
  -  )
  -  {
  -    return document;
  -  }
  -
  -  /**
  -   * Returns a list of logicsheets to be applied to this document for source
  -   * code generation.
  -   *
  -   * @param document The input document
  -   * @return An array of logicsheet <i>names</i>
  -   */
  -  protected abstract String[] getLogicsheets(Document document);
  -
  -  /**
  -   * Add a dependency on an external file to the document for inclusion in
  -   * generated code. This is used by <code>AbstractServerPagesGenerator</code>
  -   * to populate a list of <code>File</code>'s tested for change on each
  -   * invocation; this information, in turn, is used by
  -   * <code>ServerPagesLoaderImpl</code> to assert whether regeneration is
  -   * necessary.
  -   *
  -   * @param PARAM_NAME Param description
  -   * @return the value
  -   * @exception EXCEPTION_NAME If an error occurs
  -   * @see ServerPages <code>AbstractServerPagesGenerator</code>
  -   *      and <code>ServerPagesLoaderImpl</code>
  -   */
  -  protected abstract void addDependency(Document document, String location);
  -
  -  /**
  -   * Generate source code from the input document for the target
  -   * <code>ProgrammingLanguage</code>. After preprocessing the input document,
  -   * this method applies logicsheets in the following order:
  -   * <ul>
  -   *   <li>User-defined logicsheets</li>
  -   *   <li>Namespace-mapped logicsheets</li>
  -   *   <li>Language-specific logicsheet</li>
  -   * </ul>
  -   *
  -   * @param document The input document
  -   * @param filename The input document's original filename
  -   * @param programmingLanguage The target programming language
  -   * @return The generated source code
  -   * @exception Exception If an error occurs during code generation
  -   */
  -  public String generateCode(
  -    Document document, String filename, ProgrammingLanguage programmingLanguage
  -  ) throws Exception {
  -    String languageName = programmingLanguage.getName();
  -
  -    LanguageDescriptor language =
  -      (LanguageDescriptor) this.languages.get(languageName);
  -
  -    if (language == null) {
  -      throw new IllegalArgumentException(
  -        "Unsupported programming language: " + languageName
  -      );
  -    }
  -
  -    // Preprocess document as needed
  -    document = this.preprocessDocument(document, filename, programmingLanguage);
  -
  -    // Create code generator
  -    LogicsheetCodeGenerator codeGenerator = new LogicsheetCodeGenerator(); 
  -
  -    // Add user-defined logicsheets
  -    String[] logicsheetNames = this.getLogicsheets(document);
  -    for (int i = 0; i < logicsheetNames.length; i++) {
  -      this.addLogicsheet(codeGenerator, logicsheetNames[i], document);
  -    }
  -
  -    // Add namespace-mapped logicsheets
  -    Element root = document.getDocumentElement();
  -    NamedNodeMap attrs = root.getAttributes();
  -    int attrCount = attrs.getLength();
  -    for (int i = 0; i < attrCount; i++) {
  -      Attr attr = (Attr) attrs.item(i);
  -      String name = attr.getName();
  -
  -      if (name.startsWith("xmlns:")) {
  -        String prefix = name.substring(6);
  -        String namedLogicsheetName = language.getNamedLogicsheet(prefix);
  -
  -        if (namedLogicsheetName != null) {
  -          this.addLogicsheet(codeGenerator, namedLogicsheetName, document);
  -        }
  -      }
  -    }
  -
  -    // Add language-specific logicsheet (always last!)
  -    this.addLogicsheet(codeGenerator, language.getLogicsheet(), document);
  -
  -    return codeGenerator.generateCode(document, filename);
  -  }
  -
  -  /**
  -   * Add a logicsheet to the code generator.
  -   *
  -   * @param codeGenerator The code generator
  -   * @param logicsheetLocation Location of the logicsheet to be added
  -   * @param document The input document
  -   * @exception MalformedURLException If location is invalid
  -   * @exception IOException IO Error
  -   * @exception SAXException Logicsheet parse error
  -   */
  -  protected void addLogicsheet(
  -    LogicsheetCodeGenerator codeGenerator,
  -    String logicsheetLocation,
  -    Document document
  -  ) throws MalformedURLException, IOException, SAXException
  -  {
  -    String systemId = null;
  -    InputSource inputSource = null;
  -
  -    if (logicsheetLocation.indexOf(":/") < 0) { // Relative to Cocoon root
  -      EntityResolver entityResolver =
  -        (EntityResolver) this.manager.getComponent("cocoon");
  -      inputSource = entityResolver.resolveEntity(null, logicsheetLocation);
  -      systemId = inputSource.getSystemId();
  -    } else { // Fully resolved URL
  -      systemId = logicsheetLocation;
  -      inputSource = new InputSource(systemId);
  -    }
  -
  -    URL url = new URL(systemId);
  -    String logicsheetName = url.toExternalForm();
  -    CachedURL entry = (CachedURL) this.logicsheetCache.get(logicsheetName);
  -
  -    Logicsheet logicsheet = null;
  -
  -    if (entry == null) {
  -      logicsheet = new Logicsheet();
  -      logicsheet.setInputSource(inputSource);
  -      entry = new CachedURL(url, logicsheet);
  -      this.logicsheetCache.store(logicsheetName, entry);
  -    }
  -
  -    logicsheet = entry.getLogicsheet();
  -
  -    if (entry.hasChanged()) {
  -      logicsheet.setInputSource(inputSource);
  -    }
  -
  -    if (entry.isFile()) {
  -      this.addDependency(document, IOUtils.getFullFilename(entry.getFile()));
  -    }
  -
  -    codeGenerator.addLogicsheet(logicsheet);
  -  }
  -
  -  // Inner classes
  -
  -  /**
  -   * This class holds transient information about a target programming
  -   * language.
  -   *
  -   */
  -  protected class LanguageDescriptor {
  -    /**
  -     * The progamming language name
  -     */
  -    protected String name;
  -
  -    /**
  -     * The progamming language core logicsheet
  -     */
  -    protected String logicsheet;
  -
  -    /**
  -     * The list of built-in logicsheets defined for this target language
  -     */
  -    protected Hashtable namedLogicsheets;
  -
  -    /**
  -     * The default constructor
  -     */
  -    protected LanguageDescriptor() {
  -      this.namedLogicsheets = new Hashtable();
  -    }
  -
  -    /**
  -     * Set the programming language's name
  -     *
  -     * @param name The programming language's name
  -     */
  -    protected void setName(String name) {
  -      this.name = name;
  -    }
  -
  -    /**
  -     * Return the programming language's name
  -     *
  -     * @return The programming language's name
  -     */
  -    protected String getName() {
  -      return this.name;
  -    }
  -
  -    /**
  -     * Set the programming language's core logichseet location
  -     *
  -     * @param logicsheet The programming language's core logichseet location
  -     */
  -    protected void setLogicsheet(String logicsheet) {
  -      this.logicsheet = logicsheet;
  -    }
  -
  -    /**
  -     * Return the programming language's core logichseet location
  -     *
  -     * @return The programming language's core logichseet location
  -     */
  -    protected String getLogicsheet() {
  -      return this.logicsheet;
  -    }
  -
  -    /**
  -     * Add a namespace-mapped logicsheet to this language
  -     *
  -     * @param prefix The logichseet's namespace prefix
  -     * @param uri The logichseet's namespace uri
  -     * @param namedLogicsheet The logichseet's location
  -     */
  -    protected void addNamedLogicsheet(String prefix, String namedLogicsheet) {
  -      this.namedLogicsheets.put(
  -        prefix,
  -        namedLogicsheet
  -      );
  -    }
  -
  -    /**
  -     * Return a namespace-mapped logicsheet given its name
  -     *
  -     * @return The namespace-mapped logicsheet
  -     */
  -    protected String getNamedLogicsheet(String prefix) {
  -      return (String) this.namedLogicsheets.get(prefix);
  -    }
  -  }
  -
  -  /**
  -   * This class holds a cached URL entry associated with a logicsheet
  -   *
  -   */
  -  protected class CachedURL {
  -    /**
  -     * The logicsheet URL
  -     */
  -    protected URL url;
  -    /**
  -     * The logicsheet's <code>File</code> if it's actually a file.
  -     * This is used to provide last modification information not
  -     * otherwise available for URL's in Java :-(
  -     */
  -    protected File file;
  -    /**
  -     * The cached logicsheet 
  -     */
  -    protected Logicsheet logicsheet;
  -    /**
  -     * The las time this logicsheet was changed/loaded
  -     */
  -    protected long lastModified;
  -
  -    /**
  -     * The constructor.
  -     */
  -    protected CachedURL(URL url, Logicsheet logicsheet) throws IOException {
  -      this.url = url;
  -      this.logicsheet = logicsheet;
  -
  -      if (this.isFile()) {
  -        this.file = new File(url.getFile());
  -      }
  -
  -      this.lastModified = (new Date()).getTime();
  -    }
  -
  -    /**
  -     * Return this entry's URL
  -     *
  -     * @return The cached logicsheet's URL
  -     */
  -    protected URL getURL() {
  -      return this.url;
  -    }
  -
  -    protected boolean isFile() {
  -      return this.url.getProtocol().equals("file");
  -    }
  -
  -    /**
  -     * Return this entry's <code>File</code>
  -     *
  -     * @return The cached logicsheet's <code>File</code>
  -     */
  -    protected File getFile() {
  -      return this.file;
  -    }
  -
  -    /**
  -     * Return this entry's cached logicsheet
  -     *
  -     * @return The cached logicsheet
  -     */
  -    protected Logicsheet getLogicsheet() {
  -      return this.logicsheet;
  -    }
  -
  -    /**
  -     * Assert whether this entry's logicsheet should be reloaded
  -     *
  -     * @return Whether the cached logicsheet has changed
  -     */
  -    protected boolean hasChanged() {
  -      if (this.file == null) {
  -        return false;
  -      }
  -
  -      return this.lastModified < this.file.lastModified();
  -    }
  -  }
  -}
  +/*****************************************************************************
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  + * ------------------------------------------------------------------------- *
  + * This software is published under the terms of the Apache Software License *
  + * version 1.1, a copy of which has been included  with this distribution in *
  + * the LICENSE file.                                                         *
  + *****************************************************************************/
  +package org.apache.cocoon.components.language.markup;
  +
  +import java.io.File;
  +import java.net.URL;
  +import java.util.Date;
  +import java.util.Vector;
  +import java.util.Hashtable;
  +import java.util.Enumeration;
  +
  +import org.w3c.dom.Attr;
  +import org.w3c.dom.Document;
  +import org.w3c.dom.Element;
  +import org.w3c.dom.NodeList;
  +import org.w3c.dom.NamedNodeMap;
  +
  +import org.xml.sax.InputSource;
  +import org.xml.sax.EntityResolver;
  +
  +import org.apache.avalon.Composer;
  +import org.apache.avalon.Component;
  +import org.apache.avalon.ComponentManager;
  +
  +import org.apache.avalon.utils.Parameters;
  +import org.apache.avalon.AbstractNamedComponent;
  +
  +import org.apache.avalon.Configuration;
  +import org.apache.avalon.ConfigurationException;
  +
  +import org.apache.cocoon.util.IOUtils;
  +import org.apache.cocoon.components.store.MemoryStore;
  +import org.apache.cocoon.environment.Environment;
  +
  +import org.apache.cocoon.components.language.programming.ProgrammingLanguage;
  +
  +import java.io.IOException;
  +import org.xml.sax.SAXException;
  +import java.net.MalformedURLException;
  +
  +/**
  + * Base implementation of <code>MarkupLanguage</code>. This class uses
  + * logicsheets as the only means of code generation. Code generation should
  + * be decoupled from this context!!! Moreover, this class uses DOM documents
  + * (as opposed to Cocoon2's standard SAX events)
  + *
  + * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
  + * @version CVS $Revision: 1.1.2.4 $ $Date: 2000/07/27 21:48:40 $
  + */
  +public abstract class AbstractMarkupLanguage
  +  extends AbstractNamedComponent
  +  implements MarkupLanguage, Composer
  +{
  +  /**
  +   * The supported language table
  +   */
  +  protected Hashtable languages;
  +
  +  /**
  +   * The in-memory code-generation logicsheet cache
  +   */
  +  protected MemoryStore logicsheetCache;
  +
  +  /**
  +   * The markup language's namespace uri
  +   */
  +  protected String uri;
  +
  +  /**
  +   * The markup language's namespace prefix
  +   */
  +  protected String prefix;
  +
  +  /** The component manager */
  +  protected ComponentManager manager;
  +
  +  /**
  +   * Set the global component manager.
  +   *
  +   * @param manager The sitemap-specified component manager
  +   */
  +  public void setComponentManager(ComponentManager manager) {
  +    this.manager = manager;
  +  }
  +
  +  /**
  +   * The defualt constructor.
  +   */
  +  public AbstractMarkupLanguage() throws SAXException, IOException {
  +    // Initialize language table
  +    this.languages = new Hashtable();
  +
  +    // Initialize logicsheet cache
  +    this.logicsheetCache = new MemoryStore();
  +  }
  +
  +  /**
  +   * Initialize the (required) markup language namespace definition.
  +   *
  +   * @param params The sitemap-supplied parameters
  +   * @exception Exception Not actually thrown
  +   */
  +  protected void setParameters(Parameters params) throws Exception
  +  {
  +    this.uri = getRequiredParameter(params, "uri");
  +    this.prefix = getRequiredParameter(params, "prefix");
  +  }
  +
  +  /**
  +   * Process additional configuration. Load supported programming language
  +   * definitions
  +   *
  +   * @param conf The language configuration
  +   * @exception ConfigurationException If an error occurs loading logichseets
  +   */
  +  protected void setAdditionalConfiguration(Configuration conf)
  +    throws ConfigurationException
  +  {
  +    try {
  +      Enumeration l = conf.getConfigurations("target-language");
  +      while (l.hasMoreElements()) {
  +        Configuration lc = (Configuration) l.nextElement();
  +
  +        LanguageDescriptor language = new LanguageDescriptor();
  +        language.setName(lc.getAttribute("name"));
  +
  +	Parameters lcp = Parameters.fromConfiguration(lc);
  +        String logicsheetLocation =
  +	  getRequiredParameter(lcp, "core-logicsheet");
  +
  +        URL logicsheetURL = IOUtils.getURL(logicsheetLocation);
  +        String logicsheetName = logicsheetURL.toExternalForm();
  +        Logicsheet logicsheet = new Logicsheet();
  +        logicsheet.setInputSource(new InputSource(logicsheetURL.openStream()));
  +        CachedURL entry = new CachedURL(logicsheetURL, logicsheet);
  +        this.logicsheetCache.store(logicsheetName, entry);
  +        language.setLogicsheet(logicsheetName);
  +
  +        Enumeration n = lc.getConfigurations("builtin-logicsheet");
  +        while (n.hasMoreElements()) {
  +          Configuration nc = (Configuration) n.nextElement();
  +	  Parameters ncp = Parameters.fromConfiguration(nc);
  +
  +          String namedLogicsheetPrefix = getRequiredParameter(ncp, "prefix");
  +          String namedLogicsheetUri = getRequiredParameter(ncp, "uri");
  +          String namedLogicsheetLocation = getRequiredParameter(ncp, "href");
  +
  +          // FIXME: This is repetitive; add method for both cases
  +          URL namedLogicsheetURL = IOUtils.getURL(namedLogicsheetLocation);
  +          String namedLogicsheetName = namedLogicsheetURL.toExternalForm();
  +          NamedLogicsheet namedLogicsheet = new NamedLogicsheet();
  +          namedLogicsheet.setInputSource(
  +            new InputSource(namedLogicsheetURL.openStream())
  +          );
  +          namedLogicsheet.setPrefix(namedLogicsheetPrefix);
  +          namedLogicsheet.setUri(namedLogicsheetUri);
  +          CachedURL namedEntry =
  +            new CachedURL(namedLogicsheetURL, namedLogicsheet);
  +          this.logicsheetCache.store(namedLogicsheetName, namedEntry);
  +          language.addNamedLogicsheet(
  +            namedLogicsheetPrefix, namedLogicsheetName
  +          );
  +        }
  +
  +        this.languages.put(language.getName(), language);
  +      }
  +    } catch (Exception e) {
  +e.printStackTrace();
  +      throw new ConfigurationException(e.getMessage(), conf);
  +    }
  +  }
  +
  +  /**
  +   * Return the source document's encoding. This can be <code>null</code> for
  +   * the platform's default encoding. The default implementation returns
  +   * <code>null, but derived classes may override it if encoding applies to
  +   * their concrete languages. FIXME: There should be a way to get the
  +   * XML document's encoding as seen by the parser; unfortunately, this
  +   * information is not returned by current DOM or SAX parsers...
  +   *
  +   * @param document The input document
  +   * @return The document-specified encoding
  +   */
  +  public String getEncoding(Document document) {
  +    return null;
  +  }
  +
  +  /**
  +   * Prepare the document for logicsheet processing and code generation. The
  +   * default implementation does nothing, but derived classes should (at least)
  +   * use the passed programming language to quote <code>Strings</code>
  +   *
  +   * @param document The input document
  +   * @param filename The input source filename
  +   * @param language The target programming language
  +   * @return The augmented document
  +   */
  +  protected Document preprocessDocument(
  +    Document document, String filename, ProgrammingLanguage language
  +  )
  +  {
  +    return document;
  +  }
  +
  +  /**
  +   * Returns a list of logicsheets to be applied to this document for source
  +   * code generation.
  +   *
  +   * @param document The input document
  +   * @return An array of logicsheet <i>names</i>
  +   */
  +  protected abstract String[] getLogicsheets(Document document);
  +
  +  /**
  +   * Add a dependency on an external file to the document for inclusion in
  +   * generated code. This is used by <code>AbstractServerPagesGenerator</code>
  +   * to populate a list of <code>File</code>'s tested for change on each
  +   * invocation; this information, in turn, is used by
  +   * <code>ServerPagesLoaderImpl</code> to assert whether regeneration is
  +   * necessary.
  +   *
  +   * @param PARAM_NAME Param description
  +   * @return the value
  +   * @exception EXCEPTION_NAME If an error occurs
  +   * @see ServerPages <code>AbstractServerPagesGenerator</code>
  +   *      and <code>ServerPagesLoaderImpl</code>
  +   */
  +  protected abstract void addDependency(Document document, String location);
  +
  +  /**
  +   * Generate source code from the input document for the target
  +   * <code>ProgrammingLanguage</code>. After preprocessing the input document,
  +   * this method applies logicsheets in the following order:
  +   * <ul>
  +   *   <li>User-defined logicsheets</li>
  +   *   <li>Namespace-mapped logicsheets</li>
  +   *   <li>Language-specific logicsheet</li>
  +   * </ul>
  +   *
  +   * @param document The input document
  +   * @param filename The input document's original filename
  +   * @param programmingLanguage The target programming language
  +   * @return The generated source code
  +   * @exception Exception If an error occurs during code generation
  +   */
  +  public String generateCode(
  +    Document document, String filename, ProgrammingLanguage programmingLanguage,
  +    Environment environment
  +  ) throws Exception {
  +    String languageName = programmingLanguage.getName();
  +
  +    LanguageDescriptor language =
  +      (LanguageDescriptor) this.languages.get(languageName);
  +
  +    if (language == null) {
  +      throw new IllegalArgumentException(
  +        "Unsupported programming language: " + languageName
  +      );
  +    }
  +
  +    // Preprocess document as needed
  +    document = this.preprocessDocument(document, filename, programmingLanguage);
  +
  +    // Create code generator
  +    LogicsheetCodeGenerator codeGenerator = new LogicsheetCodeGenerator(); 
  +
  +    // Add user-defined logicsheets
  +    String[] logicsheetNames = this.getLogicsheets(document);
  +    for (int i = 0; i < logicsheetNames.length; i++) {
  +      this.addLogicsheet(codeGenerator, logicsheetNames[i], document, environment);
  +    }
  +
  +    // Add namespace-mapped logicsheets
  +    Element root = document.getDocumentElement();
  +    NamedNodeMap attrs = root.getAttributes();
  +    int attrCount = attrs.getLength();
  +    for (int i = 0; i < attrCount; i++) {
  +      Attr attr = (Attr) attrs.item(i);
  +      String name = attr.getName();
  +
  +      if (name.startsWith("xmlns:")) {
  +        String prefix = name.substring(6);
  +        String namedLogicsheetName = language.getNamedLogicsheet(prefix);
  +
  +        if (namedLogicsheetName != null) {
  +          this.addLogicsheet(codeGenerator, namedLogicsheetName, document, environment);
  +        }
  +      }
  +    }
  +
  +    // Add language-specific logicsheet (always last!)
  +    this.addLogicsheet(codeGenerator, language.getLogicsheet(), document, environment);
  +
  +    return codeGenerator.generateCode(document, filename);
  +  }
  +
  +  /**
  +   * Add a logicsheet to the code generator.
  +   *
  +   * @param codeGenerator The code generator
  +   * @param logicsheetLocation Location of the logicsheet to be added
  +   * @param document The input document
  +   * @exception MalformedURLException If location is invalid
  +   * @exception IOException IO Error
  +   * @exception SAXException Logicsheet parse error
  +   */
  +  protected void addLogicsheet(
  +    LogicsheetCodeGenerator codeGenerator,
  +    String logicsheetLocation,
  +    Document document,
  +    Environment environemnt
  +  ) throws MalformedURLException, IOException, SAXException
  +  {
  +    String systemId = null;
  +    InputSource inputSource = null;
  +
  +    if (logicsheetLocation.indexOf(":/") < 0) { // Relative to Cocoon root
  +      EntityResolver entityResolver =
  +        (EntityResolver) this.manager.getComponent("cocoon");
  +      inputSource = entityResolver.resolveEntity(null, logicsheetLocation);
  +      systemId = inputSource.getSystemId();
  +    } else { // Fully resolved URL
  +      systemId = logicsheetLocation;
  +      inputSource = new InputSource(systemId);
  +    }
  +
  +    URL url = new URL(systemId);
  +    String logicsheetName = url.toExternalForm();
  +    CachedURL entry = (CachedURL) this.logicsheetCache.get(logicsheetName);
  +
  +    Logicsheet logicsheet = null;
  +
  +    if (entry == null) {
  +      logicsheet = new Logicsheet();
  +      logicsheet.setInputSource(inputSource);
  +      entry = new CachedURL(url, logicsheet);
  +      this.logicsheetCache.store(logicsheetName, entry);
  +    }
  +
  +    logicsheet = entry.getLogicsheet();
  +
  +    if (entry.hasChanged()) {
  +      logicsheet.setInputSource(inputSource);
  +    }
  +
  +    if (entry.isFile()) {
  +      this.addDependency(document, IOUtils.getFullFilename(entry.getFile()));
  +    }
  +
  +    codeGenerator.addLogicsheet(logicsheet);
  +  }
  +
  +  // Inner classes
  +
  +  /**
  +   * This class holds transient information about a target programming
  +   * language.
  +   *
  +   */
  +  protected class LanguageDescriptor {
  +    /**
  +     * The progamming language name
  +     */
  +    protected String name;
  +
  +    /**
  +     * The progamming language core logicsheet
  +     */
  +    protected String logicsheet;
  +
  +    /**
  +     * The list of built-in logicsheets defined for this target language
  +     */
  +    protected Hashtable namedLogicsheets;
  +
  +    /**
  +     * The default constructor
  +     */
  +    protected LanguageDescriptor() {
  +      this.namedLogicsheets = new Hashtable();
  +    }
  +
  +    /**
  +     * Set the programming language's name
  +     *
  +     * @param name The programming language's name
  +     */
  +    protected void setName(String name) {
  +      this.name = name;
  +    }
  +
  +    /**
  +     * Return the programming language's name
  +     *
  +     * @return The programming language's name
  +     */
  +    protected String getName() {
  +      return this.name;
  +    }
  +
  +    /**
  +     * Set the programming language's core logichseet location
  +     *
  +     * @param logicsheet The programming language's core logichseet location
  +     */
  +    protected void setLogicsheet(String logicsheet) {
  +      this.logicsheet = logicsheet;
  +    }
  +
  +    /**
  +     * Return the programming language's core logichseet location
  +     *
  +     * @return The programming language's core logichseet location
  +     */
  +    protected String getLogicsheet() {
  +      return this.logicsheet;
  +    }
  +
  +    /**
  +     * Add a namespace-mapped logicsheet to this language
  +     *
  +     * @param prefix The logichseet's namespace prefix
  +     * @param uri The logichseet's namespace uri
  +     * @param namedLogicsheet The logichseet's location
  +     */
  +    protected void addNamedLogicsheet(String prefix, String namedLogicsheet) {
  +      this.namedLogicsheets.put(
  +        prefix,
  +        namedLogicsheet
  +      );
  +    }
  +
  +    /**
  +     * Return a namespace-mapped logicsheet given its name
  +     *
  +     * @return The namespace-mapped logicsheet
  +     */
  +    protected String getNamedLogicsheet(String prefix) {
  +      return (String) this.namedLogicsheets.get(prefix);
  +    }
  +  }
  +
  +  /**
  +   * This class holds a cached URL entry associated with a logicsheet
  +   *
  +   */
  +  protected class CachedURL {
  +    /**
  +     * The logicsheet URL
  +     */
  +    protected URL url;
  +    /**
  +     * The logicsheet's <code>File</code> if it's actually a file.
  +     * This is used to provide last modification information not
  +     * otherwise available for URL's in Java :-(
  +     */
  +    protected File file;
  +    /**
  +     * The cached logicsheet 
  +     */
  +    protected Logicsheet logicsheet;
  +    /**
  +     * The las time this logicsheet was changed/loaded
  +     */
  +    protected long lastModified;
  +
  +    /**
  +     * The constructor.
  +     */
  +    protected CachedURL(URL url, Logicsheet logicsheet) throws IOException {
  +      this.url = url;
  +      this.logicsheet = logicsheet;
  +
  +      if (this.isFile()) {
  +        this.file = new File(url.getFile());
  +      }
  +
  +      this.lastModified = (new Date()).getTime();
  +    }
  +
  +    /**
  +     * Return this entry's URL
  +     *
  +     * @return The cached logicsheet's URL
  +     */
  +    protected URL getURL() {
  +      return this.url;
  +    }
  +
  +    protected boolean isFile() {
  +      return this.url.getProtocol().equals("file");
  +    }
  +
  +    /**
  +     * Return this entry's <code>File</code>
  +     *
  +     * @return The cached logicsheet's <code>File</code>
  +     */
  +    protected File getFile() {
  +      return this.file;
  +    }
  +
  +    /**
  +     * Return this entry's cached logicsheet
  +     *
  +     * @return The cached logicsheet
  +     */
  +    protected Logicsheet getLogicsheet() {
  +      return this.logicsheet;
  +    }
  +
  +    /**
  +     * Assert whether this entry's logicsheet should be reloaded
  +     *
  +     * @return Whether the cached logicsheet has changed
  +     */
  +    protected boolean hasChanged() {
  +      if (this.file == null) {
  +        return false;
  +      }
  +
  +      return this.lastModified < this.file.lastModified();
  +    }
  +  }
  +}
  
  
  
  1.1.2.4   +47 -45    xml-cocoon/src/org/apache/cocoon/components/language/markup/Attic/MarkupLanguage.java
  
  Index: MarkupLanguage.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/components/language/markup/Attic/MarkupLanguage.java,v
  retrieving revision 1.1.2.3
  retrieving revision 1.1.2.4
  diff -u -r1.1.2.3 -r1.1.2.4
  --- MarkupLanguage.java	2000/07/22 20:41:33	1.1.2.3
  +++ MarkupLanguage.java	2000/07/27 21:48:40	1.1.2.4
  @@ -1,45 +1,47 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -package org.apache.cocoon.components.language.markup;
  -
  -import org.w3c.dom.Document;
  -import org.apache.avalon.NamedComponent;
  -
  -import org.apache.cocoon.components.language.programming.ProgrammingLanguage;
  -
  -/**
  - * This interface defines a markup language whose instance documents are to be
  - * translated into an executable program capable or rebuilding the original
  - * document augmenting it with dynamic content
  - *
  - * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
  - * @version CVS $Revision: 1.1.2.3 $ $Date: 2000/07/22 20:41:33 $
  - */
  -public interface MarkupLanguage extends NamedComponent {
  -  /**
  -   * Return the input document's encoding or <code>null</code> if it is the
  -   * platform's default encoding
  -   *
  -   * @return The document's encoding
  -   */
  -  public String getEncoding(Document document);
  -
  -  /**
  -   * Generate source code from the input document for the target
  -   * <code>ProgrammingLanguage</code>.
  -   *
  -   * @param document The input document
  -   * @param filename The input document's original filename
  -   * @param programmingLanguage The target programming language
  -   * @return The generated source code
  -   * @exception Exception If an error occurs during code generation
  -   */
  -  public String generateCode(
  -    Document document, String filename, ProgrammingLanguage programmingLanguage
  -  ) throws Exception;
  -}
  +/*****************************************************************************
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  + * ------------------------------------------------------------------------- *
  + * This software is published under the terms of the Apache Software License *
  + * version 1.1, a copy of which has been included  with this distribution in *
  + * the LICENSE file.                                                         *
  + *****************************************************************************/
  +package org.apache.cocoon.components.language.markup;
  +
  +import org.w3c.dom.Document;
  +import org.apache.avalon.NamedComponent;
  +
  +import org.apache.cocoon.environment.Environment;
  +import org.apache.cocoon.components.language.programming.ProgrammingLanguage;
  +
  +/**
  + * This interface defines a markup language whose instance documents are to be
  + * translated into an executable program capable or rebuilding the original
  + * document augmenting it with dynamic content
  + *
  + * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
  + * @version CVS $Revision: 1.1.2.4 $ $Date: 2000/07/27 21:48:40 $
  + */
  +public interface MarkupLanguage extends NamedComponent {
  +  /**
  +   * Return the input document's encoding or <code>null</code> if it is the
  +   * platform's default encoding
  +   *
  +   * @return The document's encoding
  +   */
  +  public String getEncoding(Document document);
  +
  +  /**
  +   * Generate source code from the input document for the target
  +   * <code>ProgrammingLanguage</code>.
  +   *
  +   * @param document The input document
  +   * @param filename The input document's original filename
  +   * @param programmingLanguage The target programming language
  +   * @return The generated source code
  +   * @exception Exception If an error occurs during code generation
  +   */
  +  public String generateCode(
  +    Document document, String filename, ProgrammingLanguage programmingLanguage,
  +    Environment environment
  +  ) throws Exception;
  +}
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.15  +34 -26    xml-cocoon/src/org/apache/cocoon/components/language/markup/sitemap/java/Attic/sitemap.xsl
  
  Index: sitemap.xsl
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/components/language/markup/sitemap/java/Attic/sitemap.xsl,v
  retrieving revision 1.1.2.14
  retrieving revision 1.1.2.15
  diff -u -r1.1.2.14 -r1.1.2.15
  --- sitemap.xsl	2000/07/25 18:48:25	1.1.2.14
  +++ sitemap.xsl	2000/07/27 21:48:46	1.1.2.15
  @@ -1,17 +1,20 @@
   <?xml version="1.0"?>
   <!-- Sitemap Core logicsheet for the Java language -->
  +<!--
  + * @author &lt;a href="mailto:Giacomo.Pati@pwr.ch"&gt;Giacomo Pati&lt;/a&gt;
  + * @version CVS $Revision: 1.1.2.15 $ $Date: 2000/07/27 21:48:46 $
  +-->
   
  -<xsl:stylesheet version="1.0"
  -  xmlns:map="http://apache.org/cocoon/sitemap/1.0" 
  -  xmlns:java="http://xml.apache.org/xslt/java"
  -  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  ->
  +<xsl:stylesheet 
  +    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  +    xmlns:map="http://apache.org/cocoon/sitemap/1.0" 
  +    xmlns:java="http://xml.apache.org/xslt/java" exclude-result-prefixes="java"
  +    version="1.0">
   
     <xsl:output method="text"/>
   
  -  <xsl:variable name="prefix">map</xsl:variable>
  -  <xsl:variable name="matcher-factory-loader" select="java:org.apache.cocoon.sitemap.XSLTMatcherFactoryLoader.new()"/>
  -  <xsl:variable name="selector-factory-loader" select="java:org.apache.cocoon.sitemap.XSLTSelectorFactoryLoader.new()"/>
  +  <xsl:variable name="prefix">map</xsl:variable> 
  +  <xsl:variable name="factory-loader" select="java:org.apache.cocoon.sitemap.XSLTFactoryLoader.new()"/>
   
     <xsl:template match="/">
       <code xml:space="preserve">
  @@ -49,14 +52,7 @@
   
       import org.xml.sax.SAXException;
       import org.xml.sax.helpers.AttributesImpl;
  -<!--
  -/**
  - *
  - * @author &lt;a href="mailto:Giacomo.Pati@pwr.ch"&gt;Giacomo Pati&lt;/a&gt;
  - * @version CVS $Revision: 1.1.2.14 $ $Date: 2000/07/25 18:48:25 $
  - *
  -/
  --->
  +
   public class <xsl:value-of select="@file-name"/> extends AbstractSitemap {
       static { 
           dateCreated = <xsl:value-of select="@creation-date"/>L; 
  @@ -70,31 +66,37 @@
       /** The generators */
       <xsl:for-each select="/map:sitemap/map:components/map:generators/map:generator">
         private Generator generator_<xsl:value-of select="translate(./@name, '- ', '__')"/> = null;
  +      private Configuration generator_config_<xsl:value-of select="translate(./@name, '- ', '__')"/> = null;
       </xsl:for-each>
       
       /** The transformers */
       <xsl:for-each select="/map:sitemap/map:components/map:transformers/map:transformer">
         private Transformer transformer_<xsl:value-of select="translate(./@name, '- ', '__')"/> = null;
  +      private Configuration transformer_config_<xsl:value-of select="translate(./@name, '- ', '__')"/> = null;
       </xsl:for-each>
       
       /** The readers */
       <xsl:for-each select="/map:sitemap/map:components/map:readers/map:reader">
         private Reader reader_<xsl:value-of select="translate(./@name, '- ', '__')"/> = null;
  +      private Configuration reader_config_<xsl:value-of select="translate(./@name, '- ', '__')"/> = null;
       </xsl:for-each>
       
       /** The serializers */
       <xsl:for-each select="/map:sitemap/map:components/map:serializers/map:serializer">
         private Serializer serializer_<xsl:value-of select="translate(./@name, '- ', '__')"/> = null;
  +      private Configuration serializer_config_<xsl:value-of select="translate(./@name, '- ', '__')"/> = null;
       </xsl:for-each>
       
       /** The matchers */
       <xsl:for-each select="/map:sitemap/map:components/map:matchers/map:matcher[@src]">
         private Matcher matcher_<xsl:value-of select="translate(./@name, '- ', '__')"/> = null;
  +      private Configuration matcher_config_<xsl:value-of select="translate(./@name, '- ', '__')"/> = null;
       </xsl:for-each>
         
       /** The selectors */  
       <xsl:for-each select="/map:sitemap/map:components/map:selectors/map:selector[@src]">
         private Selector selector_<xsl:value-of select="translate(./@name, '- ', '__')"/> = null;
  +      private Configuration selector_config_<xsl:value-of select="translate(./@name, '- ', '__')"/> = null;
       </xsl:for-each>
         
       /** The generated matchers */
  @@ -106,9 +108,9 @@
         <xsl:for-each select="/map:sitemap/map:pipelines/map:pipeline/descendant-or-self::map:match[@type=$type or (not(@type) and $default!='')]">
           <xsl:variable name="matcher-name1" select="translate(@pattern,'/- *?@:{}()[].#^\\$|&#33;','_')"/>
           <xsl:variable name="matcher-name">matcher_<xsl:value-of select='translate($matcher-name1,"&#39;","")'/></xsl:variable>
  -        <xsl:value-of select="java:getSource($matcher-factory-loader, string('class'), string($factory), string($matcher-name), string(@pattern), $config)"/>
  +        <xsl:value-of select="java:getClassSource($factory-loader,string($factory),string($matcher-name),string(@pattern),$config)"/>
           private List <xsl:value-of select="$matcher-name"/> (String pattern, Environment environment) {
  -          <xsl:value-of select="java:getSource($matcher-factory-loader, string('method'), string($factory), string($matcher-name), string(@pattern), $config)"/>
  +          <xsl:value-of select="java:getMethodSource($factory-loader,string($factory),string($matcher-name),string(@pattern),$config)"/>
           }
         </xsl:for-each>
       </xsl:for-each>
  @@ -122,9 +124,9 @@
         <xsl:for-each select="/map:sitemap/map:pipelines/map:pipeline/descendant-or-self::map:when[../map:select/@type=$type or (not(../map:select/@type) and $default!='')]">
           <xsl:variable name="selector-name1" select="translate(@test,'/- *?@:{}()[].#^\\$|&#33;','_')"/>
           <xsl:variable name="selector-name">selector_<xsl:value-of select='translate($selector-name1,"&#39;","")'/></xsl:variable>
  -        <xsl:value-of select="java:getSource($selector-factory-loader, string('class'), string($factory), string($selector-name), string(@test), $config)"/>
  +        <xsl:value-of select="java:getClassSource($factory-loader,string($factory),string($selector-name),string(@pattern),$config)"/>
           private boolean <xsl:value-of select="$selector-name"/> (String test, Environment environment) {
  -          <xsl:value-of select="java:getSource($selector-factory-loader, string('method'), string($factory), string($selector-name), string(@test), $config)"/>
  +          <xsl:value-of select="java:getMethodSource($factory-loader,string($factory),string($selector-name),string(@pattern),$config)"/>
           }
         </xsl:for-each>
       </xsl:for-each>
  @@ -143,7 +145,7 @@
         this.sitemapManager = new SitemapManager();
         this.sitemapManager.setComponentManager(this.manager);
         this.sitemapManager.setConfiguration(conf);
  -
     try {
  +      try {
         <!-- configure all components -->
         /* Configure generators */
         <xsl:call-template name="config-components">
  @@ -200,7 +202,7 @@
       <xsl:for-each select="/map:sitemap/map:resources/map:resource">
         private boolean resource_<xsl:value-of select="translate(@name, '- ', '__')"/> (ResourcePipeline pipeline, 
             List listOfLists, Environment environment, OutputStream out) 
  -      throws SAXException, IOException, ProcessingException { 
  +      throws Exception { 
           List list = null;
           Parameters param = null; 
           <xsl:apply-templates select="./*"/>
  @@ -211,8 +213,9 @@
        * Process to producing the output to the specified &gt;code&lt;OutputStream&gt;/code&lt;. 
        */ 
       public boolean process(Environment environment, OutputStream out)  
  -    throws SAXException, IOException, ProcessingException { 
  +    throws Exception { 
         ResourcePipeline pipeline = new ResourcePipeline ();
  +      pipeline.setComponentManager (this.manager);
         List listOfLists = (List)(new ArrayList());
         List list = null;
         Parameters param = null; 
  @@ -226,7 +229,8 @@
                e.printStackTrace(System.out);
               </xsl:when>
               <xsl:otherwise>
  -              pipeline.setGenerator (generator_error_handler, e.getMessage(), emptyParam);
  +              
  +              pipeline.setGenerator (generator_error_handler, e.getMessage(), null, emptyParam);
                 <xsl:apply-templates select="./map:handle-error/*"/>
                 return pipeline.process (environment, out);
               </xsl:otherwise>
  @@ -427,6 +431,7 @@
         </xsl:call-template>
         confBuilder.endDocument ();
         cconf = confBuilder.getConfiguration();
  +      <xsl:value-of select="$name"/>_config_<xsl:value-of select="translate(@name, '- ', '__')"/> = cconf;
         <xsl:value-of select="$name"/>_<xsl:value-of select="translate(@name, '- ', '__')"/> = 
           (<xsl:value-of select="$interface"/>)load_component ("<xsl:value-of select="@src"/>", 
               cconf);
  @@ -517,11 +522,14 @@
       <xsl:choose> 
         <xsl:when test="$component-source='null'"> 
           pipeline.<xsl:value-of select="$method"/> (<xsl:value-of select="$prefix"/>_<xsl:value-of select="$component-type"/>, 
  -            null, <xsl:value-of select="$component-param"/>); 
  +            null, <xsl:value-of select="$prefix"/>_config_<xsl:value-of select="$component-type"/>,
  +            <xsl:value-of select="$component-param"/>); 
         </xsl:when> 
         <xsl:otherwise> 
           pipeline.<xsl:value-of select="$method"/> (<xsl:value-of select="$prefix"/>_<xsl:value-of select="$component-type"/>,  
  -            substitute(listOfLists,"<xsl:value-of select="$component-source"/>"), <xsl:value-of select="$component-param"/>); 
  +            substitute(listOfLists,"<xsl:value-of select="$component-source"/>"), 
  +            <xsl:value-of select="$prefix"/>_config_<xsl:value-of select="$component-type"/>,
  +            <xsl:value-of select="$component-param"/>); 
         </xsl:otherwise> 
       </xsl:choose> 
     </xsl:template>
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.3   +222 -222  xml-cocoon/src/org/apache/cocoon/components/language/markup/xsp/Attic/XSPRequestHelper.java
  
  Index: XSPRequestHelper.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/components/language/markup/xsp/Attic/XSPRequestHelper.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- XSPRequestHelper.java	2000/07/22 20:41:37	1.1.2.2
  +++ XSPRequestHelper.java	2000/07/27 21:48:49	1.1.2.3
  @@ -1,222 +1,222 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -package org.apache.cocoon.components.language.markup.xsp;
  -
  -import java.util.Enumeration;
  -
  -import org.apache.cocoon.Request;
  -
  -import org.xml.sax.ContentHandler;
  -import org.xml.sax.helpers.AttributesImpl;
  -
  -import org.xml.sax.SAXException;
  -
  -/**
  - * The XSP <code>Request</code> object helper
  - *
  - * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
  - * @version CVS $Revision: 1.1.2.2 $ $Date: 2000/07/22 20:41:37 $
  - */
  -public class XSPRequestHelper extends XSPObjectHelper {
  -  /**
  -   * Assign values to the object's namespace uri and prefix
  -   */
  -  static {
  -    URI = XSP_REQUEST_URI;
  -    PREFIX = XSP_REQUEST_PREFIX;
  -  }
  -
  -  /**
  -   * Output the uri associated with the given <code>Request</code>
  -   *
  -   * @param request The Cocoon request
  -   * @param contentHandler The SAX content handler
  -   * @exception SAXException If a SAX error occurs
  -   */
  -  public static void getUri(
  -    Request request,
  -    ContentHandler contentHandler
  -  )
  -    throws SAXException
  -  {
  -    elementData(contentHandler, "uri", request.getUri());
  -  }
  -
  -  /**
  -   * Return the given request parameter value or a user-provided default if
  -   * none was specified.
  -   *
  -   * @param request The Cocoon request
  -   * @param name The parameter name
  -   * @param defaultValue Value to substitute in absence of a parameter value
  -   */
  -  public static String getParameter(
  -    Request request,
  -    String name,
  -    String defaultValue
  -  ) {
  -    String value = request.getParameter(name);
  -
  -    if (value == null) {
  -      value = defaultValue;
  -    }
  -
  -    return value;
  -  }
  -
  -  /**
  -   * Output the given request parameter value or a user-provided default if
  -   * none was specified.
  -   *
  -   * @param request The Cocoon request
  -   * @param contentHandler The SAX content handler
  -   * @param name The parameter name
  -   * @param defaultValue Value to substitute in absence of a parameter value
  -   * @exception SAXException If a SAX error occurs
  -   */
  -  public static void getParameter(
  -    Request request,
  -    ContentHandler contentHandler,
  -    String name,
  -    String defaultValue
  -  )
  -    throws SAXException
  -  {
  -    AttributesImpl attr = new AttributesImpl();
  -    addAttribute(attr, "name", name);
  -
  -    elementData(
  -      contentHandler,
  -      "parameter",
  -      getParameter(request, name, defaultValue),
  -      attr
  -    );
  -  }
  -
  -  /**
  -   * Output the request parameter values for a given name
  -   *
  -   * @param request The Cocoon request
  -   * @param contentHandler The SAX content handler
  -   * @exception SAXException If a SAX error occurs
  -   */
  -  public static void getParameterValues(
  -    Request request,
  -    ContentHandler contentHandler,
  -    String name
  -  )
  -    throws SAXException
  -  {
  -    AttributesImpl attr = new AttributesImpl();
  -    addAttribute(attr, "name", name);
  -
  -    start(contentHandler, "parameter-values", attr);
  -
  -    String[] values = request.getParameterValues(name);
  -
  -    if (values != null) {
  -      for (int i = 0; i < values.length; i++) {
  -        elementData(contentHandler, "value", values[i]);
  -      }
  -    }
  -
  -    end(contentHandler, "parameter-values");
  -  }
  -
  -  /**
  -   * Output parameter names for a given request
  -   *
  -   * @param request The Cocoon request
  -   * @param contentHandler The SAX content handler
  -   * @exception SAXException If a SAX error occurs
  -   */
  -  public static void getParameterNames(
  -    Request request,
  -    ContentHandler contentHandler
  -  )
  -    throws SAXException
  -  {
  -    start(contentHandler, "parameter-names");
  -
  -    Enumeration e = request.getParameterNames();
  -    while (e.hasMoreElements()) {
  -      String name = (String) e.nextElement();
  -      elementData(contentHandler, "name", name);
  -    }
  -
  -    end(contentHandler, "parameter-names");
  -  }
  -
  -  /**
  -   * Return the request header value for a given name
  -   *
  -   * @param request The Cocoon request
  -   * @param name The parameter name
  -   */
  -  public static String getHeader(
  -    Request request,
  -    String name
  -  ) {
  -    return request.getHeader(name);
  -  }
  -
  -  /**
  -   * Output the request header value for a given name
  -   *
  -   * @param request The Cocoon request
  -   * @param contentHandler The SAX content handler
  -   * @param name The parameter name
  -   * @exception SAXException If a SAX error occurs
  -   */
  -  public static void getHeader(
  -    Request request,
  -    ContentHandler contentHandler,
  -    String name
  -  )
  -    throws SAXException
  -  {
  -    AttributesImpl attr = new AttributesImpl();
  -    addAttribute(attr, "name", name);
  -
  -    String value = getHeader(request, name);
  -    if (value == null) {
  -      value = "";
  -    }
  -
  -    elementData(
  -      contentHandler,
  -      "header",
  -      value,
  -      attr
  -    );
  -  }
  -
  -  /**
  -   * Output the header names for a given request
  -   *
  -   * @param request The Cocoon request
  -   * @param contentHandler The SAX content handler
  -   * @exception SAXException If a SAX error occurs
  -   */
  -  public static void getHeaderNames(
  -    Request request,
  -    ContentHandler contentHandler
  -  )
  -    throws SAXException
  -  {
  -    start(contentHandler, "header-names");
  -
  -    Enumeration e = request.getHeaderNames();
  -    while (e.hasMoreElements()) {
  -      String name = (String) e.nextElement();
  -      elementData(contentHandler, "name", name);
  -    }
  -
  -    end(contentHandler, "header-names");
  -  }
  -}
  +/*****************************************************************************
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  + * ------------------------------------------------------------------------- *
  + * This software is published under the terms of the Apache Software License *
  + * version 1.1, a copy of which has been included  with this distribution in *
  + * the LICENSE file.                                                         *
  + *****************************************************************************/
  +package org.apache.cocoon.components.language.markup.xsp;
  +
  +import java.util.Enumeration;
  +
  +import org.apache.cocoon.environment.http.HttpRequest;
  +
  +import org.xml.sax.ContentHandler;
  +import org.xml.sax.helpers.AttributesImpl;
  +
  +import org.xml.sax.SAXException;
  +
  +/**
  + * The XSP <code>HttpRequest</code> object helper
  + *
  + * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
  + * @version CVS $Revision: 1.1.2.3 $ $Date: 2000/07/27 21:48:49 $
  + */
  +public class XSPRequestHelper extends XSPObjectHelper {
  +  /**
  +   * Assign values to the object's namespace uri and prefix
  +   */
  +  static {
  +    URI = XSP_REQUEST_URI;
  +    PREFIX = XSP_REQUEST_PREFIX;
  +  }
  +
  +  /**
  +   * Output the uri associated with the given <code>HttpRequest</code>
  +   *
  +   * @param request The Cocoon request
  +   * @param contentHandler The SAX content handler
  +   * @exception SAXException If a SAX error occurs
  +   */
  +  public static void getUri(
  +    HttpRequest request,
  +    ContentHandler contentHandler
  +  )
  +    throws SAXException
  +  {
  +    elementData(contentHandler, "uri", request.getRequestURI());
  +  }
  +
  +  /**
  +   * Return the given request parameter value or a user-provided default if
  +   * none was specified.
  +   *
  +   * @param request The Cocoon request
  +   * @param name The parameter name
  +   * @param defaultValue Value to substitute in absence of a parameter value
  +   */
  +  public static String getParameter(
  +    HttpRequest request,
  +    String name,
  +    String defaultValue
  +  ) {
  +    String value = request.getParameter(name);
  +
  +    if (value == null) {
  +      value = defaultValue;
  +    }
  +
  +    return value;
  +  }
  +
  +  /**
  +   * Output the given request parameter value or a user-provided default if
  +   * none was specified.
  +   *
  +   * @param request The Cocoon request
  +   * @param contentHandler The SAX content handler
  +   * @param name The parameter name
  +   * @param defaultValue Value to substitute in absence of a parameter value
  +   * @exception SAXException If a SAX error occurs
  +   */
  +  public static void getParameter(
  +    HttpRequest request,
  +    ContentHandler contentHandler,
  +    String name,
  +    String defaultValue
  +  )
  +    throws SAXException
  +  {
  +    AttributesImpl attr = new AttributesImpl();
  +    addAttribute(attr, "name", name);
  +
  +    elementData(
  +      contentHandler,
  +      "parameter",
  +      getParameter(request, name, defaultValue),
  +      attr
  +    );
  +  }
  +
  +  /**
  +   * Output the request parameter values for a given name
  +   *
  +   * @param request The Cocoon request
  +   * @param contentHandler The SAX content handler
  +   * @exception SAXException If a SAX error occurs
  +   */
  +  public static void getParameterValues(
  +    HttpRequest request,
  +    ContentHandler contentHandler,
  +    String name
  +  )
  +    throws SAXException
  +  {
  +    AttributesImpl attr = new AttributesImpl();
  +    addAttribute(attr, "name", name);
  +
  +    start(contentHandler, "parameter-values", attr);
  +
  +    String[] values = request.getParameterValues(name);
  +
  +    if (values != null) {
  +      for (int i = 0; i < values.length; i++) {
  +        elementData(contentHandler, "value", values[i]);
  +      }
  +    }
  +
  +    end(contentHandler, "parameter-values");
  +  }
  +
  +  /**
  +   * Output parameter names for a given request
  +   *
  +   * @param request The Cocoon request
  +   * @param contentHandler The SAX content handler
  +   * @exception SAXException If a SAX error occurs
  +   */
  +  public static void getParameterNames(
  +    HttpRequest request,
  +    ContentHandler contentHandler
  +  )
  +    throws SAXException
  +  {
  +    start(contentHandler, "parameter-names");
  +
  +    Enumeration e = request.getParameterNames();
  +    while (e.hasMoreElements()) {
  +      String name = (String) e.nextElement();
  +      elementData(contentHandler, "name", name);
  +    }
  +
  +    end(contentHandler, "parameter-names");
  +  }
  +
  +  /**
  +   * Return the request header value for a given name
  +   *
  +   * @param request The Cocoon request
  +   * @param name The parameter name
  +   */
  +  public static String getHeader(
  +    HttpRequest request,
  +    String name
  +  ) {
  +    return request.getHeader(name);
  +  }
  +
  +  /**
  +   * Output the request header value for a given name
  +   *
  +   * @param request The Cocoon request
  +   * @param contentHandler The SAX content handler
  +   * @param name The parameter name
  +   * @exception SAXException If a SAX error occurs
  +   */
  +  public static void getHeader(
  +    HttpRequest request,
  +    ContentHandler contentHandler,
  +    String name
  +  )
  +    throws SAXException
  +  {
  +    AttributesImpl attr = new AttributesImpl();
  +    addAttribute(attr, "name", name);
  +
  +    String value = getHeader(request, name);
  +    if (value == null) {
  +      value = "";
  +    }
  +
  +    elementData(
  +      contentHandler,
  +      "header",
  +      value,
  +      attr
  +    );
  +  }
  +
  +  /**
  +   * Output the header names for a given request
  +   *
  +   * @param request The Cocoon request
  +   * @param contentHandler The SAX content handler
  +   * @exception SAXException If a SAX error occurs
  +   */
  +  public static void getHeaderNames(
  +    HttpRequest request,
  +    ContentHandler contentHandler
  +  )
  +    throws SAXException
  +  {
  +    start(contentHandler, "header-names");
  +
  +    Enumeration e = request.getHeaderNames();
  +    while (e.hasMoreElements()) {
  +      String name = (String) e.nextElement();
  +      elementData(contentHandler, "name", name);
  +    }
  +
  +    end(contentHandler, "header-names");
  +  }
  +}
  
  
  
  1.1.2.3   +54 -54    xml-cocoon/src/org/apache/cocoon/components/language/markup/xsp/Attic/XSPResponseHelper.java
  
  Index: XSPResponseHelper.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/components/language/markup/xsp/Attic/XSPResponseHelper.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- XSPResponseHelper.java	2000/07/22 20:41:37	1.1.2.2
  +++ XSPResponseHelper.java	2000/07/27 21:48:49	1.1.2.3
  @@ -1,54 +1,54 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -package org.apache.cocoon.components.language.markup.xsp;
  -
  -import java.util.Enumeration;
  -
  -import org.apache.cocoon.Response;
  -
  -import org.xml.sax.ContentHandler;
  -import org.xml.sax.helpers.AttributesImpl;
  -
  -import org.xml.sax.SAXException;
  -
  -/**
  - * The XSP <code>Response</code> object helper
  - *
  - * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
  - * @version CVS $Revision: 1.1.2.2 $ $Date: 2000/07/22 20:41:37 $
  - */
  -public class XSPResponseHelper extends XSPObjectHelper {
  -  /**
  -   * Assign values to the object's namespace uri and prefix
  -   */
  -  static {
  -    URI = XSP_RESPONSE_URI;
  -    PREFIX = XSP_RESPONSE_PREFIX;
  -  }
  -
  -  /**
  -   * Set the content header for a given response
  -   *
  -   * @param response The Cocoon <code>Response</code>
  -   * @param name The header name
  -   * @param value The header value
  -   */
  -  public static void setHeader(Response response, String name, String value) {
  -    response.setHeader(name, value);
  -  }
  -
  -  /**
  -   * Set the content type for a given response
  -   *
  -   * @param response The Cocoon <code>Response</code>
  -   * @param type The content type
  -   */
  -  public static void setContentType(Response response, String type) {
  -    response.setContentType(type);
  -  }
  -}
  +/*****************************************************************************
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  + * ------------------------------------------------------------------------- *
  + * This software is published under the terms of the Apache Software License *
  + * version 1.1, a copy of which has been included  with this distribution in *
  + * the LICENSE file.                                                         *
  + *****************************************************************************/
  +package org.apache.cocoon.components.language.markup.xsp;
  +
  +import java.util.Enumeration;
  +
  +import org.apache.cocoon.environment.http.HttpResponse;
  +
  +import org.xml.sax.ContentHandler;
  +import org.xml.sax.helpers.AttributesImpl;
  +
  +import org.xml.sax.SAXException;
  +
  +/**
  + * The XSP <code>HttpResponse</code> object helper
  + *
  + * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
  + * @version CVS $Revision: 1.1.2.3 $ $Date: 2000/07/27 21:48:49 $
  + */
  +public class XSPResponseHelper extends XSPObjectHelper {
  +  /**
  +   * Assign values to the object's namespace uri and prefix
  +   */
  +  static {
  +    URI = XSP_RESPONSE_URI;
  +    PREFIX = XSP_RESPONSE_PREFIX;
  +  }
  +
  +  /**
  +   * Set the content header for a given response
  +   *
  +   * @param response The Cocoon <code>HttpResponse</code>
  +   * @param name The header name
  +   * @param value The header value
  +   */
  +  public static void setHeader(HttpResponse response, String name, String value) {
  +    response.setHeader(name, value);
  +  }
  +
  +  /**
  +   * Set the content type for a given response
  +   *
  +   * @param response The Cocoon <code>HttpResponse</code>
  +   * @param type The content type
  +   */
  +  public static void setContentType(HttpResponse response, String type) {
  +    response.setContentType(type);
  +  }
  +}
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.3   +162 -162  xml-cocoon/src/org/apache/cocoon/components/language/markup/xsp/java/Attic/request.xsl
  
  Index: request.xsl
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/components/language/markup/xsp/java/Attic/request.xsl,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- request.xsl	2000/07/22 20:41:38	1.1.2.2
  +++ request.xsl	2000/07/27 21:48:51	1.1.2.3
  @@ -1,162 +1,162 @@
  -<?xml version="1.0"?>
  -<!--
  - *****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * _________________________________________________________________________ *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - ***************************************************************************** 
  --->
  -
  -<!-- XSP Response logicsheet for the Java language -->
  -<xsl:stylesheet
  -  version="1.0"
  -  xmlns:xsp="http://xml.apache.org/xsp"
  -  xmlns:xsp-request="http://xml.apache.org/xsp/request"
  -
  -  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  ->
  -  <xsl:template match="xsp-request:get-uri">
  -    <xsl:variable name="as">
  -      <xsl:call-template name="value-for-as">
  -        <xsl:with-param name="default" select="'string'"/>
  -      </xsl:call-template>
  -    </xsl:variable>
  -
  -    <xsl:choose>
  -      <xsl:when test="$as = 'string'">
  -        <xsp:expr>
  -          (this.request.getUri())
  -        </xsp:expr>
  -      </xsl:when>
  -      <xsl:when test="$as = 'xml'">
  -	<!-- <xsp-request:uri> -->
  -        <xsp:logic>
  -          XSPRequestHelper.getUri(this.request, this.contentHandler);
  -        </xsp:logic>
  -      </xsl:when>
  -    </xsl:choose>
  -  </xsl:template>
  -
  -  <xsl:template match="xsp-request:get-parameter">
  -    <xsl:variable name="name">
  -      <xsl:call-template name="value-for-name"/>
  -    </xsl:variable>
  -
  -    <xsl:variable name="default">
  -      <xsl:choose>
  -        <xsl:when test="@default">"<xsl:value-of select="@default"/>"</xsl:when>
  -        <xsl:when test="default">
  -          <xsl:call-template name="get-nested-content">
  -            <xsl:with-param name="content" select="xsp-request:default"/>
  -          </xsl:call-template>
  -        </xsl:when>
  -        <xsl:otherwise>null</xsl:otherwise>
  -      </xsl:choose>
  -    </xsl:variable>
  -
  -    <xsl:variable name="as">
  -      <xsl:call-template name="value-for-as">
  -        <xsl:with-param name="default" select="'string'"/>
  -      </xsl:call-template>
  -    </xsl:variable>
  -
  -    <xsl:choose>
  -      <xsl:when test="$as = 'string'">
  -        <xsp:expr>
  -          (XSPRequestHelper.getParameter(this.request, <xsl:copy-of select="$name"/>, <xsl:copy-of select="$default"/>))
  -        </xsp:expr>
  -      </xsl:when>
  -      <xsl:when test="$as = 'xml'">
  -	<!-- <xsp-request:uri> -->
  -        <xsp:logic>
  -          XSPRequestHelper.getParameter(this.request, this.contentHandler, <xsl:copy-of select="$name"/>, <xsl:copy-of select="$default"/>);
  -        </xsp:logic>
  -      </xsl:when>
  -    </xsl:choose>
  -  </xsl:template>
  -
  -  <xsl:template match="xsp-request:get-parameter-values">
  -    <xsl:variable name="name">
  -      <xsl:call-template name="value-for-name"/>
  -    </xsl:variable>
  -
  -     <xsp:logic>
  -        XSPRequestHelper.getParameterValues(this.request, this.contentHandler, <xsl:copy-of select="$name"/>);
  -     </xsp:logic>
  -  </xsl:template>
  -
  -  <xsl:template match="xsp-request:get-parameter-names">
  -     <xsp:logic>
  -        XSPRequestHelper.getParameterNames(this.request, this.contentHandler);
  -     </xsp:logic>
  -  </xsl:template>
  -
  -  <xsl:template match="xsp-request:get-header">
  -    <xsl:variable name="name">
  -      <xsl:call-template name="value-for-name"/>
  -    </xsl:variable>
  -
  -    <xsl:variable name="as">
  -      <xsl:call-template name="value-for-as">
  -        <xsl:with-param name="default" select="'string'"/>
  -      </xsl:call-template>
  -    </xsl:variable>
  -
  -    <xsl:choose>
  -      <xsl:when test="$as = 'string'">
  -        <xsp:expr>
  -          (XSPRequestHelper.getHeader(this.request, <xsl:copy-of select="$name"/>))
  -        </xsp:expr>
  -      </xsl:when>
  -      <xsl:when test="$as = 'xml'">
  -	<!-- <xsp-request:uri> -->
  -        <xsp:logic>
  -          XSPRequestHelper.getHeader(this.request, this.contentHandler, <xsl:copy-of select="$name"/>);
  -        </xsp:logic>
  -      </xsl:when>
  -    </xsl:choose>
  -  </xsl:template>
  -
  -  <xsl:template match="xsp-request:get-header-names">
  -     <xsp:logic>
  -        XSPRequestHelper.getHeaderNames(this.request, this.contentHandler);
  -     </xsp:logic>
  -  </xsl:template>
  -
  -  <xsl:template name="value-for-as">
  -    <xsl:param name="default"/>
  -    <xsl:choose>
  -      <xsl:when test="@as"><xsl:value-of select="@as"/></xsl:when>
  -      <xsl:otherwise><xsl:value-of select="$default"/></xsl:otherwise>
  -    </xsl:choose>
  -  </xsl:template>
  -
  -  <xsl:template name="value-for-name">
  -    <xsl:choose>
  -      <xsl:when test="@name">"<xsl:value-of select="@name"/>"</xsl:when>
  -      <xsl:when test="name">
  -        <xsl:call-template name="get-nested-content">
  -          <xsl:with-param name="content" select="xsp-request:name"/>
  -        </xsl:call-template>
  -      </xsl:when>
  -    </xsl:choose>
  -  </xsl:template>
  -
  -  <xsl:template name="get-nested-content">
  -    <xsl:param name="content"/>
  -    <xsl:choose>
  -      <xsl:when test="$content/*">
  -        <xsl:apply-templates select="$content/*"/>
  -      </xsl:when>
  -      <xsl:otherwise>"<xsl:value-of select="$content"/>"</xsl:otherwise>
  -    </xsl:choose>
  -  </xsl:template>
  - 
  -  <xsl:template match="@*|*|text()|processing-instruction()">
  -    <xsl:copy>
  -      <xsl:apply-templates select="@*|*|text()|processing-instruction()"/>
  -    </xsl:copy>
  -  </xsl:template>
  -</xsl:stylesheet>
  +<?xml version="1.0"?>
  +<!--
  + *****************************************************************************
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  + * _________________________________________________________________________ *
  + * This software is published under the terms of the Apache Software License *
  + * version 1.1, a copy of which has been included  with this distribution in *
  + * the LICENSE file.                                                         *
  + ***************************************************************************** 
  +-->
  +
  +<!-- XSP Response logicsheet for the Java language -->
  +<xsl:stylesheet
  +  version="1.0"
  +  xmlns:xsp="http://xml.apache.org/xsp"
  +  xmlns:xsp-request="http://xml.apache.org/xsp/request"
  +
  +  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  +>
  +  <xsl:template match="xsp-request:get-uri">
  +    <xsl:variable name="as">
  +      <xsl:call-template name="value-for-as">
  +        <xsl:with-param name="default" select="'string'"/>
  +      </xsl:call-template>
  +    </xsl:variable>
  +
  +    <xsl:choose>
  +      <xsl:when test="$as = 'string'">
  +        <xsp:expr>
  +          (this.environment.getUri())
  +        </xsp:expr>
  +      </xsl:when>
  +      <xsl:when test="$as = 'xml'">
  +	<!-- <xsp-request:uri> -->
  +        <xsp:logic>
  +          XSPRequestHelper.getUri(((HttpEnvironment)this.environment).getRequest(), this.contentHandler);
  +        </xsp:logic>
  +      </xsl:when>
  +    </xsl:choose>
  +  </xsl:template>
  +
  +  <xsl:template match="xsp-request:get-parameter">
  +    <xsl:variable name="name">
  +      <xsl:call-template name="value-for-name"/>
  +    </xsl:variable>
  +
  +    <xsl:variable name="default">
  +      <xsl:choose>
  +        <xsl:when test="@default">"<xsl:value-of select="@default"/>"</xsl:when>
  +        <xsl:when test="default">
  +          <xsl:call-template name="get-nested-content">
  +            <xsl:with-param name="content" select="xsp-request:default"/>
  +          </xsl:call-template>
  +        </xsl:when>
  +        <xsl:otherwise>null</xsl:otherwise>
  +      </xsl:choose>
  +    </xsl:variable>
  +
  +    <xsl:variable name="as">
  +      <xsl:call-template name="value-for-as">
  +        <xsl:with-param name="default" select="'string'"/>
  +      </xsl:call-template>
  +    </xsl:variable>
  +
  +    <xsl:choose>
  +      <xsl:when test="$as = 'string'">
  +        <xsp:expr>
  +          (XSPRequestHelper.getParameter(((HttpEnvironment)this.environment).getRequest(), <xsl:copy-of select="$name"/>, <xsl:copy-of select="$default"/>))
  +        </xsp:expr>
  +      </xsl:when>
  +      <xsl:when test="$as = 'xml'">
  +	<!-- <xsp-request:uri> -->
  +        <xsp:logic>
  +          XSPRequestHelper.getParameter(((HttpEnvironment)this.environment).getRequest(), this.contentHandler, <xsl:copy-of select="$name"/>, <xsl:copy-of select="$default"/>);
  +        </xsp:logic>
  +      </xsl:when>
  +    </xsl:choose>
  +  </xsl:template>
  +
  +  <xsl:template match="xsp-request:get-parameter-values">
  +    <xsl:variable name="name">
  +      <xsl:call-template name="value-for-name"/>
  +    </xsl:variable>
  +
  +     <xsp:logic>
  +        XSPRequestHelper.getParameterValues(((HttpEnvironment)this.environment).getRequest(), this.contentHandler, <xsl:copy-of select="$name"/>);
  +     </xsp:logic>
  +  </xsl:template>
  +
  +  <xsl:template match="xsp-request:get-parameter-names">
  +     <xsp:logic>
  +        XSPRequestHelper.getParameterNames(((HttpEnvironment)this.environment).getRequest(), this.contentHandler);
  +     </xsp:logic>
  +  </xsl:template>
  +
  +  <xsl:template match="xsp-request:get-header">
  +    <xsl:variable name="name">
  +      <xsl:call-template name="value-for-name"/>
  +    </xsl:variable>
  +
  +    <xsl:variable name="as">
  +      <xsl:call-template name="value-for-as">
  +        <xsl:with-param name="default" select="'string'"/>
  +      </xsl:call-template>
  +    </xsl:variable>
  +
  +    <xsl:choose>
  +      <xsl:when test="$as = 'string'">
  +        <xsp:expr>
  +          (XSPRequestHelper.getHeader(((HttpEnvironment)this.environment).getRequest(), <xsl:copy-of select="$name"/>))
  +        </xsp:expr>
  +      </xsl:when>
  +      <xsl:when test="$as = 'xml'">
  +	<!-- <xsp-request:uri> -->
  +        <xsp:logic>
  +          XSPRequestHelper.getHeader(((HttpEnvironment)this.environment).getRequest(), this.contentHandler, <xsl:copy-of select="$name"/>);
  +        </xsp:logic>
  +      </xsl:when>
  +    </xsl:choose>
  +  </xsl:template>
  +
  +  <xsl:template match="xsp-request:get-header-names">
  +     <xsp:logic>
  +        XSPRequestHelper.getHeaderNames(((HttpEnvironment)this.environment).getRequest(), this.contentHandler);
  +     </xsp:logic>
  +  </xsl:template>
  +
  +  <xsl:template name="value-for-as">
  +    <xsl:param name="default"/>
  +    <xsl:choose>
  +      <xsl:when test="@as"><xsl:value-of select="@as"/></xsl:when>
  +      <xsl:otherwise><xsl:value-of select="$default"/></xsl:otherwise>
  +    </xsl:choose>
  +  </xsl:template>
  +
  +  <xsl:template name="value-for-name">
  +    <xsl:choose>
  +      <xsl:when test="@name">"<xsl:value-of select="@name"/>"</xsl:when>
  +      <xsl:when test="name">
  +        <xsl:call-template name="get-nested-content">
  +          <xsl:with-param name="content" select="xsp-request:name"/>
  +        </xsl:call-template>
  +      </xsl:when>
  +    </xsl:choose>
  +  </xsl:template>
  +
  +  <xsl:template name="get-nested-content">
  +    <xsl:param name="content"/>
  +    <xsl:choose>
  +      <xsl:when test="$content/*">
  +        <xsl:apply-templates select="$content/*"/>
  +      </xsl:when>
  +      <xsl:otherwise>"<xsl:value-of select="$content"/>"</xsl:otherwise>
  +    </xsl:choose>
  +  </xsl:template>
  + 
  +  <xsl:template match="@*|*|text()|processing-instruction()">
  +    <xsl:copy>
  +      <xsl:apply-templates select="@*|*|text()|processing-instruction()"/>
  +    </xsl:copy>
  +  </xsl:template>
  +</xsl:stylesheet>
  
  
  
  1.1.2.3   +81 -81    xml-cocoon/src/org/apache/cocoon/components/language/markup/xsp/java/Attic/response.xsl
  
  Index: response.xsl
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/components/language/markup/xsp/java/Attic/response.xsl,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- response.xsl	2000/07/22 20:41:38	1.1.2.2
  +++ response.xsl	2000/07/27 21:48:51	1.1.2.3
  @@ -1,81 +1,81 @@
  -<?xml version="1.0"?>
  -<!--
  - *****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * _________________________________________________________________________ *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - ***************************************************************************** 
  --->
  -
  -<!-- XSP Response logicsheet for the Java language -->
  -<xsl:stylesheet
  -  version="1.0"
  -  xmlns:xsp="http://xml.apache.org/xsp"
  -  xmlns:xsp-response="http://xml.apache.org/xsp/response"
  -
  -  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  ->
  -  <xsl:template match="xsp-response:set-header">
  -    <xsl:variable name="name">
  -      <xsl:choose>
  -        <xsl:when test="@name">"<xsl:value-of select="@name"/>"</xsl:when>
  -        <xsl:when test="name">
  -          <xsl:call-template name="get-nested-content">
  -            <xsl:with-param name="content" select="xsp-response:name"/>
  -          </xsl:call-template>
  -        </xsl:when>
  -      </xsl:choose>
  -    </xsl:variable>
  -
  -    <xsl:variable name="value">
  -      <xsl:choose>
  -        <xsl:when test="@value">"<xsl:value-of select="@value"/>"</xsl:when>
  -        <xsl:when test="value">
  -          <xsl:call-template name="get-nested-content">
  -            <xsl:with-param name="content" select="xsp-response:value"/>
  -          </xsl:call-template>
  -        </xsl:when>
  -        <xsl:otherwise>""</xsl:otherwise>
  -      </xsl:choose>
  -    </xsl:variable>
  -
  -    <xsp:logic>
  -      XSPResponseHelper.setHeader(this.response, <xsl:value-of select="$name"/>, <xsl:value-of select="$value"/>);
  -    </xsp:logic>
  -  </xsl:template>
  -
  -  <xsl:template match="xsp-response:set-content-type">
  -    <xsl:variable name="type">
  -      <xsl:choose>
  -        <xsl:when test="@type">"<xsl:value-of select="@type"/>"</xsl:when>
  -        <xsl:when test="type">
  -          <xsl:call-template name="get-nested-content">
  -            <xsl:with-param name="content" select="xsp-response:type"/>
  -          </xsl:call-template>
  -        </xsl:when>
  -      </xsl:choose>
  -    </xsl:variable>
  -
  -    <xsp:logic>
  -      XSPResponseHelper.setContentType(this.response, <xsl:value-of select="$type"/>);
  -    </xsp:logic>
  -  </xsl:template>
  -
  -  <xsl:template name="get-nested-content">
  -    <xsl:param name="content"/>
  -    <xsl:choose>
  -      <xsl:when test="$content/*">
  -        <xsl:apply-templates select="$content/*"/>
  -      </xsl:when>
  -      <xsl:otherwise>"<xsl:value-of select="$content"/>"</xsl:otherwise>
  -    </xsl:choose>
  -  </xsl:template>
  - 
  -  <xsl:template match="@*|*|text()|processing-instruction()">
  -    <xsl:copy>
  -      <xsl:apply-templates select="@*|*|text()|processing-instruction()"/>
  -    </xsl:copy>
  -  </xsl:template>
  -</xsl:stylesheet>
  +<?xml version="1.0"?>
  +<!--
  + *****************************************************************************
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  + * _________________________________________________________________________ *
  + * This software is published under the terms of the Apache Software License *
  + * version 1.1, a copy of which has been included  with this distribution in *
  + * the LICENSE file.                                                         *
  + ***************************************************************************** 
  +-->
  +
  +<!-- XSP Response logicsheet for the Java language -->
  +<xsl:stylesheet
  +  version="1.0"
  +  xmlns:xsp="http://xml.apache.org/xsp"
  +  xmlns:xsp-response="http://xml.apache.org/xsp/response"
  +
  +  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  +>
  +  <xsl:template match="xsp-response:set-header">
  +    <xsl:variable name="name">
  +      <xsl:choose>
  +        <xsl:when test="@name">"<xsl:value-of select="@name"/>"</xsl:when>
  +        <xsl:when test="name">
  +          <xsl:call-template name="get-nested-content">
  +            <xsl:with-param name="content" select="xsp-response:name"/>
  +          </xsl:call-template>
  +        </xsl:when>
  +      </xsl:choose>
  +    </xsl:variable>
  +
  +    <xsl:variable name="value">
  +      <xsl:choose>
  +        <xsl:when test="@value">"<xsl:value-of select="@value"/>"</xsl:when>
  +        <xsl:when test="value">
  +          <xsl:call-template name="get-nested-content">
  +            <xsl:with-param name="content" select="xsp-response:value"/>
  +          </xsl:call-template>
  +        </xsl:when>
  +        <xsl:otherwise>""</xsl:otherwise>
  +      </xsl:choose>
  +    </xsl:variable>
  +
  +    <xsp:logic>
  +      XSPResponseHelper.setHeader(((HttpEnvironment)environment).getResponse(), <xsl:value-of select="$name"/>, <xsl:value-of select="$value"/>);
  +    </xsp:logic>
  +  </xsl:template>
  +
  +  <xsl:template match="xsp-response:set-content-type">
  +    <xsl:variable name="type">
  +      <xsl:choose>
  +        <xsl:when test="@type">"<xsl:value-of select="@type"/>"</xsl:when>
  +        <xsl:when test="type">
  +          <xsl:call-template name="get-nested-content">
  +            <xsl:with-param name="content" select="xsp-response:type"/>
  +          </xsl:call-template>
  +        </xsl:when>
  +      </xsl:choose>
  +    </xsl:variable>
  +
  +    <xsp:logic>
  +      XSPResponseHelper.setContentType(((HttpEnvironment)environment).getResponse(), <xsl:value-of select="$type"/>);
  +    </xsp:logic>
  +  </xsl:template>
  +
  +  <xsl:template name="get-nested-content">
  +    <xsl:param name="content"/>
  +    <xsl:choose>
  +      <xsl:when test="$content/*">
  +        <xsl:apply-templates select="$content/*"/>
  +      </xsl:when>
  +      <xsl:otherwise>"<xsl:value-of select="$content"/>"</xsl:otherwise>
  +    </xsl:choose>
  +  </xsl:template>
  + 
  +  <xsl:template match="@*|*|text()|processing-instruction()">
  +    <xsl:copy>
  +      <xsl:apply-templates select="@*|*|text()|processing-instruction()"/>
  +    </xsl:copy>
  +  </xsl:template>
  +</xsl:stylesheet>
  
  
  
  1.1.2.6   +433 -431  xml-cocoon/src/org/apache/cocoon/components/language/markup/xsp/java/Attic/xsp.xsl
  
  Index: xsp.xsl
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/components/language/markup/xsp/java/Attic/xsp.xsl,v
  retrieving revision 1.1.2.5
  retrieving revision 1.1.2.6
  diff -u -r1.1.2.5 -r1.1.2.6
  --- xsp.xsl	2000/07/22 20:41:38	1.1.2.5
  +++ xsp.xsl	2000/07/27 21:48:52	1.1.2.6
  @@ -1,431 +1,433 @@
  -<?xml version="1.0"?>
  -<!--
  - *****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * _________________________________________________________________________ *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - ***************************************************************************** 
  --->
  -
  -<!-- XSP Core logicsheet for the Java language -->
  -<xsl:stylesheet
  -  version="1.0"
  -
  -  xmlns:xsp="http://xml.apache.org/xsp"
  -  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  ->
  -  <xsl:output method="text"/>
  -
  -  <xsl:variable name="prefix">xsp</xsl:variable>
  -
  -  <xsl:template match="/">
  -    <code xml:space="preserve">
  -      <xsl:apply-templates select="xsp:page"/>
  -    </code>
  -  </xsl:template>
  -
  -  <xsl:template match="xsp:page">
  -    package <xsl:value-of select="translate(@file-path, '/', '.')"/>;
  -
  -    import java.io.*;
  -    import java.net.*;
  -    import java.util.*;
  -
  -    import org.w3c.dom.*;
  -    import org.xml.sax.*;
  -    import org.xml.sax.helpers.*;
  -
  -    import org.apache.avalon.*;
  -    import org.apache.avalon.utils.*;
  -    import org.apache.cocoon.*;
  -    import org.apache.cocoon.generation.*;
  -    import org.apache.cocoon.components.parser.*;
  -
  -    import org.apache.cocoon.components.language.markup.xsp.XSPGenerator;
  -    import org.apache.cocoon.components.language.markup.xsp.XSPRequestHelper;
  -    import org.apache.cocoon.components.language.markup.xsp.XSPResponseHelper;
  -
  -
  -    /* User Imports */
  -    <xsl:for-each select="xsp:structure/xsp:include">
  -      import <xsl:value-of select="."/>;
  -    </xsl:for-each>
  -
  -    /**
  -     * Generated by XSP. Edit at your own risk, :-)
  -     */
  -    public class <xsl:value-of select="@file-name"/> extends XSPGenerator {
  -      static {
  -        dateCreated = <xsl:value-of select="@creation-date"/>L;
  -        dependencies = new File[] {
  -          <xsl:for-each select="xsp:dependency">
  -            new File("<xsl:value-of select="translate(., '\','/')"/>"),
  -          </xsl:for-each>
  -        };
  -      }
  -
  -      /* User Class Declarations */
  -      <xsl:apply-templates select="xsp:logic"/>
  -
  -      /**
  -       * Generate XML data.
  -       */
  -      public void generate() throws SAXException {
  -        this.contentHandler.startDocument();
  -        AttributesImpl xspAttr = new AttributesImpl();
  -
  -        <!-- Generate top-level processing instructions -->
  -        <xsl:apply-templates select="/processing-instruction()"/>
  -
  -        <!-- Start top-level namespace prefix mapping -->
  -        <xsl:for-each select="namespace::*[not(local-name(.) = 'xsp')]">
  -          this.contentHandler.startPrefixMapping(
  -            "<xsl:value-of select="local-name(.)"/>",
  -            "<xsl:value-of select="."/>"
  -          );
  -        </xsl:for-each>
  -
  -        <!-- Process only 1st non-XSP element as generated root -->
  -        <xsl:call-template name="process-first-element">
  -          <xsl:with-param
  -                          name="content"
  -                          select="*[not(starts-with(name(.), 'xsp:'))]"/>
  -        </xsl:call-template>
  -
  -        <!-- End top-level namespace prefix mapping -->
  -        <xsl:for-each select="namespace::*[not(local-name(.) = 'xsp')]">
  -          this.contentHandler.endPrefixMapping(
  -            "<xsl:value-of select="local-name(.)"/>"
  -          );
  -        </xsl:for-each>
  -
  -        this.contentHandler.endDocument();
  -      }
  -    }
  -  </xsl:template>
  -
  -  <xsl:template name="process-first-element">
  -    <xsl:param name="content"/>
  -    <xsl:apply-templates select="$content[1]"/>
  -  </xsl:template>
  -
  -  <xsl:template match="xsp:element">
  -    <xsl:variable name="uri">
  -      <xsl:call-template name="get-parameter">
  -        <xsl:with-param name="name">uri</xsl:with-param>
  -      </xsl:call-template>
  -    </xsl:variable>
  -
  -    <xsl:variable name="prefix">
  -      <xsl:call-template name="get-parameter">
  -        <xsl:with-param name="name">prefix</xsl:with-param>
  -      </xsl:call-template>
  -    </xsl:variable>
  -
  -    <xsl:variable name="name">
  -      <xsl:call-template name="get-parameter">
  -        <xsl:with-param name="name">name</xsl:with-param>
  -        <xsl:with-param name="required">true</xsl:with-param>
  -      </xsl:call-template>
  -    </xsl:variable>
  -
  -    <xsl:variable name="raw-name">
  -      <xsl:if test="
  -        ($uri = '&quot;&quot;' and $prefix != '&quot;&quot;') or
  -        ($uri != '&quot;&quot;' and $prefix = '&quot;&quot;')
  -      ">
  -        <xsl:call-template name="error">
  -          <xsl:with-param name="message">[&lt;xsp:element&gt;]
  -Either both 'uri' and 'prefix' or none of them must be specified
  -          </xsl:with-param>
  -        </xsl:call-template>
  -      </xsl:if>
  -
  -      <xsl:choose>
  -        <xsl:when test="$prefix = '&quot;&quot;'">
  -          <xsl:copy-of select="$name"/>
  -        </xsl:when>
  -        <xsl:otherwise>
  -          <xsl:copy-of select="$prefix"/> + ":" + <xsl:copy-of select="$name"/>
  -        </xsl:otherwise>
  -      </xsl:choose>
  -    </xsl:variable>
  -
  -    <xsl:for-each select="namespace::*">
  -      this.contentHandler.startPrefixMapping(
  -        "<xsl:value-of select="local-name(.)"/>",
  -        "<xsl:value-of select="."/>"
  -      );
  -    </xsl:for-each>
  -
  -    <xsl:apply-templates select="xsp:attribute"/>
  -
  -    this.contentHandler.startElement(
  -      <xsl:copy-of select="$uri"/>,
  -      <xsl:copy-of select="$name"/>,
  -      <xsl:copy-of select="$raw-name"/>,
  -      xspAttr
  -    );
  -
  -    xspAttr.clear();
  -
  -    <xsl:apply-templates select="node()[not(name(.) = 'xsp:attribute')]"/>
  -
  -    this.contentHandler.endElement(
  -      <xsl:copy-of select="$uri"/>,
  -      <xsl:copy-of select="$name"/>,
  -      <xsl:copy-of select="$raw-name"/>
  -    );
  -
  -    <xsl:for-each select="namespace::*">
  -      this.contentHandler.endPrefixMapping(
  -        "<xsl:value-of select="local-name(.)"/>"
  -      );
  -    </xsl:for-each>
  -  </xsl:template>
  -
  -  <xsl:template match="xsp:attribute">
  -    <xsl:variable name="uri">
  -      <xsl:call-template name="get-parameter">
  -        <xsl:with-param name="name">uri</xsl:with-param>
  -      </xsl:call-template>
  -    </xsl:variable>
  -
  -    <xsl:variable name="prefix">
  -      <xsl:call-template name="get-parameter">
  -        <xsl:with-param name="name">prefix</xsl:with-param>
  -      </xsl:call-template>
  -    </xsl:variable>
  -
  -    <xsl:variable name="name">
  -      <xsl:call-template name="get-parameter">
  -        <xsl:with-param name="name">name</xsl:with-param>
  -        <xsl:with-param name="required">true</xsl:with-param>
  -      </xsl:call-template>
  -    </xsl:variable>
  -
  -    <xsl:variable name="raw-name">
  -      <xsl:if test="
  -        ($uri = '&quot;&quot;' and $prefix != '&quot;&quot;') or
  -        ($uri != '&quot;&quot;' and $prefix = '&quot;&quot;')
  -      ">
  -        <xsl:call-template name="error">
  -          <xsl:with-param name="message">[&lt;xsp:attribute&gt;]
  -Either both 'uri' and 'prefix' or none of them must be specified
  -          </xsl:with-param>
  -        </xsl:call-template>
  -      </xsl:if>
  -
  -      <xsl:choose>
  -        <xsl:when test="$prefix = '&quot;&quot;'">
  -          <xsl:copy-of select="$name"/>
  -        </xsl:when>
  -        <xsl:otherwise>
  -          <xsl:copy-of select="$prefix"/> + ":" + <xsl:copy-of select="$name"/>
  -        </xsl:otherwise>
  -      </xsl:choose>
  -    </xsl:variable>
  -
  -    <xsl:variable name="content">
  -      <xsl:for-each select="text()|xsp:expr">
  -        <xsl:choose>
  -          <xsl:when test="name(.) = 'xsp:expr'">
  -            String.valueOf(<xsl:value-of select="."/>)
  -          </xsl:when>
  -          <xsl:otherwise>
  -            "<xsl:value-of select="."/>"
  -          </xsl:otherwise>
  -        </xsl:choose>
  -        +
  -      </xsl:for-each>
  -      ""
  -    </xsl:variable>
  -
  -    xspAttr.addAttribute(
  -      <xsl:copy-of select="$uri"/>,
  -      <xsl:copy-of select="$name"/>,
  -      <xsl:copy-of select="$raw-name"/>,
  -      "CDATA",
  -      <xsl:value-of select="normalize-space($content)"/>
  -    );
  -  </xsl:template>
  -
  -  <xsl:template match="xsp:expr">
  -    <xsl:choose>
  -      <xsl:when test="starts-with(name(..), 'xsp:') and name(..) != 'xsp:content'">
  -        <!--
  -             Expression is nested inside another XSP tag:
  -             preserve its Java type
  -        -->
  -        (<xsl:value-of select="."/>)
  -      </xsl:when>
  -      <xsl:otherwise>
  -        <!-- Coerce to String and output as character data -->
  -        this.characters(String.valueOf(<xsl:value-of select="."/>));
  -      </xsl:otherwise>
  -    </xsl:choose>
  -  </xsl:template>
  -
  -  <!-- FIXME: Is this _really_ necessary? -->
  -  <xsl:template match="xsp:content">
  -    <xsl:apply-templates/>
  -  </xsl:template>
  -
  -  <xsl:template match="xsp:logic">
  -    <xsl:apply-templates/>
  -  </xsl:template>
  -
  -  <xsl:template match="xsp:pi">
  -    <xsl:variable name="target">
  -      <xsl:call-template name="get-parameter">
  -        <xsl:with-param name="name">target</xsl:with-param>
  -      </xsl:call-template>
  -    </xsl:variable>
  -
  -    <xsl:variable name="content">
  -      <xsl:for-each select="text()|xsp:expr">
  -        <xsl:choose>
  -          <xsl:when test="name(.) = 'xsp:expr'">
  -           String.valueOf(<xsl:value-of select="."/>)
  -          </xsl:when>
  -          <xsl:otherwise>
  -            "<xsl:value-of select="."/>"
  -          </xsl:otherwise>
  -        </xsl:choose>
  -       +
  -      </xsl:for-each>
  -      ""
  -    </xsl:variable>
  -
  -    this.contentHandler.processingInstruction(
  -      <xsl:copy-of select="$target"/>,
  -      <xsl:value-of select="normalize-space($content)"/>
  -    );
  -  </xsl:template>
  -
  -  <!-- FIXME: How to create comments in SAX? -->
  -  <xsl:template match="xsp:comment">
  -    this.comment("<xsl:value-of select="."/>");
  -  </xsl:template>
  -
  -
  -  <xsl:template match="*[not(starts-with(name(.), 'xsp:'))]">
  -    <xsl:for-each select="namespace::*">
  -      this.contentHandler.startPrefixMapping(
  -        "<xsl:value-of select="local-name(.)"/>",
  -        "<xsl:value-of select="."/>"
  -      );
  -    </xsl:for-each>
  -
  -    <xsl:apply-templates select="@*"/>
  -
  -    this.contentHandler.startElement(
  -      "<xsl:value-of select="namespace-uri(.)"/>",
  -      "<xsl:value-of select="local-name(.)"/>",
  -      "<xsl:value-of select="name(.)"/>",
  -      xspAttr
  -    );
  -
  -    xspAttr.clear();
  -
  -    <xsl:apply-templates/>
  -
  -    this.contentHandler.endElement(
  -      "<xsl:value-of select="namespace-uri(.)"/>",
  -      "<xsl:value-of select="local-name(.)"/>",
  -      "<xsl:value-of select="name(.)"/>"
  -    );
  -
  -    <xsl:for-each select="namespace::*">
  -      this.contentHandler.endPrefixMapping(
  -        "<xsl:value-of select="local-name(.)"/>"
  -      );
  -    </xsl:for-each>
  -  </xsl:template>
  -
  -  <xsl:template match="@*">
  -    xspAttr.addAttribute(
  -      "<xsl:value-of select="namespace-uri(.)"/>",
  -      "<xsl:value-of select="local-name(.)"/>",
  -      "<xsl:value-of select="name(.)"/>",
  -      "CDATA",
  -      "<xsl:value-of select="."/>"
  -    );
  -  </xsl:template>
  -
  -  <xsl:template match="text()">
  -    <xsl:choose>
  -      <xsl:when test="name(..) = 'xsp:logic' or name(..) = 'xsp:expr'">
  -        <xsl:value-of select="."/>
  -      </xsl:when>
  -      <xsl:otherwise>
  -        this.characters("<xsl:value-of select="."/>");
  -      </xsl:otherwise>
  -    </xsl:choose>
  -  </xsl:template>
  -
  -  <xsl:template match="processing-instruction()">
  -    this.contentHandler.processingInstruction(
  -      "<xsl:value-of select="name()"/>",
  -      "<xsl:value-of select="."/>"
  -    );
  -  </xsl:template>
  -
  -  <!-- Utility templates -->
  -  <xsl:template name="get-parameter">
  -    <xsl:param name="name"/>
  -    <xsl:param name="default"/>
  -    <xsl:param name="required">false</xsl:param>
  -
  -    <xsl:variable name="qname">
  -      <xsl:value-of select="concat($prefix, ':param')"/>
  -    </xsl:variable>
  -
  -    <xsl:choose>
  -      <xsl:when test="@*[name(.) = $name]">"<xsl:value-of select="@*[name(.) = $name]"/>"</xsl:when>
  -      <xsl:when test="(*[name(.) = $qname])[@name = $name]">
  -        <xsl:call-template name="get-nested-content">
  -          <xsl:with-param name="content"
  -                          select="(*[name(.) = $qname])[@name = $name]"/>
  -        </xsl:call-template>
  -      </xsl:when>
  -      <xsl:otherwise>
  -        <xsl:choose>
  -          <xsl:when test="string-length($default) = 0">
  -            <xsl:choose>
  -              <xsl:when test="$required = 'true'">
  -                <xsl:call-template name="error">
  -                  <xsl:with-param name="message">[Logicsheet processor]
  -Parameter '<xsl:value-of select="$name"/>' missing in dynamic tag &lt;<xsl:value-of select="name(.)"/>&gt;
  -                  </xsl:with-param>
  -                </xsl:call-template>
  -              </xsl:when>
  -              <xsl:otherwise>""</xsl:otherwise>
  -            </xsl:choose>
  -          </xsl:when>
  -          <xsl:otherwise><xsl:copy-of select="$default"/></xsl:otherwise>
  -        </xsl:choose>
  -      </xsl:otherwise>
  -    </xsl:choose>
  -  </xsl:template>
  -
  -  <xsl:template name="get-nested-content">
  -    <xsl:param name="content"/>
  -    <xsl:choose>
  -      <xsl:when test="$content/*">
  -        <xsl:apply-templates select="$content/*"/>
  -      </xsl:when>
  -      <xsl:otherwise>"<xsl:value-of select="$content"/>"</xsl:otherwise>
  -    </xsl:choose>
  -  </xsl:template>
  -
  -  <xsl:template name="error">
  -    <xsl:param name="message"/>
  -    <xsl:message terminate="yes"><xsl:value-of select="$message"/></xsl:message>
  -  </xsl:template>
  -
  -  <!-- Ignored elements -->
  -  <xsl:template match="xsp:logicsheet|xsp:dependency|xsp:param"/>
  -</xsl:stylesheet>
  +<?xml version="1.0"?>
  +<!--
  + *****************************************************************************
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  + * _________________________________________________________________________ *
  + * This software is published under the terms of the Apache Software License *
  + * version 1.1, a copy of which has been included  with this distribution in *
  + * the LICENSE file.                                                         *
  + ***************************************************************************** 
  +-->
  +
  +<!-- XSP Core logicsheet for the Java language -->
  +<xsl:stylesheet
  +  version="1.0"
  +
  +  xmlns:xsp="http://xml.apache.org/xsp"
  +  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  +>
  +  <xsl:output method="text"/>
  +
  +  <xsl:variable name="prefix">xsp</xsl:variable>
  +
  +  <xsl:template match="/">
  +    <code xml:space="preserve">
  +      <xsl:apply-templates select="xsp:page"/>
  +    </code>
  +  </xsl:template>
  +
  +  <xsl:template match="xsp:page">
  +    package <xsl:value-of select="translate(@file-path, '/', '.')"/>;
  +
  +    import java.io.*;
  +    import java.net.*;
  +    import java.util.*;
  +
  +    import org.w3c.dom.*;
  +    import org.xml.sax.*;
  +    import org.xml.sax.helpers.*;
  +
  +    import org.apache.avalon.*;
  +    import org.apache.avalon.utils.*;
  +    import org.apache.cocoon.*;
  +    import org.apache.cocoon.environment.*;
  +    import org.apache.cocoon.environment.http.*;
  +    import org.apache.cocoon.generation.*;
  +    import org.apache.cocoon.components.parser.*;
  +
  +    import org.apache.cocoon.components.language.markup.xsp.XSPGenerator;
  +    import org.apache.cocoon.components.language.markup.xsp.XSPRequestHelper;
  +    import org.apache.cocoon.components.language.markup.xsp.XSPResponseHelper;
  +
  +
  +    /* User Imports */
  +    <xsl:for-each select="xsp:structure/xsp:include">
  +      import <xsl:value-of select="."/>;
  +    </xsl:for-each>
  +
  +    /**
  +     * Generated by XSP. Edit at your own risk, :-)
  +     */
  +    public class <xsl:value-of select="@file-name"/> extends XSPGenerator {
  +      static {
  +        dateCreated = <xsl:value-of select="@creation-date"/>L;
  +        dependencies = new File[] {
  +          <xsl:for-each select="xsp:dependency">
  +            new File("<xsl:value-of select="translate(., '\','/')"/>"),
  +          </xsl:for-each>
  +        };
  +      }
  +
  +      /* User Class Declarations */
  +      <xsl:apply-templates select="xsp:logic"/>
  +
  +      /**
  +       * Generate XML data.
  +       */
  +      public void generate() throws SAXException {
  +        this.contentHandler.startDocument();
  +        AttributesImpl xspAttr = new AttributesImpl();
  +
  +        <!-- Generate top-level processing instructions -->
  +        <xsl:apply-templates select="/processing-instruction()"/>
  +
  +        <!-- Start top-level namespace prefix mapping -->
  +        <xsl:for-each select="namespace::*[not(local-name(.) = 'xsp')]">
  +          this.contentHandler.startPrefixMapping(
  +            "<xsl:value-of select="local-name(.)"/>",
  +            "<xsl:value-of select="."/>"
  +          );
  +        </xsl:for-each>
  +
  +        <!-- Process only 1st non-XSP element as generated root -->
  +        <xsl:call-template name="process-first-element">
  +          <xsl:with-param
  +                          name="content"
  +                          select="*[not(starts-with(name(.), 'xsp:'))]"/>
  +        </xsl:call-template>
  +
  +        <!-- End top-level namespace prefix mapping -->
  +        <xsl:for-each select="namespace::*[not(local-name(.) = 'xsp')]">
  +          this.contentHandler.endPrefixMapping(
  +            "<xsl:value-of select="local-name(.)"/>"
  +          );
  +        </xsl:for-each>
  +
  +        this.contentHandler.endDocument();
  +      }
  +    }
  +  </xsl:template>
  +
  +  <xsl:template name="process-first-element">
  +    <xsl:param name="content"/>
  +    <xsl:apply-templates select="$content[1]"/>
  +  </xsl:template>
  +
  +  <xsl:template match="xsp:element">
  +    <xsl:variable name="uri">
  +      <xsl:call-template name="get-parameter">
  +        <xsl:with-param name="name">uri</xsl:with-param>
  +      </xsl:call-template>
  +    </xsl:variable>
  +
  +    <xsl:variable name="prefix">
  +      <xsl:call-template name="get-parameter">
  +        <xsl:with-param name="name">prefix</xsl:with-param>
  +      </xsl:call-template>
  +    </xsl:variable>
  +
  +    <xsl:variable name="name">
  +      <xsl:call-template name="get-parameter">
  +        <xsl:with-param name="name">name</xsl:with-param>
  +        <xsl:with-param name="required">true</xsl:with-param>
  +      </xsl:call-template>
  +    </xsl:variable>
  +
  +    <xsl:variable name="raw-name">
  +      <xsl:if test="
  +        ($uri = '&quot;&quot;' and $prefix != '&quot;&quot;') or
  +        ($uri != '&quot;&quot;' and $prefix = '&quot;&quot;')
  +      ">
  +        <xsl:call-template name="error">
  +          <xsl:with-param name="message">[&lt;xsp:element&gt;]
  +Either both 'uri' and 'prefix' or none of them must be specified
  +          </xsl:with-param>
  +        </xsl:call-template>
  +      </xsl:if>
  +
  +      <xsl:choose>
  +        <xsl:when test="$prefix = '&quot;&quot;'">
  +          <xsl:copy-of select="$name"/>
  +        </xsl:when>
  +        <xsl:otherwise>
  +          <xsl:copy-of select="$prefix"/> + ":" + <xsl:copy-of select="$name"/>
  +        </xsl:otherwise>
  +      </xsl:choose>
  +    </xsl:variable>
  +
  +    <xsl:for-each select="namespace::*">
  +      this.contentHandler.startPrefixMapping(
  +        "<xsl:value-of select="local-name(.)"/>",
  +        "<xsl:value-of select="."/>"
  +      );
  +    </xsl:for-each>
  +
  +    <xsl:apply-templates select="xsp:attribute"/>
  +
  +    this.contentHandler.startElement(
  +      <xsl:copy-of select="$uri"/>,
  +      <xsl:copy-of select="$name"/>,
  +      <xsl:copy-of select="$raw-name"/>,
  +      xspAttr
  +    );
  +
  +    xspAttr.clear();
  +
  +    <xsl:apply-templates select="node()[not(name(.) = 'xsp:attribute')]"/>
  +
  +    this.contentHandler.endElement(
  +      <xsl:copy-of select="$uri"/>,
  +      <xsl:copy-of select="$name"/>,
  +      <xsl:copy-of select="$raw-name"/>
  +    );
  +
  +    <xsl:for-each select="namespace::*">
  +      this.contentHandler.endPrefixMapping(
  +        "<xsl:value-of select="local-name(.)"/>"
  +      );
  +    </xsl:for-each>
  +  </xsl:template>
  +
  +  <xsl:template match="xsp:attribute">
  +    <xsl:variable name="uri">
  +      <xsl:call-template name="get-parameter">
  +        <xsl:with-param name="name">uri</xsl:with-param>
  +      </xsl:call-template>
  +    </xsl:variable>
  +
  +    <xsl:variable name="prefix">
  +      <xsl:call-template name="get-parameter">
  +        <xsl:with-param name="name">prefix</xsl:with-param>
  +      </xsl:call-template>
  +    </xsl:variable>
  +
  +    <xsl:variable name="name">
  +      <xsl:call-template name="get-parameter">
  +        <xsl:with-param name="name">name</xsl:with-param>
  +        <xsl:with-param name="required">true</xsl:with-param>
  +      </xsl:call-template>
  +    </xsl:variable>
  +
  +    <xsl:variable name="raw-name">
  +      <xsl:if test="
  +        ($uri = '&quot;&quot;' and $prefix != '&quot;&quot;') or
  +        ($uri != '&quot;&quot;' and $prefix = '&quot;&quot;')
  +      ">
  +        <xsl:call-template name="error">
  +          <xsl:with-param name="message">[&lt;xsp:attribute&gt;]
  +Either both 'uri' and 'prefix' or none of them must be specified
  +          </xsl:with-param>
  +        </xsl:call-template>
  +      </xsl:if>
  +
  +      <xsl:choose>
  +        <xsl:when test="$prefix = '&quot;&quot;'">
  +          <xsl:copy-of select="$name"/>
  +        </xsl:when>
  +        <xsl:otherwise>
  +          <xsl:copy-of select="$prefix"/> + ":" + <xsl:copy-of select="$name"/>
  +        </xsl:otherwise>
  +      </xsl:choose>
  +    </xsl:variable>
  +
  +    <xsl:variable name="content">
  +      <xsl:for-each select="text()|xsp:expr">
  +        <xsl:choose>
  +          <xsl:when test="name(.) = 'xsp:expr'">
  +            String.valueOf(<xsl:value-of select="."/>)
  +          </xsl:when>
  +          <xsl:otherwise>
  +            "<xsl:value-of select="."/>"
  +          </xsl:otherwise>
  +        </xsl:choose>
  +        +
  +      </xsl:for-each>
  +      ""
  +    </xsl:variable>
  +
  +    xspAttr.addAttribute(
  +      <xsl:copy-of select="$uri"/>,
  +      <xsl:copy-of select="$name"/>,
  +      <xsl:copy-of select="$raw-name"/>,
  +      "CDATA",
  +      <xsl:value-of select="normalize-space($content)"/>
  +    );
  +  </xsl:template>
  +
  +  <xsl:template match="xsp:expr">
  +    <xsl:choose>
  +      <xsl:when test="starts-with(name(..), 'xsp:') and name(..) != 'xsp:content'">
  +        <!--
  +             Expression is nested inside another XSP tag:
  +             preserve its Java type
  +        -->
  +        (<xsl:value-of select="."/>)
  +      </xsl:when>
  +      <xsl:otherwise>
  +        <!-- Coerce to String and output as character data -->
  +        this.characters(String.valueOf(<xsl:value-of select="."/>));
  +      </xsl:otherwise>
  +    </xsl:choose>
  +  </xsl:template>
  +
  +  <!-- FIXME: Is this _really_ necessary? -->
  +  <xsl:template match="xsp:content">
  +    <xsl:apply-templates/>
  +  </xsl:template>
  +
  +  <xsl:template match="xsp:logic">
  +    <xsl:apply-templates/>
  +  </xsl:template>
  +
  +  <xsl:template match="xsp:pi">
  +    <xsl:variable name="target">
  +      <xsl:call-template name="get-parameter">
  +        <xsl:with-param name="name">target</xsl:with-param>
  +      </xsl:call-template>
  +    </xsl:variable>
  +
  +    <xsl:variable name="content">
  +      <xsl:for-each select="text()|xsp:expr">
  +        <xsl:choose>
  +          <xsl:when test="name(.) = 'xsp:expr'">
  +           String.valueOf(<xsl:value-of select="."/>)
  +          </xsl:when>
  +          <xsl:otherwise>
  +            "<xsl:value-of select="."/>"
  +          </xsl:otherwise>
  +        </xsl:choose>
  +       +
  +      </xsl:for-each>
  +      ""
  +    </xsl:variable>
  +
  +    this.contentHandler.processingInstruction(
  +      <xsl:copy-of select="$target"/>,
  +      <xsl:value-of select="normalize-space($content)"/>
  +    );
  +  </xsl:template>
  +
  +  <!-- FIXME: How to create comments in SAX? -->
  +  <xsl:template match="xsp:comment">
  +    this.comment("<xsl:value-of select="."/>");
  +  </xsl:template>
  +
  +
  +  <xsl:template match="*[not(starts-with(name(.), 'xsp:'))]">
  +    <xsl:for-each select="namespace::*">
  +      this.contentHandler.startPrefixMapping(
  +        "<xsl:value-of select="local-name(.)"/>",
  +        "<xsl:value-of select="."/>"
  +      );
  +    </xsl:for-each>
  +
  +    <xsl:apply-templates select="@*"/>
  +
  +    this.contentHandler.startElement(
  +      "<xsl:value-of select="namespace-uri(.)"/>",
  +      "<xsl:value-of select="local-name(.)"/>",
  +      "<xsl:value-of select="name(.)"/>",
  +      xspAttr
  +    );
  +
  +    xspAttr.clear();
  +
  +    <xsl:apply-templates/>
  +
  +    this.contentHandler.endElement(
  +      "<xsl:value-of select="namespace-uri(.)"/>",
  +      "<xsl:value-of select="local-name(.)"/>",
  +      "<xsl:value-of select="name(.)"/>"
  +    );
  +
  +    <xsl:for-each select="namespace::*">
  +      this.contentHandler.endPrefixMapping(
  +        "<xsl:value-of select="local-name(.)"/>"
  +      );
  +    </xsl:for-each>
  +  </xsl:template>
  +
  +  <xsl:template match="@*">
  +    xspAttr.addAttribute(
  +      "<xsl:value-of select="namespace-uri(.)"/>",
  +      "<xsl:value-of select="local-name(.)"/>",
  +      "<xsl:value-of select="name(.)"/>",
  +      "CDATA",
  +      "<xsl:value-of select="."/>"
  +    );
  +  </xsl:template>
  +
  +  <xsl:template match="text()">
  +    <xsl:choose>
  +      <xsl:when test="name(..) = 'xsp:logic' or name(..) = 'xsp:expr'">
  +        <xsl:value-of select="."/>
  +      </xsl:when>
  +      <xsl:otherwise>
  +        this.characters("<xsl:value-of select="."/>");
  +      </xsl:otherwise>
  +    </xsl:choose>
  +  </xsl:template>
  +
  +  <xsl:template match="processing-instruction()">
  +    this.contentHandler.processingInstruction(
  +      "<xsl:value-of select="name()"/>",
  +      "<xsl:value-of select="."/>"
  +    );
  +  </xsl:template>
  +
  +  <!-- Utility templates -->
  +  <xsl:template name="get-parameter">
  +    <xsl:param name="name"/>
  +    <xsl:param name="default"/>
  +    <xsl:param name="required">false</xsl:param>
  +
  +    <xsl:variable name="qname">
  +      <xsl:value-of select="concat($prefix, ':param')"/>
  +    </xsl:variable>
  +
  +    <xsl:choose>
  +      <xsl:when test="@*[name(.) = $name]">"<xsl:value-of select="@*[name(.) = $name]"/>"</xsl:when>
  +      <xsl:when test="(*[name(.) = $qname])[@name = $name]">
  +        <xsl:call-template name="get-nested-content">
  +          <xsl:with-param name="content"
  +                          select="(*[name(.) = $qname])[@name = $name]"/>
  +        </xsl:call-template>
  +      </xsl:when>
  +      <xsl:otherwise>
  +        <xsl:choose>
  +          <xsl:when test="string-length($default) = 0">
  +            <xsl:choose>
  +              <xsl:when test="$required = 'true'">
  +                <xsl:call-template name="error">
  +                  <xsl:with-param name="message">[Logicsheet processor]
  +Parameter '<xsl:value-of select="$name"/>' missing in dynamic tag &lt;<xsl:value-of select="name(.)"/>&gt;
  +                  </xsl:with-param>
  +                </xsl:call-template>
  +              </xsl:when>
  +              <xsl:otherwise>""</xsl:otherwise>
  +            </xsl:choose>
  +          </xsl:when>
  +          <xsl:otherwise><xsl:copy-of select="$default"/></xsl:otherwise>
  +        </xsl:choose>
  +      </xsl:otherwise>
  +    </xsl:choose>
  +  </xsl:template>
  +
  +  <xsl:template name="get-nested-content">
  +    <xsl:param name="content"/>
  +    <xsl:choose>
  +      <xsl:when test="$content/*">
  +        <xsl:apply-templates select="$content/*"/>
  +      </xsl:when>
  +      <xsl:otherwise>"<xsl:value-of select="$content"/>"</xsl:otherwise>
  +    </xsl:choose>
  +  </xsl:template>
  +
  +  <xsl:template name="error">
  +    <xsl:param name="message"/>
  +    <xsl:message terminate="yes"><xsl:value-of select="$message"/></xsl:message>
  +  </xsl:template>
  +
  +  <!-- Ignored elements -->
  +  <xsl:template match="xsp:logicsheet|xsp:dependency|xsp:param"/>
  +</xsl:stylesheet>
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.4   +10 -12    xml-cocoon/src/org/apache/cocoon/environment/Attic/Environment.java
  
  Index: Environment.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/environment/Attic/Environment.java,v
  retrieving revision 1.1.2.3
  retrieving revision 1.1.2.4
  diff -u -r1.1.2.3 -r1.1.2.4
  --- Environment.java	2000/07/25 18:48:27	1.1.2.3
  +++ Environment.java	2000/07/27 21:48:58	1.1.2.4
  @@ -1,12 +1,12 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -package org.apache.cocoon.environment;
  -
  +/*****************************************************************************
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  + * ------------------------------------------------------------------------- *
  + * This software is published under the terms of the Apache Software License *
  + * version 1.1, a copy of which has been included  with this distribution in *
  + * the LICENSE file.                                                         *
  + *****************************************************************************/
  +package org.apache.cocoon.environment;
  +
   import java.io.IOException; 
   import java.net.MalformedURLException; 
   
  @@ -19,6 +19,4 @@
           throws MalformedURLException;
       public String getView ();
       public String getUri (); 
  -    public InputSource resolveEntity (String systemId) 
  -        throws SAXException, IOException; 
  -}
  +}
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.5   +70 -60    xml-cocoon/src/org/apache/cocoon/environment/http/Attic/HttpEnvironment.java
  
  Index: HttpEnvironment.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/environment/http/Attic/HttpEnvironment.java,v
  retrieving revision 1.1.2.4
  retrieving revision 1.1.2.5
  diff -u -r1.1.2.4 -r1.1.2.5
  --- HttpEnvironment.java	2000/07/25 18:48:29	1.1.2.4
  +++ HttpEnvironment.java	2000/07/27 21:48:58	1.1.2.5
  @@ -1,12 +1,12 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -package org.apache.cocoon.environment.http;
  -
  +/*****************************************************************************
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  + * ------------------------------------------------------------------------- *
  + * This software is published under the terms of the Apache Software License *
  + * version 1.1, a copy of which has been included  with this distribution in *
  + * the LICENSE file.                                                         *
  + *****************************************************************************/
  +package org.apache.cocoon.environment.http;
  +
   import java.io.File; 
   import java.io.IOException; 
   import java.net.MalformedURLException; 
  @@ -20,22 +20,22 @@
    
   import org.xml.sax.InputSource; 
   import org.xml.sax.SAXException; 
  -
  -public class HttpEnvironment implements Environment {
  -
  -    /** The current uri in progress */
  -    private String uri = null;
  -
  -    /** The current prefix to strip off from the request uri */
  -    private StringBuffer prefix = new StringBuffer();
  -
  -    /** The View requested */
  -    private String view = "";
  -
  -    /** The HttpServletRequest */
  -    private HttpRequest req = null;
  -
   
  +public class HttpEnvironment implements Environment {
  +
  +    /** The current uri in progress */
  +    private String uri = null;
  +
  +    /** The current prefix to strip off from the request uri */
  +    private StringBuffer prefix = new StringBuffer();
  +
  +    /** The View requested */
  +    private String view = "";
  +
  +    /** The HttpServletRequest */
  +    private HttpRequest req = null;
  +
  +
       /** The HttpServletResponse */ 
       private HttpResponse res = null; 
    
  @@ -45,26 +45,32 @@
       /** The Context path */ 
       private URL context = null; 
   
  -    /**
  -     * Constructs a HttpEnvironment object from a HttpServletRequest 
  -     * and HttpServletResponse objects
  -     */
  +    /**
  +     * Constructs a HttpEnvironment object from a HttpServletRequest 
  +     * and HttpServletResponse objects
  +     */
       public HttpEnvironment (String uri, HttpServletRequest req, 
                               HttpServletResponse res, 
                               ServletContext servletContext) 
       throws MalformedURLException {
  -        this.uri = uri;
  -        this.view = req.getHeader("cocoon-view");
  -        this.req = new HttpRequest (req, this);
  -        this.res = new HttpResponse (res);
  +        this.uri = uri;
  +        this.view = req.getHeader("cocoon-view");
  +        this.req = new HttpRequest (req, this);
  +        this.res = new HttpResponse (res);
           this.servletContext = servletContext; 
  +        System.out.println ("HttpEnvironment: Context path is \""+req.getContextPath()+"\"");
  +        System.out.println ("HttpEnvironment: Servlet path is \""+req.getServletPath()+"\"");
  +        System.out.println ("HttpEnvironment: Translated path is \""+req.getPathTranslated()+"\"");
  +        System.out.println ("HttpEnvironment: Real path is \""+servletContext.getRealPath("/")+"\"");
           this.context = new URL("file://"+servletContext.getRealPath("/"));
  -    }
  -    /**
  -     * Adds an prefix to the overall stripped off prefix from the request uri
  -     */
  +        System.out.println ("HttpEnvironment: Context path is \""+servletContext.getRealPath("/")+"\"");
  +    }
  +    /**
  +     * Adds an prefix to the overall stripped off prefix from the request uri
  +     */
       public void changeContext(String prefix, String context) 
       throws MalformedURLException { 
  +        System.out.println ("Environment: addUriPrefix(\""+prefix+"\",\""+context+"\")");
           if (uri.startsWith (prefix)) {
               this.prefix.append (prefix);
               uri = uri.substring(prefix.length());
  @@ -73,36 +79,39 @@
                   this.context=f.getParentFile().toURL(); 
               else
                   this.context = f.toURL();
  +            System.out.println ("HttpEnvironment: New context path set to \""+this.context+"\"");
           } else {
               //FIXME: should we throw an error here ?
           }
  -    }
  -
  -    /**
  -     * Returns the request view
  -     */
  -    public String getView () {
  -        return this.view;
  -    }
  -
  -    /**
  -     * Returns the uri in progress. The prefix is stripped off
  -     */
  -    public String getUri () {
  -        return this.uri;
  -    }
  -
  -    /**
  -     * Returns a wrapped HttpRequest object of the real HttpRequest in progress
  -     */
  -    public HttpServletRequest getRequest () {
  -        return this.req;
  -    }
  +        System.out.println ("Environment: addUriPrefix: new uri=\""+this.uri+"\", new context=\""+this.context+"\")");
  +    }
  +
  +    /**
  +     * Returns the request view
  +     */
  +    public String getView () {
  +        return this.view;
  +    }
  +
  +    /**
  +     * Returns the uri in progress. The prefix is stripped off
  +     */
  +    public String getUri () {
  +        System.out.println ("Environment: getUri = \""+this.uri+"\"");
  +        return this.uri;
  +    }
  +
  +    /**
  +     * Returns a wrapped HttpRequest object of the real HttpRequest in progress
  +     */
  +    public HttpRequest getRequest () {
  +        return this.req;
  +    }
    
       /** 
        * Returns a wrapped HttpResponse object of the real HttpResponse in progress 
        */ 
  -    public HttpServletResponse getResponse () { 
  +    public HttpResponse getResponse () { 
           return this.res; 
       } 
     
  @@ -119,6 +128,7 @@
        */ 
       public InputSource resolveEntity(String publicId, String systemId) 
       throws SAXException, IOException { 
  +        System.out.println ("Environment: resolveEntity(\""+publicId+"\",\""+systemId+"\")");
           if (systemId==null) throw new SAXException("Invalid System ID"); 
    
           if (systemId.length()==0) 
  @@ -129,4 +139,4 @@
               return new InputSource(this.context.getProtocol()+":"+systemId); 
           return(new InputSource(new URL(this.context,systemId).toExternalForm())); 
       } 
  -}
  +}
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.3   +35 -33    xml-cocoon/src/org/apache/cocoon/generation/Attic/ComposerGenerator.java
  
  Index: ComposerGenerator.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/generation/Attic/ComposerGenerator.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- ComposerGenerator.java	2000/07/22 20:41:47	1.1.2.2
  +++ ComposerGenerator.java	2000/07/27 21:49:00	1.1.2.3
  @@ -1,33 +1,35 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -package org.apache.cocoon.generation;
  -
  -import org.apache.avalon.Composer;
  -import org.apache.avalon.ComponentManager;
  -import org.apache.cocoon.Cocoon;
  -
  -/**
  - *
  - * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
  - *         (Apache Software Foundation, Exoffice Technologies)
  - * @version CVS $Revision: 1.1.2.2 $ $Date: 2000/07/22 20:41:47 $
  - */
  -public abstract class ComposerGenerator extends AbstractGenerator
  -implements Composer {
  -
  -    /** The component manager instance */
  -    protected ComponentManager manager=null;
  -
  -    /**
  -     * Set the current <code>ComponentManager</code> instance used by this
  -     * <code>Composer</code>.
  -     */
  -    public void setComponentManager(ComponentManager manager) {
  -        this.manager=manager;
  -    }
  -}
  +/*****************************************************************************
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  + * ------------------------------------------------------------------------- *
  + * This software is published under the terms of the Apache Software License *
  + * version 1.1, a copy of which has been included  with this distribution in *
  + * the LICENSE file.                                                         *
  + *****************************************************************************/
  +package org.apache.cocoon.generation;
  +
  +import org.apache.avalon.Composer;
  +import org.apache.avalon.ComponentManager;
  +import org.apache.cocoon.Cocoon;
  +
  +/**
  + *
  + * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
  + *         (Apache Software Foundation, Exoffice Technologies)
  + * @version CVS $Revision: 1.1.2.3 $ $Date: 2000/07/27 21:49:00 $
  + */
  +public abstract class ComposerGenerator extends AbstractGenerator
  +implements Composer {
  +
  +    /** The component manager instance */
  +    protected ComponentManager manager=null;
  +
  +    /**
  +     * Set the current <code>ComponentManager</code> instance used by this
  +     * <code>Composer</code>.
  +     */
  +    public void setComponentManager(ComponentManager manager) {
  +        this.manager=manager;
  +System.out.println ("ComposerGenerator.setComponentManager: manager is "
  ++((this.manager == null)?"null":"set"));
  +    }
  +}
  
  
  
  1.1.2.3   +249 -249  xml-cocoon/src/org/apache/cocoon/generation/Attic/DirectoryGenerator.java
  
  Index: DirectoryGenerator.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/generation/Attic/DirectoryGenerator.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- DirectoryGenerator.java	2000/07/22 20:41:47	1.1.2.2
  +++ DirectoryGenerator.java	2000/07/27 21:49:00	1.1.2.3
  @@ -1,249 +1,249 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -package org.apache.cocoon.generation;
  -
  -import java.io.File;
  -import java.io.IOException;
  -import java.net.URL;
  -import java.text.SimpleDateFormat;
  -import java.util.Date;
  -import org.xml.sax.EntityResolver;
  -import org.xml.sax.InputSource;
  -import org.xml.sax.SAXException;
  -import org.xml.sax.helpers.AttributesImpl;
  -import org.apache.avalon.utils.Parameters;
  -import org.apache.cocoon.environment.Environment;
  -
  -/**
  - * Generates an XML directory listing.
  - * <p>
  - * The root node of the generated document will normally be a
  - * <code>directory</code> node, and a directory node can contain zero
  - * or more <code>file</code> or directory nodes. A file node has no
  - * children. Each node will contain the following attributes:
  - * <blockquote>
  - *   <dl>
  - *   <dt> name
  - *   <dd> the name of the file or directory
  - *   <dt> lastModified
  - *   <dd> the time the file was last modified, measured as the number of
  - *   milliseconds since the epoch (as in java.io.File.lastModified)
  - *   <dt> date (optional)
  - *   <dd> the time the file was last modified in human-readable form
  - *   </dl>
  - * </blockquote>
  - * <p>
  - * <b>Configuration options:</b>
  - * <dl>
  - * <dt> <i>depth</i> (optional)
  - * <dd> Sets how deep DirectoryGenerator should delve into the
  - * directory structure. If set to 1 (the default), only the starting
  - * directory's immediate contents will be returned.
  - * <dt> <i>dateFormat</i> (optional)
  - * <dd> Sets the format for the date attribute of each node, as
  - * described in java.text.SimpleDateFormat. If unset, the default
  - * format for the current locale will be used.
  - * </dl>
  - *
  - * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
  - *         (Apache Software Foundation, Exoffice Technologies)
  - * @version CVS $Revision: 1.1.2.2 $ $Date: 2000/07/22 20:41:47 $ */
  -public class DirectoryGenerator extends ComposerGenerator {
  -
  -    /** The URI of the namespace of this generator. */
  -    protected static final String URI =
  -	"http://xml.apache.org/cocoon/2.0/DirectoryGenerator";
  -
  -    /* Node and attribute names */
  -    protected static final String DIR_NODE_NAME		= "directory";
  -    protected static final String FILE_NODE_NAME		= "file";
  -
  -    protected static final String FILENAME_ATTR_NAME	= "name";
  -    protected static final String LASTMOD_ATTR_NAME	= "lastModified";
  -    protected static final String DATE_ATTR_NAME		= "date";
  -
  -    /*
  -     * Variables set per-request
  -     * 
  -     * FIXME: SimpleDateFormat is not supported by all locales!
  -     */
  -    protected int depth;
  -    protected AttributesImpl attributes = new AttributesImpl();
  -    protected SimpleDateFormat dateFormatter;
  -
  -    /**
  -     * Set the request parameters. Must be called before the generate
  -     * method.
  -     *
  -     * @param	environment
  -     * 		the calling environment object
  -     * @param	src
  -     * 		the URI for this request (?)
  -     * @param	par
  -     * 		configuration parameters
  -     */
  -    public void setup(Environment environment, String src, Parameters par) {
  -	super.setup(environment, src, par);
  -
  -	String dateFormatString = par.getParameter("dateFormat", null);
  -
  -	if (dateFormatString != null) {
  -	    this.dateFormatter = new SimpleDateFormat(dateFormatString);
  -	} else {
  -	    this.dateFormatter = new SimpleDateFormat();
  -	}
  -
  -	this.depth = par.getParameterAsInteger("depth", 1);
  -
  -	/* Create a reusable attributes for creating nodes */
  -	AttributesImpl attributes = new AttributesImpl();
  -    }
  -
  -
  -    /**
  -     * Generate XML data.
  -     * 
  -     * @throws	SAXException
  -     * 		if an error occurs while outputting the document
  -     * @throws	IOException
  -     * 		if the requsted URI isn't a directory on the local
  -     * 		filesystem
  -     */
  -    public void generate()
  -    throws SAXException, IOException {
  -
  -        EntityResolver resolver;
  -        InputSource input;
  -
  -	URL url;
  -	File path;
  -
  -	resolver = (EntityResolver)super.manager.getComponent("cocoon");
  -	input = resolver.resolveEntity(null,super.source);
  -        url = new URL(input.getSystemId());
  -        path = new File(url.getFile());
  -
  -        if (!path.isDirectory()) {
  -            throw new IOException("Cannot read directory from "
  -				  + url.toString() + "\"");
  -	}
  -
  -        this.contentHandler.startDocument();
  -        this.contentHandler.startPrefixMapping("",URI);
  -	addPath(path, depth);
  -        this.contentHandler.endPrefixMapping("");
  -        this.contentHandler.endDocument();
  -
  -    }
  -
  -    /**
  -     * Adds a single node to the generated document. If the path is a
  -     * directory, and depth is greater than zero, then recursive calls
  -     * are made to add nodes for the directory's children.
  -     *
  -     * @param	path
  -     * 		the file/directory to process
  -     * @param	depth
  -     * 		how deep to scan the directory
  -     *
  -     * @throws	SAXException
  -     * 		if an error occurs while constructing nodes
  -     */
  -    protected void addPath(File path, int depth)
  -    throws SAXException {
  -
  -	if (path.isDirectory()) {
  -
  -	    startNode(DIR_NODE_NAME, path);
  -
  -	    if (depth>0) {
  -		File contents[] = path.listFiles();
  -
  -		for (int i=0; i<contents.length; i++) {
  -		    addPath(contents[i], depth-1);
  -		}
  -	    }
  -
  -	    endNode(DIR_NODE_NAME);
  -
  -	} else {
  -
  -	    startNode(FILE_NODE_NAME, path);
  -	    endNode(FILE_NODE_NAME);
  -
  -	}
  -
  -    }
  -
  -    /**
  -     * Begins a named node, and calls setNodeAttributes to set its
  -	 * attributes.
  -     *
  -     * @param	nodeName
  -     * 		the name of the new node
  -     * @param	path
  -     * 		the file/directory to use when setting attributes
  -     * 
  -     * @throws	SAXException
  -     * 		if an error occurs while creating the node
  -     */
  -    protected void startNode(String nodeName, File path)
  -    throws SAXException {
  -
  -	setNodeAttributes(path);
  -	super.contentHandler.startElement(URI, nodeName, nodeName, attributes);
  -    }
  -
  -	/**
  -	 * Sets the attributes for a given path. The default method sets attributes 
  -	 * for the name of thefile/directory and for the last modification time 
  -	 * of the path.
  -	 *
  -	 * @param path
  -	 *        the file/directory to use when setting attributes
  -	 *
  -	 * @throws SAXException
  -	 *         if an error occurs while setting the attributes
  -	 */
  -	protected void setNodeAttributes(File path) throws SAXException {
  -	
  -	long lastModified = path.lastModified();
  -	attributes.clear();
  -	attributes.addAttribute("", FILENAME_ATTR_NAME,
  -				FILENAME_ATTR_NAME, "CDATA",
  -				path.getName());
  -	attributes.addAttribute("", LASTMOD_ATTR_NAME,
  -				LASTMOD_ATTR_NAME, "CDATA",
  -				Long.toString(path.lastModified()));
  -	attributes.addAttribute("", LASTMOD_ATTR_NAME,
  -				LASTMOD_ATTR_NAME, "CDATA",
  -				Long.toString(lastModified));
  -	attributes.addAttribute("", DATE_ATTR_NAME,
  -				DATE_ATTR_NAME, "CDATA",
  -				dateFormatter.format(new Date(lastModified)));
  -	
  -	}
  -
  -
  -    /**
  -     * Ends the named node.
  -     *
  -     * @param	nodeName
  -     * 		the name of the new node
  -     * @param	path
  -     * 		the file/directory to use when setting attributes
  -     * 
  -     * @throws	SAXException
  -     * 		if an error occurs while closing the node
  -     */
  -    protected void endNode(String nodeName)
  -    throws SAXException {
  -	super.contentHandler.endElement(URI, nodeName, nodeName);
  -    }
  -
  -}
  +/*****************************************************************************
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  + * ------------------------------------------------------------------------- *
  + * This software is published under the terms of the Apache Software License *
  + * version 1.1, a copy of which has been included  with this distribution in *
  + * the LICENSE file.                                                         *
  + *****************************************************************************/
  +package org.apache.cocoon.generation;
  +
  +import java.io.File;
  +import java.io.IOException;
  +import java.net.URL;
  +import java.text.SimpleDateFormat;
  +import java.util.Date;
  +import org.xml.sax.EntityResolver;
  +import org.xml.sax.InputSource;
  +import org.xml.sax.SAXException;
  +import org.xml.sax.helpers.AttributesImpl;
  +import org.apache.avalon.utils.Parameters;
  +import org.apache.cocoon.environment.Environment;
  +
  +/**
  + * Generates an XML directory listing.
  + * <p>
  + * The root node of the generated document will normally be a
  + * <code>directory</code> node, and a directory node can contain zero
  + * or more <code>file</code> or directory nodes. A file node has no
  + * children. Each node will contain the following attributes:
  + * <blockquote>
  + *   <dl>
  + *   <dt> name
  + *   <dd> the name of the file or directory
  + *   <dt> lastModified
  + *   <dd> the time the file was last modified, measured as the number of
  + *   milliseconds since the epoch (as in java.io.File.lastModified)
  + *   <dt> date (optional)
  + *   <dd> the time the file was last modified in human-readable form
  + *   </dl>
  + * </blockquote>
  + * <p>
  + * <b>Configuration options:</b>
  + * <dl>
  + * <dt> <i>depth</i> (optional)
  + * <dd> Sets how deep DirectoryGenerator should delve into the
  + * directory structure. If set to 1 (the default), only the starting
  + * directory's immediate contents will be returned.
  + * <dt> <i>dateFormat</i> (optional)
  + * <dd> Sets the format for the date attribute of each node, as
  + * described in java.text.SimpleDateFormat. If unset, the default
  + * format for the current locale will be used.
  + * </dl>
  + *
  + * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
  + *         (Apache Software Foundation, Exoffice Technologies)
  + * @version CVS $Revision: 1.1.2.3 $ $Date: 2000/07/27 21:49:00 $ */
  +public class DirectoryGenerator extends ComposerGenerator {
  +
  +    /** The URI of the namespace of this generator. */
  +    protected static final String URI =
  +	"http://xml.apache.org/cocoon/2.0/DirectoryGenerator";
  +
  +    /* Node and attribute names */
  +    protected static final String DIR_NODE_NAME		= "directory";
  +    protected static final String FILE_NODE_NAME		= "file";
  +
  +    protected static final String FILENAME_ATTR_NAME	= "name";
  +    protected static final String LASTMOD_ATTR_NAME	= "lastModified";
  +    protected static final String DATE_ATTR_NAME		= "date";
  +
  +    /*
  +     * Variables set per-request
  +     * 
  +     * FIXME: SimpleDateFormat is not supported by all locales!
  +     */
  +    protected int depth;
  +    protected AttributesImpl attributes = new AttributesImpl();
  +    protected SimpleDateFormat dateFormatter;
  +
  +    /**
  +     * Set the request parameters. Must be called before the generate
  +     * method.
  +     *
  +     * @param	environment
  +     * 		the calling environment object
  +     * @param	src
  +     * 		the URI for this request (?)
  +     * @param	par
  +     * 		configuration parameters
  +     */
  +    public void setup(Environment environment, String src, Parameters par) {
  +	super.setup(environment, src, par);
  +
  +	String dateFormatString = par.getParameter("dateFormat", null);
  +
  +	if (dateFormatString != null) {
  +	    this.dateFormatter = new SimpleDateFormat(dateFormatString);
  +	} else {
  +	    this.dateFormatter = new SimpleDateFormat();
  +	}
  +
  +	this.depth = par.getParameterAsInteger("depth", 1);
  +
  +	/* Create a reusable attributes for creating nodes */
  +	AttributesImpl attributes = new AttributesImpl();
  +    }
  +
  +
  +    /**
  +     * Generate XML data.
  +     * 
  +     * @throws	SAXException
  +     * 		if an error occurs while outputting the document
  +     * @throws	IOException
  +     * 		if the requsted URI isn't a directory on the local
  +     * 		filesystem
  +     */
  +    public void generate()
  +    throws SAXException, IOException {
  +
  +        EntityResolver resolver;
  +        InputSource input;
  +
  +	URL url;
  +	File path;
  +
  +	resolver = (EntityResolver)this.environment;
  +	input = resolver.resolveEntity(null,super.source);
  +        url = new URL(input.getSystemId());
  +        path = new File(url.getFile());
  +
  +        if (!path.isDirectory()) {
  +            throw new IOException("Cannot read directory from "
  +				  + url.toString() + "\"");
  +	}
  +
  +        this.contentHandler.startDocument();
  +        this.contentHandler.startPrefixMapping("",URI);
  +	addPath(path, depth);
  +        this.contentHandler.endPrefixMapping("");
  +        this.contentHandler.endDocument();
  +
  +    }
  +
  +    /**
  +     * Adds a single node to the generated document. If the path is a
  +     * directory, and depth is greater than zero, then recursive calls
  +     * are made to add nodes for the directory's children.
  +     *
  +     * @param	path
  +     * 		the file/directory to process
  +     * @param	depth
  +     * 		how deep to scan the directory
  +     *
  +     * @throws	SAXException
  +     * 		if an error occurs while constructing nodes
  +     */
  +    protected void addPath(File path, int depth)
  +    throws SAXException {
  +
  +	if (path.isDirectory()) {
  +
  +	    startNode(DIR_NODE_NAME, path);
  +
  +	    if (depth>0) {
  +		File contents[] = path.listFiles();
  +
  +		for (int i=0; i<contents.length; i++) {
  +		    addPath(contents[i], depth-1);
  +		}
  +	    }
  +
  +	    endNode(DIR_NODE_NAME);
  +
  +	} else {
  +
  +	    startNode(FILE_NODE_NAME, path);
  +	    endNode(FILE_NODE_NAME);
  +
  +	}
  +
  +    }
  +
  +    /**
  +     * Begins a named node, and calls setNodeAttributes to set its
  +	 * attributes.
  +     *
  +     * @param	nodeName
  +     * 		the name of the new node
  +     * @param	path
  +     * 		the file/directory to use when setting attributes
  +     * 
  +     * @throws	SAXException
  +     * 		if an error occurs while creating the node
  +     */
  +    protected void startNode(String nodeName, File path)
  +    throws SAXException {
  +
  +	setNodeAttributes(path);
  +	super.contentHandler.startElement(URI, nodeName, nodeName, attributes);
  +    }
  +
  +	/**
  +	 * Sets the attributes for a given path. The default method sets attributes 
  +	 * for the name of thefile/directory and for the last modification time 
  +	 * of the path.
  +	 *
  +	 * @param path
  +	 *        the file/directory to use when setting attributes
  +	 *
  +	 * @throws SAXException
  +	 *         if an error occurs while setting the attributes
  +	 */
  +	protected void setNodeAttributes(File path) throws SAXException {
  +	
  +	long lastModified = path.lastModified();
  +	attributes.clear();
  +	attributes.addAttribute("", FILENAME_ATTR_NAME,
  +				FILENAME_ATTR_NAME, "CDATA",
  +				path.getName());
  +	attributes.addAttribute("", LASTMOD_ATTR_NAME,
  +				LASTMOD_ATTR_NAME, "CDATA",
  +				Long.toString(path.lastModified()));
  +	attributes.addAttribute("", LASTMOD_ATTR_NAME,
  +				LASTMOD_ATTR_NAME, "CDATA",
  +				Long.toString(lastModified));
  +	attributes.addAttribute("", DATE_ATTR_NAME,
  +				DATE_ATTR_NAME, "CDATA",
  +				dateFormatter.format(new Date(lastModified)));
  +	
  +	}
  +
  +
  +    /**
  +     * Ends the named node.
  +     *
  +     * @param	nodeName
  +     * 		the name of the new node
  +     * @param	path
  +     * 		the file/directory to use when setting attributes
  +     * 
  +     * @throws	SAXException
  +     * 		if an error occurs while closing the node
  +     */
  +    protected void endNode(String nodeName)
  +    throws SAXException {
  +	super.contentHandler.endElement(URI, nodeName, nodeName);
  +    }
  +
  +}
  
  
  
  1.1.2.4   +33 -35    xml-cocoon/src/org/apache/cocoon/generation/Attic/FileGenerator.java
  
  Index: FileGenerator.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/generation/Attic/FileGenerator.java,v
  retrieving revision 1.1.2.3
  retrieving revision 1.1.2.4
  diff -u -r1.1.2.3 -r1.1.2.4
  --- FileGenerator.java	2000/07/25 18:48:31	1.1.2.3
  +++ FileGenerator.java	2000/07/27 21:49:00	1.1.2.4
  @@ -1,35 +1,33 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -package org.apache.cocoon.generation;
  -
  -import java.io.IOException;
  -import org.apache.cocoon.Cocoon;
  -import org.apache.cocoon.components.parser.Parser;
  -import org.apache.cocoon.ProcessingException;
  -import org.xml.sax.SAXException;
  -
  -/**
  - *
  - * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
  - *         (Apache Software Foundation, Exoffice Technologies)
  - * @version CVS $Revision: 1.1.2.3 $ $Date: 2000/07/25 18:48:31 $
  - */
  -public class FileGenerator extends ComposerGenerator {
  -
  -    /**
  -     * Generate XML data.
  -     */
  -    public void generate()
  -    throws IOException, SAXException {
  -        Parser parser=(Parser)this.manager.getComponent("parser");
  -        //Cocoon cocoon=(Cocoon)this.manager.getComponent("cocoon");
  -        parser.setContentHandler(this.contentHandler);
  -        parser.setLexicalHandler(this.lexicalHandler);
  -        parser.parse(super.environment.resolveEntity(this.source));
  -    }    
  -}
  +/*****************************************************************************
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  + * ------------------------------------------------------------------------- *
  + * This software is published under the terms of the Apache Software License *
  + * version 1.1, a copy of which has been included  with this distribution in *
  + * the LICENSE file.                                                         *
  + *****************************************************************************/
  +package org.apache.cocoon.generation;
  +
  +import java.io.IOException;
  +import org.apache.cocoon.components.parser.Parser;
  +import org.apache.cocoon.ProcessingException;
  +import org.xml.sax.SAXException;
  +
  +/**
  + *
  + * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
  + *         (Apache Software Foundation, Exoffice Technologies)
  + * @version CVS $Revision: 1.1.2.4 $ $Date: 2000/07/27 21:49:00 $
  + */
  +public class FileGenerator extends ComposerGenerator {
  +
  +    /**
  +     * Generate XML data.
  +     */
  +    public void generate()
  +    throws IOException, SAXException {
  +        Parser parser=(Parser)this.manager.getComponent("parser");
  +        parser.setContentHandler(this.contentHandler);
  +        parser.setLexicalHandler(this.lexicalHandler);
  +        parser.parse(super.environment.resolveEntity(this.source));
  +    }    
  +}
  
  
  
  1.1.2.3   +26 -27    xml-cocoon/src/org/apache/cocoon/generation/Attic/Generator.java
  
  Index: Generator.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/generation/Attic/Generator.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- Generator.java	2000/07/22 20:41:47	1.1.2.2
  +++ Generator.java	2000/07/27 21:49:00	1.1.2.3
  @@ -1,27 +1,26 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -package org.apache.cocoon.generation;
  -
  -import java.io.IOException;
  -import org.apache.cocoon.ProcessingException;
  -import org.apache.cocoon.sitemap.SitemapComponent;
  -import org.apache.cocoon.xml.XMLProducer;
  -import org.xml.sax.SAXException;
  -
  -/**
  - *
  - * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
  - *         (Apache Software Foundation, Exoffice Technologies)
  - * @version CVS $Revision: 1.1.2.2 $ $Date: 2000/07/22 20:41:47 $
  - */
  -public interface Generator extends XMLProducer, SitemapComponent {
  -
  -    public void generate()
  -    throws IOException, SAXException, ProcessingException;
  -    
  -}
  +/*****************************************************************************
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  + * ------------------------------------------------------------------------- *
  + * This software is published under the terms of the Apache Software License *
  + * version 1.1, a copy of which has been included  with this distribution in *
  + * the LICENSE file.                                                         *
  + *****************************************************************************/
  +package org.apache.cocoon.generation;
  +
  +import java.io.IOException;
  +import org.apache.cocoon.ProcessingException;
  +import org.apache.cocoon.sitemap.SitemapComponent;
  +import org.apache.cocoon.xml.XMLProducer;
  +import org.xml.sax.SAXException;
  +
  +/**
  + *
  + * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
  + *         (Apache Software Foundation, Exoffice Technologies)
  + * @version CVS $Revision: 1.1.2.3 $ $Date: 2000/07/27 21:49:00 $
  + */
  +public interface Generator extends XMLProducer, SitemapComponent {
  +
  +    public void generate()
  +    throws IOException, SAXException, ProcessingException;
  +}
  
  
  
  1.1.2.3   +230 -230  xml-cocoon/src/org/apache/cocoon/generation/Attic/PhpGenerator.java
  
  Index: PhpGenerator.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/generation/Attic/PhpGenerator.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- PhpGenerator.java	2000/07/22 20:41:47	1.1.2.2
  +++ PhpGenerator.java	2000/07/27 21:49:00	1.1.2.3
  @@ -1,230 +1,230 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -package org.apache.cocoon.generation;
  -
  -import java.io.*;
  -import java.util.*;
  -import java.net.*;
  -
  -import javax.servlet.*;
  -
  -import net.php.servlet;
  -import net.php.reflect;
  -
  -import org.apache.cocoon.Response;
  -import org.apache.cocoon.Request;
  -import org.apache.cocoon.Cocoon;
  -import org.apache.cocoon.components.parser.Parser;
  -import org.apache.cocoon.ProcessingException;
  -
  -import org.xml.sax.InputSource;
  -import org.xml.sax.SAXException;
  -
  -/**
  - * Allows PHP to be used as a generator.  Builds upon the PHP servlet
  - * functionallity.  Taking a step back, the PHP functionality needs to
  - * be restructured so that faking out all this servlet infrastructure
  - * is not required in order to simply get a response produced from a
  - * request...
  - *
  - * @author <a href="mailto:rubys@us.ibm.com">Sam Ruby</a>
  - * @version CVS $Revision: 1.1.2.2 $ $Date: 2000/07/22 20:41:47 $
  - */
  -public class PhpGenerator extends ComposerGenerator {
  -
  -    /**
  -     * Stub implementation of Servlet Context
  -     */
  -    class Context implements ServletContext {
  -        Vector v = new Vector();
  -        public ServletContext getContext(String uripath) { return null; }
  -        public int getMajorVersion() { return 0; }
  -        public int getMinorVersion() { return 0; }
  -        public String getMimeType(String file) { return ""; }
  -        public java.net.URL getResource(String path) { return null; }
  -        public InputStream getResourceAsStream(String path) { return null; }
  -        public RequestDispatcher getRequestDispatcher(String path) 
  -               { return null; }
  -        public RequestDispatcher getNamedDispatcher(String name) 
  -               { return null; }
  -        public void log(String msg) {}
  -        public void log(String message, Throwable throwable) {}
  -        public String getRealPath(String path) { return ""; }
  -        public String getServerInfo() { return "Cocoon PhpGenerator"; }
  -        public String getInitParameter(String name) { return ""; }
  -        public Enumeration getInitParameterNames() { return v.elements(); }
  -        public Object getAttribute(String name) { return null; }
  -        public Enumeration getAttributeNames() { return v.elements(); }
  -        public void setAttribute(String name, Object object) {};
  -        public void removeAttribute(String name) {};
  -
  -        /**
  -         * @deprecated
  -         */
  -        public Servlet getServlet(String name) { return null; };
  -        /**
  -         * @deprecated
  -         */
  -        public Enumeration getServlets() { return v.elements(); }
  -        /**
  -         * @deprecated
  -         */
  -        public Enumeration getServletNames() { return v.elements(); }
  -        /**
  -         * @deprecated
  -         */
  -        public void log(Exception exception, String msg) {}
  -    }
  -
  -    /**
  -     * Stub implementation of Servlet Config
  -     */
  -    class Config implements ServletConfig {
  -        Context c = new Context();
  -        public String getServletName() { return "PhpGenerator"; }
  -        public Enumeration getInitParameterNames() 
  -               { return c.getInitParameterNames(); }
  -        public ServletContext getServletContext() { return c; }
  -        public String getInitParameter(String name) { return null; }
  -    }
  -
  -    /**
  -     * Subclass the PHP servlet implementation, replacing calls to the
  -     * javax.servlet objects like request and response with the cocoon
  -     * equivalents.
  -     */
  -    public class PhpServlet extends net.php.servlet implements Runnable {
  -
  -        Request request;
  -        Response response;
  -        OutputStream output;
  -        String source;
  -
  -        /******************************************************************/
  -        /*                       php sapi callbacks                       */ 
  -        /******************************************************************/
  -
  -        public String readPost(int bytes) {
  -            String result;
  -
  -            Enumeration e = request.getParameterNames();
  -            result="";
  -            String concat="";
  -            while (e.hasMoreElements()) {
  -                String name = (String)e.nextElement();
  -                String value = request.getParameter(name);
  -                result+=concat+name+"="+URLEncoder.encode(value);
  -                concat="&";
  -            }
  -
  -            return result; 
  -        }
  -
  -        public String readCookies() {
  -            reflect.setResult(define("request"), request);
  -            reflect.setResult(define("response"), response);
  -            reflect.setResult(define("PHP_SELF"), request.getUri());
  -            return request.getHeader("cookie");
  -        }
  -
  -        public void header(String data) {
  -
  -            try {
  -                if (data.startsWith("Content-type: ")) {
  -                    response.setContentType(data.substring(data.indexOf(" ")+0));
  -                } else {
  -                    int colon = data.indexOf(": ");
  -                    if (colon > 0) {
  -                        response.setHeader(data.substring(0,colon), 
  -                                           data.substring(colon+2) );
  -                    } else {
  -                        output.write((data+"\n").getBytes());
  -                    }
  -                }
  -            } catch (IOException e) {
  -                  e.printStackTrace(System.err);
  -            }
  -
  -        }
  -
  -        public void write(String data) {
  -            try {
  -                output.write(data.getBytes());
  -            } catch (IOException e) {
  -                e.printStackTrace(System.err);
  -            }
  -        }
  -
  -        /******************************************************************/
  -        /*                        servlet interface                       */ 
  -        /******************************************************************/
  -
  -        public void service(Request request, Response response, 
  -                            OutputStream output, String source)
  -        {
  -            this.request=request;
  -            this.response=response;
  -            this.output=output;
  -            this.source=source;
  -        }
  -
  -        /******************************************************************/
  -        /*                       runnable interface                       */ 
  -        /******************************************************************/
  -
  -        public void run() {
  -            send("GET", null, request.getUri(), source, null, -1, null, false);
  -
  -            try {
  -                output.close();
  -            } catch (IOException e) {
  -                // should never happen
  -            }
  -        }
  -
  -    }
  -
  -    /**
  -     * Generate XML data from PHP.
  -     */
  -    public void generate() throws IOException, SAXException {
  -        Cocoon cocoon=(Cocoon)this.manager.getComponent("cocoon");
  -        Parser parser=(Parser)this.manager.getComponent("parser");
  -        parser.setContentHandler(this.contentHandler);
  -        parser.setLexicalHandler(this.lexicalHandler);
  -        
  -        // ensure that we are serving a file...
  -        String systemId = cocoon.resolveEntity(this.source).getSystemId();
  -        if (!systemId.startsWith("file:/"))
  -            throw new IOException("protocol not supported: " + systemId);
  -
  -        try {
  -            // construct both ends of the pipe
  -            PipedInputStream input = new PipedInputStream();
  -            PipedOutputStream output = new PipedOutputStream(input);
  -        
  -            // start PHP producing results into the pipe
  -            PhpServlet php = new PhpServlet();
  -            php.init(new Config());
  -            php.service(request, response, output, systemId.substring(6));
  -            new Thread(php).start();
  -
  -            // pipe the results into the parser
  -            parser.parse(new InputSource(input));
  -
  -            // clean up
  -            php.destroy();
  -        } catch (SAXException e) {
  -            throw e;
  -        } catch (IOException e) {
  -            throw e;
  -        } catch (Exception e) {
  -            throw new IOException(e.toString());
  -        }
  -    }    
  -}
  +/*****************************************************************************
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  + * ------------------------------------------------------------------------- *
  + * This software is published under the terms of the Apache Software License *
  + * version 1.1, a copy of which has been included  with this distribution in *
  + * the LICENSE file.                                                         *
  + *****************************************************************************/
  +package org.apache.cocoon.generation;
  +
  +import java.io.*;
  +import java.util.*;
  +import java.net.*;
  +
  +import javax.servlet.*;
  +
  +import net.php.servlet;
  +import net.php.reflect;
  +
  +import org.apache.cocoon.Response;
  +import org.apache.cocoon.Request;
  +import org.apache.cocoon.Cocoon;
  +import org.apache.cocoon.components.parser.Parser;
  +import org.apache.cocoon.ProcessingException;
  +
  +import org.xml.sax.InputSource;
  +import org.xml.sax.SAXException;
  +
  +/**
  + * Allows PHP to be used as a generator.  Builds upon the PHP servlet
  + * functionallity.  Taking a step back, the PHP functionality needs to
  + * be restructured so that faking out all this servlet infrastructure
  + * is not required in order to simply get a response produced from a
  + * request...
  + *
  + * @author <a href="mailto:rubys@us.ibm.com">Sam Ruby</a>
  + * @version CVS $Revision: 1.1.2.3 $ $Date: 2000/07/27 21:49:00 $
  + */
  +public class PhpGenerator extends ComposerGenerator {
  +
  +    /**
  +     * Stub implementation of Servlet Context
  +     */
  +    class Context implements ServletContext {
  +        Vector v = new Vector();
  +        public ServletContext getContext(String uripath) { return null; }
  +        public int getMajorVersion() { return 0; }
  +        public int getMinorVersion() { return 0; }
  +        public String getMimeType(String file) { return ""; }
  +        public java.net.URL getResource(String path) { return null; }
  +        public InputStream getResourceAsStream(String path) { return null; }
  +        public RequestDispatcher getRequestDispatcher(String path) 
  +               { return null; }
  +        public RequestDispatcher getNamedDispatcher(String name) 
  +               { return null; }
  +        public void log(String msg) {}
  +        public void log(String message, Throwable throwable) {}
  +        public String getRealPath(String path) { return ""; }
  +        public String getServerInfo() { return "Cocoon PhpGenerator"; }
  +        public String getInitParameter(String name) { return ""; }
  +        public Enumeration getInitParameterNames() { return v.elements(); }
  +        public Object getAttribute(String name) { return null; }
  +        public Enumeration getAttributeNames() { return v.elements(); }
  +        public void setAttribute(String name, Object object) {};
  +        public void removeAttribute(String name) {};
  +
  +        /**
  +         * @deprecated
  +         */
  +        public Servlet getServlet(String name) { return null; };
  +        /**
  +         * @deprecated
  +         */
  +        public Enumeration getServlets() { return v.elements(); }
  +        /**
  +         * @deprecated
  +         */
  +        public Enumeration getServletNames() { return v.elements(); }
  +        /**
  +         * @deprecated
  +         */
  +        public void log(Exception exception, String msg) {}
  +    }
  +
  +    /**
  +     * Stub implementation of Servlet Config
  +     */
  +    class Config implements ServletConfig {
  +        Context c = new Context();
  +        public String getServletName() { return "PhpGenerator"; }
  +        public Enumeration getInitParameterNames() 
  +               { return c.getInitParameterNames(); }
  +        public ServletContext getServletContext() { return c; }
  +        public String getInitParameter(String name) { return null; }
  +    }
  +
  +    /**
  +     * Subclass the PHP servlet implementation, replacing calls to the
  +     * javax.servlet objects like request and response with the cocoon
  +     * equivalents.
  +     */
  +    public class PhpServlet extends net.php.servlet implements Runnable {
  +
  +        Request request;
  +        Response response;
  +        OutputStream output;
  +        String source;
  +
  +        /******************************************************************/
  +        /*                       php sapi callbacks                       */ 
  +        /******************************************************************/
  +
  +        public String readPost(int bytes) {
  +            String result;
  +
  +            Enumeration e = request.getParameterNames();
  +            result="";
  +            String concat="";
  +            while (e.hasMoreElements()) {
  +                String name = (String)e.nextElement();
  +                String value = request.getParameter(name);
  +                result+=concat+name+"="+URLEncoder.encode(value);
  +                concat="&";
  +            }
  +
  +            return result; 
  +        }
  +
  +        public String readCookies() {
  +            reflect.setResult(define("request"), request);
  +            reflect.setResult(define("response"), response);
  +            reflect.setResult(define("PHP_SELF"), request.getUri());
  +            return request.getHeader("cookie");
  +        }
  +
  +        public void header(String data) {
  +
  +            try {
  +                if (data.startsWith("Content-type: ")) {
  +                    response.setContentType(data.substring(data.indexOf(" ")+0));
  +                } else {
  +                    int colon = data.indexOf(": ");
  +                    if (colon > 0) {
  +                        response.setHeader(data.substring(0,colon), 
  +                                           data.substring(colon+2) );
  +                    } else {
  +                        output.write((data+"\n").getBytes());
  +                    }
  +                }
  +            } catch (IOException e) {
  +                  e.printStackTrace(System.err);
  +            }
  +
  +        }
  +
  +        public void write(String data) {
  +            try {
  +                output.write(data.getBytes());
  +            } catch (IOException e) {
  +                e.printStackTrace(System.err);
  +            }
  +        }
  +
  +        /******************************************************************/
  +        /*                        servlet interface                       */ 
  +        /******************************************************************/
  +
  +        public void service(Request request, Response response, 
  +                            OutputStream output, String source)
  +        {
  +            this.request=request;
  +            this.response=response;
  +            this.output=output;
  +            this.source=source;
  +        }
  +
  +        /******************************************************************/
  +        /*                       runnable interface                       */ 
  +        /******************************************************************/
  +
  +        public void run() {
  +            send("GET", null, request.getUri(), source, null, -1, null, false);
  +
  +            try {
  +                output.close();
  +            } catch (IOException e) {
  +                // should never happen
  +            }
  +        }
  +
  +    }
  +
  +    /**
  +     * Generate XML data from PHP.
  +     */
  +    public void generate() throws IOException, SAXException {
  +        Cocoon cocoon=(Cocoon)this.manager.getComponent("cocoon");
  +        Parser parser=(Parser)this.manager.getComponent("parser");
  +        parser.setContentHandler(this.contentHandler);
  +        parser.setLexicalHandler(this.lexicalHandler);
  +        
  +        // ensure that we are serving a file...
  +        String systemId = environment.resolveEntity(this.source).getSystemId();
  +        if (!systemId.startsWith("file:/"))
  +            throw new IOException("protocol not supported: " + systemId);
  +
  +        try {
  +            // construct both ends of the pipe
  +            PipedInputStream input = new PipedInputStream();
  +            PipedOutputStream output = new PipedOutputStream(input);
  +        
  +            // start PHP producing results into the pipe
  +            PhpServlet php = new PhpServlet();
  +            php.init(new Config());
  +            php.service(request, response, output, systemId.substring(6));
  +            new Thread(php).start();
  +
  +            // pipe the results into the parser
  +            parser.parse(new InputSource(input));
  +
  +            // clean up
  +            php.destroy();
  +        } catch (SAXException e) {
  +            throw e;
  +        } catch (IOException e) {
  +            throw e;
  +        } catch (Exception e) {
  +            throw new IOException(e.toString());
  +        }
  +    }    
  +}
  
  
  
  1.1.2.3   +369 -371  xml-cocoon/src/org/apache/cocoon/generation/Attic/ServerPagesGenerator.java
  
  Index: ServerPagesGenerator.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/generation/Attic/ServerPagesGenerator.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- ServerPagesGenerator.java	2000/07/22 20:41:47	1.1.2.2
  +++ ServerPagesGenerator.java	2000/07/27 21:49:01	1.1.2.3
  @@ -1,371 +1,369 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -package org.apache.cocoon.generation;
  -
  -import java.io.File;
  -import java.net.URL;
  -
  -import org.xml.sax.InputSource;
  -import org.xml.sax.EntityResolver;
  -
  -import java.util.Stack;
  -import org.xml.sax.Locator;
  -import org.xml.sax.Attributes;
  -import org.xml.sax.ContentHandler;
  -import org.xml.sax.ext.LexicalHandler;
  -
  -import org.apache.avalon.Composer;
  -import org.apache.avalon.ComponentManager;
  -import org.apache.cocoon.components.language.generator.ProgramGenerator;
  -
  -import java.io.IOException;
  -import org.xml.sax.SAXException;
  -import java.net.MalformedURLException;
  -import org.apache.cocoon.ProcessingException;
  -
  -/**
  - * This class acts as a proxy to a dynamically loaded<code>Generator</code>
  - * delegating actual SAX event generation.
  - *
  - * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
  - * @version CVS $Revision: 1.1.2.2 $ $Date: 2000/07/22 20:41:47 $
  - */
  -public class ServerPagesGenerator
  -  extends ComposerGenerator
  -  implements ContentHandler, LexicalHandler
  -{
  -  /**
  -   * The sitemap-defined server pages program generator
  -   */
  -  protected static ProgramGenerator programGenerator = null;
  -
  -  /**
  -   * Set the global component manager. This method sets the sitemap-defined
  -   * program generator
  -   *
  -   * @param manager The global component manager
  -   */
  -  public void setComponentManager(ComponentManager manager) {
  -    super.setComponentManager(manager);
  -
  -    if (programGenerator == null) {
  -      programGenerator = (ProgramGenerator)
  -        this.manager.getComponent("program-generator");
  -    }
  -  }
  -
  -  /**
  -   * The loaded generator's <code>MarkupLanguage</code>
  -   */
  -  protected String markupLanguage;
  -
  -  /**
  -   * The loaded generator's <code>ProgrammingLanguage</code>
  -   */
  -  protected String programmingLanguage;
  -
  -  /**
  -   * The default <code>MarkupLanguage</code>
  -   */
  -  public final static String DEFAULT_MARKUP_LANGUAGE = "xsp";
  -
  -  /**
  -   * The default <code>ProgrammingLanguage</code>
  -   */
  -  public final static String DEFAULT_PROGRAMMING_LANGUAGE = "java";
  -
  -
  -  /**
  -   * Generate XML data. This method loads a server pages generator associated
  -   * with its (file) input source and delegates SAX event generator to it
  -   * taking care of "closing" any event left open by the loaded generator as a
  -   * result of its possible "premature" return (a common situation in server
  -   * pages)
  -   *
  -   * @exception IOException IO Error
  -   * @exception SAXException SAX event generation error
  -   * @exception ProcessingException Error during load/execution
  -   */
  -  public void generate() throws IOException, SAXException, ProcessingException {
  -    EntityResolver resolver =
  -      (EntityResolver) this.manager.getComponent("cocoon");
  -    InputSource inputSource = resolver.resolveEntity(null, this.source);
  -
  -    String systemId = inputSource.getSystemId();
  -
  -    URL url = new URL(systemId);
  -    if (!url.getProtocol().equals("file")) {
  -      throw new IOException("Not a file: " + url.toString());
  -    } 
  -
  -    File file = new File(url.getFile());
  -
  -    if (!file.canRead()) {
  -      throw new IOException("Can't read file: " + url.toString());
  -    }
  -
  -    String markupLanguage = this.parameters.getParameter(
  -      "markup-language", DEFAULT_MARKUP_LANGUAGE
  -    );
  -    String programmingLanguage = this.parameters.getParameter(
  -      "programming-language", DEFAULT_PROGRAMMING_LANGUAGE
  -    );
  -
  -    Generator generator = null;
  -
  -    try {
  -      generator = (Generator)
  -        programGenerator.load(file, markupLanguage, programmingLanguage);
  -    } catch (Exception e) {
  -e.printStackTrace();
  -      throw new ProcessingException(e.getMessage());
  -    }
  -
  -    // Delegate XML production to loaded generator
  -    if (generator instanceof Composer) {
  -      ((Composer) generator).setComponentManager(this.manager);
  -    }
  -
  -    generator.setContentHandler(this);
  -    generator.setLexicalHandler(this);
  -    generator.setup(this.environment, this.source, this.parameters);
  -
  -    generator.generate();
  -
  -    // End any started events in case of premature return
  -    while (!this.eventStack.empty()) {
  -      EventData eventData = (EventData) this.eventStack.pop();
  -
  -      switch (eventData.eventType) {
  -        case DOCUMENT:
  -	  this.contentHandler.endDocument();
  -	  break;
  -	case ELEMENT:
  -	  this.contentHandler.endElement(
  -	    eventData.getNamespaceURI(),
  -	    eventData.getLocalName(),
  -	    eventData.getRawName()
  -	  );
  -	  break;
  -	case PREFIX_MAPPING:
  -	  this.contentHandler.endPrefixMapping(eventData.getPrefix());
  -	  break;
  -	case CDATA:
  -	  this.lexicalHandler.endCDATA();
  -	  break;
  -	case DTD:
  -	  this.lexicalHandler.endDTD();
  -	  break;
  -	case ENTITY:
  -	  this.lexicalHandler.endEntity(eventData.getName());
  -	  break;
  -      }
  -    }
  -  }    
  -
  -  /* Handlers */
  -
  -  /**
  -   * The SAX event stack. Used for "completing" pendind SAX events left "open"
  -   * by prematurely returning server pages generators
  -   */
  -  protected Stack eventStack = new Stack();
  -
  -    /**
  -     * Receive notification of character data.
  -     */
  -  public void characters(char[] ch, int start, int length) throws SAXException {
  -    this.contentHandler.characters(ch, start, length);
  -  }
  -
  -    /**
  -     * Receive notification of the end of a document.
  -     */
  -  public void endDocument() throws SAXException {
  -    this.eventStack.pop();
  -    this.contentHandler.endDocument();
  -  }
  -
  -    /**
  -     * Receive notification of the end of an element.
  -     */
  -  public void endElement(String namespaceURI, String localName, String rawName)
  -    throws SAXException
  -  {
  -    this.eventStack.pop();
  -    this.contentHandler.endElement(namespaceURI, localName, rawName);
  -  }
  -
  -    /**
  -     * End the scope of a prefix-URI mapping.
  -     */
  -  public void endPrefixMapping(String prefix) throws SAXException {
  -    this.eventStack.pop();
  -    this.contentHandler.endPrefixMapping(prefix);
  -  }
  -
  -    /**
  -     * Receive notification of ignorable whitespace in element content.
  -     */
  -  public void ignorableWhitespace(char[] ch, int start, int length)
  -    throws SAXException
  -  {
  -    this.contentHandler.ignorableWhitespace(ch, start, length);
  -  }
  -
  -    /**
  -     * Receive notification of a processing instruction.
  -     */
  -  public void processingInstruction(String target, String data)
  -    throws SAXException
  -  {
  -    this.contentHandler.processingInstruction(target, data);
  -  }
  -
  -    /**
  -     * Receive an object for locating the origin of SAX document events.
  -     */
  -  public void setDocumentLocator(Locator locator) {
  -    this.contentHandler.setDocumentLocator(locator);
  -  }
  -
  -    /**
  -     * Receive notification of a skipped entity.
  -     */
  -  public void skippedEntity(String name)
  -    throws SAXException
  -  {
  -    this.contentHandler.skippedEntity(name);
  -  }
  -
  -    /**
  -     * Receive notification of the beginning of a document.
  -     */
  -  public void startDocument() throws SAXException {
  -    this.contentHandler.startDocument();
  -    this.eventStack.push(new EventData(DOCUMENT));
  -  }
  -
  -    /**
  -     * Receive notification of the beginning of an element.
  -     */
  -  public void startElement(
  -    String namespaceURI, String localName, String rawName, Attributes atts
  -  )
  -    throws SAXException
  -  {
  -    this.contentHandler.startElement(namespaceURI, localName, rawName, atts);
  -    this.eventStack.push(new EventData(ELEMENT, namespaceURI, localName, rawName));
  -  }
  -
  -    /**
  -     * Begin the scope of a prefix-URI Namespace mapping.
  -     */
  -  public void startPrefixMapping(String prefix, String uri) throws SAXException
  -  {
  -    this.contentHandler.startPrefixMapping(prefix, uri);
  -    this.eventStack.push(new EventData(PREFIX_MAPPING, prefix));
  -  }
  -
  -  public void comment(char[] ch, int start, int length) throws SAXException {
  -    this.lexicalHandler.comment(ch, start, length);
  -  }
  -
  -  public void endCDATA() throws SAXException {
  -    this.lexicalHandler.endCDATA();
  -    this.eventStack.pop();
  -  }
  -
  -  public void endDTD() throws SAXException {
  -    this.lexicalHandler.endDTD();
  -    this.eventStack.pop();
  -  }
  -
  -  public void endEntity(String name) throws SAXException {
  -    this.lexicalHandler.endEntity(name);
  -    this.eventStack.pop();
  -  }
  -
  -  public void startCDATA() throws SAXException {
  -    this.lexicalHandler.startCDATA();
  -    this.eventStack.push(new EventData(CDATA));
  -  }
  -  
  -  public void startDTD(String name, String publicId, String systemId)
  -    throws SAXException
  -  {
  -    this.lexicalHandler.startDTD(name, publicId, systemId);
  -    this.eventStack.push(new EventData(DTD, name, publicId, systemId));
  -  }
  -
  -  public void startEntity(String name) throws SAXException {
  -    this.lexicalHandler.startEntity(name);
  -    this.eventStack.push(new EventData(ENTITY, name));
  -  }
  -
  -  protected final static int DOCUMENT = 0;
  -  protected final static int ELEMENT = 1;
  -  protected final static int PREFIX_MAPPING = 2;
  -  protected final static int CDATA = 3;
  -  protected final static int DTD = 4;
  -  protected final static int ENTITY = 5;
  -
  -  protected class EventData {
  -    protected int eventType;
  -    protected String namespaceURI;
  -    protected String localName;
  -    protected String rawName;
  -    protected String prefix;
  -    protected String publicId;
  -    protected String systemId;
  -    protected String name;
  -
  -    protected EventData(int eventType) {
  -      this.eventType = eventType; // DOCUMENT | CDATA
  -    }
  -
  -    protected EventData(
  -      int eventType, String data1, String data2, String data3
  -    )
  -    {
  -      this.eventType = eventType;
  -      switch (this.eventType) {
  -        case ELEMENT:
  -          this.namespaceURI = data1;
  -          this.localName = data2;
  -          this.rawName = data3;
  -	  break;
  -        case DTD:
  -          this.name = data1;
  -          this.publicId = data2;
  -          this.systemId = data3;
  -	  break;
  -      }
  -    }
  -
  -    protected EventData(int eventType, String data) {
  -      this.eventType = eventType;
  -      switch (this.eventType) {
  -        case PREFIX_MAPPING:
  -	  this.prefix = data;
  -	  break;
  -	case ENTITY:
  -	  this.name = data;
  -	  break;
  -      }
  -    }
  -
  -    protected String getNamespaceURI() { return this.namespaceURI; }
  -    protected String getLocalName() { return this.localName; }
  -    protected String getRawName() { return this.rawName; }
  -    protected String getPrefix() { return this.prefix; }
  -    protected String getPublicId() { return this.publicId; }
  -    protected String getSystemId() { return this.systemId; }
  -    protected String getName() { return this.name; }
  -  }
  -}
  +/*****************************************************************************
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  + * ------------------------------------------------------------------------- *
  + * This software is published under the terms of the Apache Software License *
  + * version 1.1, a copy of which has been included  with this distribution in *
  + * the LICENSE file.                                                         *
  + *****************************************************************************/
  +package org.apache.cocoon.generation;
  +
  +import java.io.File;
  +import java.net.URL;
  +
  +import org.xml.sax.InputSource;
  +import org.xml.sax.EntityResolver;
  +
  +import java.util.Stack;
  +import org.xml.sax.Locator;
  +import org.xml.sax.Attributes;
  +import org.xml.sax.ContentHandler;
  +import org.xml.sax.ext.LexicalHandler;
  +
  +import org.apache.avalon.Composer;
  +import org.apache.avalon.ComponentManager;
  +import org.apache.cocoon.components.language.generator.ProgramGenerator;
  +
  +import java.io.IOException;
  +import org.xml.sax.SAXException;
  +import java.net.MalformedURLException;
  +import org.apache.cocoon.ProcessingException;
  +
  +/**
  + * This class acts as a proxy to a dynamically loaded<code>Generator</code>
  + * delegating actual SAX event generation.
  + *
  + * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
  + * @version CVS $Revision: 1.1.2.3 $ $Date: 2000/07/27 21:49:01 $
  + */
  +public class ServerPagesGenerator
  +  extends ComposerGenerator
  +  implements ContentHandler, LexicalHandler
  +{
  +  /**
  +   * The sitemap-defined server pages program generator
  +   */
  +  protected static ProgramGenerator programGenerator = null;
  +
  +  /**
  +   * Set the global component manager. This method sets the sitemap-defined
  +   * program generator
  +   *
  +   * @param manager The global component manager
  +   */
  +  public void setComponentManager(ComponentManager manager) {
  +    super.setComponentManager(manager);
  +
  +    if (programGenerator == null) {
  +      programGenerator = (ProgramGenerator)
  +        this.manager.getComponent("program-generator");
  +    }
  +  }
  +
  +  /**
  +   * The loaded generator's <code>MarkupLanguage</code>
  +   */
  +  protected String markupLanguage;
  +
  +  /**
  +   * The loaded generator's <code>ProgrammingLanguage</code>
  +   */
  +  protected String programmingLanguage;
  +
  +  /**
  +   * The default <code>MarkupLanguage</code>
  +   */
  +  public final static String DEFAULT_MARKUP_LANGUAGE = "xsp";
  +
  +  /**
  +   * The default <code>ProgrammingLanguage</code>
  +   */
  +  public final static String DEFAULT_PROGRAMMING_LANGUAGE = "java";
  +
  +
  +  /**
  +   * Generate XML data. This method loads a server pages generator associated
  +   * with its (file) input source and delegates SAX event generator to it
  +   * taking care of "closing" any event left open by the loaded generator as a
  +   * result of its possible "premature" return (a common situation in server
  +   * pages)
  +   *
  +   * @exception IOException IO Error
  +   * @exception SAXException SAX event generation error
  +   * @exception ProcessingException Error during load/execution
  +   */
  +  public void generate() throws IOException, SAXException, ProcessingException {
  +    InputSource inputSource = this.environment.resolveEntity(null, this.source);
  +
  +    String systemId = inputSource.getSystemId();
  +
  +    URL url = new URL(systemId);
  +    if (!url.getProtocol().equals("file")) {
  +      throw new IOException("Not a file: " + url.toString());
  +    } 
  +
  +    File file = new File(url.getFile());
  +
  +    if (!file.canRead()) {
  +      throw new IOException("Can't read file: " + url.toString());
  +    }
  +
  +    String markupLanguage = this.parameters.getParameter(
  +      "markup-language", DEFAULT_MARKUP_LANGUAGE
  +    );
  +    String programmingLanguage = this.parameters.getParameter(
  +      "programming-language", DEFAULT_PROGRAMMING_LANGUAGE
  +    );
  +
  +    Generator generator = null;
  +
  +    try {
  +      generator = (Generator)
  +        programGenerator.load(file, markupLanguage, programmingLanguage, environment);
  +    } catch (Exception e) {
  +e.printStackTrace();
  +      throw new ProcessingException(e.getMessage());
  +    }
  +
  +    // Delegate XML production to loaded generator
  +    if (generator instanceof Composer) {
  +      ((Composer) generator).setComponentManager(this.manager);
  +    }
  +
  +    generator.setContentHandler(this);
  +    generator.setLexicalHandler(this);
  +    generator.setup(this.environment, this.source, this.parameters);
  +
  +    generator.generate();
  +
  +    // End any started events in case of premature return
  +    while (!this.eventStack.empty()) {
  +      EventData eventData = (EventData) this.eventStack.pop();
  +
  +      switch (eventData.eventType) {
  +        case DOCUMENT:
  +	  this.contentHandler.endDocument();
  +	  break;
  +	case ELEMENT:
  +	  this.contentHandler.endElement(
  +	    eventData.getNamespaceURI(),
  +	    eventData.getLocalName(),
  +	    eventData.getRawName()
  +	  );
  +	  break;
  +	case PREFIX_MAPPING:
  +	  this.contentHandler.endPrefixMapping(eventData.getPrefix());
  +	  break;
  +	case CDATA:
  +	  this.lexicalHandler.endCDATA();
  +	  break;
  +	case DTD:
  +	  this.lexicalHandler.endDTD();
  +	  break;
  +	case ENTITY:
  +	  this.lexicalHandler.endEntity(eventData.getName());
  +	  break;
  +      }
  +    }
  +  }    
  +
  +  /* Handlers */
  +
  +  /**
  +   * The SAX event stack. Used for "completing" pendind SAX events left "open"
  +   * by prematurely returning server pages generators
  +   */
  +  protected Stack eventStack = new Stack();
  +
  +    /**
  +     * Receive notification of character data.
  +     */
  +  public void characters(char[] ch, int start, int length) throws SAXException {
  +    this.contentHandler.characters(ch, start, length);
  +  }
  +
  +    /**
  +     * Receive notification of the end of a document.
  +     */
  +  public void endDocument() throws SAXException {
  +    this.eventStack.pop();
  +    this.contentHandler.endDocument();
  +  }
  +
  +    /**
  +     * Receive notification of the end of an element.
  +     */
  +  public void endElement(String namespaceURI, String localName, String rawName)
  +    throws SAXException
  +  {
  +    this.eventStack.pop();
  +    this.contentHandler.endElement(namespaceURI, localName, rawName);
  +  }
  +
  +    /**
  +     * End the scope of a prefix-URI mapping.
  +     */
  +  public void endPrefixMapping(String prefix) throws SAXException {
  +    this.eventStack.pop();
  +    this.contentHandler.endPrefixMapping(prefix);
  +  }
  +
  +    /**
  +     * Receive notification of ignorable whitespace in element content.
  +     */
  +  public void ignorableWhitespace(char[] ch, int start, int length)
  +    throws SAXException
  +  {
  +    this.contentHandler.ignorableWhitespace(ch, start, length);
  +  }
  +
  +    /**
  +     * Receive notification of a processing instruction.
  +     */
  +  public void processingInstruction(String target, String data)
  +    throws SAXException
  +  {
  +    this.contentHandler.processingInstruction(target, data);
  +  }
  +
  +    /**
  +     * Receive an object for locating the origin of SAX document events.
  +     */
  +  public void setDocumentLocator(Locator locator) {
  +    this.contentHandler.setDocumentLocator(locator);
  +  }
  +
  +    /**
  +     * Receive notification of a skipped entity.
  +     */
  +  public void skippedEntity(String name)
  +    throws SAXException
  +  {
  +    this.contentHandler.skippedEntity(name);
  +  }
  +
  +    /**
  +     * Receive notification of the beginning of a document.
  +     */
  +  public void startDocument() throws SAXException {
  +    this.contentHandler.startDocument();
  +    this.eventStack.push(new EventData(DOCUMENT));
  +  }
  +
  +    /**
  +     * Receive notification of the beginning of an element.
  +     */
  +  public void startElement(
  +    String namespaceURI, String localName, String rawName, Attributes atts
  +  )
  +    throws SAXException
  +  {
  +    this.contentHandler.startElement(namespaceURI, localName, rawName, atts);
  +    this.eventStack.push(new EventData(ELEMENT, namespaceURI, localName, rawName));
  +  }
  +
  +    /**
  +     * Begin the scope of a prefix-URI Namespace mapping.
  +     */
  +  public void startPrefixMapping(String prefix, String uri) throws SAXException
  +  {
  +    this.contentHandler.startPrefixMapping(prefix, uri);
  +    this.eventStack.push(new EventData(PREFIX_MAPPING, prefix));
  +  }
  +
  +  public void comment(char[] ch, int start, int length) throws SAXException {
  +    this.lexicalHandler.comment(ch, start, length);
  +  }
  +
  +  public void endCDATA() throws SAXException {
  +    this.lexicalHandler.endCDATA();
  +    this.eventStack.pop();
  +  }
  +
  +  public void endDTD() throws SAXException {
  +    this.lexicalHandler.endDTD();
  +    this.eventStack.pop();
  +  }
  +
  +  public void endEntity(String name) throws SAXException {
  +    this.lexicalHandler.endEntity(name);
  +    this.eventStack.pop();
  +  }
  +
  +  public void startCDATA() throws SAXException {
  +    this.lexicalHandler.startCDATA();
  +    this.eventStack.push(new EventData(CDATA));
  +  }
  +  
  +  public void startDTD(String name, String publicId, String systemId)
  +    throws SAXException
  +  {
  +    this.lexicalHandler.startDTD(name, publicId, systemId);
  +    this.eventStack.push(new EventData(DTD, name, publicId, systemId));
  +  }
  +
  +  public void startEntity(String name) throws SAXException {
  +    this.lexicalHandler.startEntity(name);
  +    this.eventStack.push(new EventData(ENTITY, name));
  +  }
  +
  +  protected final static int DOCUMENT = 0;
  +  protected final static int ELEMENT = 1;
  +  protected final static int PREFIX_MAPPING = 2;
  +  protected final static int CDATA = 3;
  +  protected final static int DTD = 4;
  +  protected final static int ENTITY = 5;
  +
  +  protected class EventData {
  +    protected int eventType;
  +    protected String namespaceURI;
  +    protected String localName;
  +    protected String rawName;
  +    protected String prefix;
  +    protected String publicId;
  +    protected String systemId;
  +    protected String name;
  +
  +    protected EventData(int eventType) {
  +      this.eventType = eventType; // DOCUMENT | CDATA
  +    }
  +
  +    protected EventData(
  +      int eventType, String data1, String data2, String data3
  +    )
  +    {
  +      this.eventType = eventType;
  +      switch (this.eventType) {
  +        case ELEMENT:
  +          this.namespaceURI = data1;
  +          this.localName = data2;
  +          this.rawName = data3;
  +	  break;
  +        case DTD:
  +          this.name = data1;
  +          this.publicId = data2;
  +          this.systemId = data3;
  +	  break;
  +      }
  +    }
  +
  +    protected EventData(int eventType, String data) {
  +      this.eventType = eventType;
  +      switch (this.eventType) {
  +        case PREFIX_MAPPING:
  +	  this.prefix = data;
  +	  break;
  +	case ENTITY:
  +	  this.name = data;
  +	  break;
  +      }
  +    }
  +
  +    protected String getNamespaceURI() { return this.namespaceURI; }
  +    protected String getLocalName() { return this.localName; }
  +    protected String getRawName() { return this.rawName; }
  +    protected String getPrefix() { return this.prefix; }
  +    protected String getPublicId() { return this.publicId; }
  +    protected String getSystemId() { return this.systemId; }
  +    protected String getName() { return this.name; }
  +  }
  +}
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.7   +66 -60    xml-cocoon/src/org/apache/cocoon/matching/Attic/BrowserMatcherFactory.java
  
  Index: BrowserMatcherFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/matching/Attic/BrowserMatcherFactory.java,v
  retrieving revision 1.1.2.6
  retrieving revision 1.1.2.7
  diff -u -r1.1.2.6 -r1.1.2.7
  --- BrowserMatcherFactory.java	2000/07/22 20:41:49	1.1.2.6
  +++ BrowserMatcherFactory.java	2000/07/27 21:49:02	1.1.2.7
  @@ -1,60 +1,66 @@
  -/***************************************************************************** 
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        * 
  - * ------------------------------------------------------------------------- * 
  - * This software is published under the terms of the Apache Software License * 
  - * version 1.1, a copy of which has been included  with this distribution in * 
  - * the LICENSE file.                                                         * 
  - *****************************************************************************/ 
  -package org.apache.cocoon.matching; 
  -
  -import java.util.Stack;
  -
  -import org.w3c.dom.DocumentFragment;
  -import org.w3c.dom.Node;
  -import org.w3c.dom.NamedNodeMap;
  -import org.w3c.dom.traversal.TreeWalker;
  -import org.w3c.dom.traversal.NodeFilter;
  -
  -import org.apache.xerces.dom.TreeWalkerImpl;
  - 
  -/** 
  - * This class generates source code which matches a specific browser pattern
  - * for request URIs
  - * 
  - * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a> 
  - * @version CVS $Revision: 1.1.2.6 $ $Date: 2000/07/22 20:41:49 $ 
  - */ 
  -
  -public class BrowserMatcherFactory implements MatcherFactory {
  -    public String generateMethodLevel (String prefix, String test_expression, DocumentFragment conf) throws Exception {
  -        StringBuffer sb = new StringBuffer();
  -        TreeWalker tw = new TreeWalkerImpl (conf, NodeFilter.SHOW_ALL, null, false);
  -        Node node = null;
  -        Node nodea = null;
  -        NamedNodeMap nm = null;
  -
  -        sb.append ("/*\n");
  -        while ((node = tw.nextNode()) != null) {
  -            sb.append("name=")
  -              .append(node.getNodeName())
  -              .append(" type=")
  -              .append(node.getNodeType())
  -              .append(" value="+node.getNodeValue()+"\n");
  -            nm = node.getAttributes();
  -            if (nm != null) {
  -                int i = nm.getLength();
  -                for (int j = 0; j < i; j++) {
  -                    nodea = nm.item(j);
  -                    sb.append("name="+nodea.getNodeName())
  -                      .append(" type="+nodea.getNodeType())
  -                      .append(" value="+nodea.getNodeValue()+"\n");
  -                }
  -            }
  -        }
  -        return sb.append("*/\nreturn null;").toString();
  -    }
  -
  -    public String generateClassLevel (String prefix, String pattern, DocumentFragment conf) throws Exception {
  -        return "";
  -    }
  -}
  +/***************************************************************************** 
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        * 
  + * ------------------------------------------------------------------------- * 
  + * This software is published under the terms of the Apache Software License * 
  + * version 1.1, a copy of which has been included  with this distribution in * 
  + * the LICENSE file.                                                         * 
  + *****************************************************************************/ 
  +package org.apache.cocoon.matching; 
  +
  +import java.util.Stack;
  +
  +import org.w3c.dom.DocumentFragment;
  +import org.w3c.dom.Node;
  +import org.w3c.dom.NamedNodeMap;
  +import org.w3c.dom.traversal.TreeWalker;
  +import org.w3c.dom.traversal.NodeFilter;
  +
  +import org.apache.avalon.ConfigurationException;
  +
  +import org.apache.xerces.dom.TreeWalkerImpl;
  + 
  +/** 
  + * This class generates source code which matches a specific browser pattern
  + * for request URIs
  + * 
  + * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a> 
  + * @version CVS $Revision: 1.1.2.7 $ $Date: 2000/07/27 21:49:02 $ 
  + */ 
  +
  +public class BrowserMatcherFactory implements MatcherFactory {
  +    public String generateMethodSource (String prefix, String test_expression, 
  +                                        DocumentFragment conf)
  +    throws ConfigurationException {
  +        StringBuffer sb = new StringBuffer();
  +        TreeWalker tw = new TreeWalkerImpl (conf, NodeFilter.SHOW_ALL, null, false);
  +        Node node = null;
  +        Node nodea = null;
  +        NamedNodeMap nm = null;
  +
  +        sb.append ("/*\n");
  +        while ((node = tw.nextNode()) != null) {
  +            sb.append("name=")
  +              .append(node.getNodeName())
  +              .append(" type=")
  +              .append(node.getNodeType())
  +              .append(" value="+node.getNodeValue()+"\n");
  +            nm = node.getAttributes();
  +            if (nm != null) {
  +                int i = nm.getLength();
  +                for (int j = 0; j < i; j++) {
  +                    nodea = nm.item(j);
  +                    sb.append("name="+nodea.getNodeName())
  +                      .append(" type="+nodea.getNodeType())
  +                      .append(" value="+nodea.getNodeValue()+"\n");
  +                }
  +            }
  +        }
  +        return sb.append("*/\nreturn null;").toString();
  +    }
  +
  +    public String generateClassSource (String prefix, String pattern, 
  +                                       DocumentFragment conf)
  +    throws ConfigurationException {
  +        return "";
  +    }
  +}
  
  
  
  1.1.2.5   +32 -27    xml-cocoon/src/org/apache/cocoon/matching/Attic/MatcherFactory.java
  
  Index: MatcherFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/matching/Attic/MatcherFactory.java,v
  retrieving revision 1.1.2.4
  retrieving revision 1.1.2.5
  diff -u -r1.1.2.4 -r1.1.2.5
  --- MatcherFactory.java	2000/07/22 20:41:49	1.1.2.4
  +++ MatcherFactory.java	2000/07/27 21:49:02	1.1.2.5
  @@ -1,27 +1,32 @@
  -/***************************************************************************** 
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        * 
  - * ------------------------------------------------------------------------- * 
  - * This software is published under the terms of the Apache Software License * 
  - * version 1.1, a copy of which has been included  with this distribution in * 
  - * the LICENSE file.                                                         * 
  - *****************************************************************************/ 
  -package org.apache.cocoon.matching; 
  -
  -import org.w3c.dom.DocumentFragment;
  - 
  -/** 
  - * Interface a class has to implement that produces java source code 
  - * representing logic for a <code>Matcher</code>s match method. The 
  - * returned source code will be directly integrated into a method of the 
  - * generated sitemap code. 
  - * This <code>MatcherFactory</code>s generate method will be called during 
  - * sitemap code generation.
  - * 
  - * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a> 
  - * @version CVS $Revision: 1.1.2.4 $ $Date: 2000/07/22 20:41:49 $ 
  - */ 
  -
  -public interface MatcherFactory {
  -    public String generateClassLevel (String prefix, String pattern, DocumentFragment conf) throws Exception;
  -    public String generateMethodLevel (String prefix, String pattern, DocumentFragment conf) throws Exception;
  -}
  +/***************************************************************************** 
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        * 
  + * ------------------------------------------------------------------------- * 
  + * This software is published under the terms of the Apache Software License * 
  + * version 1.1, a copy of which has been included  with this distribution in * 
  + * the LICENSE file.                                                         * 
  + *****************************************************************************/ 
  +package org.apache.cocoon.matching; 
  +
  +import org.apache.avalon.ConfigurationException;
  +
  +import org.w3c.dom.DocumentFragment;
  + 
  +/** 
  + * Interface a class has to implement that produces java source code 
  + * representing logic for a <code>Matcher</code>s match method. The 
  + * returned source code will be directly integrated into a method of the 
  + * generated sitemap code. 
  + * This <code>MatcherFactory</code>s generate method will be called during 
  + * sitemap code generation.
  + * 
  + * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a> 
  + * @version CVS $Revision: 1.1.2.5 $ $Date: 2000/07/27 21:49:02 $ 
  + */ 
  +
  +public interface MatcherFactory {
  +    public String generateClassSource (String prefix, String pattern, DocumentFragment conf) 
  +    throws ConfigurationException;
  +
  +    public String generateMethodSource (String prefix, String pattern, DocumentFragment conf)
  +    throws ConfigurationException;
  +}
  
  
  
  1.1.2.4   +84 -74    xml-cocoon/src/org/apache/cocoon/matching/Attic/RegexpURIMatcherFactory.java
  
  Index: RegexpURIMatcherFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/matching/Attic/RegexpURIMatcherFactory.java,v
  retrieving revision 1.1.2.3
  retrieving revision 1.1.2.4
  diff -u -r1.1.2.3 -r1.1.2.4
  --- RegexpURIMatcherFactory.java	2000/07/22 20:41:49	1.1.2.3
  +++ RegexpURIMatcherFactory.java	2000/07/27 21:49:03	1.1.2.4
  @@ -1,74 +1,84 @@
  -/***************************************************************************** 
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        * 
  - * ------------------------------------------------------------------------- * 
  - * This software is published under the terms of the Apache Software License * 
  - * version 1.1, a copy of which has been included  with this distribution in * 
  - * the LICENSE file.                                                         * 
  - *****************************************************************************/ 
  -package org.apache.cocoon.matching; 
  -
  -import org.apache.regexp.RECompiler;
  -import org.apache.regexp.REProgram;
  -import org.apache.regexp.RESyntaxException;
  -
  -import org.w3c.dom.DocumentFragment;
  - 
  -/** 
  - * This class generates source code which represents a specific pattern matcher
  - * for request URIs
  - * 
  - * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a> 
  - * @version CVS $Revision: 1.1.2.3 $ $Date: 2000/07/22 20:41:49 $ 
  - */ 
  -
  -public class RegexpURIMatcherFactory implements MatcherFactory {
  -    public String generateClassLevel (String prefix, String pattern, DocumentFragment conf) throws Exception {
  -        StringBuffer sb = new StringBuffer ();
  -        RECompiler r = new RECompiler();
  -        String name         = prefix;
  -        String instructions = name + "PatternInstructions";
  -        sb.append("\n    // Pre-compiled regular expression '")
  -          .append(pattern).append("'\n")
  -          .append("    static char[] ");
  -        sb.append(instructions).append(" = \n    {");
  -        REProgram program = r.compile(pattern);
  -        int numColumns = 7;
  -        char[] p = program.getInstructions();
  -        for (int j = 0; j < p.length; j++) {
  -            if ((j % numColumns) == 0) {
  -                sb.append("\n        ");
  -            }
  -            String hex = Integer.toHexString(p[j]);
  -            while (hex.length() < 4) {
  -                hex = "0" + hex;
  -            }
  -            sb.append("0x").append(hex).append(", ");
  -        }
  -        sb.append("\n    };")
  -          .append("\n    static org.apache.regexp.RE ") 
  -          .append(name)
  -          .append("Pattern = new org.apache.regexp.RE(new org.apache.regexp.REProgram(")
  -          .append(instructions)
  -          .append("));");
  -        return sb.toString();
  -    }
  -
  -    public String generateMethodLevel (String prefix, String pattern, DocumentFragment conf) throws Exception {
  -        StringBuffer sb = new StringBuffer ();
  -        String name         = prefix;
  -        String instructions = name + "PatternInstructions";
  -        sb.append("java.util.ArrayList list = new java.util.ArrayList ();")
  -          .append("if (").append(name).append("Pattern.match(environment.getUri())) {");
  -        // Count number of parens
  -        int i = 0;
  -        int j = -1;
  -        while ((j = pattern.indexOf('(', j+1)) != -1) {
  -            if (j == 0 || pattern.charAt(j-1) != '\\') {
  -                sb.append("list.add (").append(name).append("Pattern.getParen(")
  -                  .append(++i).append("));");
  -            }
  -        }
  -        sb.append("return list; } else { return null; }");
  -        return sb.toString();
  -    }
  -}
  +/***************************************************************************** 
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        * 
  + * ------------------------------------------------------------------------- * 
  + * This software is published under the terms of the Apache Software License * 
  + * version 1.1, a copy of which has been included  with this distribution in * 
  + * the LICENSE file.                                                         * 
  + *****************************************************************************/ 
  +package org.apache.cocoon.matching; 
  +
  +import org.apache.regexp.RECompiler;
  +import org.apache.regexp.REProgram;
  +import org.apache.regexp.RESyntaxException;
  +
  +import org.apache.avalon.ConfigurationException;
  +
  +import org.w3c.dom.DocumentFragment;
  + 
  +/** 
  + * This class generates source code which represents a specific pattern matcher
  + * for request URIs
  + * 
  + * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a> 
  + * @version CVS $Revision: 1.1.2.4 $ $Date: 2000/07/27 21:49:03 $ 
  + */ 
  +
  +public class RegexpURIMatcherFactory implements MatcherFactory {
  +    public String generateClassSource (String prefix, String pattern, 
  +                                       DocumentFragment conf) 
  +    throws ConfigurationException {
  +        StringBuffer sb = new StringBuffer ();
  +        try {
  +            RECompiler r = new RECompiler();
  +            String name         = prefix;
  +            String instructions = name + "PatternInstructions";
  +            sb.append("\n    // Pre-compiled regular expression '")
  +              .append(pattern).append("'\n")
  +              .append("    static char[] ");
  +            sb.append(instructions).append(" = \n    {");
  +            REProgram program = r.compile(pattern);
  +            int numColumns = 7;
  +            char[] p = program.getInstructions();
  +            for (int j = 0; j < p.length; j++) {
  +                if ((j % numColumns) == 0) {
  +                    sb.append("\n        ");
  +                }
  +                String hex = Integer.toHexString(p[j]);
  +                while (hex.length() < 4) {
  +                    hex = "0" + hex;
  +                }
  +                sb.append("0x").append(hex).append(", ");
  +            }
  +            sb.append("\n    };")
  +              .append("\n    static org.apache.regexp.RE ") 
  +              .append(name)
  +              .append("Pattern = new org.apache.regexp.RE(new org.apache.regexp.REProgram(")
  +              .append(instructions)
  +              .append("));");
  +            return sb.toString();
  +        } catch (RESyntaxException rse) {
  +            throw new ConfigurationException (rse.getMessage(), null);
  +        }
  +    }
  +
  +    public String generateMethodSource (String prefix, String pattern, 
  +                                        DocumentFragment conf) 
  +    throws ConfigurationException {
  +        StringBuffer sb = new StringBuffer ();
  +        String name         = prefix;
  +        String instructions = name + "PatternInstructions";
  +        sb.append("java.util.ArrayList list = new java.util.ArrayList ();")
  +          .append("if (").append(name).append("Pattern.match(environment.getUri())) {");
  +        // Count number of parens
  +        int i = 0;
  +        int j = -1;
  +        while ((j = pattern.indexOf('(', j+1)) != -1) {
  +            if (j == 0 || pattern.charAt(j-1) != '\\') {
  +                sb.append("list.add (").append(name).append("Pattern.getParen(")
  +                  .append(++i).append("));");
  +            }
  +        }
  +        sb.append("return list; } else { return null; }");
  +        return sb.toString();
  +    }
  +}
  
  
  
  1.1.2.6   +169 -161  xml-cocoon/src/org/apache/cocoon/matching/Attic/WildcardURIMatcherFactory.java
  
  Index: WildcardURIMatcherFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/matching/Attic/WildcardURIMatcherFactory.java,v
  retrieving revision 1.1.2.5
  retrieving revision 1.1.2.6
  diff -u -r1.1.2.5 -r1.1.2.6
  --- WildcardURIMatcherFactory.java	2000/07/22 20:41:49	1.1.2.5
  +++ WildcardURIMatcherFactory.java	2000/07/27 21:49:03	1.1.2.6
  @@ -1,161 +1,169 @@
  -/***************************************************************************** 
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        * 
  - * ------------------------------------------------------------------------- * 
  - * This software is published under the terms of the Apache Software License * 
  - * version 1.1, a copy of which has been included  with this distribution in * 
  - * the LICENSE file.                                                         * 
  - *****************************************************************************/ 
  -package org.apache.cocoon.matching; 
  -
  -import org.apache.cocoon.sitemap.patterns.PatternTranslator; 
  -import org.apache.cocoon.sitemap.patterns.PatternException; 
  -
  -import org.w3c.dom.DocumentFragment;
  - 
  -/** 
  - * This class generates source code which represents a specific pattern matcher
  - * for request URIs
  - * 
  - * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a> 
  - * @version CVS $Revision: 1.1.2.5 $ $Date: 2000/07/22 20:41:49 $ 
  - */ 
  -
  -public class WildcardURIMatcherFactory /*extends PatternTranslator*/ implements MatcherFactory {
  -
  -    /** The int representing '*' in the pattern <code>int []</code>. */
  -    protected static final int MATCH_FILE=-1;
  -    /** The int representing '**' in the pattern <code>int []</code>. */
  -    protected static final int MATCH_PATH=-2;
  -    /** The int value that terminates the pattern <code>int []</code>. */
  -    protected static final int MATCH_END=-3;
  -
  -    /** The <code>int []</code> identifying the pattern to match. */
  -    protected int[] sourcePattern=null;
  -
  -    /**
  -     * Generates the matcher method level source code
  -     */
  -    public String generateMethodLevel (String prefix, String pattern, DocumentFragment conf) 
  -    throws PatternException {
  -        StringBuffer result = new StringBuffer();
  -        return result.append ("java.util.ArrayList list = new ArrayList();")
  -                     .append ("if (org.apache.cocoon.matching.helpers.WildcardURIMatcher.match (list, environment.getUri(), ")
  -                     .append(prefix).append("_expr))")
  -                     .append ("return list;")
  -                     .append ("else return null;").toString();
  -    }
  -
  -    /**
  -     * Generates the matcher class level source code
  -     */
  -    public String generateClassLevel (String prefix, String pattern, DocumentFragment conf) 
  -    throws PatternException {
  -        StringBuffer result = new StringBuffer();
  -        this.setPattern (pattern);
  -   
  -        result.append ("/* pattern=\""+pattern+"\" */")
  -              .append ("int expr[] = {");
  -
  -        int j = sourcePattern.length-1;
  -        char c;
  -        for (int i = 0; i < j; i++) {
  -            result.append (sourcePattern[i])
  -                  .append (',');
  -        }
  -        return result.append (sourcePattern[j])
  -                     .append ("};").toString();
  -    }
  -
  -    /**
  -     * Set the pattern for matching.
  -     */
  -    public void setPattern(String pattern)
  -    throws PatternException {
  -        if (pattern==null) throw new PatternException("Null pattern");
  -        this.sourcePattern=this.convertPattern(pattern);
  -    }
  -
  -    /**
  -     * Translate the given <code>String</code> into a <code>int []</code>
  -     * representing the pattern matchable by this class.
  -     * <br>
  -     * This function translates a <code>String</code> into an int array
  -     * converting the special '*' and '\' characters.
  -     * <br>
  -     * Here is how the conversion algorithm works:
  -     * <ul>
  -     *   <li>The '*' character is converted to MATCH_FILE, meaning that zero
  -     *        or more characters (excluding the path separator '/') are to
  -     *        be matched.</li>
  -     *   <li>The '**' sequence is converted to MATCH_PATH, meaning that zero
  -     *       or more characters (including the path separator '/') are to
  -     *        be matched.</li>
  -     *   <li>The '\' character is used as an escape sequence ('\*' is
  -     *       translated in '*', not in MATCH_FILE). If an exact '\' character
  -     *       is to be matched the source string must contain a '\\'.
  -     *       sequence.</li>
  -     * </ul>
  -     * When more than two '*' characters, not separated by another character,
  -     * are found their value is considered as '**' (MATCH_PATH).
  -     * <br>
  -     * The array is always terminated by a special value (MATCH_END).
  -     * <br>
  -     * All MATCH* values are less than zero, while normal characters are equal
  -     * or greater.
  -     *
  -     * @parameter data The string to translate.
  -     * @return The encoded string as an int array, terminated by the MATCH_END
  -     *         value (don't consider the array length).
  -     * @exception NullPointerException If data is null.
  -     */
  -    protected int[] convertPattern(String data)
  -    throws NullPointerException {
  -        // Prepare the arrays
  -        int expr[]=new int[data.length()+1];
  -        char buff[]=data.toCharArray();
  -        // Prepare variables for the translation loop
  -        int y=0;
  -        boolean slash=false;
  -        if(buff[0]=='\\') slash=true;
  -        else if(buff[0]=='*') expr[y++]=MATCH_FILE;
  -        else expr[y++]=buff[0];
  -        // Main translation loop
  -        for (int x=1; x<buff.length; x++) {
  -            // If the previous char was '\' simply copy this char.
  -            if (slash) {
  -                expr[y++]=buff[x];
  -                slash=false;
  -            // If the previous char was not '\' we have to do a bunch of checks
  -            } else {
  -                int prev=(y-1);
  -                // If this char is '\' declare that and continue
  -                if(buff[x]=='\\') {
  -                    slash=true;
  -                // If this char is '*' check the previous one
  -                } else if(buff[x]=='*') {
  -                    // If the previous character als was '*' match a path
  -                    if(expr[y-1]<=MATCH_FILE) expr[y-1]=MATCH_PATH;
  -                    else expr[y++]=MATCH_FILE;
  -                } else expr[y++]=buff[x];
  -            }
  -        }
  -        // Declare the end of the array and return it
  -        expr[y]=MATCH_END;
  -        return(expr);
  -    }        
  -     
  -    /** Testing */
  -    public static void main(String argv[]) {
  -        try {
  -            if (argv.length<1) return;
  -            System.out.println("Matching Expr.    \""+argv[0]+"\"");
  -            WildcardURIMatcherFactory wm = new WildcardURIMatcherFactory();
  -            System.out.println(wm.generateClassLevel ("", argv[0], null));
  -            System.out.println(wm.generateMethodLevel ("", argv[0], null));
  -        } catch (Exception e) {
  -            System.out.println(e.getClass().getName());
  -            System.out.println(e.getMessage());
  -        }
  -    }
  -
  -}
  +/***************************************************************************** 
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        * 
  + * ------------------------------------------------------------------------- * 
  + * This software is published under the terms of the Apache Software License * 
  + * version 1.1, a copy of which has been included  with this distribution in * 
  + * the LICENSE file.                                                         * 
  + *****************************************************************************/ 
  +package org.apache.cocoon.matching; 
  +
  +import org.apache.cocoon.sitemap.patterns.PatternTranslator; 
  +import org.apache.cocoon.sitemap.patterns.PatternException; 
  +
  +import org.apache.avalon.ConfigurationException;
  +
  +import org.w3c.dom.DocumentFragment;
  + 
  +/** 
  + * This class generates source code which represents a specific pattern matcher
  + * for request URIs
  + * 
  + * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a> 
  + * @version CVS $Revision: 1.1.2.6 $ $Date: 2000/07/27 21:49:03 $ 
  + */ 
  +
  +public class WildcardURIMatcherFactory /*extends PatternTranslator*/ implements MatcherFactory {
  +
  +    /** The int representing '*' in the pattern <code>int []</code>. */
  +    protected static final int MATCH_FILE=-1;
  +    /** The int representing '**' in the pattern <code>int []</code>. */
  +    protected static final int MATCH_PATH=-2;
  +    /** The int value that terminates the pattern <code>int []</code>. */
  +    protected static final int MATCH_END=-3;
  +
  +    /** The <code>int []</code> identifying the pattern to match. */
  +    protected int[] sourcePattern=null;
  +
  +    /**
  +     * Generates the matcher method level source code
  +     */
  +    public String generateMethodSource (String prefix, String pattern, 
  +                                        DocumentFragment conf) 
  +    throws ConfigurationException {
  +        StringBuffer result = new StringBuffer();
  +        return result.append ("java.util.ArrayList list = new ArrayList();")
  +                     .append ("if (org.apache.cocoon.matching.helpers.WildcardURIMatcher.match (list, environment.getUri(), ")
  +                     .append(prefix).append("_expr))")
  +                     .append ("return list;")
  +                     .append ("else return null;").toString();
  +    }
  +
  +    /**
  +     * Generates the matcher class level source code
  +     */
  +    public String generateClassSource (String prefix, String pattern, 
  +                                       DocumentFragment conf) 
  +    throws ConfigurationException {
  +        StringBuffer result = new StringBuffer();
  +        try {
  +            this.setPattern (pattern);
  +   
  +            result.append ("/* pattern=\""+pattern+"\" */")
  +                  .append ("int expr[] = {");
  +
  +            int j = sourcePattern.length-1;
  +            char c;
  +            for (int i = 0; i < j; i++) {
  +                result.append (sourcePattern[i])
  +                      .append (',');
  +            }
  +            return result.append (sourcePattern[j])
  +                         .append ("};").toString();
  +        } catch (PatternException pe) {
  +            throw new ConfigurationException (pe.getMessage(), null);
  +        }
  +    }
  +
  +    /**
  +     * Set the pattern for matching.
  +     */
  +    public void setPattern(String pattern)
  +    throws PatternException {
  +        if (pattern==null) throw new PatternException("Null pattern");
  +        this.sourcePattern=this.convertPattern(pattern);
  +    }
  +
  +    /**
  +     * Translate the given <code>String</code> into a <code>int []</code>
  +     * representing the pattern matchable by this class.
  +     * <br>
  +     * This function translates a <code>String</code> into an int array
  +     * converting the special '*' and '\' characters.
  +     * <br>
  +     * Here is how the conversion algorithm works:
  +     * <ul>
  +     *   <li>The '*' character is converted to MATCH_FILE, meaning that zero
  +     *        or more characters (excluding the path separator '/') are to
  +     *        be matched.</li>
  +     *   <li>The '**' sequence is converted to MATCH_PATH, meaning that zero
  +     *       or more characters (including the path separator '/') are to
  +     *        be matched.</li>
  +     *   <li>The '\' character is used as an escape sequence ('\*' is
  +     *       translated in '*', not in MATCH_FILE). If an exact '\' character
  +     *       is to be matched the source string must contain a '\\'.
  +     *       sequence.</li>
  +     * </ul>
  +     * When more than two '*' characters, not separated by another character,
  +     * are found their value is considered as '**' (MATCH_PATH).
  +     * <br>
  +     * The array is always terminated by a special value (MATCH_END).
  +     * <br>
  +     * All MATCH* values are less than zero, while normal characters are equal
  +     * or greater.
  +     *
  +     * @parameter data The string to translate.
  +     * @return The encoded string as an int array, terminated by the MATCH_END
  +     *         value (don't consider the array length).
  +     * @exception NullPointerException If data is null.
  +     */
  +    protected int[] convertPattern(String data)
  +    throws NullPointerException {
  +        // Prepare the arrays
  +        int expr[]=new int[data.length()+1];
  +        char buff[]=data.toCharArray();
  +        // Prepare variables for the translation loop
  +        int y=0;
  +        boolean slash=false;
  +        if(buff[0]=='\\') slash=true;
  +        else if(buff[0]=='*') expr[y++]=MATCH_FILE;
  +        else expr[y++]=buff[0];
  +        // Main translation loop
  +        for (int x=1; x<buff.length; x++) {
  +            // If the previous char was '\' simply copy this char.
  +            if (slash) {
  +                expr[y++]=buff[x];
  +                slash=false;
  +            // If the previous char was not '\' we have to do a bunch of checks
  +            } else {
  +                int prev=(y-1);
  +                // If this char is '\' declare that and continue
  +                if(buff[x]=='\\') {
  +                    slash=true;
  +                // If this char is '*' check the previous one
  +                } else if(buff[x]=='*') {
  +                    // If the previous character als was '*' match a path
  +                    if(expr[y-1]<=MATCH_FILE) expr[y-1]=MATCH_PATH;
  +                    else expr[y++]=MATCH_FILE;
  +                } else expr[y++]=buff[x];
  +            }
  +        }
  +        // Declare the end of the array and return it
  +        expr[y]=MATCH_END;
  +        return(expr);
  +    }        
  +     
  +    /** Testing */
  +    public static void main(String argv[]) {
  +        try {
  +            if (argv.length<1) return;
  +            System.out.println("Matching Expr.    \""+argv[0]+"\"");
  +            WildcardURIMatcherFactory wm = new WildcardURIMatcherFactory();
  +            System.out.println(wm.generateClassSource ("", argv[0], null));
  +            System.out.println(wm.generateMethodSource ("", argv[0], null));
  +        } catch (Exception e) {
  +            System.out.println(e.getClass().getName());
  +            System.out.println(e.getMessage());
  +        }
  +    }
  +
  +}
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.5   +33 -29    xml-cocoon/src/org/apache/cocoon/selection/Attic/BrowserSelectorFactory.java
  
  Index: BrowserSelectorFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/selection/Attic/BrowserSelectorFactory.java,v
  retrieving revision 1.1.2.4
  retrieving revision 1.1.2.5
  diff -u -r1.1.2.4 -r1.1.2.5
  --- BrowserSelectorFactory.java	2000/07/22 20:41:51	1.1.2.4
  +++ BrowserSelectorFactory.java	2000/07/27 21:49:03	1.1.2.5
  @@ -1,29 +1,33 @@
  -/***************************************************************************** 
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        * 
  - * ------------------------------------------------------------------------- * 
  - * This software is published under the terms of the Apache Software License * 
  - * version 1.1, a copy of which has been included  with this distribution in * 
  - * the LICENSE file.                                                         * 
  - *****************************************************************************/ 
  -package org.apache.cocoon.selection; 
  -
  -import org.w3c.dom.DocumentFragment;
  - 
  -/** 
  - * This class generates source code which tests a specific browser pattern
  - * agains the requesting user-agent
  - * 
  - * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a> 
  - * @version CVS $Revision: 1.1.2.4 $ $Date: 2000/07/22 20:41:51 $ 
  - */ 
  -
  -public class BrowserSelectorFactory implements SelectorFactory {
  -
  -    public String generateClassLevel (String test, String prefix, DocumentFragment conf) throws Exception {
  -        return "";
  -    }
  -
  -    public String generateMethodLevel (String test, String prefix, DocumentFragment conf) throws Exception {
  -        return "return true;";
  -    }
  -}
  +/***************************************************************************** 
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        * 
  + * ------------------------------------------------------------------------- * 
  + * This software is published under the terms of the Apache Software License * 
  + * version 1.1, a copy of which has been included  with this distribution in * 
  + * the LICENSE file.                                                         * 
  + *****************************************************************************/ 
  +package org.apache.cocoon.selection; 
  +
  +import org.apache.avalon.ConfigurationException;
  +
  +import org.w3c.dom.DocumentFragment;
  + 
  +/** 
  + * This class generates source code which tests a specific browser pattern
  + * agains the requesting user-agent
  + * 
  + * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a> 
  + * @version CVS $Revision: 1.1.2.5 $ $Date: 2000/07/27 21:49:03 $ 
  + */ 
  +
  +public class BrowserSelectorFactory implements SelectorFactory {
  +
  +    public String generateClassSource (String test, String prefix, DocumentFragment conf) 
  +    throws ConfigurationException {
  +        return "";
  +    }
  +
  +    public String generateMethodSource (String test, String prefix, DocumentFragment conf)
  +    throws ConfigurationException {
  +        return "return true;";
  +    }
  +}
  
  
  
  1.1.2.5   +32 -27    xml-cocoon/src/org/apache/cocoon/selection/Attic/SelectorFactory.java
  
  Index: SelectorFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/selection/Attic/SelectorFactory.java,v
  retrieving revision 1.1.2.4
  retrieving revision 1.1.2.5
  diff -u -r1.1.2.4 -r1.1.2.5
  --- SelectorFactory.java	2000/07/22 20:41:52	1.1.2.4
  +++ SelectorFactory.java	2000/07/27 21:49:04	1.1.2.5
  @@ -1,27 +1,32 @@
  -/***************************************************************************** 
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        * 
  - * ------------------------------------------------------------------------- * 
  - * This software is published under the terms of the Apache Software License * 
  - * version 1.1, a copy of which has been included  with this distribution in * 
  - * the LICENSE file.                                                         * 
  - *****************************************************************************/ 
  -package org.apache.cocoon.selection; 
  -
  -import org.w3c.dom.DocumentFragment;
  - 
  -/** 
  - * Interface a class has to implement that produces java source code 
  - * representing logic for a <code>Selector</code>s select method. The 
  - * returned source code will be directly integrated into a method of the 
  - * generated sitemap code. 
  - * This <code>SelectorFactory</code>s generate method will be called during 
  - * sitemap code generation.
  - * 
  - * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a> 
  - * @version CVS $Revision: 1.1.2.4 $ $Date: 2000/07/22 20:41:52 $ 
  - */ 
  -
  -public interface SelectorFactory {
  -    public String generateClassLevel (String test, String prefix, DocumentFragment conf) throws Exception;
  -    public String generateMethodLevel (String test, String prefix, DocumentFragment conf) throws Exception;
  -}
  +/***************************************************************************** 
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        * 
  + * ------------------------------------------------------------------------- * 
  + * This software is published under the terms of the Apache Software License * 
  + * version 1.1, a copy of which has been included  with this distribution in * 
  + * the LICENSE file.                                                         * 
  + *****************************************************************************/ 
  +package org.apache.cocoon.selection; 
  +
  +import org.apache.avalon.ConfigurationException;
  +
  +import org.w3c.dom.DocumentFragment;
  + 
  +/** 
  + * Interface a class has to implement that produces java source code 
  + * representing logic for a <code>Selector</code>s select method. The 
  + * returned source code will be directly integrated into a method of the 
  + * generated sitemap code. 
  + * This <code>SelectorFactory</code>s generate method will be called during 
  + * sitemap code generation.
  + * 
  + * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a> 
  + * @version CVS $Revision: 1.1.2.5 $ $Date: 2000/07/27 21:49:04 $ 
  + */ 
  +
  +public interface SelectorFactory {
  +    public String generateClassSource (String test, String prefix, DocumentFragment conf) 
  +    throws ConfigurationException;
  +
  +    public String generateMethodSource (String test, String prefix, DocumentFragment conf) 
  +    throws ConfigurationException;
  +}
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.2   +134 -153  xml-cocoon/src/org/apache/cocoon/sitemap/Attic/AbstractSitemap.java
  
  Index: AbstractSitemap.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/sitemap/Attic/AbstractSitemap.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- AbstractSitemap.java	2000/07/23 00:04:11	1.1.2.1
  +++ AbstractSitemap.java	2000/07/27 21:49:05	1.1.2.2
  @@ -1,169 +1,150 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -package org.apache.cocoon.sitemap;
  -
  -import java.io.File;
  -import java.io.IOException;
  -import java.io.OutputStream;
  -import java.util.List;
  -
  -import org.apache.avalon.ComponentManager;
  -import org.apache.avalon.Component;
  -import org.apache.avalon.Composer;
  -import org.apache.avalon.Configurable;
  -import org.apache.avalon.Configuration;
  -import org.apache.cocoon.ProcessingException; 
  -import org.apache.cocoon.Processor; 
  -import org.apache.cocoon.environment.Environment; 
  -import org.apache.cocoon.sitemap.patterns.PatternException;
  -
  -import org.xml.sax.SAXException; 
  -
  -/**
  - * Base class for generated <code>Sitemap</code> classes
  - *
  - * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
  - * @version CVS $Revision: 1.1.2.1 $ $Date: 2000/07/23 00:04:11 $
  - */
  -public abstract class AbstractSitemap
  -         implements Sitemap {      
  +/*****************************************************************************
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  + * ------------------------------------------------------------------------- *
  + * This software is published under the terms of the Apache Software License *
  + * version 1.1, a copy of which has been included  with this distribution in *
  + * the LICENSE file.                                                         *
  + *****************************************************************************/
  +package org.apache.cocoon.sitemap;
  +
  +import java.io.File;
  +import java.io.IOException;
  +import java.io.OutputStream;
  +import java.util.List;
  +
  +import org.apache.avalon.ComponentManager;
  +import org.apache.avalon.Component;
  +import org.apache.avalon.Composer;
  +import org.apache.avalon.Configurable;
  +import org.apache.avalon.Configuration;
  +import org.apache.cocoon.ProcessingException; 
  +import org.apache.cocoon.Processor; 
  +import org.apache.cocoon.environment.Environment; 
  +import org.apache.cocoon.sitemap.patterns.PatternException;
  +
  +import org.xml.sax.SAXException; 
  +
  +/**
  + * Base class for generated <code>Sitemap</code> classes
  + *
  + * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
  + * @version CVS $Revision: 1.1.2.2 $ $Date: 2000/07/27 21:49:05 $
  + */
  +public abstract class AbstractSitemap
  +         implements Sitemap {      
       /** The component manager instance */  
       protected ComponentManager manager=null;  
    
       /** The sitemap manager instance */  
       protected SitemapManager sitemapManager=null;  
  - 
  -    /** The base path of this sitemap */ 
  -    protected String basePath = null; 
  -
  -    /** The creation date */
  -    protected static long dateCreated = -1L;
  +
  +    /** The creation date */
  +    protected static long dateCreated = -1L;
     
       /**  
        * Set the current <code>ComponentManager</code> instance used by this  
        * <code>Composer</code>.  
        */  
       public void setComponentManager(ComponentManager manager) {  
  +System.out.println ("AbstractSitemap.setComponentManager manager = "+(manager==null?"null":"set"));
           this.manager=manager;  
  -    }  
  -  
  -    /**  
  -     * Set the current base path.  
  -     */  
  -    public void setBasePath(String basePath) {  
  -        this.basePath=basePath;  
       }  
  -
  -    /**
  -     * Determines whether this generator's source files have changed
  -     *
  -     * @return Whether any of the files this sitemap depends on has changed
  -     * since it was created
  -     */
  -    public final boolean modifiedSince(long date) {
  -        if (dateCreated < date) {
  -            return true;
  -        }

  -        return false;
  -    }
  -
  -    /**
  -     * Determines whether generated content has changed since
  -     * last invocation. Users may override this method to take
  -     * advantage of SAX event cacheing
  -     *
  -     * @param request The request whose data must be inspected to assert whether
  -     * dynamically generated content has changed
  -     * @return Whether content has changes for this request's data
  -     */
  -    public boolean hasContentChanged(Environment environment) {
  -        return true;
  -    }
  -
  -     /** 
  -      * Loads a class specified in a sitemap component definition and
  -      * initialize it
  -      */ 
  -    protected Component load_component (String classURL, Configuration conf) 
  -    throws ClassNotFoundException, InstantiationException, IllegalAccessException {
  -        Class cl = this.getClass().getClassLoader().loadClass(classURL);
  -        Object comp = cl.newInstance();
  -        if (comp instanceof Composer) {
  -            ((Composer)comp).setComponentManager (this.manager);
  -        }
  -        if (comp instanceof Configurable) {
  -            ((Configurable)comp).setConfiguration (conf);
  -        }
  -        return ((SitemapComponent)comp); 
  -    } 
  -
  -     /** 
  -      * Replaces occurences of xpath like expressions ina argument String
  -      * with content from a List of Lists
  -      */ 
  -    protected String substitute (List list, String expr) 
  -    throws PatternException, NumberFormatException {
  -        StringBuffer result = new StringBuffer();
  -        String s = null;
  -        int j = 0;
  -        int k = 0;
  -        int l = 0;
  -        int m = 0;
  -        int n = 0;
  -        int ii = 0;
  -        int i = -1;
  -        try {
  -            while (ii <= expr.length() && (i = expr.indexOf('{', ii)) != -1) {
  -                result.append(expr.substring(ii, i));
  -                j = expr.indexOf('}', i);
  -                if (j < i) 
  -                    throw new PatternException ("invalid expression in \""+expr+"\"");
  -                ii = j+1;
  -                if (j == -1) 
  -                    throw new PatternException ("invalid expression in URL "+expr);
  -                k = list.size() - 1;
  -                s = expr.substring (i+1,j);
  -                for (l = -1; (l = s.indexOf("../",l+1)) != -1; k--);
  -                m = s.lastIndexOf('/');
  -                if (m == -1) {
  -                    n = Integer.parseInt(s) - 1;
  -                } else {
  -                    n = Integer.parseInt(s.substring(m+1)) - 1;
  -                }
  -                result.append((String)((List)list.get(k)).get(n));
  -            }
  -            if (ii < expr.length()) {
  -                result.append(expr.substring(ii));
  -            }
  -            return (result.toString()); 
  -        } catch (Exception e) {
  -            throw new PatternException 
  -                    ("error occurred during evaluation of expression \""
  -                     +expr+"\" at position "+(i+1)+"\n"
  -                     + e.getMessage());        
  -        }
  -    }
  -
  -    /**
  -     * Make a relative source absolute.
  -     */
  -    protected String makeAbsolute(String source) { 
  -        if (source.charAt(0) != '/') {
  -           return basePath+source;
  +
  +    /**
  +     * Determines whether this generator's source files have changed
  +     *
  +     * @return Whether any of the files this sitemap depends on has changed
  +     * since it was created
  +     */
  +    public final boolean modifiedSince(long date) {
  +        if (dateCreated < date) {
  +            return true;
  +        }
  +        return false;
  +    }
  +
  +    /**
  +     * Determines whether generated content has changed since
  +     * last invocation. Users may override this method to take
  +     * advantage of SAX event cacheing
  +     *
  +     * @param request The request whose data must be inspected to assert whether
  +     * dynamically generated content has changed
  +     * @return Whether content has changes for this request's data
  +     */
  +    public boolean hasContentChanged(Environment environment) {
  +        return true;
  +    }
  +
  +     /** 
  +      * Loads a class specified in a sitemap component definition and
  +      * initialize it
  +      */ 
  +    protected Component load_component (String classURL, Configuration conf) 
  +    throws ClassNotFoundException, InstantiationException, IllegalAccessException {
  +        Class cl = this.getClass().getClassLoader().loadClass(classURL);
  +        Object comp = cl.newInstance();
  +        if (comp instanceof Composer) {
  +            ((Composer)comp).setComponentManager (this.manager);
  +        }
  +        if (comp instanceof Configurable) {
  +            ((Configurable)comp).setConfiguration (conf);
  +        }
  +        return ((SitemapComponent)comp); 
  +    } 
  +
  +     /** 
  +      * Replaces occurences of xpath like expressions in an argument String
  +      * with content from a List of Lists
  +      */ 
  +    protected String substitute (List list, String expr) 
  +    throws PatternException, NumberFormatException {
  +        StringBuffer result = new StringBuffer();
  +        String s = null;
  +        int j = 0;
  +        int k = 0;
  +        int l = 0;
  +        int m = 0;
  +        int n = 0;
  +        int ii = 0;
  +        int i = -1;
  +        try {
  +            while (ii <= expr.length() && (i = expr.indexOf('{', ii)) != -1) {
  +                result.append(expr.substring(ii, i));
  +                j = expr.indexOf('}', i);
  +                if (j < i) 
  +                    throw new PatternException ("invalid expression in \""+expr+"\"");
  +                ii = j+1;
  +                if (j == -1) 
  +                    throw new PatternException ("invalid expression in URL "+expr);
  +                k = list.size() - 1;
  +                s = expr.substring (i+1,j);
  +                for (l = -1; (l = s.indexOf("../",l+1)) != -1; k--);
  +                m = s.lastIndexOf('/');
  +                if (m == -1) {
  +                    n = Integer.parseInt(s) - 1;
  +                } else {
  +                    n = Integer.parseInt(s.substring(m+1)) - 1;
  +                }
  +                result.append((String)((List)list.get(k)).get(n));
  +            }
  +            if (ii < expr.length()) {
  +                result.append(expr.substring(ii));
  +            }
  +            return (result.toString()); 
  +        } catch (Exception e) {
  +            throw new PatternException 
  +                    ("error occurred during evaluation of expression \""
  +                     +expr+"\" at position "+(i+1)+"\n"
  +                     + e.getMessage());        
           }
  -        return(source); 
  -    } 
  -
  -    /**
  -     * Constructs a resource to the supplied <code>OutputStream</code>
  -     * for the <code>Request</code> and <code>Response</code> arguments.
  -     * This method is supplied by the generated Sitemap.
  -     */
  +    }
  +
  +    /**
  +     * Constructs a resource to the supplied <code>OutputStream</code>
  +     * for the <code>Request</code> and <code>Response</code> arguments.
  +     * This method is supplied by the generated Sitemap.
  +     */
       public abstract boolean process (Environment environment, OutputStream out)
  -    throws SAXException, IOException, ProcessingException;
  +    throws Exception;
   } 
  
  
  
  1.1.2.8   +147 -109  xml-cocoon/src/org/apache/cocoon/sitemap/Attic/ResourcePipeline.java
  
  Index: ResourcePipeline.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/sitemap/Attic/ResourcePipeline.java,v
  retrieving revision 1.1.2.7
  retrieving revision 1.1.2.8
  diff -u -r1.1.2.7 -r1.1.2.8
  --- ResourcePipeline.java	2000/07/25 18:48:44	1.1.2.7
  +++ ResourcePipeline.java	2000/07/27 21:49:05	1.1.2.8
  @@ -1,109 +1,147 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -package org.apache.cocoon.sitemap;
  -
  -import java.util.Vector;
  -import java.io.IOException;
  -import java.io.OutputStream;
  -
  -//import org.apache.avalon.ConfigurationException;
  -import org.apache.avalon.utils.Parameters;
  -import org.apache.cocoon.ProcessingException;
  -import org.apache.cocoon.environment.Environment;
  -import org.apache.cocoon.generation.Generator;
  -import org.apache.cocoon.reading.Reader;
  -import org.apache.cocoon.transformation.Transformer;
  -import org.apache.cocoon.serialization.Serializer;
  -import org.apache.cocoon.xml.XMLProducer;
  -
  -import org.xml.sax.SAXException;
  -
  -/**
  - *
  - * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
  - * @version CVS $Revision: 1.1.2.7 $ $Date: 2000/07/25 18:48:44 $
  - */
  -public class ResourcePipeline {
  -    private Generator generator = null;
  -    private Parameters generatorParam = null;
  -    private String generatorSource = null;
  -    private Reader reader = null;
  -    private Parameters readerParam = null;
  -    private String readerSource = null;
  -    private Vector transformers = new Vector();
  -    private Vector transformerParams = new Vector();
  -    private Vector transformerSources = new Vector();
  -    private Serializer serializer = null;
  -    private Parameters serializerParam = null;
  -    private String serializerSource = null;
  -    private boolean isReader = false;
  -
  -    public ResourcePipeline () {
  -    }
  -
  -    public void setGenerator (Generator generator, String source, Parameters param) {
  -        this.generator = generator;
  -        this.generatorSource = source;
  -        this.generatorParam = param;
  -    }
  -
  -    public void setReader (Reader reader, String source, Parameters param) {
  -        this.reader = reader;
  -        this.readerSource = source;
  -        this.readerParam = param;
  -        this.isReader = true;
  -    }
  -
  -    public void setSerializer (Serializer serializer, String source, Parameters param) {
  -        this.serializer = serializer;
  -        this.serializerSource = source;
  -        this.serializerParam = param;
  -    }
  -
  -    public void addTransformer (Transformer transformer, String source, Parameters param) {
  -        this.transformers.add (transformer);
  -        this.transformerSources.add (source);
  -        this.transformerParams.add (param);
  -    }
  -
  -    public boolean process (Environment environment, OutputStream out)
  -                            throws ProcessingException, IOException, SAXException {
  -        if (isReader) {
  -            reader.setup (environment, serializerSource, generatorParam);
  -            reader.setOutputStream (out);
  -            reader.generate();
  -        } else {
  -            if (generator == null) {
  -                throw new ProcessingException ("Generator not specified");
  -            }
  -
  -            if (serializer == null) {
  -                throw new ProcessingException ("Serializer not specified");
  -            }
  -
  -            generator.setup (environment, generatorSource, generatorParam);
  -            Transformer transformer = null;
  -            XMLProducer producer = generator;
  -            int i = transformers.size();
  -
  -            for (int j=0; j < i; j++) {
  -                transformer = (Transformer) transformers.elementAt (j);
  -                transformer.setup (environment, (String)transformerSources.elementAt (j),
  -                               (Parameters)transformerParams.elementAt (j));
  -                producer.setConsumer (transformer);
  -                producer = transformer;
  -            }
  -
  -            serializer.setup (environment, serializerSource, serializerParam);
  -            serializer.setOutputStream (out);
  -            producer.setConsumer (serializer);
  -            generator.generate();
  -        }
  -        return true;
  -    }
  -} 
  +/*****************************************************************************
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  + * ------------------------------------------------------------------------- *
  + * This software is published under the terms of the Apache Software License *
  + * version 1.1, a copy of which has been included  with this distribution in *
  + * the LICENSE file.                                                         *
  + *****************************************************************************/
  +package org.apache.cocoon.sitemap;
  +
  +import java.util.Vector;
  +import java.io.IOException;
  +import java.io.OutputStream;
  +
  +import org.apache.avalon.Configuration;
  +import org.apache.avalon.Configurable;
  +import org.apache.avalon.ComponentManager;
  +import org.apache.avalon.Composer;
  +import org.apache.avalon.utils.Parameters;
  +
  +import org.apache.cocoon.ProcessingException;
  +import org.apache.cocoon.environment.Environment;
  +import org.apache.cocoon.generation.Generator;
  +import org.apache.cocoon.reading.Reader;
  +import org.apache.cocoon.transformation.Transformer;
  +import org.apache.cocoon.serialization.Serializer;
  +import org.apache.cocoon.xml.XMLProducer;
  +
  +import org.xml.sax.SAXException;
  +
  +/**
  + *
  + * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
  + * @version CVS $Revision: 1.1.2.8 $ $Date: 2000/07/27 21:49:05 $
  + */
  +public class ResourcePipeline implements Composer {
  +    private Generator generator = null;
  +    private Parameters generatorParam = null;
  +    private String generatorSource = null;
  +    private Reader reader = null;
  +    private Parameters readerParam = null;
  +    private String readerSource = null;
  +    private Vector transformers = new Vector();
  +    private Vector transformerParams = new Vector();
  +    private Vector transformerSources = new Vector();
  +    private Serializer serializer = null;
  +    private Parameters serializerParam = null;
  +    private String serializerSource = null;
  +
  +    /** the component manager */
  +    private ComponentManager manager = null;
  +
  +    public ResourcePipeline () {
  +    }
  +
  +    public void setComponentManager (ComponentManager manager) {
  +        this.manager = manager;
  +System.out.println ("ResourcePipeline.setComponentManager: manager is "
  ++((this.manager == null)?"null":"set"));
  +    }
  +    public void setGenerator (Generator generator, String source, 
  +                              Configuration conf, Parameters param) 
  +    throws InstantiationException, IllegalAccessException {
  +        this.generator = (Generator)generator.getClass().newInstance();
  +System.out.println ("ResourcePipeline.setGenerator: object is "
  ++((this.generator instanceof Composer)?"a":"not a")+" Composer");
  +System.out.println ("ResourcePipeline.setGenerator: manager is "
  ++((this.manager == null)?"null":"set"));
  +        if (this.generator instanceof Composer) 
  +            ((Composer)this.generator).setComponentManager (manager);
  +        if (this.generator instanceof Configurable) 
  +            ((Configurable)this.generator).setConfiguration (conf);
  +        this.generatorSource = source;
  +        this.generatorParam = param;
  +    }
  +
  +    public void setReader (Reader reader, String source, 
  +                           Configuration conf, Parameters param) 
  +    throws InstantiationException, IllegalAccessException {
  +        this.reader = (Reader)reader.getClass().newInstance();
  +        if (this.reader instanceof Composer) 
  +            ((Composer)this.generator).setComponentManager (manager);
  +        if (this.reader instanceof Configurable) 
  +            ((Configurable)this.reader).setConfiguration (conf);
  +        this.readerSource = source;
  +        this.readerParam = param;
  +    }
  +
  +    public void setSerializer (Serializer serializer, String source, 
  +                               Configuration conf, Parameters param) 
  +    throws InstantiationException, IllegalAccessException {
  +        this.serializer = (Serializer)serializer.getClass().newInstance();
  +        if (this.serializer instanceof Composer) 
  +            ((Composer)this.generator).setComponentManager (manager);
  +        if (this.serializer instanceof Configurable) 
  +            ((Configurable)this.serializer).setConfiguration (conf);
  +        this.serializerSource = source;
  +        this.serializerParam = param;
  +    }
  +
  +    public void addTransformer (Transformer transformer, String source, 
  +                               Configuration conf, Parameters param) 
  +    throws InstantiationException, IllegalAccessException {
  +        Transformer transfmr = (Transformer)transformer.getClass().newInstance();
  +        if (transfmr instanceof Composer) 
  +            ((Composer)this.generator).setComponentManager (manager);
  +        if (transfmr instanceof Configurable) 
  +            ((Configurable)transfmr).setConfiguration (conf);
  +        this.transformers.add (transfmr);
  +        this.transformerSources.add (source);
  +        this.transformerParams.add (param);
  +    }
  +
  +    public boolean process (Environment environment, OutputStream out)
  +                            throws ProcessingException, IOException, SAXException {
  +        if (generator == null) {
  +            if (reader != null) {
  +                reader.setup (environment, readerSource, readerParam);
  +                reader.setOutputStream (out);
  +                reader.generate();
  +            } else {
  +                throw new ProcessingException ("Generator/Reader not specified");
  +            }
  +        } else {
  +            if (serializer == null) {
  +                throw new ProcessingException ("Serializer not specified");
  +            }
  +
  +            generator.setup (environment, generatorSource, generatorParam);
  +            Transformer transformer = null;
  +            XMLProducer producer = generator;
  +            int i = transformers.size();
  +            for (int j=0; j < i; j++) {
  +                transformer = (Transformer) transformers.elementAt (j);
  +                transformer.setup (environment, (String)transformerSources.elementAt (j),
  +                               (Parameters)transformerParams.elementAt (j));
  +                producer.setConsumer (transformer);
  +                producer = transformer;
  +            }
  +
  +            serializer.setup (environment, serializerSource, serializerParam);
  +            serializer.setOutputStream (out);
  +            producer.setConsumer (serializer);
  +            generator.generate();
  +        }
  +        return true;
  +    }
  +} 
  
  
  
  1.1.4.9   +20 -23    xml-cocoon/src/org/apache/cocoon/sitemap/Attic/Sitemap.java
  
  Index: Sitemap.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/sitemap/Attic/Sitemap.java,v
  retrieving revision 1.1.4.8
  retrieving revision 1.1.4.9
  diff -u -r1.1.4.8 -r1.1.4.9
  --- Sitemap.java	2000/07/22 20:41:57	1.1.4.8
  +++ Sitemap.java	2000/07/27 21:49:05	1.1.4.9
  @@ -1,27 +1,24 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -package org.apache.cocoon.sitemap;
  -
  -import org.apache.avalon.Composer; 
  -import org.apache.avalon.Modifiable; 
  +/*****************************************************************************
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  + * ------------------------------------------------------------------------- *
  + * This software is published under the terms of the Apache Software License *
  + * version 1.1, a copy of which has been included  with this distribution in *
  + * the LICENSE file.                                                         *
  + *****************************************************************************/
  +package org.apache.cocoon.sitemap;
  +
  +import org.apache.avalon.Composer; 
  +import org.apache.avalon.Modifiable; 
   import org.apache.avalon.Configurable; 
   import org.apache.avalon.Configuration; 
  -import org.apache.cocoon.Processor;
  -
  -/**
  - * Base interface for generated <code>Sitemap</code> classes
  - *
  - * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
  - * @version CVS $Revision: 1.1.4.8 $ $Date: 2000/07/22 20:41:57 $
  - */
  -public interface Sitemap
  -         extends Composer, Configurable, Processor, Modifiable { 
  +import org.apache.cocoon.Processor;
   
  -    /** set the base path of a sitemap */
  -    public void setBasePath (String basePath);
  +/**
  + * Base interface for generated <code>Sitemap</code> classes
  + *
  + * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
  + * @version CVS $Revision: 1.1.4.9 $ $Date: 2000/07/27 21:49:05 $
  + */
  +public interface Sitemap
  +         extends Composer, Configurable, Processor, Modifiable { 
   } 
  
  
  
  1.1.2.5   +152 -144  xml-cocoon/src/org/apache/cocoon/sitemap/Attic/SitemapHandler.java
  
  Index: SitemapHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/sitemap/Attic/SitemapHandler.java,v
  retrieving revision 1.1.2.4
  retrieving revision 1.1.2.5
  diff -u -r1.1.2.4 -r1.1.2.5
  --- SitemapHandler.java	2000/07/25 18:48:45	1.1.2.4
  +++ SitemapHandler.java	2000/07/27 21:49:05	1.1.2.5
  @@ -1,77 +1,81 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -package org.apache.cocoon.sitemap;
  -
  -import java.io.File;
  -import java.io.FileNotFoundException;
  -import java.io.IOException;
  -import java.io.OutputStream;
  -
  -import org.xml.sax.InputSource;
  -import org.xml.sax.SAXException;
  -
  -import org.apache.cocoon.ProcessingException;
  -import org.apache.cocoon.components.language.generator.ProgramGenerator;
  -import org.apache.cocoon.environment.Environment;
  -
  -import org.apache.avalon.Configurable;
  -import org.apache.avalon.Configuration;
  -import org.apache.avalon.Composer;
  -import org.apache.avalon.ComponentManager;
  -
  -/**
  - * Handles the manageing and stating of one <code>Sitemap</code>
  - *
  - * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
  - * @version CVS $Revision: 1.1.2.4 $ $Date: 2000/07/25 18:48:45 $
  - */
  -public class SitemapHandler implements Runnable, Configurable, Composer {
  -
  -    /** the configuration */
  -    private Configuration conf = null;
  -
  -    /** the component manager */
  -    private ComponentManager manager = null;
  -
  -    /** the source of this sitemap */
  +/*****************************************************************************
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  + * ------------------------------------------------------------------------- *
  + * This software is published under the terms of the Apache Software License *
  + * version 1.1, a copy of which has been included  with this distribution in *
  + * the LICENSE file.                                                         *
  + *****************************************************************************/
  +package org.apache.cocoon.sitemap;
  +
  +import java.io.File;
  +import java.io.FileNotFoundException;
  +import java.io.IOException;
  +import java.io.OutputStream;
  +
  +import org.xml.sax.InputSource;
  +import org.xml.sax.SAXException;
  +
  +import org.apache.cocoon.ProcessingException;
  +import org.apache.cocoon.components.language.generator.ProgramGenerator;
  +import org.apache.cocoon.environment.Environment;
  +
  +import org.apache.avalon.Configurable;
  +import org.apache.avalon.Configuration;
  +import org.apache.avalon.Composer;
  +import org.apache.avalon.ComponentManager;
  +
  +/**
  + * Handles the manageing and stating of one <code>Sitemap</code>
  + *
  + * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
  + * @version CVS $Revision: 1.1.2.5 $ $Date: 2000/07/27 21:49:05 $
  + */
  +public class SitemapHandler implements Runnable, Configurable, Composer {
  +
  +    /** the configuration */
  +    private Configuration conf = null;
  +
  +    /** the component manager */
  +    private ComponentManager manager = null;
  +
  +    /** the source of this sitemap */
       private File sourceFile = null;
  -
  -    /** the last error */
  -    private Exception exception = null;
  -
  -    /** the managed sitemap */
  -    private Sitemap sitemap = null;
  +
  +    /** the last error */
  +    private Exception exception = null;
  +
  +    /** the managed sitemap */
  +    private Sitemap sitemap = null;
  +    private boolean check_reload = true;
    
       /** the regenerating thread */ 
       private Thread regeneration = null; 
       private boolean isRegenerationRunning = false;
  +    private Environment environment = null;
    
       /** the sitemaps base path */ 
       private String basePath = null; 
  -
  -    public void setComponentManager (ComponentManager manager) {
  -        this.manager = manager;
  -    }
  -
  -    public void setConfiguration (Configuration conf) {
  -        this.conf = conf;
  -    }
  -
  -    protected SitemapHandler (String source) throws FileNotFoundException {
  +
  +    public void setComponentManager (ComponentManager manager) {
  +        this.manager = manager;
  +    }
  +
  +    public void setConfiguration (Configuration conf) {
  +        this.conf = conf;
  +    }
  +
  +    protected SitemapHandler (String source, boolean check_reload) throws FileNotFoundException {
           System.out.println("SitemapHandler: Instantiating sitemap \""+source+"\"");
  -        System.out.println("SitemapHandler: last char of source is \""+source.charAt(source.length()-1)+"\"");
  +        this.check_reload = check_reload;
           String s = null;
  -        if (source.charAt(source.length()-1) == '/') {
  +System.out.println("SitemapHandler: source=\""+source+"\"");
  +        if (source.charAt(source.length()-1) == File.separatorChar) {
               s = source+"sitemap.xmap";
               this.sourceFile = new File (s);
           } else {
               sourceFile = new File (source);
               if (!sourceFile.isFile()) {
  +System.out.println("SitemapHandler: source=\""+source+"\" is not a file");
                   s = source+File.separatorChar+"sitemap.xmap";
                   sourceFile = new File (s);
               }
  @@ -87,116 +91,120 @@
           System.out.println("SitemapHandler.throwError()");
           Exception e = exception;
           exception = null;
  -        if (e instanceof ProcessingException) {
  -            throw (ProcessingException) exception;
  -        } else if (e instanceof SAXException) {
  -            throw (SAXException) exception;
  -        } else if (e instanceof IOException) {
  -            throw (IOException) exception;
  -        } else if (e instanceof InterruptedException) {
  -            throw (InterruptedException) exception;
  -        } else if (e != null) {
  -            throw new ProcessingException ("Unknown Exception raised: "
  -                                         + exception.toString());
  -        }
  +        if (e instanceof ProcessingException) {
  +            throw (ProcessingException) exception;
  +        } else if (e instanceof SAXException) {
  +            throw (SAXException) exception;
  +        } else if (e instanceof IOException) {
  +            throw (IOException) exception;
  +        } else if (e instanceof InterruptedException) {
  +            throw (InterruptedException) exception;
  +        } else if (e != null) {
  +            throw new ProcessingException ("Unknown Exception raised: "
  +                                         + exception.toString());
  +        }
           System.out.println("SitemapHandler.throwError() no Exception to throw");
  -    }
  -
  -    protected boolean available () {
  +    }
  +
  +    protected boolean available () {
           System.out.println("SitemapHandler.available() = "+(sitemap!=null?"true":"false"));
  -        return (sitemap != null);
  -    }
  -
  -    protected boolean hasChanged () {
  +        return (sitemap != null);
  +    }
  +
  +    protected boolean hasChanged () {
           System.out.print("SitemapHandler.hasChanged() = ");
  -        if (sitemap != null) {
  -            System.out.println((sitemap.modifiedSince(this.sourceFile.lastModified())?"true":"false"));
  -            return sitemap.modifiedSince(this.sourceFile.lastModified());
  -        }
  +        if (sitemap != null) {
  +            if (check_reload) {
  +                System.out.println((sitemap.modifiedSince(this.sourceFile.lastModified())?"true":"false"));
  +                return sitemap.modifiedSince(this.sourceFile.lastModified());
  +            }
  +            System.out.println("false");
  +            return false;
  +        }
           System.out.println("true");
  -        return true;
  -    }
  -
  -    protected boolean isRegenerating () {
  +        return true;
  +    }
  +
  +    protected boolean isRegenerating () {
           System.out.print("SitemapHandler.isRegenerating() = "+(isRegenerationRunning?"true":"false"));
           return isRegenerationRunning; 
  -    }
  -
  -    protected void regenerateAsynchroniously () {
  +    }
  +
  +    protected synchronized void regenerateAsynchroniously (Environment environment) {
           System.out.println("SitemapHandler.regenerateAsynchroniously()");
  -        if (!this.isRegenerationRunning) {
  +        if (!this.isRegenerationRunning) {
               isRegenerationRunning = true;
  -            regeneration = new Thread (this);
  -            regeneration.start();
  -        }
  -    }
  -
  -    protected void regenerate () 
  +            regeneration = new Thread (this);
  +            this.environment = environment;
  +            regeneration.start();
  +        }
  +    }
  +
  +    protected synchronized void regenerate (Environment environment) 
       throws ProcessingException, SAXException, IOException, InterruptedException { 
           System.out.println("SitemapHandler.regenerate()");
  -        if (!this.isRegenerationRunning) {
  +        if (!this.isRegenerationRunning) {
               System.out.println("SitemapHandler.regenerate(): regenerating");
               isRegenerationRunning = true;
  -            regeneration = new Thread (this);
  -            regeneration.start();
  -            regeneration.join();
  +            regeneration = new Thread (this);
  +            this.environment = environment;
  +            regeneration.start();
  +            regeneration.join();
               throwError();
           } else {
               System.out.println("SitemapHandler.regenerate(): regenerating already in progress");
           }
  -    }
  -
  -    public boolean process (Environment environment, OutputStream out) 
  -    throws ProcessingException, SAXException, IOException, InterruptedException {
  +    }
  +
  +    public boolean process (Environment environment, OutputStream out) 
  +    throws Exception {
           System.out.println("SitemapHandler.process()");
           this.throwError();
  -        return sitemap.process (environment, out);
  -    }
  -
  -    /** Generate the Sitemap class */
  -    public void run() {
  +        return sitemap.process (environment, out);
  +    }
  +
  +    /** Generate the Sitemap class */
  +    public void run() {
           System.out.println("SitemapHandler.run()");
  -/*
  -    private void generateSitemap (String sitemapName) 
  -            throws java.net.MalformedURLException, IOException, 
  -                   org.apache.cocoon.ProcessingException {
  -*/
  -
  -        InputSource inputSource = new InputSource (sourceFile.getPath());
  -        String systemId = inputSource.getSystemId();
  -        System.out.println ("C2 generateSitemap: "+systemId);
  -
  -        File file = new File(systemId);
  -
  -        String markupLanguage = "sitemap";
  -        String programmingLanguage = "java";
  -
  -        ProgramGenerator programGenerator = null;
  -
  -        System.out.println ("C2 generateSitemap: obtaining programGenerator");
  -        programGenerator = (ProgramGenerator) this.manager.getComponent("program-generator");
  -        System.out.println ("C2 generateSitemap: programGenerator obtained");
  -
  -        System.out.println ("C2 generateSitemap: obtaining generator");
  -        try {
  -            sitemap = (Sitemap) programGenerator.load(file, markupLanguage, programmingLanguage);
  -            System.out.println ("C2 generateSitemap: generator obtained");
  -            if (sitemap instanceof Composer) sitemap.setComponentManager(this.manager);
  -            if (sitemap instanceof Configurable) sitemap.setConfiguration(this.conf);
  -            sitemap.setBasePath (basePath);
  -            System.out.println ("C2 generateSitemap: generator called");
  -        } catch (Exception e) {
  -            synchronized (this.exception) {
  -                this.exception = e;
  -            }
  +
  +        Sitemap smap = null;
  +        InputSource inputSource = new InputSource (sourceFile.getPath());
  +        String systemId = inputSource.getSystemId();
  +        System.out.println ("C2 generateSitemap: "+systemId);
  +
  +        File file = new File(systemId);
  +
  +        String markupLanguage = "sitemap";
  +        String programmingLanguage = "java";
  +
  +        ProgramGenerator programGenerator = null;
  +
  +        System.out.println ("C2 generateSitemap: obtaining programGenerator");
  +        programGenerator = (ProgramGenerator) this.manager.getComponent("program-generator");
  +        System.out.println ("C2 generateSitemap: programGenerator obtained");
  +
  +        System.out.println ("C2 generateSitemap: obtaining generator");
  +        try {
  +            smap = (Sitemap) programGenerator.load(file, markupLanguage, 
  +                                 programmingLanguage, environment);
  +            System.out.println ("C2 generateSitemap: generator obtained");
  +            if (smap instanceof Composer) smap.setComponentManager(this.manager);
  +            if (smap instanceof Configurable) smap.setConfiguration(this.conf);
  +            this.sitemap = smap;
  +            System.out.println ("C2 generateSitemap: generator called");
  +        } catch (Exception e) {
  +            synchronized (this.exception) {
  +                this.exception = e;
  +            }
           } finally {
               System.out.println("SitemapHandler.run(): finally");
               regeneration = null;
  +            environment = null;
               isRegenerationRunning = false;
           }
  -    }
  +    }
   
       public void setBasePath (String basePath) {
           this.basePath = basePath;
       }
  -} 
  +} 
  
  
  
  1.1.2.4   +100 -82   xml-cocoon/src/org/apache/cocoon/sitemap/Attic/SitemapManager.java
  
  Index: SitemapManager.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/sitemap/Attic/SitemapManager.java,v
  retrieving revision 1.1.2.3
  retrieving revision 1.1.2.4
  diff -u -r1.1.2.3 -r1.1.2.4
  --- SitemapManager.java	2000/07/25 18:48:45	1.1.2.3
  +++ SitemapManager.java	2000/07/27 21:49:05	1.1.2.4
  @@ -1,92 +1,110 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -package org.apache.cocoon.sitemap;
  -
  -import java.io.FileNotFoundException;
  -import java.io.IOException;
  -import java.io.OutputStream;
  +/*****************************************************************************
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  + * ------------------------------------------------------------------------- *
  + * This software is published under the terms of the Apache Software License *
  + * version 1.1, a copy of which has been included  with this distribution in *
  + * the LICENSE file.                                                         *
  + *****************************************************************************/
  +package org.apache.cocoon.sitemap;
  +
  +import java.io.FileNotFoundException;
  +import java.io.IOException;
  +import java.io.OutputStream;
   import java.net.MalformedURLException; 
  -import java.util.Hashtable;
  -
  -import org.apache.avalon.ComponentManager;
  -import org.apache.avalon.Composer;
  -import org.apache.avalon.Configurable;
  -import org.apache.avalon.Configuration;
  -
  -import org.apache.cocoon.ProcessingException;
  -import org.apache.cocoon.environment.Environment;
  -import org.apache.cocoon.sitemap.SitemapHandler;
  -
  -import org.xml.sax.SAXException;
  -
  -/**
  - * This class manages all sub <code>Sitemap</code>s of a <code>Sitemap</code>
  - * Invokation of sub sitemaps will be done by this instance as well 
  - * checking regeneration of the sub <code>Sitemap</code>
  - *
  - * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
  - * @version CVS $Revision: 1.1.2.3 $ $Date: 2000/07/25 18:48:45 $
  - */
  -public class SitemapManager implements Configurable, Composer {
  -
  -    /** The vectors of sub sitemaps */
  -    private Hashtable sitemaps = new Hashtable();
  -
  -    /** The configuration */
  -    private Configuration conf = null;
  -
  -    /** The component manager */
  -    private ComponentManager manager = null;
  -
  -    public SitemapManager () {
  -    }
  -
  -    public void setConfiguration (Configuration conf) {
  -        this.conf = conf;
  -    }
  -
  -    public void setComponentManager (ComponentManager manager) {
  -        this.manager = manager;
  -    }
  -
  -    public boolean invoke (Environment environment, String uri_prefix, 
  -                           String source, boolean check_reload, OutputStream out) 
  -    throws SAXException, ProcessingException, IOException, InterruptedException,
  -           FileNotFoundException {
  -        SitemapHandler sitemapHandler = (SitemapHandler) sitemaps.get (source);
  +import java.util.Enumeration;
  +import java.util.Hashtable;
  +
  +import org.apache.avalon.ComponentManager;
  +import org.apache.avalon.Composer;
  +import org.apache.avalon.Configurable;
  +import org.apache.avalon.Configuration;
  +
  +import org.apache.cocoon.ProcessingException;
  +import org.apache.cocoon.environment.Environment;
  +import org.apache.cocoon.sitemap.SitemapHandler;
  +
  +import org.xml.sax.SAXException;
  +
  +/**
  + * This class manages all sub <code>Sitemap</code>s of a <code>Sitemap</code>
  + * Invokation of sub sitemaps will be done by this instance as well 
  + * checking regeneration of the sub <code>Sitemap</code>
  + *
  + * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
  + * @version CVS $Revision: 1.1.2.4 $ $Date: 2000/07/27 21:49:05 $
  + */
  +public class SitemapManager implements Configurable, Composer {
  +
  +    /** The vectors of sub sitemaps */
  +    private Hashtable sitemaps = new Hashtable();
  +
  +    /** The configuration */
  +    private Configuration conf = null;
  +
  +    /** The component manager */
  +    private ComponentManager manager = null;
  +
  +    public SitemapManager () {
  +    }
  +
  +    public void setConfiguration (Configuration conf) {
  +        this.conf = conf;
  +    }
  +
  +    public void setComponentManager (ComponentManager manager) {
  +        this.manager = manager;
  +System.out.println ("SitemapManager.setComponentManager: manager is "
  ++((this.manager == null)?"null":"set"));
  +    }
  +
  +    public boolean invoke (Environment environment, String uri_prefix, 
  +                           String source, boolean check_reload, OutputStream out) 
  +    throws Exception {
  +        SitemapHandler sitemapHandler = (SitemapHandler) sitemaps.get (source);
           System.out.println ("SitemapManager.invoke(\""+uri_prefix+"\",\""+source+"\")");
  -        if (sitemapHandler != null) {
  +        if (sitemapHandler != null) {
               System.out.println ("SitemapManager.invoke: SitemapHandler found");
  -            sitemapHandler.throwError();
  -            if (sitemapHandler.available()) {
  -                if (check_reload 
  -                 && sitemapHandler.hasChanged()
  -                 && !sitemapHandler.isRegenerating()) {
  -                    sitemapHandler.regenerateAsynchroniously();
  -                }
  +            sitemapHandler.throwError();
  +            if (sitemapHandler.available()) {
  +                if (check_reload 
  +                 && sitemapHandler.hasChanged()
  +                 && !sitemapHandler.isRegenerating()) {
  +                    sitemapHandler.regenerateAsynchroniously(environment);
  +                }
                   environment.changeContext (uri_prefix, source);
  -                return sitemapHandler.process (environment, out);
  -            } else {
  -                sitemapHandler.regenerate();
  -            }
  +                return sitemapHandler.process (environment, out);
  +            } else {
  +                sitemapHandler.regenerate(environment);
  +            }
               System.out.println ("SitemapManager.invoke: setting uri prefix");
               environment.changeContext (uri_prefix, source);
  -            return sitemapHandler.process (environment, out);
  -        } else {
  +            return sitemapHandler.process (environment, out);
  +        } else {
               System.out.println ("SitemapManager.invoke: instantiating SitemapHandler");
  -            sitemapHandler = new SitemapHandler(source);
  -            if (sitemapHandler instanceof Composer) sitemapHandler.setComponentManager (this.manager);
  +            sitemapHandler = new SitemapHandler(source, check_reload);
  +            if (sitemapHandler instanceof Composer) sitemapHandler.setComponentManager (this.manager);
               if (sitemapHandler instanceof Configurable) sitemapHandler.setConfiguration (this.conf); 
  -            sitemaps.put(source, sitemapHandler);
  -            sitemapHandler.regenerate(); 
  +            sitemaps.put(source, sitemapHandler);
  +            sitemapHandler.regenerate(environment); 
               System.out.println ("SitemapManager.invoke: setting uri prefix");
               environment.changeContext (uri_prefix, source);
  -            return sitemapHandler.process (environment, out);
  -        }
  -    }
  -}
  +            return sitemapHandler.process (environment, out);
  +        }
  +    }
  +
  +    public boolean hasChanged () {
  +        System.out.print("SitemapManager.hasChanged() = ");
  +        SitemapHandler sitemapHandler = null;
  +        Enumeration enum = sitemaps.elements();
  +        while (enum.hasMoreElements()) {
  +            sitemapHandler = (SitemapHandler) enum.nextElement ();
  +            if (sitemapHandler != null) {
  +                System.out.println((sitemapHandler.hasChanged()?"true":"false"));
  +                if (sitemapHandler.hasChanged())
  +                    return true;
  +            }
  +        }
  +        System.out.println("true");
  +        return true;
  +    }
  +}
  
  
  

Mime
View raw message