Search in sources :

Example 66 with NavException

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

the class XLFHandler method getTgtContent.

/**
	 * 得到目标的完整内容
	 * @param rowId
	 *            行的唯一标识
	 * @return 目标的完整内容;
	 */
public String getTgtContent(String rowId) {
    String tuXPath = RowIdUtil.parseRowIdToXPath(rowId);
    VTDNav vn = getVTDNavByRowId(rowId);
    try {
        VTDUtils vu = new VTDUtils(vn);
        return vu.getValue(tuXPath + "/target/text()");
    } catch (NavException e) {
        LOGGER.error("", e);
        e.printStackTrace();
    }
    return null;
}
Also used : VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) NavException(com.ximpleware.NavException) VTDNav(com.ximpleware.VTDNav)

Example 67 with NavException

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

the class XLFHandler method getCaseTgtContent.

/** burke 为修改锁定行目标文本不能修改其大小写添加 getCaseTgtContent方法 */
/**
	 * 获取要改变大小写的target中的文本内容
	 * @param rowId
	 * @return
	 */
public String getCaseTgtContent(String rowId) {
    AutoPilot ap = new AutoPilot();
    VTDNav vn = null;
    vn = getVTDNavByRowId(rowId);
    ap.bind(vn);
    try {
        String tuXPath = RowIdUtil.parseRowIdToXPath(rowId);
        ap.selectXPath(tuXPath);
        if (ap.evalXPath() != -1) {
            int attrIndex = vn.getAttrVal("translate");
            if (attrIndex != -1) {
                String attrValue = vn.toString(attrIndex);
                if (attrValue.equals("no")) {
                    return "no";
                }
            }
        }
        ap.resetXPath();
    } catch (XPathEvalException e) {
        LOGGER.error("", e);
        e.printStackTrace();
    } catch (NavException e) {
        LOGGER.error("", e);
        e.printStackTrace();
    } catch (XPathParseException e) {
        LOGGER.error("", e);
        e.printStackTrace();
    }
    String tgt = getTgtContent(rowId);
    return tgt;
}
Also used : XPathParseException(com.ximpleware.XPathParseException) AutoPilot(com.ximpleware.AutoPilot) XPathEvalException(com.ximpleware.XPathEvalException) NavException(com.ximpleware.NavException) VTDNav(com.ximpleware.VTDNav)

Example 68 with NavException

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

the class XLFHandler method getSrcPureText.

/**
	 * 得到源的纯文本内容
	 * @param rowId
	 *            行的唯一标识
	 * @return 源的纯文本内容;
	 */
public String getSrcPureText(String rowId) {
    String tuXPath = RowIdUtil.parseRowIdToXPath(rowId);
    VTDNav vn = getVTDNavByRowId(rowId);
    try {
        VTDUtils vu = new VTDUtils(vn);
        vn.push();
        vu.pilot(tuXPath + "/source");
        String result = getTUPureText(vu.getVTDNav());
        vn.pop();
        return result;
    } catch (NavException e) {
        LOGGER.error("", e);
        e.printStackTrace();
    }
    return null;
}
Also used : VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) NavException(com.ximpleware.NavException) VTDNav(com.ximpleware.VTDNav)

Example 69 with NavException

use of com.ximpleware.NavException 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;
}
Also used : FileOutputStream(java.io.FileOutputStream) NavException(com.ximpleware.NavException) ModifyException(com.ximpleware.ModifyException) VTDGen(com.ximpleware.VTDGen) XPathParseException(com.ximpleware.XPathParseException) ParseException(com.ximpleware.ParseException) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) TranscodeException(com.ximpleware.TranscodeException)

Example 70 with NavException

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

the class ProjectConfiger method getCurrentProjectConfig.

/**
	 * 获取项目配置信息
	 * @return 指定项目配置文件中的所有信息;
	 */
public ProjectInfoBean getCurrentProjectConfig() {
    ProjectInfoBean bean = new ProjectInfoBean();
    vu.getVTDNav().push();
    AutoPilot hsAp = new AutoPilot(vu.getVTDNav());
    try {
        hsAp.selectXPath("/projectDescription/hs");
        if (hsAp.evalXPath() != -1) {
            bean.setProjectName(getProjectName());
            bean.setMapField(getFieldMap());
            bean.setMapAttr(getAttrMap());
            bean.setSourceLang(getSourceLanguage());
            bean.setTargetLang(getTargetlanguages());
            bean.setTmDb(getAllTmDbs());
            bean.setTbDb(getTermBaseDbs(false));
        }
    } catch (XPathParseException e) {
        logger.error("", e);
    } catch (XPathEvalException e) {
        logger.error("", e);
    } catch (NavException e) {
        logger.error("", e);
    }
    vu.getVTDNav().pop();
    return bean;
}
Also used : XPathParseException(com.ximpleware.XPathParseException) ProjectInfoBean(net.heartsome.cat.common.bean.ProjectInfoBean) AutoPilot(com.ximpleware.AutoPilot) XPathEvalException(com.ximpleware.XPathEvalException) NavException(com.ximpleware.NavException)

Aggregations

NavException (com.ximpleware.NavException)93 AutoPilot (com.ximpleware.AutoPilot)70 XPathParseException (com.ximpleware.XPathParseException)70 XPathEvalException (com.ximpleware.XPathEvalException)67 VTDNav (com.ximpleware.VTDNav)63 VTDUtils (net.heartsome.xml.vtdimpl.VTDUtils)58 XMLModifier (com.ximpleware.XMLModifier)31 ModifyException (com.ximpleware.ModifyException)29 ArrayList (java.util.ArrayList)22 IOException (java.io.IOException)21 VTDGen (com.ximpleware.VTDGen)17 UnsupportedEncodingException (java.io.UnsupportedEncodingException)13 HashMap (java.util.HashMap)13 TranscodeException (com.ximpleware.TranscodeException)12 ParseException (com.ximpleware.ParseException)11 FileOutputStream (java.io.FileOutputStream)11 List (java.util.List)10 LinkedList (java.util.LinkedList)9 FileNotFoundException (java.io.FileNotFoundException)8 LinkedHashMap (java.util.LinkedHashMap)8