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();
}
}
}
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);
}
}
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);
}
}
Aggregations