[Htmlparser-cvs] htmlparser/src/org/htmlparser/tests/scannersTests CompositeTagScannerTest.java,1.51
Brought to you by:
derrickoswald
From: <der...@us...> - 2003-11-06 03:01:15
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/scannersTests In directory sc8-pr-cvs1:/tmp/cvs-serv6198/tests/scannersTests Modified Files: CompositeTagScannerTest.java Log Message: The tags now own their ids, enders and end tag enders. The isTagToBeEndedFor logic is now uses information from the tags, not the scanners. The kludge to get the scanner from the NodeFactory is now gone too, this also comes from the tag. Index: CompositeTagScannerTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/scannersTests/CompositeTagScannerTest.java,v retrieving revision 1.51 retrieving revision 1.52 diff -C2 -d -r1.51 -r1.52 *** CompositeTagScannerTest.java 1 Nov 2003 21:55:43 -0000 1.51 --- CompositeTagScannerTest.java 6 Nov 2003 03:00:40 -0000 1.52 *************** *** 559,562 **** --- 559,563 ---- public static class CustomScanner extends CompositeTagScanner { private static final String MATCH_NAME [] = { "CUSTOM" }; + private boolean selfChildrenAllowed; public CustomScanner() { this(true); *************** *** 564,568 **** public CustomScanner(boolean selfChildrenAllowed) { ! super("", selfChildrenAllowed ? new String[] {} : MATCH_NAME); } --- 565,570 ---- public CustomScanner(boolean selfChildrenAllowed) { ! // super("", selfChildrenAllowed ? new String[] {} : MATCH_NAME); ! this.selfChildrenAllowed = selfChildrenAllowed; } *************** *** 575,579 **** CustomTag ret; ! ret = new CustomTag (); ret.setPage (page); ret.setStartPosition (start); --- 577,581 ---- CustomTag ret; ! ret = new CustomTag (selfChildrenAllowed); ret.setPage (page); ret.setStartPosition (start); *************** *** 590,599 **** public static class AnotherScanner extends CompositeTagScanner { private static final String MATCH_NAME [] = { "ANOTHER" }; public AnotherScanner() { ! super("", new String[] {"CUSTOM"}); } public AnotherScanner(boolean acceptCustomTagsButDontAcceptCustomEndTags) { ! super("", new String[] {}, new String[] {"CUSTOM"}); } --- 592,604 ---- public static class AnotherScanner extends CompositeTagScanner { private static final String MATCH_NAME [] = { "ANOTHER" }; + private boolean acceptCustomTagsButDontAcceptCustomEndTags; public AnotherScanner() { ! // super("", new String[] {"CUSTOM"}); ! acceptCustomTagsButDontAcceptCustomEndTags = false; } public AnotherScanner(boolean acceptCustomTagsButDontAcceptCustomEndTags) { ! // super("", new String[] {}, new String[] {"CUSTOM"}); ! this.acceptCustomTagsButDontAcceptCustomEndTags = acceptCustomTagsButDontAcceptCustomEndTags; } *************** *** 606,610 **** AnotherTag ret; ! ret = new AnotherTag (); ret.setPage (page); ret.setStartPosition (start); --- 611,615 ---- AnotherTag ret; ! ret = new AnotherTag (acceptCustomTagsButDontAcceptCustomEndTags); ret.setPage (page); ret.setStartPosition (start); *************** *** 625,632 **** --- 630,729 ---- public static class CustomTag extends CompositeTag { + /** + * The set of names handled by this tag. + */ + private static final String[] mIds = new String[] {"CUSTOM"}; + + protected String[] mEnders; + + public CustomTag () + { + this (true); + } + + public CustomTag (boolean selfChildrenAllowed) + { + if (selfChildrenAllowed) + mEnders = new String[0]; + else + mEnders = mIds; + } + + /** + * Return the set of names handled by this tag. + * @return The names to be matched that create tags of this type. + */ + public String[] getIds () + { + return (mIds); + } + + /** + * Return the set of tag names that cause this tag to finish. + * @return The names of following tags that stop further scanning. + */ + public String[] getEnders () + { + return (mEnders); + } } public static class AnotherTag extends CompositeTag { + /** + * The set of names handled by this tag. + */ + private static final String[] mIds = new String[] {"ANOTHER"}; + + /** + * The set of tag names that indicate the end of this tag. + */ + private final String[] mEnders; + + /** + * The set of end tag names that indicate the end of this tag. + */ + private final String[] mEndTagEnders; + + public AnotherTag (boolean acceptCustomTagsButDontAcceptCustomEndTags) + { + if (acceptCustomTagsButDontAcceptCustomEndTags) + { + mEnders = new String[0]; + mEndTagEnders = new String[] {"CUSTOM"}; + } + else + { + mEnders = new String[] {"CUSTOM"}; + mEndTagEnders = new String[] {"CUSTOM"}; + } + } + + /** + * Return the set of names handled by this tag. + * @return The names to be matched that create tags of this type. + */ + public String[] getIds () + { + return (mIds); + } + + /** + * Return the set of tag names that cause this tag to finish. + * @return The names of following tags that stop further scanning. + */ + public String[] getEnders () + { + return (mEnders); + } + + /** + * Return the set of end tag names that cause this tag to finish. + * @return The names of following end tags that stop further scanning. + */ + public String[] getEndTagEnders () + { + return (mEndTagEnders); + } } } |