FileDocCategorySizeDatePackage
StringAdapter.javaAPI DocExample4301Mon Jul 23 13:26:44 BST 2007org.apache.struts2.views.xslt

StringAdapter

public class StringAdapter extends AbstractAdapterElement
StringAdapter adapts a Java String value to a DOM Element with the specified property name containing the String's text. e.g. a property
String getFoo() { return "My Text!"; }
will appear in the result DOM as: MyText! Subclasses may override the getStringValue() method in order to use StringAdapter as a simplified custom XML adapter for Java types. A subclass can enable XML parsing of the value string via the setParseStringAsXML() method and then override getStringValue() to return a String containing the custom formatted XML.

(Omit source code)

Fields Summary
private Log
log
boolean
parseStringAsXML
Constructors Summary
public StringAdapter()


      
    
public StringAdapter(AdapterFactory adapterFactory, AdapterNode parent, String propertyName, String value)

        setContext(adapterFactory, parent, propertyName, value);
    
Methods Summary
protected java.util.ListbuildChildAdapters()

        Node node;
        if (getParseStringAsXML()) {
            log.debug("parsing string as xml: " + getStringValue());
            // Parse the String to a DOM, then proxy that as our child
            node = DomHelper.parse(new InputSource(new StringReader(getStringValue())));
            node = getAdapterFactory().proxyNode(this, node);
        } else {
            log.debug("using string as is: " + getStringValue());
            // Create a Text node as our child
            node = new SimpleTextNode(getAdapterFactory(), this, "text", getStringValue());
        }

        List<Node> children = new ArrayList<Node>();
        children.add(node);
        return children;
    
public booleangetParseStringAsXML()
Is this StringAdapter to interpret its string values as containing XML Text?

see
#setParseStringAsXML(boolean)

        return parseStringAsXML;
    
protected java.lang.StringgetStringValue()
Get the object to be adapted as a String value.

This method can be overridden by subclasses that wish to use StringAdapter as a simplified customizable XML adapter for Java types. A subclass can enable parsing of the value string as containing XML text via the setParseStringAsXML() method and then override getStringValue() to return a String containing the custom formatted XML.

        return getPropertyValue().toString();
    
public voidsetParseStringAsXML(boolean parseStringAsXML)
When set to true the StringAdapter will interpret its String value as containing XML text and parse it to a DOM Element. The new DOM Element will be a child of this String element. (i.e. wrapped in an element of the property name specified for this StringAdapter).

param
parseStringAsXML
see
#getParseStringAsXML()

        this.parseStringAsXML = parseStringAsXML;