Search in sources :

Example 6 with ParseException

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

the class TextUtil method loadLanguages.

private static void loadLanguages() {
    descriptions = null;
    isBidi = null;
    descriptions = new Hashtable<String, String>();
    isBidi = new Hashtable<String, String>();
    String strFile = CoreActivator.LANGUAGE_CODE_PATH;
    VTDGen vg = new VTDGen();
    try {
        vg.setDoc(readBytesFromIS(CoreActivator.getConfigurationFileInputStream(strFile)));
        vg.parse(true);
        VTDNav vn = vg.getNav();
        VTDUtils vu = new VTDUtils(vn);
        AutoPilot ap = new AutoPilot(vn);
        ap.selectXPath("/languages/lang");
        int codeIndex;
        String code = null;
        int bidiIndex;
        String bidi = null;
        String langName;
        while ((ap.evalXPath()) != -1) {
            codeIndex = vn.getAttrVal("code");
            if (codeIndex != -1) {
                code = vn.toString(codeIndex);
            }
            bidiIndex = vn.getAttrVal("bidi");
            if (bidiIndex != -1) {
                bidi = vn.toString(bidiIndex);
            }
            langName = vu.getElementPureText();
            if (code != null && langName != null) {
                descriptions.put(code, langName);
            }
            if (code != null && bidi != null) {
                isBidi.put(code, bidi);
            }
        }
        ap.resetXPath();
    } catch (NavException e) {
        if (LOGGER.isErrorEnabled()) {
            String msg = Messages.getString("util.TextUtil.logger1");
            Object[] args = { strFile };
            LOGGER.error(new MessageFormat(msg).format(args), e);
        }
    } catch (XPathParseException e) {
        if (LOGGER.isErrorEnabled()) {
            String msg = Messages.getString("util.TextUtil.logger1");
            Object[] args = { strFile };
            LOGGER.error(new MessageFormat(msg).format(args), e);
        }
    } catch (XPathEvalException e) {
        if (LOGGER.isErrorEnabled()) {
            String msg = Messages.getString("util.TextUtil.logger1");
            Object[] args = { strFile };
            LOGGER.error(new MessageFormat(msg).format(args), e);
        }
    } catch (EncodingException e) {
        if (LOGGER.isErrorEnabled()) {
            String msg = Messages.getString("util.TextUtil.logger1");
            Object[] args = { strFile };
            LOGGER.error(new MessageFormat(msg).format(args), e);
        }
    } catch (EOFException e) {
        if (LOGGER.isErrorEnabled()) {
            String msg = Messages.getString("util.TextUtil.logger1");
            Object[] args = { strFile };
            LOGGER.error(new MessageFormat(msg).format(args), e);
        }
    } catch (EntityException e) {
        if (LOGGER.isErrorEnabled()) {
            String msg = Messages.getString("util.TextUtil.logger1");
            Object[] args = { strFile };
            LOGGER.error(new MessageFormat(msg).format(args), e);
        }
    } catch (ParseException e) {
        if (LOGGER.isErrorEnabled()) {
            String msg = Messages.getString("util.TextUtil.logger1");
            Object[] args = { strFile };
            LOGGER.error(new MessageFormat(msg).format(args), e);
        }
    } catch (IOException e) {
        if (LOGGER.isErrorEnabled()) {
            String msg = Messages.getString("util.TextUtil.logger1");
            Object[] args = { strFile };
            LOGGER.error(new MessageFormat(msg).format(args), e);
        }
    } finally {
        vg.clear();
    }
}
Also used : MessageFormat(java.text.MessageFormat) EncodingException(com.ximpleware.EncodingException) NavException(com.ximpleware.NavException) XPathEvalException(com.ximpleware.XPathEvalException) EntityException(com.ximpleware.EntityException) VTDGen(com.ximpleware.VTDGen) IOException(java.io.IOException) XPathParseException(com.ximpleware.XPathParseException) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) EOFException(com.ximpleware.EOFException) XPathParseException(com.ximpleware.XPathParseException) ParseException(com.ximpleware.ParseException) VTDNav(com.ximpleware.VTDNav)

Example 7 with ParseException

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

the class TextUtil method loadCountries.

private static void loadCountries() {
    String strFile = CoreActivator.ISO3166_1_PAHT;
    countries = new Hashtable<String, String>();
    VTDGen vg = new VTDGen();
    try {
        vg.setDoc(readBytesFromIS(CoreActivator.getConfigurationFileInputStream(strFile)));
        vg.parse(true);
        VTDNav vn = vg.getNav();
        VTDUtils vu = new VTDUtils(vn);
        AutoPilot ap = new AutoPilot(vn);
        ap.selectXPath("/ISO_3166-1_List_en/ISO_3166-1_Entry");
        while ((ap.evalXPath()) != -1) {
            countries.put(vu.getChildContent("ISO_3166-1_Alpha-2_Code_element"), vu.getChildContent("ISO_3166-1_Country_name"));
        }
        ap.resetXPath();
    } catch (NavException e) {
        if (LOGGER.isErrorEnabled()) {
            String msg = Messages.getString("util.TextUtil.logger1");
            Object[] args = { strFile };
            LOGGER.error(new MessageFormat(msg).format(args), e);
        }
    } catch (XPathParseException e) {
        if (LOGGER.isErrorEnabled()) {
            String msg = Messages.getString("util.TextUtil.logger1");
            Object[] args = { strFile };
            LOGGER.error(new MessageFormat(msg).format(args), e);
        }
    } catch (XPathEvalException e) {
        if (LOGGER.isErrorEnabled()) {
            String msg = Messages.getString("util.TextUtil.logger1");
            Object[] args = { strFile };
            LOGGER.error(new MessageFormat(msg).format(args), e);
        }
    } catch (EncodingException e) {
        if (LOGGER.isErrorEnabled()) {
            String msg = Messages.getString("util.TextUtil.logger1");
            Object[] args = { strFile };
            LOGGER.error(new MessageFormat(msg).format(args), e);
        }
    } catch (EOFException e) {
        if (LOGGER.isErrorEnabled()) {
            String msg = Messages.getString("util.TextUtil.logger1");
            Object[] args = { strFile };
            LOGGER.error(new MessageFormat(msg).format(args), e);
        }
    } catch (EntityException e) {
        if (LOGGER.isErrorEnabled()) {
            String msg = Messages.getString("util.TextUtil.logger1");
            Object[] args = { strFile };
            LOGGER.error(new MessageFormat(msg).format(args), e);
        }
    } catch (ParseException e) {
        if (LOGGER.isErrorEnabled()) {
            String msg = Messages.getString("util.TextUtil.logger1");
            Object[] args = { strFile };
            LOGGER.error(new MessageFormat(msg).format(args), e);
        }
    } catch (IOException e) {
        if (LOGGER.isErrorEnabled()) {
            String msg = Messages.getString("util.TextUtil.logger1");
            Object[] args = { strFile };
            LOGGER.error(new MessageFormat(msg).format(args), e);
        }
    } finally {
        vg.clear();
    }
}
Also used : MessageFormat(java.text.MessageFormat) EncodingException(com.ximpleware.EncodingException) NavException(com.ximpleware.NavException) XPathEvalException(com.ximpleware.XPathEvalException) EntityException(com.ximpleware.EntityException) VTDGen(com.ximpleware.VTDGen) IOException(java.io.IOException) XPathParseException(com.ximpleware.XPathParseException) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) EOFException(com.ximpleware.EOFException) XPathParseException(com.ximpleware.XPathParseException) ParseException(com.ximpleware.ParseException) VTDNav(com.ximpleware.VTDNav)

Example 8 with ParseException

use of com.ximpleware.ParseException 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 9 with ParseException

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

the class ImportAbstract method doImport.

/**
	 * 导入文件内容
	 * @param fileContent
	 * @param srcLang
	 * @param monitor
	 * @return ;
	 * @throws ImportException
	 */
public int doImport(String fileContent, String srcLang, IProgressMonitor monitor) throws ImportException {
    if (monitor == null) {
        this.monitor = new NullProgressMonitor();
    } else {
        this.monitor = monitor;
    }
    // 解析文件
    String message = "";
    VTDGen vg = new VTDGen();
    vg.setDoc(fileContent.getBytes());
    try {
        vg.parse(true);
    } catch (EncodingException e) {
        logger.error(Messages.getString("document.ImportAbstract.logger1"), e);
        message = Messages.getString("document.ImportAbstract.msg1");
        throw new ImportException(message + e.getMessage());
    } catch (EOFException e) {
        logger.error("", e);
        message = Messages.getString("document.ImportAbstract.tbx.msg1");
        throw new ImportException(message + e.getMessage());
    } catch (EntityException e) {
        logger.error("", e);
        message = Messages.getString("document.ImportAbstract.tbx.msg1");
        throw new ImportException(message + e.getMessage());
    } catch (ParseException e) {
        logger.error(Messages.getString("document.ImportAbstract.logger3"), e);
        String errMsg = e.getMessage();
        if (errMsg.indexOf("invalid encoding") != -1) {
            // 编码异常
            message = Messages.getString("document.ImportAbstract.msg1");
        } else {
            message = Messages.getString("document.ImportAbstract.tbx.msg1");
        }
        throw new ImportException(message + e.getMessage());
    }
    try {
        // 构建VTD解析工具
        vu = new VTDUtils(vg.getNav());
        dbOperator.beginTransaction();
        // 执行导入
        executeImport(srcLang);
        dbOperator.commit();
    } catch (VTDException e) {
        logger.error("", e);
        try {
            dbOperator.rollBack();
        } catch (SQLException e1) {
            logger.error("", e);
        }
        return FAILURE_4;
    } catch (SQLException e) {
        logger.error("", e);
        try {
            dbOperator.rollBack();
        } catch (SQLException e1) {
            logger.error("", e1);
        }
        throw new ImportException(Messages.getString("document.ImportAbstract.tbx.importDbError") + e.getMessage());
    } catch (OperationCanceledException e) {
        logger.error("", e);
        try {
            dbOperator.rollBack();
        } catch (SQLException e1) {
            logger.error("", e1);
            return CANCEL;
        }
    } catch (Exception e) {
        logger.error("", e);
        try {
            dbOperator.rollBack();
        } catch (SQLException e1) {
            logger.error("", e1);
        }
        throw new ImportException(Messages.getString("document.ImportAbstract.tbx.importDbError") + e.getMessage());
    }
    return SUCCESS;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) EncodingException(com.ximpleware.EncodingException) SQLException(java.sql.SQLException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) EntityException(com.ximpleware.EntityException) VTDGen(com.ximpleware.VTDGen) NavException(com.ximpleware.NavException) EncodingException(com.ximpleware.EncodingException) SQLException(java.sql.SQLException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ImportException(net.heartsome.cat.common.core.exception.ImportException) TranscodeException(com.ximpleware.TranscodeException) XPathEvalException(com.ximpleware.XPathEvalException) EOFException(com.ximpleware.EOFException) XPathParseException(com.ximpleware.XPathParseException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ModifyException(com.ximpleware.ModifyException) ParseException(com.ximpleware.ParseException) VTDException(com.ximpleware.VTDException) EntityException(com.ximpleware.EntityException) ImportException(net.heartsome.cat.common.core.exception.ImportException) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) VTDException(com.ximpleware.VTDException) EOFException(com.ximpleware.EOFException) XPathParseException(com.ximpleware.XPathParseException) ParseException(com.ximpleware.ParseException)

Example 10 with ParseException

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

the class XLPHandler method saveXliffInfo.

/**
	 * 保存 XLIFF 信息
	 * @param xliffInfo
	 *            XLIFF 信息 ;
	 */
public void saveXliffInfo(List<? extends Map<String, String>> xliffInfo) {
    try {
        XMLModifier xm = new XMLModifier(vn);
        AutoPilot ap = new AutoPilot(vn);
        StringBuffer items = new StringBuffer();
        String pattern = "<item {0}=\"{1}\" {2}=\"{3}\" />";
        ap.selectXPath("/xlfedit-project");
        if (ap.evalXPath() != -1) {
            for (Map<String, String> map : xliffInfo) {
                vn.push();
                String xliff = map.get(ATTR_XLIFF);
                String tgtEnc = map.get(ATTR_TGT_ENC);
                String xpath = "./item[@" + ATTR_XLIFF + "='" + xliff + "']";
                ap.selectXPath(xpath);
                if (ap.evalXPath() != -1) {
                    updateAttribute(xm, ATTR_TGT_ENC, tgtEnc);
                } else {
                    String item = MessageFormat.format(pattern, ATTR_XLIFF, xliff, ATTR_TGT_ENC, tgtEnc);
                    items.append(item).append(LINE_SEPARATOR);
                }
                vn.pop();
            }
            if (items.length() > 1) {
                xm.insertBeforeTail(items.toString());
            }
            save(xm);
        }
    } catch (NavException e) {
        LOGGER.error("", e);
        e.printStackTrace();
    } catch (ParseException e) {
        LOGGER.error("", e);
        e.printStackTrace();
    } catch (TranscodeException e) {
        LOGGER.error("", e);
        e.printStackTrace();
    } catch (ModifyException e) {
        LOGGER.error("", e);
        e.printStackTrace();
    } catch (IOException e) {
        LOGGER.error("", e);
        e.printStackTrace();
    } catch (XPathParseException e) {
        LOGGER.error("", e);
        e.printStackTrace();
    } catch (XPathEvalException e) {
        LOGGER.error("", e);
        e.printStackTrace();
    }
}
Also used : XPathParseException(com.ximpleware.XPathParseException) XMLModifier(com.ximpleware.XMLModifier) AutoPilot(com.ximpleware.AutoPilot) NavException(com.ximpleware.NavException) XPathEvalException(com.ximpleware.XPathEvalException) ModifyException(com.ximpleware.ModifyException) XPathParseException(com.ximpleware.XPathParseException) ParseException(com.ximpleware.ParseException) IOException(java.io.IOException) TranscodeException(com.ximpleware.TranscodeException)

Aggregations

ParseException (com.ximpleware.ParseException)15 XPathParseException (com.ximpleware.XPathParseException)14 NavException (com.ximpleware.NavException)13 IOException (java.io.IOException)13 XPathEvalException (com.ximpleware.XPathEvalException)11 VTDGen (com.ximpleware.VTDGen)10 AutoPilot (com.ximpleware.AutoPilot)9 VTDUtils (net.heartsome.xml.vtdimpl.VTDUtils)8 EncodingException (com.ximpleware.EncodingException)7 ModifyException (com.ximpleware.ModifyException)7 TranscodeException (com.ximpleware.TranscodeException)7 EOFException (com.ximpleware.EOFException)6 EntityException (com.ximpleware.EntityException)6 VTDNav (com.ximpleware.VTDNav)5 XMLModifier (com.ximpleware.XMLModifier)5 FileInputStream (java.io.FileInputStream)4 FileNotFoundException (java.io.FileNotFoundException)4 MessageFormat (java.text.MessageFormat)3 VTDException (com.ximpleware.VTDException)2 File (java.io.File)2