Search in sources :

Example 6 with SAXBuilder

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

use of net.heartsome.xml.SAXBuilder 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 8 with SAXBuilder

use of net.heartsome.xml.SAXBuilder 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)8 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 XMLOutputter (net.heartsome.xml.XMLOutputter)1 TreeItem (org.eclipse.swt.widgets.TreeItem)1