Search in sources :

Example 11 with TranscodeException

use of com.ximpleware.TranscodeException 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 12 with TranscodeException

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

the class XLFHandler 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();
        IPath path = URIUtil.toPath(file.toURI());
        IFile iFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
        if (iFile != null) {
            // 同步导航视图和文件系统
            iFile.refreshLocal(IResource.DEPTH_ZERO, null);
        }
        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();
    } catch (CoreException e) {
        LOGGER.error("", e);
        e.printStackTrace();
    }
    return false;
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) FileOutputStream(java.io.FileOutputStream) ModifyException(com.ximpleware.ModifyException) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) TranscodeException(com.ximpleware.TranscodeException)

Example 13 with TranscodeException

use of com.ximpleware.TranscodeException 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)

Example 14 with TranscodeException

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

the class XLPHandler method saveSourceInfo.

/**
	 * 保存 XLIFF 信息
	 * @param sourceInfo
	 *            源文件信息 ;
	 */
public void saveSourceInfo(List<? extends Map<String, String>> sourceInfo) {
    try {
        XMLModifier xm = new XMLModifier(vn);
        AutoPilot ap = new AutoPilot(vn);
        StringBuffer items = new StringBuffer();
        String pattern = "<item {0}=\"{1}\" {2}=\"{3}\" {4}=\"{5}\" {6}=\"{7}\" />";
        ap.selectXPath("/xlfedit-project");
        if (ap.evalXPath() != -1) {
            for (Map<String, String> map : sourceInfo) {
                vn.push();
                String source = map.get(ATTR_SOURCE);
                String format = map.get(ATTR_FORMAT);
                String srcLang = map.get(ATTR_SRC_LANG);
                String srcEnc = map.get(ATTR_SRC_ENC);
                String xpath = "./item[@" + ATTR_SOURCE + "=\"" + source + "\"]";
                ap.selectXPath(xpath);
                if (ap.evalXPath() != -1) {
                    updateAttribute(xm, ATTR_FORMAT, format);
                    updateAttribute(xm, ATTR_SRC_LANG, srcLang);
                    updateAttribute(xm, ATTR_SRC_ENC, srcEnc);
                } else {
                    String item = MessageFormat.format(pattern, ATTR_SOURCE, source, ATTR_FORMAT, format, ATTR_SRC_LANG, srcLang, ATTR_SRC_ENC, srcEnc);
                    ap.selectXPath(xpath);
                    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)

Example 15 with TranscodeException

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

the class QAXmlHandler 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();
        IPath path = URIUtil.toPath(file.toURI());
        IFile iFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
        if (iFile != null) {
            // 同步导航视图和文件系统
            iFile.refreshLocal(IResource.DEPTH_ZERO, null);
        }
        return true;
    } catch (ModifyException e) {
        e.printStackTrace();
        logger.error(MessageFormat.format(Messages.getString("qa.QAXmlHandler.logger4"), file.getAbsolutePath()), e);
    } catch (TranscodeException e) {
        e.printStackTrace();
        logger.error(MessageFormat.format(Messages.getString("qa.QAXmlHandler.logger4"), file.getAbsolutePath()), e);
    } catch (IOException e) {
        e.printStackTrace();
        logger.error(MessageFormat.format(Messages.getString("qa.QAXmlHandler.logger5"), file.getAbsolutePath()), e);
    } catch (CoreException e) {
        e.printStackTrace();
        logger.error(MessageFormat.format(Messages.getString("qa.QAXmlHandler.logger6"), file.getAbsolutePath()), e);
    }
    return false;
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) FileOutputStream(java.io.FileOutputStream) ModifyException(com.ximpleware.ModifyException) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) TranscodeException(com.ximpleware.TranscodeException)

Aggregations

ModifyException (com.ximpleware.ModifyException)19 TranscodeException (com.ximpleware.TranscodeException)19 IOException (java.io.IOException)19 FileOutputStream (java.io.FileOutputStream)14 NavException (com.ximpleware.NavException)12 XPathParseException (com.ximpleware.XPathParseException)12 XMLModifier (com.ximpleware.XMLModifier)11 BufferedOutputStream (java.io.BufferedOutputStream)10 AutoPilot (com.ximpleware.AutoPilot)9 XPathEvalException (com.ximpleware.XPathEvalException)9 VTDGen (com.ximpleware.VTDGen)7 ParseException (com.ximpleware.ParseException)6 VTDNav (com.ximpleware.VTDNav)6 VTDUtils (net.heartsome.xml.vtdimpl.VTDUtils)5 FileNotFoundException (java.io.FileNotFoundException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 File (java.io.File)3 OutputStream (java.io.OutputStream)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 IFile (org.eclipse.core.resources.IFile)2