Class TagParser

java.lang.Object
   |
   +----TagParser

public class TagParser
extends Object
This class takes some input as stream or string and returns defined text parts defined by user defined patterns.

Usage:

     String[][] patterns={{"t","t"},{"hier "," mit"}};
     TagParser tp=new TagParser(patterns, true);
     tp.setSource("Ein Testtext. und hier noch mit zweitem pattern.");
     while (tp.hasMoreTags()) System.out.println(tp.nextTag());
This example should return:
 Test
 text
 hier noch mit
 tem pat

Another example analyzing a html file:

     String[][] patterns={{"",""}};
     TagParser tp=new TagParser(patterns,false);
     tp.setSource("Hello User!");
     tp.hasMoreTags(); System.out.println(tp.nextTag());
will return "<b>User</b>".

Quellcode mit GPL-Lizenz.


Variable Index

 o ignore_case
if true, at comparing the patterns case must be ignored

Constructor Index

 o TagParser()
Creates a new TagParser with no patterns.
 o TagParser(String[][])
Creates a new TagParser with the given tag patterns and no case ignore.
 o TagParser(String[][], boolean)
Creates a new TagParser with the given tag patterns and no case ignore.

Method Index

 o compare(char, char)
compares the two characters
 o extractTagAttribute(String, String)
Extracts the specified attribute from the given tag text.
 o getInputPosition()
Gets the number of characters read till now.
 o getTag()
 o getTagIndex()
Gets the index of the founded tag returned by nexttag().
 o hasMoreTags()
Checks if there are more tags contained in input.
 o nextTag()
Gets the tag found by the last call of hasMoreTags().
 o setPattern(String[][])
sets the tag patterns to the given pairs, without ignoring cases.
 o setPattern(String[][], boolean)
sets the tag patterns to the given pairs.
 o setSource(InputStream)
Sets the data source to be used for input.
 o setSource(Reader)
Sets the data source to be used for input.
 o setSource(String)
Sets the data source to be used for input.

Variables

 o ignore_case
 protected boolean ignore_case
if true, at comparing the patterns case must be ignored

Constructors

 o TagParser
 public TagParser()
Creates a new TagParser with no patterns.

See Also:
setPattern
 o TagParser
 public TagParser(String pts[][])
Creates a new TagParser with the given tag patterns and no case ignore.

Parameters:
pts - an array of all tags, each given as array of length 2 with start and end pattern
See Also:
setPattern
 o TagParser
 public TagParser(String pts[][],
                  boolean ignore_case)
Creates a new TagParser with the given tag patterns and no case ignore.

Parameters:
pts - an array of all tags, each given as array of length 2 with start and end pattern
ignore_case - if true, cases will be ignored at pattern matching
See Also:
setPattern

Methods

 o setSource
 public void setSource(InputStream is)
Sets the data source to be used for input.

Parameters:
is - an InputStream to read characters from using a InputStreamReader
 o setSource
 public void setSource(String s)
Sets the data source to be used for input.

Parameters:
s - a String to read characters from using a StringReader
 o setSource
 public final void setSource(Reader r)
Sets the data source to be used for input.

 o setPattern
 public final void setPattern(String pts[][])
sets the tag patterns to the given pairs, without ignoring cases.

Parameters:
pts - an array of all tags, each given as array of length 2 with start and end pattern
 o setPattern
 public final void setPattern(String pts[][],
                              boolean ignore_case)
sets the tag patterns to the given pairs.

Parameters:
pts - an array of all tags, each given as array of length 2 with start and end pattern
ignore_case - if true, cases will be ignored at pattern matching
 o compare
 protected boolean compare(char a,
                           char b)
compares the two characters

 o hasMoreTags
 public final boolean hasMoreTags() throws IOException
Checks if there are more tags contained in input. Only complete tags delimited by start and pattern as defined are recognized. Note: This methods performs the input evaluation!

Returns:
true if there are more tags
 o nextTag
 public final String nextTag()
Gets the tag found by the last call of hasMoreTags(). If you use hasMoreTags() properly, you should never get null.

Returns:
the tag delimited by start and end pattern, or null if no tag present
 o getTag
 public final String getTag()
 o getInputPosition
 public final long getInputPosition()
Gets the number of characters read till now.

 o getTagIndex
 public final int getTagIndex()
Gets the index of the founded tag returned by nexttag().

 o extractTagAttribute
 public static String extractTagAttribute(String tag,
                                          String attribute)
Extracts the specified attribute from the given tag text. Note: This is a supporting function that could be useful, but not necessary for fcuntion of TagParser.