|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.swing.text.AbstractWriter javax.swing.text.html.MinimalHTMLWriter
MinimalHTMLWriter is a fallback writer used by the HTMLEditorKit to write out HTML for a document that is a not produced by the EditorKit. The format for the document is:
<html> <head> <style> <!-- list of named styles p.normal { font-family: SansSerif; margin-height: 0; font-size: 14 } --> </style> </head> <body> <p style=normal> Bold, italic, and underline attributes of the run are emitted as HTML tags. The remaining attributes are emitted as part of the style attribute of a <span> tag. The syntax is similar to inline styles. </p> </body> </html>
Field Summary | |
private static int |
BOLD
These static finals are used to tweak and query the fontMask about which of these tags need to be generated or terminated. |
private static CSS |
css
|
(package private) int |
endOffset
|
private AttributeSet |
fontAttributes
Stores the attributes of the previous run. |
private int |
fontMask
|
private static int |
ITALIC
|
(package private) int |
startOffset
|
private Hashtable |
styleNameMapping
Maps from style name as held by the Document, to the archived style name (style name written out). |
private static int |
UNDERLINE
|
Fields inherited from class javax.swing.text.AbstractWriter |
NEWLINE |
Constructor Summary | |
MinimalHTMLWriter(Writer w,
StyledDocument doc)
Creates a new MinimalHTMLWriter. |
|
MinimalHTMLWriter(Writer w,
StyledDocument doc,
int pos,
int len)
Creates a new MinimalHTMLWriter. |
Method Summary | |
private String |
addStyleName(String style)
Adds the style named style to the style mapping. |
protected void |
endFontTag()
This is no longer used, instead <span> will be written out. |
private void |
endSpanTag()
Writes out an end tag for the <span> tag. |
protected boolean |
inFontTag()
Returns true if we are currently in a <font> tag. |
protected boolean |
isText(Element elem)
Returns true if the element is a text element. |
private boolean |
isValidCharacter(char character)
|
private String |
mapStyleName(String style)
Returns the mapped style name corresponding to style . |
private void |
setFontMask(AttributeSet attr)
Tweaks the appropriate bits of fontMask to reflect whether the text is to be displayed in bold, italic, and/or with an underline. |
protected void |
startFontTag(String style)
This is no longer used, instead <span> will be written out. |
private void |
startSpanTag(String style)
Writes out a start tag for the <font> tag. |
protected void |
text(Element elem)
Writes out text. |
void |
write()
Generates HTML output from a StyledDocument. |
protected void |
writeAttributes(AttributeSet attr)
Writes out all the attributes for the following types: StyleConstants.ParagraphConstants, StyleConstants.CharacterConstants, StyleConstants.FontConstants, StyleConstants.ColorConstants. |
protected void |
writeBody()
Iterates over the elements in the document and processes elements based on whether they are branch elements or leaf elements. |
protected void |
writeComponent(Element elem)
Responsible for handling Component Elements; deliberately unimplemented. |
protected void |
writeContent(Element elem,
boolean needsIndenting)
Writes out the attribute set in an HTML-compliant manner. |
private void |
writeEndMask(int mask)
Writes out end tags for <u>, <i>, and <b> based on the mask settings. |
protected void |
writeEndParagraph()
Emits an end tag for a <p> tag. |
protected void |
writeEndTag(String endTag)
Writes out an end tag appropriately indented. |
protected void |
writeHeader()
Writes out the <head> and <style> tags, and then invokes writeStyles() to write out all the named styles as the content of the <style> tag. |
protected void |
writeHTMLTags(AttributeSet attr)
Generates bold <b>, italic <i>, and <u> tags for the text based on its attribute settings. |
protected void |
writeImage(Element elem)
Responsible for handling Icon Elements; deliberately unimplemented. |
protected void |
writeLeaf(Element elem)
Responsible for writing out other non-text leaf elements. |
protected void |
writeNonHTMLAttributes(AttributeSet attr)
Writes out the remaining character-level attributes (attributes other than bold, italic, and underline) in an HTML-compliant way. |
private void |
writeStartMask(int mask)
Writes out start tags <u>, <i>, and <b> based on the mask settings. |
protected void |
writeStartParagraph(Element elem)
Emits the start tag for a paragraph. |
protected void |
writeStartTag(String tag)
Writes out a start tag appropriately indented. |
protected void |
writeStyles()
Writes out all the named styles as the content of the <style> tag. |
Methods inherited from class javax.swing.text.AbstractWriter |
decrIndent, getCanWrapLines, getCurrentLineLength, getDocument, getElementIterator, getEndOffset, getIndentLevel, getIndentSpace, getLineLength, getLineSeparator, getStartOffset, getText, getWriter, incrIndent, indent, inRange, isLineEmpty, output, setCanWrapLines, setCurrentLineLength, setIndentSpace, setLineLength, setLineSeparator, write, write, write, writeLineSeparator |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static final int BOLD
private static final int ITALIC
private static final int UNDERLINE
private static final CSS css
private int fontMask
int startOffset
int endOffset
private AttributeSet fontAttributes
private Hashtable styleNameMapping
Constructor Detail |
public MinimalHTMLWriter(Writer w, StyledDocument doc)
w
- Writerdoc
- StyledDocumentpublic MinimalHTMLWriter(Writer w, StyledDocument doc, int pos, int len)
w
- Writerdoc
- StyledDocumentpos
- The location in the document to fetch the
content.len
- The amount to write out.Method Detail |
public void write() throws IOException, BadLocationException
write
in class AbstractWriter
IOException
- on any I/O error
BadLocationException
- if pos represents an invalid
location within the document.protected void writeAttributes(AttributeSet attr) throws IOException
writeAttributes
in class AbstractWriter
attr
- an AttributeSet.
IOException
- on any I/O errorprotected void text(Element elem) throws IOException, BadLocationException
text
in class AbstractWriter
elem
- an Element.
IOException
- on any I/O error
BadLocationException
- if pos represents an invalid
location within the document.protected void writeStartTag(String tag) throws IOException
IOException
- on any I/O errorprotected void writeEndTag(String endTag) throws IOException
IOException
- on any I/O errorprotected void writeHeader() throws IOException
IOException
- on any I/O errorprotected void writeStyles() throws IOException
IOException
- on any I/O errorprotected void writeBody() throws IOException, BadLocationException
IOException
- on any I/O error
BadLocationException
protected void writeEndParagraph() throws IOException
IOException
- on any I/O errorprotected void writeStartParagraph(Element elem) throws IOException
IOException
- on any I/O errorprotected void writeLeaf(Element elem) throws IOException
IOException
- on any I/O errorprotected void writeImage(Element elem) throws IOException
elem
- element of type StyleConstants.IconElementName
IOException
protected void writeComponent(Element elem) throws IOException
IOException
protected boolean isText(Element elem)
protected void writeContent(Element elem, boolean needsIndenting) throws IOException, BadLocationException
IOException
- on any I/O error
BadLocationException
- if pos represents an invalid
location within the document.protected void writeHTMLTags(AttributeSet attr) throws IOException
IOException
- on any I/O errorprivate void setFontMask(AttributeSet attr)
private void writeStartMask(int mask) throws IOException
IOException
- on any I/O errorprivate void writeEndMask(int mask) throws IOException
IOException
- on any I/O errorprotected void writeNonHTMLAttributes(AttributeSet attr) throws IOException
IOException
- on any I/O errorprotected boolean inFontTag()
protected void endFontTag() throws IOException
Writes out an end tag for the <font> tag.
IOException
- on any I/O errorprotected void startFontTag(String style) throws IOException
Writes out a start tag for the <font> tag. Because font tags cannot be nested, this method closes out any enclosing font tag before writing out a new start tag.
IOException
- on any I/O errorprivate void startSpanTag(String style) throws IOException
IOException
- on any I/O errorprivate void endSpanTag() throws IOException
IOException
- on any I/O errorprivate String addStyleName(String style)
style
to the style mapping. This
returns the name that should be used when outputting. CSS does not
allow the full Unicode set to be used as a style name.
private String mapStyleName(String style)
style
.
private boolean isValidCharacter(char character)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |