Search in sources :

Example 1 with Document

use of net.heartsome.xml.Document in project translationstudio8 by heartsome.

the class AutoConfiguration method run.

/**
	 * Run.
	 * @param input
	 *            the input
	 * @param out
	 *            the out
	 * @param catalogue
	 *            the catalogue
	 * @throws SAXException
	 *             the SAX exception
	 * @throws IOException
	 *             Signals that an I/O exception has occurred.
	 * @throws ParserConfigurationException
	 *             the parser configuration exception
	 */
public void run(String input, String out, String catalogue) throws SAXException, IOException, ParserConfigurationException {
    SAXBuilder builder = new SAXBuilder();
    builder.setEntityResolver(new Catalogue(catalogue));
    Document d = builder.build(input);
    Element r = d.getRootElement();
    segment = new Hashtable<String, String>();
    recurse(r);
    //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    Document doc = new Document(null, "ini-file", "-//HEARTSOME//Converters 2.0.0//EN", "configuration.dtd");
    Element root = doc.getRootElement();
    Enumeration<String> keys = segment.keys();
    while (keys.hasMoreElements()) {
        //$NON-NLS-1$
        Element e = new Element("tag", doc);
        String key = keys.nextElement();
        e.setText(key);
        //$NON-NLS-1$ //$NON-NLS-2$
        e.setAttribute("hard-break", "segment");
        root.addContent(e);
        //$NON-NLS-1$
        root.addContent("\n");
    }
    XMLOutputter outputter = new XMLOutputter();
    FileOutputStream output = new FileOutputStream(out);
    outputter.output(doc, output);
    output.close();
}
Also used : Catalogue(net.heartsome.xml.Catalogue) XMLOutputter(net.heartsome.xml.XMLOutputter) SAXBuilder(net.heartsome.xml.SAXBuilder) Element(net.heartsome.xml.Element) FileOutputStream(java.io.FileOutputStream) Document(net.heartsome.xml.Document)

Example 2 with Document

use of net.heartsome.xml.Document in project translationstudio8 by heartsome.

the class PluginHelpDialog method loadToc.

private void loadToc(TreeItem itemParent, String tocFile) throws Exception {
    File file = new File(tocFile);
    String basePath = "";
    if (file.exists()) {
        basePath = file.getParent();
    }
    SAXBuilder builder = new SAXBuilder();
    builder.setEntityResolver(new Catalogue(PluginUtil.getCataloguePath()));
    Document document = builder.build(tocFile);
    Element root = document.getRootElement();
    recurseTree(root, itemParent, basePath);
    String url = root.getAttributeValue("url");
    if (!url.equals("")) {
        File f = new File(url);
        if (!f.exists()) {
            url = basePath + "/" + url;
        }
        hashTable.put(itemParent, new File(url).toURI().toURL().toString());
    }
}
Also used : Catalogue(net.heartsome.xml.Catalogue) SAXBuilder(net.heartsome.xml.SAXBuilder) Element(net.heartsome.xml.Element) Document(net.heartsome.xml.Document) File(java.io.File)

Example 3 with Document

use of net.heartsome.xml.Document in project translationstudio8 by heartsome.

the class PluginHelpDialog method searchFile.

private void searchFile(String file, String text, boolean sensitive) throws SAXException, IOException, ParserConfigurationException {
    SAXBuilder builder = new SAXBuilder();
    //$NON-NLS-1$
    builder.setEntityResolver(new Catalogue(PluginUtil.getCataloguePath()));
    if (!file.startsWith("file:")) {
        //$NON-NLS-1$
        if (!file.startsWith("http:")) {
            //$NON-NLS-1$
            File f = new File(file);
            file = f.toURI().toURL().toString();
        }
    }
    URL url = new URL(file);
    Document doc = builder.build(url);
    Element root = doc.getRootElement();
    searchElement(root, file, text, sensitive);
}
Also used : Catalogue(net.heartsome.xml.Catalogue) SAXBuilder(net.heartsome.xml.SAXBuilder) Element(net.heartsome.xml.Element) Document(net.heartsome.xml.Document) File(java.io.File) URL(java.net.URL)

Example 4 with Document

use of net.heartsome.xml.Document in project translationstudio8 by heartsome.

the class TBXTemplateUtil method getTemplateFiles.

public static Vector<String> getTemplateFiles(String catalogueFile, String templatePath, boolean needArray) {
    Vector<String> result = new Vector<String>();
    File templateDir = new File(templatePath);
    String[] contents = templateDir.list();
    if (contents != null) {
        for (int i = 0; i < contents.length; i++) {
            File currentFile = new File(templateDir.getAbsolutePath(), contents[i]);
            if (currentFile.isFile()) {
                try {
                    SAXBuilder builder = new SAXBuilder();
                    if (!catalogueFile.equals("")) {
                        //$NON-NLS-1$
                        Catalogue cat = new Catalogue(catalogueFile);
                        builder.setEntityResolver(cat);
                    }
                    Document doc = builder.build(currentFile.getAbsolutePath());
                    Element tbxXCS = doc.getRootElement();
                    //$NON-NLS-1$
                    Element datCatSet = tbxXCS.getChild("datCatSet");
                    if (datCatSet != null) {
                        result.add(currentFile.getName());
                    }
                } catch (Exception e) {
                    LOGGER.error("", e);
                }
            }
        }
    }
    return result;
}
Also used : Catalogue(net.heartsome.xml.Catalogue) SAXBuilder(net.heartsome.xml.SAXBuilder) Element(net.heartsome.xml.Element) Document(net.heartsome.xml.Document) Vector(java.util.Vector) File(java.io.File) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 5 with Document

use of net.heartsome.xml.Document in project translationstudio8 by heartsome.

the class PluginHelpDialog method loadTree.

private void loadTree(String helpFile) {
    try {
        tree.removeAll();
        hashTable.clear();
        File file = new File(helpFile);
        String basePath = "";
        if (!file.isAbsolute()) {
            helpFile = file.getCanonicalPath();
            file = new File(helpFile);
        }
        basePath = file.getParent();
        currentFilePath = helpFile;
        SAXBuilder builder = new SAXBuilder();
        builder.setEntityResolver(new Catalogue(PluginUtil.getCataloguePath()));
        Document document = builder.build(helpFile);
        Element root = document.getRootElement();
        TreeItem item = new TreeItem(tree, SWT.NONE);
        item.setText(root.getAttributeValue("title"));
        getShell().setText(root.getAttributeValue("title"));
        recurseTree(root, item, basePath);
        item.setExpanded(true);
        String url = root.getAttributeValue("url");
        if (!url.equals("")) {
            File f = new File(url);
            if (!f.exists()) {
                url = basePath + "/" + url;
            }
            browser.setUrl(new File(url).toURI().toURL().toString());
            hashTable.put(item, url);
        }
    } catch (Exception e) {
    }
}
Also used : Catalogue(net.heartsome.xml.Catalogue) SAXBuilder(net.heartsome.xml.SAXBuilder) TreeItem(org.eclipse.swt.widgets.TreeItem) Element(net.heartsome.xml.Element) Document(net.heartsome.xml.Document) File(java.io.File) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

Catalogue (net.heartsome.xml.Catalogue)5 Document (net.heartsome.xml.Document)5 Element (net.heartsome.xml.Element)5 SAXBuilder (net.heartsome.xml.SAXBuilder)5 File (java.io.File)4 IOException (java.io.IOException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 SAXException (org.xml.sax.SAXException)2 FileOutputStream (java.io.FileOutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URL (java.net.URL)1 Vector (java.util.Vector)1 XMLOutputter (net.heartsome.xml.XMLOutputter)1 TreeItem (org.eclipse.swt.widgets.TreeItem)1