Search in sources :

Example 1 with Catalogue

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

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

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

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

the class ReverseConversionValidateWithLibrary3 method readXliff.

/**
	 * @param xliff
	 *             xliff 文件的路径
	 * @throws ParserConfigurationException
	 * @throws IOException
	 * @throws SAXException
	 */
private void readXliff(String xliff) throws SAXException, IOException, ParserConfigurationException {
    builder = new SAXBuilder();
    builder.setEntityResolver(new Catalogue(ConverterContext.catalogue));
    doc = builder.build(xliff);
    root = doc.getRootElement();
    //$NON-NLS-1$
    Element file = root.getChild("file");
    //$NON-NLS-1$
    dataType = file.getAttributeValue("datatype");
    //$NON-NLS-1$ //$NON-NLS-2$
    targetLanguage = file.getAttributeValue("target-language", Messages.getString("model.ReverseConversionValidateWithLibrary3.msg4"));
}
Also used : Catalogue(net.heartsome.xml.Catalogue) SAXBuilder(net.heartsome.xml.SAXBuilder) Element(net.heartsome.xml.Element)

Example 5 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)

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