cocoon-dev 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/processor/xsp XSPUtil.java
Date Sun, 19 Mar 2000 00:59:33 GMT
stefano     00/03/18 16:59:33

  Modified:    src/org/apache/cocoon Utils.java
               src/org/apache/cocoon/processor/dcp DCPEngine.java
               src/org/apache/cocoon/processor/xsp XSPUtil.java
  Log:
  use the new tokenizer
  
  Revision  Changes    Path
  1.10      +26 -26    xml-cocoon/src/org/apache/cocoon/Utils.java
  
  Index: Utils.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Utils.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Utils.java	2000/02/13 18:29:16	1.9
  +++ Utils.java	2000/03/19 00:59:32	1.10
  @@ -1,36 +1,36 @@
  -/*-- $Id: Utils.java,v 1.9 2000/02/13 18:29:16 stefano Exp $ -- 
  +/*-- $Id: Utils.java,v 1.10 2000/03/19 00:59:32 stefano Exp $ --
   
    ============================================================================
                      The Apache Software License, Version 1.1
    ============================================================================
  - 
  +
    Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  - 
  +
    Redistribution and use in source and binary forms, with or without modifica-
    tion, are permitted provided that the following conditions are met:
  - 
  +
    1. Redistributions of  source code must  retain the above copyright  notice,
       this list of conditions and the following disclaimer.
  - 
  +
    2. Redistributions in binary form must reproduce the above copyright notice,
       this list of conditions and the following disclaimer in the documentation
       and/or other materials provided with the distribution.
  - 
  +
    3. The end-user documentation included with the redistribution, if any, must
       include  the following  acknowledgment:  "This product includes  software
       developed  by the  Apache Software Foundation  (http://www.apache.org/)."
       Alternately, this  acknowledgment may  appear in the software itself,  if
       and wherever such third-party acknowledgments normally appear.
  - 
  +
    4. The names "Cocoon" and  "Apache Software Foundation"  must not be used to
       endorse  or promote  products derived  from this  software without  prior
       written permission. For written permission, please contact
       apache@apache.org.
  - 
  +
    5. Products  derived from this software may not  be called "Apache", nor may
       "Apache" appear  in their name,  without prior written permission  of the
       Apache Software Foundation.
  - 
  +
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
    FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  @@ -41,12 +41,12 @@
    ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
    (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  - 
  +
    This software  consists of voluntary contributions made  by many individuals
    on  behalf of the Apache Software  Foundation and was  originally created by
  - Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache 
  + Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
    Software Foundation, please see <http://www.apache.org/>.
  - 
  +
    */
   package org.apache.cocoon;
   
  @@ -61,7 +61,7 @@
    * Utility methods for Cocoon and its classes.
    *
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  - * @version $Revision: 1.9 $ $Date: 2000/02/13 18:29:16 $
  + * @version $Revision: 1.10 $ $Date: 2000/03/19 00:59:32 $
    */
   
   public final class Utils {
  @@ -72,7 +72,7 @@
       public static final Vector getAllPIs(Document document, String name) {
           return getAllPIs(document, name, false);
       }
  -	
  +
       /**
        * This method returns a vector of PI nodes based on the PI target name
        * and removes the found PIs from the document if the remove flag is
  @@ -80,7 +80,7 @@
        */
       public static final Vector getAllPIs(Document document, String name, boolean remove)
{
           Vector pis = new Vector();
  -        
  +
           NodeList nodelist = document.getChildNodes();
           int i = nodelist.getLength();
           for (int j = 0; j < i; j++) {
  @@ -95,10 +95,10 @@
                   }
               }
           }
  -        
  +
           return pis;
       }
  -    
  +
       /**
        * This method returns the first PI node based on the PI target name.
        */
  @@ -128,7 +128,7 @@
   
           return pi;
       }
  -    
  +
       /**
        * This method returns an hashtable with all the pseudo attributes collected
        * in the document. If more PI have the same target, the attributes are
  @@ -138,10 +138,10 @@
       public static final Hashtable getPIPseudoAttributes(Document document, String name)
{
           Hashtable attributes = new Hashtable();
           Enumeration nodes = getAllPIs(document, name).elements();
  -        
  +
           while (nodes.hasMoreElements()) {
               String data = ((ProcessingInstruction) nodes.nextElement()).getData();
  -            StringTokenizer st = new StringTokenizer(data, " \t=");
  +            Tokenizer st = new Tokenizer(data, " \t\n\f\r=");
               while (st.hasMoreTokens()) {
                   String key = st.nextToken();
                   String token = st.nextToken();
  @@ -149,10 +149,10 @@
                   attributes.put(key, token);
               }
           }
  -        
  +
           return attributes;
       }
  -    
  +
       /**
        * This method returns an hashtable of pseudo attributes found in the first
        * occurrence of the PI with the given name in the given document.
  @@ -160,16 +160,16 @@
        */
       public static final Hashtable getPIPseudoAttributes(ProcessingInstruction pi) {
           Hashtable attributes = new Hashtable();
  -        
  +
           String data = pi.getData();
  -        StringTokenizer st = new StringTokenizer(data, " \t=");
  +        Tokenizer st = new Tokenizer(data, " \t\n\f\r=");
           while (st.hasMoreTokens()) {
               String key = st.nextToken();
               String token = st.nextToken();
               token = token.substring(1, token.length() - 1);
               attributes.put(key, token);
           }
  -        
  +
           return attributes;
       }
   
  @@ -190,7 +190,7 @@
       public static final String encode(HttpServletRequest req, boolean agent) {
           return encode(req, agent, true);
       }
  -    
  +
       /**
        * Encodes the given request into a string using the format
        *   userAgent:protocol://serverName:serverPort/requestURI?query
  
  
  
  1.6       +61 -60    xml-cocoon/src/org/apache/cocoon/processor/dcp/DCPEngine.java
  
  Index: DCPEngine.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/processor/dcp/DCPEngine.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DCPEngine.java	2000/02/13 18:29:30	1.5
  +++ DCPEngine.java	2000/03/19 00:59:32	1.6
  @@ -1,36 +1,36 @@
  -/*-- $Id: DCPEngine.java,v 1.5 2000/02/13 18:29:30 stefano Exp $ -- 
  +/*-- $Id: DCPEngine.java,v 1.6 2000/03/19 00:59:32 stefano Exp $ --
   
    ============================================================================
                      The Apache Software License, Version 1.1
    ============================================================================
  - 
  +
    Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  - 
  +
    Redistribution and use in source and binary forms, with or without modifica-
    tion, are permitted provided that the following conditions are met:
  - 
  +
    1. Redistributions of  source code must  retain the above copyright  notice,
       this list of conditions and the following disclaimer.
  - 
  +
    2. Redistributions in binary form must reproduce the above copyright notice,
       this list of conditions and the following disclaimer in the documentation
       and/or other materials provided with the distribution.
  - 
  +
    3. The end-user documentation included with the redistribution, if any, must
       include  the following  acknowledgment:  "This product includes  software
       developed  by the  Apache Software Foundation  (http://www.apache.org/)."
       Alternately, this  acknowledgment may  appear in the software itself,  if
       and wherever such third-party acknowledgments normally appear.
  - 
  +
    4. The names "Cocoon" and  "Apache Software Foundation"  must not be used to
       endorse  or promote  products derived  from this  software without  prior
       written permission. For written permission, please contact
       apache@apache.org.
  - 
  +
    5. Products  derived from this software may not  be called "Apache", nor may
       "Apache" appear  in their name,  without prior written permission  of the
       Apache Software Foundation.
  - 
  +
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
    FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  @@ -41,12 +41,12 @@
    ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
    (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  - 
  +
    This software  consists of voluntary contributions made  by many individuals
    on  behalf of the Apache Software  Foundation and was  originally created by
  - Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache 
  + Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
    Software Foundation, please see <http://www.apache.org/>.
  - 
  +
    */
   package org.apache.cocoon.processor.dcp;
   
  @@ -54,6 +54,7 @@
   import java.util.*;
   import org.w3c.dom.*;
   import javax.servlet.http.*;
  +import org.apache.cocoon.*;
   import org.apache.cocoon.processor.*;
   import org.apache.cocoon.framework.*;
   import org.apache.cocoon.interpreter.*;
  @@ -63,7 +64,7 @@
    * <i><font color="green">&lt;?</font><font color="brown">dcp?</font>
    * <font color="green">&gt;</font></i> processing instructions to
generate
    * dynamic content.
  - * 
  + *
    * <p align="justify">
    * The following processing instructions are recognized:
    * </p>
  @@ -78,7 +79,7 @@
    * This instruction declares an external program (or <i>DCP script</i>) that
contains
    * node-generation methods. These methods will be invoked during document processing
    * as dictated by the appearance of subsequent <i><font color="green">&lt;?</font>
  - * <font color="brown">dcp-content?</font><font color="green">&gt;</font></i>

  + * <font color="brown">dcp-content?</font><font color="green">&gt;</font></i>
    * directives (explained below).
    * </p>
    * <p align="justify">
  @@ -109,7 +110,7 @@
    * <li>
    * <pre><font color="green">&lt;?</font><font color="brown">dcp-content</font>
    * <font color="darkGreen">method</font>=<font color="magenta">"<i>object.method</i>"</font>
  - * [<font color="darkGreen">param1</font>=<font color="magenta">"<i>value</i>"</font>

  + * [<font color="darkGreen">param1</font>=<font color="magenta">"<i>value</i>"</font>
    * <font color="darkGreen">param2</font>=<font color="magenta">"<i>value</i>"</font>
...]
    * <font color="green">?&gt;</font></pre>
    * <p align="justify">
  @@ -167,13 +168,13 @@
    * </p>
    * </li>
    * </ul>
  - * 
  + *
    * @author <a href="mailto:rrocha@plenix.org">Ricardo Rocha</a>
  - * @version $Revision: 1.5 $ $Date: 2000/02/13 18:29:30 $
  + * @version $Revision: 1.6 $ $Date: 2000/03/19 00:59:32 $
    */
  - 
  +
   public class DCPEngine {
  -    
  +
       private static final String OBJECT_PI = "dcp-object";
       private static final String CONTENT_PI = "dcp-content";
       private static final String VARIABLE_PI = "dcp-var";
  @@ -181,7 +182,7 @@
       private static final String LANGUAGE_ATTRIBUTE = "language";
       private static final String CODE_ATTRIBUTE = "code";
       private static final String METHOD_ATTRIBUTE = "method";
  -    
  +
       private InterpreterFactory interpreterFactory;
       private Document document;
       private Director director;
  @@ -198,7 +199,7 @@
        * processing instructions as well as the context parameters provided by the
        * invoking environment.
        * </p>
  -     * 
  +     *
        * @param document The document to be processed for dynamic content
        * @param parameters The table of environment variables to be used during processing
        */
  @@ -218,7 +219,7 @@
        * This method carries out the actual expansion of dynamic content
        * processing instructions embedded in the document.
        * </p>
  -     * 
  +     *
        * @throws Exception When any error occurs during processing
        */
       public void process() throws Exception {
  @@ -234,8 +235,8 @@
               Instance instance = (Instance) this.instances.get(instanceName);
   
               instance.destroy();
  -        } 
  -    } 
  +        }
  +    }
   
       private void doProcess(Node node) {
           short nodeType = node.getNodeType();
  @@ -249,7 +250,7 @@
   
                   for (int i = 0; i < children.length; i++) {
                       doProcess(children[i]);
  -                } 
  +                }
   
                   break;
   
  @@ -270,15 +271,15 @@
                               parent.removeChild(pi);
                           } else {
                               parent.replaceChild(result, pi);
  -                        } 
  +                        }
                       } else if (target.equals(VARIABLE_PI)) {
                           processVariable(pi);
                           parent.removeChild(pi);
  -                    } 
  +                    }
                   } catch (Exception e) {
                       String message = e.getMessage();
                       String className = e.getClass().getName();
  -                    
  +
                       StringWriter sw = new StringWriter();
                       PrintWriter pw = new PrintWriter(sw, true);
                       e.printStackTrace(pw);
  @@ -288,13 +289,13 @@
                           message + "}\n" +
                           sw.toString()
                       );
  -                    
  +
                       parent.replaceChild(errorText, pi);
  -                } 
  +                }
   
                   break;
           }
  -    } 
  +    }
   
       private void processObject(ProcessingInstruction pi) throws Exception {
   
  @@ -305,18 +306,18 @@
           if (objectName == null) {
               // Object name is mandatory
               throw new DCPException("Missing name in object definition");
  -        } 
  +        }
   
           // Verify object name uniqueness within document
           if (this.instances.containsKey(objectName)) {
               throw new DCPException("Duplicate object name: " + objectName);
  -        } 
  +        }
   
           String codeLocation = (String) attributes.get(CODE_ATTRIBUTE);
  -        if (codeLocation == null) {     
  +        if (codeLocation == null) {
               // Code location is mandatory
               throw new DCPException("Missing code location in object definition");
  -        } 
  +        }
   
           String languageName = (String) attributes.get(LANGUAGE_ATTRIBUTE);
   
  @@ -326,7 +327,7 @@
   
           // Register object instance
           this.instances.put(objectName, instance);
  -    } 
  +    }
   
       private Node processContent(ProcessingInstruction pi) throws Exception {
   
  @@ -338,35 +339,35 @@
           if (methodReference == null) {
               // Method reference is mandatory
               throw new DCPException("Missing method name in content generation");
  -        } 
  +        }
   
           /* Extract object and method names */
           String objectName = null;
           String methodName = null;
  -        StringTokenizer st = new StringTokenizer(methodReference, ".");
  +        Tokenizer st = new Tokenizer(methodReference, ".");
   
           try {
               objectName = st.nextToken();
               methodName = st.nextToken();
           } catch (NoSuchElementException e) {
               throw new DCPException("Invalid method reference: " + methodReference);
  -        } 
  +        }
   
           Instance instance = (Instance) this.instances.get(objectName);
   
  -        if (instance == null) {      
  +        if (instance == null) {
               // Reference to an object not previously defined
               throw new DCPException("Undefined object: " + objectName);
  -        } 
  +        }
   
           // Invoke method
           return instance.invoke(methodName, attributes, pi);
  -    } 
  +    }
   
       private void processVariable(ProcessingInstruction pi) throws Exception {
           // Add given attributes to global variable list
           parseAttributes(pi.getData(), this.globalVariables);
  -    } 
  +    }
   
       private void parseAttributes(String data, Hashtable attributes) {
           int length = data.length();
  @@ -378,59 +379,59 @@
                   /* Skip leading blanks */
                   while (index < length && chars[index] <= ' ') {
                       index++;
  -                } 
  +                }
   
                   /* Get variable name */
                   StringBuffer nameBuffer = new StringBuffer();
   
  -                while (index < length 
  +                while (index < length
                          &&!(chars[index] == '=' || chars[index] <= ' ')) {
                       nameBuffer.append(chars[index++]);
  -                } 
  +                }
   
                   String name = nameBuffer.toString();
   
                   // Skip blanks
                   while (index < length && chars[index] <= ' ') {
                       index++;
  -                } 
  +                }
   
                   /* Get variable value */
                   if (chars[index++] != '=') {
  -                    throw new Exception("Invalid attribute name: '" + name 
  +                    throw new Exception("Invalid attribute name: '" + name
                                           + "'");
  -                } 
  +                }
   
                   // Skip blanks
                   while (index < length && chars[index] <= ' ') {
                       index++;
  -                } 
  +                }
   
                   if (chars[index++] != '"') {
  -                    throw new Exception("Invalid attribute value for '" 
  +                    throw new Exception("Invalid attribute value for '"
                                           + name + "'");
  -                } 
  +                }
   
                   StringBuffer valueBuffer = new StringBuffer();
   
                   while (index < length && chars[index] != '"') {
                       valueBuffer.append(chars[index++]);
  -                } 
  +                }
   
                   String value = valueBuffer.toString();
   
                   if (index == length || chars[index] != '"') {
  -                    throw new Exception("Unterminated string '" + value 
  +                    throw new Exception("Unterminated string '" + value
                                           + "' in attribute '" + name + "'");
  -                } 
  +                }
   
                   // Store name/value pair
                   attributes.put(name, value);
  -            } 
  +            }
           } catch (Exception e) {
               System.err.println(e.getMessage());
  -        } 
  -    } 
  +        }
  +    }
   
       private Node[] getChildren(Node node) {
           NodeList nodeList = node.getChildNodes();
  @@ -439,8 +440,8 @@
   
           for (int i = 0; i < childCount; i++) {
               children[i] = nodeList.item(i);
  -        } 
  +        }
   
           return children;
  -    } 
  +    }
   }
  
  
  
  1.14      +5 -6      xml-cocoon/src/org/apache/cocoon/processor/xsp/XSPUtil.java
  
  Index: XSPUtil.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/processor/xsp/XSPUtil.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- XSPUtil.java	2000/03/17 16:47:24	1.13
  +++ XSPUtil.java	2000/03/19 00:59:33	1.14
  @@ -1,4 +1,4 @@
  -/*-- $Id: XSPUtil.java,v 1.13 2000/03/17 16:47:24 stefano Exp $ --
  +/*-- $Id: XSPUtil.java,v 1.14 2000/03/19 00:59:33 stefano Exp $ --
   
    ============================================================================
                      The Apache Software License, Version 1.1
  @@ -58,12 +58,11 @@
   import org.w3c.dom.*;
   import javax.servlet.*;
   import javax.servlet.http.*;
  +import org.apache.cocoon.*;
   
  -import org.apache.cocoon.Utils;
  -
   /**
    * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
  - * @version $Revision: 1.13 $ $Date: 2000/03/17 16:47:24 $
  + * @version $Revision: 1.14 $ $Date: 2000/03/19 00:59:33 $
    */
   public class XSPUtil {
     public static String pathComponent(String filename) {
  @@ -155,11 +154,11 @@
     }
   
     public static String[] split(String line) {
  -    return split(line, " \t\r\n");
  +    return split(line, " \t\r\f\n");
     }
   
     public static String[] split(String line, String delimiter) {
  -    StringTokenizer tokenizer = new StringTokenizer(line, delimiter);
  +    Tokenizer tokenizer = new Tokenizer(line, delimiter);
       int tokenCount = tokenizer.countTokens();
       String[] result = new String[tokenCount];
   
  
  
  

Mime
View raw message