/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* 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:
* <pre>
* <html>
* <head>
* <style>
* <!-- list of named styles
* p.normal {
* font-family: SansSerif;
* margin-height: 0;
* font-size: 14
* }
* -->
* </style>
* </head>
* <body>
* <p style=normal>
* <b>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.</b>
* </p>
* </body>
* </html>
* </pre>
*
* @author Sunita Mani
*/
/**
* These static finals are used to
* tweak and query the fontMask about which
* of these tags need to be generated or
* terminated.
*/
// Used to map StyleConstants to CSS.
/**
* Stores the attributes of the previous run.
* Used to compare with the current run's
* attributeset. If identical, then a
* <span> tag is not emitted.
*/
/**
* Maps from style name as held by the Document, to the archived
* style name (style name written out). These may differ.
*/
/**
* Creates a new MinimalHTMLWriter.
*
* @param w Writer
* @param doc StyledDocument
*
*/
super(w, doc);
}
/**
* Creates a new MinimalHTMLWriter.
*
* @param w Writer
* @param doc StyledDocument
* @param pos The location in the document to fetch the
* content.
* @param len The amount to write out.
*
*/
}
/**
* Generates HTML output
* from a StyledDocument.
*
* @exception IOException on any I/O error
* @exception BadLocationException if pos represents an invalid
* location within the document.
*
*/
writeStartTag("<html>");
writeHeader();
writeBody();
writeEndTag("</html>");
}
/**
* Writes out all the attributes for the
* following types:
* StyleConstants.ParagraphConstants,
* StyleConstants.CharacterConstants,
* StyleConstants.FontConstants,
* StyleConstants.ColorConstants.
* The attribute name and value are separated by a colon.
* Each pair is separated by a semicolon.
*
* @exception IOException on any I/O error
*/
while (attributeNames.hasMoreElements()) {
indent();
write(':');
toString());
write(';');
}
}
}
/**
* Writes out text.
*
* @exception IOException on any I/O error
*/
}
}
}
/**
* Writes out a start tag appropriately
* indented. Also increments the indent level.
*
* @exception IOException on any I/O error
*/
indent();
incrIndent();
}
/**
* Writes out an end tag appropriately
* indented. Also decrements the indent level.
*
* @exception IOException on any I/O error
*/
decrIndent();
indent();
}
/**
* 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. The content is surrounded by
* valid HTML comment markers to ensure that the
* document is viewable in applications/browsers
* that do not support the tag.
*
* @exception IOException on any I/O error
*/
writeStartTag("<head>");
writeStartTag("<style>");
writeStartTag("<!--");
writeStyles();
writeEndTag("-->");
writeEndTag("</style>");
writeEndTag("</head>");
}
/**
* Writes out all the named styles as the
* content of the <style> tag.
*
* @exception IOException on any I/O error
*/
/*
* Access to DefaultStyledDocument done to workaround
* a missing API in styled document to access the
* stylenames.
*/
while (styleNames.hasMoreElements()) {
/** PENDING: Once the name attribute is removed
from the list we check check for 0. **/
if (s.getAttributeCount() == 1 &&
continue;
}
indent();
write(" {\n");
incrIndent();
writeAttributes(s);
decrIndent();
indent();
write("}\n");
}
}
/**
* Iterates over the elements in the document
* and processes elements based on whether they are
* branch elements or leaf elements. This method specially handles
* leaf elements that are text.
*
* @exception IOException on any I/O error
*/
/*
This will be a section element for a styled document.
We represent this element in HTML as the body tags.
Therefore we ignore it.
*/
writeStartTag("<body>");
boolean inContent = false;
continue;
}
if (inContent) {
inContent = false;
fontMask = 0;
}
inContent = true;
} else {
inContent = true;
}
}
if (inContent) {
}
writeEndTag("</body>");
}
/**
* Emits an end tag for a <p>
* tag. Before writing out the tag, this method ensures
* that all other tags that have been opened are
* appropriately closed off.
*
* @exception IOException on any I/O error
*/
if (inFontTag()) {
endSpanTag();
} else {
}
writeEndTag("</p>");
}
/**
* Emits the start tag for a paragraph. If
* the paragraph has a named style associated with it,
* then this method also generates a class attribute for the
* <p> tag and sets its value to be the name of the
* style.
*
* @exception IOException on any I/O error
*/
} else {
writeStartTag("<p>");
}
}
/**
* Responsible for writing out other non-text leaf
* elements.
*
* @exception IOException on any I/O error
*/
indent();
}
}
/**
* Responsible for handling Icon Elements;
* deliberately unimplemented. How to implement this method is
* an issue of policy. For example, if you're generating
* an <img> tag, how should you
* represent the src attribute (the location of the image)?
* In certain cases it could be a URL, in others it could
* be read from a stream.
*
* @param elem element of type StyleConstants.IconElementName
*/
}
/**
* Responsible for handling Component Elements;
* deliberately unimplemented.
* How this method is implemented is a matter of policy.
*/
}
/**
* Returns true if the element is a text element.
*
*/
}
/**
* Writes out the attribute set
* in an HTML-compliant manner.
*
* @exception IOException on any I/O error
* @exception BadLocationException if pos represents an invalid
* location within the document.
*/
throws IOException, BadLocationException {
if (needsIndenting) {
indent();
}
}
/**
* Generates
* bold <b>, italic <i>, and <u> tags for the
* text based on its attribute settings.
*
* @exception IOException on any I/O error
*/
int endMask = 0;
int startMask = 0;
}
}
}
}
}
}
}
/**
* Tweaks the appropriate bits of fontMask
* to reflect whether the text is to be displayed in
*
*/
}
}
}
}
/**
* Writes out start tags <u>, <i>, and <b> based on
* the mask settings.
*
* @exception IOException on any I/O error
*/
if (mask != 0) {
write("<u>");
}
write("<i>");
}
write("<b>");
}
}
}
/**
* Writes out end tags for <u>, <i>, and <b> based on
* the mask settings.
*
* @exception IOException on any I/O error
*/
if (mask != 0) {
write("</b>");
}
write("</i>");
}
write("</u>");
}
}
}
/**
* Writes out the remaining
* character-level attributes (attributes other than bold,
* italic, and underline) in an HTML-compliant way. Given that
* attributes such as font family and font size have no direct
* mapping to HTML tags, a <span> tag is generated and its
* style attribute is set to contain the list of remaining
* attributes just like inline styles.
*
* @exception IOException on any I/O error
*/
return;
}
boolean first = true;
color);
first = false;
}
if (!first) {
}
first = false;
}
if (!first) {
}
first = false;
}
if (fontMask != 0) {
fontMask = 0;
}
}
else if (fontAttributes != null) {
fontMask = 0;
endSpanTag();
}
}
/**
* Returns true if we are currently in a <font> tag.
*/
protected boolean inFontTag() {
return (fontAttributes != null);
}
/**
* This is no longer used, instead <span> will be written out.
* <p>
* Writes out an end tag for the <font> tag.
*
* @exception IOException on any I/O error
*/
writeEndTag("</font>");
}
/**
* This is no longer used, instead <span> will be written out.
* <p>
* 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.
*
* @exception IOException on any I/O error
*/
boolean callIndent = false;
if (inFontTag()) {
endFontTag();
callIndent = true;
}
if (callIndent) {
indent();
}
}
/**
* 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.
*
* @exception IOException on any I/O error
*/
boolean callIndent = false;
if (inFontTag()) {
endSpanTag();
callIndent = true;
}
if (callIndent) {
indent();
}
}
/**
* Writes out an end tag for the <span> tag.
*
* @exception IOException on any I/O error
*/
writeEndTag("</span>");
}
/**
* Adds the style named <code>style</code> 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.
*/
if (styleNameMapping == null) {
return style;
}
}
}
}
}
return mappedName;
}
/**
* Returns the mapped style name corresponding to <code>style</code>.
*/
if (styleNameMapping == null) {
return style;
}
}
}
}