org.xml.sax.Attributes#getLength ( )源码实例Demo

下面列出了org.xml.sax.Attributes#getLength ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jdk1.8-source-analysis   文件: SynthParser.java
private void startImageIcon(Attributes attributes) throws SAXException {
 String path = null;
 String id = null;

 for(int i = attributes.getLength() - 1; i >= 0; i--) {
     String key = attributes.getQName(i);

     if (key.equals(ATTRIBUTE_ID)) {
         id = attributes.getValue(i);
     }
     else if (key.equals(ATTRIBUTE_PATH)) {
         path = attributes.getValue(i);
     }
 }
 if (path == null) {
     throw new SAXException("imageIcon: you must specify a path");
 }
 register(id, new LazyImageIcon(getResource(path)));
}
 
源代码2 项目: openjdk-jdk8u   文件: NGCCRuntimeEx.java
public ForeignAttributesImpl parseForeignAttributes( ForeignAttributesImpl next ) {
    ForeignAttributesImpl impl = new ForeignAttributesImpl(createValidationContext(),copyLocator(),next);

    Attributes atts = getCurrentAttributes();
    for( int i=0; i<atts.getLength(); i++ ) {
        if(atts.getURI(i).length()>0) {
            impl.addAttribute(
                atts.getURI(i),
                atts.getLocalName(i),
                atts.getQName(i),
                atts.getType(i),
                atts.getValue(i)
            );
        }
    }

    return impl;
}
 
源代码3 项目: jdk8u60   文件: AttributesImpl.java
/**
 * Copy an entire Attributes object.
 *
 * <p>It may be more efficient to reuse an existing object
 * rather than constantly allocating new ones.</p>
 *
 * @param atts The attributes to copy.
 */
public void setAttributes (Attributes atts)
{
    clear();
    length = atts.getLength();
    if (length > 0) {
        data = new String[length*5];
        for (int i = 0; i < length; i++) {
            data[i*5] = atts.getURI(i);
            data[i*5+1] = atts.getLocalName(i);
            data[i*5+2] = atts.getQName(i);
            data[i*5+3] = atts.getType(i);
            data[i*5+4] = atts.getValue(i);
        }
    }
}
 
源代码4 项目: netbeans   文件: DefaultAttributes.java
private boolean checkAttributes(Attributes attrList,HashMap<String, String> mapMandatory, HashMap<String, String> mapAllowed) {
    String temp;
    mandatAttrCount = 0;

    if (attrList == null) {
        return false;
    }

    for (int i = 0; i < attrList.getLength(); i++) {
        if (isMandatoryAttr(attrList.getQName(i)) != -1) {
            temp = attrList.getQName(i).toUpperCase(Locale.ENGLISH);
            mapMandatory.put(temp, attrList.getValue(i));

            continue;
        }

        if (isAllowedAttr(attrList.getQName(i)) != -1) {
            temp = attrList.getQName(i).toUpperCase(Locale.ENGLISH);
            mapAllowed.put(temp, attrList.getValue(i));

            continue;
        }
    }

    return isMandatOK();
}
 
源代码5 项目: TencentKona-8   文件: SchemaParser.java
public void startElement(String namespaceURI, String localName,
        String qName, Attributes atts) {
    flushText();
    if (builder != null) {
        builderStack.push(builder);
    }
    Location loc = makeLocation();
    builder = schemaBuilder.makeElementAnnotationBuilder(namespaceURI,
            localName,
            findPrefix(qName, namespaceURI),
            loc,
            getComments(),
            getContext());
    int len = atts.getLength();
    for (int i = 0; i < len; i++) {
        String uri = atts.getURI(i);
        builder.addAttribute(uri, atts.getLocalName(i), findPrefix(atts.getQName(i), uri),
                atts.getValue(i), loc);
    }
}
 
源代码6 项目: openjdk-jdk8u   文件: MutableAttrListImpl.java
/**
 * Add the contents of the attribute list to this list.
 *
 * @param atts List of attributes to add to this list
 */
public void addAttributes(Attributes atts)
{

  int nAtts = atts.getLength();

  for (int i = 0; i < nAtts; i++)
  {
    String uri = atts.getURI(i);

    if (null == uri)
      uri = "";

    String localName = atts.getLocalName(i);
    String qname = atts.getQName(i);
    int index = this.getIndex(uri, localName);
    // System.out.println("MutableAttrListImpl#addAttributes: "+uri+":"+localName+", "+index+", "+atts.getQName(i)+", "+this);
    if (index >= 0)
      this.setAttribute(index, uri, localName, qname, atts.getType(i),
                        atts.getValue(i));
    else
      addAttribute(uri, localName, qname, atts.getType(i),
                   atts.getValue(i));
  }
}
 
源代码7 项目: awacs   文件: Processor.java
@Override
public final void startElement(final String ns, final String localName,
        final String qName, final Attributes atts) throws SAXException {
    try {
        closeElement();

        writeIdent();
        w.write('<' + qName);
        if (atts != null && atts.getLength() > 0) {
            writeAttributes(atts);
        }

        if (optimizeEmptyElements) {
            openElement = true;
        } else {
            w.write(">\n");
        }
        ident += 2;

    } catch (IOException ex) {
        throw new SAXException(ex);

    }
}
 
源代码8 项目: jdk1.8-source-analysis   文件: SynthParser.java
private void startBind(Attributes attributes) throws SAXException {
    ParsedSynthStyle style = null;
    String path = null;
    int type = -1;

    for(int i = attributes.getLength() - 1; i >= 0; i--) {
        String key = attributes.getQName(i);

        if (key.equals(ATTRIBUTE_STYLE)) {
            style = (ParsedSynthStyle)lookup(attributes.getValue(i),
                                              ParsedSynthStyle.class);
        }
        else if (key.equals(ATTRIBUTE_TYPE)) {
            String typeS = attributes.getValue(i).toUpperCase();

            if (typeS.equals("NAME")) {
                type = DefaultSynthStyleFactory.NAME;
            }
            else if (typeS.equals("REGION")) {
                type = DefaultSynthStyleFactory.REGION;
            }
            else {
                throw new SAXException("bind: unknown type " + typeS);
            }
        }
        else if (key.equals(ATTRIBUTE_KEY)) {
            path = attributes.getValue(i);
        }
    }
    if (style == null || path == null || type == -1) {
        throw new SAXException("bind: you must specify a style, type " +
                               "and key");
    }
    try {
        _factory.addStyle(style, path, type);
    } catch (PatternSyntaxException pse) {
        throw new SAXException("bind: " + path + " is not a valid " +
                               "regular expression");
    }
}
 
源代码9 项目: gcs   文件: XmlPeer.java
/** Gets the list of attributes of the peer. 
* @param attrs the user defined set of attributes
* @return the set of attributes translated to iText attributes
*/
   public Properties getAttributes(Attributes attrs) {
       Properties attributes = new Properties();
       attributes.putAll(attributeValues);
       if (defaultContent != null) {
           attributes.put(ElementTags.ITEXT, defaultContent);
       }
       if (attrs != null) {
           for (int i = 0; i < attrs.getLength(); i++) {
               String attribute = getName(attrs.getQName(i));
               attributes.setProperty(attribute, attrs.getValue(i));
           }
       }
       return attributes;
   }
 
源代码10 项目: netbeans   文件: PolicyManager.java
@Override
public void startElement( String uri, String localName, String qName,
        Attributes attributes ) throws SAXException
{
    super.startElement(uri, localName, qName, attributes);
    for (DefaultHandler delegate : delegates) {
        delegate.startElement(uri, localName, qName, attributes);
    }
    boolean policy = false;
    if ( localName != null && localName.equals(POLICY)){
        policy = true;
    }
    if ( qName != null && qName.endsWith(COLON_POLICY) ) {
        policy = true;
    }
    if ( !policy ){
        return;
    }
    else {
        hasPolicy = true;
    }
    int count = attributes.getLength();
    for (int i=0; i<count ; i++) {
        String value = attributes.getValue(i);
        String attrLocalName = attributes.getLocalName(i);
        String attrQName = attributes.getQName(i);
        
        if ( (attrLocalName!=null && attrLocalName.equals(ID)) || 
                (attrLocalName!= null && attrQName.endsWith(COLON_ID)))
        {
            policies.add( attributes.getValue(i));
        }
    }
}
 
源代码11 项目: openjdk-jdk9   文件: SynthParser.java
private void startBind(Attributes attributes) throws SAXException {
    ParsedSynthStyle style = null;
    String path = null;
    int type = -1;

    for(int i = attributes.getLength() - 1; i >= 0; i--) {
        String key = attributes.getQName(i);

        if (key.equals(ATTRIBUTE_STYLE)) {
            style = (ParsedSynthStyle)lookup(attributes.getValue(i),
                                              ParsedSynthStyle.class);
        }
        else if (key.equals(ATTRIBUTE_TYPE)) {
            String typeS = attributes.getValue(i).toUpperCase();

            if (typeS.equals("NAME")) {
                type = DefaultSynthStyleFactory.NAME;
            }
            else if (typeS.equals("REGION")) {
                type = DefaultSynthStyleFactory.REGION;
            }
            else {
                throw new SAXException("bind: unknown type " + typeS);
            }
        }
        else if (key.equals(ATTRIBUTE_KEY)) {
            path = attributes.getValue(i);
        }
    }
    if (style == null || path == null || type == -1) {
        throw new SAXException("bind: you must specify a style, type " +
                               "and key");
    }
    try {
        _factory.addStyle(style, path, type);
    } catch (PatternSyntaxException pse) {
        throw new SAXException("bind: " + path + " is not a valid " +
                               "regular expression");
    }
}
 
private void descriptionStarted(String qName, Attributes attributes) {
    buffer.append("<").append(qName);
    for (int i = 0; i < attributes.getLength(); i++) {
        buffer.append(" ");
        buffer.append(attributes.getQName(i));
        buffer.append("=\"");
        buffer.append(attributes.getValue(i));
        buffer.append("\"");
    }
    buffer.append(">");
}
 
源代码13 项目: openjdk-jdk9   文件: AttributesImpl.java
/**
 * Copy an entire Attributes object.
 *
 * <p>It may be more efficient to reuse an existing object
 * rather than constantly allocating new ones.</p>
 *
 * @param atts The attributes to copy.
 */
public void setAttributes (Attributes atts)
{
clear();
length = atts.getLength();
data = new String[length*5];
for (int i = 0; i < length; i++) {
    data[i*5] = atts.getURI(i);
    data[i*5+1] = atts.getLocalName(i);
    data[i*5+2] = atts.getQName(i);
    data[i*5+3] = atts.getType(i);
    data[i*5+4] = atts.getValue(i);
}
}
 
源代码14 项目: hottub   文件: AttributesImplSerializer.java
/**
 * This method sets the attributes, previous attributes are cleared,
 * it also keeps the hashtable up to date for quick lookup via
 * getIndex(qName).
 * @param atts the attributes to copy into these attributes.
 * @see org.xml.sax.helpers.AttributesImpl#setAttributes(Attributes)
 * @see #getIndex(String)
 */
public final void setAttributes(Attributes atts)
{

    super.setAttributes(atts);

    // we've let the super class add the attributes, but
    // we need to keep the hash table up to date ourselves for the
    // potentially new qName/index pairs for quick lookup.
    int numAtts = atts.getLength();
    if (MAX <= numAtts)
        switchOverToHash(numAtts);

}
 
源代码15 项目: openjdk-jdk8u-backup   文件: SAXBufferCreator.java
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    storeQualifiedName(T_ELEMENT_LN,
            uri, localName, qName);

    // Has namespaces attributes
    if (_namespaceAttributesPtr > 0) {
        storeNamespaceAttributes();
    }

    // Has attributes
    if (attributes.getLength() > 0) {
        storeAttributes(attributes);
    }
    depth++;
}
 
源代码16 项目: TencentKona-8   文件: Parser.java
/**
 * checks the list of attributes against a list of allowed attributes
 * for a particular element node.
 */
private void checkForSuperfluousAttributes(SyntaxTreeNode node,
    Attributes attrs)
{
    QName qname = node.getQName();
    boolean isStylesheet = (node instanceof Stylesheet);
    String[] legal = _instructionAttrs.get(qname.getStringRep());
    if (versionIsOne && legal != null) {
        int j;
        final int n = attrs.getLength();

        for (int i = 0; i < n; i++) {
            final String attrQName = attrs.getQName(i);

            if (isStylesheet && attrQName.equals("version")) {
                versionIsOne = attrs.getValue(i).equals("1.0");
            }

            // Ignore if special or if it has a prefix
            if (attrQName.startsWith("xml") ||
                attrQName.indexOf(':') > 0) continue;

            for (j = 0; j < legal.length; j++) {
                if (attrQName.equalsIgnoreCase(legal[j])) {
                    break;
                }
            }
            if (j == legal.length) {
                final ErrorMsg err =
                    new ErrorMsg(ErrorMsg.ILLEGAL_ATTRIBUTE_ERR,
                            attrQName, node);
                // Workaround for the TCK failure ErrorListener.errorTests.error001..
                err.setWarningError(true);
                reportError(WARNING, err);
            }
        }
    }
}
 
源代码17 项目: microMathematics   文件: SVGParser.java
private void  parseAttributesUse(SVG.Use obj, Attributes attributes) throws SVGParseException
{
   for (int i=0; i<attributes.getLength(); i++)
   {
      String val = attributes.getValue(i).trim();
      switch (SVGAttr.fromString(attributes.getLocalName(i)))
      {
         case x:
            obj.x = parseLength(val);
            break;
         case y:
            obj.y = parseLength(val);
            break;
         case width:
            obj.width = parseLength(val);
            if (obj.width.isNegative())
               throw new SVGParseException("Invalid <use> element. width cannot be negative");
            break;
         case height:
            obj.height = parseLength(val);
            if (obj.height.isNegative())
               throw new SVGParseException("Invalid <use> element. height cannot be negative");
            break;
         case href:
            if ("".equals(attributes.getURI(i)) || XLINK_NAMESPACE.equals(attributes.getURI(i)))
               obj.href = val;
            break;
         default:
            break;
      }
   }
}
 
源代码18 项目: Tomcat8-Source-Read   文件: Validator.java
@Override
public void visit(Node.TagDirective n) throws JasperException {
    // Note: Most of the validation is done in TagFileProcessor
    // when it created a TagInfo object from the
    // tag file in which the directive appeared.

    // This method does additional processing to collect page info

    Attributes attrs = n.getAttributes();
    for (int i = 0; attrs != null && i < attrs.getLength(); i++) {
        String attr = attrs.getQName(i);
        String value = attrs.getValue(i);

        if ("language".equals(attr)) {
            if (pageInfo.getLanguage(false) == null) {
                pageInfo.setLanguage(value, n, err, false);
            } else if (!pageInfo.getLanguage(false).equals(value)) {
                err.jspError(n, "jsp.error.tag.conflict.language",
                        pageInfo.getLanguage(false), value);
            }
        } else if ("isELIgnored".equals(attr)) {
            if (pageInfo.getIsELIgnored() == null) {
                pageInfo.setIsELIgnored(value, n, err, false);
            } else if (!pageInfo.getIsELIgnored().equals(value)) {
                err.jspError(n, "jsp.error.tag.conflict.iselignored",
                        pageInfo.getIsELIgnored(), value);
            }
        } else if ("pageEncoding".equals(attr)) {
            if (pageEncodingSeen)
                err.jspError(n, "jsp.error.tag.multi.pageencoding");
            pageEncodingSeen = true;
            compareTagEncodings(value, n);
            n.getRoot().setPageEncoding(value);
        } else if ("deferredSyntaxAllowedAsLiteral".equals(attr)) {
            if (pageInfo.getDeferredSyntaxAllowedAsLiteral() == null) {
                pageInfo.setDeferredSyntaxAllowedAsLiteral(value, n,
                        err, false);
            } else if (!pageInfo.getDeferredSyntaxAllowedAsLiteral()
                    .equals(value)) {
                err
                        .jspError(
                                n,
                                "jsp.error.tag.conflict.deferredsyntaxallowedasliteral",
                                pageInfo
                                        .getDeferredSyntaxAllowedAsLiteral(),
                                value);
            }
        } else if ("trimDirectiveWhitespaces".equals(attr)) {
            if (pageInfo.getTrimDirectiveWhitespaces() == null) {
                pageInfo.setTrimDirectiveWhitespaces(value, n, err,
                        false);
            } else if (!pageInfo.getTrimDirectiveWhitespaces().equals(
                    value)) {
                err
                        .jspError(
                                n,
                                "jsp.error.tag.conflict.trimdirectivewhitespaces",
                                pageInfo.getTrimDirectiveWhitespaces(),
                                value);
            }
        }
    }

    // Attributes for imports for this node have been processed by
    // the parsers, just add them to pageInfo.
    pageInfo.addImports(n.getImports());
}
 
源代码19 项目: openjdk-jdk9   文件: SynthParser.java
private void startState(Attributes attributes) throws SAXException {
    ParsedSynthStyle.StateInfo stateInfo = null;
    int state = 0;
    String id = null;

    _stateInfo = null;
    for(int i = attributes.getLength() - 1; i >= 0; i--) {
        String key = attributes.getQName(i);
        if (key.equals(ATTRIBUTE_ID)) {
            id = attributes.getValue(i);
        }
        else if (key.equals(ATTRIBUTE_IDREF)) {
            _stateInfo = (ParsedSynthStyle.StateInfo)lookup(
               attributes.getValue(i), ParsedSynthStyle.StateInfo.class);
        }
        else if (key.equals(ATTRIBUTE_CLONE)) {
            _stateInfo = (ParsedSynthStyle.StateInfo)((ParsedSynthStyle.
                         StateInfo)lookup(attributes.getValue(i),
                         ParsedSynthStyle.StateInfo.class)).clone();
        }
        else if (key.equals(ATTRIBUTE_VALUE)) {
            StringTokenizer tokenizer = new StringTokenizer(
                               attributes.getValue(i));
            while (tokenizer.hasMoreTokens()) {
                String stateString = tokenizer.nextToken().toUpperCase().
                                               intern();
                if (stateString == "ENABLED") {
                    state |= SynthConstants.ENABLED;
                }
                else if (stateString == "MOUSE_OVER") {
                    state |= SynthConstants.MOUSE_OVER;
                }
                else if (stateString == "PRESSED") {
                    state |= SynthConstants.PRESSED;
                }
                else if (stateString == "DISABLED") {
                    state |= SynthConstants.DISABLED;
                }
                else if (stateString == "FOCUSED") {
                    state |= SynthConstants.FOCUSED;
                }
                else if (stateString == "SELECTED") {
                    state |= SynthConstants.SELECTED;
                }
                else if (stateString == "DEFAULT") {
                    state |= SynthConstants.DEFAULT;
                }
                else if (stateString != "AND") {
                    throw new SAXException("Unknown state: " + state);
                }
            }
        }
    }
    if (_stateInfo == null) {
        _stateInfo = new ParsedSynthStyle.StateInfo();
    }
    _stateInfo.setComponentState(state);
    register(id, _stateInfo);
    _stateInfos.add(_stateInfo);
}
 
源代码20 项目: currency   文件: Parser.java
@Override
public void startElement(String uri, String localName, String qName,
                         Attributes attributes)
{
    String name = "EUR";
    double rate;

    if (localName.equals("Cube"))
    {
        for (int i = 0; i < attributes.getLength(); i++)
        {
            // Get the date
            switch (attributes.getLocalName(i))
            {
            case "time":
                date = attributes.getValue(i);
                break;

            // Get the currency name
            case "currency":
                name = attributes.getValue(i);
                break;

            // Get the currency rate
            case "rate":
                try
                {
                    rate = Double.parseDouble(attributes.getValue(i));
                }
                catch (Exception e)
                {
                    rate = 1.0;
                }

                // Add new currency to the map
                map.put(name, rate);
                break;
            }
        }
    }
}