use of org.omegat.filters2.TranslationException in project omegat by omegat-org.
the class Handler method endDocument.
/**
* Receive notification of the end of the document.
*/
@Override
public void endDocument() throws SAXException {
try {
translateAndFlush();
if (extWriter != null) {
extWriter.close();
extWriter = null;
}
translateAndFlush();
currWriter().close();
} catch (TranslationException e) {
throw new SAXException(e);
} catch (IOException e) {
throw new SAXException(e);
}
}
use of org.omegat.filters2.TranslationException in project omegat by omegat-org.
the class OpenDocFilter method processFile.
/**
* Processes a single OpenDocument file, which is actually a ZIP file consisting of many XML files, some
* of which should be translated.
*/
@Override
public void processFile(File inFile, File outFile, FilterContext fc) throws IOException, TranslationException {
ZipFile zipfile = new ZipFile(inFile);
ZipOutputStream zipout = null;
if (outFile != null) {
zipout = new ZipOutputStream(new FileOutputStream(outFile));
}
Enumeration<? extends ZipEntry> zipcontents = zipfile.entries();
while (zipcontents.hasMoreElements()) {
ZipEntry zipentry = zipcontents.nextElement();
String shortname = zipentry.getName();
if (shortname.lastIndexOf('/') >= 0) {
shortname = shortname.substring(shortname.lastIndexOf('/') + 1);
}
if (TRANSLATABLE.contains(shortname)) {
File tmpin = tmp();
FileUtils.copyInputStreamToFile(zipfile.getInputStream(zipentry), tmpin);
File tmpout = null;
if (zipout != null) {
tmpout = tmp();
}
try {
createXMLFilter(processOptions).processFile(tmpin, tmpout, fc);
} catch (Exception e) {
zipfile.close();
throw new TranslationException(e.getLocalizedMessage() + "\n" + OStrings.getString("OpenDoc_ERROR_IN_FILE") + inFile);
}
if (zipout != null) {
ZipEntry outentry = new ZipEntry(zipentry.getName());
outentry.setMethod(ZipEntry.DEFLATED);
zipout.putNextEntry(outentry);
FileUtils.copyFile(tmpout, zipout);
zipout.closeEntry();
}
if (!tmpin.delete()) {
tmpin.deleteOnExit();
}
if (tmpout != null) {
if (!tmpout.delete()) {
tmpout.deleteOnExit();
}
}
} else {
if (zipout != null) {
ZipEntry outentry = new ZipEntry(zipentry.getName());
zipout.putNextEntry(outentry);
IOUtils.copy(zipfile.getInputStream(zipentry), zipout);
zipout.closeEntry();
}
}
}
if (zipout != null) {
zipout.close();
}
zipfile.close();
}
Aggregations