Package org.apache.commons.jelly

Examples of org.apache.commons.jelly.Tag


        }

        // If the dynamic bean is itself a tag, let it execute itself
        if (bean instanceof Tag)
        {
            Tag tag = (Tag) bean;
            tag.setBody(getBody());
            tag.setContext(getContext());
            tag.setParent(getParent());
            ((Tag) bean).doTag(output);
           
            return;
        }
View Full Code Here


    /** Evaluates the body of a tag */
    public void run(JellyContext context, XMLOutput output) throws Exception {
        if ( ! context.isCacheTags() ) {
            clearTag();
        }
        Tag tag = getTag();
        if ( tag == null ) {
            return;
        }
        tag.setContext(context);
       
        // initialize all the properties of the tag before its used
        // if there is a problem abort this tag
        for (int i = 0, size = expressions.length; i < size; i++) {
            Expression expression = expressions[i];
            Method method = methods[i];
            Class type = types[i];
           
            // some types are Expression objects so let the tag
            // evaluate them
            Object value = null;
            if (type.isAssignableFrom(Expression.class) && !type.isAssignableFrom(Object.class)) {
                value = expression;
            }
            else {
                value = expression.evaluate(context);
            }
            // convert value to correct type
            if (value != null) {
                value = convertType(value, type);
            }           
            Object[] arguments = { value };
            try {
                method.invoke(tag, arguments);
            }
            catch (Exception e) {
                String valueTypeName = (value != null ) ? value.getClass().getName() : "null";
                log.warn(
                    "Cannot call method: " + method.getName() + " as I cannot convert: "
                    + value + " of type: " + valueTypeName + " into type: " + type.getName()
                );
                throw createJellyException(
                    "Cannot call method: " + method.getName() + " on tag of type: "
                    + tag.getClass().getName() + " with value: " + value + " of type: "
                    + valueTypeName + ". Exception: " + e, e
                );
            }
        }
       
        try {
            tag.doTag(output);
        }
        catch (JellyException e) {
            handleException(e);
        }
        catch (Exception e) {
View Full Code Here

            startNamespacePrefixes(output);
        } catch (SAXException e) {
            throw new JellyTagException("could not start namespace prefixes",e);
        }

        Tag tag = null;
        try {
            tag = getTag();

            // lets see if we have a dynamic tag
            if (tag instanceof StaticTag) {
                tag = findDynamicTag(context, (StaticTag) tag);
            }

            setTag(tag);
        } catch (JellyException e) {
            throw new JellyTagException(e);
        }

        try {
            if ( tag == null ) {
                return;
            }
            tag.setContext(context);

            DynaTag dynaTag = (DynaTag) tag;

            // ### probably compiling this to 2 arrays might be quicker and smaller
            for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();) {
                Map.Entry entry = (Map.Entry) iter.next();
                String name = (String) entry.getKey();
                Expression expression = (Expression) entry.getValue();

                Object value = null;

                if ( Expression.class.isAssignableFrom( dynaTag.getAttributeType(name) ) ) {
                    value = expression;
                } else {
                    value = expression.evaluate(context);
                }

                dynaTag.setAttribute(name, value);
            }

            tag.doTag(output);
        }
        catch (JellyTagException e) {
            handleException(e);
        }
        catch (RuntimeException e) {
View Full Code Here

     */
    protected Tag findDynamicTag(JellyContext context, StaticTag tag) throws JellyException {
        // lets see if there's a tag library for this URI...
        TagLibrary taglib = context.getTagLibrary( tag.getUri() );
        if ( taglib != null ) {
            Tag newTag = taglib.createTag( tag.getLocalName(), getSaxAttributes() );
            if ( newTag != null ) {
                newTag.setParent( tag.getParent() );
                newTag.setBody( tag.getBody() );
                return newTag;
            }
        }
        return tag;
    }
View Full Code Here

    public void run(JellyContext context, XMLOutput output) throws JellyTagException {
        if ( ! context.isCacheTags() ) {
            clearTag();
        }
        try {
            Tag tag = getTag();
            if ( tag == null ) {
                return;
            }
            tag.setContext(context);

            if ( tag instanceof DynaTag ) {
                DynaTag dynaTag = (DynaTag) tag;

                // ### probably compiling this to 2 arrays might be quicker and smaller
                for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();) {
                    Map.Entry entry = (Map.Entry) iter.next();
                    String name = (String) entry.getKey();
                    Expression expression = (Expression) entry.getValue();

                    Class type = dynaTag.getAttributeType(name);
                    Object value = null;
                    if (type != null && type.isAssignableFrom(Expression.class) && !type.isAssignableFrom(Object.class)) {
                        value = expression;
                    }
                    else {
                        value = expression.evaluateRecurse(context);
                    }
                    dynaTag.setAttribute(name, value);
                }
            }
            else {
                // treat the tag as a bean
                DynaBean dynaBean = new ConvertingWrapDynaBean( tag );
                for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();) {
                    Map.Entry entry = (Map.Entry) iter.next();
                    String name = (String) entry.getKey();
                    Expression expression = (Expression) entry.getValue();

                    DynaProperty property = dynaBean.getDynaClass().getDynaProperty(name);
                    if (property == null) {
                        throw new JellyException("This tag does not understand the '" + name + "' attribute" );
                    }
                    Class type = property.getType();

                    Object value = null;
                    if (type.isAssignableFrom(Expression.class) && !type.isAssignableFrom(Object.class)) {
                        value = expression;
                    }
                    else {
                        value = expression.evaluateRecurse(context);
                    }
                    dynaBean.set(name, value);
                }
            }

            tag.doTag(output);
        }
        catch (JellyTagException e) {
            handleException(e);
        }
        catch (JellyException e) {
View Full Code Here

    /**
     * @return the tag to be evaluated, creating it lazily if required.
     */
    public Tag getTag() throws JellyException {
        Tag tag = (Tag) tagHolder.get();
        if ( tag == null ) {
            tag = createTag();
            if ( tag != null ) {
                tagHolder.set(tag);
            }
View Full Code Here

     */
    protected void configureTag(Tag tag) throws JellyException {
        if (tag instanceof CompilableTag) {
            ((CompilableTag) tag).compile();
        }
        Tag parentTag = null;
        if ( parent != null ) {
            parentTag = parent.getTag();
        }
        tag.setParent( parentTag );
        tag.setBody( tagBody );
View Full Code Here

            startNamespacePrefixes(output);
        } catch (SAXException e) {
            throw new JellyTagException("could not start namespace prefixes",e);
        }

        Tag tag = null;
        try {
            tag = getTag();

            // lets see if we have a dynamic tag
            if (tag instanceof StaticTag) {
                tag = findDynamicTag(context, (StaticTag) tag);
            }

            setTag(tag);
        } catch (JellyException e) {
            throw new JellyTagException(e);
        }

        URL rootURL = context.getRootURL();
        URL currentURL = context.getCurrentURL();
        try {
            if ( tag == null ) {
                return;
            }
            tag.setContext(context);
            setContextURLs(context);

            DynaTag dynaTag = (DynaTag) tag;

            // ### probably compiling this to 2 arrays might be quicker and smaller
            for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();) {
                Map.Entry entry = (Map.Entry) iter.next();
                String name = (String) entry.getKey();
                Expression expression = (Expression) entry.getValue();

                Object value = null;

                if ( Expression.class.isAssignableFrom( dynaTag.getAttributeType(name) ) ) {
                    value = expression;
                } else {
                    value = expression.evaluate(context);
                }

                dynaTag.setAttribute(name, value);
            }

            tag.doTag(output);
        }
        catch (JellyTagException e) {
            handleException(e);
        }
        catch (RuntimeException e) {
View Full Code Here

     */
    protected Tag findDynamicTag(JellyContext context, StaticTag tag) throws JellyException {
        // lets see if there's a tag library for this URI...
        TagLibrary taglib = context.getTagLibrary( tag.getUri() );
        if ( taglib != null ) {
            Tag newTag = taglib.createTag( tag.getLocalName(), getSaxAttributes() );
            if ( newTag != null ) {
                newTag.setParent( tag.getParent() );
                newTag.setBody( tag.getBody() );
                return newTag;
            }
        }
        return tag;
    }
View Full Code Here

        }

        // If the dynamic bean is itself a tag, let it execute itself
        if (bean instanceof Tag)
        {
            Tag tag = (Tag) bean;
            tag.setBody(getBody());
            tag.setContext(getContext());
            tag.setParent(getParent());
            ((Tag) bean).doTag(output);

            return;
        }
View Full Code Here

TOP

Related Classes of org.apache.commons.jelly.Tag

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.