use of com.ximpleware.TranscodeException in project translationstudio8 by heartsome.
the class ProjectConfiger method save.
/**
* 保存文件
* @param xm
* XMLModifier对象
* @param fileName
* 文件名
* @return 是否保存成功;
*/
private boolean save(XMLModifier xm, File file) {
try {
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos);
// 写入文件
xm.output(bos);
bos.close();
fos.close();
VTDGen vg = new VTDGen();
try {
if (vg.parseFile(projCfgFile.getPath(), true)) {
vu.bind(vg.getNav());
} else {
throw new ParseException();
}
} catch (NavException e) {
logger.error("", e);
} catch (ParseException e) {
logger.error("", e);
}
return true;
} catch (ModifyException e) {
logger.error("", e);
e.printStackTrace();
} catch (TranscodeException e) {
logger.error("", e);
e.printStackTrace();
} catch (IOException e) {
logger.error("", e);
e.printStackTrace();
}
return false;
}
use of com.ximpleware.TranscodeException in project translationstudio8 by heartsome.
the class XLFHandler method save.
/**
* 保存文件
* @param xm
* XMLModifier对象
* @param fileName
* 文件名
* @return 是否保存成功;
*/
private boolean save(XMLModifier xm, File file) {
try {
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos);
// 写入文件
xm.output(bos);
bos.close();
fos.close();
IPath path = URIUtil.toPath(file.toURI());
IFile iFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
if (iFile != null) {
// 同步导航视图和文件系统
iFile.refreshLocal(IResource.DEPTH_ZERO, null);
}
return true;
} catch (ModifyException e) {
LOGGER.error("", e);
e.printStackTrace();
} catch (TranscodeException e) {
LOGGER.error("", e);
e.printStackTrace();
} catch (IOException e) {
LOGGER.error("", e);
e.printStackTrace();
} catch (CoreException e) {
LOGGER.error("", e);
e.printStackTrace();
}
return false;
}
use of com.ximpleware.TranscodeException in project translationstudio8 by heartsome.
the class XLPHandler method saveXliffInfo.
/**
* 保存 XLIFF 信息
* @param xliffInfo
* XLIFF 信息 ;
*/
public void saveXliffInfo(List<? extends Map<String, String>> xliffInfo) {
try {
XMLModifier xm = new XMLModifier(vn);
AutoPilot ap = new AutoPilot(vn);
StringBuffer items = new StringBuffer();
String pattern = "<item {0}=\"{1}\" {2}=\"{3}\" />";
ap.selectXPath("/xlfedit-project");
if (ap.evalXPath() != -1) {
for (Map<String, String> map : xliffInfo) {
vn.push();
String xliff = map.get(ATTR_XLIFF);
String tgtEnc = map.get(ATTR_TGT_ENC);
String xpath = "./item[@" + ATTR_XLIFF + "='" + xliff + "']";
ap.selectXPath(xpath);
if (ap.evalXPath() != -1) {
updateAttribute(xm, ATTR_TGT_ENC, tgtEnc);
} else {
String item = MessageFormat.format(pattern, ATTR_XLIFF, xliff, ATTR_TGT_ENC, tgtEnc);
items.append(item).append(LINE_SEPARATOR);
}
vn.pop();
}
if (items.length() > 1) {
xm.insertBeforeTail(items.toString());
}
save(xm);
}
} catch (NavException e) {
LOGGER.error("", e);
e.printStackTrace();
} catch (ParseException e) {
LOGGER.error("", e);
e.printStackTrace();
} catch (TranscodeException e) {
LOGGER.error("", e);
e.printStackTrace();
} catch (ModifyException e) {
LOGGER.error("", e);
e.printStackTrace();
} catch (IOException e) {
LOGGER.error("", e);
e.printStackTrace();
} catch (XPathParseException e) {
LOGGER.error("", e);
e.printStackTrace();
} catch (XPathEvalException e) {
LOGGER.error("", e);
e.printStackTrace();
}
}
use of com.ximpleware.TranscodeException in project translationstudio8 by heartsome.
the class XLPHandler method saveSourceInfo.
/**
* 保存 XLIFF 信息
* @param sourceInfo
* 源文件信息 ;
*/
public void saveSourceInfo(List<? extends Map<String, String>> sourceInfo) {
try {
XMLModifier xm = new XMLModifier(vn);
AutoPilot ap = new AutoPilot(vn);
StringBuffer items = new StringBuffer();
String pattern = "<item {0}=\"{1}\" {2}=\"{3}\" {4}=\"{5}\" {6}=\"{7}\" />";
ap.selectXPath("/xlfedit-project");
if (ap.evalXPath() != -1) {
for (Map<String, String> map : sourceInfo) {
vn.push();
String source = map.get(ATTR_SOURCE);
String format = map.get(ATTR_FORMAT);
String srcLang = map.get(ATTR_SRC_LANG);
String srcEnc = map.get(ATTR_SRC_ENC);
String xpath = "./item[@" + ATTR_SOURCE + "=\"" + source + "\"]";
ap.selectXPath(xpath);
if (ap.evalXPath() != -1) {
updateAttribute(xm, ATTR_FORMAT, format);
updateAttribute(xm, ATTR_SRC_LANG, srcLang);
updateAttribute(xm, ATTR_SRC_ENC, srcEnc);
} else {
String item = MessageFormat.format(pattern, ATTR_SOURCE, source, ATTR_FORMAT, format, ATTR_SRC_LANG, srcLang, ATTR_SRC_ENC, srcEnc);
ap.selectXPath(xpath);
items.append(item).append(LINE_SEPARATOR);
}
vn.pop();
}
if (items.length() > 1) {
xm.insertBeforeTail(items.toString());
}
save(xm);
}
} catch (NavException e) {
LOGGER.error("", e);
e.printStackTrace();
} catch (ParseException e) {
LOGGER.error("", e);
e.printStackTrace();
} catch (TranscodeException e) {
LOGGER.error("", e);
e.printStackTrace();
} catch (ModifyException e) {
LOGGER.error("", e);
e.printStackTrace();
} catch (IOException e) {
LOGGER.error("", e);
e.printStackTrace();
} catch (XPathParseException e) {
LOGGER.error("", e);
e.printStackTrace();
} catch (XPathEvalException e) {
LOGGER.error("", e);
e.printStackTrace();
}
}
use of com.ximpleware.TranscodeException in project translationstudio8 by heartsome.
the class QAXmlHandler method save.
/**
* 保存文件
* @param xm
* XMLModifier对象
* @param fileName
* 文件名
* @return 是否保存成功;
*/
private boolean save(XMLModifier xm, File file) {
try {
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos);
// 写入文件
xm.output(bos);
bos.close();
fos.close();
IPath path = URIUtil.toPath(file.toURI());
IFile iFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
if (iFile != null) {
// 同步导航视图和文件系统
iFile.refreshLocal(IResource.DEPTH_ZERO, null);
}
return true;
} catch (ModifyException e) {
e.printStackTrace();
logger.error(MessageFormat.format(Messages.getString("qa.QAXmlHandler.logger4"), file.getAbsolutePath()), e);
} catch (TranscodeException e) {
e.printStackTrace();
logger.error(MessageFormat.format(Messages.getString("qa.QAXmlHandler.logger4"), file.getAbsolutePath()), e);
} catch (IOException e) {
e.printStackTrace();
logger.error(MessageFormat.format(Messages.getString("qa.QAXmlHandler.logger5"), file.getAbsolutePath()), e);
} catch (CoreException e) {
e.printStackTrace();
logger.error(MessageFormat.format(Messages.getString("qa.QAXmlHandler.logger6"), file.getAbsolutePath()), e);
}
return false;
}
Aggregations