Search in sources :

Example 6 with Catalogue

use of net.heartsome.xml.Catalogue 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)

Example 7 with Catalogue

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

the class TBXTemplateUtil method loadTemplate.

private void loadTemplate(String catalogueFile) throws SAXException, ParserConfigurationException, IOException {
    SAXBuilder builder = new SAXBuilder();
    if (!catalogueFile.equals("")) {
        //$NON-NLS-1$
        Catalogue cat = new Catalogue(catalogueFile);
        builder.setEntityResolver(cat);
        builder.setValidating(true);
    }
    //$NON-NLS-1$
    File templateFile = new File(templatePath, templateFileName);
    document = builder.build(templateFile.getAbsolutePath());
    Element tbxXCS = document.getRootElement();
    //$NON-NLS-1$
    Element datCatSet = tbxXCS.getChild("datCatSet");
    if (datCatSet != null) {
        List<Element> specs = datCatSet.getChildren();
        Iterator<Element> specsIt = specs.iterator();
        while (specsIt.hasNext()) {
            Element spec = specsIt.next();
            //$NON-NLS-1$
            Element contents = spec.getChild("contents");
            if (contents != null) {
                items.add(spec);
            }
        }
    }
}
Also used : Catalogue(net.heartsome.xml.Catalogue) SAXBuilder(net.heartsome.xml.SAXBuilder) Element(net.heartsome.xml.Element) File(java.io.File)

Example 8 with Catalogue

use of net.heartsome.xml.Catalogue 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 9 with Catalogue

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

the class Xliff2Resx method openXml.

/**
	 * Open xml.
	 * @param filename
	 *            the filename
	 * @param catalogue
	 *            the catalogue
	 * @return the document
	 * @throws Exception
	 *             the exception
	 */
private static Document openXml(String filename, String catalogue) throws Exception {
    SAXBuilder builder = new SAXBuilder();
    builder.setEntityResolver(new Catalogue(catalogue));
    return builder.build(filename);
}
Also used : Catalogue(net.heartsome.xml.Catalogue) SAXBuilder(net.heartsome.xml.SAXBuilder)

Aggregations

Catalogue (net.heartsome.xml.Catalogue)9 SAXBuilder (net.heartsome.xml.SAXBuilder)8 Element (net.heartsome.xml.Element)7 File (java.io.File)5 Document (net.heartsome.xml.Document)5 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 SAXParserFactory (javax.xml.parsers.SAXParserFactory)1 Transformer (javax.xml.transform.Transformer)1 TransformerFactory (javax.xml.transform.TransformerFactory)1 SAXSource (javax.xml.transform.sax.SAXSource)1 StreamResult (javax.xml.transform.stream.StreamResult)1 StreamSource (javax.xml.transform.stream.StreamSource)1 HSErrorHandler (net.heartsome.xml.HSErrorHandler)1 XMLOutputter (net.heartsome.xml.XMLOutputter)1