public void doTag()

in jelly-tags/xml/src/main/java/org/apache/commons/jelly/tags/xml/CopyOfTag.java [50:92]


    public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException {
        Object xpathContext = getXPathContext();

        if (select == null) {
            throw new MissingAttributeException( "select" );
        }

        SAXWriter saxWriter;

        if (lexical) {
            saxWriter = new SAXWriter(output, output);
        } else {
            saxWriter = new SAXWriter(output);
        }

        Object obj;
        try {
            obj = select.evaluate(xpathContext);
        } catch (JaxenException e) {
            throw new JellyTagException("Failed to evaluate XPath expression", e);
        }

        try {
            if (obj instanceof List) {
                List nodes = (List) obj;
                for (Iterator iter = nodes.iterator(); iter.hasNext(); ) {
                    Object object = iter.next();
                    if ( object instanceof Node ) {
                        saxWriter.write( (Node) object );
                    }
                    else if (object != null ) {
                        saxWriter.write( object.toString() );
                    }
                }
            } else if (obj instanceof Node) {
                saxWriter.write( (Node) obj );
            } else {
                saxWriter.write( obj.toString() );
            }
        } catch (SAXException e) {
            throw new JellyTagException("Failed to write XML output.", e);
        }
    }