Search in sources :

Example 1 with XPathEvalException

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

the class LanguageConfiger method getAllLanguage.

/**
	 * 返回所有语言列表,key:code,value:<code>Language</code>
	 */
public Map<String, Language> getAllLanguage() {
    Map<String, Language> result = new HashMap<String, Language>();
    AutoPilot tempAp = new AutoPilot(vu.getVTDNav());
    String codeAttr = "code";
    String bidiAttr = "bidi";
    String imgAttr = "image";
    String bidiYes = "Yes";
    try {
        tempAp.selectXPath("/languages/lang");
        while (tempAp.evalXPath() != -1) {
            Map<String, String> attrs = vu.getCurrentElementAttributs();
            String code = attrs.get(codeAttr);
            String bidi = attrs.get(bidiAttr);
            String img = attrs.get(imgAttr);
            String langName = vu.getElementPureText();
            boolean isBidi = false;
            if (code != null && langName != null) {
                if (bidi != null && bidi.equals(bidiYes)) {
                    isBidi = true;
                }
                result.put(code, new Language(code, langName, img == null ? "" : img, isBidi));
            }
        }
    } catch (XPathParseException e) {
        LOGGER.error("", e);
    } catch (XPathEvalException e) {
        LOGGER.error("", e);
    } catch (NavException e) {
        LOGGER.error("", e);
    }
    return result;
}
Also used : XPathParseException(com.ximpleware.XPathParseException) Language(net.heartsome.cat.common.locale.Language) HashMap(java.util.HashMap) AutoPilot(com.ximpleware.AutoPilot) XPathEvalException(com.ximpleware.XPathEvalException) NavException(com.ximpleware.NavException)

Example 2 with XPathEvalException

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

the class LanguageConfiger method getLanguageByCode.

/**
	 * 返回Code对应的Language对象,如果在配置中找到则返回null
	 * @param code
	 * @return ;
	 */
public Language getLanguageByCode(String code) {
    AutoPilot tempAp = new AutoPilot(vu.getVTDNav());
    String bidiAttr = "bidi";
    String imgAttr = "image";
    String bidiYes = "Yes";
    try {
        tempAp.selectXPath("/languages/lang[@code='" + code + "']");
        if (tempAp.evalXPath() != -1) {
            Map<String, String> attrs = vu.getCurrentElementAttributs();
            String bidi = attrs.get(bidiAttr);
            String img = attrs.get(imgAttr);
            String langName = vu.getElementPureText();
            boolean isBidi = false;
            if (code != null && langName != null) {
                if (bidi != null && bidi.equals(bidiYes)) {
                    isBidi = true;
                }
                return new Language(code, langName, img == null ? "" : img, isBidi);
            }
        }
    } catch (XPathParseException e) {
        LOGGER.error("", e);
    } catch (XPathEvalException e) {
        LOGGER.error("", e);
    } catch (NavException e) {
        LOGGER.error("", e);
    }
    return null;
}
Also used : XPathParseException(com.ximpleware.XPathParseException) Language(net.heartsome.cat.common.locale.Language) AutoPilot(com.ximpleware.AutoPilot) XPathEvalException(com.ximpleware.XPathEvalException) NavException(com.ximpleware.NavException)

Example 3 with XPathEvalException

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

the class DocUtils method isTBX.

/**
	 * 判断是否是正确的 TBX 文件
	 * @param fileName
	 *            TBX 文件的全路径
	 * @return 反回null,验证失败
	 * @throws ParseException
	 * @throws EntityException
	 * @throws EOFException
	 * @throws EncodingException
	 * @throws FileNotFoundException
	 */
public static VTDUtils isTBX(String fileName) throws EncodingException, ParseException, FileNotFoundException {
    VTDGen vg = new VTDGen();
    FileInputStream fis = null;
    File f = null;
    try {
        f = new File(fileName);
        fis = new FileInputStream(f);
        byte[] b = new byte[(int) f.length()];
        int offset = 0;
        int numRead = 0;
        // I choose this value randomally,
        int numOfBytes = 1048576;
        // any other (not too big) value also can be here.
        if (b.length - offset < numOfBytes) {
            numOfBytes = b.length - offset;
        }
        while (offset < b.length && (numRead = fis.read(b, offset, numOfBytes)) >= 0) {
            offset += numRead;
            if (b.length - offset < numOfBytes) {
                numOfBytes = b.length - offset;
            }
        }
        vg.setDoc(b);
        vg.parse(true);
    } catch (IOException e) {
        LOGGER.error(Messages.getString("document.DocUtils.logger1"), e);
    } finally {
        if (fis != null) {
            try {
                fis.close();
            } catch (Exception e) {
            }
        }
    }
    VTDNav vn = vg.getNav();
    AutoPilot ap = new AutoPilot(vn);
    String rootPath = "/martif";
    VTDUtils vtdUtils = new VTDUtils();
    try {
        vtdUtils.bind(vn);
        ap.selectXPath(rootPath);
        if (ap.evalXPath() == -1) {
            // } else {
            return null;
        }
    } catch (NavException e) {
        LOGGER.error(Messages.getString("document.DocUtils.logger2"), e);
        return null;
    } catch (XPathEvalException e) {
        LOGGER.error(Messages.getString("document.DocUtils.logger2"), e);
        return null;
    } catch (XPathParseException e) {
        LOGGER.error(Messages.getString("document.DocUtils.logger2"), e);
        return null;
    } finally {
        vg.clear();
    }
    return vtdUtils;
}
Also used : NavException(com.ximpleware.NavException) XPathEvalException(com.ximpleware.XPathEvalException) VTDGen(com.ximpleware.VTDGen) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) EOFException(com.ximpleware.EOFException) XPathParseException(com.ximpleware.XPathParseException) NavException(com.ximpleware.NavException) IOException(java.io.IOException) EncodingException(com.ximpleware.EncodingException) FileNotFoundException(java.io.FileNotFoundException) ParseException(com.ximpleware.ParseException) XPathEvalException(com.ximpleware.XPathEvalException) EntityException(com.ximpleware.EntityException) XPathParseException(com.ximpleware.XPathParseException) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) File(java.io.File) VTDNav(com.ximpleware.VTDNav)

Example 4 with XPathEvalException

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

the class XliffUtil method getLangPairOfFile.

/**
	 * @param xlfFile
	 * @param filePath
	 * @return String[] 第一个元素为源语言,第二个为目标语言
	 */
public static String[] getLangPairOfFile(String xlfFile, String filePath) {
    VTDUtils vu = getVU(xlfFile);
    String xpath = "/xliff/file[@original=\"" + filePath + "\"]";
    String[] langPair = new String[2];
    try {
        langPair[0] = vu.getElementAttribute(xpath, "source-language");
        langPair[1] = vu.getElementAttribute(xpath, "target-language");
    } catch (XPathParseException e) {
        e.printStackTrace();
    } catch (XPathEvalException e) {
        e.printStackTrace();
    } catch (NavException e) {
        e.printStackTrace();
    }
    return langPair;
}
Also used : XPathParseException(com.ximpleware.XPathParseException) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) XPathEvalException(com.ximpleware.XPathEvalException) NavException(com.ximpleware.NavException)

Example 5 with XPathEvalException

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

the class XliffUtil method getOriginalFiles.

/**
	 * @param vu
	 *            XLIFF 文件对应的 VTDUtils
	 * @return List&lt;String&gt;
	 */
public static List<String> getOriginalFiles(VTDUtils vu) {
    ArrayList<String> list = new ArrayList<String>();
    String xpath = "/xliff/file";
    AutoPilot ap = new AutoPilot(vu.getVTDNav());
    try {
        ap.selectXPath(xpath);
        while (ap.evalXPath() != -1) {
            list.add(vu.getElementAttribute(".", "original"));
        }
    } catch (XPathParseException e) {
        e.printStackTrace();
    } catch (XPathEvalException e) {
        e.printStackTrace();
    } catch (NavException e) {
        e.printStackTrace();
    }
    return list;
}
Also used : XPathParseException(com.ximpleware.XPathParseException) AutoPilot(com.ximpleware.AutoPilot) ArrayList(java.util.ArrayList) XPathEvalException(com.ximpleware.XPathEvalException) NavException(com.ximpleware.NavException)

Aggregations

NavException (com.ximpleware.NavException)65 XPathEvalException (com.ximpleware.XPathEvalException)65 XPathParseException (com.ximpleware.XPathParseException)65 AutoPilot (com.ximpleware.AutoPilot)59 VTDNav (com.ximpleware.VTDNav)44 VTDUtils (net.heartsome.xml.vtdimpl.VTDUtils)36 ModifyException (com.ximpleware.ModifyException)17 ArrayList (java.util.ArrayList)17 XMLModifier (com.ximpleware.XMLModifier)15 IOException (java.io.IOException)15 UnsupportedEncodingException (java.io.UnsupportedEncodingException)13 VTDGen (com.ximpleware.VTDGen)11 HashMap (java.util.HashMap)9 ParseException (com.ximpleware.ParseException)8 TranscodeException (com.ximpleware.TranscodeException)7 FileNotFoundException (java.io.FileNotFoundException)7 FileOutputStream (java.io.FileOutputStream)6 EOFException (com.ximpleware.EOFException)5 EncodingException (com.ximpleware.EncodingException)5 EntityException (com.ximpleware.EntityException)5