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));
    }
  }
 public String getAttributeType(int index) {
   if (state == STATE_START_DOCUMENT || state == STATE_END_DOCUMENT) {
     throw new IllegalStateException();
   } else {
     return parent.getAttributeType(index);
   }
 }
Beispiel #3
0
  /**
   * Get the attributes associated with the given START_ELEMENT or ATTRIBUTE StAXevent.
   *
   * @return the StAX attributes converted to an org.xml.sax.Attributes
   */
  private Attributes getAttributes() {
    AttributesImpl attrs = new AttributesImpl();

    int eventType = staxStreamReader.getEventType();
    if (eventType != XMLStreamConstants.ATTRIBUTE
        && eventType != XMLStreamConstants.START_ELEMENT) {
      throw new InternalError("getAttributes() attempting to process: " + eventType);
    }

    // in SAX, namespace declarations are not part of attributes by default.
    // (there's a property to control that, but as far as we are concerned
    // we don't use it.) So don't add xmlns:* to attributes.

    // gather non-namespace attrs
    for (int i = 0; i < staxStreamReader.getAttributeCount(); i++) {
      String uri = staxStreamReader.getAttributeNamespace(i);
      if (uri == null) uri = "";
      String localName = staxStreamReader.getAttributeLocalName(i);
      String prefix = staxStreamReader.getAttributePrefix(i);
      String qName;
      if (prefix == null || prefix.length() == 0) qName = localName;
      else qName = prefix + ':' + localName;
      String type = staxStreamReader.getAttributeType(i);
      String value = staxStreamReader.getAttributeValue(i);

      attrs.addAttribute(uri, localName, qName, type, value);
    }

    return attrs;
  }
 private void fillXMLAttributes(XMLStreamReader input) {
   fAttributes.removeAllAttributes();
   final int len = input.getAttributeCount();
   for (int i = 0; i < len; ++i) {
     fillQName(
         fAttributeQName,
         input.getAttributeNamespace(i),
         input.getAttributeLocalName(i),
         input.getAttributePrefix(i));
     String type = input.getAttributeType(i);
     fAttributes.addAttributeNS(
         fAttributeQName,
         (type != null) ? type : XMLSymbols.fCDATASymbol,
         input.getAttributeValue(i));
     fAttributes.setSpecified(i, input.isAttributeSpecified(i));
   }
 }
  private static void printAttributes(XMLStreamReader xmlr) {

    if (xmlr.getAttributeCount() > 0) {

      int count = xmlr.getAttributeCount();
      for (int i = 0; i < count; i++) {

        QName name = xmlr.getAttributeName(i);
        String namespace = xmlr.getAttributeNamespace(i);
        String type = xmlr.getAttributeType(i);
        String prefix = xmlr.getAttributePrefix(i);
        String value = xmlr.getAttributeValue(i);

        System.out.println(
            "\tAttribute: {" + namespace + "}:" + name.toString() + "(" + type + ")=" + value);
      }
    }
  }
 public String getAttributeType(final int index) {
   return streamReader.getAttributeType(index);
 }
Beispiel #7
0
 public String getAttributeType(int index) {
   return reader.getAttributeType(index);
 }