org.w3c.dom.NamedNodeMap Java Examples

The following examples show how to use org.w3c.dom.NamedNodeMap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Internalizer.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validates attributes of a <jaxb:bindings> element.
 */
private void validate( Element bindings ) {
    NamedNodeMap atts = bindings.getAttributes();
    for( int i=0; i<atts.getLength(); i++ ) {
        Attr a = (Attr)atts.item(i);
        if( a.getNamespaceURI()!=null )
            continue;   // all foreign namespace OK.
        if( a.getLocalName().equals("node") )
            continue;
        if( a.getLocalName().equals("schemaLocation"))
            continue;
        if( a.getLocalName().equals("scd") )
            continue;

        // enhancements
        if( a.getLocalName().equals("required") ) //
            continue;
        if( a.getLocalName().equals("multiple") ) //
            continue;


        // TODO: flag error for this undefined attribute
    }
}
 
Example #2
Source File: SchemaDOM.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void traverse(Node node, int depth) {
    indent(depth);
    System.out.print("<"+node.getNodeName());

    if (node.hasAttributes()) {
        NamedNodeMap attrs = node.getAttributes();
        for (int i=0; i<attrs.getLength(); i++) {
            System.out.print("  "+((Attr)attrs.item(i)).getName()+"=\""+((Attr)attrs.item(i)).getValue()+"\"");
        }
    }

    if (node.hasChildNodes()) {
        System.out.println(">");
        depth+=4;
        for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
            traverse(child, depth);
        }
        depth-=4;
        indent(depth);
        System.out.println("</"+node.getNodeName()+">");
    }
    else {
        System.out.println("/>");
    }
}
 
Example #3
Source File: DomainEditor.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private boolean updateWithSampleDataSource(Document domainDoc){
    boolean sampleExists = false;
    NodeList dataSourceNodeList = domainDoc.getElementsByTagName(CONST_JDBC);
    for(int i=0; i<dataSourceNodeList.getLength(); i++){
        Node dsNode = dataSourceNodeList.item(i);
        NamedNodeMap dsAttrMap = dsNode.getAttributes();
        String jndiName = dsAttrMap.getNamedItem(CONST_JNDINAME).getNodeValue();
        if(jndiName.equals(SAMPLE_DATASOURCE)) {
            sampleExists = true;
        }
    }
    if(!sampleExists) {
        return createSampleDatasource(domainDoc);
    }
    return true;
}
 
Example #4
Source File: SchemaDOM.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void traverse(Node node, int depth) {
    indent(depth);
    System.out.print("<"+node.getNodeName());

    if (node.hasAttributes()) {
        NamedNodeMap attrs = node.getAttributes();
        for (int i=0; i<attrs.getLength(); i++) {
            System.out.print("  "+((Attr)attrs.item(i)).getName()+"=\""+((Attr)attrs.item(i)).getValue()+"\"");
        }
    }

    if (node.hasChildNodes()) {
        System.out.println(">");
        depth+=4;
        for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
            traverse(child, depth);
        }
        depth-=4;
        indent(depth);
        System.out.println("</"+node.getNodeName()+">");
    }
    else {
        System.out.println("/>");
    }
}
 
Example #5
Source File: CloneProfileTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Find subsystems from profile node
 */
private List<String> findSubsystemsInProfile(NodeList nodeList) {
    List<String> output = new LinkedList<>();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node tempNode = nodeList.item(i);
        if (tempNode.getNodeType() == Node.ELEMENT_NODE) {
            String nodeName = tempNode.getNodeName();
            if (!nodeName.contains("subsystem")) {
                continue;
            }
            if (tempNode.hasAttributes()) {
                NamedNodeMap nodeMap = tempNode.getAttributes();
                for (int j = 0; j < nodeMap.getLength(); j++) {
                    Node node = nodeMap.item(j);
                    if (node.getNodeName().equals("xmlns")) {
                        output.add(node.getNodeValue());
                    }
                }
            }
        }
    }
    return output;
}
 
Example #6
Source File: MergeDocuments.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
/**
 * Starts the merge process
 *
 * @param mainDoc  The document to edit.
 * @param mergeDoc The document containing the edit instructions.
 * @throws XPathException A problem parsing the XPath location.
 */
protected void applyMerge(Document mainDoc, Document mergeDoc) throws XPathException {
    NodeList mergeActions = handler.getNodeList(mergeDoc, BASE_XPATH_EXPR);

    for (int i = 0; i < mergeActions.getLength(); i++) {
        Node node = mergeActions.item(i);

        // get the attribute map and action information
        NamedNodeMap attrMap = node.getAttributes();
        String type = attrMap.getNamedItem(ATTR_TYPE).getNodeValue();
        String action = attrMap.getNamedItem(ATTR_ACTION).getNodeValue();
        String xpath = attrMap.getNamedItem(ATTR_XPATH).getNodeValue();
        NodeList actionArgs = node.getChildNodes();

        // perform the transform
        performTransform(mainDoc, type, action, xpath, actionArgs);
    }
}
 
Example #7
Source File: JPEGMetadata.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void mergeStandardTextNode(Node node)
    throws IIOInvalidTreeException {
    // Convert to comments.  For the moment ignore the encoding issue.
    // Ignore keywords, language, and encoding (for the moment).
    // If compression tag is present, use only entries with "none".
    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        NamedNodeMap attrs = child.getAttributes();
        Node comp = attrs.getNamedItem("compression");
        boolean copyIt = true;
        if (comp != null) {
            String compString = comp.getNodeValue();
            if (!compString.equals("none")) {
                copyIt = false;
            }
        }
        if (copyIt) {
            String value = attrs.getNamedItem("value").getNodeValue();
            COMMarkerSegment com = new COMMarkerSegment(value);
            insertCOMMarkerSegment(com);
        }
    }
}
 
Example #8
Source File: AbstractSerializer.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
protected static String createContext(String source, Node ctx) {
    // Create the context to parse the document against
    StringBuilder sb = new StringBuilder();
    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><dummy");

    // Run through each node up to the document node and find any xmlns: nodes
    Map<String, String> storedNamespaces = new HashMap<String, String>();
    Node wk = ctx;
    while (wk != null) {
        NamedNodeMap atts = wk.getAttributes();
        if (atts != null) {
            for (int i = 0; i < atts.getLength(); ++i) {
                Node att = atts.item(i);
                String nodeName = att.getNodeName();
                if ((nodeName.equals("xmlns") || nodeName.startsWith("xmlns:"))
                    && !storedNamespaces.containsKey(att.getNodeName())) {
                    sb.append(" " + nodeName + "=\"" + att.getNodeValue() + "\"");
                    storedNamespaces.put(nodeName, att.getNodeValue());
                }
            }
        }
        wk = wk.getParentNode();
    }
    sb.append(">" + source + "</dummy>");
    return sb.toString();
}
 
Example #9
Source File: HeritrixAttributeValueModifier.java    From Asqatasun with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Document modifyDocument(Document document, String value) {
    if (value == null || value.isEmpty()) {
        LOGGER.debug( " value is empty " + this.getClass());
        return document;
    }
    try {
        Node parentNode = getNodeFromXpath(document);
        NamedNodeMap attr = parentNode.getAttributes();
        Node nodeAttr = attr.getNamedItem(DEFAULT_ATTRIBUTE_NAME);
        if (StringUtils.isNotEmpty(value)) {
            nodeAttr.setTextContent(value);
        } else {
            parentNode.getParentNode().removeChild(parentNode);
        }
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Update " + getAttributeValue() +" attribute of bean "+getIdBeanParent()+ " with value "+ value);
        }
    } catch (XPathExpressionException ex) {
        LOGGER.warn(ex);
    }
    return document;
}
 
Example #10
Source File: XMLUtil.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public static Document replaceSystemPropsInXml(Document doc) {
   NodeList nodeList = doc.getElementsByTagName("*");
   for (int i = 0, len = nodeList.getLength(); i < len; i++) {
      Node node = nodeList.item(i);
      if (node != null && node.getNodeType() == Node.ELEMENT_NODE) {
         if (node.hasAttributes()) {
            NamedNodeMap attributes = node.getAttributes();
            for (int j = 0; j < attributes.getLength(); j++) {
               Node attribute = attributes.item(j);
               attribute.setTextContent(XMLUtil.replaceSystemPropsInString(attribute.getTextContent()));
            }
         }
         if (node.hasChildNodes()) {
            NodeList children = node.getChildNodes();
            for (int j = 0; j < children.getLength(); j++) {
               String value = children.item(j).getNodeValue();
               if (value != null) {
                  children.item(j).setNodeValue(XMLUtil.replaceSystemPropsInString(value));
               }
            }
         }
      }
   }

   return doc;
}
 
Example #11
Source File: AdobeMarkerSegment.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
void updateFromNativeNode(Node node, boolean fromScratch)
    throws IIOInvalidTreeException {
    // Only the transform is required
    NamedNodeMap attrs = node.getAttributes();
    transform = getAttributeValue(node, attrs, "transform", 0, 2, true);
    int count = attrs.getLength();
    if (count > 4) {
        throw new IIOInvalidTreeException
            ("Adobe APP14 node cannot have > 4 attributes", node);
    }
    if (count > 1) {
        int value = getAttributeValue(node, attrs, "version",
                                      100, 255, false);
        version = (value != -1) ? value : version;
        value = getAttributeValue(node, attrs, "flags0", 0, 65535, false);
        flags0 = (value != -1) ? value : flags0;
        value = getAttributeValue(node, attrs, "flags1", 0, 65535, false);
        flags1 = (value != -1) ? value : flags1;
    }
}
 
Example #12
Source File: XmlUtils.java    From ngAndroid with Apache License 2.0 6 votes vote down vote up
private Option<XmlScope> getScopeAttr(Node node) {
    return Option.of(node.getAttributes()).fold(new Option.OptionCB<NamedNodeMap, Option<XmlScope>>() {
        @Override
        public Option<XmlScope> absent() {
            return Option.absent();
        }
        @Override
        public Option<XmlScope> present(NamedNodeMap namedNodeMap) {
            for (Node attr : new NamedNodeMapCollection(namedNodeMap)) {
                Matcher matcher = attrPattern.matcher(attr.toString());
                if(matcher.matches() && scopeAttrNameResolver.getScopeAttrName().equals(matcher.group(1))) {
                    return Option.of(new XmlScope(matcher.group(2)));
                }
            }
            return Option.absent();
        }
    });
}
 
Example #13
Source File: Internalizer.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Declares a new prefix on the given element and associates it
 * with the specified namespace URI.
 * <p>
 * Note that this method doesn't use the default namespace
 * even if it can.
 */
private String allocatePrefix( Element e, String nsUri ) {
    // look for existing namespaces.
    NamedNodeMap atts = e.getAttributes();
    for( int i=0; i<atts.getLength(); i++ ) {
        Attr a = (Attr)atts.item(i);
        if( Const.XMLNS_URI.equals(a.getNamespaceURI()) ) {
            if( a.getName().indexOf(':')==-1 )  continue;

            if( a.getValue().equals(nsUri) )
                return a.getLocalName();    // found one
        }
    }

    // none found. allocate new.
    while(true) {
        String prefix = "p"+(int)(Math.random()*1000000)+'_';
        if(e.getAttributeNodeNS(Const.XMLNS_URI,prefix)!=null)
            continue;   // this prefix is already allocated.

        e.setAttributeNS(Const.XMLNS_URI,"xmlns:"+prefix,nsUri);
        return prefix;
    }
}
 
Example #14
Source File: DOMXPathTransform.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private void unmarshalParams(Element paramsElem) {
    String xPath = paramsElem.getFirstChild().getNodeValue();
    // create a Map of namespace prefixes
    NamedNodeMap attributes = paramsElem.getAttributes();
    if (attributes != null) {
        int length = attributes.getLength();
        Map<String, String> namespaceMap =
            new HashMap<String, String>(length);
        for (int i = 0; i < length; i++) {
            Attr attr = (Attr)attributes.item(i);
            String prefix = attr.getPrefix();
            if (prefix != null && prefix.equals("xmlns")) {
                namespaceMap.put(attr.getLocalName(), attr.getValue());
            }
        }
        this.params = new XPathFilterParameterSpec(xPath, namespaceMap);
    } else {
        this.params = new XPathFilterParameterSpec(xPath);
    }
}
 
Example #15
Source File: XmlCombiner.java    From xml-combiner with Apache License 2.0 6 votes vote down vote up
/**
 * Copies attributes from one {@link Element} to the other.
 * @param source source element
 * @param destination destination element
 */
private void copyAttributes(@Nullable Element source, Element destination) {
	if (source == null) {
		return;
	}
	NamedNodeMap attributes = source.getAttributes();
	for (int i = 0; i < attributes.getLength(); i++) {
		Attr attribute = (Attr) attributes.item(i);
		Attr destAttribute = destination.getAttributeNodeNS(attribute.getNamespaceURI(), attribute.getName());

		if (destAttribute == null) {
			destination.setAttributeNodeNS((Attr) document.importNode(attribute, true));
		} else {
			destAttribute.setValue(attribute.getValue());
		}
	}
}
 
Example #16
Source File: PhysicalModelPropertiesFromFileInitializer.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
private void initModelAdmissibleValues(NodeList nodes, Model model) throws Exception {
	int nodesLength = nodes.getLength();
	for (int j = 0; j < nodesLength; j++) {
		NamedNodeMap nodeAttributes = nodes.item(j).getAttributes();
		if (nodeAttributes != null) {
			String typeId = nodeAttributes.getNamedItem("typeId").getNodeValue();
			ModelPropertyType propertyType = getModelPropertyType(model, typeId);

			NodeList values = nodes.item(j).getChildNodes();

			for (int z = 0; z < values.getLength(); z++) {
				Node n = values.item(z);
				String nodeName = n.getNodeName();
				if ("value".equalsIgnoreCase(nodeName)) {
					/**
					 * TODO REVIEW FOR PORTING
					 */
					String value = values.item(z).getTextContent();
					propertyType.getAdmissibleValues().add(value);
				}
			}
		}
	}
}
 
Example #17
Source File: TypeGen.java    From j-road with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a map of the namespaces from the WSDL definitions element for XmlBeans
 *
 * @param wsdlDoc
 */
private static Map<String, String> getNamespaces(Document wsdlDoc) {
  Map<String, String> additionalNs = new HashMap<String, String>();
  NamedNodeMap map = wsdlDoc.getElementsByTagNameNS(WSDL_NS, "definitions").item(0).getAttributes();
  for (int i = 0; i < map.getLength(); i++) {
    Node attribute = map.item(i);
    if (NS_PREFIX.equals(attribute.getPrefix()) && attribute.getLocalName() != null) {
      additionalNs.put(attribute.getLocalName(), attribute.getNodeValue());
    }
  }
  return additionalNs;
}
 
Example #18
Source File: NodeUtils.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
private static String getUniqueNsAttribute(NamedNodeMap attributes) {
    if (attributes == null) {
        return "xmlns:ns1";
    }

    int i = 2;
    while (true) {
        String name = String.format("xmlns:ns%d", i++);
        if (attributes.getNamedItem(name) == null) {
            return name;
        }
    }
}
 
Example #19
Source File: TestLayoutVsICU.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static Map<String, String> attrs(Node testCase) {
    Map<String,String> rv = new TreeMap<String,String>();
    NamedNodeMap nnm = testCase.getAttributes();
    for(int i=0;i<nnm.getLength();i++) {
        Node n = nnm.item(i);
        String k = n.getNodeName();
        String v = n.getNodeValue();
        rv.put(k, v);
    }
    return rv;
}
 
Example #20
Source File: DocumentTypeImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * NON-DOM: Access the collection of ElementDefinitions.
 * @see ElementDefinitionImpl
 */
public NamedNodeMap getElements() {
    if (needsSyncChildren()) {
        synchronizeChildren();
    }
    return elements;
}
 
Example #21
Source File: DHTMarkerSegment.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
Htable(Node node) throws IIOInvalidTreeException {
    if (node.getNodeName().equals("dhtable")) {
        NamedNodeMap attrs = node.getAttributes();
        int count = attrs.getLength();
        if (count != 2) {
            throw new IIOInvalidTreeException
                ("dhtable node must have 2 attributes", node);
        }
        tableClass = getAttributeValue(node, attrs, "class", 0, 1, true);
        tableID = getAttributeValue(node, attrs, "htableId", 0, 3, true);
        if (node instanceof IIOMetadataNode) {
            IIOMetadataNode ourNode = (IIOMetadataNode) node;
            JPEGHuffmanTable table =
                (JPEGHuffmanTable) ourNode.getUserObject();
            if (table == null) {
                throw new IIOInvalidTreeException
                    ("dhtable node must have user object", node);
            }
            numCodes = table.getLengths();
            values = table.getValues();
        } else {
            throw new IIOInvalidTreeException
                ("dhtable node must have user object", node);
        }
    } else {
        throw new IIOInvalidTreeException
            ("Invalid node, expected dqtable", node);
    }

}
 
Example #22
Source File: SOSMarkerSegment.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
ScanComponentSpec(Node node) throws IIOInvalidTreeException {
    NamedNodeMap attrs = node.getAttributes();
    componentSelector = getAttributeValue(node, attrs, "componentSelector",
                                          0, 255, true);
    dcHuffTable = getAttributeValue(node, attrs, "dcHuffTable",
                                    0, 3, true);
    acHuffTable = getAttributeValue(node, attrs, "acHuffTable",
                                    0, 3, true);
}
 
Example #23
Source File: ToolContentVersionFilter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static Node renameNode(Node oldNode, String oldName, String newName) {
if (oldNode.getNodeName().equals(oldName)) {
    Element newNode = oldNode.getOwnerDocument().createElement(newName);

    //copy attributes
    if (oldNode.getAttributes() != null) {
	NamedNodeMap attributes = oldNode.getAttributes();
	for (int attrIndex = 0; attrIndex < attributes.getLength(); attrIndex++) {
	    Node clonedAttribute = attributes.item(attrIndex).cloneNode(true);
	    String value = clonedAttribute.getTextContent();
	    if (value != null && value.contains(oldName)) {
		value = value.replace(oldName, newName);
		clonedAttribute.setTextContent(value);
	    }
	    newNode.getAttributes().setNamedItem(clonedAttribute);
	}
    }

    if (oldNode.hasChildNodes()) {
	//copy child nodes
	NodeList children = oldNode.getChildNodes();
	for (int childIndex = 0; childIndex < children.getLength(); childIndex++) {
	    Node clonedChildNode = children.item(childIndex).cloneNode(true);
	    newNode.appendChild(clonedChildNode);
	}
    } else {
	newNode.setTextContent(oldNode.getTextContent());
    }
    oldNode.getParentNode().replaceChild(newNode, oldNode);
    ToolContentVersionFilter.log.debug("Node " + oldName + " was renamed to " + newName);
    return newNode;
}
return oldNode;
   }
 
Example #24
Source File: DocumentType.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Returns entities.
 * @return entities
 */
@JsxGetter
public Object getEntities() {
    final NamedNodeMap entities = ((DomDocumentType) getDomNodeOrDie()).getEntities();
    if (null != entities) {
        return entities;
    }

    if (getBrowserVersion().hasFeature(JS_DOCTYPE_ENTITIES_NULL)) {
        return null;
    }
    return Undefined.instance;
}
 
Example #25
Source File: RuleElement.java    From OpenEphyra with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Instantiates a RuleElement from an XML Element.  
 * @param ruleElementElement the Element to construct a Rule from
 */    
public RuleElement(Element ruleElementElement) {
    NamedNodeMap ruleElementAttributes = ruleElementElement.getAttributes();
    this.feature = ruleElementAttributes.getNamedItem("feature_name").getNodeValue().toString();
    
    this.values = new HashSet<String>();
    NodeList featureValueList = ruleElementElement.getChildNodes();
    for (int j = 0; j < featureValueList.getLength(); j++) {
        Node featureValueElement = featureValueList.item(j);
        if (!featureValueElement.getNodeName().equals("FEATURE_VALUE")) continue;
        values.add(featureValueElement.getChildNodes().item(0).getNodeValue());
    }
}
 
Example #26
Source File: ResourceItem.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
private ResourceType getType(String qName, NamedNodeMap attributes) {
    String typeValue;

    // if the node is <item>, we get the type from the attribute "type"
    if (SdkConstants.TAG_ITEM.equals(qName)) {
        typeValue = getAttributeValue(attributes, ATTR_TYPE);
    } else {
        // the type is the name of the node.
        typeValue = qName;
    }

    return ResourceType.getEnum(typeValue);
}
 
Example #27
Source File: XAdESCanonicalizationTest.java    From dss with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void checkSignedProperties(Document doc) {
	// ------------------------------------ SIGNED PROPERTIES
	// -----------------------------------------------------
	try {
		// Signed properties extraction + verification
		NodeList signedPropertiesNodeList = DomUtils.getNodeList(doc, AbstractPaths.all(XAdES132Element.SIGNED_PROPERTIES));
		assertNotNull(signedPropertiesNodeList);
		assertEquals(1, signedPropertiesNodeList.getLength());

		Node signedProperties = signedPropertiesNodeList.item(0);

		NamedNodeMap signedPropertiesAttributes = signedProperties.getAttributes();
		Node signedPropertiesId = signedPropertiesAttributes.getNamedItem("Id");
		assertNotNull(signedPropertiesId);

		Canonicalizer canonicalizer = Canonicalizer.getInstance(canonicalizationSignedProperties);

		// Verify KeyInfo Canonicalization Algorithm
		NodeList transformNodes = getReferenceTransforms(doc, "#" + signedPropertiesId.getNodeValue());
		String signedPropertiesTransformAlgo = getTransformAlgo(transformNodes.item(0));
		assertEquals(canonicalizer.getURI(), signedPropertiesTransformAlgo);

		// Verify KeyInfo Digest
		String signedPropertiesDigest = getReferenceDigest(doc, "#" + signedPropertiesId.getNodeValue());
		byte[] canonicalizedSignedProperties = canonicalizer.canonicalizeSubtree(signedProperties);
		byte[] digestProperties = DSSUtils.digest(DigestAlgorithm.SHA256, canonicalizedSignedProperties);
		String propertiesBase64 = Base64.getEncoder().encodeToString(digestProperties);
		assertEquals(propertiesBase64, signedPropertiesDigest);
	} catch (Exception e) {
		fail(e.getMessage());
	}
}
 
Example #28
Source File: C14nHelper.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This method throws a CanonicalizationException if the supplied Element
 * contains any relative namespaces.
 *
 * @param ctxNode
 * @throws CanonicalizationException
 * @see C14nHelper#assertNotRelativeNS(Attr)
 */
public static void checkForRelativeNamespace(Element ctxNode)
    throws CanonicalizationException {
    if (ctxNode != null) {
        NamedNodeMap attributes = ctxNode.getAttributes();

        for (int i = 0; i < attributes.getLength(); i++) {
            C14nHelper.assertNotRelativeNS((Attr) attributes.item(i));
        }
    } else {
        throw new CanonicalizationException("Called checkForRelativeNamespace() on null");
    }
}
 
Example #29
Source File: SignedElementsBuilder.java    From steady with Apache License 2.0 5 votes vote down vote up
private void addNamespaces(Node element, SignedEncryptedElements parent) {
    if (element.getParentNode() != null) {
        addNamespaces(element.getParentNode(), parent);
    }
    if (element instanceof Element) {
        Element el = (Element)element;
        NamedNodeMap map = el.getAttributes();
        for (int x = 0; x < map.getLength(); x++) {
            Attr attr = (Attr)map.item(x);
            if ("xmlns".equals(attr.getPrefix())) {
                parent.addDeclaredNamespaces(attr.getValue(), attr.getLocalName());
            }
        }
    }
}
 
Example #30
Source File: AbstractXmlNode.java    From JVoiceXML with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Checks, if the attribute with the given name is present.
 * @param attribute name of the attribute to check for
 * @return <code>true</code> if there is an attribute with the given name
 * @since 0.7.6
 */
public final boolean hasAttribute(final String attribute) {
    final NamedNodeMap attributes = node.getAttributes();
    if (attributes == null) {
        return false;
    }
    final Node item = attributes.getNamedItem(attribute);
    return item != null;
}