当前位置: 首页>>代码示例>>Java>>正文


Java Nodes.size方法代码示例

本文整理汇总了Java中nu.xom.Nodes.size方法的典型用法代码示例。如果您正苦于以下问题:Java Nodes.size方法的具体用法?Java Nodes.size怎么用?Java Nodes.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nu.xom.Nodes的用法示例。


在下文中一共展示了Nodes.size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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$
	}
	
}
 
开发者ID:ADHO,项目名称:dhconvalidator,代码行数:22,代码来源:OdtInputConverter.java

示例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;
}
 
开发者ID:hamishmorgan,项目名称:XomB,代码行数:20,代码来源:ElementBuilderImpl.java

示例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);
}
 
开发者ID:imintel,项目名称:ddmsence,代码行数:40,代码来源:Resource.java

示例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);
      }
    }
  }
}
 
开发者ID:stickycode,项目名称:bounds-maven-plugin,代码行数:18,代码来源:StickyBoundsMojo.java

示例5: 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());
    }
}
 
开发者ID:jasonrbriggs,项目名称:proton,代码行数:23,代码来源:BasicTest.java

示例6: 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());
    }
}
 
开发者ID:ksclarke,项目名称:solr-iso639-filter,代码行数:25,代码来源:ISO639SolrIntegrationTest.java

示例7: 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
			}
		}
	}
}
 
开发者ID:sjas,项目名称:isabel,代码行数:20,代码来源:SA00047Validator.java

示例8: 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;
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:9,代码来源:XmlUtils.java

示例9: loadXmlDefinition

import nu.xom.Nodes; //导入方法依赖的package包/类
/**
 * Use the CacheXmlGenerator to create XML from the entity associated with
 * the current cache.
 * 
 * @param element Name of the XML element to search for.
 * @param attributes
 *          Attributes of the element that should match, for example "name" or
 *          "id" and the value they should equal.
 * 
 * @return XML string representation of the entity.
 */
private final String loadXmlDefinition(final String element, final Map<String, String> attributes) {
  final Cache cache = CacheFactory.getAnyInstance();
  Document document = null;

  try {
    final StringWriter stringWriter = new StringWriter();
    final PrintWriter printWriter = new PrintWriter(stringWriter);
    CacheXmlGenerator.generate(cache, printWriter, false, false, false);
    printWriter.close();

    // Remove the DOCTYPE line when getting the string to prevent
    // errors when trying to locate the DTD.
    String xml = stringWriter.toString().replaceFirst("<!DOCTYPE.*>", "");
    document = new Builder(false).build(xml, null);

  } catch (ValidityException vex) {
    cache.getLogger().error("Could not parse XML when creating XMLEntity", vex);

  } catch (ParsingException pex) {
    cache.getLogger().error("Could not parse XML when creating XMLEntity", pex);
    
  } catch (IOException ioex) {
    cache.getLogger().error("Could not parse XML when creating XMLEntity", ioex);
  }
  
  Nodes nodes = document.query(createQueryString(element, attributes));
  if (nodes.size() != 0) {
    return nodes.get(0).toXML();
  }
  
  cache.getLogger().warning("No XML definition could be found with name=" + element + " and attributes=" + attributes);
  return null;
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:45,代码来源:XmlEntity.java

示例10: 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
}
 
开发者ID:cemfi,项目名称:meico,代码行数:39,代码来源:Goto.java

示例11: getNodeList

import nu.xom.Nodes; //导入方法依赖的package包/类
public static List<Node> getNodeList(String xpath, Node node)
{
    Nodes nodes = getNodes(xpath, node);
    List<Node> nodeList = new LinkedList<Node>();

    for (int i = 0; i < nodes.size(); i++)
    {
        nodeList.add(nodes.get(i));
    }

    return nodeList;
}
 
开发者ID:julian-eggers,项目名称:xpath-helper,代码行数:13,代码来源:XPathHelper.java

示例12: appendChildrenToNewParent

import nu.xom.Nodes; //导入方法依赖的package包/类
@Override
protected void appendChildrenToNewParent(Element oldParent,
        Element newParent) throws SAXException {
    try {
        Nodes children = oldParent.removeChildren();
        for (int i = 0; i < children.size(); i++) {
            newParent.appendChild(children.get(i));
        }
    } catch (XMLException e) {
        fatal(e);
    }
}
 
开发者ID:google,项目名称:caja,代码行数:13,代码来源:XOMTreeBuilder.java

示例13: cleanupParagraphStyles

import nu.xom.Nodes; //导入方法依赖的package包/类
/**
 * Removes paragraph styles that are not supported.
 * 
 * @param document
 */
private void cleanupParagraphStyles(Document document) {
	Nodes searchResult = 
			document.query("//w:pPr/w:rPr", xPathContext); //$NON-NLS-1$
	// remove region properties from paragraphs, they are not supported 
	for (int i=0; i<searchResult.size(); i++) {
		Element element = (Element) searchResult.get(i);
		element.getParent().removeChild(element);
	}

	searchResult = document.query("//w:p", xPathContext); //$NON-NLS-1$
	
	for (int i=0; i<searchResult.size(); i++) {
		Element paragraphElement = (Element) searchResult.get(i);
		Elements regions = paragraphElement.getChildElements("r", Namespace.MAIN.toUri()); //$NON-NLS-1$
		// there is only one region...
		if (regions.size() == 1) {
			Element region = regions.get(0);
			Element regionProps = region.getFirstChildElement("rPr", Namespace.MAIN.toUri()); //$NON-NLS-1$
			if (regionProps != null) {
				// ... and it contains region properties. This looks like a trick to avoid proper head styles
				// so we remove the properties.
				region.removeChild(regionProps);
			}
		}
	}		
	
}
 
开发者ID:ADHO,项目名称:dhconvalidator,代码行数:33,代码来源:DocxInputConverter.java

示例14: injectAuthorsIntoContent

import nu.xom.Nodes; //导入方法依赖的package包/类
/**
 * Injects authors into the readonly authors section. 
 * @param document
 * @param authorsAndAffiliations
 * @throws IOException
 */
private void injectAuthorsIntoContent(Document document,
		List<User> authorsAndAffiliations) throws IOException {
	Nodes searchResult = 
			document.query("//w:pStyle[@w:val='DH-AuthorAffiliation']", xPathContext); //$NON-NLS-1$
	
	if (searchResult.size() != 1) {
		throw new IOException(
			Messages.getString(
					"DocxInputConverter.templateerror1", //$NON-NLS-1$
					searchResult.size())); 
	}
	
	Element authorStyleElement = (Element) searchResult.get(0);
	Element authorParagraphElement = (Element) authorStyleElement.getParent().getParent();
	Element paragraphParent = (Element) authorParagraphElement.getParent();
	int insertPosition = paragraphParent.indexOf(authorParagraphElement)-1;
	
	for (User authorAffiliation : authorsAndAffiliations){
		Element curAuthorParagraphElement = (Element) authorParagraphElement.copy();
		
		Element authorElement = DocumentUtil.getFirstMatch(
				curAuthorParagraphElement, "w:r/w:t", xPathContext); //$NON-NLS-1$
		
		authorElement.removeChildren();
		authorElement.appendChild(
			authorAffiliation.getFirstName() + " " + authorAffiliation.getLastName()  //$NON-NLS-1
			+ " (" + authorAffiliation.getEmail() + "), " //$NON-NLS-1 //$NON-NLS-2
			+ authorAffiliation.getOrganizations()); //$NON-NLS-1$
		paragraphParent.insertChild(curAuthorParagraphElement, insertPosition);
		insertPosition++;
	}
	
	paragraphParent.removeChild(authorParagraphElement);
	
}
 
开发者ID:ADHO,项目名称:dhconvalidator,代码行数:42,代码来源:DocxInputConverter.java

示例15: makeFigureHead

import nu.xom.Nodes; //导入方法依赖的package包/类
/**
 * Puts all image descriptions in a head element.
 * @param document
 */
private void makeFigureHead(Document document) {
	Nodes searchResult = document.query("//tei:figure", xPathContext); //$NON-NLS-1$
	for (int i=0; i<searchResult.size(); i++) {
		Element figureElement = (Element)searchResult.get(i);
		StringBuilder descBuilder = new StringBuilder();
		String conc = "";
		for (int j=0; j<figureElement.getChildCount(); j++) {
			Node child = figureElement.getChild(j);
			if (child instanceof Text) {
				descBuilder.append(conc);
				descBuilder.append(((Text)child).getValue());
				conc = " ";
				child.getParent().removeChild(child);
			}
		}
		
		if (descBuilder.length() > 0) {
			Element headElement = figureElement.getFirstChildElement("head", TeiNamespace.TEI.toUri());
			if (headElement == null) {
				headElement = new Element("head", TeiNamespace.TEI.toUri());
				figureElement.appendChild(headElement);
			}
			headElement.appendChild(descBuilder.toString());
		}
	}
}
 
开发者ID:ADHO,项目名称:dhconvalidator,代码行数:31,代码来源:CommonOutputConverter.java


注:本文中的nu.xom.Nodes.size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。