Search in sources :

Example 26 with Logger

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

the class Xliff2Resx method run.

public static List<String> run(Map<String, String> params) {
    List<String> result = new ArrayList<>();
    try {
        result = Xliff2Xml.run(params);
        if (!Constants.SUCCESS.equals(result.get(0))) {
            return result;
        }
        String inputFile = params.get("backfile");
        String catalog = params.get("catalog");
        Document xmlResx = openXml(inputFile, catalog);
        Element root = xmlResx.getRootElement();
        List<Element> lstNodes = root.getChildren();
        for (int i = 0; i < lstNodes.size(); i++) {
            Element node = lstNodes.get(i);
            List<XMLNode> lstChilds = node.getContent();
            for (int j = 0; j < lstChilds.size(); j++) {
                if (lstChilds.get(j).getNodeType() == XMLNode.ELEMENT_NODE) {
                    Element child = (Element) lstChilds.get(j);
                    if (isConvNode(child)) {
                        Element newChild = new Element("value");
                        newChild.setContent(child.getContent());
                        lstChilds.set(j, newChild);
                    }
                }
            }
            node.setContent(lstChilds);
        }
        saveXml(xmlResx, inputFile);
        result.add(Constants.SUCCESS);
    } catch (IOException | ParserConfigurationException | SAXException | URISyntaxException e) {
        Logger logger = System.getLogger(Xliff2Resx.class.getName());
        logger.log(Level.ERROR, "Error merging ResX file", e);
        result.add(Constants.ERROR);
        result.add(e.getMessage());
    }
    return result;
}
Also used : XMLNode(com.maxprograms.xml.XMLNode) 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) SAXException(org.xml.sax.SAXException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 27 with Logger

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

the class Ts2Xliff method run.

public static List<String> run(Map<String, String> params) {
    List<String> result = new ArrayList<>();
    segId = 0;
    String inputFile = params.get("source");
    String xliffFile = params.get("xliff");
    String skeletonFile = params.get("skeleton");
    sourceLanguage = params.get("srcLang");
    String targetLanguage = params.get("tgtLang");
    String srcEncoding = params.get("srcEncoding");
    String tgtLang = "";
    if (targetLanguage != null) {
        tgtLang = "\" target-language=\"" + targetLanguage;
    }
    try {
        output = new FileOutputStream(xliffFile);
        writeString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
        writeString("<xliff version=\"1.2\" xmlns=\"urn:oasis:names:tc:xliff:document:1.2\" " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + "xsi:schemaLocation=\"urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd\">\n");
        writeString("<file original=\"" + inputFile + "\" source-language=\"" + sourceLanguage + tgtLang + "\" tool-id=\"" + Constants.TOOLID + "\" datatype=\"x-ts\">\n");
        writeString("<header>\n");
        writeString("   <skl>\n");
        writeString("      <external-file href=\"" + skeletonFile + "\"/>\n");
        writeString("   </skl>\n");
        writeString("   <tool tool-version=\"" + Constants.VERSION + " " + Constants.BUILD + "\" tool-id=\"" + Constants.TOOLID + "\" tool-name=\"" + Constants.TOOLNAME + "\"/>\n");
        writeString("</header>\n");
        writeString("<?encoding " + srcEncoding + "?>\n");
        writeString("<body>\n");
        SAXBuilder builder = new SAXBuilder();
        Document doc = builder.build(inputFile);
        recurse(doc.getRootElement());
        try (FileOutputStream skl = new FileOutputStream(skeletonFile)) {
            XMLOutputter outputter = new XMLOutputter();
            outputter.preserveSpace(true);
            outputter.output(doc, skl);
        }
        writeString("</body>\n");
        writeString("</file>\n");
        writeString("</xliff>");
        output.close();
        result.add(Constants.SUCCESS);
    } catch (IOException | SAXException | ParserConfigurationException e) {
        Logger logger = System.getLogger(Ts2Xliff.class.getName());
        logger.log(Level.ERROR, "Error converting .ts file", e);
        result.add(Constants.ERROR);
        result.add(e.getMessage());
    }
    return result;
}
Also used : XMLOutputter(com.maxprograms.xml.XMLOutputter) SAXBuilder(com.maxprograms.xml.SAXBuilder) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(com.maxprograms.xml.Document) Logger(java.lang.System.Logger) SAXException(org.xml.sax.SAXException)

Example 28 with Logger

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

the class Xliff2Text method run.

public static List<String> run(Map<String, String> params) {
    List<String> result = new ArrayList<>();
    String sklFile = params.get("skeleton");
    xliffFile = params.get("xliff");
    encoding = params.get("encoding");
    try {
        catalog = new Catalog(params.get("catalog"));
        String outputFile = params.get("backfile");
        File f = new File(outputFile);
        File p = f.getParentFile();
        if (p == null) {
            p = new File(System.getProperty("user.dir"));
        }
        if (!p.exists()) {
            p.mkdirs();
        }
        if (!f.exists()) {
            Files.createFile(Paths.get(f.toURI()));
        }
        output = new FileOutputStream(f);
        loadSegments();
        try (InputStreamReader input = new InputStreamReader(new FileInputStream(sklFile), StandardCharsets.UTF_8)) {
            BufferedReader buffer = new BufferedReader(input);
            String line;
            while ((line = buffer.readLine()) != null) {
                line = line + "\n";
                if (line.indexOf("%%%") != -1) {
                    // 
                    // contains translatable text
                    // 
                    int index = line.indexOf("%%%");
                    while (index != -1) {
                        String start = line.substring(0, index);
                        writeString(start);
                        line = line.substring(index + 3);
                        String code = line.substring(0, line.indexOf("%%%"));
                        line = line.substring(line.indexOf("%%%") + 3);
                        Element segment = segments.get(code);
                        if (segment != null) {
                            Element target = segment.getChild("target");
                            Element source = segment.getChild("source");
                            if (target != null) {
                                if (segment.getAttributeValue("approved", "no").equals("yes")) {
                                    writeString(extractText(target));
                                } else {
                                    writeString(extractText(source));
                                }
                            } else {
                                writeString(extractText(source));
                            }
                        } else {
                            result.add(Constants.ERROR);
                            result.add("segment " + code + " not found");
                            return result;
                        }
                        index = line.indexOf("%%%");
                        if (index == -1) {
                            writeString(line);
                        }
                    }
                // end while
                } else {
                    // 
                    // non translatable portion
                    // 
                    writeString(line);
                }
            }
        }
        output.close();
        result.add(Constants.SUCCESS);
    } catch (IOException | SAXException | ParserConfigurationException | URISyntaxException e) {
        Logger logger = System.getLogger(Xliff2Text.class.getName());
        logger.log(Level.ERROR, "Error merging TEXT file", e);
        result.add(Constants.ERROR);
        result.add(e.getMessage());
    }
    return result;
}
Also used : InputStreamReader(java.io.InputStreamReader) Element(com.maxprograms.xml.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) Logger(java.lang.System.Logger) Catalog(com.maxprograms.xml.Catalog) FileInputStream(java.io.FileInputStream) SAXException(org.xml.sax.SAXException) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File)

Example 29 with Logger

use of java.lang.System.Logger in project slf4j by qos-ch.

the class SLF4JPlatformLoggingTest method throwTest.

@Test
public void throwTest() throws IOException {
    LoggerFinder finder = System.LoggerFinder.getLoggerFinder();
    assertEquals(EXPECTED_FINDER_CLASS, finder.getClass().getName());
    Logger systemLogger = finder.getLogger("throwTest", null);
    systemLogger.log(Level.INFO, "we have a problem", new Exception());
    List<String> results = SPS.stringList;
    // INFO throwTest - a problem
    // java.lang.Exception
    // at org.slf4j.jdk.platform.logging/org.slf4j.jdk.platform.logging.SLF4JPlatformLoggingTest.throwTest(SLF4JPlatformLoggingTest.java:92)
    assertEquals("INFO throwTest - we have a problem", results.get(0));
    assertEquals(Exception.class.getName(), results.get(1));
    assertTrue(results.get(2).contains("at "));
    assertTrue(results.get(2).contains(this.getClass().getName()));
}
Also used : LoggerFinder(java.lang.System.LoggerFinder) Logger(java.lang.System.Logger) IOException(java.io.IOException) Test(org.junit.Test)

Example 30 with Logger

use of java.lang.System.Logger in project slf4j by qos-ch.

the class SLF4JPlatformLoggingTest method smoke.

@Test
public void smoke() throws IOException {
    LoggerFinder finder = System.LoggerFinder.getLoggerFinder();
    assertEquals(EXPECTED_FINDER_CLASS, finder.getClass().getName());
    Logger systemLogger = finder.getLogger("smoke", null);
    systemLogger.log(Level.INFO, "hello");
    systemLogger.log(Level.INFO, "hello %s", "world");
    List<String> results = SPS.stringList;
    assertEquals(2, results.size());
    assertEquals("INFO smoke - hello", results.get(0));
    assertEquals("INFO smoke - hello world", results.get(1));
}
Also used : LoggerFinder(java.lang.System.LoggerFinder) Logger(java.lang.System.Logger) Test(org.junit.Test)

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