Java Code Examples for org.xml.sax.helpers.AttributesImpl#getValue()

The following examples show how to use org.xml.sax.helpers.AttributesImpl#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Digester.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * 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.
 */
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 {
            newAttrs.setValue(i, IntrospectionUtils.replaceProperties(value, null, source, getClassLoader()).intern());
        } catch (Exception e) {
            log.warn(sm.getString("digester.failedToUpdateAttributes", newAttrs.getLocalName(i), value), e);
        }
    }

    return newAttrs;
}
 
Example 2
Source File: Digester.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * 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.
 */
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;

}
 
Example 3
Source File: Digester.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * 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.
 */
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;

}
 
Example 4
Source File: EmbeddingHTMLParsingReader.java    From extract with MIT License 4 votes vote down vote up
@Override
public void startElement(final String uri, final String localName, final String qName, final Attributes atts)
		throws SAXException {
	final AttributesImpl attributes = new AttributesImpl(atts);

	if (IMG_TAG.equalsIgnoreCase(localName) && XHTML.equals(uri) && !isEmbeddedImgTagOpen &&
			!isEmbeddedAnchorTagOpen) {

		final String src = attributes.getValue("", "src");

		if (null != src && src.startsWith("embedded:")) {
			isEmbeddedImgTagOpen = true;
			imgAttributes = attributes;

		} else if (null != src && src.startsWith("cid:")) {
			super.startElement(uri, localName, qName, atts);
		}

	} else if (ANCHOR_TAG.equalsIgnoreCase(localName) && XHTML.equals(uri) && !isEmbeddedAnchorTagOpen) {

		final String href = attributes.getValue("", "href");
		String path = null;

		if (null != href && href.startsWith(open) && href.endsWith(close)) {
			path = href.substring(open.length(), href.length() - close.length());
		}

		if (null != path && null != parent.getEmbed(path)) {
			isEmbeddedAnchorTagOpen = true;

			// Drop the anchor tag if coming after an embedded image.
			if (isEmbeddedImgTagOpen) {
				imgAttributes.setAttribute(imgAttributes.getIndex("", "src"), "", "src", "src",
						"CDATA", href);
				super.startElement(uri, IMG_TAG, IMG_TAG, imgAttributes);
				super.endElement(uri, IMG_TAG, IMG_TAG);
				isEmbeddedImgTagOpen = false;
				imgAttributes = null;
				anchorTagDropped = true;
			} else {
				super.startElement(uri, localName, qName, attributes);
				anchorTagDropped = false;
			}
		} else if (isEmbeddedImgTagOpen) {
			isEmbeddedImgTagOpen = false;
			imgAttributes = null;
			super.startElement(uri, localName, qName, attributes);
		}
	} else {
		if (isEmbeddedAnchorTagOpen) {
			isEmbeddedAnchorTagOpen = false;
			anchorTagDropped = false;
		}

		if (isEmbeddedImgTagOpen) {
			isEmbeddedImgTagOpen = false;
			imgAttributes = null;
		}

		super.startElement(uri, localName, qName, attributes);
	}
}