You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by st...@locus.apache.org on 2000/03/20 22:14:16 UTC
cvs commit: xml-cocoon/src/org/apache/cocoon Tokenizer.java Utils.java
stefano 00/03/20 13:14:16
Modified: src/org/apache/cocoon Tokenizer.java Utils.java
Log:
fixed some bugs in string tokenization and PI pseudo attribute parsing
Revision Changes Path
1.2 +5 -3 xml-cocoon/src/org/apache/cocoon/Tokenizer.java
Index: Tokenizer.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Tokenizer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Tokenizer.java 2000/03/19 00:59:02 1.1
+++ Tokenizer.java 2000/03/20 21:14:16 1.2
@@ -1,4 +1,4 @@
-/*-- $Id: Tokenizer.java,v 1.1 2000/03/19 00:59:02 stefano Exp $ --
+/*-- $Id: Tokenizer.java,v 1.2 2000/03/20 21:14:16 stefano Exp $ --
============================================================================
The Apache Software License, Version 1.1
@@ -129,9 +129,11 @@
* after the current position; false otherwise.
*/
public boolean hasMoreTokens() {
- return (current < max);
+ return ((current < max) ? (true) :
+ (((current == max) && (max == 0
+ || (returnTokens && delim.indexOf(str.charAt(previous)) >= 0)))));
}
-
+
/**
* Returns the next token from this string tokenizer.
*
1.11 +27 -22 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.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Utils.java 2000/03/19 00:59:32 1.10
+++ Utils.java 2000/03/20 21:14:16 1.11
@@ -1,4 +1,4 @@
-/*-- $Id: Utils.java,v 1.10 2000/03/19 00:59:32 stefano Exp $ --
+/*-- $Id: Utils.java,v 1.11 2000/03/20 21:14:16 stefano Exp $ --
============================================================================
The Apache Software License, Version 1.1
@@ -61,7 +61,7 @@
* Utility methods for Cocoon and its classes.
*
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @version $Revision: 1.10 $ $Date: 2000/03/19 00:59:32 $
+ * @version $Revision: 1.11 $ $Date: 2000/03/20 21:14:16 $
*/
public final class Utils {
@@ -138,18 +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();
- 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);
- }
- }
-
+ ProcessingInstruction pi = (ProcessingInstruction) nodes.nextElement();
+ addPIPseudoAttributes(pi, attributes);
+ }
return attributes;
}
@@ -160,19 +152,32 @@
*/
public static final Hashtable getPIPseudoAttributes(ProcessingInstruction pi) {
Hashtable attributes = new Hashtable();
+ addPIPseudoAttributes(pi, attributes);
+ return attributes;
+ }
+ /**
+ * This method adds pseudo attributes from a pi to an existing attribute list.
+ * All attributes are all put in the same hashtable.
+ * If there are collisions, the last attribute is inserted.
+ * No validation is performed on the PI pseudo syntax.
+ */
+ private static final void addPIPseudoAttributes(ProcessingInstruction pi, Hashtable attributes) {
String data = pi.getData();
- 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;
+ Tokenizer st = new Tokenizer(data, "\"");
+ try {
+ while (st.hasMoreTokens()) {
+ String key = st.nextToken(); // attribute name and '='
+ String token = st.nextToken(); // exact attribute value
+ key = key.replace('=',' ').trim(); // remove whitespace and '='
+ attributes.put(key, token);
+ }
+ } catch(NoSuchElementException nsee) {
+ // ignore white-space at the end of pseudo-list
+ }
}
-
+
/**
* Encodes the given request into a string using the format
* protocol://serverName:serverPort/requestURI?query