本文整理汇总了Java中nu.xom.Nodes.get方法的典型用法代码示例。如果您正苦于以下问题:Java Nodes.get方法的具体用法?Java Nodes.get怎么用?Java Nodes.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nu.xom.Nodes
的用法示例。
在下文中一共展示了Nodes.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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);
}
示例3: 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$
}
}
示例4: 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)");
}
示例5: 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)");
}
示例6: 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);
}
}
}
示例7: 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());
}
}
}
示例8: 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$
}
}
示例9: 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);
}
示例10: 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());
}
示例11: 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());
}
}
示例12: findXsdType
import nu.xom.Nodes; //导入方法依赖的package包/类
private Node findXsdType(String typeQName, Node variable) {
String variableTypeNamespaceURI = variable.getDocument()
.getRootElement()
.getNamespaceURI(PrefixHelper.getPrefix(typeQName));
String xsdTypeName = PrefixHelper.removePrefix(typeQName);
Node xsdType = null;
for (Node node : fileHandler.getSchemas()) {
if (new NodeHelper(node)
.hasTargetNamespace(variableTypeNamespaceURI)) {
Nodes xsdTypes = node.getDocument().query(
"//*[@name='" + xsdTypeName + "']", CONTEXT);
if (xsdTypes.hasAny()) {
xsdType = xsdTypes.get(0);
break;
}
}
}
return xsdType;
}
示例13: validate
import nu.xom.Nodes; //导入方法依赖的package包/类
@Override
public void validate() {
List<Nodes> messageActivityList = getMessageActivities();
for (Nodes messageActivityNodes : messageActivityList) {
for (int i = 0; i < messageActivityNodes.size(); i++) {
Node messageActivity = messageActivityNodes.get(i);
try {
if (hasMessagePart(messageActivity)) {
validateMessagePartConstraint(messageActivity);
} else {
validateNoMessagePartConstraint(messageActivity);
}
} catch (NavigationException e) {
// This node could not be validated
}
}
}
}
示例14: getNode
import nu.xom.Nodes; //导入方法依赖的package包/类
public static Node getNode(Document doc, String entityType, String entityName) {
String query = createQueryStringByName(entityType, entityName);
Nodes nodes = doc.query(query);
if (nodes != null && nodes.size() > 0) {
return nodes.get(0);
}
return null;
}
示例15: Goto
import nu.xom.Nodes; //导入方法依赖的package包/类
/**
* constructor
* @param gt
*/
public Goto(Element gt) throws InvalidParameterException {
Attribute a = gt.getAttribute("midi.date"); // get its midi.date attribute
if (a == null) // if it has none
throw new InvalidParameterException("Missing attribute midi.date in " + gt.toXML()); // the Goto instance cannot be created
this.date = Double.parseDouble(gt.getAttributeValue("midi.date")); // get the date as double
// get its target.id and target element
if ((gt.getAttribute("target.id") != null) && !gt.getAttributeValue("target.id").isEmpty()) { // if there is a nonempty attribute target.id
this.targetId = gt.getAttributeValue("target.id").trim(); // get target.id
if (this.targetId.startsWith("#")) // remove the # at the start
this.targetId = this.targetId.substring(1, this.targetId.length());
Nodes targetCandidates = gt.getParent().query("descendant::*[attribute::xml:id='" + this.targetId + "']"); // find target element (must be a sibling of gt)
if (targetCandidates.size() > 0) this.target = (Element) targetCandidates.get(0); // get it
}
// determine target date
a = gt.getAttribute("target.date"); // get its target.date
if (a == null) { // if it has none
if (this.target == null) // and there is no target specified otherwise
throw new InvalidParameterException("Missing attribute target.date or a valid target.id in " + gt.toXML()); // the Goto instance cannot be created
try {
this.targetDate = Double.parseDouble(this.target.getAttributeValue("midi.date")); // get the date from the target
} catch (Exception e) { // if it fails
throw new InvalidParameterException("The target of " + gt.toXML() + " has no valid attribute midi.date."); // the Goto instance cannot be created
}
}
else { // it has the target.date attribute
this.targetDate = Double.parseDouble(gt.getAttributeValue("target.date")); // get the date as double
}
this.activity = (gt.getAttribute("activity") == null) ? "1" : gt.getAttributeValue("activity"); // get the activity string
}