Search in sources :

Example 91 with NavException

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

the class XLFHandler method deleteAltTrans.

/**
	 * 删除匹配
	 * @param xpath
	 *            alter-trans节点中的条件Xpath
	 */
public void deleteAltTrans(String xpath) {
    Map<String, List<String>> map = RowIdUtil.groupRowIdByFileName(rowIds);
    for (Entry<String, List<String>> entry : map.entrySet()) {
        try {
            VTDUtils vu = new VTDUtils(vnMap.get(entry.getKey()));
            xpath = XPATH_ALL_TU + "/alt-trans[" + xpath + "]";
            XMLModifier xm = vu.delete(xpath, VTDUtils.PILOT_TO_END);
            saveAndReparse(xm, entry.getKey());
        } catch (NavException e) {
            LOGGER.error("", e);
            e.printStackTrace();
        }
    }
}
Also used : XMLModifier(com.ximpleware.XMLModifier) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) NavException(com.ximpleware.NavException) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 92 with NavException

use of com.ximpleware.NavException 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 93 with NavException

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

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