use of com.ximpleware.XMLModifier in project translationstudio8 by heartsome.
the class XLFHandler method deleteSplitInfoParent.
/**
* 删除目标文件的切割信息的父节点<hs:splitInfos>
* @param xlfPath
*/
public void deleteSplitInfoParent(String xlfPath) {
VTDNav vn = vnMap.get(xlfPath);
Assert.isNotNull(vn, Messages.getString("file.XLFHandler.msg4") + xlfPath);
try {
// --robert split
String xPath = "/xliff/file/header/hs:splitInfos";
// String xPath = "/xliff/file/header/splitInfos";
VTDUtils vu = new VTDUtils(vn);
AutoPilot ap = new AutoPilot(vn);
ap.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
XMLModifier xm = vu.delete(ap, null, xPath, VTDUtils.PILOT_TO_END);
saveAndReparse(xm, xlfPath);
} catch (Exception e) {
LOGGER.error("", e);
e.printStackTrace();
}
}
use of com.ximpleware.XMLModifier in project translationstudio8 by heartsome.
the class TMXValidator method createTmpFile.
/**
* 创建一个用于编辑的临时TMX文件
*/
public File createTmpFile(String tmxLocation) throws Exception {
File tmpFile = null;
File folder = null;
File curFolder = new File(".");
if (Utils.OS_WINDOWS == Utils.getCurrentOS()) {
folder = new File(curFolder.getAbsoluteFile() + Utils.getFileSeparator() + "~$temp");
if (!folder.exists()) {
folder.mkdirs();
}
folder.deleteOnExit();
String sets = "attrib +H \"" + folder.getAbsolutePath() + "\"";
// 运行命令串
Runtime.getRuntime().exec(sets);
} else {
folder = new File(curFolder.getAbsoluteFile() + Utils.getFileSeparator() + ".temp");
if (!folder.exists()) {
folder.mkdirs();
}
folder.deleteOnExit();
}
tmpFile = File.createTempFile("tmp", ".TMX", folder);
tmpFile.deleteOnExit();
VTDNav vn = vnMap.get(tmxLocation);
Assert.isNotNull(vn, MessageFormat.format(Messages.getString("plugin.TMXValidator.msg11"), tmxLocation));
XMLModifier xm = new XMLModifier(vn);
save(xm, tmpFile);
return tmpFile;
}
use of com.ximpleware.XMLModifier in project translationstudio8 by heartsome.
the class PluginConfigManageDialog method addPluginData.
/**
* 添加插件配置信息到插件文件 ;
*/
private boolean addPluginData(PluginConfigBean pluginBean) {
File pluginXMl = new File(pluginXmlLocation);
if (!pluginXMl.getParentFile().exists()) {
pluginXMl.getParentFile().mkdirs();
}
pluginXMl = new File(pluginXmlLocation);
try {
// 如果配置文件不存在,则创建
if (!pluginXMl.exists()) {
OutputStream output = new FileOutputStream(pluginXmlLocation);
output.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n".getBytes("UTF-8"));
output.write("<shortcuts>\n</shortcuts>".getBytes("UTF-8"));
output.close();
}
} catch (Exception e) {
LOGGER.error("", e);
}
// 开始存放文件
try {
VTDGen vg = new VTDGen();
vg.parseFile(pluginXmlLocation, true);
VTDNav vn = vg.getNav();
AutoPilot ap = new AutoPilot(vn);
ap.selectXPath(manage.buildXpath(pluginBean));
if (ap.evalXPath() != -1) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.PluginConfigManageDialog.msgTitle"), Messages.getString("dialog.PluginConfigManageDialog.msg3"));
return false;
}
ap.resetXPath();
// 先判断此次添加的数据是否存在
String addData = manage.buildPluginData(pluginBean);
ap.selectXPath("/shortcuts");
if (ap.evalXPath() != -1) {
XMLModifier xm = new XMLModifier(vn);
xm.insertBeforeTail(addData + "\n");
FileOutputStream fos = new FileOutputStream(pluginXmlLocation);
BufferedOutputStream bos = new BufferedOutputStream(fos);
// 写入文件
xm.output(bos);
bos.close();
fos.close();
}
} catch (Exception e) {
LOGGER.error("", e);
}
return true;
}
use of com.ximpleware.XMLModifier in project translationstudio8 by heartsome.
the class PluginConfigManageDialog method editPlugindata.
private void editPlugindata(PluginConfigBean bean) {
VTDGen vg = new VTDGen();
vg.parseFile(pluginXmlLocation, true);
VTDNav vn = vg.getNav();
AutoPilot ap = new AutoPilot(vn);
try {
ap.selectXPath(manage.buildXpath(curPluginBean));
XMLModifier xm = new XMLModifier(vn);
while (ap.evalXPath() != -1) {
xm.remove();
xm.insertAfterElement(manage.buildPluginData(bean));
manage.updataPluginMenu(bean);
}
FileOutputStream fos = new FileOutputStream(pluginXmlLocation);
BufferedOutputStream bos = new BufferedOutputStream(fos);
// 写入文件
xm.output(bos);
bos.close();
fos.close();
} catch (Exception e) {
LOGGER.error("", e);
}
}
use of com.ximpleware.XMLModifier in project translationstudio8 by heartsome.
the class PluginConfigurationDialog method deletePluginData.
private void deletePluginData() {
ISelection selection = tableViewer.getSelection();
if (selection != null && !selection.isEmpty() && selection instanceof StructuredSelection) {
boolean response = MessageDialog.openConfirm(getShell(), Messages.getString("dialog.PluginConfigurationDialog.msgTitle2"), Messages.getString("dialog.PluginConfigurationDialog.msg2"));
if (!response) {
return;
}
StructuredSelection structuredSelection = (StructuredSelection) selection;
@SuppressWarnings("unchecked") Iterator<PluginConfigBean> it = structuredSelection.iterator();
VTDGen vg = new VTDGen();
vg.parseFile(pluginXmlLocation, true);
VTDNav vn = vg.getNav();
AutoPilot ap = new AutoPilot(vn);
try {
XMLModifier xm = new XMLModifier(vn);
while (it.hasNext()) {
PluginConfigBean configBean = it.next();
String xpath = manage.buildXpath(configBean);
ap.selectXPath(xpath);
while (ap.evalXPath() != -1) {
xm.remove();
manage.deletePluginMenu(configBean.getId());
}
ap.resetXPath();
}
FileOutputStream fos = new FileOutputStream(pluginXmlLocation);
BufferedOutputStream bos = new BufferedOutputStream(fos);
// 写入文件
xm.output(bos);
bos.close();
fos.close();
refreshTable(null);
} catch (Exception e) {
LOGGER.error("", e);
}
} else {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.PluginConfigurationDialog.msgTitle"), Messages.getString("dialog.PluginConfigurationDialog.msg3"));
}
}
Aggregations