cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stef...@locus.apache.org
Subject cvs commit: xml-cocoon/src/org/apache/cocoon/generation ErrorGenerator.java DirectoryGenerator.java PhpGenerator.java ServerPagesGenerator.java StatusGenerator.java
Date Mon, 21 Aug 2000 17:38:00 GMT
stefano     00/08/21 10:38:00

  Modified:    src/org/apache/cocoon/generation Tag: xml-cocoon2
                        DirectoryGenerator.java PhpGenerator.java
                        ServerPagesGenerator.java StatusGenerator.java
  Added:       src/org/apache/cocoon/generation Tag: xml-cocoon2
                        ErrorGenerator.java
  Log:
  cleaned up a bunch of generators
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.6   +117 -126  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.5
  retrieving revision 1.1.2.6
  diff -u -r1.1.2.5 -r1.1.2.6
  --- DirectoryGenerator.java	2000/08/04 21:11:42	1.1.2.5
  +++ DirectoryGenerator.java	2000/08/21 17:37:47	1.1.2.6
  @@ -5,6 +5,7 @@
    * 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;
  @@ -13,10 +14,12 @@
   import java.text.SimpleDateFormat;
   import java.util.Date;
   import java.util.Dictionary;
  +
   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;
   
   /**
  @@ -52,20 +55,24 @@
    *
    * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
    *         (Apache Software Foundation, Exoffice Technologies)
  - * @version CVS $Revision: 1.1.2.5 $ $Date: 2000/08/04 21:11:42 $ */
  + * @version CVS $Revision: 1.1.2.6 $ $Date: 2000/08/21 17:37:47 $ */
  + 
   public class DirectoryGenerator extends ComposerGenerator {
   
       /** The URI of the namespace of this generator. */
       protected static final String URI =
  -	"http://apache.org/cocoon/2.0/DirectoryGenerator";
  +    "http://apache.org/cocoon/2.0/directory";
   
  +    /** The namespace prefix for this namespace. */
  +    protected static final String PREFIX = "dir";
  +
       /* Node and attribute names */
  -    protected static final String DIR_NODE_NAME		= "directory";
  -    protected static final String FILE_NODE_NAME		= "file";
  +    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";
  +    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
  @@ -81,63 +88,61 @@
        * Set the request parameters. Must be called before the generate
        * method.
        *
  -     * @param	resolver
  -     * 		the EntityResolver object
  -     * @param	objectModel
  -     * 		a <code>Dictionary</code> containing model object
  -     * @param	src
  -     * 		the URI for this request (?)
  -     * @param	par
  -     * 		configuration parameters
  +     * @param   resolver
  +     *      the EntityResolver object
  +     * @param   objectModel
  +     *      a <code>Dictionary</code> containing model object
  +     * @param   src
  +     *      the URI for this request (?)
  +     * @param   par
  +     *      configuration parameters
        */
       public void setup(EntityResolver resolver, Dictionary objectModel, String src, Parameters
par) {
  -	super.setup(resolver, objectModel, 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();
  +        super.setup(resolver, objectModel, 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
  +     * @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 {
   
           InputSource input;
  +        URL url;
  +        File path;
  +    
  +        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() + "\"");
  +        }
   
  -	URL url;
  -	File path;
  -
  -	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.startPrefixMapping(PREFIX,URI);
  +        addPath(path, depth);
  +        this.contentHandler.endPrefixMapping(PREFIX);
           this.contentHandler.endDocument();
   
       }
  @@ -147,104 +152,90 @@
        * 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
  +     * @param   path
  +     *      the file/directory to process
  +     * @param   depth
  +     *      how deep to scan the directory
        *
  -     * @throws	SAXException
  -     * 		if an error occurs while constructing nodes
  +     * @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);
  -
  -	}
  -
  +        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.
  +     * attributes.
        *
  -     * @param	nodeName
  -     * 		the name of the new node
  -     * @param	path
  -     * 		the file/directory to use when setting 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
  +     * @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);
  +        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)));
  -	
  -	}
   
  +    /**
  +     * 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
  +     * @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
  +     * @throws  SAXException
  +     *      if an error occurs while closing the node
        */
       protected void endNode(String nodeName)
       throws SAXException {
  -	super.contentHandler.endElement(URI, nodeName, nodeName);
  +        super.contentHandler.endElement(URI, nodeName, nodeName);
       }
  -
   }
  
  
  
  1.1.2.7   +2 -2      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.6
  retrieving revision 1.1.2.7
  diff -u -r1.1.2.6 -r1.1.2.7
  --- PhpGenerator.java	2000/08/04 21:11:45	1.1.2.6
  +++ PhpGenerator.java	2000/08/21 17:37:52	1.1.2.7
  @@ -26,7 +26,7 @@
    * results into SAX events.
    *
    * @author <a href="mailto:rubys@us.ibm.com">Sam Ruby</a>
  - * @version CVS $Revision: 1.1.2.6 $ $Date: 2000/08/04 21:11:45 $
  + * @version CVS $Revision: 1.1.2.7 $ $Date: 2000/08/21 17:37:52 $
    */
   public class PhpGenerator extends ServletGenerator {
   
  @@ -76,7 +76,7 @@
               try {
                   output.write(data.getBytes());
               } catch (IOException e) {
  -                e.printStackTrace(System.err);
  +                throw new RuntimeException(e.getMessage());
               }
           }
   
  
  
  
  1.1.2.5   +1 -2      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.4
  retrieving revision 1.1.2.5
  diff -u -r1.1.2.4 -r1.1.2.5
  --- ServerPagesGenerator.java	2000/08/04 21:11:46	1.1.2.4
  +++ ServerPagesGenerator.java	2000/08/21 17:37:52	1.1.2.5
  @@ -33,7 +33,7 @@
    * delegating actual SAX event generation.
    *
    * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
  - * @version CVS $Revision: 1.1.2.4 $ $Date: 2000/08/04 21:11:46 $
  + * @version CVS $Revision: 1.1.2.5 $ $Date: 2000/08/21 17:37:52 $
    */
   public class ServerPagesGenerator
     extends ServletGenerator
  @@ -120,7 +120,6 @@
         generator = (Generator)
           programGenerator.load(file, markupLanguage, programmingLanguage, resolver);
       } catch (Exception e) {
  -e.printStackTrace();
         throw new ProcessingException(e.getMessage());
       }
   
  
  
  
  1.1.2.4   +51 -5     xml-cocoon/src/org/apache/cocoon/generation/Attic/StatusGenerator.java
  
  Index: StatusGenerator.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/generation/Attic/StatusGenerator.java,v
  retrieving revision 1.1.2.3
  retrieving revision 1.1.2.4
  diff -u -r1.1.2.3 -r1.1.2.4
  --- StatusGenerator.java	2000/07/29 18:30:34	1.1.2.3
  +++ StatusGenerator.java	2000/08/21 17:37:53	1.1.2.4
  @@ -8,8 +8,12 @@
   
   package org.apache.cocoon.generation;
   
  +import java.io.File;
   import java.util.Calendar;
   import java.util.Date;
  +import java.util.List;
  +import java.util.ArrayList;
  +import java.util.StringTokenizer;
   import java.text.DateFormat;
   import java.net.InetAddress;
   import java.net.UnknownHostException;
  @@ -36,21 +40,24 @@
    *     name CDATA #IMPLIED
    * &gt;
    *
  - * &lt;!ELEMENT value (#PCDATA)&gt;
  + * &lt;!ELEMENT value (line)+&gt;
    * &lt;!ATTLIST value
    *     name CDATA #REQUIRED
  + *
  + * &lt;!ELEMENT line (#PCDATA)+&gt;
    * &gt;
    * </code>
    * 
    * @author <a href="mailto:paul@luminas.co.uk">Paul Russell</a> (Luminas Limited)
  - * @version CVS $Revision: 1.1.2.3 $ $Date: 2000/07/29 18:30:34 $
  + * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  + * @version CVS $Revision: 1.1.2.4 $ $Date: 2000/08/21 17:37:53 $
    */
   public class StatusGenerator extends ComposerGenerator {
   
   	/** The XML namespace for the output document.
   	 */
   	protected static final String namespace =
  -		"http://apache.org/cocoon/status";
  +		"http://apache.org/cocoon/2.0/status";
   
   	/** The XML namespace for xlink
   	 */
  @@ -137,7 +144,13 @@
   		endGroup(ch);
   		// END operating system
   		
  -		addValue(ch, "classpath", System.getProperty("java.class.path"));
  +		String classpath = System.getProperty("java.class.path");
  +		List paths = new ArrayList();
  +		StringTokenizer tokenizer = new StringTokenizer(classpath, System.getProperty("path.separator"));
  +		while (tokenizer.hasMoreTokens()) {
  +		    paths.add(tokenizer.nextToken());
  +		}
  +		addMultilineValue(ch, "classpath", paths);
   
   		// BEGIN OS info
   		endGroup(ch);
  @@ -180,10 +193,43 @@
   		}
   		ai.addAttribute(namespace, "name", "name", "CDATA", name);
   		ch.startElement(namespace, "value", "value", ai);
  -		if ( value != null ) {
  +		ch.startElement(namespace, "line", "line", new AttributesImpl());
  +
  +    	if ( value != null ) {
   			ch.characters(value.toCharArray(), 0, value.length());
   		}
  +
  +		ch.endElement(namespace, "line", "line");
  +		ch.endElement(namespace, "value", "value");
  +	}
  +
  +	/** Utility function to begin and end a <code>value</code> tag pair. */
  +	private void addMultilineValue(ContentHandler ch, String name, List values) throws SAXException
{
  +		addMultilineValue(ch, name, values, null);
  +	}
  +	
  +	/** Utility function to begin and end a <code>value</code> tag pair with added
attributes. */
  +	private void addMultilineValue(ContentHandler ch, String name, List values, Attributes
atts) throws SAXException {
  +		AttributesImpl ai;
  +		if ( atts == null ) {
  +			ai = new AttributesImpl();
  +		} else {
  +			ai = new AttributesImpl(atts);
  +		}
  +		ai.addAttribute(namespace, "name", "name", "CDATA", name);
  +		ch.startElement(namespace, "value", "value", ai);
  +
  +        for (int i = 0; i < values.size(); i++) {
  +            String value = (String) values.get(i);
  +    	    if ( value != null ) {
  +        		ch.startElement(namespace, "line", "line", new AttributesImpl());
  +			    ch.characters(value.toCharArray(), 0, value.length());
  +        		ch.endElement(namespace, "line", "line");
  +		    }
  +		}
  +
   		ch.endElement(namespace, "value", "value");
  +	    
   	}
   }
    
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +245 -0    xml-cocoon/src/org/apache/cocoon/generation/Attic/ErrorGenerator.java
  
  
  
  

Mime
View raw message