Beispiel #1
0
  /**
   * Method processAttributes.
   *
   * @param node
   */
  protected void processAttributes(OMElement node) {
    int attribCount = parser.getAttributeCount();
    for (int i = 0; i < attribCount; i++) {
      String uri = parser.getAttributeNamespace(i);
      String prefix = parser.getAttributePrefix(i);

      OMNamespace namespace = null;
      if (uri != null && uri.length() > 0) {

        // prefix being null means this elements has a default namespace or it has inherited
        // a default namespace from its parent
        namespace = node.findNamespace(uri, prefix);
        if (namespace == null) {
          if (prefix == null || "".equals(prefix)) {
            prefix = OMSerializerUtil.getNextNSPrefix();
          }
          namespace = node.declareNamespace(uri, prefix);
        }
      }

      // todo if the attributes are supposed to namespace qualified all the time
      // todo then this should throw an exception here

      OMAttribute attr =
          node.addAttribute(
              parser.getAttributeLocalName(i), parser.getAttributeValue(i), namespace);
      attr.setAttributeType(parser.getAttributeType(i));
    }
  }
Beispiel #2
0
 public final String prepareSetNamespace(String prefix, String namespaceURI, boolean declare)
     throws CoreModelException {
   if (prefix != null) {
     NSUtil.validateAttributeNamespace(prefix, namespaceURI);
   }
   AxiomElement ownerElement = (AxiomElement) coreGetOwnerElement();
   if (ownerElement != null) {
     prefix = ownerElement.checkNamespaceIsDeclared(prefix, namespaceURI, false, declare);
   } else if (prefix == null) {
     prefix = namespaceURI.isEmpty() ? "" : OMSerializerUtil.getNextNSPrefix();
   }
   return prefix;
 }