use of org.omegat.filters2.FilterContext in project omegat by omegat-org.
the class XHTMLFilterTest method testLoad.
@Test
public void testLoad() throws Exception {
String f = "test/data/filters/xhtml/file-XHTMLFilter.html";
XHTMLFilter filter = new XHTMLFilter();
filter.isFileSupported(new File(f), new TreeMap<String, String>(), new FilterContext(new Language("en"), new Language("be"), false));
IProject.FileInfo fi = loadSourceFiles(filter, f);
checkMultiStart(fi, f);
checkMulti("en", null, null, "", "en", null);
checkMulti("en", null, null, "en", "XHTML 1.0 Example", null);
checkMulti("XHTML 1.0 Example", null, null, "en", "Extensible HyperText Markup Language", null);
checkMulti("Extensible HyperText Markup Language", null, null, "XHTML 1.0 Example", "http://www.w3.org/Icons/valid-xhtml10", null);
}
use of org.omegat.filters2.FilterContext in project omegat by omegat-org.
the class XHTMLFilterTest method testTagsOptimization.
@Test
public void testTagsOptimization() throws Exception {
String f = "test/data/filters/xhtml/file-XHTMLFilter-tags-optimization.html";
XHTMLFilter filter = new XHTMLFilter();
Core.getFilterMaster().getConfig().setRemoveTags(false);
filter.isFileSupported(new File(f), new TreeMap<String, String>(), new FilterContext(new Language("en"), new Language("be"), false));
IProject.FileInfo fi = loadSourceFiles(filter, f);
checkMultiStart(fi, f);
checkMultiNoPrevNext("en", null, null, null);
checkMultiNoPrevNext("en", null, null, null);
checkMultiNoPrevNext("<i0/><b1><c2>This</c2> is <i3>first</i3> line.</b1>", null, null, null);
translateXML(filter, f);
Core.getFilterMaster().getConfig().setRemoveTags(true);
filter.isFileSupported(new File(f), new TreeMap<String, String>(), new FilterContext(new Language("en"), new Language("be"), false));
fi = loadSourceFiles(filter, f);
checkMultiStart(fi, f);
checkMultiNoPrevNext("en", null, null, null);
checkMultiNoPrevNext("en", null, null, null);
checkMultiNoPrevNext("<c0>This</c0> is <i1>first</i1> line.", null, null, null);
translateXML(filter, f);
}
use of org.omegat.filters2.FilterContext in project omegat by omegat-org.
the class FilterMaster method alignFile.
public void alignFile(String sourceDir, String fileName, String targetdir, FilterContext fc, IAlignCallback alignCallback) throws Exception {
LookupInformation lookup = lookupFilter(new File(sourceDir, fileName), fc);
if (lookup == null) {
// Skip it
return;
}
File inFile = new File(sourceDir, fileName);
File outFile = new File(targetdir, getTargetForSource(fileName, lookup, fc.getTargetLang()));
if (!outFile.exists()) {
// out file not exist - skip
return;
}
fc.setInEncoding(lookup.outFilesInfo.getSourceEncoding());
fc.setOutEncoding(lookup.outFilesInfo.getTargetEncoding());
IFilter filterObject = lookup.filterObject;
try {
filterObject.alignFile(inFile, outFile, lookup.config, fc, alignCallback);
} catch (Exception ex) {
Log.log(ex);
}
}
use of org.omegat.filters2.FilterContext 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