|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.wings.template.parser.SGMLTag
public class SGMLTag
Convenient class for parsing SGML tokens from a page.
This class is optimized for speed, not ease of use. (Though I'd contend its fairly easy to use anyway!).
Other than earlier versions of this class this one reads
its content from a Reader to avoid reading
the whole file into a String before parsing it.
The Reader is required to support the mark()
operation.
Tags are only read enough to find out what the tag name is;
If you want to read the full tag call parse(inputReader).
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, Reader input)
{
SGMLTag tag = new SGMLTag(input);
while (!tag.finished()) {
out.println ("tag: " + tag.toString());
tag = new SGMLTag (input);
}
}
| Field Summary | |
|---|---|
static char |
doubleQuote
|
static char |
singleQuote
|
| Constructor Summary | |
|---|---|
SGMLTag(Reader input)
Create new SGML tag reference, starting at current location of the Reader. |
|
SGMLTag(Reader input,
boolean parseIt)
Create new SGML tag reference, starting at current location of the Reader. |
|
| Method Summary | |
|---|---|
Iterator |
attributes(boolean upperCase)
Get list of attribute names. |
boolean |
finished()
Checked whether this tag indicates we're at the end of the list. |
String |
getAttribute(String key,
String defaultValue)
Deprecated. use attributes() and value() instead |
HashMap |
getAttributes()
Deprecated. use attributes() and value() instead |
String |
getName()
get the Name of this SGML tag, in uppercase format. |
int |
getOffset()
returns the number of chars skipped before the starting '<' |
boolean |
isNamed(String name)
Check name of tag. |
boolean |
isWellFormed()
Check for well-formedness of this tag. |
String |
nextToken(Reader input)
Read next token from string. |
String |
nextToken(Reader input,
boolean skipWhitespaces)
Read next token from string. |
void |
parse(Reader input)
|
protected void |
searchStart(Reader input)
Skip over any HTML-style comments, as denoted by matched <-- ... |
static int |
skipWhiteSpace(Reader r)
could be overwritten |
String |
toString()
Render this tag as a string. |
String |
value(String attributeName,
String defaultValue)
Get attribute value, or default if not set. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final char singleQuote
public static final char doubleQuote
| Constructor Detail |
|---|
public SGMLTag(Reader input,
boolean parseIt)
throws IOException
parseIt is false.
Tag may not be well-formed: if interested, call "parse(input)"
directly afterwards (without reading any characters
from the Reader) to get the attributes.
Note that this constructor skips over any HTML-style comments, as denoted by matched <-- ... --> pairs.
input - the Reader being parsed for SGML tagsparseIt - boolean which denotes if SGMLTag should be
parsed fully
IOExceptionattributes(boolean)
public SGMLTag(Reader input)
throws IOException
Note that this constructor skips over any HTML-style comments, as denoted by matched <-- ... --> pairs.
input - the Reader being parsed for SGML tags
IOExceptionattributes(boolean)| Method Detail |
|---|
public void parse(Reader input)
throws IOException
IOException
protected void searchStart(Reader input)
throws IOException
input - the reader being parsed for SGMLtags
IOExceptionpublic boolean finished()
public boolean isNamed(String name)
public boolean isWellFormed()
public int getOffset()
public String getName()
public Iterator attributes(boolean upperCase)
upperCase - true returns names in all uppercase (good for
case-insensitive applications), false returns attribute names
with same case as in original text
public String value(String attributeName,
String defaultValue)
attributeName - attribute for which to checkdefaultValue - value if attribute unset
public String nextToken(Reader input)
throws IOException
IOException
public String nextToken(Reader input,
boolean skipWhitespaces)
throws IOException
IOException
public static int skipWhiteSpace(Reader r)
throws IOException
IOException
public String getAttribute(String key,
String defaultValue)
key - name (uppercase) of attribute for which to checkdefaultValue - value if attribute unset
attributes(boolean),
value(java.lang.String, java.lang.String)public HashMap getAttributes()
attributes(boolean),
value(java.lang.String, java.lang.String)public String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||