本文整理汇总了Java中nu.xom.Nodes类的典型用法代码示例。如果您正苦于以下问题:Java Nodes类的具体用法?Java Nodes怎么用?Java Nodes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Nodes类属于nu.xom包,在下文中一共展示了Nodes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Note
import nu.xom.Nodes; //导入依赖的package包/类
public Note(Nodes title, Nodes content, Nodes tags) {
super();
if (title.isEmpty()) {
throw new IllegalArgumentException();
}
this.title = extractString(title);
if (content.isEmpty()) {
this.content = "";
} else {
this.content = extractContent(content);
}
for (Node tag : tags) {
Nodes tagValue = tag.query("./text()");
if (!tagValue.hasAny()) {
continue;
}
String tagString = extractContent(tagValue);
this.tags.add(tagString);
}
}
示例2: addAttribute
import nu.xom.Nodes; //导入依赖的package包/类
@Override
@Nonnull
public ElementBuilder addAttribute(
@Nonnull final String name, @Nonnull final Optional<URI> namespace,
@Nonnull final String value, @Nonnull final Attribute.Type type) {
checkNotNull(name, "name");
checkArgument(!name.isEmpty(), "argument name is empty");
checkNotNull(namespace, "namespaceURI");
checkNotNull(value, "name");
checkNotNull(type, "type");
Nodes nodes = factory.makeAttribute(name,
namespace.isPresent() ? namespace.get().toString() : "",
value, type);
for (int i = 0; i < nodes.size(); i++) {
add(nodes.get(i));
}
return this;
}
示例3: validateWithSchematron
import nu.xom.Nodes; //导入依赖的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);
}
示例4: updateProperty
import nu.xom.Nodes; //导入依赖的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);
}
}
}
}
示例5: update
import nu.xom.Nodes; //导入依赖的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)");
}
示例6: updateWithClassifier
import nu.xom.Nodes; //导入依赖的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)");
}
示例7: removeSegs
import nu.xom.Nodes; //导入依赖的package包/类
/**
* Segments are not allowed so far, so we convert them to hi elements or remove the
* completely.
* @param document
*/
private void removeSegs(Document document) {
Nodes searchResult =
document.query(
"//tei:seg", //$NON-NLS-1$
xPathContext);
for (int i=0; i<searchResult.size(); i++) {
Element segElement = (Element)searchResult.get(i);
Element parentElement = (Element)segElement.getParent();
if (segElement.getAttribute("rend") != null) {//$NON-NLS-1$
segElement.setLocalName("hi"); //$NON-NLS-1$
}
else {
int position = parentElement.indexOf(segElement);
for (int j=0; j<segElement.getChildCount(); j++) {
parentElement.insertChild(segElement.getChild(j).copy(), position);
position++;
}
parentElement.removeChild(segElement);
}
}
}
示例8: fixFormulae
import nu.xom.Nodes; //导入依赖的package包/类
/**
* Ensures that mathml formulae appear always within a formula element
* @param document
*/
private void fixFormulae(Document document) {
Nodes searchResult =
document.query(
"//mml:math", //$NON-NLS-1$
xPathContext);
for (int i=0; i<searchResult.size(); i++) {
Element mathElement = (Element)searchResult.get(i);
Element parentElement = (Element)mathElement.getParent();
if (!parentElement.getLocalName().equals("formula")) { //$NON-NLS-1$
Element formulaElement = new Element("formula", TeiNamespace.TEI.toUri()); //$NON-NLS-1$
parentElement.replaceChild(mathElement, formulaElement);
formulaElement.appendChild(mathElement.copy());
}
}
}
示例9: makeHeaderElement
import nu.xom.Nodes; //导入依赖的package包/类
private void makeHeaderElement(Document contentDoc) {
Nodes searchResult =
contentDoc.query(
"//office:text/text:p[starts-with(@text:style-name,'DH-Heading')]", //$NON-NLS-1$
xPathContext);
for (int i=0; i<searchResult.size(); i++) {
Element headElement = (Element) searchResult.get(i);
String styleName =
headElement.getAttributeValue(
"style-name", Namespace.TEXT.toUri()); //$NON-NLS-1$
Integer level = 1;
if (!styleName.equals("DH-Heading")) { //$NON-NLS-1$
level = Integer.valueOf(styleName.substring("DH-Heading".length())); //$NON-NLS-1$
}
headElement.setLocalName("h"); //$NON-NLS-1$
headElement.addAttribute(
new Attribute("text:outline-level", Namespace.TEXT.toUri(), level.toString())); //$NON-NLS-1$
}
}
示例10: getPaperIdFromMeta
import nu.xom.Nodes; //导入依赖的package包/类
private Integer getPaperIdFromMeta(Document metaDoc) throws IOException {
Nodes searchResult =
metaDoc.query(
"/office:document-meta/office:meta/meta:user-defined[@meta:name='" //$NON-NLS-1$
+CONFTOOLPAPERID_ATTRIBUTENAME+"']", //$NON-NLS-1$
xPathContext);
if (searchResult.size() == 1) {
Element confToolPaperIdElement = (Element) searchResult.get(0);
return Integer.valueOf(confToolPaperIdElement.getValue());
}
else {
throw new IOException(
Messages.getString("OdtInputConverter.invalidmeta")); //$NON-NLS-1$
}
}
示例11: injectPaperIdIntoMeta
import nu.xom.Nodes; //导入依赖的package包/类
/**
* Injects the ConfTool paperId into the meta data of the template.
* @param metaDoc
* @param paperId
*/
private void injectPaperIdIntoMeta(Document metaDoc, Integer paperId) {
Nodes searchResult =
metaDoc.query(
"/office:document-meta/office:meta/meta:user-defined[@meta:name='" //$NON-NLS-1$
+CONFTOOLPAPERID_ATTRIBUTENAME+"']", //$NON-NLS-1$
xPathContext);
if (searchResult.size() != 0) {
for (int i=0; i<searchResult.size(); i++) {
Node n = searchResult.get(i);
n.getParent().removeChild(n);
}
}
Element confToolPaperIdElement =
new Element("meta:user-defined", Namespace.META.toUri()); //$NON-NLS-1$
confToolPaperIdElement.addAttribute(
new Attribute("meta:name", Namespace.META.toUri(), CONFTOOLPAPERID_ATTRIBUTENAME)); //$NON-NLS-1$
confToolPaperIdElement.appendChild(String.valueOf(paperId));
Element metaElement = metaDoc.getRootElement()
.getFirstChildElement("meta", Namespace.OFFICE.toUri()); //$NON-NLS-1$
metaElement.appendChild(confToolPaperIdElement);
}
示例12: injectSubmissionLanguageIntoMeta
import nu.xom.Nodes; //导入依赖的package包/类
/**
* Injects the Submission language into the meta data of the template.
* @param metaDoc
* @param paperId
*/
private void injectSubmissionLanguageIntoMeta(Document metaDoc, SubmissionLanguage submissionLanguage) {
Nodes searchResult =
metaDoc.query(
"/office:document-meta/office:meta/meta:user-defined[@meta:name='" //$NON-NLS-1$
+SUBMISSIONLANGUAGE_ATTRIBUTENAME+"']", //$NON-NLS-1$
xPathContext);
if (searchResult.size() != 0) {
for (int i=0; i<searchResult.size(); i++) {
Node n = searchResult.get(i);
n.getParent().removeChild(n);
}
}
Element submissionLanguageElement =
new Element("meta:user-defined", Namespace.META.toUri()); //$NON-NLS-1$
submissionLanguageElement.addAttribute(
new Attribute("meta:name", Namespace.META.toUri(), SUBMISSIONLANGUAGE_ATTRIBUTENAME)); //$NON-NLS-1$
submissionLanguageElement.appendChild(submissionLanguage.name());
Element metaElement = metaDoc.getRootElement()
.getFirstChildElement("meta", Namespace.OFFICE.toUri()); //$NON-NLS-1$
metaElement.appendChild(submissionLanguageElement);
}
示例13: testHiding2
import nu.xom.Nodes; //导入依赖的package包/类
public void testHiding2() throws Exception {
Template tmp = templates.get("hiding2.xhtml");
tmp.setElement("title", "Hiding Example 2");
tmp.hideElement("autopayments");
tmp.hideElement("exchange");
tmp.hideElement("transactions");
Document doc = loadXml(tmp);
System.out.println(tmp.toString());
Nodes anchorNodes = doc.query("//body/ul/li");
assertEquals(3, anchorNodes.size());
anchorNodes = doc.query("//a");
Element anchor1 = (Element) anchorNodes.get(0);
assertEquals("/accounts", anchor1.getAttribute("href").getValue());
Element anchor2 = (Element) anchorNodes.get(1);
assertEquals("/transfer", anchor2.getAttribute("href").getValue());
Element anchor3 = (Element) anchorNodes.get(2);
assertEquals("/bills", anchor3.getAttribute("href").getValue());
}
示例14: testRepetition
import nu.xom.Nodes; //导入依赖的package包/类
public void testRepetition() throws Exception {
Template tmp = templates.get("repeat.xhtml");
tmp.setElement("title", "Repeating Xhtml Page");
tmp.setElement("link", "This is a link to Google");
tmp.setAttribute("link", "href", "http://www.google.com");
tmp.repeatElement("list-item", 5);
for (int i = 0, j = 1; i < 5; i++, j++) {
tmp.setElement("list-item", "test" + j, i);
}
Document doc = loadXml(tmp);
System.out.println(tmp.toString());
Nodes listNodes = doc.query("//body/ul/li");
assertEquals(5, listNodes.size());
for (int i = 0; i < listNodes.size(); i++) {
Element listNode = (Element) listNodes.get(i);
assertEquals("test" + (i+1), listNode.getValue());
}
}
示例15: test
import nu.xom.Nodes; //导入依赖的package包/类
/**
* Tests that the schema registers a iso639 field and that the needed jar
* file has been successfully loaded into Solr.
*/
@Test
public void test() {
try {
InputStream source = new URL(QUERY).openStream();
Document doc = new Builder().build(source);
Nodes nodes = doc.query(FACET_PATH);
if (nodes.size() != 1) {
fail("Didn't find the facet.field facet in the response XML");
}
assertEquals("iso639", nodes.get(0).getValue().trim());
} catch (Exception details) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Error connecting to integration server", details);
}
fail(details.getMessage());
}
}