Example usage for org.xml.sax Attributes getValue

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

Introduction

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

Prototype

public abstract String getValue(String qName);

Source Link

Document

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

Usage

From source file:com.sun.faces.config.rules.DisplayNameRule.java

/**
 * <p>Create or retrieve an instance of <code>DisplayNameBean</code>
 * and push it on to the object statck.</p>
 *
 * @param namespace the namespace URI of the matching element, or an 
 *   empty string if the parser is not namespace aware or the element has
 *   no namespace/* w  ww  .  j  ava 2 s  .  com*/
 * @param name the local name if the parser is namespace aware, or just 
 *   the element name otherwise
 * @param attributes The attribute list of this element
 *
 * @exception IllegalStateException if the parent stack element is not
 *  of type FeatureBean
 */
public void begin(String namespace, String name, Attributes attributes) throws Exception {

    FeatureBean fb = null;
    try {
        fb = (FeatureBean) digester.peek();
    } catch (Exception e) {
        throw new IllegalStateException("No parent FeatureBean on object stack");
    }
    String lang = attributes.getValue("lang");
    if (lang == null) {
        lang = attributes.getValue("xml:lang"); // If digester not ns-aware
    }
    if (lang == null) {
        lang = ""; // Avoid NPE errors on sorted map comparisons
    }
    DisplayNameBean dnb = fb.getDisplayName(lang);
    if (dnb == null) {
        if (digester.getLogger().isDebugEnabled()) {
            digester.getLogger().debug("[DisplayNameRule]{" + digester.getMatch() + "} New (" + lang + ")");
        }
        Class clazz = digester.getClassLoader().loadClass(CLASS_NAME);
        dnb = (DisplayNameBean) clazz.newInstance();
        dnb.setLang(lang);
        fb.addDisplayName(dnb);
    } else {
        if (digester.getLogger().isDebugEnabled()) {
            digester.getLogger().debug("[DisplayNameRule]{" + digester.getMatch() + "} Old (" + lang + ")");
        }
    }
    digester.push(dnb);

}

From source file:net.sf.jasperreports.engine.xml.JRAbstractStyleFactory.java

@Override
public Object createObject(Attributes atts) {
    JRDesignStyle style = new JRDesignStyle();

    // get style name
    style.setName(atts.getValue(JRXmlConstants.ATTRIBUTE_name));

    String isDefault = atts.getValue(JRXmlConstants.ATTRIBUTE_isDefault);
    if (isDefault != null && isDefault.length() > 0) {
        style.setDefault(Boolean.valueOf(isDefault));
    }/*w  w w  .ja v  a2  s . c o  m*/

    // get parent style
    if (atts.getValue(JRXmlConstants.ATTRIBUTE_style) != null) {
        setParentStyle(style, atts.getValue(JRXmlConstants.ATTRIBUTE_style));
    }

    // set common style attributes
    setCommonStyle(style, atts);

    return style;
}

From source file:net.sibcolombia.sibsp.model.factory.CallParamNoNSRule.java

@Override
public void begin(Attributes attributes) throws Exception {
    Object param = null;//from w w  w .j a va  2s .c o m
    for (int i = 0; i < attributes.getLength(); i++) {

        // if it has no prefix, or has SOME prefix and ends in the attribute name
        // (___:attributeName)
        if (attributes.getQName(i).equals(attributeName)
                || attributes.getQName(i).endsWith(":" + attributeName)) {
            param = attributes.getValue(i);
            break;
        }
    }
    // add to the params stack
    if (param != null) {
        Object[] parameters = (Object[]) digester.peekParams();
        parameters[paramIndex] = param;
    }
}

From source file:de.weltraumschaf.groundzero.transform.CheckstyleSaxHandler.java

@Override
public void startElement(final String uri, final String name, final String qName, final Attributes atts) {
    recognizeTag(qName);/*from w w  w  .  j av  a 2s. c om*/

    if (isCurrentTag(ReportTags.CHECKSTYLE)) {
        currentReport = new CheckstyleReport(atts.getValue(CheckstyleTagAttribute.VERSION.getName()));
    } else if (isCurrentTag(ReportTags.FILE)) {
        final String fileName = atts.getValue(FileTagAttribute.NAME.getName());
        currentFile = new CheckstyleFile(fileName);
    } else if (isCurrentTag(ReportTags.ERROR)) {
        parseError(atts);
    }
}

From source file:fedora.server.security.servletfilters.xmluserfile.ParserXmlUserfile.java

@Override
public void startElement(String uri, String localName, String qName, Attributes a) throws SAXException {
    if (localName.equals("users")) {
        log.debug("<users> foundUser==" + foundUser);
    } else if (localName.equals("user")) {
        log.debug("<user> foundUser==" + foundUser);
        log.debug(//from ww  w  .  j  a v  a  2s . co  m
                "<<user>> this node username==" + a.getValue("name") + " password==" + a.getValue("password"));
        if (username.equals(a.getValue("name"))) {
            foundUser = true;
            authenticated = Boolean.valueOf(password != null && password.equals(a.getValue("password")));
        }
    } else if (localName.equals("attribute")) {
        log.debug("<attribute> foundUser==" + foundUser);
        if (foundUser) {
            attributeName = a.getValue("name");
            attributeValues = new HashSet();
            log.debug("attributeName==" + attributeName);
        }
    } else if (localName.equals("value")) {
        log.debug("<value> foundUser==" + foundUser);
        inValue = true;
    }
}

From source file:hd3gtv.mydmam.db.BackupDbCassandra.java

public void startElement(String uri, String localName, String qName, Attributes attributes)
        throws SAXException {

    if (qName.equalsIgnoreCase("columnfamily")) {
        String cfname = attributes.getValue("name");

        Log2Dump dump = new Log2Dump();
        dump.add("keyspace", attributes.getValue("keyspace"));
        dump.add("name", cfname);
        dump.addDate("created", Long.parseLong(attributes.getValue("created")));
        Log2.log.info("Start import XML for restore Cassandra Column Family", dump);

        try {/*from w  ww  . jav a 2s . c om*/
            boolean iscfexists = CassandraDb.isColumnFamilyExists(keyspace, cfname);

            if (purgebefore & iscfexists) {
                keyspace.truncateColumnFamily(cfname);
            } else if (iscfexists == false) {
                CassandraDb.createColumnFamilyString(CassandraDb.getDefaultKeyspacename(), cfname, true);
            }
        } catch (ConnectionException e) {
            Log2.log.error("Prepare column family", e, dump);
            return;
        }
        mutator_key_count = 0;
        columnfamily = new ColumnFamily<String, String>(cfname, StringSerializer.get(), StringSerializer.get());

        return;
    }

    if (qName.equalsIgnoreCase("coldef")) {
        try {
            CassandraDb.declareIndexedColumn(keyspace, columnfamily, attributes.getValue("name"),
                    attributes.getValue("indexname"), attributes.getValue("validationclass"));
        } catch (ConnectionException e) {
            throw new SAXException("Can't declare column", e);
        }
        return;
    }

    if (qName.equalsIgnoreCase("key")) {
        key_name = attributes.getValue("name");
        if (mutator == null) {
            try {
                mutator = CassandraDb.prepareMutationBatch();
            } catch (ConnectionException e) {
                throw new SAXException("Can't open access to CassandraDb", e);
            }
        }
        mutator_key_count++;
        return;
    }

    if (qName.equalsIgnoreCase("col")) {
        rawtext = new StringBuffer();
        col_name = attributes.getValue("name");
        col_ttl = Integer.parseInt(attributes.getValue("ttl"));
        return;
    }

    Log2Dump dump = new Log2Dump();
    dump.add("qName", qName);
    Log2.log.error("Unknow start qName", null, dump);
}

From source file:com.textocat.textokit.morph.ruscorpora.RusCorporaXmlContentHandler.java

private void onSpanStart(Attributes attrs) {
    if ("note".equals(attrs.getValue("class"))) {
        // skip content of notes in spoken docs
        skipCurrentElementContent();/*from  www  . ja v a 2  s .co m*/
    } else {
        throw new IllegalStateException(
                String.format("Unknown <span> with attributes %s at %s", attrs, getLocationString()));
    }
}

From source file:FragmentContentHandler.java

@Override
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
    Integer count = elementNameCount.get(qName);
    if (null == count) {
        count = 1;/*from w ww  .ja v a 2 s .  c  o m*/
    } else {
        count++;
    }
    elementNameCount.put(qName, count);
    String childXPath = xPath + "/" + qName + "[" + count + "]";

    int attsLength = atts.getLength();
    for (int x = 0; x < attsLength; x++) {
        System.out.println(childXPath + "[@" + atts.getQName(x) + "='" + atts.getValue(x) + ']');
    }

    FragmentContentHandler child = new FragmentContentHandler(childXPath, xmlReader, this);
    xmlReader.setContentHandler(child);
}

From source file:com.aurel.track.admin.customize.category.filter.tree.io.TreeFilterParser.java

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) {
    if (qName.equalsIgnoreCase(TreeFilterReader.ROOT_NODE)) {
        return;//from ww  w .  j  a v  a 2s  .  c  om
    }
    boolean negate = false;
    String negateString = attributes.getValue("negate");
    if (negateString != null) {
        negate = negateString.equalsIgnoreCase("true");
    }
    if (qName.equalsIgnoreCase(TreeFilterReader.AND_NODE)) {
        currentNode = new QNode();
        currentNode.setType(QNode.AND);
        currentNode.setNegate(negate);
    }
    if (qName.equalsIgnoreCase(TreeFilterReader.OR_NODE)) {
        currentNode = new QNode();
        currentNode.setType(QNode.OR);
        currentNode.setNegate(negate);
    }
    if (qName.equalsIgnoreCase(TreeFilterReader.EXP_NODE)) {
        currentNode = new QNodeExpression();
        currentNode.setType(QNode.EXP);
        String strFieldMoment = attributes.getValue("fieldMoment");
        if (strFieldMoment != null) {
            Integer fieldMoment = null;
            try {
                fieldMoment = Integer.valueOf(strFieldMoment);
                ((QNodeExpression) currentNode).setFieldMoment(fieldMoment);
            } catch (Exception e) {
                LOGGER.info(
                        "Parsing the fieldMoment from " + strFieldMoment + " failed with " + e.getMessage());
                LOGGER.debug(ExceptionUtils.getStackTrace(e));
            }
        }
        String strFieldID = attributes.getValue("fieldId");
        Integer fieldID = null;
        if (strFieldID != null) {
            try {
                fieldID = Integer.valueOf(strFieldID);
            } catch (Exception e) {
                LOGGER.info("Parsing the fieldID from " + strFieldID + " failed with " + e.getMessage());
                LOGGER.debug(ExceptionUtils.getStackTrace(e));
            }
        }
        String strMatcher = attributes.getValue("matcherId");
        Integer matcherID = null;
        if (strMatcher != null && !"".equals(strMatcher)) {
            try {
                matcherID = Integer.valueOf(strMatcher);
            } catch (Exception e) {
                LOGGER.info("Parsing the matcher from " + strMatcher + " failed with " + e.getMessage());
                LOGGER.debug(ExceptionUtils.getStackTrace(e));
            }
        }
        ((QNodeExpression) currentNode).setField(fieldID);
        ((QNodeExpression) currentNode).setMatcherID(matcherID);
        String value = attributes.getValue("value");
        if (!TreeFilterString.isPseudoField(fieldID)) {
            MatcherConverter mc = null;
            if (fieldID.intValue() > 0) {
                IFieldTypeRT fieldTypeRT = FieldTypeManager.getFieldTypeRT(fieldID);
                //It can be that this field is already deleted. 
                //The query containing this field was not deleted because the foreign key 
                //relationship is not direct (just inside the clob).
                if (fieldTypeRT != null) {
                    //real (system or custom) and existing field
                    mc = fieldTypeRT.getMatcherConverter();
                }

            } else {
                mc = FieldExpressionBL.getPseudoFieldMatcherConverter(fieldID);
            }
            if (mc != null) {
                ((QNodeExpression) currentNode).setValue(mc.fromXMLString(value, matcherID));
            } else {
                //the field does not exists any more
                //and mark this with setting the fieldID as null
                //to avoid adding it to the tree (see endElement())
                ((QNodeExpression) currentNode).setField(null);
                return;
            }
        } else {
            //pseudo field
            ((QNodeExpression) currentNode)
                    .setValue(TreeFilterString.getPseudoFieldFromXMLString(fieldID, value, matcherID));
        }
        if (negate) {
            removeNegate((QNodeExpression) currentNode);
        }
    }
    stack.push(currentNode);
    if (root == null) {
        root = currentNode;
    }
}

From source file:com.textocat.textokit.morph.ruscorpora.RusCorporaXmlContentHandler.java

private String requiredAttribute(Attributes attrs, String name) {
    String val = attrs.getValue(name);
    if (val == null) {
        throw new IllegalStateException(
                String.format("Missing attribute '%s' at %s", name, getLocationString()));
    }/*from ww w.  jav  a2 s  .  c o  m*/
    return val;
}