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

The following examples show how to use org.xml.sax.Attributes#getLocalName() . 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: AttributesImpl.java    From openjdk-8-source 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 2
Source File: MutableAttrListImpl.java    From openjdk-jdk9 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 3
Source File: ResourceRegistrationHelper.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void readAttributes(String qname, Attributes attributes) throws SAXException {
    properties = new HashMap<String, String>();

    String resourceName = attributes.getValue(nameKey);
    properties.put(nameKey, resourceName);  //NOI18N

    int attrLen = attributes.getLength();
    for (int i = 0; i < attrLen; i++) {
        String name = attributes.getLocalName(i);
        String value = attributes.getValue(i);
        if (name != null && name.length() > 0 && value != null && value.length() > 0) {
            properties.put(name, value);
        }
    }
}
 
Example 4
Source File: MutableAttrListImpl.java    From openjdk-jdk8u-backup 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 5
Source File: AttributesImpl.java    From openjdk-jdk8u-backup 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 6
Source File: EncodingAlgorithmAttributesImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Copy an entire Attributes object.
 *
 * @param atts The attributes to copy.
 */
public void setAttributes(Attributes atts) {
    _length = atts.getLength();
    if (_length > 0) {

        if (_length >= _algorithmData.length) {
            resizeNoCopy();
        }

        int index = 0;
        for (int i = 0; i < _length; i++) {
            _data[index++] = atts.getURI(i);
            _data[index++] = atts.getLocalName(i);
            _data[index++] = atts.getQName(i);
            _data[index++] = atts.getType(i);
            _data[index++] = atts.getValue(i);
            index++;
            _toIndex[i] = false;
            _alphabets[i] = null;
        }
    }
}
 
Example 7
Source File: AttributesImpl.java    From TencentKona-8 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 8
Source File: AttributesImpl.java    From openjdk-jdk9 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 9
Source File: EncodingAlgorithmAttributesImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Copy an entire Attributes object.
 *
 * @param atts The attributes to copy.
 */
public void setAttributes(Attributes atts) {
    _length = atts.getLength();
    if (_length > 0) {

        if (_length >= _algorithmData.length) {
            resizeNoCopy();
        }

        int index = 0;
        for (int i = 0; i < _length; i++) {
            _data[index++] = atts.getURI(i);
            _data[index++] = atts.getLocalName(i);
            _data[index++] = atts.getQName(i);
            _data[index++] = atts.getType(i);
            _data[index++] = atts.getValue(i);
            index++;
            _toIndex[i] = false;
            _alphabets[i] = null;
        }
    }
}
 
Example 10
Source File: SketchHandler.java    From CQL with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Converts an Attributes XML object into a Map of String,String pairs.
 * Duplicate attributes (which Easik won't generate anyway) won't work.
 * 
 * @param atts the Attributes object to convert to a Map
 * @param omit any number of local names that should be omitted from the
 *             generated Map
 * @return a Map of String,String pairs with local attribute names as the keys,
 *         values as the values, not including any keys with a local name in
 *         <code>omit</code>.
 */
private static Map<String, String> attributeMap(Attributes atts, String... omit) {
	LinkedHashMap<String, String> attMap = new LinkedHashMap<>();
	HashSet<String> skip = new HashSet<>(Arrays.asList(omit));

	for (int i = 0; i < atts.getLength(); i++) {
		String local = atts.getLocalName(i);

		if (local.equals("")) {
			local = atts.getQName(i);
		}

		if (!skip.contains(local)) {
			attMap.put(local, atts.getValue(i));
		}
	}

	return attMap;
}
 
Example 11
Source File: LocationRecordingProgressReportingHandler.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 5 votes vote down vote up
public void startElement(
        String uri, String localName, String qName, Attributes attrs) {
	progress.setWorkRemaining(100);
    Element e = null;
    if (localName != null && !"".equals(localName)) {
        e = doc.createElementNS(uri, localName);
    } else {
        e = doc.createElement(qName);
    }

    // But this part isn't lifted ;)
    setLocationData(e);

    if (current == null) {
        doc.appendChild(e);
    } else {
        current.appendChild(e);
    }
    current = e;

    // For each attribute, make a new attribute in the DOM, append it
    // to the current element, and set the column and line numbers.
    if (attrs != null) {
        for (int i = 0; i < attrs.getLength(); i++) {
            Attr attr = null;
            if (attrs.getLocalName(i) != null && !"".equals(attrs.getLocalName(i))) {
                attr = doc.createAttributeNS(attrs.getURI(i), attrs.getLocalName(i));
                attr.setValue(attrs.getValue(i));
                setLocationData(attr);
                current.setAttributeNodeNS(attr);
            } else {
                attr = doc.createAttribute(attrs.getQName(i));
                attr.setValue(attrs.getValue(i));
                setLocationData(attr);
                current.setAttributeNode(attr);
            }
        }
    }
}
 
Example 12
Source File: JvmConfigReader.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
    public void readAttributes(String qname, Attributes attributes) throws SAXException {
//        <java-config
//            classpath-prefix="CP-PREFIX"
//            classpath-suffix="CP-SUFFIX"
//            debug-enabled="false"
//            debug-options="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9009"
//            env-classpath-ignored="false"
//            java-home="${com.sun.aas.javaRoot}"
//            javac-options="-g"
//            native-library-path-prefix="NATIVE-LIB-PREFIX"
//            native-library-path-suffix="NATIVE-LIB-SUFFIX"
//            rmic-options="-iiop -poa -alwaysgenerate -keepgenerated -g"
//            server-classpath="SERVER-CLASSPATH"
//            system-classpath="SYSTEM-CLASSPATH">
        if (readConfig) {
            int attrLen = attributes.getLength();
            for (int i = 0; i < attrLen; i++) {
                String name = attributes.getLocalName(i);
                // seems that sometimes from uknown reasons
                // getLocalName returns empty string...
                if ((name == null) || name.isEmpty()) {
                    name = attributes.getQName(i);
                }
                String value = attributes.getValue(i);
                if (name != null && name.length() > 0 && value != null && value.length() > 0) {
                    propMap.put(name, value);
                }
            }
        }
    }
 
Example 13
Source File: AttributesImpl.java    From openjdk-8 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 14
Source File: XMLParser.java    From AndroidChromium 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 {
    if (mTagStack.empty()) throw new SAXException("Tag stack is empty when it shouldn't be.");

    Node currentNode = new Node(qName);
    mTagStack.peek().children.add(currentNode);
    mTagStack.push(currentNode);

    for (int i = 0; i < attributes.getLength(); ++i) {
        String attributeName = attributes.getLocalName(i);
        String attributeValue = attributes.getValue(attributeName);
        currentNode.attributes.put(attributeName, attributeValue);
    }
}
 
Example 15
Source File: NodeCreateRule.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a new child {@link org.w3c.dom.Element Element} to the current
 * node.
 * 
 * @param namespaceURI the namespace URI
 * @param localName the local name
 * @param qName the qualified (prefixed) name
 * @param atts the list of attributes
 * @throws SAXException if the DOM implementation throws an exception
 */
@Override
public void startElement(String namespaceURI, String localName,
                         String qName, Attributes atts)
    throws SAXException {

    try {
        Node previousTop = top;
        if ((localName == null) || (localName.length() == 0)) { 
            top = doc.createElement(qName);
        } else {
            top = doc.createElementNS(namespaceURI, localName);
        }
        for (int i = 0; i < atts.getLength(); i++) {
            Attr attr = null;
            if ((atts.getLocalName(i) == null) ||
                (atts.getLocalName(i).length() == 0)) {
                attr = doc.createAttribute(atts.getQName(i));
                attr.setNodeValue(atts.getValue(i));
                ((Element)top).setAttributeNode(attr);
            } else {
                attr = doc.createAttributeNS(atts.getURI(i),
                                             atts.getLocalName(i));
                attr.setNodeValue(atts.getValue(i));
                ((Element)top).setAttributeNodeNS(attr);
            }
        }
        previousTop.appendChild(top);
        depth++;
    } catch (DOMException e) {
        throw new SAXException(e.getMessage(), e);
    }

}
 
Example 16
Source File: SchemaParser.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
void attributes(Attributes atts) throws SAXException {
    int len = atts.getLength();
    for (int i = 0; i < len; i++) {
        String uri = atts.getURI(i);
        if (uri.length() == 0) {
            String name = atts.getLocalName(i);
            if (name.equals("name")) {
                setName(atts.getValue(i).trim());
            } else if (name.equals("ns")) {
                ns = atts.getValue(i);
            } else if (name.equals("datatypeLibrary")) {
                datatypeLibrary = atts.getValue(i);
                checkUri(datatypeLibrary);
                if (!datatypeLibrary.equals("")
                        && !Uri.isAbsolute(datatypeLibrary)) {
                    error("relative_datatype_library");
                }
                if (Uri.hasFragmentId(datatypeLibrary)) {
                    error("fragment_identifier_datatype_library");
                }
                datatypeLibrary = Uri.escapeDisallowedChars(datatypeLibrary);
            } else {
                setOtherAttribute(name, atts.getValue(i));
            }
        } else if (uri.equals(relaxngURI)) {
            error("qualified_attribute", atts.getLocalName(i));
        } else if (uri.equals(WellKnownNamespaces.XML)
                && atts.getLocalName(i).equals("base")) {
            xmlBaseHandler.xmlBaseAttribute(atts.getValue(i));
        } else {
            if (annotations == null) {
                annotations = schemaBuilder.makeAnnotations(null, getContext());
            }
            annotations.addAttribute(uri, atts.getLocalName(i), findPrefix(atts.getQName(i), uri),
                    atts.getValue(i), startLocation);
        }
    }
    endAttributes();
}
 
Example 17
Source File: AttributesImpl.java    From openjdk-jdk8u-backup 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 18
Source File: AttributesImpl.java    From openjdk-8-source 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 19
Source File: XMLParser.java    From delion 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 {
    if (mTagStack.empty()) throw new SAXException("Tag stack is empty when it shouldn't be.");

    Node currentNode = new Node(qName);
    mTagStack.peek().children.add(currentNode);
    mTagStack.push(currentNode);

    for (int i = 0; i < attributes.getLength(); ++i) {
        String attributeName = attributes.getLocalName(i);
        String attributeValue = attributes.getValue(attributeName);
        currentNode.attributes.put(attributeName, attributeValue);
    }
}
 
Example 20
Source File: SchemaParser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
void attributes(Attributes atts) throws SAXException {
    int len = atts.getLength();
    for (int i = 0; i < len; i++) {
        String uri = atts.getURI(i);
        if (uri.length() == 0) {
            String name = atts.getLocalName(i);
            if (name.equals("name")) {
                setName(atts.getValue(i).trim());
            } else if (name.equals("ns")) {
                ns = atts.getValue(i);
            } else if (name.equals("datatypeLibrary")) {
                datatypeLibrary = atts.getValue(i);
                checkUri(datatypeLibrary);
                if (!datatypeLibrary.equals("")
                        && !Uri.isAbsolute(datatypeLibrary)) {
                    error("relative_datatype_library");
                }
                if (Uri.hasFragmentId(datatypeLibrary)) {
                    error("fragment_identifier_datatype_library");
                }
                datatypeLibrary = Uri.escapeDisallowedChars(datatypeLibrary);
            } else {
                setOtherAttribute(name, atts.getValue(i));
            }
        } else if (uri.equals(relaxngURI)) {
            error("qualified_attribute", atts.getLocalName(i));
        } else if (uri.equals(WellKnownNamespaces.XML)
                && atts.getLocalName(i).equals("base")) {
            xmlBaseHandler.xmlBaseAttribute(atts.getValue(i));
        } else {
            if (annotations == null) {
                annotations = schemaBuilder.makeAnnotations(null, getContext());
            }
            annotations.addAttribute(uri, atts.getLocalName(i), findPrefix(atts.getQName(i), uri),
                    atts.getValue(i), startLocation);
        }
    }
    endAttributes();
}