Search in sources :

Example 1 with OutlineParser

use of org.eclipse.mylyn.wikitext.parser.outline.OutlineParser in project mylyn.docs by eclipse.

the class MarkupToDitaTask method processFile.

private void processFile(MarkupLanguage markupLanguage, final File baseDir, final File source) throws BuildException {
    // $NON-NLS-1$
    log(MessageFormat.format(Messages.getString("MarkupToDitaTask.8"), source), Project.MSG_VERBOSE);
    String markupContent = null;
    String name = source.getName();
    if (name.lastIndexOf('.') != -1) {
        name = name.substring(0, name.lastIndexOf('.'));
    }
    // $NON-NLS-1$
    File outputFile = new File(source.getParentFile(), filenameFormat.replace("$1", name));
    if (!outputFile.exists() || overwrite || outputFile.lastModified() < source.lastModified()) {
        if (markupContent == null) {
            markupContent = readFully(source);
        }
        performValidation(source, markupContent);
        OutlineItem outline = new OutlineParser(markupLanguage).parse(markupContent);
        Writer writer;
        try {
            // $NON-NLS-1$
            writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(outputFile)), "utf-8");
        } catch (Exception e) {
            throw new BuildException(// $NON-NLS-1$
            MessageFormat.format(// $NON-NLS-1$
            Messages.getString("MarkupToDitaTask.11"), // $NON-NLS-1$
            outputFile, e.getMessage()), e);
        }
        try {
            if (topicStrategy == BreakStrategy.NONE) {
                DitaTopicDocumentBuilder builder = new DitaTopicDocumentBuilder(new DefaultXmlStreamWriter(writer), formatting);
                builder.setRootTopicTitle(bookTitle);
                MarkupParser parser = new MarkupParser();
                parser.setMarkupLanguage(markupLanguage);
                parser.setBuilder(builder);
                if (topicDoctype != null) {
                    builder.setDoctype(topicDoctype);
                }
                builder.setFilename(outputFile.getName());
                builder.setOutline(outline);
                parser.parse(markupContent);
            } else {
                DitaBookMapDocumentBuilder builder = new DitaBookMapDocumentBuilder(formatting ? new FormattingXMLStreamWriter(new DefaultXmlStreamWriter(writer)) : new DefaultXmlStreamWriter(writer));
                try {
                    builder.setFormattingDependencies(formatting);
                    MarkupParser parser = new MarkupParser();
                    parser.setMarkupLanguage(markupLanguage);
                    parser.setBuilder(builder);
                    builder.setBookTitle(bookTitle == null ? name : bookTitle);
                    if (doctype != null) {
                        builder.setDoctype(doctype);
                    }
                    if (topicDoctype != null) {
                        builder.setTopicDoctype(topicDoctype);
                    }
                    builder.setTargetFile(outputFile);
                    builder.setTopicFolder(topicFolder);
                    builder.setOutline(outline);
                    switch(topicStrategy) {
                        case FIRST:
                            if (!outline.getChildren().isEmpty()) {
                                builder.setTopicBreakLevel(outline.getChildren().get(0).getLevel());
                            } else {
                                builder.setTopicBreakLevel(1);
                            }
                            break;
                        case LEVEL1:
                            builder.setTopicBreakLevel(1);
                            break;
                    }
                    parser.parse(markupContent);
                } finally {
                    try {
                        builder.close();
                    } catch (IOException e) {
                        throw new BuildException(MessageFormat.format(// $NON-NLS-1$
                        Messages.getString("MarkupToDitaTask.12"), // $NON-NLS-1$
                        outputFile, e.getMessage()), e);
                    }
                }
            }
        } finally {
            try {
                writer.close();
            } catch (Exception e) {
                throw new BuildException(MessageFormat.format(// $NON-NLS-1$
                Messages.getString("MarkupToDitaTask.12"), // $NON-NLS-1$
                outputFile, e.getMessage()), e);
            }
        }
    }
}
Also used : DitaBookMapDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.DitaBookMapDocumentBuilder) FormattingXMLStreamWriter(org.eclipse.mylyn.wikitext.util.FormattingXMLStreamWriter) DitaTopicDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.DitaTopicDocumentBuilder) DefaultXmlStreamWriter(org.eclipse.mylyn.wikitext.util.DefaultXmlStreamWriter) IOException(java.io.IOException) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem) OutlineParser(org.eclipse.mylyn.wikitext.parser.outline.OutlineParser) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) FormattingXMLStreamWriter(org.eclipse.mylyn.wikitext.util.FormattingXMLStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) DefaultXmlStreamWriter(org.eclipse.mylyn.wikitext.util.DefaultXmlStreamWriter) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Example 2 with OutlineParser

use of org.eclipse.mylyn.wikitext.parser.outline.OutlineParser in project mylyn.docs by eclipse.

the class WikiTextContextStructureBridge method getOutline.

private OutlineItem getOutline(IFile file) {
    // FIXME: is editor integration the way to go?? we probably need some kind of core model
    IEditorPart editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (editorPart != null) {
        OutlineItem outline = (OutlineItem) editorPart.getAdapter(OutlineItem.class);
        if (outline != null) {
            return outline;
        }
    }
    MarkupLanguage markupLanguage = WikiText.getMarkupLanguageForFilename(file.getName());
    if (markupLanguage != null) {
        OutlineParser parser = new OutlineParser(markupLanguage);
        try {
            String contents = getContents(file);
            OutlineItem outline = parser.parse(contents);
            outline.setResourcePath(file.getFullPath().toString());
            return outline;
        } catch (Exception e) {
            // ignore
            return null;
        }
    }
    return null;
}
Also used : OutlineParser(org.eclipse.mylyn.wikitext.parser.outline.OutlineParser) IEditorPart(org.eclipse.ui.IEditorPart) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) CoreException(org.eclipse.core.runtime.CoreException) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 3 with OutlineParser

use of org.eclipse.mylyn.wikitext.parser.outline.OutlineParser in project mylyn.docs by eclipse.

the class OutlineItemTest method testGetSectionLength.

public void testGetSectionLength() {
    OutlineParser outlineParser = new OutlineParser(new TextileLanguage());
    String markup = "h1. First Header\n\nh2. First Header First Child\n\nh1. Third Header\n";
    OutlineItem outline = outlineParser.parse(markup);
    OutlineItem firstHeader = outline.getChildren().get(0);
    OutlineItem secondHeader = outline.getChildren().get(1);
    OutlineItem firstHeaderFirstChild = firstHeader.getChildren().get(0);
    assertEquals(markup.length(), outline.getSectionLength());
    assertEquals(48, firstHeader.getSectionLength());
    assertEquals(17, secondHeader.getSectionLength());
    assertEquals(30, firstHeaderFirstChild.getSectionLength());
}
Also used : TextileLanguage(org.eclipse.mylyn.wikitext.textile.TextileLanguage) OutlineParser(org.eclipse.mylyn.wikitext.parser.outline.OutlineParser) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 4 with OutlineParser

use of org.eclipse.mylyn.wikitext.parser.outline.OutlineParser in project mylyn.docs by eclipse.

the class OutlineItemTest method testContains.

public void testContains() {
    OutlineParser outlineParser = new OutlineParser(new TextileLanguage());
    OutlineItem outline = outlineParser.parse("h1. First Header\n\nh2. First Header First Child\n\nh1. Third Header\n");
    OutlineItem firstHeader = outline.getChildren().get(0);
    OutlineItem secondHeader = outline.getChildren().get(1);
    OutlineItem firstHeaderFirstChild = firstHeader.getChildren().get(0);
    assertTrue(outline.contains(firstHeader));
    assertTrue(outline.contains(secondHeader));
    assertTrue(firstHeader.contains(firstHeader));
    assertTrue(secondHeader.contains(secondHeader));
    assertFalse(firstHeader.contains(secondHeader));
    assertFalse(secondHeader.contains(firstHeader));
    assertFalse(firstHeaderFirstChild.contains(firstHeader));
    assertTrue(firstHeader.contains(firstHeaderFirstChild));
}
Also used : TextileLanguage(org.eclipse.mylyn.wikitext.textile.TextileLanguage) OutlineParser(org.eclipse.mylyn.wikitext.parser.outline.OutlineParser) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 5 with OutlineParser

use of org.eclipse.mylyn.wikitext.parser.outline.OutlineParser in project mylyn.docs by eclipse.

the class XslfoDocumentBuilderIntegrationTest method testforTableCSSAttributes_bug336813.

public void testforTableCSSAttributes_bug336813() {
    final String markup = "{| style=\"border-style: solid; border-color: #000; border-width: 1px;\"\n" + "|-\n" + "! header 1\n" + "! header 2\n" + "! header 3\n" + "|-\n" + "| row 1, cell 1\n" + "| row 1, cell 2\n" + "| row 1, cell 3\n" + "|- style=\"border-style: solid; border-color: #000; border-width: 1px;\" \n" + "| row 2, cell 1\n" + "| row 2, cell 2\n" + "| style=\"border-style: solid; border-color: #000; border-width: 1px;\" | row 2, cell 3\n" + "|}";
    documentBuilder.getConfiguration().setPageNumbering(true);
    documentBuilder.getConfiguration().setTitle("Title");
    OutlineItem op = new OutlineParser(new MediaWikiLanguage()).parse(markup);
    documentBuilder.setOutline(op);
    parser.setMarkupLanguage(new MediaWikiLanguage());
    parser.parse(markup, true);
    final String xslfo = out.toString();
    // Test for border attributes in table
    assertTrue(Pattern.compile("<table-body border-color=\"#000\" border-style=\"solid\" border-width=\"1px\">").matcher(xslfo).find());
    // Test for border attributes in row
    assertTrue(Pattern.compile("<table-row border-color=\"#000\" border-style=\"solid\" border-width=\"1px\">").matcher(xslfo).find());
    // Test for border attributes in cell
    assertTrue(Pattern.compile("<block font-size=\"10.0pt\" border-color=\"#000\" border-style=\"solid\" border-width=\"1px\">").matcher(xslfo).find());
}
Also used : OutlineParser(org.eclipse.mylyn.wikitext.parser.outline.OutlineParser) MediaWikiLanguage(org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Aggregations

OutlineParser (org.eclipse.mylyn.wikitext.parser.outline.OutlineParser)19 OutlineItem (org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)18 MediaWikiLanguage (org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage)9 TextileLanguage (org.eclipse.mylyn.wikitext.textile.TextileLanguage)3 BufferedOutputStream (java.io.BufferedOutputStream)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Writer (java.io.Writer)2 BuildException (org.apache.tools.ant.BuildException)2 MarkupParser (org.eclipse.mylyn.wikitext.parser.MarkupParser)2 IOException (java.io.IOException)1 LinkedHashSet (java.util.LinkedHashSet)1 CoreException (org.eclipse.core.runtime.CoreException)1 ConfluenceLanguage (org.eclipse.mylyn.wikitext.confluence.ConfluenceLanguage)1 DitaBookMapDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.DitaBookMapDocumentBuilder)1 DitaTopicDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.DitaTopicDocumentBuilder)1 XslfoDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.XslfoDocumentBuilder)1 MarkupLanguage (org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage)1 AbstractMarkupGenerationTest (org.eclipse.mylyn.wikitext.toolkit.AbstractMarkupGenerationTest)1