Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser
In directory sc8-pr-cvs1:/tmp/cvs-serv18761/src/org/htmlparser
Modified Files:
Node.java Parser.java StringNode.java
Log Message:
add setting for parser to perform the Translate.decode() on all StringNodes. This will later be refactored to a Decorator implementation.
Index: Node.java
===================================================================
RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/Node.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -d -r1.24 -r1.25
*** Node.java 13 Jun 2003 20:27:04 -0000 1.24
--- Node.java 17 Jun 2003 03:26:19 -0000 1.25
***************
*** 113,115 ****
--- 113,116 ----
*/
public abstract void setParent(CompositeTag tag);
+
}
Index: Parser.java
===================================================================
RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/Parser.java,v
retrieving revision 1.44
retrieving revision 1.45
diff -C2 -d -r1.44 -r1.45
*** Parser.java 13 Jun 2003 20:27:04 -0000 1.44
--- Parser.java 17 Jun 2003 03:26:19 -0000 1.45
***************
*** 183,186 ****
--- 183,193 ----
/**
+ * Flag to tell the parser to decode nodes while parsing.
+ * Decoding occurs via the method, org.htmlparser.util.Translate.decode()
+ */
+ private boolean shouldDecodeNodes = false;
+
+
+ /**
* Feedback object.
*/
***************
*** 1208,1211 ****
--- 1215,1229 ----
public static String getLineSeparator() {
return lineSeparator;
+ }
+
+ /**
+ * Tells the parser to decode nodes using org.htmlparser.util.Translate.decode()
+ */
+ public void setNodeDecoding(boolean shouldDecodeNodes) {
+ this.shouldDecodeNodes = shouldDecodeNodes;
+ }
+
+ public boolean shouldDecodeNodes() {
+ return shouldDecodeNodes;
}
}
Index: StringNode.java
===================================================================
RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/StringNode.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** StringNode.java 13 Jun 2003 20:27:04 -0000 1.20
--- StringNode.java 17 Jun 2003 03:26:19 -0000 1.21
***************
*** 31,34 ****
--- 31,35 ----
import org.htmlparser.util.NodeList;
+ import org.htmlparser.util.Translate;
import org.htmlparser.visitors.NodeVisitor;
***************
*** 38,42 ****
--- 39,49 ----
public class StringNode extends AbstractNode
{
+ /**
+ * boolean to tell whether decoding of this node should happen or not.
+ */
+ private boolean shouldDecode = false;;
+
public static final String STRING_FILTER="-string";
+
/**
* The text of the string.
***************
*** 57,60 ****
--- 64,72 ----
}
+ public StringNode(StringBuffer textBuffer, int textBegin, int textEnd,
+ boolean shouldDecode) {
+ this(textBuffer, textBegin, textEnd);
+ this.shouldDecode = shouldDecode;
+ }
/**
***************
*** 73,82 ****
textBuffer = new StringBuffer (text);
}
public String toPlainTextString() {
! return textBuffer.toString();
}
public String toHtml() {
! return textBuffer.toString();
}
public String toString() {
return "Text = "+getText()+"; begins at : "+elementBegin()+"; ends at : "+elementEnd();
--- 85,104 ----
textBuffer = new StringBuffer (text);
}
+
public String toPlainTextString() {
! return nodeContents();
}
+
public String toHtml() {
! return nodeContents();
}
+
+ private String nodeContents() {
+ String result = textBuffer.toString();
+ if (shouldDecode)
+ result = Translate.decode(result);
+ return result;
+ }
+
public String toString() {
return "Text = "+getText()+"; begins at : "+elementBegin()+"; ends at : "+elementEnd();
|