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