Search in sources :

Example 51 with XMLModifier

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();
    }
}
Also used : XMLModifier(com.ximpleware.XMLModifier) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) VTDNav(com.ximpleware.VTDNav) NavException(com.ximpleware.NavException) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) XPathParseException(com.ximpleware.XPathParseException) FileNotFoundException(java.io.FileNotFoundException) XQException(javax.xml.xquery.XQException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TranscodeException(com.ximpleware.TranscodeException) XPathEvalException(com.ximpleware.XPathEvalException) IOException(java.io.IOException) ModifyException(com.ximpleware.ModifyException)

Example 52 with XMLModifier

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;
}
Also used : XMLModifier(com.ximpleware.XMLModifier) File(java.io.File) VTDNav(com.ximpleware.VTDNav)

Example 53 with XMLModifier

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;
}
Also used : XMLModifier(com.ximpleware.XMLModifier) AutoPilot(com.ximpleware.AutoPilot) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) VTDGen(com.ximpleware.VTDGen) File(java.io.File) VTDNav(com.ximpleware.VTDNav) BufferedOutputStream(java.io.BufferedOutputStream)

Example 54 with XMLModifier

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);
    }
}
Also used : XMLModifier(com.ximpleware.XMLModifier) AutoPilot(com.ximpleware.AutoPilot) FileOutputStream(java.io.FileOutputStream) VTDGen(com.ximpleware.VTDGen) VTDNav(com.ximpleware.VTDNav) BufferedOutputStream(java.io.BufferedOutputStream)

Example 55 with XMLModifier

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"));
    }
}
Also used : XMLModifier(com.ximpleware.XMLModifier) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) VTDGen(com.ximpleware.VTDGen) PluginConfigBean(net.heartsome.cat.ts.ui.plugin.bean.PluginConfigBean) AutoPilot(com.ximpleware.AutoPilot) FileOutputStream(java.io.FileOutputStream) ISelection(org.eclipse.jface.viewers.ISelection) VTDNav(com.ximpleware.VTDNav) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

XMLModifier (com.ximpleware.XMLModifier)76 NavException (com.ximpleware.NavException)52 VTDNav (com.ximpleware.VTDNav)49 ModifyException (com.ximpleware.ModifyException)48 AutoPilot (com.ximpleware.AutoPilot)46 VTDUtils (net.heartsome.xml.vtdimpl.VTDUtils)41 XPathParseException (com.ximpleware.XPathParseException)40 XPathEvalException (com.ximpleware.XPathEvalException)39 IOException (java.io.IOException)35 TranscodeException (com.ximpleware.TranscodeException)32 UnsupportedEncodingException (java.io.UnsupportedEncodingException)22 VTDGen (com.ximpleware.VTDGen)19 CoreException (org.eclipse.core.runtime.CoreException)17 FileNotFoundException (java.io.FileNotFoundException)15 ParseException (com.ximpleware.ParseException)13 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)13 ArrayList (java.util.ArrayList)12 FileOutputStream (java.io.FileOutputStream)11 XQException (javax.xml.xquery.XQException)11 File (java.io.File)10