Search in sources :

Example 36 with Logger

use of java.lang.System.Logger in project Bytecoder by mirkosertic.

the class BootstrapLogger method log.

@Override
public void log(Level level, String msg, Throwable thrown) {
    if (checkBootstrapping()) {
        push(LogEvent.valueOf(this, level, null, msg, thrown));
    } else {
        final Logger spi = holder.wrapped();
        spi.log(level, msg, thrown);
    }
}
Also used : PlatformLogger(sun.util.logging.PlatformLogger) Logger(java.lang.System.Logger)

Example 37 with Logger

use of java.lang.System.Logger in project Bytecoder by mirkosertic.

the class BootstrapLogger method log.

@Override
public void log(Level level, ResourceBundle bundle, String key, Throwable thrown) {
    if (checkBootstrapping()) {
        push(LogEvent.valueOf(this, level, bundle, key, thrown));
    } else {
        final Logger spi = holder.wrapped();
        spi.log(level, bundle, key, thrown);
    }
}
Also used : PlatformLogger(sun.util.logging.PlatformLogger) Logger(java.lang.System.Logger)

Example 38 with Logger

use of java.lang.System.Logger in project Bytecoder by mirkosertic.

the class BootstrapLogger method log.

@Override
public void log(Level level, String msg) {
    if (checkBootstrapping()) {
        push(LogEvent.valueOf(this, level, null, msg, (Object[]) null));
    } else {
        final Logger spi = holder.wrapped();
        spi.log(level, msg);
    }
}
Also used : PlatformLogger(sun.util.logging.PlatformLogger) Logger(java.lang.System.Logger)

Example 39 with Logger

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

the class Xliff2Po 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 {
        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(f.toPath());
        }
        output = new FileOutputStream(f);
        loadSegments();
        try (InputStreamReader input = new InputStreamReader(new FileInputStream(sklFile), StandardCharsets.UTF_8)) {
            BufferedReader buffer = new BufferedReader(input);
            String line = buffer.readLine();
            while (line != 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) {
                            writeSegment(segment);
                        } else {
                            MessageFormat mf = new MessageFormat("Segment {0} not found.");
                            throw new UnexistentSegmentException(mf.format(new Object[] { code }));
                        }
                        index = line.indexOf("%%%");
                        if (index == -1) {
                            writeString(line);
                        }
                    }
                // end while
                } else {
                    // 
                    // non translatable portion
                    // 
                    writeString(line);
                }
                line = buffer.readLine();
            }
        }
        output.close();
        result.add(Constants.SUCCESS);
    } catch (IOException | SAXException | UnexistentSegmentException | ParserConfigurationException e) {
        Logger logger = System.getLogger(Xliff2Po.class.getName());
        logger.log(Level.ERROR, "Error merging PO file.", e);
        result.add(Constants.ERROR);
        result.add(e.getMessage());
    }
    return result;
}
Also used : InputStreamReader(java.io.InputStreamReader) MessageFormat(java.text.MessageFormat) Element(com.maxprograms.xml.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Logger(java.lang.System.Logger) FileInputStream(java.io.FileInputStream) SAXException(org.xml.sax.SAXException) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) UnexistentSegmentException(com.maxprograms.converters.UnexistentSegmentException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File)

Example 40 with Logger

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

the class Xliff2Sdlrpx method run.

public static List<String> run(Map<String, String> params) {
    List<String> result = new ArrayList<>();
    srcLang = "";
    tgtLang = "";
    Map<String, String> filesMap = new HashMap<>();
    String sklFile = params.get("skeleton");
    String xliffFile = params.get("xliff");
    String catalog = params.get("catalog");
    String outputFile = params.get("backfile");
    try {
        SAXBuilder builder = new SAXBuilder();
        builder.setEntityResolver(new Catalog(catalog));
        Document doc = builder.build(xliffFile);
        Element root = doc.getRootElement();
        List<Element> files = root.getChildren("file");
        Iterator<Element> it = files.iterator();
        XMLOutputter outputter = new XMLOutputter();
        outputter.preserveSpace(true);
        while (it.hasNext()) {
            Element file = it.next();
            Element header = file.getChild("header");
            if (header == null) {
                throw new SAXException("Missing <header>");
            }
            Element skl = header.getChild("skl");
            if (skl == null) {
                throw new SAXException("Missing <skl>");
            }
            List<Element> propGroups = header.getChildren("prop-group");
            if (propGroups == null) {
                throw new SAXException("Missing <prp-groups>");
            }
            String sdlxliffFile = "";
            for (int i = 0; i < propGroups.size(); i++) {
                Element propGroup = propGroups.get(i);
                if (propGroup.getAttributeValue("name").equals("document")) {
                    List<Element> props = propGroup.getChildren("prop");
                    for (int j = 0; j < props.size(); j++) {
                        Element prop = props.get(j);
                        if (prop.getAttributeValue("prop-type").equals("original")) {
                            sdlxliffFile = prop.getText();
                        }
                    }
                }
            }
            if (sdlxliffFile.isEmpty()) {
                throw new SAXException("Missing sdlxliff file name");
            }
            if (tgtLang.isEmpty()) {
                tgtLang = file.getAttributeValue("target-language");
            }
            if (srcLang.isEmpty()) {
                srcLang = file.getAttributeValue("source-language");
            }
            Document d = new Document(null, "xliff", null, null);
            Element r = d.getRootElement();
            r.setAttribute("version", "1.2");
            r.setAttribute("xmlns", "urn:oasis:names:tc:xliff:document:1.2");
            r.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
            r.setAttribute("xsi:schemaLocation", "urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd");
            r.addContent(file);
            File tempXliff = File.createTempFile("tmp", ".xlf");
            try (FileOutputStream outFile = new FileOutputStream(tempXliff)) {
                outputter.output(d, outFile);
            }
            filesMap.put(sdlxliffFile, tempXliff.getAbsolutePath());
        }
        out = new ZipOutputStream(new FileOutputStream(outputFile));
        try (ZipInputStream in = new ZipInputStream(new FileInputStream(sklFile))) {
            ZipEntry entry = null;
            while ((entry = in.getNextEntry()) != null) {
                File f = new File(entry.getName());
                String name = f.getName();
                String extension = name.substring(name.lastIndexOf('.'));
                File tmp = File.createTempFile("tmp", extension);
                try (FileOutputStream output = new FileOutputStream(tmp.getAbsolutePath())) {
                    byte[] buf = new byte[1024];
                    int len;
                    while ((len = in.read(buf)) > 0) {
                        output.write(buf, 0, len);
                    }
                }
                if (name.endsWith(".skl")) {
                    File back = File.createTempFile("tmp", ".sdlxliff");
                    String xliff = entry.getName();
                    xliff = xliff.substring(0, xliff.length() - 4);
                    Map<String, String> map = new HashMap<>();
                    map.put("xliff", filesMap.get(xliff));
                    map.put("skeleton", tmp.getAbsolutePath());
                    map.put("catalog", catalog);
                    map.put("backfile", back.getAbsolutePath());
                    List<String> res = Xliff2Sdl.run(map);
                    if (!res.get(0).equals(Constants.SUCCESS)) {
                        return res;
                    }
                    saveEntry(xliff, back.getAbsolutePath());
                    Files.delete(back.toPath());
                } else if (name.endsWith(".sdlproj")) {
                    // update project
                    updateProjectFile(tmp);
                    saveEntry(updateProjectName(entry.getName()), tmp.getAbsolutePath());
                } else {
                    // store as is
                    saveEntry(entry.getName(), tmp.getAbsolutePath());
                }
                Files.delete(tmp.toPath());
            }
        }
        out.close();
        Set<String> keySet = filesMap.keySet();
        Iterator<String> kt = keySet.iterator();
        while (kt.hasNext()) {
            String file = filesMap.get(kt.next());
            Files.delete(new File(file).toPath());
        }
        result.add(Constants.SUCCESS);
    } catch (IOException | SAXException | ParserConfigurationException | URISyntaxException e) {
        Logger logger = System.getLogger(Xliff2Sdlrpx.class.getName());
        logger.log(Level.ERROR, "Error merging XLIFF file", e);
        result.add(Constants.ERROR);
        result.add(e.getMessage());
    }
    return result;
}
Also used : XMLOutputter(com.maxprograms.xml.XMLOutputter) HashMap(java.util.HashMap) Element(com.maxprograms.xml.Element) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) Document(com.maxprograms.xml.Document) Logger(java.lang.System.Logger) SAXException(org.xml.sax.SAXException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXBuilder(com.maxprograms.xml.SAXBuilder) IOException(java.io.IOException) Catalog(com.maxprograms.xml.Catalog) FileInputStream(java.io.FileInputStream) ZipInputStream(java.util.zip.ZipInputStream) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) 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