public Element getSingleElement(Element element, String tagName) { return (Element) element.getElementsByTagNameNS( RedissonNamespaceParserSupport.REDISSON_NAMESPACE, tagName) .item(0); } }
public boolean hasElement(Element element, String tagName) { return element.getElementsByTagNameNS( RedissonNamespaceParserSupport.REDISSON_NAMESPACE, tagName) .getLength() > 0; }
private String readElement(Document xmlDoc, String localName, String namespaceURI) { Element el = (Element)xmlDoc.getDocumentElement().getElementsByTagNameNS(namespaceURI, localName).item(0); if (el == null) { return null; } return el.getTextContent(); }
private void parseNested(Element element, String eltType, ParserContext parserContext, BeanDefinitionBuilder builder, RedissonNamespaceParserSupport helper) { NodeList list = element.getElementsByTagNameNS( RedissonNamespaceParserSupport.REDISSON_NAMESPACE, eltType); if (list.getLength() == 1) { Element elt = (Element) list.item(0); helper.setAttribute(elt, RedissonNamespaceParserSupport.READ_WRITE_LOCK_REF_ATTRIBUTE, helper.getAttribute(element, RedissonNamespaceParserSupport.ID_ATTRIBUTE)); parserContext.getDelegate() .parseCustomElement(elt, builder.getRawBeanDefinition()); } } }
private static NodeList selectNodes(Document xml, String[] path, String namespaceUri) throws XPathExpressionException { Element ref = xml.getDocumentElement(); for (int i = 0; i < path.length - 1; i++) { NodeList nodes = ref.getChildNodes(); if (nodes.getLength() < 1) { return null; } Element elem; for (int j = 0; j < nodes.getLength(); j++) { if (nodes.item(j).getNodeType() == Node.ELEMENT_NODE) { elem = (Element) nodes.item(j); if (elem.getNodeName().equals(path[i]) && elem.getNamespaceURI().equals(namespaceUri)) { ref = elem; break; } } } } return ref.getElementsByTagNameNS(namespaceUri, path[path.length - 1]); }
public void testEncodeAsFilter() throws Exception { Document doc = encode(FilterMockData.propertyIsLike(), OGC.Filter); // print(doc); assertEquals( 1, doc.getDocumentElement() .getElementsByTagNameNS(OGC.NAMESPACE, OGC.PropertyName.getLocalPart()) .getLength()); assertEquals( 1, doc.getDocumentElement() .getElementsByTagNameNS(OGC.NAMESPACE, OGC.Literal.getLocalPart()) .getLength()); Element e = getElementByQName(doc, OGC.PropertyIsLike); assertEquals("x", e.getAttribute("wildCard")); assertEquals("y", e.getAttribute("singleChar")); assertEquals("z", e.getAttribute("escape")); }
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; Element docElem; NodeList elementList; doc = (Document) load("staffNS", false); docElem = doc.getDocumentElement(); elementList = docElem.getElementsByTagNameNS("http://www.nomatch.com", "address"); assertSize("matchSize", 0, elementList); } /**
private void parseNested(Element element, String eltType, ParserContext parserContext, BeanDefinitionBuilder builder, RedissonNamespaceParserSupport helper) { NodeList list = element.getElementsByTagNameNS( RedissonNamespaceParserSupport.REDISSON_NAMESPACE, eltType); if (list.getLength() == 1) { Element elt = (Element) list.item(0); helper.setAttribute(elt, RedissonNamespaceParserSupport.READ_WRITE_LOCK_REF_ATTRIBUTE, helper.getAttribute(element, RedissonNamespaceParserSupport.ID_ATTRIBUTE)); parserContext.getDelegate() .parseCustomElement(elt, builder.getRawBeanDefinition()); } } }
NodeList defaultTypes = xmlContentTypetDoc.getDocumentElement().getElementsByTagNameNS(TYPES_NAMESPACE_URI, DEFAULT_TAG_NAME); int defaultTypeCount = defaultTypes.getLength(); for (int i = 0; i < defaultTypeCount; i++) { Element element = (Element) defaultTypes.item(i); String extension = element.getAttribute(EXTENSION_ATTRIBUTE_NAME); String contentType = element.getAttribute(CONTENT_TYPE_ATTRIBUTE_NAME); NodeList overrideTypes = xmlContentTypetDoc.getDocumentElement().getElementsByTagNameNS(TYPES_NAMESPACE_URI, OVERRIDE_TAG_NAME); int overrideTypeCount = overrideTypes.getLength(); for (int i = 0; i < overrideTypeCount; i++) { Element element = (Element) overrideTypes.item(i); URI uri = new URI(element.getAttribute(PART_NAME_ATTRIBUTE_NAME)); PackagePartName partName = PackagingURIHelper.createPartName(uri);
private Element setElementTextContent(String localName, NamespaceImpl namespace, Optional<?> property, String propertyValue) { if (!property.isPresent()) return null; Element root = xmlDoc.getDocumentElement(); Element elem = (Element) root.getElementsByTagNameNS(namespace.getNamespaceURI(), localName).item(0); if (elem == null) { // missing, we add it elem = xmlDoc.createElementNS(namespace.getNamespaceURI(), getQName(localName, namespace)); root.appendChild(elem); } elem.setTextContent(propertyValue); return elem; }
public void testEncodeAsFilter() throws Exception { Document doc = encode(FilterMockData.propertyIsLike(), OGC.Filter); // print(doc); assertEquals( 1, doc.getDocumentElement() .getElementsByTagNameNS(OGC.NAMESPACE, OGC.PropertyName.getLocalPart()) .getLength()); assertEquals( 1, doc.getDocumentElement() .getElementsByTagNameNS(OGC.NAMESPACE, OGC.Literal.getLocalPart()) .getLength()); Element e = getElementByQName(doc, OGC.PropertyIsLike); assertEquals("x", e.getAttribute("wildCard")); assertEquals("y", e.getAttribute("singleChar")); assertEquals("z", e.getAttribute("escapeChar")); assertEquals("false", e.getAttribute("matchCase")); } }
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; Element docElem; NodeList newList; doc = (Document) load("staffNS", false); docElem = doc.getDocumentElement(); newList = docElem.getElementsByTagNameNS("*", "*"); assertSize("listSize", 36, newList); } /**
public Element getSingleElement(Element element, String tagName) { return (Element) element.getElementsByTagNameNS( RedissonNamespaceParserSupport.REDISSON_NAMESPACE, tagName) .item(0); } }
public boolean hasElement(Element element, String tagName) { return element.getElementsByTagNameNS( RedissonNamespaceParserSupport.REDISSON_NAMESPACE, tagName) .getLength() > 0; }
@Override public void decorate(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, RedissonNamespaceParserSupport helper) { NodeList list = element.getElementsByTagNameNS( RedissonNamespaceParserSupport.REDISSON_NAMESPACE, RedissonNamespaceParserSupport.LOCAL_CACHED_MAP_OPTIONS_ELEMENT); Element options = null; String id; if (list.getLength() == 1) { options = (Element) list.item(0); id = invokeOptions(options, parserContext, helper); for (int i = 0; i < options.getAttributes().getLength(); i++) {
Element root = xmlRelationshipsDoc.getDocumentElement(); NodeList nodeList = root.getElementsByTagNameNS(PackageNamespaces.RELATIONSHIPS, PackageRelationship.RELATIONSHIP_TAG_NAME); int nodeCount = nodeList.getLength(); for (int i = 0; i < nodeCount; i++) { Element element = (Element)nodeList.item(i);
@Test public void testUpgradeSchemaFromGemfireWithCustomPrefix() throws Exception { String xml = "<a:cache xmlns:a=\"http://schema.pivotal.io/gemfire/cache\">\n" + " <a:region name=\"one\">\n" + " <a:region-attributes scope=\"distributed-ack\" data-policy=\"replicate\"/>\n" + " </a:region>\n" + "</a:cache>"; Document doc = XmlUtils.createDocumentFromXml(xml); Element oldRoot = doc.getDocumentElement(); assertThat(oldRoot.getNamespaceURI()).isEqualTo(CacheXml.GEMFIRE_NAMESPACE); String version = "1.0"; doc = XmlUtils.upgradeSchema(doc, GEODE_NAMESPACE, LATEST_SCHEMA_LOCATION, version); Element root = doc.getDocumentElement(); assertThat(root.getNamespaceURI()).isEqualTo(GEODE_NAMESPACE); assertThat(root.getAttribute(CacheXml.VERSION)).isEqualTo(version); assertThat(root.getAttribute("xsi:schemaLocation")).isEqualTo(GEODE_SCHEMA_LOCATION); Node regionNode = root.getElementsByTagNameNS(GEODE_NAMESPACE, "region").item(0); assertThat(regionNode.getNamespaceURI()).isEqualTo(GEODE_NAMESPACE); }
public void testBackwardLikeFilter() throws Exception { String f = "<ogc:Filter xmlns:ogc=\"http://www.opengis.net/ogc\"><ogc:PropertyIsLike wildCard=\"*\" singleChar=\"#\" escapeChar=\"!\">\n" + "<ogc:Literal>M*</ogc:Literal>\n" + "<ogc:PropertyName>gml:name</ogc:PropertyName>\n" + "</ogc:PropertyIsLike></ogc:Filter>"; Configuration configuration = new org.geotools.filter.v1_0.OGCConfiguration(); Parser parser = new Parser(configuration); Filter filter = (Filter) parser.parse(new ByteArrayInputStream(f.getBytes())); Document doc = encode(filter, OGC.Filter); // print(doc); assertEquals( 1, doc.getDocumentElement() .getElementsByTagNameNS(OGC.NAMESPACE, OGC.PropertyName.getLocalPart()) .getLength()); assertEquals( 1, doc.getDocumentElement() .getElementsByTagNameNS(OGC.NAMESPACE, OGC.Literal.getLocalPart()) .getLength()); Element e = getElementByQName(doc, OGC.PropertyIsLike); assertEquals("*", e.getAttribute("wildCard")); assertEquals("#", e.getAttribute("singleChar")); assertEquals("!", e.getAttribute("escape")); }
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; Element element; NodeList elementList; doc = (Document) load("staffNS", false); element = doc.getDocumentElement(); elementList = element.getElementsByTagNameNS("http://www.altavista.com", "*"); assertSize("elementgetelementsbytagnamens05", 1, elementList); } /**
public static X509Certificate loadX509IssuerSerial(Crypto crypto, Element certNode) throws Exception { Node issuerNameNode = certNode.getElementsByTagNameNS(Constants.SignatureSpecNS, "X509IssuerName").item(0); Node serialNumberNode = certNode.getElementsByTagNameNS(Constants.SignatureSpecNS, "X509SerialNumber").item(0); CryptoType cryptoType = new CryptoType(CryptoType.TYPE.ISSUER_SERIAL); cryptoType.setIssuerSerial(issuerNameNode.getTextContent(), new BigInteger(serialNumberNode.getTextContent())); return crypto.getX509Certificates(cryptoType)[0]; }