@Override protected XmlStreamWriter createXmlStreamWriter(Writer out) { return super.createFormattingXmlStreamWriter(out); } };
@Override public void beginHeading(int level, Attributes attributes) { closeSections(Math.max(level - 1, 0)); while (headingLevel < level) { headingLevel++; writer.writeStartElement(headingLevel == 1 ? "chapter" : "section"); //$NON-NLS-1$ //$NON-NLS-2$ if (attributes != null) { applyAttributes(attributes); attributes = null; } } writer.writeStartElement("title"); //$NON-NLS-1$ }
@Override public void lineBreak() { ensureBlockElementsOpen(); // no equivalent in DocBook. characters("\n"); //$NON-NLS-1$ }
@Override public void image(Attributes attributes, String url) { ensureBlockElementsOpen(); String cssClass = attributes.getCssClass(); boolean inlined = false; if (cssClass != null && CSS_CLASS_INLINE.matcher(cssClass).find()) { inlined = true; } emitImage(attributes, url, inlined); }
@Override public void beginBlock(BlockType type, Attributes attributes) { if (headingLevel == 0) { beginHeading(1, new Attributes()); endHeading(); case DEFINITION_TERM: BlockDescription blockDescription = findBlockDescription(BlockType.DEFINITION_LIST); if (blockDescription.entrySize > 0) { endBlockEntry(blockDescription); openBlockEntry(blockDescription, new String[] { "varlistentry" }); //$NON-NLS-1$ endBlockEntry(previousBlock); applyAttributes(attributes);
parser.setMarkupLanguage(markupLanguage); parser.setBuilder(builder); builder.setBookTitle(bookTitle == null ? name : bookTitle); if (doctype != null) { builder.setDoctype(doctype);
private void emitImage(Attributes attributes, String url, boolean inline) { ensureBlockElementsOpen(); writer.writeStartElement(inline ? "inlinemediaobject" : "mediaobject"); //$NON-NLS-1$ //$NON-NLS-2$ applyAttributes(attributes); writer.writeStartElement("imageobject"); //$NON-NLS-1$ writer.writeEmptyElement("imagedata"); //$NON-NLS-1$ writer.writeAttribute("fileref", makeUrlAbsolute(url)); //$NON-NLS-1$ String cssStyle = attributes.getCssStyle(); if (cssStyle != null) {
@Override public void endDocument() { closeSections(0); writeGlossaryAppendix(); writer.writeEndElement(); // book writer.writeEndDocument(); acronyms.clear(); }
public String parse(String markupContent) throws Exception { if (markupLanguage == null) { throw new IllegalStateException("must set markupLanguage"); //$NON-NLS-1$ } StringWriter out = new StringWriter(); DocBookDocumentBuilder builder = new DocBookDocumentBuilder(out) { @Override protected XmlStreamWriter createXmlStreamWriter(Writer out) { return super.createFormattingXmlStreamWriter(out); } }; builder.setBookTitle(bookTitle); MarkupParser markupParser = new MarkupParser(); markupParser.setBuilder(builder); markupParser.setMarkupLanguage(markupLanguage); markupParser.parse(markupContent); return out.toString(); }
@Override public void beginSpan(SpanType type, Attributes attributes) { ensureBlockElementsOpen(); switch (type) { case BOLD: break; applyAttributes(attributes);
@Override public void characters(String text) { ensureBlockElementsOpen(); super.characters(text); }
@Override public void acronym(String text, String definition) { String previousDef = acronyms.put(text, definition); if (previousDef != null && previousDef.length() > definition.length()) { acronyms.put(text, previousDef); } writer.writeStartElement("glossterm"); //$NON-NLS-1$ characters(text); writer.writeEndElement(); }
@Override public void charactersUnescaped(String literal) { ensureBlockElementsOpen(); // note: this *may* have HTML tags in it writer.writeLiteral(literal); // Logger.getLogger(DocBookDocumentBuilder.class.getName()).warning("HTML literal not supported in DocBook"); }
@Override protected XmlStreamWriter createXmlStreamWriter(Writer out) { return super.createFormattingXmlStreamWriter(out); } };
@Override public void entityReference(String entity) { ensureBlockElementsOpen(); if (entity.startsWith("#")) { //$NON-NLS-1$ String numeric = entity.substring(1); int base = 10; if (numeric.startsWith("x")) { //$NON-NLS-1$ numeric = entity.substring(1); base = 16; } int unicodeValue = Integer.parseInt(numeric, base); if (entityReferenceToUnicode.contains(unicodeValue)) { writer.writeCharacters("" + ((char) unicodeValue)); //$NON-NLS-1$ return; } } writer.writeEntityRef(entity); }
private void link(Attributes attributes, String href, ContentEmitter emitter) { ensureBlockElementsOpen(); if (href == null) { writer.writeStartElement("anchor"); //$NON-NLS-1$ if (attributes.getId() != null) { writer.writeAttribute("id", attributes.getId()); //$NON-NLS-1$ } emitter.emit(); writer.writeEndElement(); // anchor } else if (href.startsWith("#")) { //$NON-NLS-1$ if (href.length() > 1) { writer.writeStartElement("link"); //$NON-NLS-1$ writer.writeAttribute("linkend", href.substring(1)); //$NON-NLS-1$ emitter.emit(); writer.writeEndElement(); // link } else { emitter.emit(); } } else { writer.writeStartElement("ulink"); //$NON-NLS-1$ writer.writeAttribute("url", href); //$NON-NLS-1$ emitter.emit(); writer.writeEndElement(); // ulink } }