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

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

Introduction

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

Prototype

public void setValue(int index, String value) 

Source Link

Document

Set the value of a specific attribute.

Usage

From source file:com.adobe.acs.commons.rewriter.impl.ResourceResolverMapTransformerFactory.java

protected Attributes rebuildAttributes(final SlingHttpServletRequest slingRequest, final String elementName,
        final Attributes attrs) {
    if (slingRequest == null || !attributes.containsKey(elementName)) {
        // element is not defined as a candidate to rewrite
        return attrs;
    }/* ww w .j  av a2  s. co  m*/
    final String[] modifiableAttributes = attributes.get(elementName);

    // clone the attributes
    final AttributesImpl newAttrs = new AttributesImpl(attrs);
    final int len = newAttrs.getLength();

    for (int i = 0; i < len; i++) {
        final String attrName = newAttrs.getLocalName(i);
        if (ArrayUtils.contains(modifiableAttributes, attrName)) {
            final String attrValue = newAttrs.getValue(i);
            if (StringUtils.startsWith(attrValue, "/") && !StringUtils.startsWith(attrValue, "//")) {
                // Only map absolute paths (starting w /), avoid relative-scheme URLs starting w //
                newAttrs.setValue(i, slingRequest.getResourceResolver().map(slingRequest, attrValue));
            }
        }
    }
    return newAttrs;
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLInputElement.java

/**
 * Sets the value of the attribute {@code type}.
 * Note: this replace the DOM node with a new one.
 * @param newType the new type to set/*from  w  ww . j  ava  2s. com*/
 */
@JsxSetter
public void setType(String newType) {
    HtmlInput input = getDomNodeOrDie();

    final String currentType = input.getAttribute("type");

    if (!currentType.equalsIgnoreCase(newType)) {
        if (newType != null && getBrowserVersion().hasFeature(JS_INPUT_SET_TYPE_LOWERCASE)) {
            newType = newType.toLowerCase(Locale.ROOT);
        }
        final AttributesImpl attributes = readAttributes(input);
        final int index = attributes.getIndex("type");
        if (index > -1) {
            attributes.setValue(index, newType);
        } else {
            attributes.addAttribute(null, "type", "type", null, newType);
        }

        // create a new one only if we have a new type
        if (ATTRIBUTE_NOT_DEFINED != currentType || !"text".equalsIgnoreCase(newType)) {
            final HtmlInput newInput = (HtmlInput) InputElementFactory.instance.createElement(input.getPage(),
                    "input", attributes);

            if (input.wasCreatedByJavascript()) {
                newInput.markAsCreatedByJavascript();
            }

            if (input.getParentNode() == null) {
                // the input hasn't yet been inserted into the DOM tree (likely has been
                // created via document.createElement()), so simply replace it with the
                // new Input instance created in the code above
                input = newInput;
            } else {
                input.getParentNode().replaceChild(newInput, input);
            }

            input.setScriptableObject(null);
            setDomNode(newInput, true);
        } else {
            super.setAttribute("type", newType);
        }
    }
}

From source file:com.adobe.acs.commons.rewriter.impl.StaticReferenceRewriteTransformerFactory.java

@SuppressWarnings("squid:S3776")
private Attributes rebuildAttributes(String elementName, Attributes attrs, String[] modifyableAttributes) {
    // clone the attributes
    final AttributesImpl newAttrs = new AttributesImpl(attrs);

    for (int i = 0; i < newAttrs.getLength(); i++) {
        final String attrName = newAttrs.getLocalName(i);
        if (ArrayUtils.contains(modifyableAttributes, attrName)) {
            final String attrValue = newAttrs.getValue(i);

            String key = elementName + ":" + attrName;
            if (matchingPatterns.containsKey(key)) {
                // Find value based on matching pattern
                Pattern matchingPattern = matchingPatterns.get(key);
                try {
                    newAttrs.setValue(i, handleMatchingPatternAttribute(matchingPattern, attrValue));
                } catch (Exception e) {
                    log.error("Could not perform replacement based on matching pattern", e);
                }//w w w  . ja va2 s.c  om
            } else {
                for (String prefix : prefixes) {
                    if (attrValue.startsWith(prefix)) {
                        newAttrs.setValue(i, prependHostName(attrValue));
                    }
                }
            }
        }
    }

    return newAttrs;
}

From source file:com.adobe.acs.commons.rewriter.impl.VersionedClientlibsTransformerFactory.java

private Attributes rebuildAttributes(final AttributesImpl newAttributes, final int index, final String path,
        final LibraryType libraryType, final SlingHttpServletRequest request) {
    final String contextPath = request.getContextPath();
    String libraryPath = path;//  ww w  .  jav  a  2s .c  o  m
    if (StringUtils.isNotBlank(contextPath)) {
        libraryPath = path.substring(contextPath.length());
    }

    String versionedPath = this.getVersionedPath(libraryPath, libraryType, request.getResourceResolver());

    if (StringUtils.isNotBlank(versionedPath)) {
        if (StringUtils.isNotBlank(contextPath)) {
            versionedPath = contextPath + versionedPath;
        }
        log.debug("Rewriting to: {}", versionedPath);
        newAttributes.setValue(index, versionedPath);
    } else {
        log.debug("Versioned Path could not be created properly");
    }

    return newAttributes;
}

From source file:nonjsp.application.XmlXulRuleSet.java

/**
 * This method is invoked when the beginning of the matched
 * Xml element is encountered ;/*from  www .j  av  a  2s  .  c o m*/
 *
 * @param attributes The element's attribute list
 */
public void begin(Attributes attributes) throws Exception {
    UIComponent uic = (UIComponent) digester.peek();
    if (log.isTraceEnabled()) {
        log.trace("component: " + uic.getId());
    }
    AttributesImpl attrs = new AttributesImpl(attributes);
    for (int i = 0; i < attrs.getLength(); i++) {
        String qName = attributes.getQName(i);
        attrs.setLocalName(i, qName);
        attrs.setValue(i, attributes.getValue(qName));
        if (log.isTraceEnabled()) {
            log.trace("ComponentRule: qName: " + qName + " value: " + attributes.getValue(qName));
        }
    }
    bc.applyAttributesToComponentInstance(uic, attrs);

    if (root == null) {
        root = (UIComponent) digester.peek(digester.getCount() - 1);
    }
    root.getChildren().add(uic);

    //If component is a form, make it the root so that children will be
    //added to it
    if (uic instanceof UIForm) {
        root = uic;
    }
}

From source file:nonjsp.application.XmlXulRuleSet.java

/**
 * This method is invoked when the beginning of the matched
 * Xml element is encountered (in this case "property");
 *
 * @param attributes The element's attribute list
 *///from  w w w.ja  v a  2s . c  om
public void begin(Attributes attributes) throws Exception {
    UIComponent uic = (UIComponent) digester.peek();
    AttributesImpl attrs = new AttributesImpl(attributes);
    for (int i = 0; i < attrs.getLength(); i++) {
        String qName = attributes.getQName(i);
        attrs.setLocalName(i, qName);
        attrs.setValue(i, attributes.getValue(qName));
    }
    bc.handleNestedComponentTag(uic, "SelectOne_Option", attrs);
}

From source file:org.apache.axis.message.MessageElement.java

/**
 * Set an attribute, adding the attribute if it isn't already present
 * in this element, and changing the value if it is.  Passing null as the
 * value will cause any pre-existing attribute by this name to go away.
 *///from   w  ww . j av  a 2 s  .c  om
public void setAttribute(String namespace, String localName, String value) {
    AttributesImpl attributes = makeAttributesEditable();

    int idx = attributes.getIndex(namespace, localName);
    if (idx > -1) {
        // Got it, so replace it's value.
        if (value != null) {
            attributes.setValue(idx, value);
        } else {
            attributes.removeAttribute(idx);
        }
        return;
    }

    addAttribute(namespace, localName, value);
}

From source file:org.apache.catalina.util.CatalinaDigester.java

/**
 * Returns an attributes list which contains all the attributes
 * passed in, with any text of form "${xxx}" in an attribute value
 * replaced by the appropriate value from the system property.
 *//*w w  w . j a v a  2s  . co  m*/
private Attributes updateAttributes(Attributes list) {

    if (list.getLength() == 0) {
        return list;
    }

    AttributesImpl newAttrs = new AttributesImpl(list);
    int nAttributes = newAttrs.getLength();
    for (int i = 0; i < nAttributes; ++i) {
        String value = newAttrs.getValue(i);
        try {
            String newValue = IntrospectionUtils.replaceProperties(value, null, source);
            if (value != newValue) {
                newAttrs.setValue(i, newValue);
            }
        } catch (Exception e) {
            // ignore - let the attribute have its original value
        }
    }

    return newAttrs;

}

From source file:org.apache.cocoon.forms.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));
            if (position > -1)
                newAtts.setValue(position, newValue);
            else// w  w  w .  j  av  a  2 s  . co m
                throw new RuntimeException("Attribute \"" + name + "\" not present!");
        }
    }
    return newAtts;
}

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

/**
 * Handle input elements that may don't have a "checked"
 * attributes, e.g. text, password, button.
 *///  w  w  w  .ja v a2s . com
protected void startNonCheckableElement(String aName, String uri, String name, String raw,
        AttributesImpl attributes) throws SAXException {

    // @fixed and this.fixed already considered in startInputElement
    Object fValue = this.getNextValue(aName);
    String value = attributes.getValue("value");
    if (getLogger().isDebugEnabled())
        getLogger()
                .debug("startNonCheckableElement " + name + " attributes " + this.printAttributes(attributes));
    if (fValue != null) {
        if (getLogger().isDebugEnabled())
            getLogger().debug("replacing");
        if (value != null) {
            attributes.setValue(attributes.getIndex("value"), String.valueOf(fValue));
        } else {
            attributes.addAttribute("", "value", "value", "CDATA", String.valueOf(fValue));
        }
    }
    this.relayStartElement(uri, name, raw, attributes);
}