|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.xml.sax.helpers.DefaultHandler
eTextReader.OEB.HTMLTitleHandler
public class HTMLTitleHandler
This class is used to determine the title from a document whose media type is text/html. It receives events from an XML parser that implements the SAX interface
Field Summary | |
---|---|
private java.lang.StringBuffer |
currentHeading
the content of the current parsed heading |
private java.lang.String |
currentHeadingName
the name of the currently parsed heading element, or null if not in a heading |
(package private) java.util.Map |
headingCount
contains count of each heading element found in the current div element |
private java.util.Stack |
headingCountStack
a stack containing heading element counts for the previously encountered div elements |
(package private) java.util.Set |
headingElements
contains the elements we are interested in looking for |
private java.util.List |
headingList
a list of Heading objects corresponding to the headings
in the document |
private java.util.Stack |
idStack
a stack of id tags found in div items to keep track of the location of the headers |
private boolean |
inTitle
are we currently parsing a title element? |
private boolean |
parsed
have we parsed a document yet? |
private java.lang.StringBuffer |
title
holds the contents of the table of contents as it is being built |
private static java.lang.Integer |
zero
a constant used for initialization of heading element count entries |
Constructor Summary | |
---|---|
HTMLTitleHandler()
construct a new object that can parse HTML documents for their title elements |
Method Summary | |
---|---|
void |
characters(char[] ch,
int start,
int length)
if currently in the title element, appends the data in the array ch staring at start and running for length characters to the title |
void |
endElement(java.lang.String uri,
java.lang.String localName,
java.lang.String qName)
turns off recording of character content |
java.util.List |
getHeadings()
retrieve a list of headings for the most recently parsed object |
java.lang.String |
getTitle()
get the title of the most recently parsed document |
void |
parse(java.lang.String url)
load and parse the URL url. |
protected java.util.Map |
resetHeadingCounts()
creates a map with counts of zero for each of the elements in the headingElements set |
void |
startDocument()
called when a parsing of a new document is commenced; this implementation resets the parser state |
void |
startElement(java.lang.String uri,
java.lang.String localName,
java.lang.String qName,
org.xml.sax.Attributes attr)
checks whether it is a title element and records if it is |
void |
tryLoadingTitleFromText(java.lang.String url)
|
Methods inherited from class org.xml.sax.helpers.DefaultHandler |
---|
endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startPrefixMapping, unparsedEntityDecl, warning |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private boolean parsed
private boolean inTitle
private java.lang.String currentHeadingName
private java.lang.StringBuffer currentHeading
java.util.Set headingElements
java.util.Map headingCount
private java.util.Stack idStack
private java.util.Stack headingCountStack
private java.lang.StringBuffer title
private java.util.List headingList
Heading
objects corresponding to the headings
in the document
private static java.lang.Integer zero
Constructor Detail |
---|
public HTMLTitleHandler()
Method Detail |
---|
public void startDocument()
startDocument
in interface org.xml.sax.ContentHandler
startDocument
in class org.xml.sax.helpers.DefaultHandler
protected java.util.Map resetHeadingCounts()
public void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attr)
startElement
in interface org.xml.sax.ContentHandler
startElement
in class org.xml.sax.helpers.DefaultHandler
public void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)
endElement
in interface org.xml.sax.ContentHandler
endElement
in class org.xml.sax.helpers.DefaultHandler
public void characters(char[] ch, int start, int length)
characters
in interface org.xml.sax.ContentHandler
characters
in class org.xml.sax.helpers.DefaultHandler
public void parse(java.lang.String url) throws java.lang.Exception
TitleHandler
parse
in interface TitleHandler
url
- the URL of the document to be parsed
java.lang.Exception
- if an error occurs parsing the documentpublic void tryLoadingTitleFromText(java.lang.String url)
public java.lang.String getTitle() throws java.lang.IllegalStateException
TitleHandler
getTitle
in interface TitleHandler
java.lang.IllegalStateException
- if no document has been
parsed by this handlerpublic java.util.List getHeadings() throws java.lang.IllegalStateException
TitleHandler
getHeadings
in interface TitleHandler
Heading
objects for each of the
headings in the object
java.lang.IllegalStateException
- if no document has been
parsed by this handler
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |