You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@xml.apache.org by du...@apache.org on 2001/11/13 19:25:09 UTC

cvs commit: xml-soap/java/src/org/apache/soap/util/xml DOMUtils.java

duftler     01/11/13 10:25:09

  Modified:    java/src/org/apache/soap/util/xml DOMUtils.java
  Log:
  Added a method to retrieve qualified attribute value. That is, will return
  a QName representing the value of the requested attribute.
  
  Revision  Changes    Path
  1.5       +36 -0     xml-soap/java/src/org/apache/soap/util/xml/DOMUtils.java
  
  Index: DOMUtils.java
  ===================================================================
  RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/util/xml/DOMUtils.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DOMUtils.java	2001/05/19 04:37:54	1.4
  +++ DOMUtils.java	2001/11/13 18:25:09	1.5
  @@ -287,4 +287,40 @@
   	  
   	  return null;
     }
  +
  +  public static QName getQualifiedAttributeValue(Element el,
  +                                                 String attrName)
  +    throws IllegalArgumentException
  +  {
  +    String attrValue = DOMUtils.getAttribute(el, attrName);
  +
  +    if (attrValue != null)
  +    {
  +      int    index                 = attrValue.indexOf(':');
  +      String attrValuePrefix       = (index != -1)
  +                                     ? attrValue.substring(0, index)
  +                                     : null;
  +      String attrValueLocalPart    = attrValue.substring(index + 1);
  +      String attrValueNamespaceURI =
  +        DOMUtils.getNamespaceURIFromPrefix(el, attrValuePrefix);
  +
  +      if (attrValueNamespaceURI != null)
  +      {
  +        return new QName(attrValueNamespaceURI, attrValueLocalPart);
  +      }
  +      else
  +      {
  +        throw new IllegalArgumentException("Unable to determine " +
  +                                           "namespace of '" +
  +                                           (attrValuePrefix != null
  +                                            ? attrValuePrefix + ":"
  +                                            : "") + attrValueLocalPart +
  +                                           "'.");
  +      }
  +    }
  +    else
  +    {
  +      return null;
  +    }
  +  }
   }