Search in sources :

Example 1 with MediaWikiLanguage

use of org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage in project mylyn.docs by eclipse.

the class XslfoDocumentBuilderIntegrationTest method testXslFoNoMissingBlock_bug304013.

// test for bug 304013: [wikitext-to-xslfo] Missing </block> in <static-content>
public void testXslFoNoMissingBlock_bug304013() {
    documentBuilder.getConfiguration().setPageNumbering(true);
    documentBuilder.getConfiguration().setTitle("Title");
    parser.setMarkupLanguage(new MediaWikiLanguage());
    parser.parse("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n{{NonExistantTemplate}}\n" + "\n" + "= H1 =\n" + "\n" + "== H2 ==\n" + "\n" + "some text");
    assertFalse(Pattern.compile("<static-content[^>]*></static-content>").matcher(out.toString()).find());
}
Also used : MediaWikiLanguage(org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage)

Example 2 with MediaWikiLanguage

use of org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage 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)

Example 3 with MediaWikiLanguage

use of org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage in project mylyn.docs by eclipse.

the class XslfoDocumentBuilderIntegrationTest method testforTableSpan_bug336813.

public void testforTableSpan_bug336813() {
    final String markup = "{|\n|-\n" + "| Column 1 || Column 2 || Column 3\n" + "|-\n" + "| rowspan=\"2\"| A\n" + "| colspan=\"2\" | B\n" + "|-\n" + "| C <!-- column 1 occupied by cell A -->\n" + "| D \n" + "|-\n" + "| E\n" + "| rowspan=\"2\" colspan=\"2\" | F\n" + "|- \n" + "| G <!-- column 2+3 occupied by cell F -->\n" + "|- \n" + "| colspan=\"3\" | H\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 rowspan
    assertTrue(Pattern.compile("<table-cell number-rows-spanned=\"2\" padding-left=\"2pt\" padding-right=\"2pt\" padding-top=\"2pt\" padding-bottom=\"2pt\">").matcher(xslfo).find());
    // Test for colspan
    assertTrue(Pattern.compile("<table-cell number-columns-spanned=\"2\" padding-left=\"2pt\" padding-right=\"2pt\" padding-top=\"2pt\" padding-bottom=\"2pt\">").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)

Example 4 with MediaWikiLanguage

use of org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage in project mylyn.docs by eclipse.

the class XslfoDocumentBuilderIntegrationTest method testForXslFoBookmarks_bug336592.

public void testForXslFoBookmarks_bug336592() {
    final String markup = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n= Bookmark H1 =\n== Bookmark H2 ==\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();
    assertTrue(Pattern.compile("<bookmark-tree>\\s*<bookmark internal-destination=\"Bookmark_H1\">\\s*<bookmark-title>Bookmark H1</bookmark-title>\\s*<bookmark internal-destination=\"Bookmark_H2\">\\s*<bookmark-title>Bookmark H2</bookmark-title>\\s*</bookmark>\\s*</bookmark>\\s*</bookmark-tree>").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)

Example 5 with MediaWikiLanguage

use of org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage in project mylyn.docs by eclipse.

the class WikiToDocTask method execute.

@Override
public void execute() throws ConfigurationException {
    if (dest == null) {
        // $NON-NLS-1$
        throw new ConfigurationException(Messages.getString("WikiToDocTask_specify_dest"));
    }
    if (wikiBaseUrl == null) {
        // $NON-NLS-1$
        throw new ConfigurationException(Messages.getString("WikiToDocTask_specify_wikiBaseUrl"));
    }
    if (paths.isEmpty()) {
        // $NON-NLS-1$
        throw new ConfigurationException(Messages.getString("WikiToDocTask_specify_paths"));
    }
    if (getInternalLinkPattern() == null) {
        setInternalLinkPattern(computeDefaultInternalLinkPattern());
    }
    Set<String> pathNames = new HashSet<String>();
    for (Path path : paths) {
        if (path.name == null) {
            // $NON-NLS-1$
            throw new ConfigurationException(Messages.getString("WikiToDocTask_path_must_have_name"));
        }
        if (path.name != null) {
            if (!pathNames.add(path.name)) {
                throw new ConfigurationException(MessageFormat.format(Messages.getString("WikiToDocTask_path_name_must_be_unique"), // $NON-NLS-1$
                path.name));
            }
        }
        if (!path.includeInUnifiedToc && path.getTocParentName() != null) {
            throw new ConfigurationException(MessageFormat.format(Messages.getString("WikiToDocTask_tocParentName_not_in_unified_toc"), // $NON-NLS-1$
            path.name));
        }
    }
    if (generateUnifiedToc) {
        for (Path path : paths) {
            if (path.getTocParentName() != null) {
                if (!pathNames.contains(path.getTocParentName())) {
                    throw new ConfigurationException(MessageFormat.format(Messages.getString("WikiToDocTask_unknown_tocParentName"), // $NON-NLS-1$
                    path.getTocParentName()));
                }
            }
        }
    }
    MediaWikiLanguage markupLanguage = (MediaWikiLanguage) createMarkupLanguage();
    WikiTemplateResolver templateResolver = new WikiTemplateResolver();
    templateResolver.setWikiBaseUrl(wikiBaseUrl);
    markupLanguage.getTemplateProviders().add(templateResolver);
    markupLanguage.setTemplateExcludes(templateExcludes);
    for (Stylesheet stylesheet : stylesheets) {
        if (stylesheet.url == null && stylesheet.file == null) {
            // $NON-NLS-1$
            throw new BuildException(Messages.getString("WikiToDocTask_stylesheet_file_or_url"));
        }
        if (stylesheet.url != null && stylesheet.file != null) {
            // $NON-NLS-1$
            throw new BuildException(Messages.getString("WikiToDocTask_stylesheet_not_both"));
        }
        if (stylesheet.file != null) {
            if (!stylesheet.file.exists()) {
                throw new BuildException(// $NON-NLS-1$
                MessageFormat.format(// $NON-NLS-1$
                Messages.getString("WikiToDocTask_stylesheet_file_not_exist"), stylesheet.file));
            }
            if (!stylesheet.file.isFile()) {
                throw new BuildException(// $NON-NLS-1$
                MessageFormat.format(// $NON-NLS-1$
                Messages.getString("WikiToDocTask_stylesheet_file_not_file"), stylesheet.file));
            }
            if (!stylesheet.file.canRead()) {
                throw new BuildException(MessageFormat.format(Messages.getString("WikiToDocTask_stylesheet_file_cannot_read"), // $NON-NLS-1$
                stylesheet.file));
            }
        }
    }
    if (!dest.exists()) {
        if (!dest.mkdirs()) {
            throw new BuildException(// $NON-NLS-1$
            MessageFormat.format("Cannot create dest folder: {0}", dest.getAbsolutePath()));
        }
    }
    if (tocFile == null) {
        // $NON-NLS-1$
        tocFile = new File(dest, "toc.xml");
    }
    Map<String, String> pathNameToContent = new HashMap<String, String>();
    Map<String, SplitOutlineItem> pathNameToOutline = new HashMap<String, SplitOutlineItem>();
    for (Path path : paths) {
        getProject().log(// $NON-NLS-1$
        MessageFormat.format(Messages.getString("WikiToDocTask_fetching_content_for_page"), path.name), Project.MSG_VERBOSE);
        URL pathUrl = computeRawUrl(path.name);
        try {
            Reader input = createInputReader(pathUrl);
            try {
                String content = readFully(input);
                content = preprocessMarkup(path, content);
                pathNameToContent.put(path.name, content);
                final File targetFile = computeHtmlOutputFile(path);
                SplitOutlineItem outline = computeOutline(path, markupLanguage, targetFile, content);
                outline.setResourcePath(targetFile.getAbsolutePath());
                pathNameToOutline.put(path.name, outline);
            } finally {
                input.close();
            }
        } catch (final IOException e) {
            // $NON-NLS-1$
            final String message = MessageFormat.format("Cannot read from {0}: {1}", pathUrl, e.getMessage());
            throw new BuildException(message, e);
        }
    }
    for (Path path : paths) {
        // $NON-NLS-1$
        getProject().log(// $NON-NLS-1$
        MessageFormat.format(Messages.getString("WikiToDocTask_processing_page"), path.name), Project.MSG_DEBUG);
        String markupContent = pathNameToContent.get(path.name);
        if (isValidate()) {
            performValidation(markupLanguage, path, markupContent);
        }
        Set<String> imageFilenames = null;
        if (!fetchImages) {
            // $NON-NLS-1$
            getProject().log(Messages.getString("WikiToDocTask_skipping_images"), Project.MSG_WARN);
        } else {
            imageFilenames = fetchImages(markupLanguage, path);
        }
        markupToDoc(markupLanguage, path, markupContent, pathNameToOutline, imageFilenames);
        if (path.isGenerateToc()) {
            createToc(path, pathNameToOutline.get(path.name));
        }
    }
    if (generateUnifiedToc) {
        createToc(paths, pathNameToOutline);
    }
}
Also used : HashMap(java.util.HashMap) WikiTemplateResolver(org.eclipse.mylyn.wikitext.mediawiki.WikiTemplateResolver) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) SplitOutlineItem(org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem) IOException(java.io.IOException) URL(java.net.URL) MediaWikiLanguage(org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

MediaWikiLanguage (org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage)17 OutlineItem (org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)9 OutlineParser (org.eclipse.mylyn.wikitext.parser.outline.OutlineParser)9 AbstractMarkupGenerationTest (org.eclipse.mylyn.wikitext.toolkit.AbstractMarkupGenerationTest)3 Test (org.junit.Test)3 File (java.io.File)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 BuildException (org.apache.tools.ant.BuildException)2 MarkupLanguage (org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage)2 SplitOutlineItem (org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem)2 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Reader (java.io.Reader)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1