本文整理汇总了Java中nu.xom.XPathContext类的典型用法代码示例。如果您正苦于以下问题:Java XPathContext类的具体用法?Java XPathContext怎么用?Java XPathContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XPathContext类属于nu.xom包,在下文中一共展示了XPathContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: validateWithSchematron
import nu.xom.XPathContext; //导入依赖的package包/类
/**
* Performs a Schematron validation of the DDMS Resource, via the ISO Schematron skeleton stylesheets for XSLT1
* or XSLT2 processors. This action can only be performed on a DDMS Resource which is already valid according
* to the DDMS specification.
*
* <p>The informational results of this validation are returned to the caller in a list of ValidationMessages of
* type "Warning" for reports and "Error" for failed asserts. These messages do NOT affect the validity of the
* underlying object model. The locator on the ValidationMessage will be the location attribute from the
* successful-report or failed-assert element.</p>
*
* <p>Details about ISO Schematron can be found at: http://www.schematron.com/ </p>
*
* @param schematronFile the file containing the ISO Schematron constraints. This file is transformed with the ISO
* Schematron skeleton files.
* @return a list of ValidationMessages
* @throws XSLException if there are XSL problems transforming with stylesheets
* @throws IOException if there are problems reading or parsing the Schematron file
*/
public List<ValidationMessage> validateWithSchematron(InputStream schematronFile) throws XSLException, IOException {
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
XSLTransform schematronTransform = Util.buildSchematronTransform(schematronFile);
Nodes nodes = schematronTransform.transform(new Document(getXOMElementCopy()));
Document doc = XSLTransform.toDocument(nodes);
XPathContext context = XPathContext.makeNamespaceContext(doc.getRootElement());
String svrlNamespace = context.lookup("svrl");
Nodes outputNodes = doc.query("//svrl:failed-assert | //svrl:successful-report", context);
for (int i = 0; i < outputNodes.size(); i++) {
if (outputNodes.get(i) instanceof Element) {
Element outputElement = (Element) outputNodes.get(i);
boolean isAssert = "failed-assert".equals(outputElement.getLocalName());
String text = outputElement.getFirstChildElement("text", svrlNamespace).getValue();
String locator = outputElement.getAttributeValue("location");
messages.add(isAssert ? ValidationMessage.newError(text, locator) : ValidationMessage.newWarning(text,
locator));
}
}
return (messages);
}
开发者ID:imintel,项目名称:ddmsence,代码行数:40,代码来源:Resource.java
示例2: updateProperty
import nu.xom.XPathContext; //导入依赖的package包/类
void updateProperty(Document pom, String propertyName, String newVersion) throws MojoExecutionException {
XPathContext context = new XPathContext("mvn", "http://maven.apache.org/POM/4.0.0");
Nodes nodes = pom.query("//mvn:properties", context);
if (nodes.size() > 0) {
final Element propertiesElement = (Element) nodes.get(0);
Elements properties = propertiesElement.getChildElements();
for (int i = 0; i < properties.size(); i++) {
Element property = properties.get(i);
if (property.getLocalName().equals(propertyName)) {
Element newRange = new Element(propertyName, "http://maven.apache.org/POM/4.0.0");
newRange.appendChild(newVersion);
propertiesElement.replaceChild(property, newRange);
}
}
}
}
开发者ID:stickycode,项目名称:bounds-maven-plugin,代码行数:18,代码来源:StickyBoundsMojo.java
示例3: update
import nu.xom.XPathContext; //导入依赖的package包/类
@Test
public void update()
throws ValidityException, ParsingException, IOException, MojoExecutionException {
Document pom = new Builder().build(new File(new File("src/it/reflector"), "pom.xml"));
Artifact artifact = new DefaultArtifact(
"net.stickycode",
"sticky-coercion",
"jar",
"",
"[3.1,4)");
new StickyBoundsMojo().updateDependency(pom, artifact, "[3.6,4)");
XPathContext context = new XPathContext("mvn", "http://maven.apache.org/POM/4.0.0");
Nodes versions = pom.query("//mvn:version", context);
assertThat(versions.size()).isEqualTo(3);
Nodes nodes = pom.query("//mvn:version[text()='[3.6,4)']", context);
assertThat(nodes.size()).isEqualTo(1);
Node node = nodes.get(0);
assertThat(node.getValue()).isEqualTo("[3.6,4)");
}
开发者ID:stickycode,项目名称:bounds-maven-plugin,代码行数:22,代码来源:StickyBoundsMojoIntegrationTest.java
示例4: updateWithClassifier
import nu.xom.XPathContext; //导入依赖的package包/类
@Test
public void updateWithClassifier()
throws ValidityException, ParsingException, IOException, MojoExecutionException {
Document pom = new Builder().build(new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("classifiers.xml"))));
Artifact artifact = new DefaultArtifact(
"net.stickycode",
"sticky-coercion",
"jar",
"",
"[2.1,4)");
new StickyBoundsMojo().updateDependency(pom, artifact, "[2.6,3)");
XPathContext context = new XPathContext("mvn", "http://maven.apache.org/POM/4.0.0");
Nodes versions = pom.query("//mvn:version", context);
assertThat(versions.size()).isEqualTo(4);
Nodes nodes = pom.query("//mvn:version[text()='[2.6,3)']", context);
assertThat(nodes.size()).isEqualTo(1);
Node node = nodes.get(0);
assertThat(node.getValue()).isEqualTo("[2.6,3)");
}
开发者ID:stickycode,项目名称:bounds-maven-plugin,代码行数:22,代码来源:StickyBoundsMojoIntegrationTest.java
示例5: updateTheClassifier
import nu.xom.XPathContext; //导入依赖的package包/类
@Test
public void updateTheClassifier()
throws ValidityException, ParsingException, IOException, MojoExecutionException {
Document pom = new Builder().build(new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("classifiers.xml"))));
Artifact artifact = new DefaultArtifact(
"net.stickycode",
"sticky-coercion",
"jar",
"test-jar",
"[2.1,4)");
new StickyBoundsMojo().updateDependency(pom, artifact, "[2.6,3)");
XPathContext context = new XPathContext("mvn", "http://maven.apache.org/POM/4.0.0");
Nodes versions = pom.query("//mvn:version", context);
assertThat(versions.size()).isEqualTo(4);
Nodes nodes = pom.query("//mvn:version[text()='[2.6,3)']", context);
assertThat(nodes.size()).isEqualTo(1);
Node node = nodes.get(0);
assertThat(node.getValue()).isEqualTo("[2.6,3)");
}
开发者ID:stickycode,项目名称:bounds-maven-plugin,代码行数:22,代码来源:StickyBoundsMojoIntegrationTest.java
示例6: handleParagraph
import nu.xom.XPathContext; //导入依赖的package包/类
@Override
public State handleParagraph(Element matchElement, Document document,
XPathContext xPathContext) {
// found an editable paragraph?
if (matchElement.getFirstChildElement("permStart", Namespace.MAIN.toUri()) != null) { //$NON-NLS-1$
if (matchElement.getFirstChildElement("permEnd", Namespace.MAIN.toUri()) != null) { //$NON-NLS-1$
return State.SEEKPERMSTART; // yes, but since permEnd is also present we continue searching the next editable paragraph
}
return State.INPERM; // yes, so change state to search the end of the section
}
else if (DocumentUtil.hasMatch(
matchElement, "w:pPr/w:pStyle[@w:val='DH-BibliographyHeading']", xPathContext) //$NON-NLS-1$
&& (DocumentUtil.hasMatch(matchElement, "w:r", xPathContext))) { //$NON-NLS-1$
// the References section is not editable but we want to keep it and continue with searching
return State.SEEKPERMSTART;
}
else {
// remove the non editable section and continue with searching
matchElement.getParent().removeChild(matchElement);
return State.SEEKPERMSTART;
}
}
开发者ID:ADHO,项目名称:dhconvalidator,代码行数:24,代码来源:SeekPermStartHandler.java
示例7: stripTemplateSections
import nu.xom.XPathContext; //导入依赖的package包/类
public void stripTemplateSections(Document document, XPathContext xPathContext) {
// grab all paragraphs and loose permEnds (permStart is always inside a paragraph)
Nodes searchResult =
document.query("/w:document/w:body/w:p | /w:document/w:body/w:permEnd", xPathContext); //$NON-NLS-1$
// we start by looking for the first editable section start
State currentState = State.SEEKPERMSTART;
// loop over the search result
for (int i=0; i<searchResult.size(); i++) {
Element paragraphElement = (Element)searchResult.get(i);
currentState = currentState.getStateHandler().handleParagraph(
paragraphElement, document, xPathContext);
}
}
开发者ID:ADHO,项目名称:dhconvalidator,代码行数:16,代码来源:ParagraphParser.java
示例8: getFirstMatch
import nu.xom.XPathContext; //导入依赖的package包/类
/**
* @param document the document to search in
* @param query the search query
* @param xPathContext the context for the query
* @return the first match
* @throws IllegalStateException if there is no such match
*/
public static Element getFirstMatch(Document document, String query,
XPathContext xPathContext) {
Nodes nodes = document.query(query, xPathContext);
if ((nodes.size() > 0) && (nodes.get(0) instanceof Element)) {
return (Element)nodes.get(0);
}
throw new IllegalStateException(
Messages.getString("DocumentUtil.unexpectedResult")); //$NON-NLS-1$
}
开发者ID:ADHO,项目名称:dhconvalidator,代码行数:18,代码来源:DocumentUtil.java
示例9: tryFirstMatch
import nu.xom.XPathContext; //导入依赖的package包/类
/**
* @param document the document to search in
* @param query the search query
* @param xPathContext the context for the query
* @return the first match or <code>null</code> if there is no match
*/
public static Element tryFirstMatch(Document document, String query,
XPathContext xPathContext) {
Nodes nodes = document.query(query, xPathContext);
if ((nodes.size() > 0) && (nodes.get(0) instanceof Element)) {
return (Element)nodes.get(0);
}
else {
return null;
}
}
开发者ID:ADHO,项目名称:dhconvalidator,代码行数:17,代码来源:DocumentUtil.java
示例10: toXpathContext
import nu.xom.XPathContext; //导入依赖的package包/类
private XPathContext toXpathContext(NamespaceContext namespaceContext) {
XPathContext context = new XPathContext();
Iterator prefixes = namespaceContext.getPrefixes("http://www.example.com/my");
while (prefixes.hasNext()) {
String prefix = (String) prefixes.next();
context.addNamespace(prefix, namespaceContext.getNamespaceURI(prefix));
}
return context;
}
开发者ID:SimY4,项目名称:xpath-to-xml,代码行数:10,代码来源:XmlBuilderTest.java
示例11: OdtInputConverter
import nu.xom.XPathContext; //导入依赖的package包/类
public OdtInputConverter() {
// create xpathcontext with all the necessar namespaces
xPathContext = new XPathContext();
for (Namespace ns : Namespace.values()) {
xPathContext.addNamespace(
ns.getName(),
ns.toUri());
}
}
开发者ID:ADHO,项目名称:dhconvalidator,代码行数:10,代码来源:OdtInputConverter.java
示例12: handleParagraph
import nu.xom.XPathContext; //导入依赖的package包/类
@Override
public State handleParagraph(Element matchElement, Document document,
XPathContext xPathContext) {
// are we still in an editable section?
if (matchElement.getLocalName().equals("permEnd") //$NON-NLS-1$
|| matchElement.getFirstChildElement("permEnd", Namespace.MAIN.toUri()) != null) { //$NON-NLS-1$
// editable section ends here, start searching for the next one
return State.SEEKPERMSTART;
}
return State.INPERM; // still within an editable section
}
开发者ID:ADHO,项目名称:dhconvalidator,代码行数:14,代码来源:InPermHandler.java
示例13: DocxInputConverter
import nu.xom.XPathContext; //导入依赖的package包/类
public DocxInputConverter() {
xPathContext = new XPathContext();
for (Namespace ns : Namespace.values()) {
xPathContext.addNamespace(
ns.getName(),
ns.toUri());
}
}
开发者ID:ADHO,项目名称:dhconvalidator,代码行数:9,代码来源:DocxInputConverter.java
示例14: updateDependency
import nu.xom.XPathContext; //导入依赖的package包/类
private void updateDependency(Document pom, String dependencyPath, String newVersion, Artifact artifact)
throws MojoExecutionException {
XPathContext context = new XPathContext("mvn", "http://maven.apache.org/POM/4.0.0");
Nodes nodes = pom.query(dependencyPath, context);
if (nodes.size() == 0) {
throw new MojoExecutionException(String.format("Missing <dependency> element for dependency %s, skipping.",
artifact.getArtifactId()));
}
for (int i = 0; i < nodes.size(); i++) {
Node node = nodes.get(i);
ParentNode dependency = node.getParent();
Nodes classifier = dependency.query("mvn:classifier", context);
if (classifier.size() != 0)
if (!classifier.get(0).getValue().equals(artifact.getClassifier()))
return;
final Nodes versionNodes = dependency.query("mvn:version", context);
if (versionNodes.size() > 0) {
getLog().info("Updating " + artifact.toString() + " to " + newVersion);
Element version = (Element) versionNodes.get(0);
if (!version.getValue().startsWith("${") || updateProperties) {
Element newRange = new Element("version", "http://maven.apache.org/POM/4.0.0");
newRange.appendChild(newVersion);
dependency.replaceChild(version, newRange);
}
}
else {
throw new MojoExecutionException(String.format("Missing <version> element for dependency %s, skipping.",
artifact.getArtifactId()));
}
}
}
开发者ID:stickycode,项目名称:bounds-maven-plugin,代码行数:35,代码来源:StickyBoundsMojo.java
示例15: main
import nu.xom.XPathContext; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
XPathContext context = new XPathContext("xhtml", "http://www.w3.org/1999/xhtml");
Properties properties = new Properties();
properties.load(new FileInputStream(args[0]));
PropertyProvider.setProperties(properties);
ConfToolClient client = new ConfToolClient();
List<User> users = client.getUsers();
for (User user : users) {
List<Paper> papers = client.getPapers(user);
for (Paper paper : papers) {
String inputFilename =
user.getLastName().toUpperCase() + "_" + user.getFirstName()
+ "_" + paper.getTitle();
inputFilename = inputFilename.replaceAll("[^a-zA-Z_0-9]", "_");
if (inputFilename.length() > 60) {
System.out.println(user);
System.out.println(paper);
ZipFs zipFs = client.getDhcFile(user, paper);
try {
String newTitle = inputFilename.substring(0, 60);
Document htmlFile = zipFs.getDocument(inputFilename + ".html");
Element linkElement = DocumentUtil.getFirstMatch(
htmlFile, "//xhtml:a[@href='"
+ inputFilename + ".xml"
+"']", context);
linkElement.getAttribute("href").setValue(newTitle+".xml");
zipFs.putDocument(inputFilename +".html", htmlFile);
zipFs.rename(inputFilename+".html", newTitle + ".html");
zipFs.rename(inputFilename+".xml", newTitle + ".xml");
try (FileOutputStream fos = new FileOutputStream(new File(args[1], newTitle + ".dhc"))) {
fos.write(zipFs.toZipData());
}
}
catch (Exception e) {
e.printStackTrace();
try (FileOutputStream fos = new FileOutputStream(new File(args[1]+"failed/", inputFilename + ".dhc"))) {
fos.write(zipFs.toZipData());
}
}
}
}
}
// try {
// System.out.println(
// new ConfToolClient(args[0], args[1].toCharArray()).getExportData(ExportType.subsumed_authors, null, "p");
// .toXML());
// } catch (IOException e) {
// e.printStackTrace();
// }
}
开发者ID:ADHO,项目名称:dhconvalidator,代码行数:61,代码来源:ConfToolClient.java
示例16: Converter
import nu.xom.XPathContext; //导入依赖的package包/类
/**
* @param oxGarageBaseURL the URL for the OxGarage web service
* @throws IOException in case of any failure
*/
public Converter(String oxGarageBaseURL) throws IOException {
this.oxGarageBaseURL = oxGarageBaseURL;
xPathContext = new XPathContext(XHTML_NAMESPACE, XHTML_NAMESPACE_URI);
}
开发者ID:ADHO,项目名称:dhconvalidator,代码行数:9,代码来源:Converter.java
示例17: BibTeXMLEntry
import nu.xom.XPathContext; //导入依赖的package包/类
public BibTeXMLEntry(Node entry) {
this.entry = entry;
context = new XPathContext("bibtex", BibTeXMLFile.BIBTEXML_NAMESPACE);
context.addNamespace("b", BibTeXMLFile.BIBTEXML_NAMESPACE);
}
开发者ID:cdk,项目名称:cdk-build-util,代码行数:6,代码来源:BibTeXMLEntry.java
示例18: BibTeXMLFile
import nu.xom.XPathContext; //导入依赖的package包/类
public BibTeXMLFile(Node root) {
this.root = root;
context = new XPathContext("bibtex", BIBTEXML_NAMESPACE);
context.addNamespace("b", BIBTEXML_NAMESPACE);
}
开发者ID:cdk,项目名称:cdk-build-util,代码行数:6,代码来源:BibTeXMLFile.java
示例19: CommonOutputConverter
import nu.xom.XPathContext; //导入依赖的package包/类
public CommonOutputConverter() {
xPathContext = new XPathContext();
xPathContext.addNamespace(TeiNamespace.TEI.getName(), TeiNamespace.TEI.toUri());
xPathContext.addNamespace("mml", "http://www.w3.org/1998/Math/MathML");
}
开发者ID:ADHO,项目名称:dhconvalidator,代码行数:6,代码来源:CommonOutputConverter.java
示例20: handleParagraph
import nu.xom.XPathContext; //导入依赖的package包/类
/**
* @param matchElement the element that matched the original query (p or permEnd)
* @param document the docx document
* @param xPathContext query context
* @return the next current State
*/
public State handleParagraph(Element matchElement, Document document, XPathContext xPathContext);
开发者ID:ADHO,项目名称:dhconvalidator,代码行数:8,代码来源:StateHandler.java
注:本文中的nu.xom.XPathContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论