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

项目:TuLiPA-frames    文件:DOMderivationBuilder.java   
public static void buildDerivationTree(Element mother, Node derivation){
    Element t = derivDoc.createElement("tree");
    NamedNodeMap atts = derivation.getAttributes();     
    for (int i = 0 ; i < atts.getLength() ; i++){
        Attr a = (Attr) atts.item(i);
        String name = a.getNodeName();
        String val  = a.getNodeValue();
        if (name.equals("id")) {
            t.setAttribute("id", val);
        } else if (name.equals("op")) {
            t.setAttribute("op", val);
        } else if (name.equals("op-node")) {
            t.setAttribute("node", val);
        } // skip the other attributes
    }
    NodeList childList = derivation.getChildNodes();
       for (int i = 0; i < childList.getLength(); i++)
       {
           Node child = childList.item(i);
           if (child instanceof Element)
           {
               buildDerivationTree(t, child);
           }
       }
       mother.appendChild(t);
}
项目:openjdk-jdk10    文件:DOMStreamReader.java   
/**
 * If the given attribute is a namespace declaration for the given namespace URI,
 * return its prefix. Otherwise null.
 */
private static String getPrefixForAttr(Attr attr, String nsUri) {
    String attrName = attr.getNodeName();
    if (!attrName.startsWith("xmlns:") && !attrName.equals("xmlns"))
        return null;    // not nsdecl

    if(attr.getValue().equals(nsUri)) {
        if(attrName.equals("xmlns"))
            return "";
        String localName = attr.getLocalName();
        return (localName != null) ? localName :
            QName.valueOf(attrName).getLocalPart();
    }

    return null;
}
项目:lams    文件:EncryptionPropertyUnmarshaller.java   
/** {@inheritDoc} */
protected void processAttribute(XMLObject xmlObject, Attr attribute) throws UnmarshallingException {
    EncryptionProperty ep = (EncryptionProperty) xmlObject;

    if (attribute.getLocalName().equals(EncryptionProperty.ID_ATTRIB_NAME)) {
        ep.setID(attribute.getValue());
        attribute.getOwnerElement().setIdAttributeNode(attribute, true);
    } else if (attribute.getLocalName().equals(EncryptionProperty.TARGET_ATTRIB_NAME)) {
        ep.setTarget(attribute.getValue());
    } else {
        QName attributeName = XMLHelper.getNodeQName(attribute);
        if (attribute.isId()) {
            ep.getUnknownAttributes().registerID(attributeName);
        }
        ep.getUnknownAttributes().put(attributeName, attribute.getValue());
    }
}
项目:Equella    文件:PropBagEx.java   
/**
 * Sets the name of the root element. Warning this can be expensive
 * operation until we use DOM Level 3
 * 
 * @param newname
 * @return
 */
public void setNodeName(final String newname)
{
    ensureRoot();
    checkNotAttribute(newname);

    final NamedNodeMap attributes = m_elRoot.getAttributes();
    final Document doc = m_elRoot.getOwnerDocument();
    final Element newelem = doc.createElement(newname);

    Node child;
    while( (child = m_elRoot.getFirstChild()) != null )
    {
        m_elRoot.removeChild(child);
        newelem.appendChild(child);
    }

    for( int i = 0; i < attributes.getLength(); i++ )
    {
        final Attr attr = (Attr) attributes.item(i);
        newelem.setAttribute(attr.getName(), attr.getValue());
    }

    m_elRoot.getParentNode().replaceChild(newelem, m_elRoot);
    m_elRoot = newelem;
}
项目:dpdirect    文件:SchemaLoader.java   
/**
 * Sets the text value of an attribute on a provided element if set in the attributeValueMap table.
 * 
 * @param attName the attribute local name.
 * @param contentElem the element to set the attribute on.
 */
public void assignAttributeValue(String attName,
                                 Element contentElem) {
   if (null != attName && null != contentElem) {
      String attValue = null;
      if (sampleXML) {
         attValue = "?";
      }
      else {
         attValue = getAttributeValue(attName, contentElem);
      }
      if (null != attValue) {
         Attr att = DocumentHelper.createAttribute(generatedDoc, "", attName);
         att.setValue(attValue);
         contentElem.setAttributeNode(att);
      }
   }
}
项目:gemini.blueprint    文件:StandardAttributeCallback.java   
public boolean process(Element parent, Attr attribute, BeanDefinitionBuilder builder) {
    String name = attribute.getLocalName();

    if (BeanDefinitionParserDelegate.ID_ATTRIBUTE.equals(name)) {
        return false;
    }

    if (BeanDefinitionParserDelegate.DEPENDS_ON_ATTRIBUTE.equals(name)) {
        builder.getBeanDefinition().setDependsOn(
            (StringUtils.tokenizeToStringArray(attribute.getValue(),
                BeanDefinitionParserDelegate.MULTI_VALUE_ATTRIBUTE_DELIMITERS)));
        return false;
    }
    if (BeanDefinitionParserDelegate.LAZY_INIT_ATTRIBUTE.equals(name)) {
        builder.setLazyInit(Boolean.valueOf(attribute.getValue()));
        return false;
    }
    return true;
}
项目:OpenJSharp    文件:Internalizer.java   
/**
 * Adds the specified namespace URI to the jaxb:extensionBindingPrefixes
 * attribute of the target document.
 */
private void declareExtensionNamespace( Element target, String nsUri ) {
    // look for the attribute
    Element root = target.getOwnerDocument().getDocumentElement();
    Attr att = root.getAttributeNodeNS(Const.JAXB_NSURI,EXTENSION_PREFIXES);
    if( att==null ) {
        String jaxbPrefix = allocatePrefix(root,Const.JAXB_NSURI);
        // no such attribute. Create one.
        att = target.getOwnerDocument().createAttributeNS(
            Const.JAXB_NSURI,jaxbPrefix+':'+EXTENSION_PREFIXES);
        root.setAttributeNodeNS(att);
    }

    String prefix = allocatePrefix(root,nsUri);
    if( att.getValue().indexOf(prefix)==-1 )
        // avoid redeclaring the same namespace twice.
        att.setValue( att.getValue()+' '+prefix);
}
项目:OpenJSharp    文件:CanonicalizerPhysical.java   
/**
 * Returns the Attr[]s to be output for the given element.
 * <br>
 * The code of this method is a copy of {@link #handleAttributes(Element,
 * NameSpaceSymbTable)},
 * whereas it takes into account that subtree-c14n is -- well -- subtree-based.
 * So if the element in question isRoot of c14n, it's parent is not in the
 * node set, as well as all other ancestors.
 *
 * @param element
 * @param ns
 * @return the Attr[]s to be output
 * @throws CanonicalizationException
 */
@Override
protected Iterator<Attr> handleAttributesSubtree(Element element, NameSpaceSymbTable ns)
    throws CanonicalizationException {
    if (!element.hasAttributes()) {
        return null;
    }

    // result will contain all the attrs declared directly on that element
    final SortedSet<Attr> result = this.result;
    result.clear();

    if (element.hasAttributes()) {
        NamedNodeMap attrs = element.getAttributes();
        int attrsLength = attrs.getLength();

        for (int i = 0; i < attrsLength; i++) {
            Attr attribute = (Attr) attrs.item(i);
            result.add(attribute);
        }
    }

    return result.iterator();
}
项目:openjdk-jdk10    文件:DomPostInitAction.java   
public void run() {
    Set<String> declaredPrefixes = new HashSet<String>();
    for( Node n=node; n!=null && n.getNodeType()==Node.ELEMENT_NODE; n=n.getParentNode() ) {
        NamedNodeMap atts = n.getAttributes();
        if(atts==null)      continue; // broken DOM. but be graceful.
        for( int i=0; i<atts.getLength(); i++ ) {
            Attr a = (Attr)atts.item(i);
            String nsUri = a.getNamespaceURI();
            if(nsUri==null || !nsUri.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI))
                continue;   // not a namespace declaration
            String prefix = a.getLocalName();
            if(prefix==null)
                continue;   // broken DOM. skip to be safe
            if(prefix.equals("xmlns")) {
                prefix = "";
            }
            String value = a.getValue();
            if(value==null)
                continue;   // broken DOM. skip to be safe
            if(declaredPrefixes.add(prefix)) {
                serializer.addInscopeBinding(value,prefix);
            }
        }
    }
}
项目:openjdk-jdk10    文件: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
        );
    }
}
项目:mpd-tools    文件:MyDifferenceEvaluator.java   
@Override
public ComparisonResult evaluate(Comparison comparison, ComparisonResult outcome) {
    if (outcome == ComparisonResult.EQUAL) {
        return outcome; // only evaluate differences.
    }

    Node controlNode = comparison.getControlDetails().getTarget();
    Node testNode = comparison.getTestDetails().getTarget();

    if ((controlNode instanceof Attr && testNode instanceof Attr)) {
        if (similarAttributes((Attr) controlNode, (Attr) testNode)) {
            return ComparisonResult.SIMILAR;
        } else {
            return outcome;
        }
    }

    return outcome;
}
项目:openjdk-jdk10    文件:CanonicalizerPhysical.java   
/**
 * Returns the Attr[]s to be output for the given element.
 * <br>
 * The code of this method is a copy of {@link #handleAttributes(Element,
 * NameSpaceSymbTable)},
 * whereas it takes into account that subtree-c14n is -- well -- subtree-based.
 * So if the element in question isRoot of c14n, it's parent is not in the
 * node set, as well as all other ancestors.
 *
 * @param element
 * @param ns
 * @return the Attr[]s to be output
 * @throws CanonicalizationException
 */
@Override
protected Iterator<Attr> handleAttributesSubtree(Element element, NameSpaceSymbTable ns)
    throws CanonicalizationException {
    if (!element.hasAttributes()) {
        return null;
    }

    // result will contain all the attrs declared directly on that element
    final SortedSet<Attr> result = this.result;
    result.clear();

    if (element.hasAttributes()) {
        NamedNodeMap attrs = element.getAttributes();
        int attrsLength = attrs.getLength();

        for (int i = 0; i < attrsLength; i++) {
            Attr attribute = (Attr) attrs.item(i);
            result.add(attribute);
        }
    }

    return result.iterator();
}
项目:lams    文件:StatusResponseTypeUnmarshaller.java   
/** {@inheritDoc} */
protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {
    StatusResponseType sr = (StatusResponseType) samlObject;

    if (attribute.getLocalName().equals(StatusResponseType.VERSION_ATTRIB_NAME)) {
        sr.setVersion(SAMLVersion.valueOf(attribute.getValue()));
    } else if (attribute.getLocalName().equals(StatusResponseType.ID_ATTRIB_NAME)) {
        sr.setID(attribute.getValue());
        attribute.getOwnerElement().setIdAttributeNode(attribute, true);
    } else if (attribute.getLocalName().equals(StatusResponseType.IN_RESPONSE_TO_ATTRIB_NAME)) {
        sr.setInResponseTo(attribute.getValue());
    } else if (attribute.getLocalName().equals(StatusResponseType.ISSUE_INSTANT_ATTRIB_NAME)
            && !DatatypeHelper.isEmpty(attribute.getValue())) {
        sr.setIssueInstant(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC()));
    } else if (attribute.getLocalName().equals(StatusResponseType.DESTINATION_ATTRIB_NAME)) {
        sr.setDestination(attribute.getValue());
    } else if (attribute.getLocalName().equals(StatusResponseType.CONSENT_ATTRIB_NAME)) {
        sr.setConsent(attribute.getValue());
    } else {
        super.processAttribute(samlObject, attribute);
    }
}
项目:jdk8u-jdk    文件:RetrievalMethodResolver.java   
/**
 * Resolves the input from the given retrieval method
 * @return
 * @throws XMLSecurityException
 */
private static XMLSignatureInput resolveInput(
    RetrievalMethod rm, String baseURI, boolean secureValidation
) throws XMLSecurityException {
    Attr uri = rm.getURIAttr();
    // Apply the transforms
    Transforms transforms = rm.getTransforms();
    ResourceResolver resRes = ResourceResolver.getInstance(uri, baseURI, secureValidation);
    XMLSignatureInput resource = resRes.resolve(uri, baseURI, secureValidation);
    if (transforms != null) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "We have Transforms");
        }
        resource = transforms.performTransforms(resource);
    }
    return resource;
}
项目:openjdk-jdk10    文件:Internalizer.java   
/**
 * Adds the specified namespace URI to the jaxb:extensionBindingPrefixes
 * attribute of the target document.
 */
private void declareExtensionNamespace( Element target, String nsUri ) {
    // look for the attribute
    Element root = target.getOwnerDocument().getDocumentElement();
    Attr att = root.getAttributeNodeNS(Const.JAXB_NSURI,EXTENSION_PREFIXES);
    if( att==null ) {
        String jaxbPrefix = allocatePrefix(root,Const.JAXB_NSURI);
        // no such attribute. Create one.
        att = target.getOwnerDocument().createAttributeNS(
            Const.JAXB_NSURI,jaxbPrefix+':'+EXTENSION_PREFIXES);
        root.setAttributeNodeNS(att);
    }

    String prefix = allocatePrefix(root,nsUri);
    if( att.getValue().indexOf(prefix)==-1 )
        // avoid redeclaring the same namespace twice.
        att.setValue( att.getValue()+' '+prefix);
}
项目:HL4A    文件:XmlNode.java   
private Namespaces getAllNamespaces() {
    Namespaces rv = new Namespaces();

    Node target = this.dom;
    if (target instanceof Attr) {
        target = ((Attr)target).getOwnerElement();
    }
    while(target != null) {
        if (target instanceof Element) {
            addNamespaces(rv, (Element)target);
        }
        target = target.getParentNode();
    }
    //    Fallback in case no namespace was declared
    rv.declare(Namespace.create("", ""));
    return rv;
}
项目:ciguan    文件:AsUtil.java   
/**
 * Method removed when ref removed from configuration, only used for menu... separator, languages
 */
@Deprecated
public static void makeIdMap(Node pElement, Map<String, CwfDataIf> pIdMap) {
    if (pElement.getNodeType() == Node.ELEMENT_NODE) {
        String tTagName = ((Element) pElement).getTagName();
        String tId = ((Element) pElement).getAttribute("id");
        if (!tId.isEmpty() && tTagName.equals(TAG_MENUITEM)) {
            CwfDataIf tData = CwfDataFactory.create();
            tData.setProperty(ATTR_TAG_NAME, TAG_MENUITEM);
            for (int i = 0; i < pElement.getAttributes().getLength(); i++) {
                Attr tAttr = (Attr) pElement.getAttributes().item(i);
                tData.setProperty(tAttr.getName(), tAttr.getValue());
            }
            pIdMap.put(tId, tData);

        }
        NodeList tNodes = pElement.getChildNodes();
        for (int i = 0; i < tNodes.getLength(); i++) {
            makeIdMap(tNodes.item(i), pIdMap);
        }
    }
}
项目:ciguan    文件:ConfigurationTest.java   
@SuppressWarnings("unused")
private static void ensureMetaData(String pXpath) {
    List<Attr> tList = createAttrList(pXpath);
    int tCount = cErrors.size();
    System.out.print("Model: " + pXpath + " (" + tList.size() + ")");
    for (Attr tAttr : tList) {
        Class<?> tClass = ensureType(tAttr.getNodeValue(), tAttr.getOwnerElement());
        if (tClass == null || !cMetaDatas.contains(tClass.getName())) {
            error("Metadata not found: " + tClass, tAttr.getOwnerElement());
        }
    }
    if (tCount != cErrors.size()) {
        System.out.print(" - " + (cErrors.size() - tCount) + " problems");
    }
    System.out.println();
}
项目:Java-APIs    文件:AbstractSimpleNode.java   
public AbstractSimpleNode(Element element) {
    logger.debug("Constructor - entry");

    NodeList nodeList = element.getChildNodes();
    for (int n = 0; n < nodeList.getLength(); n++) {
        Node node = nodeList.item(n);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            Element childElement = (Element) node;
            logger.trace("Unrecognized child node: '" + childElement.getNodeName() + "' (" + this.getClass().getName() + ")");
        } else if (node.getNodeType() == Node.TEXT_NODE) {
            this.setValue(node.getNodeValue());
        }
    }

    NamedNodeMap namedNodeMap = element.getAttributes();
    if (namedNodeMap != null) {
        for (int a = 0; a < namedNodeMap.getLength(); a++) {
            Attr attributeNode = (Attr) namedNodeMap.item(a);
            logger.trace("Unrecognized attribute: '" + attributeNode.getName() + "' (" + this.getClass().getName() + ")");
        }
    }


    logger.debug("Constructor - exit");
}
项目:TuLiPA-frames    文件:DOMderivationBuilder.java   
public static void buildDerivedTree(Element mother, Node derived){
    Element t = derivDoc.createElement("node");

    Element narg = derivDoc.createElement("narg");
    t.appendChild(narg);

    Element fs= derivDoc.createElement("fs");
    narg.appendChild(fs);

    NamedNodeMap atts = derived.getAttributes();
    for (int i = 0 ; i < atts.getLength() ; i++){
        Attr a = (Attr) atts.item(i);
        Element f = derivDoc.createElement("f");
        String name = a.getNodeName();
        f.setAttribute("name", name);
        String val  = a.getNodeValue();
        buildVal(f, val);
        fs.appendChild(f);
    }
    NodeList childList = derived.getChildNodes();
       for (int i = 0; i < childList.getLength(); i++)
       {
           Node child = childList.item(i);
           if (child instanceof Element)
           {
               buildDerivedTree(t, child);
           }
       }
       if (childList.getLength() == 0) {
        //lex node
        t.setAttribute("type", "lex");
        t.setAttribute("value", derived.getNodeName());
       } else {
        t.setAttribute("type", "std");
       }
    mother.appendChild(t);
}
项目:OpenJSharp    文件:IIOMetadataNode.java   
/**
 * This DOM Level 3 method is not supported for {@code IIOMetadataNode}
 * and will throw a {@code DOMException}.
 * @throws DOMException - always.
 */
public void setIdAttributeNode(Attr idAttr,
                               boolean isId)
                               throws DOMException {
    throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
                           "Method not supported");
}
项目:lams    文件:DelegateUnmarshaller.java   
/** {@inheritDoc} */
protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {
    Delegate delegate = (Delegate) samlObject;

    String attrName = attribute.getLocalName();
    if (Delegate.CONFIRMATION_METHOD_ATTRIB_NAME.equals(attrName)) {
        delegate.setConfirmationMethod(attribute.getValue());
    } else if (Delegate.DELEGATION_INSTANT_ATTRIB_NAME.equals(attrName)) {
        delegate.setDelegationInstant(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC()));
    } else {
        super.processAttribute(samlObject, attribute);
    }
}
项目:openjdk-jdk10    文件: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);
    }

}
项目:lams    文件:ReferenceTypeUnmarshaller.java   
/** {@inheritDoc} */
protected void processAttribute(XMLObject xmlObject, Attr attribute) throws UnmarshallingException {
    ReferenceType rt = (ReferenceType) xmlObject;

    if (attribute.getLocalName().equals(ReferenceType.URI_ATTRIB_NAME)) {
        rt.setURI(attribute.getValue());
    } else {
        super.processAttribute(xmlObject, attribute);
    }
}
项目:lams    文件:EntityDescriptorMarshaller.java   
/** {@inheritDoc} */
protected void marshallAttributes(XMLObject samlElement, Element domElement) {
    EntityDescriptor entityDescriptor = (EntityDescriptor) samlElement;

    // Set the entityID attribute
    if (entityDescriptor.getEntityID() != null) {
        domElement.setAttributeNS(null, EntityDescriptor.ENTITY_ID_ATTRIB_NAME, entityDescriptor.getEntityID());
    }

    // Set the ID attribute
    if (entityDescriptor.getID() != null) {
        domElement.setAttributeNS(null, EntityDescriptor.ID_ATTRIB_NAME, entityDescriptor.getID());
        domElement.setIdAttributeNS(null, EntityDescriptor.ID_ATTRIB_NAME, true);
    }

    // Set the validUntil attribute
    if (entityDescriptor.getValidUntil() != null) {
        log.debug("Writting validUntil attribute to EntityDescriptor DOM element");
        String validUntilStr = Configuration.getSAMLDateFormatter().print(entityDescriptor.getValidUntil());
        domElement.setAttributeNS(null, TimeBoundSAMLObject.VALID_UNTIL_ATTRIB_NAME, validUntilStr);
    }

    // Set the cacheDuration attribute
    if (entityDescriptor.getCacheDuration() != null) {
        log.debug("Writting cacheDuration attribute to EntityDescriptor DOM element");
        String cacheDuration = XMLHelper.longToDuration(entityDescriptor.getCacheDuration());
        domElement.setAttributeNS(null, CacheableSAMLObject.CACHE_DURATION_ATTRIB_NAME, cacheDuration);
    }

    Attr attribute;
    for (Entry<QName, String> entry : entityDescriptor.getUnknownAttributes().entrySet()) {
        attribute = XMLHelper.constructAttribute(domElement.getOwnerDocument(), entry.getKey());
        attribute.setValue(entry.getValue());
        domElement.setAttributeNodeNS(attribute);
        if (Configuration.isIDAttribute(entry.getKey())
                || entityDescriptor.getUnknownAttributes().isIDAttribute(entry.getKey())) {
            attribute.getOwnerElement().setIdAttributeNode(attribute, true);
        }
    }
}
项目:lams    文件:SubjectTypeUnmarshaller.java   
/** {@inheritDoc} */
protected void processAttribute(XMLObject xmlObject, Attr attribute) throws UnmarshallingException {
    SubjectType attrib = (SubjectType) xmlObject;
    if (attribute.getLocalName().equals(SubjectType.SUBJECT_CATEGORY_ATTTRIB_NAME)) {
        attrib.setSubjectCategory(attribute.getValue());
    } else {
        super.processAttribute(xmlObject, attribute);
    }
}
项目:lams    文件:XMLHelper.java   
/**
 * Constructs a QName from an attributes value.
 * 
 * @param attribute the attribute with a QName value
 * 
 * @return a QName from an attributes value, or null if the given attribute is null
 */
public static QName getAttributeValueAsQName(Attr attribute) {
    if (attribute == null || DatatypeHelper.isEmpty(attribute.getValue())) {
        return null;
    }

    String attributeValue = attribute.getTextContent();
    String[] valueComponents = attributeValue.split(":");
    if (valueComponents.length == 1) {
        return constructQName(attribute.lookupNamespaceURI(null), valueComponents[0], null);
    } else {
        return constructQName(attribute.lookupNamespaceURI(valueComponents[0]), valueComponents[1],
                valueComponents[0]);
    }
}
项目:lams    文件:LocalizedURIMarshaller.java   
/**
 * {@inheritDoc}
 */
protected void marshallAttributes(XMLObject samlObject, Element domElement) throws MarshallingException {
    LocalizedURI name = (LocalizedURI) samlObject;

    if (name.getURI() != null) {
        Attr attribute = XMLHelper.constructAttribute(domElement.getOwnerDocument(), SAMLConstants.XML_NS,
                LangBearing.XML_LANG_ATTR_LOCAL_NAME, SAMLConstants.XML_PREFIX);
        attribute.setValue(name.getURI().getLanguage());
        domElement.setAttributeNodeNS(attribute);
    }
}
项目:lams    文件:RuleTypeUnmarshaller.java   
/** {@inheritDoc} */
protected void processAttribute(XMLObject xmlObject, Attr attribute) throws UnmarshallingException {
    RuleType ruleType = (RuleType) xmlObject;

    if(attribute.getLocalName().equals(RuleType.EFFECT_ATTRIB_NAME)){
        ruleType.setEffect(EffectType.valueOf(
                DatatypeHelper.safeTrimOrNullString(attribute.getValue())));                       
    } else if(attribute.getLocalName().equals(RuleType.RULE_ID_ATTRIB_NAME)){
        ruleType.setRuleId(DatatypeHelper.safeTrimOrNullString(attribute.getValue()));
    } else {
        super.processAttribute(xmlObject, attribute);
    }

}
项目:lams    文件:AbstractExtensibleXMLObjectUnmarshaller.java   
/**
 * Unmarshalls the <code>xs:anyAttribute</code> attributes.
 * 
 * {@inheritDoc}
 */
protected void processAttribute(XMLObject xmlObject, Attr attribute) throws UnmarshallingException {
    AttributeExtensibleXMLObject anyAttribute = (AttributeExtensibleXMLObject) xmlObject;
    QName attribQName = XMLHelper.constructQName(attribute.getNamespaceURI(), attribute.getLocalName(), attribute
            .getPrefix());
    if (attribute.isId()) {
        anyAttribute.getUnknownAttributes().registerID(attribQName);
    }
    anyAttribute.getUnknownAttributes().put(attribQName, attribute.getValue());
}
项目:openjdk-jdk10    文件:ResourceResolver.java   
/**
 * Method getInstance
 *
 * @param uri
 * @param baseURI
 * @param individualResolvers
 * @param secureValidation
 * @return the instance
 *
 * @throws ResourceResolverException
 */
public static ResourceResolver getInstance(
    Attr uri, String baseURI, List<ResourceResolver> individualResolvers, boolean secureValidation
) throws ResourceResolverException {
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE,
            "I was asked to create a ResourceResolver and got "
            + (individualResolvers == null ? 0 : individualResolvers.size())
        );
    }

    ResourceResolverContext context = new ResourceResolverContext(uri, baseURI, secureValidation);

    // first check the individual Resolvers
    if (individualResolvers != null) {
        for (int i = 0; i < individualResolvers.size(); i++) {
            ResourceResolver resolver = individualResolvers.get(i);

            if (resolver != null) {
                if (log.isLoggable(java.util.logging.Level.FINE)) {
                    String currentClass = resolver.resolverSpi.getClass().getName();
                    log.log(java.util.logging.Level.FINE, "check resolvability by class " + currentClass);
                }

                if (resolver.canResolve(context)) {
                    return resolver;
                }
            }
        }
    }

    return internalGetInstance(context);
}
项目:lams    文件:AbstractXMLObjectUnmarshaller.java   
/**
 * Unmarshalls the attributes from the given DOM Attr into the given XMLObject. If the attribute is an XML namespace
 * declaration the attribute is passed to
 * {@link AbstractXMLObjectUnmarshaller#unmarshallNamespaceAttribute(XMLObject, Attr)}. If it is an schema type
 * decleration (xsi:type) it is ignored because this attribute is handled by {@link #buildXMLObject(Element)}. All
 * other attributes are passed to the {@link #processAttribute(XMLObject, Attr)}
 * 
 * @param attribute the attribute to be unmarshalled
 * @param xmlObject the XMLObject that will recieve information from the DOM attribute
 * 
 * @throws UnmarshallingException thrown if there is a problem unmarshalling an attribute
 */
protected void unmarshallAttribute(XMLObject xmlObject, Attr attribute) throws UnmarshallingException {
    QName attribName = XMLHelper.getNodeQName(attribute);
    log.trace("Pre-processing attribute {}", attribName);
    String attributeNamespace = DatatypeHelper.safeTrimOrNullString(attribute.getNamespaceURI());

    if (DatatypeHelper.safeEquals(attributeNamespace, XMLConstants.XMLNS_NS)) {
        unmarshallNamespaceAttribute(xmlObject, attribute);
    } else if (DatatypeHelper.safeEquals(attributeNamespace, XMLConstants.XSI_NS)) {
        unmarshallSchemaInstanceAttributes(xmlObject, attribute);
    } else {
        if (log.isTraceEnabled()) {
            log.trace("Attribute {} is neither a schema type nor namespace, calling processAttribute()",
                    XMLHelper.getNodeQName(attribute));
        }
        String attributeNSURI = attribute.getNamespaceURI();
        String attributeNSPrefix;
        if (attributeNSURI != null) {
            attributeNSPrefix = attribute.lookupPrefix(attributeNSURI);
            if (attributeNSPrefix == null && XMLConstants.XML_NS.equals(attributeNSURI)) {
                attributeNSPrefix = XMLConstants.XML_PREFIX;
            }
            xmlObject.getNamespaceManager().registerAttributeName(attribName);
        }

        checkIDAttribute(attribute);

        processAttribute(xmlObject, attribute);
    }
}
项目:lams    文件:IDPEntryUnmarshaller.java   
/** {@inheritDoc} */
protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {
    IDPEntry entry = (IDPEntry) samlObject;

    if (attribute.getLocalName().equals(IDPEntry.PROVIDER_ID_ATTRIB_NAME)) {
        entry.setProviderID(attribute.getValue());
    } else if (attribute.getLocalName().equals(IDPEntry.NAME_ATTRIB_NAME)) {
        entry.setName(attribute.getValue());
    } else if (attribute.getLocalName().equals(IDPEntry.LOC_ATTRIB_NAME)) {
        entry.setLoc(attribute.getValue());
    } else {
        super.processAttribute(samlObject, attribute);
    }
}
项目:lams    文件:XMLHelper.java   
/**
 * Marshall an attribute name and value to a DOM Element. This is particularly useful for attributes whose names
 * appear in namespace-qualified form.
 * 
 * @param attributeName the attribute name in QName form
 * @param attributeValue the attribute value
 * @param domElement the target element to which to marshall
 * @param isIDAttribute flag indicating whether the attribute being marshalled should be handled as an ID-typed
 *            attribute
 */
public static void marshallAttribute(QName attributeName, String attributeValue, Element domElement,
        boolean isIDAttribute) {
    Document document = domElement.getOwnerDocument();
    Attr attribute = XMLHelper.constructAttribute(document, attributeName);
    attribute.setValue(attributeValue);
    domElement.setAttributeNodeNS(attribute);
    if (isIDAttribute) {
        domElement.setIdAttributeNode(attribute, true);
    }
}
项目:hashsdn-controller    文件:OpendaylightNamespaceHandler.java   
private static ComponentMetadata decorateServiceType(final Attr attr, final ComponentMetadata component,
        final ParserContext context) {
    if (!(component instanceof MutableServiceMetadata)) {
        throw new ComponentDefinitionException("Expected an instanceof MutableServiceMetadata");
    }

    MutableServiceMetadata service = (MutableServiceMetadata)component;

    LOG.debug("decorateServiceType for {} - adding type property {}", service.getId(), attr.getValue());

    service.addServiceProperty(createValue(context, TYPE_ATTR), createValue(context, attr.getValue()));
    return component;
}
项目:lams    文件:EnvironmentMatchTypeUnmarshaller.java   
/** {@inheritDoc} */
protected void processAttribute(XMLObject xmlObject, Attr attribute) throws UnmarshallingException {
    if (attribute.getLocalName().equals(EnvironmentMatchType.MATCH_ID_ATTRIB_NAME)) {
        EnvironmentMatchType matchType = (EnvironmentMatchType) xmlObject;
        matchType.setMatchId(DatatypeHelper.safeTrimOrNullString(attribute.getValue()));
    } else {
        super.processAttribute(xmlObject, attribute);
    }
}
项目:Java-APIs    文件:AttributeType.java   
protected AttributeType(Element element) {
    logger.debug("Constructor - entry");

    NodeList nodeList = element.getChildNodes();
    for (int n = 0; n < nodeList.getLength(); n++) {
        Node node = nodeList.item(n);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            logger.trace("Unrecognized child node: '" + element.getNodeName() + "'");
        } else if (node.getNodeType() == Node.TEXT_NODE) {
            logger.trace("Unexpected text node: '" + element.getNodeName() + "'");
        }
    }

    NamedNodeMap namedNodeMap = element.getAttributes();
    if (namedNodeMap != null) {
        for (int a = 0; a < namedNodeMap.getLength(); a++) {
            Attr attributeNode = (Attr) namedNodeMap.item(a);
            if ("ID".equals(attributeNode.getName())) {
                setId(attributeNode.getValue());
            } else if ("NAME".equals(attributeNode.getName())) {
                setName(attributeNode.getValue());
            } else {
                logger.trace("Unrecognized attribute: '" + attributeNode.getName() + "'");
            }
        }

    }
    logger.debug("Constructor - exit");
}
项目:convertigo-engine    文件:URLrewriter.java   
public void rewriteURL(Element elt){
    if(attributesXpath.length()==0) return;
    try {
        NodeList list = xpathApi.selectNodeList(elt, attributesXpath);
        for(int i = 0 ; i < list.getLength() ; i++) {
            Attr attr_n = (Attr)list.item(i);
            attr_n.setValue(rewriteURL(attr_n.getValue()));
        }
    } catch (TransformerException e) {
        Engine.logEngine.trace("WebClipper cannot evaluate this xpath : "+attributesXpath);
    }
}
项目:openjdk-jdk10    文件:ElementImpl.java   
private boolean removeAttribute(String uri, String localName) {
    String nonzeroLengthUri =
        (uri == null || uri.length() == 0) ? null : uri;
    org.w3c.dom.Attr attribute =
        getAttributeNodeNS(nonzeroLengthUri, localName);
    if (attribute == null) {
        return false;
    }
    removeAttributeNode(attribute);
    return true;
}
项目:OpenJSharp    文件:ElementImpl.java   
/**
 * Look up a single Attribute by name. Returns the Attribute Node,
 * so its complete child tree is available. This could be important in
 * XML, where the string rendering may not be sufficient information.
 * <p>
 * If no matching attribute is available, returns null.
 */
public Attr getAttributeNode(String name) {

    if (needsSyncData()) {
        synchronizeData();
    }
    if (attributes == null) {
        return null;
    }
    return (Attr)attributes.getNamedItem(name);

}