Package com.inet.html
Class InetHtmlWriter
java.lang.Object
javax.swing.text.AbstractWriter
com.inet.html.InetHtmlWriter
Write the InetHtmlDocument as text/plain. Some protected method have the same signature
like the Sun javax.swing.text.html.HTMLWriter to make it easer to port to this implementation.
As a 'special feature' this writer can replace image source links, which is useful for e-mails for instance.
As a 'special feature' this writer can replace image source links, which is useful for e-mails for instance.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceThe attribute filter can modify attribute value on the fly while the document is written. -
Field Summary
Fields inherited from class javax.swing.text.AbstractWriter
NEWLINE -
Constructor Summary
ConstructorsConstructorDescriptionInetHtmlWriter(Writer out, Document doc, int pos, int len) Create a new InetHtmlWriterInetHtmlWriter(Writer out, Element element) Create a new InetHtmlWriter, which writes the contents of a certain element. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidWrite a single Element that have never childs like <BR>.protected voidWrite the start tag of an element that can span multiple elements.intReturns the map with the Tags we do not want writtenprotected booleanisBlockTag(Element elem) Test if the current Element is a block element.protected voidoutput(char[] chars, int start, int length) voidRegisters the filter to be used when writing CSS and HTML attributesvoidregisterImageSRCreplace(Map<String, String> imageReplaceMap) Registers an image SRC replace map at this writer.voidregisterLinkHREFreplace(Map<String, String> hrefReplaceMap) Registers an <a>-href replace map at this writer.voidsetAbsolutePathMode(boolean absolutePathMode) Advised the writer to convert all relative pathes in the document to absolute pathes.voidsetAllowStyleSpan(boolean allowStyleSpan) Allows or prohibits the style SPAN on partial or element based write operation.voidsetEmptyBlockFiller(String emptyBlockFiller) Sets the string to be written to an empty block (if activated by the document configuration).voidsetInlineMode(boolean inlineMode) Sets the writer to inline-CSS mode.static voidsetSorted(boolean sorted) Enable or disable the attribute sorting of the writer.voidsetStyleContainer(HTML.Tag styleContainer) Defines the style container element to be used when writing with inline mode.voidsetTagWritingOptions(Map<HTML.Tag, Boolean> tagWritingOptionsMap) Set the map with the Tags we do not want written (if null everything will be written)voidsetTrustedImagePath(boolean trustedImagePath) Sets whether the image paths in the image map ofregisterImageSRCreplace(Map)already encoded; So iftruethe paths will not be URL path encoded.voidsetWriteIfNoTextContent(boolean writeIfNoTextContent) Defines whether or not to write the full DOM in case there is no actual text content.voidsetWriteSelectedElementOnly(boolean writeSelectedElementOnly) Defines whether or not to write only the selected element or a full HTML document with the selected element as content.
NOTE: Although this flag can be used in a any case, it's most useful when combined with inline mode and style container element to write a independent and complete HTML snippet.protected booleanWrite the start tag of an element that can span multiple elements.voidwrite()protected voidwriteAttributes(AttributeSet attrs) Write the Attributes inside of a tag.Methods inherited from class javax.swing.text.AbstractWriter
decrIndent, getCanWrapLines, getCurrentLineLength, getDocument, getElementIterator, getIndentLevel, getIndentSpace, getLineLength, getLineSeparator, getStartOffset, getText, getWriter, incrIndent, indent, inRange, isLineEmpty, setCanWrapLines, setCurrentLineLength, setIndentSpace, setLineLength, setLineSeparator, text, write, write, write, writeLineSeparator
-
Constructor Details
-
InetHtmlWriter
Create a new InetHtmlWriter, which writes the contents of a certain element.- Parameters:
out- any Writerelement- the element to be written, must not be null- Since:
- 1.05
-
InetHtmlWriter
Create a new InetHtmlWriter- Parameters:
out- any Writerdoc- a HTML4Documentpos- the start position of the document that should be written.len- the length of data that should be written- Since:
- 1.05
-
-
Method Details
-
write
- Specified by:
writein classAbstractWriter- Throws:
BadLocationExceptionIOException
-
emptyTag
Write a single Element that have never childs like <BR>. This method is API compatible with javax.swing.text.html.HTMLWriter.- Parameters:
elem- the Element that should be write- Throws:
BadLocationException- should not occurIOException- on any I/O error with the Writer- Since:
- 1.05
-
isBlockTag
Test if the current Element is a block element.- Parameters:
elem- the element to check- Returns:
- true if it is a block.
- Since:
- 1.05
-
startTag
Write the start tag of an element that can span multiple elements.- Parameters:
elem- the Element that should be write- Returns:
- true, if the start-tag was HEAD and writeHead was called, false otherwise
- Throws:
IOException- on any I/O error with the Writer- Since:
- 1.05
-
endTag
Write the start tag of an element that can span multiple elements. This method is API compatible with javax.swing.text.html.HTMLWriter.- Parameters:
elem- the Element that should be write- Throws:
IOException- on any I/O error with the Writer- Since:
- 1.05
-
writeAttributes
Write the Attributes inside of a tag.- Overrides:
writeAttributesin classAbstractWriter- Parameters:
attrs- the attributes of the Element- Throws:
IOException- on any I/O error with the Writer- Since:
- 1.05
-
output
- Overrides:
outputin classAbstractWriter- Throws:
IOException
-
registerImageSRCreplace
Registers an image SRC replace map at this writer. If the SRC-location of an image element is registered in this map it will be replaced before it is written. Useful to redirect image locations for embedded images.- Parameters:
imageReplaceMap- Key=original location, Value=new location- Since:
- 1.05
-
registerLinkHREFreplace
Registers an <a>-href replace map at this writer. If the HREF-location of an element is registered in this map it will be replaced before it is written. Useful to redirect links to local documents.- Parameters:
hrefReplaceMap- Key=original location, Value=new location- Since:
- 1.12
-
registerAttributeFilter
Registers the filter to be used when writing CSS and HTML attributes- Parameters:
filter- the filter to be used,nullfor none- Since:
- 1.12
-
getEndOffset
public int getEndOffset()- Overrides:
getEndOffsetin classAbstractWriter
-
setSorted
public static void setSorted(boolean sorted) Enable or disable the attribute sorting of the writer. Since writers are create internally on demand this option is static for allInetHtmlWriteron the current VM! Note: This will- Parameters:
sorted- true, if the attributes should be sorted- Since:
- 1.05
-
setInlineMode
public void setInlineMode(boolean inlineMode) Sets the writer to inline-CSS mode. In this mode all linked stylesheets and the script tag will be dropped. Instead the effective styles will be written inline into each element. That way the writer generates an monolithic but style-reference free html output.- Parameters:
inlineMode- true to activate the inline mode, false to write a normal html content- Since:
- 1.05
-
setAbsolutePathMode
public void setAbsolutePathMode(boolean absolutePathMode) Advised the writer to convert all relative pathes in the document to absolute pathes. This will allow external HTML renderers to resolve the URL as well. But use this mode wiht caution: if the URLs point to a local file or localhost, the output will not be portable anymore.
Requires a base-URL to be set for the document to work!- Parameters:
absolutePathMode- iftrue, all relative URLs will be written as absulte ones- Since:
- 1.05
-
setAllowStyleSpan
public void setAllowStyleSpan(boolean allowStyleSpan) Allows or prohibits the style SPAN on partial or element based write operation. Default is true.
By default: in case of a partial copy the style inheritance and CSS selector hierarchy is broken. To get the correct styles in this case, a SPAN is added as root of the copied elements to replace the missing parent and to allow a correct inheritance of styles.- Parameters:
allowStyleSpan- true to allow the root SPAN, false to get the row element structure- Since:
- 1.05
-
setWriteSelectedElementOnly
public void setWriteSelectedElementOnly(boolean writeSelectedElementOnly) Defines whether or not to write only the selected element or a full HTML document with the selected element as content.
NOTE: Although this flag can be used in a any case, it's most useful when combined with inline mode and style container element to write a independent and complete HTML snippet.- Parameters:
writeSelectedElementOnly- iftrueonly the selected element will be written, no implicit implicit HTML, HEAD or BODY element will be created unless it's the element to write. Iffalsethe HTML, HEAD and BODY elements will always be written(or created) to create a valid HTML document. Default isfalse- Since:
- 1.13
-
setWriteIfNoTextContent
public void setWriteIfNoTextContent(boolean writeIfNoTextContent) Defines whether or not to write the full DOM in case there is no actual text content. E.g. the document may have an empty DIV element which is styles to display a background image. This would have a rendering appearance but since theInetHtmlDocument.getLength()would yield 0, the writer would write nothing. This flag defines whether or not do apply this optimization.
NOTE: A completely empty BODY element will result in nothing to be written in any case
The default isfalse.- Parameters:
writeIfNoTextContent-trueto write DOM with no text content,falseto write nothing ifInetHtmlDocument.getLength()is 0.- Since:
- 1.13
-
setStyleContainer
Defines the style container element to be used when writing with inline mode. Default isHTML.Tag.SPAN
By default: in case of a partial copy the style inheritance and CSS selector hierarchy is broken. To get the correct styles in this case, a container element is added as root of the copied elements to replace the missing parent and to allow a correct inheritance of styles.
NOTE: There is a major difference between inline an block level elements for the container! While it has no effect on the inheritance of styles, it will affect the rendering. Since the line-height is taken from the latest block level element, an inline element as style container will not set the correct line height for anonymous elements. So if inline is not strictly required, use aHTML.Tag.DIVhere.- Parameters:
styleContainer- the container element to be used,nullto skip the artificial container element- Since:
- 1.12
-
getTagWritingOptions
Returns the map with the Tags we do not want written- Returns:
- the map with the Tags we do not want written
- Since:
- 1.09
-
setTagWritingOptions
Set the map with the Tags we do not want written (if null everything will be written)- Parameters:
tagWritingOptionsMap- he map with the Tags we do not want written- Since:
- 1.09
-
setTrustedImagePath
public void setTrustedImagePath(boolean trustedImagePath) Sets whether the image paths in the image map ofregisterImageSRCreplace(Map)already encoded; So iftruethe paths will not be URL path encoded. This may lead to a corrupted file in case the paths are not properly encoded. When in doubt, set tofalseor don't use this method.- Parameters:
trustedImagePath-trueif paths are already encoded, hencefalse
-
setEmptyBlockFiller
Sets the string to be written to an empty block (if activated by the document configuration). By default the fill string is ' ' but some HTML editors use '
' instead.- Parameters:
emptyBlockFiller- the string to write to an empty block,nullwill be interpreted as an empty string- Since:
- 1.12
-