本文整理汇总了Java中com.ximpleware.VTDGen.enableIgnoredWhiteSpace方法的典型用法代码示例。如果您正苦于以下问题:Java VTDGen.enableIgnoredWhiteSpace方法的具体用法?Java VTDGen.enableIgnoredWhiteSpace怎么用?Java VTDGen.enableIgnoredWhiteSpace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ximpleware.VTDGen
的用法示例。
在下文中一共展示了VTDGen.enableIgnoredWhiteSpace方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insertVersionIntoOriginalIfNecessary
import com.ximpleware.VTDGen; //导入方法依赖的package包/类
private void insertVersionIntoOriginalIfNecessary(final String pOwnVersionOrNull)
throws ModifyException, NavException, UnsupportedEncodingException, IOException, TranscodeException {
if (pOwnVersionOrNull != null) {
final VTDGen gen = new VTDGen();
gen.enableIgnoredWhiteSpace(true);
final XMLModifier modifier = new XMLModifier();
if (gen.parseFile(file.getAbsolutePath(), false)) {
final VTDNav vn = gen.getNav();
modifier.bind(vn);
if (vn.toElement(FC, ARTIFACT_ID)) {
final long l = vn.expandWhiteSpaces(vn.getElementFragment(), WS_LEADING);
final ByteArrayOutputStream out = new ByteArrayOutputStream();
vn.dumpFragment(l, out);
final String version = new String(out.toByteArray()).replaceAll(ARTIFACT_ID_PATTERN,
format(VERSION_FORMAT, pOwnVersionOrNull));
modifier.insertAfterElement(version);
}
}
try (final FileOutputStream out = new FileOutputStream(file)) {
modifier.output(out);
}
}
}
示例2: updateProjectParentVersion
import com.ximpleware.VTDGen; //导入方法依赖的package包/类
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);
}
}
示例3: updateProjectVersion
import com.ximpleware.VTDGen; //导入方法依赖的package包/类
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);
}
}
示例4: updateAllConfigurationFiles
import com.ximpleware.VTDGen; //导入方法依赖的package包/类
private void updateAllConfigurationFiles(MavenProject project, Map<String, ModelNode> extensionSchemas,
int indentationSize) throws Exception {
VTDGen gen = new VTDGen();
gen.enableIgnoredWhiteSpace(true);
gen.parseFile(project.getFile().getAbsolutePath(), true);
VTDNav nav = gen.getNav();
XMLModifier mod = new XMLModifier(nav);
AutoPilot ap = new AutoPilot(nav);
ThrowingConsumer<String> update = xpath -> {
ap.resetXPath();
ap.selectXPath(xpath);
while (ap.evalXPath() != -1) {
int textPos = nav.getText();
String configFile = nav.toString(textPos);
File newFile = updateConfigurationFile(new File(configFile), extensionSchemas, indentationSize);
if (newFile == null) {
continue;
}
mod.updateToken(textPos, newFile.getPath());
}
};
update.accept("//plugin[groupId = 'org.revapi' and artifactId = 'revapi-maven-plugin']" +
"/configuration/analysisConfigurationFiles/*[not(self::configurationFile)]");
update.accept("//plugin[groupId = 'org.revapi' and artifactId = 'revapi-maven-plugin']" +
"/configuration/analysisConfigurationFiles/configurationFile[not(roots)]/path");
update.accept("//plugin[groupId = 'org.revapi' and artifactId = 'revapi-maven-plugin']" +
"/executions/execution/configuration/analysisConfigurationFiles/*[not(self::configurationFile)]");
update.accept("//plugin[groupId = 'org.revapi' and artifactId = 'revapi-maven-plugin']" +
"/executions/execution/configuration/analysisConfigurationFiles/configurationFile[not(roots)]/path");
try (OutputStream out = new FileOutputStream(project.getFile())) {
mod.output(out);
}
}
示例5: updateAllConfigurations
import com.ximpleware.VTDGen; //导入方法依赖的package包/类
private static void updateAllConfigurations(File pomXml, Map<String, ModelNode> extensionSchemas,
int indentationSize) throws Exception {
VTDGen gen = new VTDGen();
gen.enableIgnoredWhiteSpace(true);
gen.parseFile(pomXml.getAbsolutePath(), true);
VTDNav nav = gen.getNav();
XMLModifier mod = new XMLModifier(nav);
Callable<Void> update = () -> {
int textPos = nav.getText();
String jsonConfig = nav.toRawString(textPos);
PlexusConfiguration xml = convertToXml(extensionSchemas, jsonConfig);
if (xml == null) {
return null;
}
StringWriter pretty = new StringWriter();
XmlUtil.toIndentedString(xml, indentationSize, nav.getTokenDepth(textPos), pretty);
//remove the first indentation, because text is already indented
String prettyXml = pretty.toString().substring(indentationSize * nav.getTokenDepth(textPos));
mod.insertAfterElement(prettyXml);
mod.remove();
return null;
};
AutoPilot ap = new AutoPilot(nav);
ap.selectXPath("//plugin[groupId = 'org.revapi' and artifactId = 'revapi-maven-plugin']/configuration/analysisConfiguration");
while (ap.evalXPath() != -1) {
update.call();
}
ap.resetXPath();
ap.selectXPath("//plugin[groupId = 'org.revapi' and artifactId = 'revapi-maven-plugin']/executions/execution/configuration/analysisConfiguration");
while (ap.evalXPath() != -1) {
update.call();
}
try (OutputStream out = new FileOutputStream(pomXml)) {
mod.output(out);
}
}