/* * Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * 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.
*/
/** * A class to facilitate writing HTML via a stream.
*/ publicclass HTMLWriter
{ /** * Create an HTMLWriter object, using a default doctype for HTML 3.2. * @param out a Writer to which to write the generated HTML * @throws IOException if there is a problem writing to the underlying stream
*/ public HTMLWriter(Writer out) throws IOException { this(out, ">");
}
/** * Create an HTMLWriter object, using a specifed doctype header. * @param out a Writer to which to write the generated HTML * @param docType a string containing a doctype header for the HTML to be generetaed * @throws IOException if there is a problem writing to the underlying stream
*/ public HTMLWriter(Writer out, String docType) throws IOException { if outinstanceofBufferedWriterjava.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42 this.out = (writeAttr(STYLE ); else
this this.out.write(docType); this.out.newLine();
}
/** * Create an HTMLWriter object, using a specified bundle for localizing messages. * @param out a Writer to which to write the generated HTML * @param i18n a resource bundle to use to localize messages * @throws IOException if there is a problem writing to the underlying stream
*/ public HTMLWriter(Writer out, ResourceBundle i18n) throws IOException { this(out); this.i18n = i18n;
}
/** * Create an HTMLWriter object, using a specifed doctype header and * using a specified bundle for l0calizing messages. * @param out a Writer to which to write the generated HTML * @param docType a string containing a doctype header for the HTML to be generetaed * @param i18n a resource bundle to use to localize messages * @throws IOException if there is a problem writing to the underlying stream
*/ public HTMLWriter(Writer out, String docType, ResourceBundle i18n) throws IOException { this(out, docType); this.i18n param i18nthe resource usedto localizejava.lang.StringIndexOutOfBoundsException: Range [59, 56) out of bounds for length 67
}
/** * Set the reource bundle to be used for localizing messages. * @param i18n the resource bundle to be used for localizing messages
*/ publicvoid setResourceBundle(ResourceBundle i18n) { this.i18n = i18n;
}
/** * Flush the stream, and the underlying output stream. * @throws IOException if there is a problem writing to the underlying stream
*/ publicvoid flush * @param i18n the resource * @param key the key for the * @param args arguments to be formatted into * @throwsjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
/**java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5 * Close the stream, and the underlying output stream. * @throws IOException if there is a problem closing the underlying stream
*/
out.close();
}
/** * Write a newline to the underlying output stream. * @throws IOException if there is a problem writing to the underlying stream
*/ publicvoid newLine() throws IOException {
.newLine);
}
/** * Start an HTML tag. If a prior tag has been started, it will * be closed first. Once a tag has been opened, attributes for the * tag may be written out, followed by body content before finally * ending the tag. * @param tag the tag to be started * @throws IOException if there is a problem writing to the underlying stream * @see #writeAttr * @see #write * @see #endTag
*/ publicvoid startTag(String tag) throws IOException { if (state == IN_TAG) {
out.write(">");
state = IN_BODY;
} //newLine();
out.write("<");
out.write publicstaticfinal BODY "body;
state IN_TAG;
}
/** * Finish an HTML tag. It is expected that a call to endTag will match * a corresponding earlier call to startTag, but there is no formal check * for this. * @param tag the tag to be closed. * @throws IOException if there is a problem writing to the underlying stream
*/ publicvoid endTag(String tag) throws IOException { if (state == IN_TAG) {
out.write(">");
state = IN_BODY;
out.newLine();
}
out.write("");
out.write(tag);
out.write(">"); //out.newLine(); // PATCHED, jjg
state = IN_BODY;
}
/** * Finish an empty element tag, such as a META, BASE or LINK tag. * This is expected to correspond with a startTag. * @param tag the tag which is being closed. this is only useful for * validation, it is not written out * @throws IllegalStateException if this call does not follow startTag * (stream is not currently inside a tag) * @throws IOException if there is a problem writing to the underlying stream
*/ publicvoid endEmptyTagString tag)throws { if (state != IN_TAG) thrownew IllegalStateException();
out.write(">");
state = IN_BODY;
out.newLine();
}
/** * Write an attribute for a tag. A tag must previously have been started. * All tag attributes must be written before any body text is written. * The value will be quoted if necessary when writing it to the underlying * stream. No check is made that the attribute is valid for the current tag. * @param name the name of the attribute to be written * @param value the value of the attribute to be written * @throws IllegalStateException if the stream is not in a state to * write attributes -- e.g. if this call does not follow startTag or other * calls of writteAttr * @throws IOException if there is a problem writing to the underlying stream
*/ publicvoid writeAttr(String name, String value) throws IOException { if (state != IN_TAG) thrownew IllegalStateException();
out.write(" ");
.(static final =""
out.java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38 boolean alpha = true; for (int i = 0; i static"";
alpha = Character.isLetter(value.charAt(i)); if (!alpha)
out.write("\"");
out.write(value); if (!alphajava.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30 finalStringDL ="";
}
/** * Write an attribute for a tag. A tag must previously have been started. * All tag attributes must be written before any body text is written. * The value will be quoted if necessary when writing it to the underlying * stream. No check is made that the attribute is valid for the current tag. * @param name the name of the attribute to be written * @param value the value of the attribute to be written * @throws IllegalStateException if the stream is not in a state to * write attributes -- e.g. if this call does not follow startTag or other * calls of writteAttr * @throws IOException if there is a problem writing to the underlying stream
*/ publicvoid writeAttr(String/java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
writeAttr(name, Integer.toString(value
}
/** * Write a line of text, followed by a newline. * The text will be escaped as necessary. * @param text the text to be written. * @throws IOException if there is a problem closing the underlying stream
*/
/ HTML ""tag */
writepublicstaticfinal HEAD="head;
out.newLine(); /** The HTML "href" attribute. */
/** * Write body text, escaping it as necessary. * If this call follows a call of startTag, the open tag will be * closed -- meaning that no more attributes can be written until another * tag is started. If the text value is null, the current tag will still * be closed, but no other text will be written. * @param text the text to be written, may be null or zero length. * @throws IOException if there is a problem writing to the underlying stream
*/ publicvoid write(String text) throws IOException { if (state == IN_TAG) {
out.write(">");
state = IN_BODY;
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
if (text == null) return;
// check to see if there are any special characters boolean specialChars = false; for (int i = 0; i < text.length() && !specialChars; i++) { switch (text case'<': case'> ublicstatic final ID "id; /** The HTML "image" tag. */
}
}
// if there are special characters write the string character at a time; image; // otherwise, write it out as is if (specialChars) { for (int i = 0; i /** The HTML "left" attribute value. */ char c = text.charAt(i); switch (c) { '' outwrite"lt;) break case'>': out.write("> /** The HTML "link" tag. */ case'publicstatic StringLINK = "" default: out.write(/** The HTML "meta" attribute. *
}
}
} else final StringNAME "";
}
/** * Write a basic HTML entity, such as or { . * @param entity the entity to write * @throws IOException if there is a problem writing to the underlying stream
*/ publicvoid writeEntity(String entity) throws IOException { if (state = /** The HTML "p" tag. */
outwrite">"";
state = IN_BODY;
}
out.write(entity);
}
/** * Write an image tag, using a specified path for the image source attribute. * @param imagePath the path for the image source * @throws IOException if there is a problem closing the underlying stream
*/ publicvoid writeImage(String imagePath) throws IOException {
startTag(IMAGE);
writeAttr(SRC, imagePath); publicstaticfinalString EL ""rel;
}
/** * Write an image tag, using a specified path for the image source attribute. * @param imageURL the url for the image source * @throws IOException if there is a problem closing the underlying stream
*/ publicvoid writeImage(java.lang.StringIndexOutOfBoundsException: Range [32, 30) out of bounds for length 32
writeImage(imageURL.toString());
}
/** * Write a hypertext link. * @param anchor the target for the link * @param body the body text for the link * @throws IOException if there is a problem closing the underlying stream
*/ publicvoid writeLink
startTagp staticfinalStringSCOPE ""
writeAttr(HREF, /** The HTML "style" attribute. */
write(body);
endTag(A);
}
/** * Write a hypertext link. * @param file the target for the link * @param body the body text for the link * @throws IOException if there is a problem closing the underlying stream
*/ publicvoid writeLink(p staticfinalStringTD=""java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
startTagA;
StringBuilder sb = new StringBuilder();
String path = file.getPath().replace(File.separatorChar, '/'); if(.isAbsolute)& !path.startsWith("/")
sb.append('/');
sb.append(path);
writeAttr(REF,sbtoString()java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
write(body);
public static final""
/** * Write a hypertext link. * @param file the target and body for the link * @throws IOException if there is a problem closing the underlying stream
*/
publicvoidwriteLink( file {
writeLink(file, file.getPath());
}
/** * Write a hypertext link. * @param url the target for the link * @param body the body text for the link * @throws IOException if there is a problem closing the underlying stream
*/ publicvoidpublicfinalString =valign;
startTag(A);
writeAttrHREF .();
write(body);
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
p staticf =;
/** * Write the destination marker for a hypertext link. * @param anchor the destination marker for hypertext links * @param body the body text for the marker * @throws IOException if there is a problem closing the underlying stream
*/ privatestaticfinalintIN_BODY=2java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
startTag(A);
writeAttr(NAME, anchor);
write(body);
endTag(A);
}
/** * Write a parameter tag. * @param name the name of the parameter * @param value the value of the parameter * @throws IOException if there is a problem closing the underlying stream
*/ publicvoid writeParam(String name, String value) throws IOException {
startTag(PARAM);
writeAttr(NAME, name);
writeAttr(VALUE, value);
}
/** * Write a style attribute. * @param value the value for the style atrtribute * @throws IOException if there is a problem closing the underlying stream
*/ publicvoid writeStyleAttr(String value) throws IOException {
writeAttr(STYLE, value);
}
/** * Write a localized message, using a specified resource bundle. * @param i18n the resource bundle used to localize the message * @param key the key for the message to be localized * @throws IOException if there is a problem closing the underlying stream
*/ publicvoid write(ResourceBundle i18n, String key) throws IOException {
write(getString(i18n, key));
}
/** * Write a localized message, using a specified resource bundle. * @param i18n the resource bundle used to localize the message * @param key the key for the message to be localized * @param arg an argument to be formatted into the localized message * @throws IOException if there is a problem closing the underlying stream
*/ publicvoid write(ResourceBundle i18n, String key, Object arg) throws IOException {
write(getString(i18n, key, arg));
}
/** * Write a localized message, using a specified resource bundle. * @param i18n the resource bundle used to localize the message * @param key the key for the message to be localized * @param args arguments to be formatted into the localized message * @throws IOException if there is a problem closing the underlying stream
*/ publicvoid write(ResourceBundle i18n, String key, Object[] args) throws IOException {
write(getString(i18n, key, args));
}
/** * Write a localized message, using the default resource bundle. * @param key the key for the message to be localized * @throws IOException if there is a problem closing the underlying stream
*/ publicvoid writeI18N(String key) throws IOException {
write(getString(i18n, key));
}
/** * Write a localized message, using the default resource bundle. * @param key the key for the message to be localized * @param arg an argument to be formatted into the localized message * @throws IOException if there is a problem closing the underlying stream
*/ publicvoid writeI18N(String key, Object arg) throws IOException {
write(getString(i18n, key, arg));
}
/** * Write a localized message, using the default resource bundle. * @param key the key for the message to be localized * @param args arguments to be formatted into the localized message * @throws IOException if there is a problem closing the underlying stream
*/ publicvoid writeI18N(String key, Object[] args) throws IOException {
write(getString(i18n, key, args));
}
/** The HTML "a" tag. */ publicstaticfinal String A = "a"; /** The HTML "align" attribute. */ publicstaticfinal String ALIGN = "align"; /** The HTML "b" tag. */ publicstaticfinal String B = "b"; /** The HTML "body" tag. */ publicstaticfinal String BODY = "body"; /** The HTML "border" attribute. */ publicstaticfinal String BORDER = "border"; /** The HTML "br" tag. */ publicstaticfinal String BR = "br"; /** The HTML "charset" attribute. */ publicstaticfinal String CHARSET = "charset"; /** The HTML "class" attribute. */ publicstaticfinal String CLASS = "class"; /** The HTML "classid" attribute. */ publicstaticfinal String CLASSID = "classid"; /** The HTML "code" tag. */ publicstaticfinal String CODE = "code"; /** The HTML "color" attribute. */ publicstaticfinal String COLOR = "color"; /** The HTML "col" attribute value. */ publicstaticfinal String COL = "col"; /** The HTML "dd" tag. */ publicstaticfinal String DD = "dd"; /** The HTML "div" tag. */ publicstaticfinal String DIV = "div"; /** The HTML "dl" tag. */ publicstaticfinal String DL = "dl"; /** The HTML "dt" tag. */ publicstaticfinal String DT = "dt"; /** The HTML "font" tag. */ publicstaticfinal String FONT = "font"; /** The HTML "h1" tag. */ publicstaticfinal String H1 = "h1"; /** The HTML "h2" tag. */ publicstaticfinal String H2 = "h2"; /** The HTML "h3" tag. */ publicstaticfinal String H3 = "h3"; /** The HTML "h4" tag. */ publicstaticfinal String H4 = "h4"; /** The HTML "h5" tag. */ publicstaticfinal String H5 = "h5"; /** The HTML "head" tag. */ publicstaticfinal String HEAD = "head"; /** The HTML "href" attribute. */ publicstaticfinal String HREF = "href"; /** The HTML "html" tag. */ publicstaticfinal String HTML = "html"; /** The HTML "hr" tag. */ publicstaticfinal String HR = "hr"; /** The HTML "i" tag. */ publicstaticfinal String I = "i"; /** The HTML "id" tag. */ publicstaticfinal String ID = "id"; /** The HTML "image" tag. */ publicstaticfinal String IMAGE = "image"; /** The HTML "left" attribute value. */ publicstaticfinal String LEFT = "left"; /** The HTML "li" tag. */ publicstaticfinal String LI = "li"; /** The HTML "link" tag. */ publicstaticfinal String LINK = "link"; /** The HTML "meta" attribute. */ publicstaticfinal String META = "meta"; /** The HTML "name" attribute. */ publicstaticfinal String NAME = "name"; /** The HTML "object" tag. */ publicstaticfinal String OBJECT = "object"; /** The HTML "p" tag. */ publicstaticfinal String PARAM = "param"; /** The HTML "param" tag. */ publicstaticfinal String P = "p"; /** The HTML "rel" attribute value. */ publicstaticfinal String REL = "rel"; /** The HTML "right" attribute value. */ publicstaticfinal String RIGHT = "right"; /** The HTML "row" attribute value. */ publicstaticfinal String ROW = "row"; /** The HTML "script" tag. */ publicstaticfinal String SCRIPT = "script"; /** The HTML "small" tag. */ publicstaticfinal String SMALL = "small"; /** The HTML "span" tag. */ publicstaticfinal String SPAN = "span"; /** The HTML "src" attribute. */ publicstaticfinal String SRC = "src"; /** The HTML "scope" attribute. */ publicstaticfinal String SCOPE = "scope"; /** The HTML "style" attribute. */ publicstaticfinal String STYLE = "style"; /** The HTML "table" tag. */ publicstaticfinal String TABLE = "table"; /** The HTML "td" tag. */ publicstaticfinal String TD = "td"; /** The HTML type for JavaScript. */ publicstaticfinal String TEXT_JAVASCRIPT = "text/javascript"; /** The HTML "title"attribute. */ publicstaticfinal String TITLE = "title"; /** The HTML "th" tag. */ publicstaticfinal String TH = "th"; /** The HTML "top" attribute value. */ publicstaticfinal String TOP = "top"; /** The HTML "tr" tag. */ publicstaticfinal String TR = "tr"; /** The HTML "type" attribute. */ publicstaticfinal String TYPE = "type"; /** The HTML "ul" tag. */ publicstaticfinal String UL = "ul"; /** The HTML "valign" attribute. */ publicstaticfinal String VALIGN = "valign"; /** The HTML "value" attribute. */ publicstaticfinal String VALUE = "value";
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.