/** * Gets an instance of the <CODE>HtmlWriter</CODE>. * * @param document The <CODE>Document</CODE> that has to be written * @param os The <CODE>OutputStream</CODE> the writer has to write to. * @return a new <CODE>HtmlWriter</CODE> */ public static HtmlWriter getInstance(Document document, OutputStream os) { return new HtmlWriter(document, os); }
/** * Writes a link in the header. * * @param header the element that has to be written * @throws IOException */ protected void writeLink(Header header) throws IOException { addTabs(2); writeStart(HtmlTags.LINK); write(HtmlTags.REL, header.getName()); write(HtmlTags.TYPE, HtmlTags.TEXT_CSS); write(HtmlTags.REFERENCE, header.getContent()); writeEnd(); }
/** * Signals that the <CODE>Document</CODE> was closed and that no other * <CODE>Elements</CODE> will be added. */ public void close() { try { initFooter(); // line added by David Freels addTabs(1); writeEnd(HtmlTags.BODY); os.write(NEWLINE); writeEnd(HtmlTags.HTML); super.close(); } catch(IOException ioe) { throw new ExceptionConverter(ioe); } }
/** * Signals that an new page has to be started. * * @return <CODE>true</CODE> if this action succeeded, <CODE>false</CODE> if not. */ public boolean newPage() { try { writeStart(HtmlTags.DIV); write(" "); write(HtmlTags.STYLE); write("=\""); writeCssProperty(Markup.CSS_KEY_PAGE_BREAK_BEFORE, Markup.CSS_VALUE_ALWAYS); write("\" /"); os.write(GT); } catch(IOException ioe) { throw new ExceptionConverter(ioe); } return true; }
Header h = (Header) element; if (HtmlTags.STYLESHEET.equals(h.getName())) { writeLink(h); writeJavaScript(h); writeHeader(h); case Element.AUTHOR: Meta meta = (Meta) element; writeHeader(meta); return true; case Element.TITLE: addTabs(2); writeStart(HtmlTags.TITLE); os.write(GT); addTabs(3); write(HtmlEncoder.encode(((Meta)element).getContent())); addTabs(2); writeEnd(HtmlTags.TITLE); return true; case Element.CREATOR: writeComment("Creator: " + HtmlEncoder.encode(((Meta)element).getContent())); return true; case Element.PRODUCER: writeComment("Producer: " + HtmlEncoder.encode(((Meta)element).getContent())); return true; case Element.CREATIONDATE: writeComment("Creationdate: " + HtmlEncoder.encode(((Meta)element).getContent()));
case Element.MARKED: { try { add(element); } catch (DocumentException e) { e.printStackTrace(); write(image, indent); return; boolean tag = isOtherFont(chunk.getFont()) || markup.size() > 0; if (tag) { addTabs(indent); writeStart(HtmlTags.SPAN); if (isOtherFont(chunk.getFont())) { write(chunk.getFont(), null); writeMarkupAttributes(markup); os.write(GT); writeStart(HtmlTags.SUP); writeStart(HtmlTags.SUB); write(HtmlEncoder.encode(chunk.getContent())); if (attributes != null && attributes.get(Chunk.SUBSUPSCRIPT) != null) { os.write(FORWARD); if (((Float)attributes.get(Chunk.SUBSUPSCRIPT)).floatValue() > 0) {
super.open(); try { writeComment(Document.getVersion()); writeComment("CreationDate: " + new Date().toString()); addTabs(1); writeEnd(HtmlTags.HEAD); addTabs(1); writeStart(HtmlTags.BODY); if (document.leftMargin() > 0) { write(HtmlTags.LEFTMARGIN, String.valueOf(document.leftMargin())); write(HtmlTags.RIGHTMARGIN, String.valueOf(document.rightMargin())); write(HtmlTags.TOPMARGIN, String.valueOf(document.topMargin())); write(HtmlTags.BOTTOMMARGIN, String.valueOf(document.bottomMargin())); write(HtmlTags.BACKGROUNDCOLOR, HtmlEncoder.encode(pageSize.getBackgroundColor())); write(HtmlTags.JAVASCRIPT_ONLOAD, HtmlEncoder.encode(document.getJavaScript_onLoad())); write(HtmlTags.JAVASCRIPT_ONUNLOAD, HtmlEncoder.encode(document.getJavaScript_onUnLoad())); write(Markup.HTML_ATTR_CSS_CLASS, document.getHtmlStyleClass()); initHeader(); // line added by David Freels
if (font == null || !isOtherFont(font) /* || styleAttributes == null*/) return; write(" "); write(HtmlTags.STYLE); write("=\""); if (styleAttributes != null) { String key; for (Enumeration e = styleAttributes.propertyNames(); e.hasMoreElements(); ) { key = (String)e.nextElement(); writeCssProperty(key, styleAttributes.getProperty(key)); if (isOtherFont(font)) { writeCssProperty(Markup.CSS_KEY_FONTFAMILY, font.getFamilyname()); writeCssProperty(Markup.CSS_KEY_FONTSIZE, font.getSize() + "pt"); writeCssProperty(Markup.CSS_KEY_COLOR, HtmlEncoder.encode(font.getColor())); switch (fontstyle & Font.BOLDITALIC) { case Font.BOLD: writeCssProperty(Markup.CSS_KEY_FONTWEIGHT, Markup.CSS_VALUE_BOLD); break; case Font.ITALIC: writeCssProperty(Markup.CSS_KEY_FONTSTYLE, Markup.CSS_VALUE_ITALIC); break; case Font.BOLDITALIC: writeCssProperty(Markup.CSS_KEY_FONTWEIGHT, Markup.CSS_VALUE_BOLD); writeCssProperty(Markup.CSS_KEY_FONTSTYLE, Markup.CSS_VALUE_ITALIC); break;
/** * Writes out a CSS property. * @param prop a CSS property * @param value the value of the CSS property * @throws IOException */ protected void writeCssProperty(String prop, String value) throws IOException { write(new StringBuffer(prop).append(": ").append(value).append("; ").toString()); } }
/** * Adds the header to the top of the </CODE>Document</CODE> */ protected void initHeader() { if (header != null) { try { add(header.paragraph()); } catch(Exception e) { throw new ExceptionConverter(e); } } }
/** * Constructs a <CODE>HtmlWriter</CODE>. * * @param doc The <CODE>Document</CODE> that has to be written as HTML * @param os The <CODE>OutputStream</CODE> the writer has to write to. */ protected HtmlWriter(Document doc, OutputStream os) { super(doc, os); document.addDocListener(this); this.pageN = document.getPageNumber(); try { os.write(LT); os.write(getISOBytes(HtmlTags.HTML)); os.write(GT); os.write(NEWLINE); os.write(TAB); os.write(LT); os.write(getISOBytes(HtmlTags.HEAD)); os.write(GT); } catch(IOException ioe) { throw new ExceptionConverter(ioe); } }
Header h = (Header) element; if (HtmlTags.STYLESHEET.equals(h.getName())) { writeLink(h); writeJavaScript(h); writeHeader(h); case Element.AUTHOR: Meta meta = (Meta) element; writeHeader(meta); return true; case Element.TITLE: addTabs(2); writeStart(HtmlTags.TITLE); os.write(GT); addTabs(3); write(HtmlEncoder.encode(((Meta)element).getContent())); addTabs(2); writeEnd(HtmlTags.TITLE); return true; case Element.CREATOR: writeComment("Creator: " + HtmlEncoder.encode(((Meta)element).getContent())); return true; case Element.PRODUCER: writeComment("Producer: " + HtmlEncoder.encode(((Meta)element).getContent())); return true; case Element.CREATIONDATE: writeComment("Creationdate: " + HtmlEncoder.encode(((Meta)element).getContent()));
case Element.MARKED: { try { add(element); } catch (DocumentException e) { e.printStackTrace(); write(image, indent); return; boolean tag = isOtherFont(chunk.getFont()) || markup.size() > 0; if (tag) { addTabs(indent); writeStart(HtmlTags.SPAN); if (isOtherFont(chunk.getFont())) { write(chunk.getFont(), null); writeMarkupAttributes(markup); os.write(GT); writeStart(HtmlTags.SUP); writeStart(HtmlTags.SUB); write(HtmlEncoder.encode(chunk.getContent())); if (attributes != null && attributes.get(Chunk.SUBSUPSCRIPT) != null) { os.write(FORWARD); if (((Float)attributes.get(Chunk.SUBSUPSCRIPT)).floatValue() > 0) {
super.open(); try { writeComment(Document.getVersion()); writeComment("CreationDate: " + new Date().toString()); addTabs(1); writeEnd(HtmlTags.HEAD); addTabs(1); writeStart(HtmlTags.BODY); if (document.leftMargin() > 0) { write(HtmlTags.LEFTMARGIN, String.valueOf(document.leftMargin())); write(HtmlTags.RIGHTMARGIN, String.valueOf(document.rightMargin())); write(HtmlTags.TOPMARGIN, String.valueOf(document.topMargin())); write(HtmlTags.BOTTOMMARGIN, String.valueOf(document.bottomMargin())); write(HtmlTags.BACKGROUNDCOLOR, HtmlEncoder.encode(pageSize.getBackgroundColor())); write(HtmlTags.JAVASCRIPT_ONLOAD, HtmlEncoder.encode(document.getJavaScript_onLoad())); write(HtmlTags.JAVASCRIPT_ONUNLOAD, HtmlEncoder.encode(document.getJavaScript_onUnLoad())); write(Markup.HTML_ATTR_CSS_CLASS, document.getHtmlStyleClass()); initHeader(); // line added by David Freels
/** * Signals that an new page has to be started. * * @return <CODE>true</CODE> if this action succeeded, <CODE>false</CODE> if not. */ public boolean newPage() { try { writeStart(HtmlTags.DIV); write(" "); write(HtmlTags.STYLE); write("=\""); writeCssProperty(Markup.CSS_KEY_PAGE_BREAK_BEFORE, Markup.CSS_VALUE_ALWAYS); write("\" /"); os.write(GT); } catch(IOException ioe) { throw new ExceptionConverter(ioe); } return true; }
if (font == null || !isOtherFont(font) /* || styleAttributes == null*/) return; write(" "); write(HtmlTags.STYLE); write("=\""); if (styleAttributes != null) { String key; for (Enumeration e = styleAttributes.propertyNames(); e.hasMoreElements(); ) { key = (String)e.nextElement(); writeCssProperty(key, styleAttributes.getProperty(key)); if (isOtherFont(font)) { writeCssProperty(Markup.CSS_KEY_FONTFAMILY, font.getFamilyname()); writeCssProperty(Markup.CSS_KEY_FONTSIZE, font.getSize() + "pt"); writeCssProperty(Markup.CSS_KEY_COLOR, HtmlEncoder.encode(font.getColor())); switch (fontstyle & Font.BOLDITALIC) { case Font.BOLD: writeCssProperty(Markup.CSS_KEY_FONTWEIGHT, Markup.CSS_VALUE_BOLD); break; case Font.ITALIC: writeCssProperty(Markup.CSS_KEY_FONTSTYLE, Markup.CSS_VALUE_ITALIC); break; case Font.BOLDITALIC: writeCssProperty(Markup.CSS_KEY_FONTWEIGHT, Markup.CSS_VALUE_BOLD); writeCssProperty(Markup.CSS_KEY_FONTSTYLE, Markup.CSS_VALUE_ITALIC); break;
/** * Writes out a CSS property. * @param prop a CSS property * @param value the value of the CSS property * @throws IOException */ protected void writeCssProperty(String prop, String value) throws IOException { write(new StringBuffer(prop).append(": ").append(value).append("; ").toString()); } }
/** * Adds the header to the top of the </CODE>Document</CODE> */ protected void initHeader() { if (header != null) { try { add(header.paragraph()); } catch(Exception e) { throw new ExceptionConverter(e); } } }