本文整理汇总了Java中org.w3c.dom.Attr类的典型用法代码示例。如果您正苦于以下问题:Java Attr类的具体用法?Java Attr怎么用?Java Attr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Attr类属于org.w3c.dom包,在下文中一共展示了Attr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeIdMap
import org.w3c.dom.Attr; //导入依赖的package包/类
/**
* 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);
}
}
}
示例2: buildDerivationTree
import org.w3c.dom.Attr; //导入依赖的package包/类
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);
}
示例3: getPrefixForAttr
import org.w3c.dom.Attr; //导入依赖的package包/类
/**
* 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;
}
示例4: processAttribute
import org.w3c.dom.Attr; //导入依赖的package包/类
/** {@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());
}
}
示例5: setNodeName
import org.w3c.dom.Attr; //导入依赖的package包/类
/**
* 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;
}
示例6: assignAttributeValue
import org.w3c.dom.Attr; //导入依赖的package包/类
/**
* 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);
}
}
}
示例7: process
import org.w3c.dom.Attr; //导入依赖的package包/类
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;
}
示例8: declareExtensionNamespace
import org.w3c.dom.Attr; //导入依赖的package包/类
/**
* 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);
}
示例9: handleAttributesSubtree
import org.w3c.dom.Attr; //导入依赖的package包/类
/**
* 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();
}
示例10: run
import org.w3c.dom.Attr; //导入依赖的package包/类
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);
}
}
}
}
示例11: assertNotRelativeNS
import org.w3c.dom.Attr; //导入依赖的package包/类
/**
* 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
);
}
}
示例12: evaluate
import org.w3c.dom.Attr; //导入依赖的package包/类
@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;
}
示例13: processAttribute
import org.w3c.dom.Attr; //导入依赖的package包/类
/** {@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);
}
}
示例14: resolveInput
import org.w3c.dom.Attr; //导入依赖的package包/类
/**
* 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;
}
示例15: getAllNamespaces
import org.w3c.dom.Attr; //导入依赖的package包/类
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;
}