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