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;
}
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;
}
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;
}
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()));
}
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));
}
Aggregations