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

Variable Index

 o end
Place on page where tag ends, as far as this class knows.
 o name
Name of this SGML tag, in uppercase format.
 o start
Location on "page" (passed string) where this tag begins (inclusive).

Constructor Index

 o SGMLTag(String, int)
Create new SGML tag reference, starting at given location.

Method Index

 o finished()
Checked whether this tag indicates we're at end of the list.
 o getAttribute(String, String)
Return value of attribute (parameter) setting in SGML tag.
 o getAttributes()
Return tag attributes and values.
 o isDelimiter(char)
Decide whether character is SGML delimiter or equals.
 o isNamed(String)
Check name of tag.
 o isWellFormed()
Check for well-formedness of this tag.
 o isWhiteSpace(char)
Decide whether character is white space.
 o nextToken(String, int)
Read next token from string.
 o skipWhiteSpace(String, int)
Increment index into string to pass over any white space characters.
 o toString()
Render this tag as a string.

Variables

 o 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
 o start
 public int start
Location on "page" (passed string) where this tag begins (inclusive). (This is the opening greater-than sign.)

 o 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

Constructors

 o 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

Methods

 o 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
 o isNamed
 public boolean isNamed(String name)
Check name of tag. (Comparision is case-insensitive.)

Returns:
true if passed tag matches this one.
 o 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
 o 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
 o getAttributes
 public Hashtable getAttributes()
Return tag attributes and values.

Returns:
parameter key / value pairs
 o 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
 o 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
 o 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
 o 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
 o 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