Example usage for org.xml.sax Attributes getQName

List of usage examples for org.xml.sax Attributes getQName

Introduction

In this page you can find the example usage for org.xml.sax Attributes getQName.

Prototype

public abstract String getQName(int index);

Source Link

Document

Look up an attribute's XML qualified (prefixed) name by index.

Usage

From source file:org.xwiki.xml.Sax2Dom.java

@Override
public void startElement(String namespace, String localName, String qName, Attributes atts) {
    final Element element = this.document.createElementNS(namespace, qName);

    // Add namespace declarations first
    if (this.namespaceDecls != null) {
        final int nDecls = this.namespaceDecls.size();
        for (int i = 0; i < nDecls; i += 2) {
            String prefix = this.namespaceDecls.get(i);
            String uri = this.namespaceDecls.get(i + 1);

            if (StringUtils.isEmpty(prefix)) {
                element.setAttributeNS(XMLNS_URI, XMLNS_PREFIX, uri);
            } else {
                element.setAttributeNS(XMLNS_URI, XMLNS_STRING + prefix, uri);
            }/*from  w  ww . j ava 2s.com*/
        }
        this.namespaceDecls.clear();
    }

    // Add attributes to element
    final int nattrs = atts.getLength();
    for (int i = 0; i < nattrs; i++) {
        if (atts.getLocalName(i) == null) {
            element.setAttribute(atts.getQName(i), atts.getValue(i));
        } else {
            element.setAttributeNS(atts.getURI(i), atts.getQName(i), atts.getValue(i));
        }
    }

    // Append this new node onto current stack node
    this.nodes.peek().appendChild(element);

    // Push this node onto stack
    this.nodes.push(element);
}

From source file:sos.insert.InsertObservation.java

/** SAX handling, Receive notification of the start of an element. 
 * /*from  w  w  w  .j a v  a 2s .c o  m*/
 * @param namespaceURI  The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
 * @param localName The local name (without prefix), or the empty string if Namespace processing is not being performed.
 * @param qName The qualified name (with prefix), or the empty string if qualified names are not available.
 * @param atts The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
 * @throws SAXException Any SAX exception, possibly wrapping another exception.
 */
@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
        throws SAXException {
    if (qName.compareTo(INSERT_OBSERVATION) == 0) {
        insertObservationOn = true;
    } else if (insertObservationOn) {
        if (qName.compareTo(OFFERING) == 0) {
            // It is not managed here
        } else if (qName.compareTo(OBSERVATION) == 0) {
            buffer.delete(0, buffer.length());
            observationOn = true;
        } else if (observationOn) {
            buffer.append("<");
            buffer.append(qName);
            for (int i = 0; i < atts.getLength(); i++) {
                buffer.append(" ");
                buffer.append(atts.getQName(i));
                buffer.append("=\"");
                buffer.append(org.json.XML.escape(atts.getValue(i)));
                buffer.append("\"");
            }
            buffer.append(">");
        }
    } else {
        throw new SnannySostServerException(SnannySostServerMessages.ERROR_XML_INSERT + qName,
                Status.BAD_REQUEST);
    }
}

From source file:sos.insert.InsertSensor.java

/** SAX handling, Receive notification of the start of an element. 
 * //from w ww.j  a va  2s . co  m
 * @param namespaceURI The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
 * @param localName The local name (without prefix), or the empty string if Namespace processing is not being performed.
 * @param qName The qualified name (with prefix), or the empty string if qualified names are not available.
 * @param atts The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
 * @throws SAXException Any SAX exception, possibly wrapping another exception.
 */
@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
        throws SAXException {
    if (qName.compareTo(INSERT_SENSOR) == 0) {
        insertSensorOn = true;
    } else if (insertSensorOn) {
        if (qName.compareTo(FORMAT) == 0) {
            if (procedureOn || observablePropertyOn) {
                throw new SnannySostServerException(SnannySostServerMessages.ERROR_XML_INSERT + qName,
                        Status.BAD_REQUEST);
            }
            formatOn = true;
            format = "";
            buffer.delete(0, buffer.length());
        } else if (qName.compareTo(PROCEDURE) == 0) {
            if (formatOn || observablePropertyOn) {
                throw new SnannySostServerException(SnannySostServerMessages.ERROR_XML_INSERT + qName,
                        Status.BAD_REQUEST);
            }
            procedureOn = true;
            sensorML = "";
            buffer.delete(0, buffer.length());
        } else if (qName.compareTo(OBSERVABLE_PROPERTY) == 0) {
            if (formatOn || procedureOn) {
                throw new SnannySostServerException(SnannySostServerMessages.ERROR_XML_INSERT + qName,
                        Status.BAD_REQUEST);
            }
            observablePropertyOn = true;
        } else if (procedureOn) {
            buffer.append("<");
            buffer.append(qName);
            for (int i = 0; i < atts.getLength(); i++) {
                buffer.append(" ");
                buffer.append(atts.getQName(i));
                buffer.append("=\"");
                buffer.append(org.json.XML.escape(atts.getValue(i)));
                buffer.append("\"");
            }
            buffer.append(">");
        }
    } else {
        throw new SnannySostServerException(SnannySostServerMessages.ERROR_XML_INSERT + qName,
                Status.BAD_REQUEST);
    }
}

From source file:validation.xslt.handler.XsltResultHandler.java

/** SAX handling, Receive notification of the start of an element. 
 * //from w  w  w.j  ava2  s .  c om
 * @param namespaceURI The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
 * @param localName The local name (without prefix), or the empty string if Namespace processing is not being performed.
 * @param qName The qualified name (with prefix), or the empty string if qualified names are not available.
 * @param atts The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
 * @throws SAXException Any SAX exception, possibly wrapping another exception.
 */
@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
        throws SAXException {
    if (qName.compareTo(FAILED) == 0) {
        failed = true;
        buffer.append("<");
        buffer.append(qName);
        for (int i = 0; i < atts.getLength(); i++) {
            buffer.append(" ");
            buffer.append(atts.getQName(i));
            buffer.append("=\"");
            buffer.append(org.json.XML.escape(atts.getValue(i)));
            buffer.append("\"");
        }
        buffer.append('>');
    }
}