public class HTMLReader extends java.lang.Object implements SGMLParserListener, java.io.Serializable
HTMLReader class implements the reader that reads the
HTML document ('text/html') and renders it into the
HTMLText object or HTMLReaderTarget object.
For example:
URL url = null;
try {
url = new URL("http://ring.aist.go.jp/openlab/kyasu/");
}
catch (MalformedURLException e) { return; }
HTMLReader htmlReader = new HTMLReader(new HTMLStyle());
HTMLText htmlText = null;
try {
htmlText = htmlReader.readFrom(url);
}
catch (IOException e) { return; }
This class does not support the following tags:
TABLE, FORM, FRAME, APPLET,.etc.
| 修飾子とタイプ | クラスと説明 |
|---|---|
protected static interface |
HTMLReader.RenderingAction
The rendering action performed by the
SGMLEvent. |
| 修飾子とタイプ | フィールドと説明 |
|---|---|
protected java.net.URL |
baseURL
The base url defined by the
BASE tag. |
protected jp.kyasu.graphics.html.HTMLReaderContext |
context
The context of the html reader.
|
protected java.util.Stack |
contextStack
The stack for the context of the html reader.
|
protected java.net.URL |
documentURL
The document url.
|
protected HTMLStyle |
htmlStyle
The html style.
|
protected boolean |
interrupted
The flag indicating that the reader is interrupted.
|
protected static char |
LINE_BREAK
The constant for the line break character.
|
protected static java.lang.String |
LINE_BREAK_STRING
The constant for the line break string.
|
protected static char |
LINE_SEPARATOR
The constant for the line separator character.
|
protected static java.lang.String |
LINE_SEPARATOR_STRING
The constant for the line separator string.
|
protected java.awt.event.ActionListener |
linkActionListener
The action listener for the link (
A). |
protected java.awt.Color |
linkColor
The link color defined by the
BODY tag. |
protected BasicTSModifier |
linkModifier
The text style modifier for the
A tag. |
protected java.util.Hashtable |
renderingActions
The predefined rendering actions.
|
protected java.awt.Color |
textColor
The text color defined by the
BODY tag. |
| コンストラクタと説明 |
|---|
HTMLReader(HTMLStyle htmlStyle)
Constructs a html reader with the specified html style.
|
HTMLReader(HTMLStyle htmlStyle,
java.awt.event.ActionListener linkActionListener)
Constructs a html reader with the specified html style and action
listener for the link (
A). |
| 修飾子とタイプ | メソッドと説明 |
|---|---|
protected void |
append(java.lang.String str)
Appends the string to the text buffer of the current context.
|
protected void |
append(Text text)
Appends the text to the text buffer of the current context.
|
protected void |
append(TextAttachment ta)
Appends the text attachment to the text buffer of the current context.
|
protected void |
appendLineSep()
Appends the line separator to the text buffer of the current context
according to the current context.
|
protected void |
appendLineSep(boolean force)
Appends the line separator to the text buffer of the current context
according to the current context.
|
void |
cdataParsed(SGMLEvent e)
Invoked when a cdata has been parsed.
|
protected void |
dupParagraphStyleStack()
Pushes the current paragraph style onto the paragraph style stack.
|
protected void |
dupTextStyleStack()
Pushes the current text style onto the text style stack.
|
void |
endTagParsed(SGMLEvent e)
Invoked when a end tag has been parsed.
|
protected ParagraphStyle |
getCurrentParagraphStyle()
Returns the current paragraph style.
|
protected TextStyle |
getCurrentTextStyle()
Returns the current text style.
|
protected void |
initRenderingActions()
Initializes the rendering actions.
|
void |
interruptReading()
Interrupts the reading.
|
protected boolean |
isWhitespace(char c)
Checks if the specified character is white space of the HTML.
|
protected void |
modifyParagraphStyle(ParagraphStyleModifier modifier)
Modifies the current paragraph style.
|
protected void |
modifyTextStyle(TextStyleModifier modifier)
Modifies the current text style.
|
protected boolean |
needsWhitespace()
Checks if the white space is needed in the current context.
|
protected java.awt.Color |
parseColor(java.lang.String str)
Parses the specified string as a color value (#RRGGBB).
|
protected int |
parseHex(char c)
Parses the specified string as a hex value (0-F).
|
void |
parsingFinished(SGMLEvent e)
Invoked when a parsing has been finished.
|
protected jp.kyasu.graphics.html.HTMLReaderContext |
popContext()
Removes the context at the top of the context style stack, and sets
the current context to be the removed context.
|
protected void |
popParagraphStyleStack()
Removes the paragraph style at the top of the paragraph style stack,
and sets the current paragraph style to be the removed paragraph style
modified with the current context.
|
protected void |
popParagraphStyleStack(boolean withVSpace)
Removes the paragraph style at the top of the paragraph style stack,
and sets the current paragraph style to be the removed paragraph style
modified with the current context and the specified flag for the
vertical space.
|
protected void |
popTextStyleStack()
Removes the text style at the top of the text style stack, and sets
the current text style to be the removed text style.
|
protected void |
pushContext()
Pushes the current context onto the context style stack, and sets the
current context to be a new context.
|
protected void |
pushContext(boolean useCurrentTarget)
Pushes the current context onto the context style stack, and sets the
current context to be a new context.
|
protected void |
pushParagraphStyleStack(ParagraphStyle pStyle)
Pushes the current paragraph style onto the paragraph style stack,
and sets the current paragraph style to be the specified paragraph
style modified with the current context.
|
protected void |
pushParagraphStyleStack(ParagraphStyle pStyle,
java.lang.String align)
Pushes the current paragraph style onto the paragraph style stack,
and sets the current paragraph style to be the specified paragraph
style modified with the current context and the specified alignment.
|
protected void |
pushTextStyleStack(TextStyleModifier modifier)
Pushes the current text style onto the text style stack, and sets the
current text style to be the modified text style by the specified text
style modifier.
|
void |
read(java.net.URL url,
HTMLReaderTarget target)
Reads the HTML document ('
text/html') from the specified
url and renders it into the HTMLReaderTarget object. |
void |
read(java.net.URL documentURL,
java.io.Reader reader,
HTMLReaderTarget target)
Reads the HTML document ('
text/html') from the specified
reader with the url of the HTML document, and renders it into the
HTMLReaderTarget object. |
void |
read(java.net.URL url,
java.lang.String encodingName,
HTMLReaderTarget target)
Reads the HTML document ('
text/html') from the specified
url with the specified encoding, and renders it into the
HTMLReaderTarget object. |
HTMLText |
readFrom(java.net.URL url)
Reads the HTML document ('
text/html') from the specified
url and renders it into the HTMLText object. |
HTMLText |
readFrom(java.net.URL documentURL,
java.io.Reader reader)
Reads the HTML document ('
text/html') from the specified
reader with the url of the HTML document, and renders it into the
HTMLText object. |
HTMLText |
readFrom(java.net.URL url,
java.lang.String encodingName)
Reads the HTML document ('
text/html') from the specified
url with the specified encoding, and renders it into the
HTMLText object. |
protected void |
setParagraphStyle(ParagraphStyle paragraphStyle)
Sets the current paragraph style.
|
protected void |
setTextStyle(TextStyle textStyle)
Sets the current text style.
|
void |
startTagParsed(SGMLEvent e)
Invoked when a start tag has been parsed.
|
protected HTMLStyle htmlStyle
protected transient java.awt.event.ActionListener linkActionListener
A).protected java.net.URL documentURL
protected java.net.URL baseURL
BASE tag.protected java.awt.Color textColor
BODY tag.protected java.awt.Color linkColor
BODY tag.protected BasicTSModifier linkModifier
A tag.protected transient boolean interrupted
protected transient jp.kyasu.graphics.html.HTMLReaderContext context
protected transient java.util.Stack contextStack
protected java.util.Hashtable renderingActions
protected static final char LINE_SEPARATOR
protected static final char LINE_BREAK
protected static final java.lang.String LINE_SEPARATOR_STRING
protected static final java.lang.String LINE_BREAK_STRING
public HTMLReader(HTMLStyle htmlStyle)
htmlStyle - the html style for the rendering.public HTMLReader(HTMLStyle htmlStyle, java.awt.event.ActionListener linkActionListener)
A).htmlStyle - the html style for the rendering.linkActionListener - the action listener for the link
(A). If null,
the created HTMLText becomes
non clickable.public HTMLText readFrom(java.net.URL url) throws java.io.IOException
text/html') from the specified
url and renders it into the HTMLText object.url - the url.HTMLText object.java.io.IOException - If an I/O error occurs or the content
type of the url is not 'text/html'.public HTMLText readFrom(java.net.URL url, java.lang.String encodingName) throws java.io.IOException
text/html') from the specified
url with the specified encoding, and renders it into the
HTMLText object.url - the url.encodingName - the encoding name for reading.HTMLText object.java.io.IOException - If an I/O error occurs or the content
type of the url is not 'text/html'.public HTMLText readFrom(java.net.URL documentURL, java.io.Reader reader) throws java.io.IOException
text/html') from the specified
reader with the url of the HTML document, and renders it into the
HTMLText object.documentURL - the url of the HTML document.reader - the reader containing the HTML document.HTMLText object.java.io.IOException - If an I/O error occurs.public void read(java.net.URL url,
HTMLReaderTarget target)
throws java.io.IOException
text/html') from the specified
url and renders it into the HTMLReaderTarget object.url - the url.target - the HTMLReaderTarget into which to render.java.io.IOException - If an I/O error occurs or the content
type of the url is not 'text/html'.public void read(java.net.URL url,
java.lang.String encodingName,
HTMLReaderTarget target)
throws java.io.IOException
text/html') from the specified
url with the specified encoding, and renders it into the
HTMLReaderTarget object.url - the url.encodingName - the encoding name for reading.target - the HTMLReaderTarget into which
to render.java.io.IOException - If an I/O error occurs or the content
type of the url is not 'text/html'.public void read(java.net.URL documentURL,
java.io.Reader reader,
HTMLReaderTarget target)
throws java.io.IOException
text/html') from the specified
reader with the url of the HTML document, and renders it into the
HTMLReaderTarget object.documentURL - the url of the HTML document.reader - the reader containing the HTML document.target - the HTMLReaderTarget into which
to render.java.io.IOException - If an I/O error occurs.public void interruptReading()
public void startTagParsed(SGMLEvent e) throws java.io.IOException
startTagParsed インタフェース内 SGMLParserListenerjava.io.IOException - If an I/O error occurs.SGMLParserListener.startTagParsed(jp.kyasu.sgml.SGMLEvent)public void endTagParsed(SGMLEvent e) throws java.io.IOException
endTagParsed インタフェース内 SGMLParserListenerjava.io.IOException - If an I/O error occurs.SGMLParserListener.endTagParsed(jp.kyasu.sgml.SGMLEvent)public void cdataParsed(SGMLEvent e) throws java.io.IOException
cdataParsed インタフェース内 SGMLParserListenerjava.io.IOException - If an I/O error occurs.SGMLParserListener.cdataParsed(jp.kyasu.sgml.SGMLEvent)public void parsingFinished(SGMLEvent e) throws java.io.IOException
parsingFinished インタフェース内 SGMLParserListenerjava.io.IOException - If an I/O error occurs.SGMLParserListener.parsingFinished(jp.kyasu.sgml.SGMLEvent)protected void initRenderingActions()
protected final boolean isWhitespace(char c)
protected java.awt.Color parseColor(java.lang.String str)
protected int parseHex(char c)
protected void pushTextStyleStack(TextStyleModifier modifier)
protected void dupTextStyleStack()
protected void popTextStyleStack()
protected void pushParagraphStyleStack(ParagraphStyle pStyle) throws java.io.IOException
java.io.IOExceptionprotected void pushParagraphStyleStack(ParagraphStyle pStyle, java.lang.String align) throws java.io.IOException
java.io.IOExceptionprotected void dupParagraphStyleStack()
protected void popParagraphStyleStack()
throws java.io.IOException
java.io.IOExceptionprotected void popParagraphStyleStack(boolean withVSpace)
throws java.io.IOException
java.io.IOExceptionprotected void pushContext()
throws java.io.IOException
java.io.IOExceptionprotected void pushContext(boolean useCurrentTarget)
throws java.io.IOException
useCurrentTarget - if true, uses current target for the new context.java.io.IOExceptionprotected jp.kyasu.graphics.html.HTMLReaderContext popContext()
throws java.io.IOException
java.io.IOExceptionprotected boolean needsWhitespace()
protected void append(java.lang.String str)
throws java.io.IOException
java.io.IOExceptionprotected void append(TextAttachment ta) throws java.io.IOException
java.io.IOExceptionprotected void append(Text text) throws java.io.IOException
java.io.IOExceptionprotected void appendLineSep()
throws java.io.IOException
java.io.IOExceptionprotected void appendLineSep(boolean force)
throws java.io.IOException
force - if true, appends the line separator anyway.java.io.IOExceptionprotected TextStyle getCurrentTextStyle()
protected void setTextStyle(TextStyle textStyle)
protected void modifyTextStyle(TextStyleModifier modifier)
protected ParagraphStyle getCurrentParagraphStyle()
protected void setParagraphStyle(ParagraphStyle paragraphStyle) throws java.io.IOException
java.io.IOExceptionprotected void modifyParagraphStyle(ParagraphStyleModifier modifier) throws java.io.IOException
java.io.IOException