Search in sources :

Example 56 with Logger

use of java.lang.System.Logger in project OpenXLIFF by rmraya.

the class FromXliff2 method run.

public static List<String> run(String sourceFile, String outputFile, String catalog) {
    List<String> result = new ArrayList<>();
    try {
        SAXBuilder builder = new SAXBuilder();
        builder.setEntityResolver(new Catalog(catalog));
        Document doc = builder.build(sourceFile);
        Element root = doc.getRootElement();
        if (!root.getAttributeValue("version").startsWith("2.")) {
            result.add(Constants.ERROR);
            result.add("Wrong XLIFF version.");
            return result;
        }
        Document xliff12 = new Document(null, "xliff", null, null);
        Element root12 = xliff12.getRootElement();
        recurse(root, root12);
        Indenter.indent(root12, 2);
        XMLOutputter outputter = new XMLOutputter();
        outputter.preserveSpace(true);
        try (FileOutputStream out = new FileOutputStream(new File(outputFile))) {
            out.write(XMLUtils.UTF8BOM);
            outputter.output(xliff12, out);
        }
        result.add(Constants.SUCCESS);
    } catch (SAXException | IOException | ParserConfigurationException | URISyntaxException ex) {
        Logger logger = System.getLogger(FromXliff2.class.getName());
        logger.log(Level.ERROR, "Error processing XLIFF 2.0", ex);
        result.add(Constants.ERROR);
        result.add(ex.getMessage());
    }
    return result;
}
Also used : XMLOutputter(com.maxprograms.xml.XMLOutputter) SAXBuilder(com.maxprograms.xml.SAXBuilder) Element(com.maxprograms.xml.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) Document(com.maxprograms.xml.Document) Logger(java.lang.System.Logger) Catalog(com.maxprograms.xml.Catalog) SAXException(org.xml.sax.SAXException) FileOutputStream(java.io.FileOutputStream) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File)

Example 57 with Logger

use of java.lang.System.Logger in project OpenXLIFF by rmraya.

the class ToXliff2 method run.

public static List<String> run(String sourceFile, String outputFile, String catalog) {
    List<String> result = new ArrayList<>();
    fileId = 1;
    try {
        SAXBuilder builder = new SAXBuilder();
        builder.setEntityResolver(new Catalog(catalog));
        Document doc = builder.build(sourceFile);
        Element root = doc.getRootElement();
        if (!root.getAttributeValue("version", "1.2").equals("1.2")) {
            result.add(Constants.ERROR);
            result.add("Wrong XLIFF version.");
            return result;
        }
        Document xliff2 = new Document(null, "xliff", null, null);
        root2 = xliff2.getRootElement();
        recurse(root, root2);
        Indenter.indent(root2, 2);
        XMLOutputter outputter = new XMLOutputter();
        outputter.preserveSpace(true);
        try (FileOutputStream out = new FileOutputStream(new File(outputFile))) {
            out.write(XMLUtils.UTF8BOM);
            outputter.output(xliff2, out);
        }
        result.add(Constants.SUCCESS);
    } catch (SAXException | IOException | ParserConfigurationException | URISyntaxException ex) {
        Logger logger = System.getLogger(ToXliff2.class.getName());
        logger.log(Level.ERROR, "Error generating XLIFF 2.0");
        result.add(Constants.ERROR);
        result.add(ex.getMessage());
    }
    return result;
}
Also used : XMLOutputter(com.maxprograms.xml.XMLOutputter) SAXBuilder(com.maxprograms.xml.SAXBuilder) Element(com.maxprograms.xml.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) Document(com.maxprograms.xml.Document) Logger(java.lang.System.Logger) Catalog(com.maxprograms.xml.Catalog) SAXException(org.xml.sax.SAXException) FileOutputStream(java.io.FileOutputStream) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File)

Example 58 with Logger

use of java.lang.System.Logger in project OpenXLIFF by rmraya.

the class Resegmenter method run.

public static List<String> run(String xliff, String srx, String srcLang, String catalog) {
    List<String> result = new ArrayList<>();
    try {
        segmenter = new Segmenter(srx, srcLang, catalog);
        SAXBuilder builder = new SAXBuilder();
        Document doc = builder.build(xliff);
        Element root = doc.getRootElement();
        recurse(root);
        try (FileOutputStream out = new FileOutputStream(new File(xliff))) {
            XMLOutputter outputter = new XMLOutputter();
            outputter.preserveSpace(true);
            Indenter.indent(root, 2);
            outputter.output(doc, out);
        }
        result.add(Constants.SUCCESS);
    } catch (SAXException | IOException | ParserConfigurationException | URISyntaxException e) {
        Logger logger = System.getLogger(Resegmenter.class.getName());
        logger.log(Level.ERROR, "Error re-segmenting XLIFF 2.0", e);
        result.add(Constants.ERROR);
        result.add(e.getMessage());
    }
    return result;
}
Also used : XMLOutputter(com.maxprograms.xml.XMLOutputter) SAXBuilder(com.maxprograms.xml.SAXBuilder) Element(com.maxprograms.xml.Element) ArrayList(java.util.ArrayList) Segmenter(com.maxprograms.segmenter.Segmenter) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) Document(com.maxprograms.xml.Document) Logger(java.lang.System.Logger) SAXException(org.xml.sax.SAXException) FileOutputStream(java.io.FileOutputStream) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File)

Aggregations

Logger (java.lang.System.Logger)58 IOException (java.io.IOException)39 ArrayList (java.util.ArrayList)38 FileOutputStream (java.io.FileOutputStream)36 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)34 SAXException (org.xml.sax.SAXException)34 URISyntaxException (java.net.URISyntaxException)28 File (java.io.File)23 Element (com.maxprograms.xml.Element)22 Document (com.maxprograms.xml.Document)17 FileInputStream (java.io.FileInputStream)16 PlatformLogger (sun.util.logging.PlatformLogger)16 SAXBuilder (com.maxprograms.xml.SAXBuilder)14 XMLOutputter (com.maxprograms.xml.XMLOutputter)14 Catalog (com.maxprograms.xml.Catalog)13 BufferedReader (java.io.BufferedReader)13 InputStreamReader (java.io.InputStreamReader)11 Segmenter (com.maxprograms.segmenter.Segmenter)7 Level (java.lang.System.Logger.Level)7 HashMap (java.util.HashMap)5