All Packages Class Hierarchy This Package Previous Next Index
Class org.apache.jserv.SGMLTag
java.lang.Object
|
+----org.apache.jserv.SGMLTag
- public class SGMLTag
- extends Object
Convenient class for parsing SGML tokens from a page.
This class is optimized for speed, not ease of use.
(Though I'd content its fairly easy to use anyway!)
Tags are only read enough to find out what the tag name is;
the tag may be checked for completeness by calling isWellFormed().
This is done so that applications don't spend time processing
tags about which they care little.
Here's a sample piece of code which uses this class to read
all SGML tags on a page:
void showTags(PrintWriter out, String text)
{
for ( SGMLTag tag = new SGMLTag(text, 0);
!tag.finished();
tag = new SGMLTag(text, tag.end))
out.println("tag: " + tag.toString();
}
- Author:
- Tim Williams
-
end
- Place on page where tag ends, as far as this class
knows.
-
name
- Name of this SGML tag, in uppercase format.
-
start
- Location on "page" (passed string) where this tag begins
(inclusive).
-
SGMLTag(String, int)
- Create new SGML tag reference, starting at given location.
-
finished()
- Checked whether this tag indicates we're at end of the list.
-
getAttribute(String, String)
- Return value of attribute (parameter) setting in SGML tag.
-
getAttributes()
- Return tag attributes and values.
-
isDelimiter(char)
- Decide whether character is SGML delimiter or equals.
-
isNamed(String)
- Check name of tag.
-
isWellFormed()
- Check for well-formedness of this tag.
-
isWhiteSpace(char)
- Decide whether character is white space.
-
nextToken(String, int)
- Read next token from string.
-
skipWhiteSpace(String, int)
- Increment index into string to pass over any white space
characters.
-
toString()
- Render this tag as a string.
name
public String name
- Name of this SGML tag, in uppercase format.
For example, P for paragraph, B for bold, etc.
This value is set to null when whitespace or another
problem was encountered where the tag would be.
- See Also:
- isWellFormed
start
public int start
- Location on "page" (passed string) where this tag begins
(inclusive). (This is the opening greater-than sign.)
end
public int end
- Place on page where tag ends, as far as this class
knows.
If tag's attributes have not yet been check, or tag
has not been checked for validity, (via isWellFormed()).
This value is exclusive, e.g. the last character in the tag
is one before charcter before this index.
- See Also:
- isWellFormed
SGMLTag
public SGMLTag(String text,
int begin)
- Create new SGML tag reference, starting at given location.
At first, only the type of tag (first argument) is read.
Tag may not be well-formed: if interested, call "getAttributes"
and check for non-null return value to insure well-formed tag.
- Parameters:
- text - string being parsed for SGML tags
- begin - first character index to examine
- Returns:
- new SGML tag location, or null if no more tags present
- See Also:
- getAttributes
finished
public boolean finished()
- Checked whether this tag indicates we're at end of the list.
Note: The end tag is not usuable as an SGML tag.
- Returns:
- true if tag represents end of tags and isn't usuable
isNamed
public boolean isNamed(String name)
- Check name of tag.
(Comparision is case-insensitive.)
- Returns:
- true if passed tag matches this one.
isWellFormed
public boolean isWellFormed()
- Check for well-formedness of this tag.
Note that calling this method causes rest of tag to be parsed.
- Returns:
- true if tag is a well-formed SGML tag, false otherwise
getAttribute
public String getAttribute(String key,
String defaultValue)
- Return value of attribute (parameter) setting in SGML tag.
- Parameters:
- key - name (uppercase) of attribute for which to check
- default - value if attribute unset
- Returns:
- value of that attribute, or default if not defined
getAttributes
public Hashtable getAttributes()
- Return tag attributes and values.
- Returns:
- parameter key / value pairs
nextToken
public static String nextToken(String string,
int index)
- Read next token from string.
A token is a space-delimited word, a string in quotes
(returned with quotes), a delimiter such as a greater-than,
less-than, or equals sign.
- Parameters:
- string - string begin parsed
- index - location within string to start examining
- Returns:
- next token, or null if whitespace was encountered
skipWhiteSpace
public static int skipWhiteSpace(String string,
int index)
- Increment index into string to pass over any white space
characters.
- Parameters:
- string - string being examined
- index - current location within string
- Returns:
- index incremented to be on first non-whitespace char
isWhiteSpace
public static boolean isWhiteSpace(char c)
- Decide whether character is white space.
- Parameters:
- c - character in question
- Returns:
- true if character is a white space character
isDelimiter
public static boolean isDelimiter(char c)
- Decide whether character is SGML delimiter or equals.
- Parameters:
- c - character in question
- Returns:
- true if character is an SGML delimiter
toString
public String toString()
- Render this tag as a string.
- Returns:
- SGML tag as string, showing range and values
- Overrides:
- toString in class Object
All Packages Class Hierarchy This Package Previous Next Index