[Htmlparser-cvs] htmlparser/src/org/htmlparser/tags BaseHrefTag.java,1.29,1.30 CompositeTag.java,1.6
Brought to you by:
derrickoswald
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tags In directory sc8-pr-cvs1:/tmp/cvs-serv2656/tags Modified Files: BaseHrefTag.java CompositeTag.java FormTag.java ImageTag.java LinkTag.java Tag.java Log Message: Create nodes by cloning from a list of prototypes in the Parser (NodeFactory). So now, the startTag() is the CompositeTag, and the CompositeTagScanner just adds children. This is an intermediate code drop on the way to integrating the scanners with the tags; the scanners no longer create the tags (but they still create the prototypical ones). Index: BaseHrefTag.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tags/BaseHrefTag.java,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** BaseHrefTag.java 29 Oct 2003 03:31:17 -0000 1.29 --- BaseHrefTag.java 1 Nov 2003 21:55:43 -0000 1.30 *************** *** 31,34 **** --- 31,35 ---- import java.util.Vector; + import org.htmlparser.lexer.Page; import org.htmlparser.util.LinkProcessor; *************** *** 73,85 **** /** ! * Override this because we need a trigger to set the base HREF on the page. ! * NOTE: setting of the attributes is the last thing done on the tag ! * after creation. ! * @param attribs The new BASE tag attributes. */ ! public void setAttributesEx (Vector attribs) { ! super.setAttributesEx (attribs); ! getPage ().getLinkProcessor ().setBaseUrl (getBaseUrl ()); } } --- 74,89 ---- /** ! * Perform the meaning of this tag. ! * This sets the base URL to use for the rest of the page. */ ! public void doSemanticAction () { ! Page page; ! ! page = getPage (); ! if (null != page) ! { ! page.getLinkProcessor ().setBaseUrl (getBaseUrl ()); ! } } } Index: CompositeTag.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tags/CompositeTag.java,v retrieving revision 1.61 retrieving revision 1.62 diff -C2 -d -r1.61 -r1.62 *** CompositeTag.java 26 Oct 2003 19:46:23 -0000 1.61 --- CompositeTag.java 1 Nov 2003 21:55:43 -0000 1.62 *************** *** 45,50 **** */ public abstract class CompositeTag extends Tag { ! protected TagNode startTag; ! protected TagNode endTag; public CompositeTag () --- 45,49 ---- */ public abstract class CompositeTag extends Tag { ! protected TagNode mEndTag; public CompositeTag () *************** *** 58,62 **** public SimpleNodeIterator children () { ! return (getChildren ().elements ()); } --- 57,68 ---- public SimpleNodeIterator children () { ! SimpleNodeIterator ret; ! ! if (null != getChildren ()) ! ret = getChildren ().elements (); ! else ! ret = (new NodeList ()).elements (); ! ! return (ret); } *************** *** 107,114 **** } - public void putStartTagInto(StringBuffer sb) { - sb.append(startTag.toHtml()); - } - protected void putChildrenInto(StringBuffer sb) { --- 113,116 ---- *************** *** 127,139 **** // eliminate virtual tags // if (!(endTag.getStartPosition () == endTag.getEndPosition ())) ! sb.append(endTag.toHtml()); } public String toHtml() { StringBuffer sb = new StringBuffer(); ! putStartTagInto(sb); ! if (!startTag.isEmptyXmlTag()) { putChildrenInto(sb); ! putEndTagInto(sb); } return sb.toString(); --- 129,143 ---- // eliminate virtual tags // if (!(endTag.getStartPosition () == endTag.getEndPosition ())) ! sb.append(getEndTag ().toHtml()); } public String toHtml() { StringBuffer sb = new StringBuffer(); ! sb.append (super.toHtml ()); ! if (!isEmptyXmlTag()) ! { putChildrenInto(sb); ! if (null != getEndTag ()) // this test if for link tags that refuse to scan because there's no HREF attribute ! putEndTagInto(sb); } return sb.toString(); *************** *** 324,335 **** if (visitor.shouldRecurseChildren ()) { ! startTag.accept (visitor); ! children = children (); ! while (children.hasMoreNodes ()) { ! child = (Node)children.nextNode (); ! child.accept (visitor); } ! endTag.accept (visitor); } if (visitor.shouldRecurseSelf ()) --- 328,342 ---- if (visitor.shouldRecurseChildren ()) { ! if (null != getChildren ()) { ! children = children (); ! while (children.hasMoreNodes ()) ! { ! child = (Node)children.nextNode (); ! child.accept (visitor); ! } } ! if (null != getEndTag ()) ! getEndTag ().accept (visitor); } if (visitor.shouldRecurseSelf ()) *************** *** 341,362 **** } public TagNode getStartTag() { ! return startTag; } public void setStartTag (TagNode start) { ! startTag = start; } public TagNode getEndTag() { ! return endTag; } public void setEndTag(TagNode end) { ! endTag = end; } --- 348,376 ---- } + /** + * @deprecated The tag *is* ths start tag. + */ public TagNode getStartTag() { ! return (this); } + /** + * @deprecated The tag *is* ths start tag. + */ public void setStartTag (TagNode start) { ! if (null != start) ! throw new IllegalStateException ("the tag *is* ths start tag"); } public TagNode getEndTag() { ! return (mEndTag); } public void setEndTag(TagNode end) { ! mEndTag = end; } *************** *** 390,395 **** return stringNode; } - - - } --- 404,406 ---- Index: FormTag.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tags/FormTag.java,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** FormTag.java 1 Nov 2003 01:36:57 -0000 1.38 --- FormTag.java 1 Nov 2003 21:55:43 -0000 1.39 *************** *** 42,49 **** --- 42,55 ---- public static final String POST="POST"; public static final String GET="GET"; + + /** + * This is the derived form location, based on action. + */ + protected String mFormLocation; public FormTag () { setTagName ("FORM"); + mFormLocation = null; } *************** *** 72,76 **** public String getFormLocation() { ! return (getAttribute("ACTION")); } --- 78,86 ---- public String getFormLocation() { ! if (null == mFormLocation) ! // ... is it true that without an ACTION the default is to send it back to the same page? ! mFormLocation = extractFormLocn (getPage ().getUrl ()); ! ! return (mFormLocation); } *************** *** 82,85 **** --- 92,96 ---- public void setFormLocation(String url) { + mFormLocation = url; setAttribute ("ACTION", url); } *************** *** 179,200 **** else return (getPage ().getLinkProcessor ().extract (formURL, url)); - } - - /** - * Override this because we need a trigger to set the ACTION attribute. - * NOTE: setting of the children is the last thing done on the tag - * after creation. - * @param children The new list of children this node contains. - */ - public void setChildren (NodeList children) - { - String url; - - super.setChildren (children); - - // ... is it true that without an ACTION the default is to send it back to the same page? - url = extractFormLocn(getPage ().getUrl ()); - if (null != url && 0 < url.length()) - setAttribute ("ACTION",url); } } --- 190,193 ---- Index: ImageTag.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tags/ImageTag.java,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** ImageTag.java 1 Nov 2003 01:36:57 -0000 1.33 --- ImageTag.java 1 Nov 2003 21:55:43 -0000 1.34 *************** *** 167,171 **** { if (null == imageURL) ! imageURL = extractImageLocn (); return (imageURL); } --- 167,172 ---- { if (null == imageURL) ! if (null != getPage ()) ! imageURL = getPage ().getLinkProcessor ().extract (extractImageLocn (), getPage().getUrl ()); return (imageURL); } *************** *** 193,212 **** visitor.visitImageTag (this); super.accept (visitor); - } - - /** - * Override this because we need a trigger to set the image URL. - * Need to update the imageURL string in the this tag, - * but not the SRC attribute so toHtml() outputs the right thing. - * NOTE: setting of the attributes is the last thing done on the tag - * after creation. - * @param attribs The new IMG tag attributes. - */ - public void setAttributesEx (Vector attribs) - { - String src; - - super.setAttributesEx (attribs); - imageURL = getPage ().getLinkProcessor ().extract (getImageURL (), getPage().getUrl ()); } } --- 194,197 ---- Index: LinkTag.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tags/LinkTag.java,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** LinkTag.java 1 Nov 2003 01:36:57 -0000 1.40 --- LinkTag.java 1 Nov 2003 21:55:43 -0000 1.41 *************** *** 139,152 **** public String getLinkText() { ! return (getChildren().toString()); ! } ! /** ! * Return the text contained in this linkinode ! * Kaarle Kaila 23.10.2001 ! */ ! public String getText() ! { ! return toHtml(); } --- 139,150 ---- public String getLinkText() { ! String ret; ! if (null != getChildren()) ! ret = getChildren().toString(); ! else ! ret = ""; ! ! return (ret); } *************** *** 248,252 **** else sb.append(getAccessKey ()+"\n"); ! if (children()!=null) { sb.append(" "+"LinkData\n"); --- 246,250 ---- else sb.append(getAccessKey ()+"\n"); ! if (null != getChildren ()) { sb.append(" "+"LinkData\n"); Index: Tag.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tags/Tag.java,v retrieving revision 1.54 retrieving revision 1.55 diff -C2 -d -r1.54 -r1.55 *** Tag.java 26 Oct 2003 19:46:24 -0000 1.54 --- Tag.java 1 Nov 2003 21:55:43 -0000 1.55 *************** *** 29,32 **** --- 29,33 ---- package org.htmlparser.tags; + import java.lang.CloneNotSupportedException; import java.util.Enumeration; import java.util.HashSet; *************** *** 50,54 **** * lexer which has nodes). */ ! public class Tag extends TagNode { private TagScanner mScanner; --- 51,55 ---- * lexer which has nodes). */ ! public class Tag extends TagNode implements Cloneable { private TagScanner mScanner; *************** *** 70,73 **** --- 71,79 ---- } + public Object clone() throws CloneNotSupportedException + { + return (super.clone ()); + } + /** * Return the scanner associated with this tag. *************** *** 121,134 **** else ((NodeVisitor)visitor).visitTag (this); - } - - public int getStartingLineNumber () - { - return (getPage ().row (getStartPosition ())); - } - - public int getEndingLineNumber () - { - return (getPage ().row (getEndPosition ())); } } --- 127,130 ---- |