/** * Retrieves the name of the given attribute node. * * @param object the context attribute node * @return Returns the name of the attribute node. */ public String getAttributeName(Object object) { return ((OMAttribute) object).getLocalName(); }
/** * Retrieves the QName of the given attribute node. * * @param object the context attribute node * @return Returns the qualified name of the attribute node. */ public String getAttributeQName(Object object) { OMAttribute attr = (OMAttribute) object; String prefix = attr.getNamespace().getPrefix(); if (prefix == null || "".equals(prefix)) { return attr.getLocalName(); } return prefix + ":" + attr.getLocalName(); }
public String getLocalName() { return (isOMAttribute) ? omattr.getLocalName() : getOMNamespaceLocalName(); }
/** * Gets the collection of attributes which are none namespace declarations for an OMElement * * @param element * @return Returns the collection of attributes which are none namespace declarations */ public Collection getAttributesWithoutNS(OMElement element) { SortedMap map = new TreeMap(); Iterator itr = element.getAllAttributes(); while (itr.hasNext()) { OMAttribute attribute = (OMAttribute) itr.next(); if (!(attribute.getLocalName().equals("xmlns") || attribute.getLocalName().startsWith("xmlns:"))) map.put(getExpandedName(attribute), attribute); } return map.values(); }
HashMap<String, String> getErrorDetails(OMElement registryError) { HashMap<String, String> err = new HashMap<String, String>(); for (Iterator<OMAttribute> it=registryError.getAllAttributes(); it.hasNext(); ) { OMAttribute att = it.next(); String name = att.getLocalName(); String value = att.getAttributeValue(); err.put(name, value); } return err; }
public Map<QName, String> getAttributes(OMElement s) { Map<QName, String> mp = new HashMap<QName, String>(); Iterator<?> it = s.getAllAttributes(); while (it.hasNext()) { OMAttribute attr = (OMAttribute)it.next(); if (attr.getNamespace() == null) { mp.put(new QName("", attr.getLocalName()), attr.getAttributeValue()); } else { mp.put(new QName(attr.getNamespace().getNamespaceURI(), attr.getLocalName()), attr.getAttributeValue()); } } return mp; }
/** * Returns the value of an attribute of an element. Returns null * if the attribute is not found * @param omElement Element whose attrib is looked for * @param attrName name of attribute to look for * @return the attribute value */ public static String getAttribute(OMElement omElement, String attrName) { String val = null; Iterator allAttr = omElement.getAllAttributes(); while(allAttr.hasNext()){ OMAttribute attr = (OMAttribute)allAttr.next(); if (attr.getLocalName().equals(attrName)){ val = attr.getAttributeValue(); } } return val; }
private Boolean getBoolean(OMElement items) { for (Iterator<OMAttribute> iAttr = items.getAllAttributes(); iAttr.hasNext();) { OMAttribute test = iAttr.next(); String localName = test.getLocalName(); if (localName.equals("nil")) { if (test.getAttributeValue().equals("true")) { return null; } else if (test.getAttributeValue().equals("false")) { return false; } } else { return Boolean.parseBoolean(items.getText()); } } return false; } }
String getAttributeName(OMAttribute a) { attNamespace = a.getNamespace(); String prefix = ""; if (attNamespace != null) { prefix = attNamespace.getPrefix(); if (prefix != null && !prefix.equals("")) prefix = prefix + ":"; // if (nsPrefix != null && nsPrefix.equals("xml")) { // prefix = "xml:"; // attNamespace = null; // so namespace does not get added to element // } } String attName = a.getLocalName(); return prefix + attName; }
/** * This method is an overloaded method for the digest generation for OMAttribute * * @param attribute * @param digestAlgorithm * @return Returns a byte array representing the calculated digest value */ public byte[] getDigest(OMAttribute attribute, String digestAlgorithm) throws OMException { byte[] digest = new byte[0]; if (!(attribute.getLocalName().equals("xmlns") || attribute.getLocalName().startsWith("xmlns:"))) try { MessageDigest md = MessageDigest.getInstance(digestAlgorithm); md.update((byte) 0); md.update((byte) 0); md.update((byte) 0); md.update((byte) 2); md.update(getExpandedName(attribute).getBytes("UnicodeBigUnmarked")); md.update((byte) 0); md.update((byte) 0); md.update(attribute.getAttributeValue().getBytes("UnicodeBigUnmarked")); digest = md.digest(); } catch (NoSuchAlgorithmException e) { throw new OMException(e); } catch (UnsupportedEncodingException e) { throw new OMException(e); } return digest; }
/** * @param i * @return Returns String. * @see javax.xml.stream.XMLStreamReader#getAttributeLocalName */ public String getAttributeLocalName(int i) { String returnString = null; if (parser != null) { returnString = parser.getAttributeLocalName(i); } else { if (isStartElement()) { loadAttributes(); returnString = attributes[i].getLocalName(); } else { throw new IllegalStateException( "attribute localName accessed in illegal event!"); } } return returnString; }
if (prefix != null) { writer.writeAttribute(prefix, namespaceName, attr.getLocalName(), attr.getAttributeValue()); } else { writer.writeAttribute(namespaceName, attr.getLocalName(), attr.getAttributeValue()); String localName = attr.getLocalName(); String attributeValue = attr.getAttributeValue(); writer.writeAttribute(localName, attributeValue);
void fix_v2_ns_recursive(OMElement ele, OMNamespace ns) { ele.setNamespace(ns); for (@SuppressWarnings("unchecked") Iterator<OMAttribute> it = ele.getAllAttributes(); it.hasNext();) { OMAttribute a = it.next(); if (a.getLocalName().equals("lang")) a.setOMNamespace(MetadataSupport.xml_namespace); } for (@SuppressWarnings("unchecked") Iterator<OMElement> it = ele.getChildElements(); it.hasNext();) { OMElement child = (OMElement) it.next(); fix_v2_ns_recursive(child, MetadataSupport.ebRIMns2); } }
@SuppressWarnings("unchecked") private List<Validator> getValidators(Iterator<OMElement> valItr) { List<Validator> vals = new ArrayList<Validator>(); OMElement valEl; String valElementName; Iterator<OMAttribute> attrItr; Map<String, String> propMap; OMAttribute attr; while (valItr.hasNext()) { valEl = valItr.next(); valElementName = valEl.getLocalName(); attrItr = valEl.getAllAttributes(); propMap = new HashMap<String, String>(); while (attrItr.hasNext()) { attr = attrItr.next(); propMap.put(attr.getLocalName(), attr.getAttributeValue()); } Map<String, String> customPropMap = extractAdvancedProps(valEl); vals.add(new Validator(valElementName, propMap, customPropMap)); } return vals; }
@SuppressWarnings("unchecked") private List<Validator> getValidators(Iterator<OMElement> valItr) { List<Validator> vals = new ArrayList<Validator>(); OMElement valEl; String valElementName; Iterator<OMAttribute> attrItr; Map<String, String> propMap; OMAttribute attr; while (valItr.hasNext()) { valEl = valItr.next(); valElementName = valEl.getLocalName(); attrItr = valEl.getAllAttributes(); propMap = new HashMap<String, String>(); while (attrItr.hasNext()) { attr = attrItr.next(); propMap.put(attr.getLocalName(), attr.getAttributeValue()); } Map<String, String> customPropMap = extractAdvancedProps(valEl); vals.add(new Validator(valElementName, propMap, customPropMap)); } return vals; }
/** * Visit all attributes of an xml element. * * @param ele * the element * @param visitor * the visitor */ public static void traverseAttributes(OMElement ele, IAttributeVisitor visitor) { for (OMAttribute attr : new Attributes(ele)) { visitor.visit(ele, attr.getLocalName(), attr.getAttributeValue()); } }
/** * Visit all attributes of an xml element. * * @param ele * the element * @param visitor * the visitor */ public static void traverseAttributes(OMElement ele, IAttributeVisitor visitor) { for (OMAttribute attr : new Attributes(ele)) { visitor.visit(ele, attr.getLocalName(), attr.getAttributeValue()); } }
/** * @param i * @return Returns String. * @see javax.xml.stream.XMLStreamReader#getAttributeLocalName */ public String getAttributeLocalName(int i) { String returnString = null; if (parser != null) { returnString = parser.getAttributeLocalName(i); } else { if (isStartElement() || (currentEvent == ATTRIBUTE)) { OMAttribute attrib = getAttribute((OMElement) lastNode, i); if (attrib != null) { if (attrib.getNamespace() != null) { returnString = attrib.getLocalName(); } else { returnString = ((Attr) attrib).getNodeName(); } } } else { throw new IllegalStateException( "attribute localName accessed in illegal event!"); } } return returnString; }
OMElement dup_wrapper1(OMElement e) { OMElement e_dup = om_factory().createOMElement(e.getLocalName(), e.getNamespace()); for (@SuppressWarnings("unchecked") Iterator<OMAttribute> it = e.getAllAttributes(); it.hasNext();) { OMAttribute a = it.next(); String name = a.getLocalName(); String value = a.getAttributeValue(); e_dup.addAttribute(name, value, null); } if (e.getLocalName().equals(wrapper.getLocalName())) { wrapperDup = e_dup; return e_dup; } for (@SuppressWarnings("unchecked") Iterator<OMElement> it = e.getChildElements(); it.hasNext();) { OMElement ele = it.next(); OMElement ele_dup = dup_wrapper1(ele); e_dup.addChild(ele_dup); } return e_dup; }
/** * In Axiom, a single tree should always contain objects created from the same type of factory * (eg: LinkedListImplFactory, DOMFactory, etc.,). This method will convert omAttribute to the * given omFactory. * * @see ElementHelper#importOMElement(OMElement, OMFactory) to convert instances of OMElement */ public static void importOMAttribute(OMAttribute omAttribute, OMElement omElement) { // first check whether the given OMAttribute has the same OMFactory if (omAttribute.getOMFactory().getMetaFactory() == omElement.getOMFactory().getMetaFactory()) { omElement.addAttribute(omAttribute); } else { OMNamespace ns = omAttribute.getNamespace(); omElement.addAttribute(omAttribute.getLocalName(), omAttribute.getAttributeValue(), omElement.getOMFactory().createOMNamespace(ns.getNamespaceURI(), ns.getPrefix())); } } }