Search in sources :

Example 16 with TranscodeException

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

the class LanguageConfiger method saveToFile.

/**
	 * 保存文件
	 * @param xm
	 *            XMLModifier对象
	 * @param fileName
	 *            文件名
	 * @return 是否保存成功;
	 */
private boolean saveToFile(XMLModifier xm, File file) {
    try {
        FileOutputStream fos = new FileOutputStream(file);
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        // 写入文件
        xm.output(bos);
        bos.close();
        fos.close();
        return true;
    } catch (ModifyException e) {
        LOGGER.error("", e);
    } catch (TranscodeException e) {
        LOGGER.error("", e);
    } catch (IOException e) {
        LOGGER.error("", e);
    }
    return false;
}
Also used : FileOutputStream(java.io.FileOutputStream) ModifyException(com.ximpleware.ModifyException) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) TranscodeException(com.ximpleware.TranscodeException)

Example 17 with TranscodeException

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

the class ExportFilterStoreConfiger method saveToFile.

/**
	 * 保存文件
	 * @param xm
	 *            XMLModifier对象
	 * @param fileName
	 *            文件名
	 * @return 是否保存成功;
	 */
private boolean saveToFile(XMLModifier xm, File file) {
    try {
        FileOutputStream fos = new FileOutputStream(file);
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        // 写入文件
        xm.output(bos);
        bos.close();
        fos.close();
        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) ModifyException(com.ximpleware.ModifyException) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) TranscodeException(com.ximpleware.TranscodeException)

Example 18 with TranscodeException

use of com.ximpleware.TranscodeException in project revapi by revapi.

the class AbstractVersionModifyingMojo method updateProjectParentVersion.

void updateProjectParentVersion(MavenProject project, Version version) throws MojoExecutionException {
    try {
        VTDGen gen = new VTDGen();
        gen.enableIgnoredWhiteSpace(true);
        gen.parseFile(project.getFile().getAbsolutePath(), true);
        VTDNav nav = gen.getNav();
        AutoPilot ap = new AutoPilot(nav);
        ap.selectXPath("namespace-uri(.)");
        String ns = ap.evalXPathToString();
        nav.toElementNS(VTDNav.FIRST_CHILD, ns, "parent");
        nav.toElementNS(VTDNav.FIRST_CHILD, ns, "version");
        int pos = nav.getText();
        XMLModifier mod = new XMLModifier(nav);
        mod.updateToken(pos, version.toString());
        try (OutputStream out = new FileOutputStream(project.getFile())) {
            mod.output(out);
        }
    } catch (IOException | ModifyException | NavException | XPathParseException | TranscodeException e) {
        throw new MojoExecutionException("Failed to update the parent version of project " + project, e);
    }
}
Also used : XMLModifier(com.ximpleware.XMLModifier) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) NavException(com.ximpleware.NavException) VTDGen(com.ximpleware.VTDGen) IOException(java.io.IOException) TranscodeException(com.ximpleware.TranscodeException) XPathParseException(com.ximpleware.XPathParseException) AutoPilot(com.ximpleware.AutoPilot) FileOutputStream(java.io.FileOutputStream) ModifyException(com.ximpleware.ModifyException) VTDNav(com.ximpleware.VTDNav)

Example 19 with TranscodeException

use of com.ximpleware.TranscodeException in project revapi by revapi.

the class AbstractVersionModifyingMojo method updateProjectVersion.

void updateProjectVersion(MavenProject project, Version version) throws MojoExecutionException {
    try {
        int indentationSize;
        try (BufferedReader rdr = new BufferedReader(new FileReader(project.getFile()))) {
            indentationSize = XmlUtil.estimateIndentationSize(rdr);
        }
        VTDGen gen = new VTDGen();
        gen.enableIgnoredWhiteSpace(true);
        gen.parseFile(project.getFile().getAbsolutePath(), true);
        VTDNav nav = gen.getNav();
        AutoPilot ap = new AutoPilot(nav);
        XMLModifier mod = new XMLModifier(nav);
        ap.selectXPath("/project/version");
        if (ap.evalXPath() != -1) {
            // found the version
            int textPos = nav.getText();
            mod.updateToken(textPos, version.toString());
        } else {
            // place the version after the artifactId
            ap.selectXPath("/project/artifactId");
            if (ap.evalXPath() == -1) {
                throw new MojoExecutionException("Failed to find artifactId element in the pom.xml of project " + project.getArtifact().getId() + " when trying to insert a version tag after it.");
            } else {
                StringBuilder versionLine = new StringBuilder();
                versionLine.append('\n');
                for (int i = 0; i < indentationSize; ++i) {
                    versionLine.append(' ');
                }
                versionLine.append("<version>").append(version.toString()).append("</version>");
                mod.insertAfterElement(versionLine.toString());
            }
        }
        try (OutputStream out = new FileOutputStream(project.getFile())) {
            mod.output(out);
        }
    } catch (IOException | ModifyException | NavException | XPathParseException | XPathEvalException | TranscodeException e) {
        throw new MojoExecutionException("Failed to update the version of project " + project, e);
    }
}
Also used : XMLModifier(com.ximpleware.XMLModifier) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) NavException(com.ximpleware.NavException) XPathEvalException(com.ximpleware.XPathEvalException) VTDGen(com.ximpleware.VTDGen) IOException(java.io.IOException) TranscodeException(com.ximpleware.TranscodeException) XPathParseException(com.ximpleware.XPathParseException) AutoPilot(com.ximpleware.AutoPilot) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) ModifyException(com.ximpleware.ModifyException) FileReader(java.io.FileReader) VTDNav(com.ximpleware.VTDNav)

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