Search in sources :

Example 81 with AutoPilot

use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.

the class ProjectConfiger method getTermBaseDbs.

/**
	 * 获取项目的所有术语库
	 * @param isDefault
	 *            是否获取默认术语库
	 * @return 数据库参数列表List<DatabaseModelBean> {@link DatabaseModelBean};;
	 */
public List<DatabaseModelBean> getTermBaseDbs(boolean isDefault) {
    List<DatabaseModelBean> dbList = new ArrayList<DatabaseModelBean>();
    try {
        AutoPilot ap = new AutoPilot(vu.getVTDNav());
        if (isDefault) {
            ap.selectXPath("/projectDescription/hs/tb/db[@default='Y']");
        } else {
            ap.selectXPath("/projectDescription/hs/tb/db");
        }
        while (ap.evalXPath() != -1) {
            DatabaseModelBean dbm = new DatabaseModelBean();
            String defaultAttr = vu.getCurrentElementAttribut("default", "N");
            if (defaultAttr.equals("Y")) {
                dbm.setDefault(true);
            } else {
                dbm.setDefault(false);
            }
            dbm.setDbType(vu.getChildContent("type"));
            dbm.setDbName(vu.getChildContent("name"));
            dbm.setItlDBLocation(vu.getChildContent("location"));
            dbm.setInstance(vu.getChildContent("instance"));
            dbm.setHost(vu.getChildContent("server"));
            dbm.setPort(vu.getChildContent("port"));
            dbm.setUserName(vu.getChildContent("user"));
            dbm.setPassword(DESImpl.decrypt(vu.getChildContent("password")));
            String hasMatch = vu.getChildContent("hasmatch");
            if (hasMatch.equals("true")) {
                dbm.setHasMatch(true);
            } else {
                dbm.setHasMatch(false);
            }
            dbList.add(dbm);
        }
    } catch (Exception e) {
        logger.error(Messages.getString("file.ProjectConfiger.logger2"), e);
        return dbList;
    }
    return dbList;
}
Also used : AutoPilot(com.ximpleware.AutoPilot) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) ArrayList(java.util.ArrayList) 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 82 with AutoPilot

use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.

the class ProjectConfiger method getDefaultTMDb.

/**
	 * 获取当前项目的默认的记忆库,default='Y'
	 * @return 返回{@link DatabaseModelBean};
	 */
public DatabaseModelBean getDefaultTMDb() {
    try {
        AutoPilot ap = new AutoPilot(vu.getVTDNav());
        ap.selectXPath("/projectDescription/hs/tm/db[@default='Y']");
        if (ap.evalXPath() != -1) {
            DatabaseModelBean dbm = new DatabaseModelBean();
            dbm.setDefault(true);
            dbm.setDbType(vu.getChildContent("type"));
            dbm.setDbName(vu.getChildContent("name"));
            dbm.setItlDBLocation(vu.getChildContent("location"));
            dbm.setInstance(vu.getChildContent("instance"));
            dbm.setHost(vu.getChildContent("server"));
            dbm.setPort(vu.getChildContent("port"));
            dbm.setUserName(vu.getChildContent("user"));
            dbm.setPassword(DESImpl.decrypt(vu.getChildContent("password")));
            String hasMatch = vu.getChildContent("hasmatch");
            if (hasMatch.equals("true")) {
                dbm.setHasMatch(true);
            } else {
                dbm.setHasMatch(false);
            }
            return dbm;
        }
    } catch (Exception e) {
        logger.error(Messages.getString("file.ProjectConfiger.logger4"), e);
        return null;
    }
    return null;
}
Also used : AutoPilot(com.ximpleware.AutoPilot) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) 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 83 with AutoPilot

use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.

the class ProjectConfiger method getFieldMap.

/**
	 * 获取配置文件中的项目文本字段信息
	 * @return
	 * @throws XPathParseException
	 * @throws XPathEvalException
	 * @throws NavException ;
	 */
private LinkedHashMap<String, String> getFieldMap() throws XPathParseException, XPathEvalException, NavException {
    AutoPilot ap = new AutoPilot(vu.getVTDNav());
    Map<String, String> mapField = new HashMap<String, String>();
    ap.selectXPath("/projectDescription/hs//fieldList/field");
    while (ap.evalXPath() != -1) {
        String fieldName = TextUtil.stringToXML(vu.getCurrentElementAttribut("name", ""));
        String fieldValue = vu.getElementContent();
        mapField.put(fieldName, fieldValue);
    }
    List<Entry<String, String>> lstAttr = new ArrayList<Entry<String, String>>(mapField.entrySet());
    final Collator collatorChinese = Collator.getInstance(java.util.Locale.CHINA);
    Collections.sort(lstAttr, new Comparator<Entry<String, String>>() {

        public int compare(Entry<String, String> arg0, Entry<String, String> arg1) {
            return collatorChinese.compare(arg0.getKey(), arg1.getKey());
        }
    });
    LinkedHashMap<String, String> linkedMapAttr = new LinkedHashMap<String, String>();
    for (Entry<String, String> entry : lstAttr) {
        linkedMapAttr.put(entry.getKey(), entry.getValue());
    }
    return linkedMapAttr;
}
Also used : Entry(java.util.Map.Entry) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AutoPilot(com.ximpleware.AutoPilot) ArrayList(java.util.ArrayList) Collator(java.text.Collator) LinkedHashMap(java.util.LinkedHashMap)

Example 84 with AutoPilot

use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.

the class QAXmlHandler method getAllRowIdsByLanguages.

/**
	 * 通过源与目标语言得到所有当前打开的文件包含的 RowId
	 * ///xliff/file//descendant::trans-unit[(source/text()!='' or source/*)]
	 * @return ;
	 */
public List<String> getAllRowIdsByLanguages(String srcLanguage, String tgtLanguage) {
    List<String> allRowIds = new LinkedList<String>();
    AutoPilot ap = new AutoPilot();
    ap.declareXPathNameSpace("xml", VTDUtils.XML_NAMESPACE_URL);
    ap.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
    VTDUtils vu = new VTDUtils();
    for (Entry<String, VTDNav> entry : vnMap.entrySet()) {
        String fileName = entry.getKey();
        VTDNav vn = entry.getValue();
        ap.bind(vn);
        try {
            vu.bind(vn);
            // 查询相同目标与相同源文本的tu
            String XPATH_ALL_TU_BYLANGUAGE = "/xliff/file[upper-case(@source-language)=''{0}'' and upper-case(@target-language)=''{1}'']/body/descendant::trans-unit[(source/text()!='''' or source/*)]";
            String xpath = MessageFormat.format(XPATH_ALL_TU_BYLANGUAGE, new Object[] { srcLanguage, tgtLanguage });
            ap.selectXPath(xpath);
            while (ap.evalXPath() != -1) {
                String rowId = RowIdUtil.getRowId(vn, fileName);
                if (rowId != null) {
                    allRowIds.add(rowId);
                }
            }
        } catch (NavException e) {
            e.printStackTrace();
            logger.error(Messages.getString("qa.QAXmlHandler.logger11"), e);
        } catch (XPathParseException e) {
            e.printStackTrace();
            logger.error(Messages.getString("qa.QAXmlHandler.logger9"), e);
        } catch (XPathEvalException e) {
            e.printStackTrace();
            logger.error(Messages.getString("qa.QAXmlHandler.logger10"), e);
        }
    }
    return allRowIds;
}
Also used : XPathParseException(com.ximpleware.XPathParseException) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) NavException(com.ximpleware.NavException) XPathEvalException(com.ximpleware.XPathEvalException) VTDNav(com.ximpleware.VTDNav) LinkedList(java.util.LinkedList)

Example 85 with AutoPilot

use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.

the class QAXmlHandler method getFilteredTUContent.

/**
	 * 获取trans-unit节点过滤后的source和target节点的文本内容(不去掉标记),过滤条件为不包括上下文匹配,不包括完全匹配,不包括已锁文本,过滤条件在首选项中设置
	 * @return	Map<String, String >	两个键值对,srcContent --> 源文本的文本,tarContent --> 目标文本的文本
	 * 如果返回的是null,则标志source节点无内容,这对与行号就不自增
	 */
public Map<String, String> getFilteredTUContent(String xlfPath, String nodeXpath, Map<String, Boolean> filterMap) {
    Map<String, String> tuTextMap = new HashMap<String, String>();
    VTDNav vn = vnMap.get(xlfPath);
    AutoPilot ap = new AutoPilot(vn);
    Assert.isNotNull(vn, Messages.getString("qa.QAXmlHandler.msg1") + xlfPath);
    AutoPilot childAp = new AutoPilot(vn);
    try {
        VTDUtils vUtils = new VTDUtils(vn);
        ap.selectXPath(nodeXpath);
        while (ap.evalXPath() != -1) {
            vn.push();
            //取出源文本的纯文本之前,先查看其内容是否为空,若为空,则返回,没有source节点,也返回null
            childAp.selectXPath("./source");
            if (childAp.evalXPath() != -1) {
                //因为标准里面只有一个source,因此此处用if不用while
                String srcContent = vUtils.getElementContent();
                //如果源文本为空或无值,则返回null
                if (srcContent == null || "".equals(srcContent)) {
                    return null;
                }
            } else {
                return null;
            }
            childAp.resetXPath();
            vn.pop();
            //首先过滤,如果有不应包括的文本段,则返回空
            if (!filterTheTU(vn, filterMap)) {
                return tuTextMap;
            }
            //下面获取目标文本的纯文本,在之前先检查目标文本是否为空或为空值,若是,则返回null,若没有target节点,也返回空
            childAp.selectXPath("./target");
            if (childAp.evalXPath() != -1) {
                //因为标准里面只有一个target,因此此处用if不用while
                String tarContent = vUtils.getElementContent();
                //如果源文本为空或无值,则返回null
                if (tarContent == null || "".equals(tarContent)) {
                    return tuTextMap;
                } else {
                    //两个检查项中的忽略标记,若有一项为true,那么就必须获取纯文本
                    tuTextMap.clear();
                }
            } else {
                return tuTextMap;
            }
            childAp.resetXPath();
        }
    } catch (Exception e) {
        logger.error(Messages.getString("qa.QAXmlHandler.logger13"), e);
    }
    return tuTextMap;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) VTDNav(com.ximpleware.VTDNav) NavException(com.ximpleware.NavException) CoreException(org.eclipse.core.runtime.CoreException) TranscodeException(com.ximpleware.TranscodeException) XPathEvalException(com.ximpleware.XPathEvalException) XPathParseException(com.ximpleware.XPathParseException) IOException(java.io.IOException) ModifyException(com.ximpleware.ModifyException)

Aggregations

AutoPilot (com.ximpleware.AutoPilot)308 VTDNav (com.ximpleware.VTDNav)173 NavException (com.ximpleware.NavException)150 XPathParseException (com.ximpleware.XPathParseException)145 XPathEvalException (com.ximpleware.XPathEvalException)137 VTDUtils (net.heartsome.xml.vtdimpl.VTDUtils)112 IOException (java.io.IOException)103 ModifyException (com.ximpleware.ModifyException)95 TranscodeException (com.ximpleware.TranscodeException)82 CoreException (org.eclipse.core.runtime.CoreException)76 UnsupportedEncodingException (java.io.UnsupportedEncodingException)58 VTDGen (com.ximpleware.VTDGen)50 FileNotFoundException (java.io.FileNotFoundException)49 XMLModifier (com.ximpleware.XMLModifier)46 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)44 ArrayList (java.util.ArrayList)42 HashMap (java.util.HashMap)39 XQException (javax.xml.xquery.XQException)37 LinkedHashMap (java.util.LinkedHashMap)34 LinkedList (java.util.LinkedList)25