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:Main.java

public static Map<String, String> toMap(Attributes attributes) {
    Map<String, String> nameToValue = new LinkedHashMap<String, String>();
    for (int i = 0; i < attributes.getLength(); i++) {
        nameToValue.put(attributes.getQName(i), attributes.getValue(i));
    }/*w  w  w.  j  a v a 2 s  .  co m*/
    return nameToValue;
}

From source file:Main.java

public static Map<String, String> convertSAXAttributes(Attributes attributes, boolean useQualifiedName) {
    Map<String, String> map = newAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        String key = useQualifiedName ? attributes.getQName(i) : attributes.getLocalName(i);
        String value = attributes.getValue(i);
        map.put(key, value);//from w ww. j a va2s  .c o m
    }
    return map;
}

From source file:Main.java

/**
 * Build a start tag.// w w w  . ja va  2 s.com
 * 
 * @param pTagName
 *            name of the tag.
 * 
 * @param pAtts
 *            the attributes of the tag
 * @return requested tag.
 */
public static String startTag(String pTagName, Attributes pAtts) {
    StringBuilder tag = new StringBuilder();
    tag.append(TAG_START_LOW);
    tag.append(pTagName);
    String name;
    String value;
    for (int i = 0; i < pAtts.getLength(); i++) {
        name = pAtts.getQName(i);
        value = pAtts.getValue(i);
        tag.append(SPACE);
        tag.append(name);
        tag.append(EQUALS);
        tag.append(QUOTE);
        tag.append(value);
        tag.append(QUOTE);
    }
    tag.append(TAG_START_SUP);
    return tag.toString();
}

From source file:Main.java

/**
 * Convert a XML starting tag to a String
 *///from w ww  .ja  v a  2s  .  c o m
static String convertStartTagToString(String p_localName, Attributes p_attrs) {
    StringBuffer output = new StringBuffer(START_TAG_STRING_BUFFER_LENGTH);

    output.append("<");
    output.append(p_localName);

    if (p_attrs != null) {
        int size = p_attrs.getLength();
        for (int i = 0; i < size; i++) {
            output.append(" ");
            output.append(p_attrs.getQName(i));
            output.append("=\"");
            output.append(p_attrs.getValue(i));
            output.append("\"");
        }
    }

    output.append(">");

    return output.toString();
}

From source file:com.microsoft.tfs.core.clients.workitem.internal.form.WIFormParseHandler.java

public static String readStringValue(final Attributes attributes, final String attributeName) {
    for (int i = 0; i < attributes.getLength(); i++) {
        final String name = attributes.getQName(i);
        if (name != null && name.equalsIgnoreCase(attributeName)) {
            return attributes.getValue(i);
        }// w  w  w  .ja v  a 2s. c  o m
    }

    return null;
}

From source file:Main.java

public static String serializeOpenTag(String nsUri, String qname, Map<String, String> nsMappings,
        Attributes attrs, boolean optimizeNs) {
    String result = "<" + qname;
    if (nsUri != null && nsUri.length() > 0) {
        int idx = Math.max(qname.indexOf(':'), 0);
        nsMappings.put(qname.substring(0, idx), nsUri);
    }//ww  w.ja va2  s.c  o  m
    for (int i = 0; i < attrs.getLength(); i++) {
        result += " " + attrs.getQName(i) + "=\"" + attrs.getValue(i) + "\"";
    }
    for (String key : nsMappings.keySet()) {
        if (optimizeNs) {
            boolean found = key.isEmpty() && qname.indexOf(':') == -1
                    || key.length() > 0 && qname.startsWith(key + ":");
            for (int i = 0; i < attrs.getLength(); i++) {
                String aqn = attrs.getQName(i);
                if (aqn.startsWith("xml")) {
                    continue;
                }
                if (key.isEmpty() && aqn.indexOf(':') == -1 || key.length() > 0 && aqn.startsWith(key + ":")) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                continue;
            }
        }

        if (key.isEmpty()) {
            String value = nsMappings.get(key);
            result += " xmlns=\"" + value + "\"";
        } else {
            result += " xmlns:" + key + "=\"" + nsMappings.get(key) + "\"";
        }
    }
    result += ">";
    return result;
}

From source file:no.kantega.commons.util.XMLHelper.java

public static AttributesImpl getAttributesImpl(Attributes attributes) {
    AttributesImpl impl = new AttributesImpl();

    for (int i = 0; i < attributes.getLength(); i++) {
        impl.addAttribute(attributes.getURI(i), attributes.getLocalName(i), attributes.getQName(i),
                attributes.getType(i), attributes.getValue(i));
    }/*ww  w  .j av a  2s  .  c om*/
    return impl;
}

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

@Override
public void begin(String namespace, String name, Attributes attributes) throws Exception {

    for (int i = 0; i < attributes.getLength(); i++) {
        if (ThesaurusHandlingRule.ATTRIBUTE_THESAURUS.equals(attributes.getQName(i))) {
            Vocabulary tv = null;/*  w w w.jav a 2  s  .  co  m*/
            try {
                URI vocabURIObject = new URI(attributes.getValue(i));
                tv = vocabManager.get(vocabURIObject);
            } catch (Exception e) {
                LOG.error("Vocabulary with location " + attributes.getValue(i) + " couldnt get hold of: "
                        + e.getMessage(), e);
            }

            if (tv == null) {
                LOG.warn("No Vocabulary object exists for the URL[" + attributes.getValue(i)
                        + "] so cannot be set");
            } else {
                Object extensionPropertyAsObject = getDigester().peek();
                if (extensionPropertyAsObject instanceof ExtensionProperty) {
                    ExtensionProperty eProperty = (ExtensionProperty) extensionPropertyAsObject;
                    eProperty.setVocabulary(tv);
                    LOG.debug("Vocabulary with URI[" + tv.getUriString() + "] added to extension property");
                }
            }

            break; // since we found the attribute
        }
    }
}

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

@Override
public void begin(Attributes attributes) throws Exception {
    Object param = null;/*from   ww  w.  j  av a2 s . 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:ExampleContentHandler.java

public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
        throws SAXException {
    System.out.print("startElement: " + namespaceURI + ", " + localName + ", " + qName);
    int n = atts.getLength();
    for (int i = 0; i < n; i++) {
        System.out.print(", " + atts.getQName(i));
    }/*  w  ww .j a  v  a2 s . c  o m*/
    System.out.println("");
}