[Htmlparser-cvs] htmlparser/src/org/htmlparser/lexer/nodes Attribute.java,1.9,1.10 TagNode.java,1.14
Brought to you by:
derrickoswald
From: <der...@us...> - 2003-10-05 13:50:24
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/lexer/nodes In directory sc8-pr-cvs1:/tmp/cvs-serv9618/lexer/nodes Modified Files: Attribute.java TagNode.java Log Message: Add bean like accessors for positions on Node, AbstractNode and AbstractNodeDecorator. Handle null page in Cursor. Add smartquotes mode in Lexer and CompositeTagScannerHelper. Add simple name constructor in Attribute. Remove emptyxmltag member, replace with computing accessors in TagNode. Removed ScriptScannerHelper and moved scanning logic to ScriptScanner. Reworked extractImageLocn in ImageScanner Implement extractXMLData in TagScanner. Made virtual tags zero length in TagData. Added push() to IteratorImpl. Added single node constructor to NodeList. Numerous and various test adjustments. Still 133 failures. Index: Attribute.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/lexer/nodes/Attribute.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Attribute.java 2 Oct 2003 23:48:53 -0000 1.9 --- Attribute.java 5 Oct 2003 13:49:42 -0000 1.10 *************** *** 135,141 **** --- 135,155 ---- public Attribute (String name, String value, char quote) { + mPage = null; + mNameStart = 0; + mNameEnd = 0; + mValueStart = 0; + mValueEnd = 0; mName = name; mValue = value; mQuote = quote; + } + + /** + * Create a standalone attribute with the name given. + * @param name The name of this attribute. + */ + public Attribute (String name) + { + this (name, (String)null, (char)0); } Index: TagNode.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/lexer/nodes/TagNode.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** TagNode.java 3 Oct 2003 00:20:44 -0000 1.14 --- TagNode.java 5 Oct 2003 13:49:43 -0000 1.15 *************** *** 49,54 **** AbstractNode { - private boolean emptyXmlTag; - /** * The tag attributes. --- 49,52 ---- *************** *** 116,120 **** super (page, start, end); mAttributes = attributes; - emptyXmlTag = false; } --- 114,117 ---- *************** *** 374,394 **** public String getTagName () { - Vector attributes; String ret; ! ret = null; ! ! attributes = getAttributesEx (); ! if (0 != attributes.size ()) { ! ret = getRawTagName (); ! if (null != ret) ! { ! ret = ret.toUpperCase (); ! if (ret.startsWith ("/")) ! ret = ret.substring (1); ! if (ret.endsWith ("/")) ! ret = ret.substring (0, ret.length () - 1); ! } } --- 371,384 ---- public String getTagName () { String ret; ! ret = getRawTagName (); ! if (null != ret) { ! ret = ret.toUpperCase (); ! if (ret.startsWith ("/")) ! ret = ret.substring (1); ! if (ret.endsWith ("/")) ! ret = ret.substring (0, ret.length () - 1); } *************** *** 607,612 **** } } - if (isEmptyXmlTag ()) - ret.append ("/"); ret.append (">"); --- 597,600 ---- *************** *** 668,683 **** /** ! * Is this an empty xml tag of the form<br> ! * <tag/> ! * @return boolean */ public boolean isEmptyXmlTag () { ! return emptyXmlTag; } public void setEmptyXmlTag (boolean emptyXmlTag) { ! this.emptyXmlTag = emptyXmlTag; } --- 656,772 ---- /** ! * Is this an empty xml tag of the form <tag/>. ! * @return true if the last character of the last attribute is a '/'. */ public boolean isEmptyXmlTag () { ! Vector attributes; ! int size; ! Attribute attribute; ! String name; ! int length; ! boolean ret; ! ! ret = false; ! ! attributes = getAttributesEx (); ! size = attributes.size (); ! if (0 < size) ! { ! attribute = (Attribute)attributes.elementAt (size - 1); ! name = attribute.getName (); ! if (null != name) ! { ! length = name.length (); ! ret = name.charAt (length - 1) == '/'; ! } ! } ! ! return (ret); } + /** + * Set this tag to be an empty xml node, or not. + * Adds or removes an ending slash on the tag. + * @param If true, ensures there is an ending slash in the node, + * i.e. <tag/>, otherwise removes it. + */ public void setEmptyXmlTag (boolean emptyXmlTag) { ! Vector attributes; ! int size; ! Attribute attribute; ! String name; ! String value; ! int length; ! ! attributes = getAttributesEx (); ! size = attributes.size (); ! if (0 < size) ! { ! attribute = (Attribute)attributes.elementAt (size - 1); ! name = attribute.getName (); ! if (null != name) ! { ! length = name.length (); ! value = attribute.getValue (); ! if (null == value) ! if (name.charAt (length - 1) == '/') ! { ! // already exists, remove if requested ! if (!emptyXmlTag) ! if (1 == length) ! attributes.removeElementAt (size - 1); ! else ! { ! // this shouldn't happen, but covers the case ! // where no whitespace separates the slash ! // from the previous attribute ! name = name.substring (0, length - 1); ! attribute = new Attribute (name); ! attributes.removeElementAt (size - 1); ! attributes.addElement (attribute); ! } ! } ! else ! { ! // ends with attribute, add whitespace + slash if requested ! if (emptyXmlTag) ! { ! attribute = new Attribute ((String)null, " ", (char)0); ! attributes.addElement (attribute); ! attribute = new Attribute ("/"); ! attributes.addElement (attribute); ! } ! } ! else ! { ! // some valued attribute, add whitespace + slash if requested ! if (emptyXmlTag) ! { ! attribute = new Attribute ((String)null, " ", (char)0); ! attributes.addElement (attribute); ! attribute = new Attribute ("/"); ! attributes.addElement (attribute); ! } ! } ! } ! else ! { ! // ends with whitespace, add if requested ! if (emptyXmlTag) ! { ! attribute = new Attribute ("/"); ! attributes.addElement (attribute); ! } ! } ! } ! else ! // nothing there, add if requested ! if (emptyXmlTag) ! { ! attribute = new Attribute ("/"); ! attributes.addElement (attribute); ! } } |