List of usage examples for org.w3c.dom Element getAttributeNS
public String getAttributeNS(String namespaceURI, String localName) throws DOMException;
From source file:gov.nij.bundles.intermediaries.ers.EntityResolutionMessageHandlerTest.java
@Test public void testPerformEntityResolutionWithDetermFactors() throws Exception { XmlConverter converter = new XmlConverter(); converter.getDocumentBuilderFactory().setNamespaceAware(true); InputStream attributeParametersStream = getClass() .getResourceAsStream("/xml/TestAttributeParametersWithDeterm.xml"); entityResolutionMessageHandler.setAttributeParametersStream(attributeParametersStream); testRequestMessageInputStream = getClass() .getResourceAsStream("/xml/EntityMergeRequestMessageForDeterm.xml"); Document testRequestMessage = converter.toDOMDocument(testRequestMessageInputStream); Node entityContainerNode = testRequestMessage .getElementsByTagNameNS(EntityResolutionNamespaceContext.ER_EXT_NAMESPACE, "EntityContainer") .item(0);/*from ww w. ja va 2 s.c o m*/ assertNotNull(entityContainerNode); Document resultDocument = entityResolutionMessageHandler.performEntityResolution(entityContainerNode, null, null); resultDocument.normalizeDocument(); // LOG.info(converter.toString(resultDocument)); XPath xp = XPathFactory.newInstance().newXPath(); xp.setNamespaceContext(new EntityResolutionNamespaceContext()); NodeList entityNodes = (NodeList) xp.evaluate("//merge-result:EntityContainer/merge-result-ext:Entity", resultDocument, XPathConstants.NODESET); assertEquals(2, entityNodes.getLength()); entityNodes = (NodeList) xp.evaluate("//merge-result-ext:MergedRecord", resultDocument, XPathConstants.NODESET); assertEquals(2, entityNodes.getLength()); entityNodes = (NodeList) xp.evaluate("//merge-result-ext:OriginalRecordReference", resultDocument, XPathConstants.NODESET); assertEquals(2, entityNodes.getLength()); for (int i = 0; i < entityNodes.getLength(); i++) { Element e = (Element) entityNodes.item(i); String entityIdRef = e.getAttributeNS(EntityResolutionNamespaceContext.STRUCTURES_NAMESPACE, "ref"); assertNotNull(entityIdRef); assertNotNull(xp.evaluate("//merge-result-ext:Entity[@s:id='" + entityIdRef + "']", resultDocument, XPathConstants.NODE)); } }
From source file:edu.internet2.middleware.shibboleth.common.config.resource.SVNResourceBeanDefinitionParser.java
/** * Gets the value of the {@value #PROXY_HOST_ATTRIB_NAME} attribute. * // ww w. ja v a 2 s . c o m * @param configElement resource configuration element * * @return value of the attribute * * @throws BeanCreationException thrown if the attribute is present but contains an empty string */ protected String getProxyHost(Element configElement) throws BeanCreationException { if (configElement.hasAttributeNS(null, PROXY_HOST_ATTRIB_NAME)) { String host = DatatypeHelper .safeTrimOrNullString(configElement.getAttributeNS(null, PROXY_HOST_ATTRIB_NAME)); if (host == null) { log.error("SVN resource definition attribute '" + PROXY_HOST_ATTRIB_NAME + "' may not be an empty string"); throw new BeanCreationException("SVN resource definition attribute '" + PROXY_HOST_ATTRIB_NAME + "' may not be an empty string"); } return host; } return null; }
From source file:edu.internet2.middleware.shibboleth.common.config.resource.SVNResourceBeanDefinitionParser.java
/** * Gets the value of the {@value #PASSWORD_ATTRIB_NAME} attribute. * /* w w w .ja v a2 s.c om*/ * @param configElement resource configuration element * * @return value of the attribute * * @throws BeanCreationException thrown if the attribute is present but contains an empty string */ protected String getPassword(Element configElement) throws BeanCreationException { if (configElement.hasAttributeNS(null, PASSWORD_ATTRIB_NAME)) { String password = DatatypeHelper .safeTrimOrNullString(configElement.getAttributeNS(null, PASSWORD_ATTRIB_NAME)); if (password == null) { log.error("SVN resource definition attribute '" + PASSWORD_ATTRIB_NAME + "' may not be an empty string"); throw new BeanCreationException("SVN resource definition attribute '" + PASSWORD_ATTRIB_NAME + "' may not be an empty string"); } return password; } return null; }
From source file:edu.internet2.middleware.shibboleth.common.config.resource.SVNResourceBeanDefinitionParser.java
/** * Gets the value of the {@value #USERNAME_ATTRIB_NAME} attribute. * /*from w w w. j ava 2 s . com*/ * @param configElement resource configuration element * * @return value of the attribute * * @throws BeanCreationException thrown if the attribute is present but contains an empty string */ protected String getUsername(Element configElement) throws BeanCreationException { if (configElement.hasAttributeNS(null, USERNAME_ATTRIB_NAME)) { String username = DatatypeHelper .safeTrimOrNullString(configElement.getAttributeNS(null, USERNAME_ATTRIB_NAME)); if (username == null) { log.error("SVN resource definition attribute '" + USERNAME_ATTRIB_NAME + "' may not be an empty string"); throw new BeanCreationException("SVN resource definition attribute '" + USERNAME_ATTRIB_NAME + "' may not be an empty string"); } return username; } return null; }
From source file:edu.internet2.middleware.shibboleth.common.config.resource.SVNResourceBeanDefinitionParser.java
/** * Gets the value of the {@value #PROXY_USERNAME_ATTRIB_NAME} attribute. * /*from w w w. jav a2s .c o m*/ * @param configElement resource configuration element * * @return value of the attribute * * @throws BeanCreationException thrown if the attribute is present but contains an empty string */ protected String getProxyUsername(Element configElement) throws BeanCreationException { if (configElement.hasAttributeNS(null, PROXY_USERNAME_ATTRIB_NAME)) { String username = DatatypeHelper .safeTrimOrNullString(configElement.getAttributeNS(null, PROXY_USERNAME_ATTRIB_NAME)); if (username == null) { log.error("SVN resource definition attribute '" + PROXY_USERNAME_ATTRIB_NAME + "' may not be an empty string"); throw new BeanCreationException("SVN resource definition attribute '" + PROXY_USERNAME_ATTRIB_NAME + "' may not be an empty string"); } return username; } return null; }
From source file:edu.internet2.middleware.shibboleth.common.config.resource.SVNResourceBeanDefinitionParser.java
/** * Gets the value of the {@value #PROXY_PASSWORD_ATTRIB_NAME} attribute. * // www .j a va 2 s . c o m * @param configElement resource configuration element * * @return value of the attribute * * @throws BeanCreationException thrown if the attribute is present but contains an empty string */ protected String getProxyPassword(Element configElement) throws BeanCreationException { if (configElement.hasAttributeNS(null, PROXY_PASSWORD_ATTRIB_NAME)) { String password = DatatypeHelper .safeTrimOrNullString(configElement.getAttributeNS(null, PROXY_PASSWORD_ATTRIB_NAME)); if (password == null) { log.error("SVN resource definition attribute '" + PROXY_PASSWORD_ATTRIB_NAME + "' may not be an empty string"); throw new BeanCreationException("SVN resource definition attribute '" + PROXY_PASSWORD_ATTRIB_NAME + "' may not be an empty string"); } return password; } return null; }
From source file:edu.internet2.middleware.shibboleth.common.config.resource.SVNResourceBeanDefinitionParser.java
/** * Gets the value of the {@value #PROXY_PORT_ATTRIB_NAME} attribute. * /*from ww w .j a va 2 s . c o m*/ * @param configElement resource configuration element * * @return value of the attribute, or {@value #DEFAULT_PROXY_PORT} if the attribute is not defined * * @throws BeanCreationException thrown if the attribute is present but contains an empty string */ protected int getProxyPort(Element configElement) throws BeanCreationException { if (!configElement.hasAttributeNS(null, PROXY_PORT_ATTRIB_NAME)) { return DEFAULT_PROXY_PORT; } String port = DatatypeHelper .safeTrimOrNullString(configElement.getAttributeNS(null, PROXY_PORT_ATTRIB_NAME)); if (port == null) { log.error("SVN resource definition attribute '" + PROXY_PORT_ATTRIB_NAME + "' may not be an empty string"); throw new BeanCreationException("SVN resource definition attribute '" + PROXY_PORT_ATTRIB_NAME + "' may not be an empty string"); } try { return Integer.parseInt(port); } catch (NumberFormatException e) { log.error("SVN resource definition attribute '" + PROXY_PORT_ATTRIB_NAME + "' contains an invalid number"); throw new BeanCreationException("SVN resource definition attribute '" + PROXY_PORT_ATTRIB_NAME + "' contains an invalid number"); } }
From source file:com.evolveum.midpoint.prism.parser.JaxbDomHack.java
private ItemDefinition resolveDynamicItemDefinition(ItemDefinition parentDefinition, QName elementName, Element element, PrismContext prismContext) throws SchemaException { QName typeName = null;/* w w w . j a va 2s . co m*/ // QName elementName = null; // Set it to multi-value to be on the safe side int maxOccurs = -1; // for (Object element : valueElements) { // if (elementName == null) { // elementName = JAXBUtil.getElementQName(element); // } // TODO: try JAXB types if (element instanceof Element) { Element domElement = (Element) element; if (DOMUtil.hasXsiType(domElement)) { typeName = DOMUtil.resolveXsiType(domElement); if (typeName != null) { String maxOccursString = domElement.getAttributeNS( PrismConstants.A_MAX_OCCURS.getNamespaceURI(), PrismConstants.A_MAX_OCCURS.getLocalPart()); if (!StringUtils.isBlank(maxOccursString)) { // TODO // maxOccurs = parseMultiplicity(maxOccursString, elementName); } // break; } } } // } // FIXME: now the definition assumes property, may also be property // container? if (typeName == null) { return null; } PrismPropertyDefinition propDef = new PrismPropertyDefinition(elementName, typeName, prismContext); propDef.setMaxOccurs(maxOccurs); propDef.setDynamic(true); return propDef; }
From source file:de.betterform.xml.xforms.ui.Repeat.java
private void initializePrototype(Node parent, Node prototype) { Node copy = prototype.cloneNode(false); if (copy.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) copy; if (element.getAttributeNS(null, "id").length() == 0 && XFormsElementFactory.isUIElement(element)) { element.setAttributeNS(null, "id", this.container.generateId()); }/*w ww .ja v a 2 s . c om*/ NodeList children = prototype.getChildNodes(); for (int index = 0; index < children.getLength(); index++) { initializePrototype(element, children.item(index)); } } parent.appendChild(copy); }
From source file:gov.nij.bundles.intermediaries.ers.EntityResolutionMessageHandlerTest.java
@Test public void testPerformEntityResolution() throws Exception { XPath xp = XPathFactory.newInstance().newXPath(); xp.setNamespaceContext(testNamespaceContext); XmlConverter converter = new XmlConverter(); converter.getDocumentBuilderFactory().setNamespaceAware(true); Document testRequestMessage = converter.toDOMDocument(testRequestMessageInputStream); // LOG.info(converter.toString(testRequestMessage)); Node entityContainerNode = testRequestMessage .getElementsByTagNameNS(EntityResolutionNamespaceContext.ER_EXT_NAMESPACE, "EntityContainer") .item(0);//from www . j av a 2 s . c o m assertNotNull(entityContainerNode); List<String> lastNames = new ArrayList<String>(); List<String> firstNames = new ArrayList<String>(); List<String> sids = new ArrayList<String>(); NodeList inputEntityNodes = (NodeList) testRequestMessage .getElementsByTagNameNS(EntityResolutionNamespaceContext.ER_EXT_NAMESPACE, "Entity"); int inputEntityNodeCount = 6; assertEquals(inputEntityNodeCount, inputEntityNodes.getLength()); for (int i = 0; i < inputEntityNodeCount; i++) { Node entityNode = inputEntityNodes.item(i); lastNames.add( xp.evaluate("ext:PersonSearchResult/ext:Person/nc:PersonName/nc:PersonSurName", entityNode)); firstNames.add( xp.evaluate("ext:PersonSearchResult/ext:Person/nc:PersonName/nc:PersonGivenName", entityNode)); sids.add(xp.evaluate( "ext:PersonSearchResult/ext:Person/jxdm:PersonAugmentation/jxdm:PersonStateFingerprintIdentification/nc:IdentificationID", entityNode)); } Map<String, Integer> lastNameCountMap = new HashMap<String, Integer>(); for (String lastName : lastNames) { Integer count = lastNameCountMap.get(lastName); if (count == null) { count = 0; } lastNameCountMap.put(lastName, ++count); } Map<String, Integer> firstNameCountMap = new HashMap<String, Integer>(); for (String firstName : firstNames) { Integer count = firstNameCountMap.get(firstName); if (count == null) { count = 0; } firstNameCountMap.put(firstName, ++count); } Map<String, Integer> sidCountMap = new HashMap<String, Integer>(); for (String sid : sids) { Integer count = sidCountMap.get(sid); if (count == null) { count = 0; } sidCountMap.put(sid, ++count); } Document resultDocument = entityResolutionMessageHandler.performEntityResolution(entityContainerNode, null, null); resultDocument.normalizeDocument(); // LOG.info(converter.toString(resultDocument)); NodeList entityNodes = (NodeList) xp.evaluate("//merge-result:EntityContainer/merge-result-ext:Entity", resultDocument, XPathConstants.NODESET); assertEquals(inputEntityNodeCount, entityNodes.getLength()); entityNodes = (NodeList) xp.evaluate("//merge-result-ext:MergedRecord", resultDocument, XPathConstants.NODESET); assertEquals(3, entityNodes.getLength()); entityNodes = (NodeList) xp.evaluate("//merge-result-ext:OriginalRecordReference", resultDocument, XPathConstants.NODESET); assertEquals(inputEntityNodeCount, entityNodes.getLength()); for (int i = 0; i < entityNodes.getLength(); i++) { Element e = (Element) entityNodes.item(i); String entityIdRef = e.getAttributeNS(EntityResolutionNamespaceContext.STRUCTURES_NAMESPACE, "ref"); assertNotNull(entityIdRef); assertNotNull(xp.evaluate("//merge-result-ext:Entity[@s:id='" + entityIdRef + "']", resultDocument, XPathConstants.NODE)); } for (String lastName : lastNameCountMap.keySet()) { assertEquals(lastNameCountMap.get(lastName).intValue(), ((Number) xp.evaluate( "count(//merge-result-ext:Entity[ext:PersonSearchResult/ext:Person/nc:PersonName/nc:PersonSurName='" + lastName + "'])", resultDocument, XPathConstants.NUMBER)).intValue()); } for (String firstName : firstNames) { assertEquals(firstNameCountMap.get(firstName).intValue(), ((Number) xp.evaluate( "count(//merge-result-ext:Entity[ext:PersonSearchResult/ext:Person/nc:PersonName/nc:PersonGivenName='" + firstName + "'])", resultDocument, XPathConstants.NUMBER)).intValue()); } for (String sid : sids) { assertEquals(sidCountMap.get(sid).intValue(), ((Number) xp.evaluate( "count(//merge-result-ext:Entity[ext:PersonSearchResult/ext:Person/jxdm:PersonAugmentation/jxdm:PersonStateFingerprintIdentification/nc:IdentificationID='" + sid + "'])", resultDocument, XPathConstants.NUMBER)).intValue()); } String recordLimitExceeded = xp.evaluate( "/merge-result:EntityMergeResultMessage/merge-result:RecordLimitExceededIndicator", resultDocument); assertEquals("false", recordLimitExceeded); }