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:at.yawk.fanfiction.api.web.ChapterHandler.java

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
        throws SAXException {
    switch (stage) {
    case BEFORE://from www  . ja  v a2 s .  c o m
        if (qName.equals("div") && "storytext".equals(attributes.getValue("id"))) {
            stage = TEXT;
            textBuilder = new StringBuilder();
        }
        break;
    case TEXT:
        textBuilder.append('<').append(qName);
        for (int i = 0; i < attributes.getLength(); i++) {
            textBuilder.append(" ");
            textBuilder.append(attributes.getQName(i));
            textBuilder.append("=\"");
            textBuilder.append(attributes.getValue(i).replace("\\", "\\\\").replace("\"", "\\\""));
            textBuilder.append("\"");
        }
        textBuilder.append('>');
        break;
    }
}

From source file:com.granule.json.utils.internal.JSONSAXHandler.java

/**
 * This function parses an IFix top level element and all its children.
 *//*from  ww w. j a v  a2  s .  c om*/
public void startElement(String namespaceURI, String localName, String qName, Attributes attrs)
        throws SAXException {
    if (logger.isLoggable(Level.FINER))
        logger.exiting(className, "startElement(String,String,String,org.xml.sax.Attributes)");

    Properties props = new Properties();
    int attrLength = attrs.getLength();
    for (int i = 0; i < attrLength; i++) {
        props.put(attrs.getQName(i), attrs.getValue(i));
    }

    JSONObject obj = new JSONObject(localName, props);
    if (this.head == null) {
        this.head = obj;
        this.current = head;
    } else {
        if (current != null) {
            this.previousObjects.push(current);
            this.current.addJSONObject(obj);
        }
        this.current = obj;
    }

    if (logger.isLoggable(Level.FINER))
        logger.exiting(className, "startElement(String,String,String,org.xml.sax.Attributes)");
}

From source file:de.l3s.boilerpipe.sax.BoilerpipeHTMLContentHandler.java

private List<Pair<String, String>> convertAttributes(Attributes atts) {
    List<Pair<String, String>> attrs = new ArrayList<>();

    for (int i = 0; i < atts.getLength(); i++) {
        String qName = atts.getQName(i);
        attrs.add(Pair.of(qName, atts.getValue(qName)));
    }//  w  ww . j a va 2s.  c  om
    return attrs;
}

From source file:net.sf.joost.emitter.DOMEmitter.java

/**
 * SAX2-Callback - Creates a DOM-element-node and memorizes it for the
 * {@link #endElement(String ,String ,String)} method by putting it onto the
 * top of this stack.//from   www  .j a  v a  2 s  .  c om
 */
public void startElement(String uri, String local, String raw, Attributes attrs) throws SAXException {
    // create new element : iterate over all attribute-values
    Element elem = document.createElementNS(uri, raw);
    int nattrs = attrs.getLength();
    for (int i = 0; i < nattrs; i++) {
        String namespaceuri = attrs.getURI(i);
        String value = attrs.getValue(i);
        String qName = attrs.getQName(i);
        if ((namespaceuri == null) || (namespaceuri.equals(""))) {
            elem.setAttribute(qName, value);
        } else {
            elem.setAttributeNS(namespaceuri, qName, value);
        }
    }

    // append this new node onto current stack node
    insertNode(elem);
    // push this node into the global stack
    stack.push(elem);
}

From source file:com.jkoolcloud.tnt4j.streams.configure.sax.WsConfigParserHandler.java

private void processScenario(Attributes attrs) throws SAXParseException {
    if (currScenario != null) {
        throw new SAXParseException(StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                "ConfigParserHandler.malformed.configuration", SCENARIO_ELMT), currParseLocation);
    }// w w w .  j  av  a  2s .  co  m

    String name = null;
    for (int i = 0; i < attrs.getLength(); i++) {
        String attName = attrs.getQName(i);
        String attValue = attrs.getValue(i);
        if (NAME_ATTR.equals(attName)) {
            name = attValue;
        }
    }

    notEmpty(name, SCENARIO_ELMT, NAME_ATTR);

    currScenario = new WsScenario(name);
}

From source file:com.netspective.commons.xml.template.Template.java

public Map getTemplateParamsValues(NodeIdentifiers nodeIdentifiers, Attributes attributesFromCaller)
        throws SAXException {
    Set requiredParams = new HashSet();
    Map templateParamsValues = new HashMap();

    fillTemplateParamsRequiredAndDefaultValues(requiredParams, templateParamsValues, attributesFromCaller);

    for (int i = 0; i < attributesFromCaller.getLength(); i++) {
        String attrName = attributesFromCaller.getQName(i);
        if (attrName.startsWith(nodeIdentifiers.getTemplateParamAttrPrefix()))
            templateParamsValues.put(attrName.substring(nodeIdentifiers.getTemplateParamAttrPrefix().length()),
                    attributesFromCaller.getValue(i));
    }//www  .  j a  v a  2  s.  c o m

    // validate that all required parameters are available
    for (Iterator i = requiredParams.iterator(); i.hasNext();) {
        Parameter param = (Parameter) i.next();
        String paramValue = (String) templateParamsValues.get(param.getName());

        if (paramValue == null)
            throw new SAXException(
                    "Required param '" + param.getName() + "' not found. Available: " + templateParamsValues);
    }

    return templateParamsValues;
}

From source file:net.sf.ehcache.config.BeanHandler.java

/**
 * Receive notification of the start of an element.
 *///from ww w  .  j  a  va  2 s  .  com
public final void startElement(final String uri, final String localName, final String qName,
        final Attributes attributes) throws SAXException {
    // Create the child object
    if (element == null) {
        element = new ElementInfo(qName, bean);
    } else {
        final Object child = createChild(element, qName);
        element = new ElementInfo(element, qName, child);
    }

    // Set the attributes
    for (int i = 0; i < attributes.getLength(); i++) {
        final String attrName = attributes.getQName(i);
        final String attrValue = attributes.getValue(i);
        setAttribute(element, attrName, attrValue);
    }
}

From source file:org.syncope.core.util.ImportExport.java

@Override
public void startElement(final String uri, final String localName, final String qName, final Attributes atts)
        throws SAXException {

    // skip root element
    if (ROOT_ELEMENT.equals(qName)) {
        return;// w  w w.  j  a va2  s  .c o m
    }

    StringBuilder queryString = new StringBuilder("INSERT INTO ").append(qName).append('(');

    StringBuilder values = new StringBuilder();

    for (int i = 0; i < atts.getLength(); i++) {
        queryString.append(atts.getQName(i));
        values.append('?');
        if (i < atts.getLength() - 1) {
            queryString.append(',');
            values.append(',');
        }
    }
    queryString.append(") VALUES (").append(values).append(')');

    Query query = entityManager.createNativeQuery(queryString.toString());
    setParameters(qName, atts, query);
    query.executeUpdate();
}

From source file:com.frameworkset.orm.engine.transform.XmlToData.java

/**
 * Handles opening elements of the xml file.
 *//* www.  j av  a  2  s .com*/
public void startElement(String uri, String localName, String rawName, Attributes attributes)
        throws SAXException {
    try {
        if (rawName.equals("dataset")) {
            //ignore <dataset> for now.
        }

        else {
            Table table = database.getTableByJavaName(rawName);

            if (table == null) {
                throw new SAXException("Table '" + rawName + "' unknown");
            }
            List columnValues = new ArrayList();
            for (int i = 0; i < attributes.getLength(); i++) {
                Column col = table.getColumnByJavaName(attributes.getQName(i));

                if (col == null) {
                    throw new SAXException(
                            "Column " + attributes.getQName(i) + " in table " + rawName + " unknown.");
                }

                String value = attributes.getValue(i);
                columnValues.add(new ColumnValue(col, value));
            }
            data.add(new DataRow(table, columnValues));
        }
    } catch (Exception e) {
        throw new SAXException(e);
    }
}

From source file:com.jkoolcloud.tnt4j.streams.configure.sax.WsConfigParserHandler.java

private void processScenarioStep(Attributes attrs) throws SAXException {
    if (currScenario == null) {
        throw new SAXParseException(
                StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                        "ConfigParserHandler.malformed.configuration2", STEP_ELMT, SCENARIO_ELMT),
                currParseLocation);// ww  w. ja v a  2  s  .  com
    }
    String name = null;
    String url = null;
    String method = null;
    String username = null;
    String password = null;
    for (int i = 0; i < attrs.getLength(); i++) {
        String attName = attrs.getQName(i);
        String attValue = attrs.getValue(i);
        if (NAME_ATTR.equals(attName)) {
            name = attValue;
        } else if (URL_ATTR.equals(attName)) {
            url = attValue;
        } else if (METHOD_ATTR.equals(attName)) {
            method = attValue;
        } else if (USERMAME_ATTR.equals(attName)) {
            username = attValue;
        } else if (PASSWORD_ATTR.equals(attName)) {
            password = attValue;
        }
    }
    notEmpty(name, STEP_ELMT, NAME_ATTR);

    currStep = new WsScenarioStep(name);
    currStep.setUrlStr(url);
    currStep.setMethod(method);
    currStep.setCredentials(username, password);
}