예제 #1
0
  private void checkAndCopyAttributes(Attributes attributes, ElementInfo elInfo)
      throws SAXException, RDFParseException {
    Atts atts = new Atts(attributes.getLength());

    int attCount = attributes.getLength();
    for (int i = 0; i < attCount; i++) {
      String qName = attributes.getQName(i);
      String value = attributes.getValue(i);

      // attributes starting with "xml" should be ignored, except for the
      // ones that are handled by this parser (xml:lang and xml:base).
      if (qName.startsWith("xml")) {
        if (qName.equals("xml:lang")) {
          elInfo.xmlLang = value;
        } else if (qName.equals("xml:base")) {
          elInfo.setBaseURI(value);
        }
      } else {
        String namespace = attributes.getURI(i);
        String localName = attributes.getLocalName(i);

        // A limited set of unqualified attributes must be supported by
        // parsers, as is specified in section 6.1.4 of the spec
        if ("".equals(namespace)) {
          if (localName.equals("ID")
              || localName.equals("about")
              || localName.equals("resource")
              || localName.equals("parseType")
              || localName.equals("type")) {
            rdfParser.reportWarning(
                "use of unqualified attribute " + localName + " has been deprecated");
            namespace = RDF.NAMESPACE;
          }
        }

        if ("".equals(namespace)) {
          rdfParser.reportError(
              "unqualified attribute '" + qName + "' not allowed",
              XMLParserSettings.FAIL_ON_INVALID_QNAME);
        }

        Att att = new Att(namespace, localName, qName, value);
        atts.addAtt(att);
      }
    }

    elInfo.atts = atts;
  }