Java Code Examples for org.xml.sax.Attributes#getLength()

The following examples show how to use org.xml.sax.Attributes#getLength() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NGCCRuntimeEx.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: Processor.java    From awacs with Apache License 2.0 6 votes vote down vote up
@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);

    }
}
 
Example 3
Source File: MutableAttrListImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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));
  }
}
 
Example 4
Source File: SchemaParser.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example 5
Source File: DefaultAttributes.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 6
Source File: AttributesImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 7
Source File: SynthParser.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
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)));
}
 
Example 8
Source File: PolicyManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@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));
        }
    }
}
 
Example 9
Source File: SynthParser.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example 10
Source File: IvyXmlModuleDescriptorParser.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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(">");
}
 
Example 11
Source File: AttributesImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
}
 
Example 12
Source File: AttributesImplSerializer.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);

}
 
Example 13
Source File: SAXBufferCreator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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++;
}
 
Example 14
Source File: Parser.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
            }
        }
    }
}
 
Example 15
Source File: SVGParser.java    From microMathematics with GNU General Public License v3.0 5 votes vote down vote up
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;
      }
   }
}
 
Example 16
Source File: XmlPeer.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/** 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;
   }
 
Example 17
Source File: SynthParser.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
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");
    }
}
 
Example 18
Source File: Validator.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@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());
}
 
Example 19
Source File: SynthParser.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
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);
}
 
Example 20
Source File: Parser.java    From currency with GNU General Public License v3.0 4 votes vote down vote up
@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;
            }
        }
    }
}