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