Example usage for org.xml.sax.helpers AttributesImpl getIndex

List of usage examples for org.xml.sax.helpers AttributesImpl getIndex

Introduction

In this page you can find the example usage for org.xml.sax.helpers AttributesImpl getIndex.

Prototype

public int getIndex(String qName) 

Source Link

Document

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

Usage

From source file:org.apache.cocoon.transformation.SimpleFormTransformer.java

/**
 * Start processing a form element. Sets protection indicator if attribute
 * "fixed" is present and either "true" or "yes". Removes attribute "fixed"
 * if present.//from  w  ww .  j  av  a  2 s  .  com
 * @param uri The namespace of the element.
 * @param name The local name of the element.
 * @param raw The qualified name of the element.
 * @param attr The attributes of the element.
 */
protected void startFormElement(String uri, String name, String raw, Attributes attr) throws SAXException {

    String fixed = attr.getValue(this.fixedName);
    if (this.useFormName) {
        this.formName = attr.getValue("name");
    }
    if (fixed == null) {
        this.relayStartElement(uri, name, raw, attr);
    } else {
        if (!this.fixed && BooleanUtils.toBoolean(fixed)) {
            this.fixed = true;
        }
        // remove attributes not meant for client
        AttributesImpl attributes = null;
        if (attr instanceof AttributesImpl) {
            attributes = (AttributesImpl) attr;
        } else {
            attributes = new AttributesImpl(attr);
        }
        attributes.removeAttribute(attributes.getIndex(this.fixedName));
        this.relayStartElement(uri, name, raw, this.normalizeAttributes(attributes));
    }
}

From source file:org.apache.cocoon.transformation.SimpleFormTransformer.java

/**
 * Remove extra information from element's attributes. Currently only removes
 * the repeater variable from the element's name attribute if present.
 *
 * @param attr/*from ww w . j  a va  2s.  c  o  m*/
 * @return modified attributes
 */
private Attributes normalizeAttributes(Attributes attr) {
    Attributes result = attr;
    if (this.stripNumber && this.repeater.size() > 0) {
        String name = attr.getValue("name");
        if (name != null) {
            for (Iterator i = this.repeater.iterator(); i.hasNext();) {
                RepeaterStatus status = (RepeaterStatus) i.next();
                int pos = name.indexOf(status.var);
                if (pos >= 0) {
                    AttributesImpl attributes;
                    if (result instanceof AttributesImpl) {
                        attributes = (AttributesImpl) result;
                    } else {
                        attributes = new AttributesImpl(result);
                    }
                    name = name.substring(0, pos - this.decorationSize)
                            + name.substring(pos + status.var.length() + this.decorationSize);
                    attributes.setValue(attributes.getIndex("name"), name);
                    result = attributes;
                }
            }
        }
    }
    return result;
}

From source file:org.apache.cocoon.woody.transformation.EffectWidgetReplacingPipe.java

private Attributes translateAttributes(Attributes attributes, String[] names) {
    AttributesImpl newAtts = new AttributesImpl(attributes);
    if (names != null) {
        for (int i = 0; i < names.length; i++) {
            String name = names[i];
            int position = newAtts.getIndex(name);
            String newValue = pipeContext.translateText(newAtts.getValue(position));
            newAtts.setValue(position, newValue);
        }/* w ww  .ja v a 2s  .c  o m*/
    }
    return newAtts;
}

From source file:org.apache.tika.parser.pdf.AbstractPDF2XHTML.java

private void processDoc(String name, PDFileSpecification spec, AttributesImpl attributes)
        throws TikaException, SAXException, IOException {
    if (spec instanceof PDSimpleFileSpecification) {
        attributes.addAttribute("", "class", "class", "CDATA", "linked");
        attributes.addAttribute("", "id", "id", "CDATA", spec.getFile());
        xhtml.startElement("div", attributes);
        xhtml.endElement("div");
    } else if (spec instanceof PDComplexFileSpecification) {
        if (attributes.getIndex("source") < 0) {
            attributes.addAttribute("", "source", "source", "CDATA", "attachment");
        }/*  ww  w  . j  a  v  a  2s  . co m*/
        extractMultiOSPDEmbeddedFiles(name, (PDComplexFileSpecification) spec, attributes);
    }
}

From source file:org.dita.dost.util.XMLUtils.java

/**
 * Add or set attribute.//from   ww  w  .j  a  va2 s  .c  om
 * 
 * @param atts attributes
 * @param uri namespace URI
 * @param localName local name
 * @param qName qualified name
 * @param type attribute type
 * @param value attribute value
 */
public static void addOrSetAttribute(final AttributesImpl atts, final String uri, final String localName,
        final String qName, final String type, final String value) {
    final int i = atts.getIndex(qName);
    if (i != -1) {
        atts.setAttribute(i, uri, localName, qName, type, value);
    } else {
        atts.addAttribute(uri, localName, qName, type, value);
    }
}

From source file:org.dita.dost.util.XMLUtils.java

/**
 * Remove an attribute from the list. Do nothing if attribute does not exist.
 * //from  w  w  w .  j  av  a2s. co m
 * @param atts attributes
 * @param qName QName of the attribute to remove
 */
public static void removeAttribute(final AttributesImpl atts, final String qName) {
    final int i = atts.getIndex(qName);
    if (i != -1) {
        atts.removeAttribute(i);
    }
}

From source file:org.tizzit.util.xml.SAXHelper.java

/**
 * Sets an attribute of an SAX AttributesImpl to a specific value (namespace supported).<br/>
 * If it exists, the value will be overwritten.
 *
 * @param attr The AttributesImpl/*from www .j av a 2 s .  co m*/
 * @param namespaceUri
 * @param attrName The name
 * @param attrValue The (new) value
 * @since tizzit-common 15.10.2009
 */
public static void setSAXAttr(AttributesImpl attr, String namespaceUri, String attrName, String attrValue) {
    if (attrName != null) {
        int idx = attr.getIndex(attrName);
        String saveVal = (attrValue == null) ? "" : attrValue;
        if (idx >= 0) {
            String dd = attr.getType(attrName);
            attr.setAttribute(idx, namespaceUri, attrName, attrName, dd, saveVal);
        } else {
            attr.addAttribute(namespaceUri, attrName, attrName, "CDATA", saveVal);
        }
    }
}