Permalink
Browse files

Fixed isStartTag always true bug.

Removed use of enhanced for-loop in code.
  • Loading branch information...
1 parent a7c67aa commit 8910b99a832134e14903cd2e1abbf4c38843e4ee Riyad Kalla committed Mar 11, 2011
View
13 README
@@ -1,9 +1,17 @@
-Simple Java XML Parser (for any Java platform, including Android!)
+Simple Java XML Parser (SJXP) for any Java Platform including Android.
http://www.thebuzzmedia.com/software/simple-java-xml-parser-sjxp/
Changelog
---------
+2.1
+ * Fixed bug where isStartTag was always true for TAG type rules
+ https://github.com/thebuzzmedia/simple-java-xml-parser/issues/closed#issue/6
+
+ * Removed use of enhanced for-loop in code base because it caused a large
+ number of AbstractList$Itr classes to be created for no great reason.
+ https://github.com/thebuzzmedia/simple-java-xml-parser/issues/closed#issue/5
+
2.0
* MAJOR PERFORMANCE IMPROVEMENT
@@ -19,14 +27,12 @@ Changelog
Memory usage and performance are increased drastically in this release on all
platforms (especially good for Android).
-
https://github.com/thebuzzmedia/simple-java-xml-parser/issues/4
* New IRule.Type.TAG type is defined which allows rules to be called when
START and END tag events occur without the overhead of parsing data from the
underlying XML stream. This is valuable when you want to examine (e.g. count
elements) the XML content without actually parsing data out of it.
-
https://github.com/thebuzzmedia/simple-java-xml-parser/issues/closed#issue/3
* Support for passing through a user-object from XMLParser to the IRule
@@ -43,7 +49,6 @@ Changelog
Then in the IRule handler code your "user object" object is the passed-through
store object that you can use to store the parsed value. This is just an
example, it can be anything.
-
https://github.com/thebuzzmedia/simple-java-xml-parser/issues/closed#issue/1
1.1
View
@@ -11,7 +11,7 @@
</path>
<property name="version.major" value="2" />
- <property name="version.minor" value="0" />
+ <property name="version.minor" value="1" />
<property name="name.file" value="sjxp" />
<property name="name.file.javadoc" value="${name.file}-${version.major}.${version.minor}-javadoc.jar" />
@@ -471,18 +471,16 @@ protected void initRules(IRule<T>... rules) {
int optSize = (rules.length > 64 ? rules.length * 2 : 64);
// init the rule maps
- // tagRuleMap = new HashMap<String, List<IRule<T>>>(optSize);
- // attrRuleMap = new HashMap<String, List<IRule<T>>>(optSize);
- // charRuleMap = new HashMap<String, List<IRule<T>>>(optSize);
-
tagRuleMap = new HashMap<Integer, List<IRule<T>>>(optSize);
attrRuleMap = new HashMap<Integer, List<IRule<T>>>(optSize);
charRuleMap = new HashMap<Integer, List<IRule<T>>>(optSize);
// init the rules
List<IRule<T>> ruleList = null;
- for (IRule<T> rule : rules) {
+ for (int i = 0, length = rules.length; i < length; i++) {
+ IRule<T> rule = rules[i];
+
switch (rule.getType()) {
case TAG:
// Get the rule list for this path
@@ -645,7 +643,9 @@ protected void doStartTag(T userObject) {
// Process the TAG rules
if (tagRuleList != null) {
- for (IRule<T> rule : tagRuleList) {
+ for (int i = 0, size = tagRuleList.size(); i < size; i++) {
+ IRule<T> rule = tagRuleList.get(i);
+
if (DEBUG)
log("\t\tRunning TAG Rule: %s", rule);
@@ -655,7 +655,9 @@ protected void doStartTag(T userObject) {
// Process the ATTR rules
if (attrRuleList != null) {
- for (IRule<T> rule : attrRuleList) {
+ for (int i = 0, size = attrRuleList.size(); i < size; i++) {
+ IRule<T> rule = attrRuleList.get(i);
+
if (DEBUG)
log("\t\tRunning ATTR Rule: %s", rule);
@@ -678,8 +680,8 @@ protected void doStartTag(T userObject) {
* other approach would have been magnitudes more expensive both
* in memory and CPU requirements than doing a simple substring.
*/
- for (int i = 0; i < attrNames.length; i++) {
- String attrName = attrNames[i];
+ for (int j = 0; j < attrNames.length; j++) {
+ String attrName = attrNames[j];
String localName = null;
String namespaceURI = null;
@@ -718,7 +720,7 @@ protected void doStartTag(T userObject) {
attrName.length());
// Give the parsed attribute value to the matching rule
- rule.handleParsedAttribute(this, i,
+ rule.handleParsedAttribute(this, j,
xpp.getAttributeValue(namespaceURI, localName),
userObject);
}
@@ -758,7 +760,9 @@ protected void doText(T userObject) {
String text = xpp.getText();
// Give the parsed text to all matching IRules for this path
- for (IRule<T> rule : ruleList) {
+ for (int i = 0, size = ruleList.size(); i < size; i++) {
+ IRule<T> rule = ruleList.get(i);
+
if (DEBUG)
log("\t\tRunning Rule: %s", rule);
@@ -789,11 +793,13 @@ protected void doEndTag(T userObject) {
log("\t%d TAG rules found for END_TAG...", tagRuleList.size());
// Process the TAG rules
- for (IRule<T> rule : tagRuleList) {
+ for (int i = 0, size = tagRuleList.size(); i < size; i++) {
+ IRule<T> rule = tagRuleList.get(i);
+
if (DEBUG)
log("\t\tRunning TAG Rule: %s", rule);
- rule.handleTag(this, true, userObject);
+ rule.handleTag(this, false, userObject);
}
}
@@ -21,6 +21,7 @@
import static junit.framework.Assert.*;
+@SuppressWarnings("rawtypes")
public class DefaultRuleTest {
public static final String PATH_EMPTY = "";
public static final String PATH_SIMPLE = "/library/book";

0 comments on commit 8910b99

Please sign in to comment.