类org.w3c.dom.Attr源码实例Demo

下面列出了怎么用org.w3c.dom.Attr的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: lams   文件: EntitiesDescriptorUnmarshaller.java
/** {@inheritDoc} */
protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {
    EntitiesDescriptor entitiesDescriptor = (EntitiesDescriptor) samlObject;

    if (attribute.getLocalName().equals(EntitiesDescriptor.ID_ATTRIB_NAME)) {
        entitiesDescriptor.setID(attribute.getValue());
        attribute.getOwnerElement().setIdAttributeNode(attribute, true);
    } else if (attribute.getLocalName().equals(TimeBoundSAMLObject.VALID_UNTIL_ATTRIB_NAME)
            && !DatatypeHelper.isEmpty(attribute.getValue())) {
        entitiesDescriptor.setValidUntil(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC()));
    } else if (attribute.getLocalName().equals(CacheableSAMLObject.CACHE_DURATION_ATTRIB_NAME)) {
        entitiesDescriptor.setCacheDuration(new Long(XMLHelper.durationToLong(attribute.getValue())));
    } else if (attribute.getLocalName().equals(EntitiesDescriptor.NAME_ATTRIB_NAME)) {
        entitiesDescriptor.setName(attribute.getValue());
    } else {
        super.processAttribute(samlObject, attribute);
    }
}
 
源代码2 项目: jdk8u60   文件: AbstractDOMParser.java
protected Attr createAttrNode (QName attrQName) {
    Attr attr = null;

    if (fNamespaceAware) {
        if (fDocumentImpl != null) {
            // if we are using xerces DOM implementation, call our
            // own constructor to reuse the strings we have here.
            attr = fDocumentImpl.createAttributeNS (attrQName.uri,
            attrQName.rawname,
            attrQName.localpart);
        }
        else {
            attr = fDocument.createAttributeNS (attrQName.uri,
            attrQName.rawname);
        }
    }
    else {
        attr = fDocument.createAttribute (attrQName.rawname);
    }

    return attr;
}
 
源代码3 项目: lewis   文件: LayoutIdFormat.java
@Override
public void visitAttribute(@NonNull XmlContext context, @NonNull Attr attribute) {
    String value = attribute.getValue();

    if (!value.isEmpty()) {

        // Make sure this is really one of the android: attributes
        if (!ANDROID_URI.equals(attribute.getNamespaceURI())) {
            return;
        }

        value = value.substring(5); // ignore "@+id/"

        if (!idCorrectFormat(value)) {
            context.report(ISSUE, attribute, context.getLocation(attribute),
                    String.format("The id \"%1$s\", should be written using lowerCamelCase.", value));
        }

    }
}
 
源代码4 项目: openjdk-8-source   文件: SignatureAlgorithm.java
/**
 * Constructor SignatureAlgorithm
 *
 * @param element
 * @param baseURI
 * @param secureValidation
 * @throws XMLSecurityException
 */
public SignatureAlgorithm(
    Element element, String baseURI, boolean secureValidation
) throws XMLSecurityException {
    super(element, baseURI);
    algorithmURI = this.getURI();

    Attr attr = element.getAttributeNodeNS(null, "Id");
    if (attr != null) {
        element.setIdAttributeNode(attr, true);
    }

    if (secureValidation && (XMLSignature.ALGO_ID_MAC_HMAC_NOT_RECOMMENDED_MD5.equals(algorithmURI)
        || XMLSignature.ALGO_ID_SIGNATURE_NOT_RECOMMENDED_RSA_MD5.equals(algorithmURI))) {
        Object exArgs[] = { algorithmURI };

        throw new XMLSecurityException("signature.signatureAlgorithm", exArgs);
    }

    signatureAlgorithm = getSignatureAlgorithmSpi(algorithmURI);
    signatureAlgorithm.engineGetContextFromElement(this.constructionElement);
}
 
源代码5 项目: openjdk-jdk9   文件: SetAttributeNode.java
public static void test2() {
    String name = "attr";
    String oldValue = "old value";
    String newValue = "new value";
    Attr retAttr;

    IIOMetadataNode parent = new IIOMetadataNode("parent");
    MyAttrNode attrNode1 = new MyAttrNode(name, oldValue);
    MyAttrNode attrNode2 = new MyAttrNode(name, newValue);

    retAttr = parent.setAttributeNode(attrNode1);
    retAttr = parent.setAttributeNode(attrNode2);

    String actName = retAttr.getNodeName();
    String actValue = retAttr.getValue();

    if (!actName.equals(name) || !actValue.equals(oldValue)) {
        throw new RuntimeException("Test 2 failed: Invalid attribute " +
                                   "returned: " +
                                   "(name: " + actName +
                                   ", value: " + actValue + ")");
    }
}
 
源代码6 项目: openjdk-8   文件: NameSpaceSymbTable.java
/**
 * Gets the attribute node that defines the binding for the prefix.
 * @param prefix the prefix to obtain the attribute.
 * @return null if there is no need to render the prefix. Otherwise the node of
 * definition.
 **/
public Attr getMapping(String prefix) {
    NameSpaceSymbEntry entry = symb.get(prefix);
    if (entry == null) {
        //There is no definition for the prefix(a bug?).
        return null;
    }
    if (entry.rendered) {
        //No need to render an entry already rendered.
        return null;
    }
    // Mark this entry as render.
    entry = (NameSpaceSymbEntry) entry.clone();
    needsClone();
    symb.put(prefix, entry);
    entry.rendered = true;
    entry.lastrendered = entry.uri;
    // Return the node for outputing.
    return entry.n;
}
 
源代码7 项目: j2objc   文件: ElementImpl.java
public Attr setAttributeNode(Attr newAttr) throws DOMException {
    AttrImpl newAttrImpl = (AttrImpl) newAttr;

    if (newAttrImpl.document != this.document) {
        throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, null);
    }

    if (newAttrImpl.getOwnerElement() != null) {
        throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR, null);
    }

    AttrImpl oldAttrImpl = null;

    int i = indexOfAttribute(newAttr.getName());
    if (i != -1) {
        oldAttrImpl = attributes.get(i);
        attributes.remove(i);
    }

    attributes.add(newAttrImpl);
    newAttrImpl.ownerElement = this;

    return oldAttrImpl;
}
 
源代码8 项目: knox   文件: XmlUrlRewriteRulesExporter.java
private Element createElement( Document document, String name, Object bean )
    throws IntrospectionException, InvocationTargetException, NoSuchMethodException, IllegalAccessException {
  Element element = document.createElement( name );
  BeanInfo beanInfo = Introspector.getBeanInfo( bean.getClass(), Object.class );
  for( PropertyDescriptor propInfo: beanInfo.getPropertyDescriptors() ) {
    String propName = propInfo.getName();
    if( propInfo.getReadMethod() != null && String.class.isAssignableFrom( propInfo.getPropertyType() ) ) {
      String propValue = BeanUtils.getProperty( bean, propName );
      if( propValue != null && !propValue.isEmpty() ) {
        // Doing it the hard way to avoid having the &'s in the query string escaped at &
        Attr attr = document.createAttribute( propName );
        attr.setValue( propValue );
        element.setAttributeNode( attr );
        //element.setAttribute( propName, propValue );
      }
    }
  }
  return element;
}
 
源代码9 项目: JDKSourceCode1.8   文件: SignatureProperties.java
/**
 * Constructs {@link SignatureProperties} from {@link Element}
 * @param element <code>SignatureProperties</code> element
 * @param BaseURI the URI of the resource where the XML instance was stored
 * @throws XMLSecurityException
 */
public SignatureProperties(Element element, String BaseURI) throws XMLSecurityException {
    super(element, BaseURI);

    Attr attr = element.getAttributeNodeNS(null, "Id");
    if (attr != null) {
        element.setIdAttributeNode(attr, true);
    }

    int length = getLength();
    for (int i = 0; i < length; i++) {
        Element propertyElem =
            XMLUtils.selectDsNode(this.constructionElement, Constants._TAG_SIGNATUREPROPERTY, i);
        Attr propertyAttr = propertyElem.getAttributeNodeNS(null, "Id");
        if (propertyAttr != null) {
            propertyElem.setIdAttributeNode(propertyAttr, true);
        }
    }
}
 
源代码10 项目: astor   文件: XmlNode.java
private void addNamespaces(Namespaces rv, Element element) {
    if (element == null) throw new RuntimeException("element must not be null");
    String myDefaultNamespace = toUri(element.lookupNamespaceURI(null));
    String parentDefaultNamespace = "";
    if (element.getParentNode() != null) {
        parentDefaultNamespace = toUri(element.getParentNode().lookupNamespaceURI(null));
    }
    if (!myDefaultNamespace.equals(parentDefaultNamespace) || !(element.getParentNode() instanceof Element) ) {
        rv.declare(Namespace.create("", myDefaultNamespace));
    }
    NamedNodeMap attributes = element.getAttributes();
    for (int i=0; i<attributes.getLength(); i++) {
        Attr attr = (Attr)attributes.item(i);
        if (attr.getPrefix() != null && attr.getPrefix().equals("xmlns")) {
            rv.declare(Namespace.create(attr.getLocalName(), attr.getValue()));
        }
    }
}
 
源代码11 项目: lams   文件: ContactPersonUnmarshaller.java
/** {@inheritDoc} */
protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {
    ContactPerson person = (ContactPerson) samlObject;

    if (attribute.getLocalName().equals(ContactPerson.CONTACT_TYPE_ATTRIB_NAME)) {
        if (ContactPersonTypeEnumeration.TECHNICAL.toString().equals(attribute.getValue())) {
            person.setType(ContactPersonTypeEnumeration.TECHNICAL);
        } else if (ContactPersonTypeEnumeration.SUPPORT.toString().equals(attribute.getValue())) {
            person.setType(ContactPersonTypeEnumeration.SUPPORT);
        } else if (ContactPersonTypeEnumeration.ADMINISTRATIVE.toString().equals(attribute.getValue())) {
            person.setType(ContactPersonTypeEnumeration.ADMINISTRATIVE);
        } else if (ContactPersonTypeEnumeration.BILLING.toString().equals(attribute.getValue())) {
            person.setType(ContactPersonTypeEnumeration.BILLING);
        } else if (ContactPersonTypeEnumeration.OTHER.toString().equals(attribute.getValue())) {
            person.setType(ContactPersonTypeEnumeration.OTHER);
        } else {
            super.processAttribute(samlObject, attribute);
        }
    } else {
        QName attribQName = XMLHelper.getNodeQName(attribute);
        if (attribute.isId()) {
            person.getUnknownAttributes().registerID(attribQName);
        }
        person.getUnknownAttributes().put(attribQName, attribute.getValue());
    }
}
 
源代码12 项目: openjdk-8-source   文件: C14nHelper.java
/**
 * This method throws an exception if the Attribute value contains
 * a relative URI.
 *
 * @param attr
 * @throws CanonicalizationException
 */
public static void assertNotRelativeNS(Attr attr) throws CanonicalizationException {
    if (attr == null) {
        return;
    }

    String nodeAttrName = attr.getNodeName();
    boolean definesDefaultNS = nodeAttrName.equals("xmlns");
    boolean definesNonDefaultNS = nodeAttrName.startsWith("xmlns:");

    if ((definesDefaultNS || definesNonDefaultNS) && namespaceIsRelative(attr)) {
        String parentName = attr.getOwnerElement().getTagName();
        String attrValue = attr.getValue();
        Object exArgs[] = { parentName, nodeAttrName, attrValue };

        throw new CanonicalizationException(
            "c14n.Canonicalizer.RelativeNamespace", exArgs
        );
    }
}
 
/** {@inheritDoc} */
protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {

    AuthorizationDecisionStatement authorizationDecisionStatement;
    authorizationDecisionStatement = (AuthorizationDecisionStatement) samlObject;

    if (AuthorizationDecisionStatement.DECISION_ATTRIB_NAME.equals(attribute.getLocalName())) {
        String value = attribute.getValue();
        if (value.equals(DecisionTypeEnumeration.PERMIT.toString())) {
            authorizationDecisionStatement.setDecision(DecisionTypeEnumeration.PERMIT);
        } else if (value.equals(DecisionTypeEnumeration.DENY.toString())) {
            authorizationDecisionStatement.setDecision(DecisionTypeEnumeration.DENY);
        } else if (value.equals(DecisionTypeEnumeration.INDETERMINATE.toString())) {
            authorizationDecisionStatement.setDecision(DecisionTypeEnumeration.INDETERMINATE);
        } else {
            log.error("Unknown value for DecisionType '" + value + "'");
            throw new UnmarshallingException("Unknown value for DecisionType '" + value + "'");
        }
    } else if (AuthorizationDecisionStatement.RESOURCE_ATTRIB_NAME.equals(attribute.getLocalName())) {
        authorizationDecisionStatement.setResource(attribute.getValue());
    } else {
        super.processAttribute(samlObject, attribute);
    }
}
 
源代码14 项目: windup   文件: XmlUtil.java
/**
 * Converts the given {@link Node} to a {@link String}.
 */
public static String nodeToString(Node node)
{
    StringWriter sw = new StringWriter();
    if (node instanceof Attr)
    {
        Attr attr = (Attr) node;
        return attr.getValue();
    }
    try
    {
        Transformer t = TransformerFactory.newInstance().newTransformer();
        t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        t.setOutputProperty(OutputKeys.INDENT, "no");
        t.transform(new DOMSource(node), new StreamResult(sw));
    }
    catch (TransformerException te)
    {
        LOG.warning("Transformer Exception: " + te.getMessage());
    }
    return sw.toString();
}
 
源代码15 项目: Flashtool   文件: XmlCombiner.java
private static CombineChildren getCombineChildren(@Nullable Element element) {
	CombineChildren combine = null;
	if (element == null) {
		return null;
	}
	Attr combineAttribute = element.getAttributeNode(CombineChildren.ATTRIBUTE_NAME);
	if (combineAttribute != null) {
		try {
			combine = CombineChildren.valueOf(combineAttribute.getValue().toUpperCase());
		} catch (IllegalArgumentException e) {
			throw new RuntimeException("The attribute 'combine' of element '"
					+ element.getTagName() + "' has invalid value '"
					+ combineAttribute.getValue(), e);
		}
	}
	return combine;
}
 
源代码16 项目: openjdk-jdk8u   文件: Internalizer.java
/**
 * 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;
    }
}
 
源代码17 项目: jdk8u-dev-jdk   文件: XMLUtils.java
/**
 * This method returns the first non-null owner document of the Nodes in this Set.
 * This method is necessary because it <I>always</I> returns a
 * {@link Document}. {@link Node#getOwnerDocument} returns <CODE>null</CODE>
 * if the {@link Node} is a {@link Document}.
 *
 * @param xpathNodeSet
 * @return the owner document
 */
public static Document getOwnerDocument(Set<Node> xpathNodeSet) {
    NullPointerException npe = null;
    for (Node node : xpathNodeSet) {
        int nodeType = node.getNodeType();
        if (nodeType == Node.DOCUMENT_NODE) {
            return (Document) node;
        }
        try {
            if (nodeType == Node.ATTRIBUTE_NODE) {
                return ((Attr)node).getOwnerElement().getOwnerDocument();
            }
            return node.getOwnerDocument();
        } catch (NullPointerException e) {
            npe = e;
        }
    }

    throw new NullPointerException(I18n.translate("endorsed.jdk1.4.0")
                                   + " Original message was \""
                                   + (npe == null ? "" : npe.getMessage()) + "\"");
}
 
源代码18 项目: hottub   文件: ElementImpl.java
/**
 * Look up a single Attribute by name. Returns the Attribute's
 * string value, or an empty string (NOT null!) to indicate that the
 * name did not map to a currently defined attribute.
 * <p>
 * Note: Attributes may contain complex node trees. This method
 * returns the "flattened" string obtained from Attribute.getValue().
 * If you need the structure information, see getAttributeNode().
 */
public String getAttribute(String name) {

    if (needsSyncData()) {
        synchronizeData();
    }
    if (attributes == null) {
        return "";
    }
    Attr attr = (Attr)(attributes.getNamedItem(name));
    return (attr == null) ? "" : attr.getValue();

}
 
源代码19 项目: TencentKona-8   文件: XMLDOMWriterImpl.java
/**
 * Creates a DOM Atrribute @see org.w3c.dom.Node and associates it with the current DOM element @see org.w3c.dom.Node.
 * @param namespaceURI {@inheritDoc}
 * @param localName {@inheritDoc}
 * @param value {@inheritDoc}
 * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
 */
public void writeAttribute(String namespaceURI,String localName,String value)throws XMLStreamException {
    if(currentNode.getNodeType() == Node.ELEMENT_NODE){
        String prefix = null;
        if(namespaceURI == null ){
            throw new XMLStreamException("NamespaceURI cannot be null");
        }
        if(localName == null){
            throw new XMLStreamException("Local name cannot be null");
        }
        if(namespaceContext != null){
            prefix = namespaceContext.getPrefix(namespaceURI);
        }

        if(prefix == null){
            throw new XMLStreamException("Namespace URI "+namespaceURI +
                    "is not bound to any prefix" );
        }

        String qualifiedName = null;
        if(prefix.equals("")){
            qualifiedName = localName;
        }else{
            qualifiedName = getQName(prefix,localName);
        }
        Attr attr = ownerDoc.createAttributeNS(namespaceURI, qualifiedName);
        attr.setValue(value);
        ((Element)currentNode).setAttributeNode(attr);
    }else{
        //Convert node type to String
        throw new IllegalStateException("Current DOM Node type  is "+ currentNode.getNodeType() +
                "and does not allow attributes to be set ");
    }
}
 
源代码20 项目: openjdk-jdk9   文件: XMLDOMWriterImpl.java
/**
 * Creates a DOM Atrribute @see org.w3c.dom.Node and associates it with the current DOM element @see org.w3c.dom.Node.
 * @param localName {@inheritDoc}
 * @param value {@inheritDoc}
 * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
 */
public void writeAttribute(String localName, String value) throws XMLStreamException {

    if(currentNode.getNodeType() == Node.ELEMENT_NODE){
        Attr attr = ownerDoc.createAttribute(localName);
        attr.setValue(value);
        ((Element)currentNode).setAttributeNode(attr);
    }else{
        //Convert node type to String
        throw new IllegalStateException("Current DOM Node type  is "+ currentNode.getNodeType() +
                "and does not allow attributes to be set ");
    }
}
 
源代码21 项目: openjdk-8-source   文件: DOMStreamReader.java
/**
 * This method is not particularly fast, but shouldn't be called very
 * often. If we start to use it more, we should keep track of the
 * NS declarations using a NamespaceContext implementation instead.
 */
public String getNamespaceURI(String prefix) {
    if (prefix == null) {
        throw new IllegalArgumentException("DOMStreamReader: getNamespaceURI(String) call with a null prefix");
    }
    else if (prefix.equals("xml")) {
        return "http://www.w3.org/XML/1998/namespace";
    }
    else if (prefix.equals("xmlns")) {
        return "http://www.w3.org/2000/xmlns/";
    }

    // check scopes
    String nsUri = scopes[depth].getNamespaceURI(prefix);
    if(nsUri!=null)    return nsUri;

    // then ancestors above start node
    Node node = findRootElement();
    String nsDeclName = prefix.length()==0 ? "xmlns" : "xmlns:"+prefix;
    while (node.getNodeType() != DOCUMENT_NODE) {
        // Is ns declaration on this element?
        NamedNodeMap namedNodeMap = node.getAttributes();
        Attr attr = (Attr) namedNodeMap.getNamedItem(nsDeclName);
        if (attr != null)
            return attr.getValue();
        node = node.getParentNode();
    }
    return null;
}
 
源代码22 项目: openjdk-jdk8u   文件: DOMStreamReader.java
/**
 * Called when the current node is {@link Element} to look at attribute list
 * (which contains both ns decl and attributes in DOM) and split them
 * to attributes-proper and namespace decls.
 */
protected void splitAttributes() {
    // Clear attribute and namespace lists
    _currentAttributes.clear();

    Scope scope = allocateScope();

    _namedNodeMap = _current.getAttributes();
    if (_namedNodeMap != null) {
        final int n = _namedNodeMap.getLength();
        for (int i = 0; i < n; i++) {
            final Attr attr = (Attr) _namedNodeMap.item(i);
            final String attrName = attr.getNodeName();
            if (attrName.startsWith("xmlns:") || attrName.equals("xmlns")) {     // NS decl?
                scope.currentNamespaces.add(attr);
            }
            else {
                _currentAttributes.add(attr);
            }
        }
    }

    // verify that all the namespaces used in element and attributes are indeed available
    ensureNs(_current);
    for( int i=_currentAttributes.size()-1; i>=0; i-- ) {
        Attr a = _currentAttributes.get(i);
        if(fixNull(a.getNamespaceURI()).length()>0)
            ensureNs(a);    // no need to declare "" for attributes in the default namespace
    }
}
 
源代码23 项目: openjdk-8-source   文件: Canonicalizer20010315.java
void getXmlnsAttr(Collection<Attr> col) {
    int size = levels.size() - 1;
    if (cur == null) {
        cur = new XmlsStackElement();
        cur.level = currentLevel;
        lastlevel = currentLevel;
        levels.add(cur);
    }
    boolean parentRendered = false;
    XmlsStackElement e = null;
    if (size == -1) {
        parentRendered = true;
    } else {
        e = levels.get(size);
        if (e.rendered && e.level + 1 == currentLevel) {
            parentRendered = true;
        }
    }
    if (parentRendered) {
        col.addAll(cur.nodes);
        cur.rendered = true;
        return;
    }

    Map<String, Attr> loa = new HashMap<String, Attr>();
    for (; size >= 0; size--) {
        e = levels.get(size);
        Iterator<Attr> it = e.nodes.iterator();
        while (it.hasNext()) {
            Attr n = it.next();
            if (!loa.containsKey(n.getName())) {
                loa.put(n.getName(), n);
            }
        }
    }

    cur.rendered = true;
    col.addAll(loa.values());
}
 
源代码24 项目: netbeans   文件: Hk2DatasourceManager.java
private static void appendAttr(Document doc, Node node, String name, String value, boolean force) {
    if(force || (name != null && name.length() > 0)) {
        Attr attr = doc.createAttribute(name);
        attr.setValue(value);
        NamedNodeMap attrs = node.getAttributes();
        attrs.setNamedItem(attr);
    }
}
 
源代码25 项目: JDKSourceCode1.8   文件: ElementImpl.java
/**
* Add a new name/value pair, or replace the value of the existing
* attribute having that name.
*
* Note: this method supports only the simplest kind of Attribute,
* one whose value is a string contained in a single Text node.
* If you want to assert a more complex value (which XML permits,
* though HTML doesn't), see setAttributeNode().
*
* The attribute is created with specified=true, meaning it's an
* explicit value rather than inherited from the DTD as a default.
* Again, setAttributeNode can be used to achieve other results.
*
* @throws DOMException(INVALID_NAME_ERR) if the name is not acceptable.
* (Attribute factory will do that test for us.)
*
* @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if the node is
* readonly.
*/
   public void setAttribute(String name, String value) {

           if (ownerDocument.errorChecking && isReadOnly()) {
                   String msg =
                           DOMMessageFormatter.formatMessage(
                                   DOMMessageFormatter.DOM_DOMAIN,
                                   "NO_MODIFICATION_ALLOWED_ERR",
                                   null);
                   throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
           }

           if (needsSyncData()) {
                   synchronizeData();
           }

           Attr newAttr = getAttributeNode(name);
           if (newAttr == null) {
                   newAttr = getOwnerDocument().createAttribute(name);

                   if (attributes == null) {
                           attributes = new AttributeMap(this, null);
                   }

                   newAttr.setNodeValue(value);
                   attributes.setNamedItem(newAttr);
           }
           else {
                   newAttr.setNodeValue(value);
           }

   }
 
源代码26 项目: fastods   文件: AttrList.java
/**
 * @param attributes the attributes
 * @return the attr list
 */
static AttrList create(final NamedNodeMap attributes) {
    final int l = attributes.getLength();
    final List<Attr> as = new ArrayList<Attr>(l);
    for (int i = 0; i < l; i++) {
        as.add((Attr) attributes.item(i));
    }
    return new AttrList(as);
}
 
源代码27 项目: openjdk-8   文件: DOMNamespaceContext.java
private void addNamespaces(Node element) {
    if (element.getParentNode() != null) {
        addNamespaces(element.getParentNode());
    }
    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())) {
                namespaceMap.put(attr.getLocalName(), attr.getValue());
            }
        }
    }
}
 
源代码28 项目: lams   文件: SignatureConfirmationUnmarshaller.java
/** {@inheritDoc} */
protected void processAttribute(XMLObject xmlObject, Attr attribute) throws UnmarshallingException {
    SignatureConfirmation sc = (SignatureConfirmation) xmlObject;
    
    QName attrName =
        XMLHelper.constructQName(attribute.getNamespaceURI(), attribute.getLocalName(), attribute.getPrefix());
    if (SignatureConfirmation.WSU_ID_ATTR_NAME.equals(attrName)) {
        sc.setWSUId(attribute.getValue());
        attribute.getOwnerElement().setIdAttributeNode(attribute, true);
    } else if (SignatureConfirmation.VALUE_ATTRIB_NAME.equals(attribute.getLocalName())) {
        sc.setValue(attribute.getValue());
    } else {
        super.processAttribute(xmlObject, attribute);
    }
}
 
源代码29 项目: openjdk-jdk9   文件: NamedNodeMapTest.java
@Test
public void testSetNamedItemNS() throws Exception {
    final String nsURI = "urn:BooksAreUs.org:BookInfo";
    Document document = createDOMWithNS("NamedNodeMap01.xml");
    NodeList nodeList = document.getElementsByTagName("body");
    nodeList = nodeList.item(0).getChildNodes();
    Node n = nodeList.item(3);

    NamedNodeMap namedNodeMap = n.getAttributes();

    // creating an Attribute using createAttributeNS
    // method having the same namespaceURI
    // and the same qualified name as the existing one in the xml file
    Attr attr = document.createAttributeNS(nsURI, "b:style");
    // setting to a new Value
    attr.setValue("newValue");
    Node replacedAttr = namedNodeMap.setNamedItemNS(attr); // return the replaced attr
    assertEquals(replacedAttr.getNodeValue(), "font-family");
    Node updatedAttr = namedNodeMap.getNamedItemNS(nsURI, "style");
    assertEquals(updatedAttr.getNodeValue(), "newValue");


    // creating a non existing attribute node
    attr = document.createAttributeNS(nsURI, "b:newNode");
    attr.setValue("newValue");

    assertNull(namedNodeMap.setNamedItemNS(attr)); // return null

    // checking if the node could be accessed
    // using the getNamedItemNS method
    Node newAttr = namedNodeMap.getNamedItemNS(nsURI, "newNode");
    assertEquals(newAttr.getNodeValue(), "newValue");
}
 
源代码30 项目: jdk1.8-source-analysis   文件: ElementImpl.java
public Attr getAttributeNodeNS(String namespaceURI, String localName) {
    for (int i=0; i<attrs.length; i++) {
        if (attrs[i].getName().equals(localName) && nsEquals(attrs[i].getNamespaceURI(), namespaceURI)) {
            return attrs[i];
        }
    }
    return null;
}
 
 类所在包
 同包方法