use of com.ximpleware.XMLModifier in project translationstudio8 by heartsome.
the class DatabaseConfiger method deleteServerById.
/**
* 删除指定id的服务器配置信息
* @param id
* 服务器配置信息id;
*/
public void deleteServerById(String id) {
if (id != null && !id.equals("")) {
try {
XMLModifier xm = vu.delete("/servers/server[@id='" + id + "']");
vu.bind(xm.outputAndReparse());
saveToFile(xm, serverConfigFile);
} catch (Exception e) {
logger.error(Messages.getString("core.DatabaseConfiger.logger3"), e);
}
}
}
use of com.ximpleware.XMLModifier in project translationstudio8 by heartsome.
the class ExportFilterStoreConfiger method deleteFilterRuleByName.
/**
* 删除指定名称的规则
* @param filterName
* 规则名称
* @param ruleType
* "TMX" 或者 "TBX";
*/
public void deleteFilterRuleByName(String filterName, String ruleType) {
Assert.isLegal(!"TMX".equals(ruleType) || !"TBX".equals(ruleType));
if (filterName != null && !filterName.equals("")) {
try {
XMLModifier xm = vu.delete("/filter/" + ruleType + "/content[@name='" + filterName + "']");
vu.bind(xm.outputAndReparse());
saveToFile(xm, filterConfigFile);
} catch (Exception e) {
logger.error(Messages.getString("core.ExportFilterStoreConfiger.logger2"), e);
}
}
}
use of com.ximpleware.XMLModifier in project translationstudio8 by heartsome.
the class ExportFilterStoreConfiger method saveFilterRule.
public void saveFilterRule(ExportFilterBean filter) {
String content = generateContent(filter);
if (!content.equals("")) {
try {
XMLModifier xm = vu.insert("/filter/" + filter.getFilterType() + "/text()", content.toString());
vu.bind(xm.outputAndReparse());
saveToFile(xm, filterConfigFile);
} catch (Exception e) {
logger.error("", e);
}
ap.resetXPath();
}
}
use of com.ximpleware.XMLModifier in project translationstudio8 by heartsome.
the class WebSearchPreferencStore method storeConfig.
/**
* 保存设置值
* @param searchEntry
* ;
*/
public void storeConfig(List<SearchEntry> searchEntry) {
FileOutputStream out = null;
boolean hasError = false;
try {
out = new FileOutputStream(customConfigPath);
writeContent(out, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
writeContent(out, "<WebSearchInfo xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instancexmlns:xsd=http://www.w3.org/2001/XMLSchema\">\r\n");
writeContent(out, " <Providers>\r\n");
if (null != searchEntry) {
for (SearchEntry s : searchEntry) {
writeContent(out, convert2Xml(s));
}
}
writeContent(out, " </Providers>\r\n </WebSearchInfo>");
out.flush();
support.firePropertyChange("URL", null, getUseredConfig(searchEntry));
} catch (FileNotFoundException e) {
hasError = true;
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
hasError = true;
e.printStackTrace();
} catch (IOException e) {
hasError = true;
e.printStackTrace();
} finally {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
if (hasError) {
XMLModifier modifier;
try {
modifier = new XMLModifier(customVu.getVTDNav());
modifier.output(customConfigPath);
} catch (ModifyException e) {
e.printStackTrace();
logger.error("", e);
} catch (TranscodeException e) {
e.printStackTrace();
logger.error("", e);
} catch (IOException e) {
e.printStackTrace();
logger.error("", e);
}
} else {
try {
customVu.parseFile(customConfigPath, false);
} catch (ParseException e) {
e.printStackTrace();
logger.error("", e);
} catch (IOException e) {
e.printStackTrace();
logger.error("", e);
}
}
}
}
use of com.ximpleware.XMLModifier in project translationstudio8 by heartsome.
the class PreTranslation method executeTranslation.
/**
* 根据构建参数执行预翻译 ;
* @throws InterruptedException
*/
public List<PreTranslationCounter> executeTranslation(IProgressMonitor monitor) throws InterruptedException {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
monitor.beginTask("", this.xlfFiles.size());
monitor.setTaskName(Messages.getString("pretranslation.PreTranslation.task1"));
try {
for (String xlfPath : xlfFiles) {
if (monitor != null && monitor.isCanceled()) {
throw new InterruptedException();
}
currentCounter = new PreTranslationCounter(xlfPath);
this.transCounters.add(currentCounter);
VTDNav vn = xlfHandler.getVnMap().get(xlfPath);
VTDUtils vu = new VTDUtils(vn);
AutoPilot ap = new AutoPilot(vu.getVTDNav());
int tuNumber = xlfHandler.getNodeCount(xlfPath, "/xliff/file//descendant::trans-unit[(source/text()!='' or source/*)]");
currentCounter.setTuNumber(tuNumber);
ap.selectXPath("/xliff/file");
String srcLang = "";
String tgtLang = "";
XMLModifier xm = new XMLModifier(vn);
IProgressMonitor monitor2 = new SubProgressMonitor(monitor, 1);
monitor2.beginTask(Messages.getString("pretranslation.PreTranslation.task2"), tuNumber);
while (ap.evalXPath() != -1) {
// 循环 file 节点
String _srcLang = vu.getCurrentElementAttribut("source-language", "");
String _tgtLang = vu.getCurrentElementAttribut("target-language", "");
if (!_srcLang.equals("")) {
srcLang = _srcLang;
}
if (!_tgtLang.equals("")) {
tgtLang = _tgtLang;
}
if (srcLang.equals("") || tgtLang.equals("")) {
continue;
}
if (updateStrategy == PreTransParameters.KEEP_OLD_TARGET) {
keepCurrentMatchs(vu, _srcLang, _tgtLang, xm, monitor2);
} else if (updateStrategy == PreTransParameters.KEEP_BEST_MATCH_TARGET) {
keepHigherMatchs(vu, _srcLang, _tgtLang, xm, monitor2);
} else if (updateStrategy == PreTransParameters.KEEP_NEW_TARGET) {
overwriteMatchs(vu, srcLang, tgtLang, xm, monitor2);
}
}
monitor2.done();
FileOutputStream fos = new FileOutputStream(xlfPath);
BufferedOutputStream bos = new BufferedOutputStream(fos);
// 写入文件
xm.output(bos);
bos.close();
fos.close();
}
} catch (XPathParseException e) {
logger.error("", e);
e.printStackTrace();
} catch (NavException e) {
logger.error("", e);
e.printStackTrace();
} catch (ModifyException e) {
logger.error("", e);
e.printStackTrace();
} catch (XPathEvalException e) {
logger.error("", e);
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
logger.error("", e);
e.printStackTrace();
} catch (FileNotFoundException e) {
logger.error("", e);
e.printStackTrace();
} catch (TranscodeException e) {
logger.error("", e);
e.printStackTrace();
} catch (IOException e) {
logger.error("", e);
e.printStackTrace();
}
monitor.done();
return this.transCounters;
}
Aggregations