Author: jdonnerstag
Date: Sun Mar 25 03:36:38 2007
New Revision: 522190
URL: http://svn.apache.org/viewvc?view=rev&rev=522190
Log:
backported XmlPullParser changes
Modified:
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/AttributeModifier.java
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/ComponentTag.java
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/ContainerWithAssociatedMarkupHelper.java
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/resources/JavaScriptReference.java
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/resources/StyleSheetReference.java
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/parser/IXmlPullParser.java
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/parser/XmlPullParser.java
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/parser/XmlTag.java
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/parser/filter/WicketLinkTagHandler.java
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/parser/filter/WicketNamespaceHandler.java
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/tester/TagTester.java
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/markup/parser/XmlPullParserTest.java
Modified:
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/AttributeModifier.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/AttributeModifier.java?view=diff&rev=522190&r1=522189&r2=522190
==============================================================================
---
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/AttributeModifier.java
(original)
+++
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/AttributeModifier.java
Sun Mar 25 03:36:38 2007
@@ -20,7 +20,7 @@
import wicket.markup.ComponentTag;
import wicket.markup.parser.XmlTag;
import wicket.model.IModel;
-import wicket.util.value.ValueMap;
+import wicket.util.value.IValueMap;
/**
* This class allows a tag attribute of a component to be modified dynamically
@@ -234,7 +234,7 @@
{
if (isEnabled(component))
{
- final ValueMap attributes = tag.getAttributes();
+ final IValueMap attributes = tag.getAttributes();
final Object replacementValue =
getReplacementOrNull(component);
if (VALUELESS_ATTRIBUTE_ADD.equals(replacementValue))
Modified:
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/ComponentTag.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/ComponentTag.java?view=diff&rev=522190&r1=522189&r2=522190
==============================================================================
---
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/ComponentTag.java
(original)
+++
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/ComponentTag.java
Sun Mar 25 03:36:38 2007
@@ -31,7 +31,7 @@
import wicket.util.string.AppendingStringBuffer;
import wicket.util.string.StringValue;
import wicket.util.string.Strings;
-import wicket.util.value.ValueMap;
+import wicket.util.value.IValueMap;
/**
* A subclass of MarkupElement which represents a "significant" markup tag,
such
@@ -195,7 +195,7 @@
* @see wicket.markup.parser.XmlTag#getAttributes()
* @return The tag#s attributes
*/
- public final ValueMap getAttributes()
+ public final IValueMap getAttributes()
{
return xmlTag.getAttributes();
}
Modified:
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/ContainerWithAssociatedMarkupHelper.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/ContainerWithAssociatedMarkupHelper.java?view=diff&rev=522190&r1=522189&r2=522190
==============================================================================
---
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/ContainerWithAssociatedMarkupHelper.java
(original)
+++
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/ContainerWithAssociatedMarkupHelper.java
Sun Mar 25 03:36:38 2007
@@ -30,7 +30,7 @@
import wicket.markup.html.internal.HtmlHeaderContainer;
import wicket.response.NullResponse;
import wicket.util.lang.Classes;
-import wicket.util.value.ValueMap;
+import wicket.util.value.IValueMap;
/**
* A Wicket internal helper class to handle wicket:head tags.
@@ -165,7 +165,7 @@
final ComponentTag tag =
(ComponentTag)iter.next();
if (TagUtils.isBodyTag(tag))
{
- ValueMap attributes =
tag.getAttributes();
+ IValueMap attributes =
tag.getAttributes();
final String onLoad =
attributes.getString(attributes.getKey("onload"));
if (onLoad != null)
{
Modified:
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/resources/JavaScriptReference.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/resources/JavaScriptReference.java?view=diff&rev=522190&r1=522189&r2=522190
==============================================================================
---
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/resources/JavaScriptReference.java
(original)
+++
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/resources/JavaScriptReference.java
Sun Mar 25 03:36:38 2007
@@ -20,7 +20,7 @@
import wicket.ResourceReference;
import wicket.markup.ComponentTag;
import wicket.model.IModel;
-import wicket.util.value.ValueMap;
+import wicket.util.value.IValueMap;
/**
* Link to a packaged JavaScript file.
@@ -98,7 +98,7 @@
{
// Must be attached to a script tag
checkComponentTag(tag, "script");
- ValueMap attributes = tag.getAttributes();
+ IValueMap attributes = tag.getAttributes();
attributes.put("type", "text/javascript");
}
Modified:
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/resources/StyleSheetReference.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/resources/StyleSheetReference.java?view=diff&rev=522190&r1=522189&r2=522190
==============================================================================
---
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/resources/StyleSheetReference.java
(original)
+++
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/resources/StyleSheetReference.java
Sun Mar 25 03:36:38 2007
@@ -19,6 +19,7 @@
import wicket.ResourceReference;
import wicket.markup.ComponentTag;
import wicket.model.IModel;
+import wicket.util.value.IValueMap;
import wicket.util.value.ValueMap;
/**
@@ -83,7 +84,7 @@
{
// Must be attached to a style tag
checkComponentTag(tag, "link");
- ValueMap attributes = tag.getAttributes();
+ IValueMap attributes = tag.getAttributes();
attributes.put("rel", "stylesheet");
attributes.put("type", "text/css");
}
Modified:
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/parser/IXmlPullParser.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/parser/IXmlPullParser.java?view=diff&rev=522190&r1=522189&r2=522190
==============================================================================
---
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/parser/IXmlPullParser.java
(original)
+++
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/parser/IXmlPullParser.java
Sun Mar 25 03:36:38 2007
@@ -18,8 +18,8 @@
import java.io.IOException;
import java.io.InputStream;
+import java.text.ParseException;
-import wicket.util.resource.IResourceStream;
import wicket.util.resource.ResourceStreamNotFoundException;
/**
@@ -37,14 +37,14 @@
*
* @return if null, JVM defaults have been used.
*/
- public abstract String getEncoding();
+ String getEncoding();
/**
* Return the XML declaration string, in case if found in the markup.
*
* @return Null, if not found.
*/
- public String getXmlDeclaration();
+ String getXmlDeclaration();
/**
* Wicket dissects the markup into Wicket relevant tags and raw markup,
@@ -55,7 +55,7 @@
* To position
* @return The raw markup in between the position marker and toPos
*/
- public abstract CharSequence getInputFromPositionMarker(int toPos);
+ CharSequence getInputFromPositionMarker(int toPos);
/**
* Wicket dissects the markup into Wicket relevant tags and raw markup,
@@ -68,7 +68,19 @@
* To position
* @return The raw markup in between fromPos and toPos
*/
- public abstract CharSequence getInput(final int fromPos, final int
toPos);
+ CharSequence getInput(final int fromPos, final int toPos);
+
+ /**
+ * Dissect the XML markup into tags and text. Tags are further analysed
into
+ * comments, CDATA, processing instruction etc as well as "standard"
tags.
+ * By means of getType() the type of the current element can be
retrieved
+ * and the appropriate getters must used to get hold of the
informantion.
+ *
+ * @return false, if end-of-file as been reached. If true, than use
+ * getType() to determine what has been found.
+ * @throws ParseException
+ */
+ boolean next() throws ParseException;
/**
* Parse the markup provided. Use nextTag() to access the tags
contained one
@@ -84,26 +96,7 @@
* @throws ResourceStreamNotFoundException
* Resource not found
*/
- public abstract void parse(final CharSequence string) throws
IOException,
- ResourceStreamNotFoundException;
-
- /**
- * Reads and parses markup from a resource like file. Use nextTag() to
- * access the tags contained, one after another.
- *
- * @param resource
- * A resource like e.g. a file
- * @param encoding
- * Use null to apply JVM/OS default
- * @throws IOException
- * Error while reading the resource
- * @throws ResourceStreamNotFoundException
- * Resource not found
- *
- * @deprecated Removed in 2.0
- */
- public abstract void parse(final IResourceStream resource, final String
encoding)
- throws IOException, ResourceStreamNotFoundException;
+ void parse(final CharSequence string) throws IOException,
ResourceStreamNotFoundException;
/**
* Reads and parses markup from an input stream, using UTF-8 encoding by
@@ -133,18 +126,18 @@
* @throws ResourceStreamNotFoundException
* Resource not found
*/
- public abstract void parse(final InputStream inputStream, final String
encoding)
- throws IOException, ResourceStreamNotFoundException;
+ void parse(InputStream inputStream, final String encoding) throws
IOException,
+ ResourceStreamNotFoundException;
/**
* Set the position marker of the markup at the current position.
*/
- public abstract void setPositionMarker();
+ void setPositionMarker();
/**
* Set the position marker of the markup
*
* @param pos
*/
- public abstract void setPositionMarker(final int pos);
+ void setPositionMarker(final int pos);
}
Modified:
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/parser/XmlPullParser.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/parser/XmlPullParser.java?view=diff&rev=522190&r1=522189&r2=522190
==============================================================================
---
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/parser/XmlPullParser.java
(original)
+++
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/parser/XmlPullParser.java
Sun Mar 25 03:36:38 2007
@@ -17,6 +17,7 @@
package wicket.markup.parser;
import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
@@ -26,9 +27,7 @@
import wicket.util.io.XmlReader;
import wicket.util.parse.metapattern.parsers.TagNameParser;
import wicket.util.parse.metapattern.parsers.VariableAssignmentParser;
-import wicket.util.resource.IResourceStream;
import wicket.util.resource.ResourceStreamNotFoundException;
-import wicket.util.resource.StringResourceStream;
/**
* A fairly shallow markup pull parser which parses a markup string of a given
@@ -40,6 +39,27 @@
*/
public final class XmlPullParser extends AbstractMarkupFilter implements
IXmlPullParser
{
+ /** next() must be called at least once for the Type to be valid */
+ public static final int NOT_INITIALIZED = 0;
+
+ /** <name ...> */
+ public static final int TAG = 1;
+
+ /** Tag body in between two tags */
+ public static final int BODY = 2;
+
+ /** <!-- ... --> */
+ public static final int COMMENT = 3;
+
+ /** <![CDATA[ .. ]]> */
+ public static final int CDATA = 4;
+
+ /** <?...> */
+ public static final int PROCESSING_INSTRUCTION = 5;
+
+ /** all other tags which look like <!.. > */
+ public static final int SPECIAL_TAG = 6;
+
/**
* Reads the xml data from an input stream and converts the chars
according
* to its encoding (<?xml ... encoding="..." ?>)
@@ -55,13 +75,20 @@
/** temporary variable which will hold the name of the closing tag. */
private String skipUntilText;
+ /** The last substring selected from the input */
+ private CharSequence lastText;
+
+ /** The type of what is in lastText */
+ private int lastType = NOT_INITIALIZED;
+
+ /** If lastType == TAG, than ... */
+ private XmlTag lastTag;
+
/**
* Construct.
*/
public XmlPullParser()
{
- // The xml parser does not have a parent filter
- super(null);
}
/**
@@ -86,7 +113,7 @@
*
* @see
wicket.markup.parser.IXmlPullParser#getInputFromPositionMarker(int)
*/
- public final CharSequence getInputFromPositionMarker(int toPos)
+ public final CharSequence getInputFromPositionMarker(final int toPos)
{
return this.input.getSubstring(toPos);
}
@@ -132,8 +159,10 @@
}
this.input.setPosition(pos);
+ this.lastText = this.input.getSubstring(startIndex, pos);
+ this.lastType = BODY;
- // Get index of closing tag and advance past the tag
+ // Check that the tag is properly closed
lastPos = this.input.find('>', lastPos + tagNameLen);
if (lastPos == -1)
{
@@ -151,40 +180,150 @@
* @return The extracted tag (will always be of type XmlTag).
* @throws ParseException
*/
- public final MarkupElement nextTag() throws ParseException
+ public final boolean next() throws ParseException
{
+ // Reached end of markup file?
+ if (this.input.getPosition() >= this.input.size())
+ {
+ return false;
+ }
+
if (this.skipUntilText != null)
{
skipUntil();
+ return true;
}
- // While we can find an open tag, parse the tag
- int openBracketIndex = this.input.find('<');
- if (openBracketIndex == -1)
+ // Any more tags in the markup?
+ final int openBracketIndex = this.input.find('<');
+
+ // Tag or Body?
+ if (this.input.charAt(this.input.getPosition()) != '<')
{
- // There is no next matching tag
- return null;
+ if (openBracketIndex == -1)
+ {
+ // There is no next matching tag.
+ this.lastText = this.input.getSubstring(-1);
+ this.input.setPosition(this.input.size());
+ this.lastType = BODY;
+ return true;
+ }
+
+ this.lastText =
this.input.getSubstring(openBracketIndex);
+ this.input.setPosition(openBracketIndex);
+ this.lastType = BODY;
+ return true;
}
-
- // Determine line number
+
+ // Determine the line number
this.input.countLinesTo(openBracketIndex);
// Get index of closing tag and advance past the tag
int closeBracketIndex = this.input.find('>', openBracketIndex +
1);
-
if (closeBracketIndex == -1)
{
- throw new ParseException("No matching close bracket at
position "
- + openBracketIndex,
this.input.getPosition());
+ throw new ParseException("No matching close bracket at
position " + openBracketIndex,
+ this.input.getPosition());
}
+ // Get the complete tag text
+ this.lastText = this.input.getSubstring(openBracketIndex,
closeBracketIndex + 1);
+
// Get the tagtext between open and close brackets
- String tagText = this.input.getSubstring(openBracketIndex + 1,
closeBracketIndex)
- .toString();
+ String tagText = this.lastText.subSequence(1,
this.lastText.length() - 1).toString();
+ if (tagText.length() == 0)
+ {
+ throw new ParseException("Found empty tag: '<>' at
position " + openBracketIndex,
+ this.input.getPosition());
+ }
+ // Handle special tags like <!-- and <![CDATA ...
+ final char firstChar = tagText.charAt(0);
+ if ((firstChar == '!') || (firstChar == '?'))
+ {
+ specialTagHandling(tagText, openBracketIndex,
closeBracketIndex);
+ return true;
+ }
+
+ // Type of the tag, to be determined next
+ final XmlTag.Type type;
+
+ // If the tag ends in '/', it's a "simple" tag like <foo/>
+ if (tagText.endsWith("/"))
+ {
+ type = XmlTag.OPEN_CLOSE;
+ tagText = tagText.substring(0, tagText.length() - 1);
+ }
+ else if (tagText.startsWith("/"))
+ {
+ // The tag text starts with a '/', it's a simple close
tag
+ type = XmlTag.CLOSE;
+ tagText = tagText.substring(1);
+ }
+ else
+ {
+ // It must be an open tag
+ type = XmlTag.OPEN;
+
+ // If open tag and starts with "s" like "script" or
"style", than
+ // ...
+ if ((tagText.length() > 5)
+ && ((tagText.charAt(0) == 's') ||
(tagText.charAt(0) == 'S')))
+ {
+ final String lowerCase = tagText.substring(0,
6).toLowerCase();
+ if (lowerCase.startsWith("script"))
+ {
+ // prepare to skip everything between
the open and close tag
+ this.skipUntilText = "script";
+ }
+ else if (lowerCase.startsWith("style"))
+ {
+ // prepare to skip everything between
the open and close tag
+ this.skipUntilText = "style";
+ }
+ }
+ }
+
+ // Parse remaining tag text, obtaining a tag object or null
+ // if it's invalid
+ this.lastTag = parseTagText(tagText);
+ if (this.lastTag != null)
+ {
+ // Populate tag fields
+ this.lastTag.type = type;
+ this.lastTag.pos = openBracketIndex;
+ this.lastTag.length = this.lastText.length();
+ this.lastTag.text = this.lastText;
+ this.lastTag.lineNumber = this.input.getLineNumber();
+ this.lastTag.columnNumber =
this.input.getColumnNumber();
+
+ // Move to position after the tag
+ this.input.setPosition(closeBracketIndex + 1);
+ this.lastType = TAG;
+ return true;
+ }
+ else
+ {
+ throw new ParseException("Malformed tag (line " +
this.input.getLineNumber()
+ + ", column " +
this.input.getColumnNumber() + ")", openBracketIndex);
+ }
+ }
+
+ /**
+ * Handle special tags like <!-- --> or <![CDATA[..]]> or <?xml>
+ *
+ * @param tagText
+ * @param openBracketIndex
+ * @param closeBracketIndex
+ * @throws ParseException
+ */
+ private void specialTagHandling(String tagText, final int
openBracketIndex,
+ int closeBracketIndex) throws ParseException
+ {
// Handle comments
if (tagText.startsWith("!--"))
{
+ // Normal comment section.
// Skip ahead to "-->". Note that you can not simply
test for
// tagText.endsWith("--") as the comment might contain
a '>'
// inside.
@@ -195,119 +334,118 @@
+ input.getLineNumber() + "
column:" + input.getColumnNumber(),
openBracketIndex);
}
-
+
+ pos += 3;
+ this.lastText =
this.input.getSubstring(openBracketIndex, pos);
+ this.lastType = COMMENT;
+
// Conditional comment? <!--[if ...]>..<![endif]-->
if (tagText.startsWith("!--[if ") &&
tagText.endsWith("]")
- && this.input.getSubstring(pos + 3 -
12, pos + 3).equals("<![endif]-->"))
+ &&
this.lastText.toString().endsWith("<![endif]-->"))
{
- // fall through
+ // Actually it is no longer a comment. It is now
+ // up to the browser to select the section
appropriate.
+ this.input.setPosition(closeBracketIndex + 1);
}
else
{
- this.input.setPosition(pos + 3);
- return nextTag();
+ this.input.setPosition(pos);
}
+ return;
}
-
+
+ // The closing tag of a conditional comment <!--[if
IE]>...<![endif]-->
+ if (tagText.equals("![endif]--"))
+ {
+ this.lastType = COMMENT;
+ this.input.setPosition(closeBracketIndex + 1);
+ return;
+ }
+
// CDATA sections might contain "<" which is not part of an XML
tag.
// Make sure escaped "<" are treated right
- final String startText = (tagText.length() <= 8 ? tagText :
tagText.substring(0, 8));
- if (startText.toUpperCase().equals("![CDATA["))
+ if (tagText.startsWith("!["))
{
- int pos1 = openBracketIndex;
- do
+ final String startText = (tagText.length() <= 8 ?
tagText : tagText.substring(0, 8));
+ if (startText.toUpperCase().equals("![CDATA["))
{
- // Get index of closing tag and advance past
the tag
- closeBracketIndex = findCloseBracket('>', pos1);
-
- if (closeBracketIndex == -1)
+ int pos1 = openBracketIndex;
+ do
{
- throw new ParseException("No matching
close bracket at position "
- + openBracketIndex,
this.input.getPosition());
+ // Get index of closing tag and advance
past the tag
+ closeBracketIndex = findChar('>', pos1);
+
+ if (closeBracketIndex == -1)
+ {
+ throw new ParseException("No
matching close bracket at line:"
+ +
input.getLineNumber() + " column:" + input.getColumnNumber(),
+
this.input.getPosition());
+ }
+
+ // Get the tagtext between open and
close brackets
+ tagText =
this.input.getSubstring(openBracketIndex + 1, closeBracketIndex)
+ .toString();
+
+ pos1 = closeBracketIndex + 1;
}
-
- // Get the tagtext between open and close
brackets
- tagText =
this.input.getSubstring(openBracketIndex + 1, closeBracketIndex)
- .toString();
-
- pos1 = closeBracketIndex + 1;
+ while (tagText.endsWith("]]") == false);
+
+ // Move to position after the tag
+ this.input.setPosition(closeBracketIndex + 1);
+
+ this.lastText = tagText;
+ this.lastType = CDATA;
+ return;
}
- while (tagText.endsWith("]]") == false);
}
+ if (tagText.charAt(0) == '?')
{
- // Type of tag
- XmlTag.Type type = XmlTag.OPEN;
+ this.lastType = PROCESSING_INSTRUCTION;
- // If the tag ends in '/', it's a "simple" tag like
<foo/>
- if (tagText.endsWith("/"))
- {
- type = XmlTag.OPEN_CLOSE;
- tagText = tagText.substring(0, tagText.length()
- 1);
- }
- else if (tagText.startsWith("/"))
- {
- // The tag text starts with a '/', it's a
simple close tag
- type = XmlTag.CLOSE;
- tagText = tagText.substring(1);
- }
+ // Move to position after the tag
+ this.input.setPosition(closeBracketIndex + 1);
+ return;
+ }
- // We don't deeply parse tags like DOCTYPE that start
with !
- // or XML document definitions that start with ?
- if (tagText.startsWith("!") || tagText.startsWith("?"))
- {
- // Move to position after the tag
- this.input.setPosition(closeBracketIndex + 1);
+ // Move to position after the tag
+ this.lastType = SPECIAL_TAG;
+ this.input.setPosition(closeBracketIndex + 1);
+ }
- // Return next tag
- return nextTag();
- }
- else
+ /**
+ * Gets the next tag from the input string.
+ *
+ * @return The extracted tag (will always be of type XmlTag).
+ * @throws ParseException
+ */
+ public final MarkupElement nextTag() throws ParseException
+ {
+ while (next())
+ {
+ switch (this.lastType)
{
- String lowerCase = tagText.toLowerCase();
+ case TAG :
+ return this.lastTag;
- // Often save a (longer) comparison at the
expense of a
- // extra shorter one for 's' tags
- if ((type == XmlTag.OPEN) &&
lowerCase.startsWith("s"))
- {
- if (lowerCase.startsWith("script"))
- {
- this.skipUntilText = "script";
- }
- else if (lowerCase.startsWith("style"))
- {
- this.skipUntilText = "style";
- }
- }
+ case BODY :
+ break;
- // Parse remaining tag text, obtaining a tag
object or null
- // if it's invalid
- final XmlTag tag = parseTagText(tagText);
- if (tag != null)
- {
- // Populate tag fields
- tag.type = type;
- tag.pos = openBracketIndex;
- tag.length = (closeBracketIndex + 1) -
openBracketIndex;
- tag.text =
this.input.getSubstring(openBracketIndex, closeBracketIndex + 1)
- .toString();
- tag.lineNumber =
this.input.getLineNumber();
- tag.columnNumber =
this.input.getColumnNumber();
+ case COMMENT :
+ break;
- // Move to position after the tag
-
this.input.setPosition(closeBracketIndex + 1);
+ case CDATA :
+ break;
- // Return the tag we found!
- return tag;
- }
- else
- {
- throw new ParseException("Malformed tag
(line "
- +
this.input.getLineNumber() + ", column "
- +
this.input.getColumnNumber() + ")", openBracketIndex);
- }
+ case PROCESSING_INSTRUCTION :
+ break;
+
+ case SPECIAL_TAG :
+ break;
}
}
+
+ return null;
}
/**
@@ -319,13 +457,13 @@
* Start index
* @return -1 if not found, else the index
*/
- private int findCloseBracket(final char ch, int startIndex)
+ private int findChar(final char ch, int startIndex)
{
char quote = 0;
for (; startIndex < this.input.size(); startIndex++)
{
- char charAt = this.input.charAt(startIndex);
+ final char charAt = this.input.charAt(startIndex);
if (quote != 0)
{
if (quote == charAt)
@@ -362,35 +500,7 @@
public void parse(final CharSequence string) throws IOException,
ResourceStreamNotFoundException
{
- parse(new StringResourceStream(string), null);
- }
-
- /**
- * Reads and parses markup from a resource such as file.
- *
- * @param resource
- * The resource to read and parse
- * @param encoding
- * Default character encoding to use when not specified in
XML declaration, specify null to use JVM default
- * @throws IOException
- * @throws ResourceStreamNotFoundException
- *
- * @deprecated Removed in 2.0
- */
- public void parse(final IResourceStream resource, final String
encoding) throws IOException,
- ResourceStreamNotFoundException
- {
- try
- {
- this.xmlReader = new XmlReader(
- new
BufferedInputStream(resource.getInputStream(), 4000), encoding);
- this.input = new FullyBufferedReader(this.xmlReader);
- }
- finally
- {
- resource.close();
- if(this.xmlReader != null) this.xmlReader.close();
- }
+ parse(new ByteArrayInputStream(string.toString().getBytes()),
null);
}
/**
@@ -431,7 +541,10 @@
finally
{
inputStream.close();
- if(this.xmlReader != null) this.xmlReader.close();
+ if(this.xmlReader != null)
+ {
+ this.xmlReader.close();
+ }
}
}
@@ -495,7 +608,6 @@
// Extract attributes
final VariableAssignmentParser attributeParser = new
VariableAssignmentParser(tagText);
-
while (attributeParser.matcher().find(pos))
{
// Get key and value using attribute pattern
Modified:
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/parser/XmlTag.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/parser/XmlTag.java?view=diff&rev=522190&r1=522189&r2=522190
==============================================================================
---
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/parser/XmlTag.java
(original)
+++
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/parser/XmlTag.java
Sun Mar 25 03:36:38 2007
@@ -24,7 +24,8 @@
import wicket.util.string.AppendingStringBuffer;
import wicket.util.string.StringValue;
import wicket.util.string.Strings;
-import wicket.util.value.AttributeMap;
+import wicket.util.value.IValueMap;
+import wicket.util.value.ValueMap;
/**
* A subclass of MarkupElement which represents a tag including namespace and
@@ -44,7 +45,7 @@
public static final Type OPEN_CLOSE = new Type("OPEN_CLOSE");
/** Attribute map. */
- private AttributeMap attributes;
+ private IValueMap attributes;
/** Column number. */
int columnNumber;
@@ -65,7 +66,7 @@
int pos;
/** Full text of tag. */
- String text;
+ CharSequence text;
/** The tag type (OPEN, CLOSE or OPEN_CLOSE). */
Type type;
@@ -125,23 +126,31 @@
*
* @return The tag's attributes
*/
- public AttributeMap getAttributes()
+ public IValueMap getAttributes()
{
if (attributes == null)
{
- if (copyOf == this)
+ if ((copyOf == this) || (copyOf == null) ||
(copyOf.attributes == null))
{
- attributes = new AttributeMap();
+ attributes = new ValueMap();
}
else
{
- attributes = new
AttributeMap(copyOf.attributes);
+ attributes = new ValueMap(copyOf.attributes);
}
}
return attributes;
}
/**
+ * @return true if there 1 or more attributes.
+ */
+ public boolean hasAttributes()
+ {
+ return attributes != null && attributes.size() > 0;
+ }
+
+ /**
* Get the column number.
*
* @return Returns the columnNumber.
@@ -172,7 +181,8 @@
}
/**
- * Gets the name of the tag, for example the tag
<code><b></code>'s name would be 'b'.
+ * Gets the name of the tag, for example the tag
<code><b></code>'s
+ * name would be 'b'.
*
* @return The tag's name
*/
@@ -192,7 +202,7 @@
}
/**
- * Namespace of the tag, if available. For example,
<wicket:link>.
+ * Namespace of the tag, if available. For example, <wicket:link>.
*
* @return The tag's namespace
*/
@@ -286,7 +296,7 @@
* Compare tag name including namespace
*
* @param tag
- * @return true if name and namespace are equal
+ * @return true if name and namespace are equal
*/
public boolean hasEqualTagName(final XmlTag tag)
{
@@ -321,6 +331,7 @@
if (attributes != null)
{
attributes.makeImmutable();
+ text = null;
}
}
}
@@ -351,7 +362,10 @@
tag.isMutable = true;
tag.closes = closes;
tag.copyOf = copyOf;
-
+ if (attributes != null)
+ {
+ tag.attributes = new ValueMap(attributes);
+ }
return tag;
}
}
@@ -364,9 +378,9 @@
* @param value
* The value
* @return previous value associated with specified key, or null if
there
- * was no mapping for key. A null return can also
indicate that the
- * map previously associated null with the specified
key, if the
- * implementation supports null values.
+ * was no mapping for key. A null return can also indicate that
the
+ * map previously associated null with the specified key, if the
+ * implementation supports null values.
*/
public Object put(final String key, final boolean value)
{
@@ -381,9 +395,9 @@
* @param value
* The value
* @return previous value associated with specified key, or null if
there
- * was no mapping for key. A null return can also
indicate that the
- * map previously associated null with the specified
key, if the
- * implementation supports null values.
+ * was no mapping for key. A null return can also indicate that
the
+ * map previously associated null with the specified key, if the
+ * implementation supports null values.
*/
public Object put(final String key, final int value)
{
@@ -398,9 +412,9 @@
* @param value
* The value
* @return previous value associated with specified key, or null if
there
- * was no mapping for key. A null return can also
indicate that the
- * map previously associated null with the specified
key, if the
- * implementation supports null values.
+ * was no mapping for key. A null return can also indicate that
the
+ * map previously associated null with the specified key, if the
+ * implementation supports null values.
*/
public Object put(final String key, final CharSequence value)
{
@@ -415,9 +429,9 @@
* @param value
* The value
* @return previous value associated with specified key, or null if
there
- * was no mapping for key. A null return can also
indicate that the
- * map previously associated null with the specified
key, if the
- * implementation supports null values.
+ * was no mapping for key. A null return can also indicate that
the
+ * map previously associated null with the specified key, if the
+ * implementation supports null values.
*/
public Object put(final String key, final StringValue value)
{
@@ -590,15 +604,16 @@
buffer.append(name);
- final AttributeMap attributes = getAttributes();
+ final IValueMap attributes = getAttributes();
if (attributes.size() > 0)
{
final Iterator iterator =
attributes.keySet().iterator();
for (; iterator.hasNext();)
{
final String key = (String)iterator.next();
- if ((key != null) && ((attributeToBeIgnored ==
null) ||
-
!key.equalsIgnoreCase(attributeToBeIgnored)))
+ if ((key != null)
+ && ((attributeToBeIgnored ==
null) || !key
+
.equalsIgnoreCase(attributeToBeIgnored)))
{
buffer.append(" ");
buffer.append(key);
Modified:
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/parser/filter/WicketLinkTagHandler.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/parser/filter/WicketLinkTagHandler.java?view=diff&rev=522190&r1=522189&r2=522190
==============================================================================
---
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/parser/filter/WicketLinkTagHandler.java
(original)
+++
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/parser/filter/WicketLinkTagHandler.java
Sun Mar 25 03:36:38 2007
@@ -27,7 +27,7 @@
import wicket.util.collections.ArrayListStack;
import wicket.util.string.StringValueConversionException;
import wicket.util.string.Strings;
-import wicket.util.value.ValueMap;
+import wicket.util.value.IValueMap;
/**
* This is a markup inline filter. It identifies xml tags which include a href
@@ -178,7 +178,7 @@
{
if (tag.getId() == null)
{
- ValueMap attributes = tag.getAttributes();
+ IValueMap attributes = tag.getAttributes();
String ref = attributes.getString("href");
if (checkRef(ref))
{
Modified:
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/parser/filter/WicketNamespaceHandler.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/parser/filter/WicketNamespaceHandler.java?view=diff&rev=522190&r1=522189&r2=522190
==============================================================================
---
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/parser/filter/WicketNamespaceHandler.java
(original)
+++
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/parser/filter/WicketNamespaceHandler.java
Sun Mar 25 03:36:38 2007
@@ -25,7 +25,7 @@
import wicket.markup.Markup;
import wicket.markup.MarkupElement;
import wicket.markup.parser.AbstractMarkupFilter;
-import wicket.util.value.ValueMap;
+import wicket.util.value.IValueMap;
/**
* This is a markup inline filter. It determines the Wicket namespace name from
@@ -100,7 +100,7 @@
private String determineWicketNamespace(final ComponentTag tag)
{
// For all tags attributes
- final ValueMap attributes = tag.getAttributes();
+ final IValueMap attributes = tag.getAttributes();
final Iterator it = attributes.entrySet().iterator();
while (it.hasNext())
{
Modified:
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/tester/TagTester.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/tester/TagTester.java?view=diff&rev=522190&r1=522189&r2=522190
==============================================================================
---
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/tester/TagTester.java
(original)
+++
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/tester/TagTester.java
Sun Mar 25 03:36:38 2007
@@ -23,7 +23,7 @@
import wicket.markup.parser.XmlPullParser;
import wicket.markup.parser.XmlTag;
import wicket.util.string.Strings;
-import wicket.util.value.AttributeMap;
+import wicket.util.value.IValueMap;
/**
* Tag tester is used to test that a generated markup tag contains the correct
@@ -110,7 +110,7 @@
{
String value = null;
- AttributeMap attributeMap = openTag.getAttributes();
+ IValueMap attributeMap = openTag.getAttributes();
if (attributeMap != null)
{
@@ -359,7 +359,7 @@
if (openTag == null)
{
- AttributeMap
attributeMap = xmlTag.getAttributes();
+ IValueMap attributeMap
= xmlTag.getAttributes();
for (Iterator iter =
attributeMap.keySet().iterator(); iter.hasNext();)
{
Modified:
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/markup/parser/XmlPullParserTest.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/markup/parser/XmlPullParserTest.java?view=diff&rev=522190&r1=522189&r2=522190
==============================================================================
---
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/markup/parser/XmlPullParserTest.java
(original)
+++
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/markup/parser/XmlPullParserTest.java
Sun Mar 25 03:36:38 2007
@@ -128,31 +128,31 @@
public final void testEncoding() throws Exception
{
final XmlPullParser parser = new XmlPullParser();
- parser.parse(new StringResourceStream("<?xml version=\"1.0\"
encoding=\"iso-8859-1\" ?>"), null);
+ parser.parse(new StringResourceStream("<?xml version=\"1.0\"
encoding=\"iso-8859-1\" ?>").getInputStream(), null);
assertEquals("iso-8859-1", parser.getEncoding());
XmlTag tag = (XmlTag) parser.nextTag();
assertNull(tag);
- parser.parse(new StringResourceStream("<?xml version=\"1.0\"
encoding='iso-8859-1' ?> test test"), null);
+ parser.parse(new StringResourceStream("<?xml version=\"1.0\"
encoding='iso-8859-1' ?> test test").getInputStream(), null);
assertEquals("iso-8859-1", parser.getEncoding());
tag = (XmlTag) parser.nextTag();
assertNull(tag);
// re-order and move close (remove whitespaces
- parser.parse(new StringResourceStream(" <?xml
encoding='iso-8859-1'version=\"1.0\"?> test test"), null);
+ parser.parse(new StringResourceStream(" <?xml
encoding='iso-8859-1'version=\"1.0\"?> test test").getInputStream(), null);
assertEquals("iso-8859-1", parser.getEncoding());
tag = (XmlTag) parser.nextTag();
assertNull(tag);
// attribute value must be enclosed by ""
- parser.parse(new StringResourceStream("<?xml encoding=iso-8859-1 ?>
test test"), null);
+ parser.parse(new StringResourceStream("<?xml encoding=iso-8859-1 ?>
test test").getInputStream(), null);
assertEquals("iso-8859-1", parser.getEncoding());
// Invaluid encoding
Exception ex = null;
try
{
- parser.parse(new StringResourceStream("<?xml encoding='XXX' ?>"),
null);
+ parser.parse(new StringResourceStream("<?xml encoding='XXX'
?>").getInputStream(), null);
}
catch (UnsupportedEncodingException e)
{
@@ -162,20 +162,20 @@
// no extra characters allowed before <?xml>
// TODO General: I'd certainly prefer an exception
- parser.parse(new StringResourceStream("xxxx <?xml
encoding='iso-8859-1' ?>"), null);
+ parser.parse(new StringResourceStream("xxxx <?xml
encoding='iso-8859-1' ?>").getInputStream(), null);
assertNull(parser.getEncoding());
tag = (XmlTag) parser.nextTag();
assertNull(tag);
// no extra characters allowed before <?xml>
// Are comments allowed preceding the encoding string?
- parser.parse(new StringResourceStream("<!-- Comment --> <?xml
encoding='iso-8859-1' ?>"), null);
+ parser.parse(new StringResourceStream("<!-- Comment --> <?xml
encoding='iso-8859-1' ?>").getInputStream(), null);
assertNull(parser.getEncoding());
tag = (XmlTag) parser.nextTag();
assertNull(tag);
// 'test' is not a valid attribut. But we currently don't test it.
- parser.parse(new StringResourceStream("<?xml test='123' >"), null);
+ parser.parse(new StringResourceStream("<?xml test='123'
>").getInputStream(), null);
assertNull(parser.getEncoding());
tag = (XmlTag) parser.nextTag();
assertNull(tag);
@@ -329,6 +329,10 @@
assertNull(tag);
}
+ /**
+ *
+ * @throws Exception
+ */
public final void testNames() throws Exception
{
final XmlPullParser parser = new XmlPullParser();