Search in sources :

Example 11 with XMLModifier

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);
        }
    }
}
Also used : XMLModifier(com.ximpleware.XMLModifier) NavException(com.ximpleware.NavException) TranscodeException(com.ximpleware.TranscodeException) XPathEvalException(com.ximpleware.XPathEvalException) XPathParseException(com.ximpleware.XPathParseException) IOException(java.io.IOException) ModifyException(com.ximpleware.ModifyException) ParseException(com.ximpleware.ParseException)

Example 12 with XMLModifier

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);
        }
    }
}
Also used : XMLModifier(com.ximpleware.XMLModifier) NavException(com.ximpleware.NavException) TranscodeException(com.ximpleware.TranscodeException) XPathEvalException(com.ximpleware.XPathEvalException) XPathParseException(com.ximpleware.XPathParseException) IOException(java.io.IOException) ModifyException(com.ximpleware.ModifyException) ParseException(com.ximpleware.ParseException)

Example 13 with XMLModifier

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();
    }
}
Also used : XMLModifier(com.ximpleware.XMLModifier) NavException(com.ximpleware.NavException) TranscodeException(com.ximpleware.TranscodeException) XPathEvalException(com.ximpleware.XPathEvalException) XPathParseException(com.ximpleware.XPathParseException) IOException(java.io.IOException) ModifyException(com.ximpleware.ModifyException) ParseException(com.ximpleware.ParseException)

Example 14 with XMLModifier

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);
            }
        }
    }
}
Also used : XMLModifier(com.ximpleware.XMLModifier) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ModifyException(com.ximpleware.ModifyException) IOException(java.io.IOException) XPathParseException(com.ximpleware.XPathParseException) ParseException(com.ximpleware.ParseException) SearchEntry(net.heartsome.cat.ts.websearch.bean.SearchEntry) TranscodeException(com.ximpleware.TranscodeException)

Example 15 with XMLModifier

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;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) XMLModifier(com.ximpleware.XMLModifier) NavException(com.ximpleware.NavException) XPathEvalException(com.ximpleware.XPathEvalException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) TranscodeException(com.ximpleware.TranscodeException) XPathParseException(com.ximpleware.XPathParseException) PreTranslationCounter(net.heartsome.cat.ts.pretranslation.bean.PreTranslationCounter) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) FileOutputStream(java.io.FileOutputStream) ModifyException(com.ximpleware.ModifyException) VTDNav(com.ximpleware.VTDNav) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

XMLModifier (com.ximpleware.XMLModifier)80 NavException (com.ximpleware.NavException)54 VTDNav (com.ximpleware.VTDNav)53 AutoPilot (com.ximpleware.AutoPilot)50 ModifyException (com.ximpleware.ModifyException)50 XPathParseException (com.ximpleware.XPathParseException)42 VTDUtils (net.heartsome.xml.vtdimpl.VTDUtils)41 XPathEvalException (com.ximpleware.XPathEvalException)40 IOException (java.io.IOException)38 TranscodeException (com.ximpleware.TranscodeException)34 VTDGen (com.ximpleware.VTDGen)23 UnsupportedEncodingException (java.io.UnsupportedEncodingException)22 CoreException (org.eclipse.core.runtime.CoreException)17 FileNotFoundException (java.io.FileNotFoundException)15 FileOutputStream (java.io.FileOutputStream)15 ParseException (com.ximpleware.ParseException)13 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)13 ArrayList (java.util.ArrayList)12 File (java.io.File)11 XQException (javax.xml.xquery.XQException)11