- Index: src/test/java/org/apache/servicemix/docs/confluence/ConfluenceDocumentTest.java
- ===================================================================
- --- src/test/java/org/apache/servicemix/docs/confluence/ConfluenceDocumentTest.java (revision 954753)
- +++ src/test/java/org/apache/servicemix/docs/confluence/ConfluenceDocumentTest.java (working copy)
- @@ -%ld,%ld +%ld,%ld @@
- writer.flush();
- writer.close();
- + System.err.println(writer.toString());
- +
- String[] results = writer.toString().split("\\r?\\n\\r?");
- int i = 0;
- Index: src/test/java/org/apache/servicemix/docs/confluence/WikitextTest.java
- ===================================================================
- --- src/test/java/org/apache/servicemix/docs/confluence/WikitextTest.java (revision 0)
- +++ src/test/java/org/apache/servicemix/docs/confluence/WikitextTest.java (revision 0)
- @@ -%ld,%ld +%ld,%ld @@
- +package org.apache.servicemix.docs.confluence;
- +
- +import java.io.FileInputStream;
- +import java.io.InputStream;
- +import java.io.InputStreamReader;
- +import java.io.StringWriter;
- +
- +import org.apache.commons.io.IOUtils;
- +import org.eclipse.mylyn.wikitext.confluence.core.ConfluenceLanguage;
- +import org.eclipse.mylyn.wikitext.core.parser.MarkupParser;
- +import org.eclipse.mylyn.wikitext.core.parser.builder.DocBookDocumentBuilder;
- +import org.eclipse.mylyn.wikitext.core.parser.markup.MarkupLanguage;
- +
- +/**
- + * Created by IntelliJ IDEA.
- + * User: gnodet
- + * Date: Jun 15, 2010
- + * Time: 5:33:51 PM
- + * To change this template use File | Settings | File Templates.
- + */
- +public class WikitextTest {
- +
- + @org.junit.Test
- + public void testWikitext() throws Exception {
- +// InputStream is = getClass().getResource("lists.wiki").openStream();
- + InputStream is = new FileInputStream("/Users/gnodet/work/felix/git/karaf/manual/src/confluence/installation.wiki");
- + String markupContent = IOUtils.toString(is);
- + MarkupLanguage markupLanguage = new ConfluenceLanguage();
- + StringWriter writer = new StringWriter();
- + DocBookDocumentBuilder builder = new DocBookDocumentBuilder(writer);
- + MarkupParser parser = new MarkupParser();
- + parser.setMarkupLanguage(markupLanguage);
- + parser.setBuilder(builder);
- + parser.parse(markupContent);
- + writer.flush();
- + String out = writer.toString();
- + int beg = out.indexOf("<chapter");
- + int end = out.indexOf("</book>");
- + out = out.substring(beg, end);
- + System.err.println(out);
- +
- + writer = new StringWriter();
- + ConfluenceConverter document =
- + new ConfluenceConverter(new InputStreamReader(new FileInputStream("/Users/gnodet/work/felix/git/karaf/manual/src/confluence/installation.wiki")),
- + writer);
- +
- + document.convert();
- + writer.flush();
- + writer.close();
- + out = writer.toString();
- + System.err.println(out);
- + }
- +}
- Index: src/main/java/org/apache/servicemix/docs/confluence/CodeBlock.java
- ===================================================================
- --- src/main/java/org/apache/servicemix/docs/confluence/CodeBlock.java (revision 0)
- +++ src/main/java/org/apache/servicemix/docs/confluence/CodeBlock.java (revision 0)
- @@ -%ld,%ld +%ld,%ld @@
- +package org.apache.servicemix.docs.confluence;
- +
- +import org.eclipse.mylyn.internal.wikitext.confluence.core.block.AbstractConfluenceDelimitedBlock;
- +import org.eclipse.mylyn.wikitext.core.parser.Attributes;
- +import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder;
- +
- +/**
- + * Created by IntelliJ IDEA.
- + * User: gnodet
- + * Date: Jun 15, 2010
- + * Time: 9:44:44 PM
- + * To change this template use File | Settings | File Templates.
- + */
- +public class CodeBlock extends AbstractConfluenceDelimitedBlock {
- +
- + private String title;
- +
- + private String language;
- +
- + public CodeBlock() {
- + super("code"); //$NON-NLS-1$
- + }
- +
- + @Override
- + protected void beginBlock() {
- + if (title != null) {
- + Attributes attributes = new Attributes();
- + attributes.setTitle(title);
- + builder.beginBlock(DocumentBuilder.BlockType.PANEL, attributes);
- + }
- + Attributes attributes = new Attributes();
- + Attributes preAttributes = new Attributes();
- + if (language != null) {
- + attributes.setLanguage(language); //$NON-NLS-1$
- + }
- +// builder.beginBlock(DocumentBuilder.BlockType.PREFORMATTED, preAttributes);
- + builder.beginBlock(DocumentBuilder.BlockType.CODE, attributes);
- + builder.charactersUnescaped("<![CDATA[");
- + }
- +
- + @Override
- + protected void handleBlockContent(String content) {
- + builder.charactersUnescaped(content);
- + builder.charactersUnescaped("\n"); //$NON-NLS-1$
- + }
- +
- + @Override
- + protected void endBlock() {
- + builder.charactersUnescaped("]]>");
- + if (title != null) {
- + builder.endBlock(); // panel
- + }
- + builder.endBlock(); // code
- +// builder.endBlock(); // pre
- + }
- +
- + @Override
- + protected void resetState() {
- + super.resetState();
- + title = null;
- + }
- +
- + @Override
- + protected void setOption(String key, String value) {
- + if (key.equals("title")) { //$NON-NLS-1$
- + title = value;
- + } else if (key.equals("lang")) {
- + language = value;
- + }
- + }
- +
- + @Override
- + protected void setOption(String option) {
- + language = option.toLowerCase();
- + }
- +}
- Index: src/main/java/org/apache/servicemix/docs/confluence/ConfluenceLanguage.java
- ===================================================================
- --- src/main/java/org/apache/servicemix/docs/confluence/ConfluenceLanguage.java (revision 0)
- +++ src/main/java/org/apache/servicemix/docs/confluence/ConfluenceLanguage.java (revision 0)
- @@ -%ld,%ld +%ld,%ld @@
- +package org.apache.servicemix.docs.confluence;
- +
- +import java.util.ArrayList;
- +import java.util.List;
- +
- +import org.eclipse.mylyn.internal.wikitext.confluence.core.block.ColorBlock;
- +import org.eclipse.mylyn.internal.wikitext.confluence.core.block.ExtendedPreformattedBlock;
- +import org.eclipse.mylyn.internal.wikitext.confluence.core.block.ExtendedQuoteBlock;
- +import org.eclipse.mylyn.internal.wikitext.confluence.core.block.HeadingBlock;
- +import org.eclipse.mylyn.internal.wikitext.confluence.core.block.ListBlock;
- +import org.eclipse.mylyn.internal.wikitext.confluence.core.block.QuoteBlock;
- +import org.eclipse.mylyn.internal.wikitext.confluence.core.block.TableBlock;
- +import org.eclipse.mylyn.internal.wikitext.confluence.core.block.TableOfContentsBlock;
- +import org.eclipse.mylyn.internal.wikitext.confluence.core.block.TextBoxBlock;
- +import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder.BlockType;
- +import org.eclipse.mylyn.wikitext.core.parser.markup.Block;
- +
- +public class ConfluenceLanguage extends org.eclipse.mylyn.wikitext.confluence.core.ConfluenceLanguage {
- +
- + private final List<Block> nestedBlocks = new ArrayList<Block>();
- +
- + public ConfluenceLanguage() {
- + }
- +
- + @Override
- + protected void clearLanguageSyntax() {
- + super.clearLanguageSyntax();
- + nestedBlocks.clear();
- + }
- +
- + public List<Block> getNestedBlocks() {
- + return nestedBlocks;
- + }
- +
- + @Override
- + protected void addStandardBlocks(List<Block> blocks, List<Block> paragraphBreakingBlocks) {
- + // IMPORTANT NOTE: Most items below have order dependencies. DO NOT REORDER ITEMS BELOW!!
- +
- + HeadingBlock headingBlock = new HeadingBlock();
- + blocks.add(headingBlock);
- + paragraphBreakingBlocks.add(headingBlock);
- + nestedBlocks.add(headingBlock);
- + ListBlock listBlock = new ListBlock();
- + blocks.add(listBlock);
- + paragraphBreakingBlocks.add(listBlock);
- + nestedBlocks.add(listBlock);
- + blocks.add(new QuoteBlock());
- + TableBlock tableBlock = new TableBlock();
- + blocks.add(tableBlock);
- + paragraphBreakingBlocks.add(tableBlock);
- + nestedBlocks.add(tableBlock);
- + ExtendedQuoteBlock quoteBlock = new ExtendedQuoteBlock();
- + blocks.add(quoteBlock);
- + paragraphBreakingBlocks.add(quoteBlock);
- + ExtendedPreformattedBlock noformatBlock = new ExtendedPreformattedBlock();
- + blocks.add(noformatBlock);
- + paragraphBreakingBlocks.add(noformatBlock);
- +
- + blocks.add(new TextBoxBlock(BlockType.PANEL, "panel")); //$NON-NLS-1$
- + blocks.add(new TextBoxBlock(BlockType.NOTE, "note")); //$NON-NLS-1$
- + blocks.add(new TextBoxBlock(BlockType.INFORMATION, "info")); //$NON-NLS-1$
- + blocks.add(new TextBoxBlock(BlockType.WARNING, "warning")); //$NON-NLS-1$
- + blocks.add(new TextBoxBlock(BlockType.TIP, "tip")); //$NON-NLS-1$
- + CodeBlock codeBlock = new CodeBlock();
- + blocks.add(codeBlock);
- + paragraphBreakingBlocks.add(codeBlock);
- + blocks.add(new TableOfContentsBlock());
- + ColorBlock colorBlock = new ColorBlock();
- + blocks.add(colorBlock);
- + paragraphBreakingBlocks.add(colorBlock);
- + }
- +
- +}
- Index: src/main/java/org/apache/servicemix/docs/confluence/DocBookDocumentBuilder.java
- ===================================================================
- --- src/main/java/org/apache/servicemix/docs/confluence/DocBookDocumentBuilder.java (revision 0)
- +++ src/main/java/org/apache/servicemix/docs/confluence/DocBookDocumentBuilder.java (revision 0)
- @@ -%ld,%ld +%ld,%ld @@
- +package org.apache.servicemix.docs.confluence;
- +
- +import java.io.Writer;
- +import java.util.HashMap;
- +import java.util.HashSet;
- +import java.util.Iterator;
- +import java.util.Map;
- +import java.util.Set;
- +import java.util.Stack;
- +import java.util.TreeMap;
- +import java.util.logging.Logger;
- +import java.util.regex.Matcher;
- +import java.util.regex.Pattern;
- +
- +import org.eclipse.mylyn.internal.wikitext.core.util.css.CssParser;
- +import org.eclipse.mylyn.internal.wikitext.core.util.css.CssRule;
- +import org.eclipse.mylyn.wikitext.core.parser.Attributes;
- +import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder;
- +import org.eclipse.mylyn.wikitext.core.parser.LinkAttributes;
- +import org.eclipse.mylyn.wikitext.core.parser.builder.AbstractXmlDocumentBuilder;
- +import org.eclipse.mylyn.wikitext.core.parser.util.MarkupToDocbook;
- +import org.eclipse.mylyn.wikitext.core.util.FormattingXMLStreamWriter;
- +import org.eclipse.mylyn.wikitext.core.util.XmlStreamWriter;
- +import org.eclipse.mylyn.wikitext.core.util.anttask.MarkupToDocbookTask;
- +
- +/**
- + * A builder that can emit <a href="http://www.docbook.org/">Docbook</a>
- + *
- + * @author David Green
- + * @author Peter Friese bug 273355 Support image scaling for Textile -> DocBook
- + * @see MarkupToDocbook
- + * @see MarkupToDocbookTask
- + * @see DitaBookMapDocumentBuilder
- + * @since 1.0
- + */
- +public class DocBookDocumentBuilder extends AbstractXmlDocumentBuilder {
- +
- + private static final Pattern PERCENTAGE = Pattern.compile("(\\d+)%"); //$NON-NLS-1$
- +
- + private static final Pattern CSS_CLASS_INLINE = Pattern.compile("(^|\\s+)inline(\\s+|$)"); //$NON-NLS-1$
- +
- + private static Set<Integer> entityReferenceToUnicode = new HashSet<Integer>();
- + static {
- + entityReferenceToUnicode.add(215);
- + entityReferenceToUnicode.add(8211);
- + entityReferenceToUnicode.add(8212);
- + entityReferenceToUnicode.add(8220);
- + entityReferenceToUnicode.add(8221);
- + entityReferenceToUnicode.add(8216);
- + entityReferenceToUnicode.add(8217);
- +
- + }
- +
- +// private String bookTitle;
- +
- + private String doctype = "<!DOCTYPE book PUBLIC \"-//OASIS//DTD DocBook XML V4.5//EN\" \"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd\">"; //$NON-NLS-1$
- +
- + private final Map<String, String> acronyms = new HashMap<String, String>();
- +
- + private int headingLevel = 0;
- +
- + private final Stack<BlockDescription> blockDescriptions = new Stack<BlockDescription>();
- +
- + private boolean automaticGlossary = true;
- +
- + public DocBookDocumentBuilder(Writer out) {
- + super(out);
- + }
- +
- + public DocBookDocumentBuilder(XmlStreamWriter writer) {
- + super(writer);
- + }
- +
- + protected XmlStreamWriter createFormattingXmlStreamWriter(Writer out) {
- + XmlStreamWriter writer = super.createXmlStreamWriter(out);
- + return new FormattingXMLStreamWriter(writer) {
- + @Override
- + protected boolean preserveWhitespace(String elementName) {
- + return elementName.equals("programlisting") || elementName.equals("code") || elementName.startsWith("literal"); //$NON-NLS-1$ //$NON-NLS-2$
- + }
- + };
- + }
- +
- + public String getDoctype() {
- + return doctype;
- + }
- +
- + public void setDoctype(String doctype) {
- + this.doctype = doctype;
- + }
- +
- +// public String getBookTitle() {
- +// return bookTitle;
- +// }
- +//
- +// public void setBookTitle(String bookTitle) {
- +// this.bookTitle = bookTitle;
- +// }
- +
- + @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 link(Attributes attributes, String href, final String text) {
- + link(attributes, href, new ContentEmitter() {
- + public void emit() {
- + writer.writeCharacters(text);
- + }
- + });
- + }
- +
- + private void link(Attributes attributes, String href, ContentEmitter emitter) {
- + ensureBlockElementsOpen();
- + 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
- + }
- + }
- +
- + private interface ContentEmitter {
- + public void emit();
- + }
- +
- + @Override
- + public void beginBlock(BlockType type, Attributes attributes) {
- + if (headingLevel == 0) {
- + beginHeading(1, new Attributes());
- + endHeading();
- + }
- +
- + String elementName;
- + String[] elementNames = null;
- + boolean allowTitle = false;
- + boolean closeElementsOnBlockStart = false;
- + BlockDescription previousBlock = null;
- + if (!blockDescriptions.isEmpty()) {
- + previousBlock = blockDescriptions.peek();
- + }
- +
- + switch (type) {
- + case BULLETED_LIST:
- + elementName = "itemizedlist"; //$NON-NLS-1$
- + break;
- + case NUMERIC_LIST:
- + elementName = "orderedlist"; //$NON-NLS-1$
- + break;
- + case DEFINITION_LIST:
- + elementName = "variablelist"; //$NON-NLS-1$
- +
- + // variablelist
- + // varlistentry+
- + // term+
- + // listitem
- + //
- + break;
- + case DEFINITION_TERM:
- +
- + BlockDescription blockDescription = findBlockDescription(BlockType.DEFINITION_LIST);
- + if (blockDescription.entrySize > 0) {
- + endBlockEntry(blockDescription);
- + }
- + openBlockEntry(blockDescription, new String[] { "varlistentry" }); //$NON-NLS-1$
- +
- + elementName = "term"; //$NON-NLS-1$
- + break;
- + case DEFINITION_ITEM:
- + elementName = "listitem"; //$NON-NLS-1$
- + elementNames = new String[] { "para" }; //$NON-NLS-1$
- + closeElementsOnBlockStart = true;
- + break;
- + case FOOTNOTE:
- + case PARAGRAPH:
- + elementName = "para"; //$NON-NLS-1$
- + break;
- + case CODE:
- + elementName = "programlisting"; //$NON-NLS-1$
- + break;
- + case PREFORMATTED:
- + elementName = "literallayout"; //$NON-NLS-1$
- + break;
- + case QUOTE:
- + elementName = "blockquote"; //$NON-NLS-1$
- + break;
- + case LIST_ITEM:
- + elementName = "listitem"; //$NON-NLS-1$
- + elementNames = new String[] { "para" }; //$NON-NLS-1$
- + closeElementsOnBlockStart = true;
- + break;
- + case TABLE:
- + elementName = "informaltable"; //$NON-NLS-1$
- + break;
- + case TABLE_CELL_HEADER:
- + elementName = "th"; //$NON-NLS-1$
- + break;
- + case TABLE_CELL_NORMAL:
- + elementName = "td"; //$NON-NLS-1$
- + break;
- + case TABLE_ROW:
- + elementName = "tr"; //$NON-NLS-1$
- + break;
- + case INFORMATION:
- + elementName = "important"; //$NON-NLS-1$
- + allowTitle = true;
- + break;
- + case NOTE:
- + elementName = "note"; //$NON-NLS-1$
- + allowTitle = true;
- + break;
- + case WARNING:
- + elementName = "warning"; //$NON-NLS-1$
- + allowTitle = true;
- + break;
- + case TIP:
- + elementName = "tip"; //$NON-NLS-1$
- + allowTitle = true;
- + break;
- + case PANEL:
- + elementName = "note"; // docbook has nothing better for 'note' //$NON-NLS-1$
- + allowTitle = true;
- + break;
- + case DIV:
- + elementName = null;
- + break;
- + default:
- + throw new IllegalStateException(type.name());
- + }
- +
- + int blockSize;
- + if (elementName != null) {
- + blockSize = 1;
- +
- + if (previousBlock != null && previousBlock.closeElementsOnBlockStart) {
- + endBlockEntry(previousBlock);
- + }
- +
- + writer.writeStartElement(elementName);
- + applyAttributes(attributes);
- +
- + if (elementNames != null) {
- + for (String name : elementNames) {
- + writer.writeStartElement(name);
- + }
- + }
- +
- + if (allowTitle && attributes.getTitle() != null) {
- + writer.writeStartElement("title"); //$NON-NLS-1$
- + writer.writeCharacters(attributes.getTitle());
- + writer.writeEndElement();
- + }
- + } else {
- + blockSize = 0;
- + }
- + blockDescriptions.push(new BlockDescription(type, blockSize, elementNames, closeElementsOnBlockStart));
- + }
- +
- + @Override
- + public void endBlock() {
- + final BlockDescription blockDescription = blockDescriptions.pop();
- + int size = blockDescription.size + blockDescription.entrySize;
- + for (int x = 0; x < size; ++x) {
- + writer.writeEndElement();
- + }
- + }
- +
- + private void endBlockEntry(BlockDescription blockDescription) {
- + for (int x = 0; x < blockDescription.entrySize; ++x) {
- + writer.writeEndElement();
- + }
- + blockDescription.entrySize = 0;
- + }
- +
- + private void openBlockEntry(BlockDescription blockDescription, String[] entry) {
- + for (String ent : entry) {
- + writer.writeStartElement(ent);
- + }
- + blockDescription.entrySize += entry.length;
- + }
- +
- + @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 endHeading() {
- + writer.writeEndElement(); // title
- + }
- +
- + @Override
- + public void beginDocument() {
- + baseInHead = false;
- +// writer.writeStartDocument();
- +// writer.writeDTD(doctype);
- +
- +// writer.writeStartElement("book"); //$NON-NLS-1$
- +// writer.writeStartElement("title"); //$NON-NLS-1$
- +// if (bookTitle != null) {
- +// writer.writeCharacters(bookTitle);
- +// }
- +// writer.writeEndElement();
- + }
- +
- + @Override
- + public void beginSpan(SpanType type, Attributes attributes) {
- + ensureBlockElementsOpen();
- + switch (type) {
- + case BOLD:
- + case STRONG:
- + writer.writeStartElement("emphasis"); //$NON-NLS-1$
- + writer.writeAttribute("role", "bold"); //$NON-NLS-1$ //$NON-NLS-2$
- + break;
- + case CITATION:
- + writer.writeStartElement("citation"); //$NON-NLS-1$
- + break;
- + case CODE:
- + writer.writeStartElement("code"); //$NON-NLS-1$
- + break;
- + case DELETED:
- + writer.writeStartElement("emphasis"); //$NON-NLS-1$
- + writer.writeAttribute("role", "del"); //$NON-NLS-1$ //$NON-NLS-2$
- + break;
- + case EMPHASIS:
- + writer.writeStartElement("emphasis"); //$NON-NLS-1$
- + break;
- + case INSERTED:
- + writer.writeStartElement("emphasis"); //$NON-NLS-1$
- + writer.writeAttribute("role", "ins"); //$NON-NLS-1$ //$NON-NLS-2$
- + break;
- + case UNDERLINED:
- + writer.writeStartElement("emphasis"); //$NON-NLS-1$
- + writer.writeAttribute("role", "underline"); //$NON-NLS-1$ //$NON-NLS-2$
- + break;
- + case ITALIC:
- + writer.writeStartElement("emphasis"); //$NON-NLS-1$
- + writer.writeAttribute("role", "italic"); //$NON-NLS-1$ //$NON-NLS-2$
- + break;
- + case QUOTE:
- + writer.writeStartElement("quote"); //$NON-NLS-1$
- + break;
- + case SPAN:
- + writer.writeStartElement("phrase"); //$NON-NLS-1$
- + break;
- + case SUBSCRIPT:
- + writer.writeStartElement("subscript"); //$NON-NLS-1$
- + break;
- + case SUPERSCRIPT:
- + writer.writeStartElement("superscript"); //$NON-NLS-1$
- + break;
- + case MONOSPACE:
- + writer.writeStartElement("literal"); //$NON-NLS-1$
- + break;
- + case LINK: {
- + LinkAttributes linkAttributes = (LinkAttributes) attributes;
- + String href = linkAttributes.getHref();
- + if (href.startsWith("#")) { //$NON-NLS-1$
- + writer.writeStartElement("link"); //$NON-NLS-1$
- + if (href.length() > 1) {
- + writer.writeAttribute("linkend", href.substring(1)); //$NON-NLS-1$
- + }
- + } else {
- + writer.writeStartElement("ulink"); //$NON-NLS-1$
- + writer.writeAttribute("url", href); //$NON-NLS-1$
- + }
- + }
- + break;
- + default:
- + Logger.getLogger(DocBookDocumentBuilder.class.getName()).warning("No docbook mapping for " + type); //$NON-NLS-1$
- + writer.writeStartElement("phrase"); //$NON-NLS-1$
- + break;
- + }
- + applyAttributes(attributes);
- + }
- +
- + private void applyAttributes(Attributes attributes) {
- + if (attributes.getId() != null) {
- + writer.writeAttribute("id", attributes.getId()); //$NON-NLS-1$
- + }
- + if (attributes.getLanguage() != null) {
- + writer.writeAttribute("language", attributes.getLanguage()); //$NON-NLS-1$
- + }
- + }
- +
- + @Override
- + public void endDocument() {
- + closeSections(0);
- +
- + writeGlossaryAppendix();
- +
- +// writer.writeEndElement(); // book
- + writer.writeEndDocument();
- +
- + acronyms.clear();
- + }
- +
- + private void closeSections(int toLevel) {
- + if (toLevel < 0) {
- + toLevel = 0;
- + }
- + while (headingLevel > toLevel) {
- + writer.writeEndElement();
- + --headingLevel;
- + }
- + }
- +
- + private void writeGlossaryAppendix() {
- + if (!acronyms.isEmpty() && automaticGlossary) {
- + writer.writeStartElement("appendix"); //$NON-NLS-1$
- + writer.writeAttribute("id", "glossary"); //$NON-NLS-1$ //$NON-NLS-2$
- + writer.writeStartElement("title"); //$NON-NLS-1$
- + writer.writeAttribute("id", "glossary-end"); //$NON-NLS-1$ //$NON-NLS-2$
- + writer.writeCharacters("Glossary"); //$NON-NLS-1$
- + writer.writeEndElement(); // title
- + writer.writeStartElement("glosslist"); //$NON-NLS-1$
- +
- + for (Map.Entry<String, String> glossEntry : new TreeMap<String, String>(acronyms).entrySet()) {
- +
- + writer.writeStartElement("glossentry"); //$NON-NLS-1$
- +
- + writer.writeStartElement("glossterm"); //$NON-NLS-1$
- + writer.writeCharacters(glossEntry.getKey());
- + writer.writeEndElement(); // glossterm
- +
- + writer.writeStartElement("glossdef"); //$NON-NLS-1$
- + writer.writeStartElement("para"); //$NON-NLS-1$
- + writer.writeCharacters(glossEntry.getValue());
- + writer.writeEndElement(); // para
- + writer.writeEndElement(); // glossdef
- +
- + writer.writeEndElement(); // glossentry
- + }
- + writer.writeEndElement(); // glosslist
- + writer.writeEndElement(); // appendix
- + }
- + }
- +
- + @Override
- + public void endSpan() {
- + writer.writeEndElement();
- + }
- +
- + @Override
- + public void characters(String text) {
- + ensureBlockElementsOpen();
- + super.characters(text);
- + }
- +
- + @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");
- + }
- +
- + private void ensureBlockElementsOpen() {
- + if (!blockDescriptions.isEmpty()) {
- + BlockDescription blockDescription = blockDescriptions.peek();
- + if (blockDescription.entrySize == 0 && blockDescription.nestedElementNames != null) {
- + openBlockEntry(blockDescription, blockDescription.nestedElementNames);
- + }
- + }
- + }
- +
- + @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);
- + }
- +
- + @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);
- + }
- +
- + private void emitImage(Attributes attributes, String url, boolean inline) {
- + // see http://www.docbook.org/tdg/en/html/imagedata-x.html
- + 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) {
- + String width = null;
- + String depth = null;
- + Iterator<CssRule> ruleIterator = new CssParser().createRuleIterator(cssStyle);
- + while (ruleIterator.hasNext()) {
- + CssRule rule = ruleIterator.next();
- + if ("width".equals(rule.name)) { //$NON-NLS-1$
- + width = rule.value;
- + } else if ("height".equals(rule.name)) { //$NON-NLS-1$
- + depth = rule.value;
- + }
- + }
- + if (width != null) {
- + Matcher matcher = PERCENTAGE.matcher(width);
- + if (matcher.matches()) {
- + writer.writeAttribute("scale", matcher.group(1)); //$NON-NLS-1$
- + } else {
- + writer.writeAttribute("width", width); //$NON-NLS-1$
- + if (depth != null) {
- + writer.writeAttribute("depth", depth); //$NON-NLS-1$
- + }
- + }
- + }
- + }
- + writer.writeEndElement(); // imageobject
- + writer.writeEndElement(); // inlinemediaobject or mediaobject
- + }
- +
- + @Override
- + public void imageLink(Attributes linkAttributes, final Attributes imageAttributes, String href,
- + final String imageUrl) {
- + link(linkAttributes, href, new ContentEmitter() {
- + public void emit() {
- + emitImage(imageAttributes, imageUrl, true);
- + }
- + });
- + }
- +
- + @Override
- + public void lineBreak() {
- + ensureBlockElementsOpen();
- + // no equivalent in DocBook.
- + characters("\n"); //$NON-NLS-1$
- + }
- +
- + private BlockDescription findBlockDescription(BlockType type) {
- + for (int x = blockDescriptions.size() - 1; x >= 0; --x) {
- + BlockDescription blockDescription = blockDescriptions.get(x);
- + if (blockDescription.type == type) {
- + return blockDescription;
- + }
- + }
- + return null;
- + }
- +
- + private static class BlockDescription {
- + BlockType type;
- +
- + int size;
- +
- + int entrySize; // the size of an entry, if it is open, otherwise 0
- +
- + final String[] nestedElementNames;
- +
- + final boolean closeElementsOnBlockStart;
- +
- + public BlockDescription(DocumentBuilder.BlockType type, int size, String[] nestedElementNames, boolean closeElementsOnBlockStart) {
- + this.size = size;
- + this.entrySize = nestedElementNames == null ? 0 : nestedElementNames.length;
- + this.type = type;
- + this.nestedElementNames = nestedElementNames;
- + this.closeElementsOnBlockStart = closeElementsOnBlockStart;
- + }
- + }
- +
- + /**
- + * Indicate if this builder should generate an automatic glossary if acronyms are used. When the automatic glossary
- + * is enabled and acronyms are used in the document, then an <code>appendix</code> with title 'Glossary' is added to
- + * the document, with a <code>glosslist</code> generated for all of the acronyms that appear in the document. The
- + * default is true.
- + */
- + public boolean isAutomaticGlossary() {
- + return automaticGlossary;
- + }
- +
- + /**
- + * Indicate if this builder should generate an automatic glossary if acronyms are used. When the automatic glossary
- + * is enabled and acronyms are used in the document, then an <code>appendix</code> with title 'Glossary' is added to
- + * the document, with a <code>glosslist</code> generated for all of the acronyms that appear in the document. The
- + * default is true.
- + */
- + public void setAutomaticGlossary(boolean automaticGlossary) {
- + this.automaticGlossary = automaticGlossary;
- + }
- +
- +}
- Index: src/main/java/org/apache/servicemix/docs/confluence/ConfluenceConverter.java
- ===================================================================
- --- src/main/java/org/apache/servicemix/docs/confluence/ConfluenceConverter.java (revision 954753)
- +++ src/main/java/org/apache/servicemix/docs/confluence/ConfluenceConverter.java (working copy)
- @@ -%ld,%ld +%ld,%ld @@
- import java.io.PrintStream;
- import java.io.PrintWriter;
- import java.io.Reader;
- +import java.io.StringWriter;
- import java.io.Writer;
- import java.util.HashMap;
- import java.util.LinkedHashMap;
- @@ -%ld,%ld +%ld,%ld @@
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- +import org.eclipse.mylyn.wikitext.core.parser.MarkupParser;
- +import org.eclipse.mylyn.wikitext.core.parser.markup.MarkupLanguage;
- +
- /**
- * Represents a document in Confluence wiki markup
- */
- @@ -%ld,%ld +%ld,%ld @@
- }
- public void convert() throws IOException {
- - String line = null;
- + MarkupLanguage markupLanguage = new ConfluenceLanguage();
- + StringWriter writer = new StringWriter();
- + DocBookDocumentBuilder builder = new DocBookDocumentBuilder(writer);
- + MarkupParser parser = new MarkupParser();
- + parser.setMarkupLanguage(markupLanguage);
- + parser.setBuilder(builder);
- + parser.parse(reader);
- + writer.flush();
- + String out = writer.toString();
- +// int beg = out.indexOf("<chapter");
- +// int end = out.indexOf("</book>");
- +// out = out.substring(beg, end);
- + this.writer.write(out);
- - while ((line = reader.readLine()) != null) {
- - String trimmed = line.trim();
- - if (CHAPTER_OR_SECTION.matcher(line).matches()) {
- - writeChapterOrSection(line);
- - } else if (trimmed.startsWith("!") && trimmed.endsWith("!")) {
- - writeImage(line);
- - } else if (trimmed.startsWith("||") && trimmed.endsWith("||")) {
- - writeTableHeader(line);
- - } else if (trimmed.startsWith("|") && trimmed.endsWith("|")) {
- - writeTableBody(line);
- - } else if (line.startsWith("*")) {
- - writeBulletList(line);
- - } else if (line.startsWith("#")) {
- - writeNumberedList(line);
- - } else if (line.startsWith("-")) {
- - writeGlossaryList(line);
- - } else if (trimmed.startsWith("{code")) {
- - writeProgramListing(line);
- - } else {
- - writePara(line);
- - }
- - }
- +// String line = null;
- +// while ((line = reader.readLine()) != null) {
- +// String trimmed = line.trim();
- +// if (CHAPTER_OR_SECTION.matcher(line).matches()) {
- +// writeChapterOrSection(line);
- +// } else if (trimmed.startsWith("!") && trimmed.endsWith("!")) {
- +// writeImage(line);
- +// } else if (trimmed.startsWith("||") && trimmed.endsWith("||")) {
- +// writeTableHeader(line);
- +// } else if (trimmed.startsWith("|") && trimmed.endsWith("|")) {
- +// writeTableBody(line);
- +// } else if (line.startsWith("* ")) {
- +// writeBulletList(line);
- +// } else if (line.startsWith("# ")) {
- +// writeNumberedList(line);
- +// } else if (line.startsWith("- ")) {
- +// writeGlossaryList(line);
- +// } else if (trimmed.startsWith("{code")) {
- +// writeProgramListing(line);
- +// } else if (trimmed.startsWith("{tip")) {
- +// writeTip(line);
- +// } else if (trimmed.startsWith("{warning")) {
- +// writeWarning(line);
- +// } else if (trimmed.startsWith("{info")) {
- +// writeInfo(line);
- +// } else {
- +// writePara(line);
- +// }
- +// }
- // let's close everying that was opened
- - closeElements();
- +// closeElements();
- }
- @@ -%ld,%ld +%ld,%ld @@
- writeRaw("]]></programlisting>");
- }
- + private void writeTip(String line) throws IOException {
- + writeRaw("<programlisting><![CDATA[");
- + while ((line = reader.readLine()) != null && !line.equals("{tip}")) {
- + writeRaw(line, "");
- + }
- + writeRaw("]]></programlisting>");
- + }
- +
- + private void writeWarning(String line) throws IOException {
- + writeRaw("<programlisting><![CDATA[");
- + while ((line = reader.readLine()) != null && !line.equals("{warning}")) {
- + writeRaw(line, "");
- + }
- + writeRaw("]]></programlisting>");
- + }
- +
- + private void writeInfo(String line) throws IOException {
- + writeRaw("<programlisting><![CDATA[");
- + while ((line = reader.readLine()) != null && !line.equals("{info}")) {
- + writeRaw(line, "");
- + }
- + writeRaw("]]></programlisting>");
- + }
- +
- private void writePara(String line) {
- // a <para/> shouldn't
- ensureClosed("informaltable");
- @@ -%ld,%ld +%ld,%ld @@
- replacements.put("&", "&");
- replacements.put("<", "<");
- replacements.put(">", ">");
- - replacements.put("\\{\\{(.*)\\}\\}", "<code>$1</code>");
- + replacements.put("\\{\\{([^\\}]*)\\}\\}", "<code>$1</code>");
- replacements.put("\\*([^*]*)\\*", "<emphasis role=\\\"bold\\\">$1</emphasis>");
- + replacements.put("_([^_]*)_", "<emphasis role=\\\"italics\\\">$1</emphasis>");
- replacements.put("([^\\\\])\\[([^\\|\\]]*)\\|([^\\]]*)\\]", "$1<ulink url=\\\"$3\\\">$2</ulink>");
- replacements.put("^\\[([^\\|\\]]*)\\|([^\\]]*)\\]", "<ulink url=\\\"$2\\\">$1</ulink>");
- Index: pom.xml
- ===================================================================
- --- pom.xml (revision 954751)
- +++ pom.xml (working copy)
- @@ -%ld,%ld +%ld,%ld @@
- <version>${junit.version}</version>
- <scope>test</scope>
- </dependency>
- + <dependency>
- + <groupId>org.eclipse.mylyn.wikitext</groupId>
- + <artifactId>confluence.core</artifactId>
- + <version>1.3.0.v20100608-0100-e3x</version>
- + </dependency>
- + <dependency>
- + <groupId>org.eclipse.mylyn.wikitext</groupId>
- + <artifactId>core</artifactId>
- + <version>1.3.0.v20100608-0100-e3x</version>
- + </dependency>
- </dependencies>
- </project>