/** * Writes the start of a XHTML document, including the head and start of body element. * @param title the title of the document (can be null). */ public void writeStartHTMLDocument (String title) { write("<html>"+lineBreak); write("<head>"+lineBreak); write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">"+lineBreak); if ( title != null ) { writeElementString("title", title); writeLineBreak(); } write("</head>"+lineBreak); }
/** * Writes the start of the document. This method generates the XML declaration. */ public void writeStartDocument () { write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+lineBreak); }
/** * Closes the tag of the last start tag output, if needed. */ private void closeStartTag () { if ( inStartTag ) { write(">"); inStartTag = false; } }
/** * Writes a chunk of raw XML (and line-breaks are normalized to platform specific ones). * If a tag is open it is not closed (so this allows you to output raw attributes). * @param xmlData the data to output. No escaping is performed, but the line-breaks are * converted to the line-break type of the output. */ public void appendRawXML (String xmlData) { write(LINE_BRAKE_PATTERN.matcher(xmlData).replaceAll(lineBreak)); }
/** * Writes a comment. * @param text the text of the comment. * @param withLineBreak add a line break at the end of the comment. */ public void writeComment (String text, boolean withLineBreak) { closeStartTag(); write("<!--"); appendRawXML(text); write("-->"); if ( withLineBreak ) write(lineBreak); }
/** * Writes an element and its content. * @param name the name of the element to write. * @param content the content to enclose inside this element. */ public void writeElementString (String name, String content) { closeStartTag(); write("<" + name + ">"); write(Util.escapeToXML(content, 0, false, null)); write("</" + name + ">"); }
/** * Writes the end of the last started element and writes a line-break. */ public void writeEndElementLineBreak () { closeStartTag(); write("</" + elements.pop() + ">"+lineBreak); }
/** * Writes an attribute and its associated value. You must use * {@link #writeStartElement(String)} just before. * @param name the name of the attribute. * @param value the value of the attribute. */ public void writeAttributeString (String name, String value) { write(" " + name + "=\"" + Util.escapeToXML(value, 3, false, null) + "\""); }
/** * Writes the start of an element. * @param name the name of the element to start. */ public void writeStartElement (String name) { closeStartTag(); elements.push(name); write("<" + name); inStartTag = true; }
/** * Writes the end of the last started element. */ public void writeEndElement () { closeStartTag(); write("</" + elements.pop() + ">"); }
/** * Writes a line-break, and if the writer is in a start tag, close it before. */ public void writeLineBreak () { closeStartTag(); write(lineBreak); }