Package org.apache.commons.digester

Examples of org.apache.commons.digester.Rule


public class IncludeTest extends TestCase {

    public static class TestDigesterRuleSource implements DigesterRulesSource {
        public void getRules(Digester digester) {
            digester.addRule("bar",
                new Rule() {
                    public void body(String namespace, String name, String text) {
                        ((ArrayList) this.digester.peek()).add(text);
                    }
                });
        }
View Full Code Here


        // <binding> inside <component>

        pattern = rootElementName + "/component/binding";

        Rule createBindingSpecificationRule = new CreateBindingSpecificationRule();

        digester.addRule(pattern, createBindingSpecificationRule);
        digester.addInitializeProperty(pattern, "type", BindingType.DYNAMIC);
        digester.addSetExtendedProperty(pattern, "expression", "value", true);
        digester.addConnectChild(pattern, "setBinding", "name");

        // <field-binding> inside <component>
        // For compatibility with 1.3 DTD only, removed in 3.0 DTD

        pattern = rootElementName + "/component/field-binding";

        digester.addRule(pattern, createBindingSpecificationRule);
        digester.addInitializeProperty(pattern, "type", BindingType.FIELD);
        digester.addSetExtendedProperty(pattern, "field-name", "value", true);
        digester.addConnectChild(pattern, "setBinding", "name");

        // <inherited-binding> inside <component>

        pattern = rootElementName + "/component/inherited-binding";

        digester.addRule(pattern, createBindingSpecificationRule);
        digester.addInitializeProperty(pattern, "type", BindingType.INHERITED);
        digester.addSetLimitedProperties(pattern, "parameter-name", "value");
        digester.addConnectChild(pattern, "setBinding", "name");

        // <static-binding> inside <component>

        pattern = rootElementName + "/component/static-binding";

        digester.addRule(pattern, createBindingSpecificationRule);
        digester.addInitializeProperty(pattern, "type", BindingType.STATIC);
        digester.addSetExtendedProperty(pattern, "value", "value", true);
        digester.addConnectChild(pattern, "setBinding", "name");

        // <string-binding> inside <component>
        // Maintained just for 1.3 DTD compatibility

        pattern = rootElementName + "/component/string-binding";

        digester.addRule(pattern, createBindingSpecificationRule);
        digester.addInitializeProperty(pattern, "type", BindingType.STRING);
        digester.addSetLimitedProperties(pattern, "key", "value");
        digester.addConnectChild(pattern, "setBinding", "name");

        // Renamed to <message-binding> in the 3.0 DTD

        pattern = rootElementName + "/component/message-binding";

        digester.addRule(pattern, createBindingSpecificationRule);
        digester.addInitializeProperty(pattern, "type", BindingType.STRING);
        digester.addSetLimitedProperties(pattern, "key", "value");
        digester.addConnectChild(pattern, "setBinding", "name");

        // <listener-binding> inside <component>

        pattern = rootElementName + "/component/listener-binding";

        digester.addRule(pattern, new CreateListenerBindingSpecificationRule());
        digester.addSetLimitedProperties(pattern, "language", "language");
        digester.addBody(pattern, "value");
        digester.addConnectChild(pattern, "setBinding", "name");

        // <external-asset>

        pattern = rootElementName + "/external-asset";

        Rule createAssetSpecificationRule = new CreateAssetSpecificationRule();

        digester.addRule(pattern, createAssetSpecificationRule);
        digester.addInitializeProperty(pattern, "type", AssetType.EXTERNAL);
        digester.addValidate(
            pattern,
View Full Code Here

    private static void addParentRule(final String xp,
            final ExtendedBaseRules scxmlRules, final int parent) {
        if (parent < 1) {
            return;
        }
        scxmlRules.add(xp, new Rule() {
            // A generic version of setTopRule
            public void body(final String namespace, final String name,
                    final String text) throws Exception {
                TransitionTarget t = (TransitionTarget) getDigester().peek();
                TransitionTarget p = (TransitionTarget) getDigester().peek(
View Full Code Here

        scxmlRules.add(xp, new SetPropertiesRule(
            new String[] {"event", "cond", "target"},
            new String[] {"event", "cond", "next"}));
        scxmlRules.add(xp + XPF_TAR, new SetPropertiesRule());
        addActionRules(xp, scxmlRules, pr, customActions);
        scxmlRules.add(xp + XPF_EXT, new Rule() {
            public void end(final String namespace, final String name) {
                Transition t = (Transition) getDigester().peek(1);
                State exitState = new State();
                exitState.setIsFinal(true);
                t.setTarget(exitState);
View Full Code Here

        digester.setValidating(true);
        digester.setNamespaceAware(true);
        digester.setEntityResolver(new FacesConfigEntityResolver(externalContext));
        digester.setUseContextClassLoader(true);

        Rule rule = new GlobalRule(digester);
        digester.setRules(new GlobalRulesBase(rule));


        digester.addObjectCreate("faces-config", FacesConfig.class);       
        digester.addObjectCreate("faces-config/application", Application.class);
View Full Code Here

                        ElementDescriptor[] desc = currentDescriptor.getElementDescriptors();
                        if (desc.length == 1) {
                            path = "*/"+desc[0].getQualifiedName();
                        }
                    }
                    Rule rule = new BeanCreateRule( childDescriptor, context, path, matchIDs);
                    addRule(path, rule);
                    continue;
                }
                if ( childDescriptor.getUpdater() != null ) {
                    if (log.isTraceEnabled()) {
                        log.trace("Element has updater "
                         + ((MethodUpdater) childDescriptor.getUpdater()).getMethod().getName());
                    }
                    if ( childDescriptor.isPrimitiveType() ) {
                        addPrimitiveTypeRule(path, childDescriptor);
                       
                    } else {
                        // add the first child to the path
                        ElementDescriptor[] grandChildren = childDescriptor.getElementDescriptors();
                        if ( grandChildren != null && grandChildren.length > 0 ) {
                            ElementDescriptor grandChild = grandChildren[0];
                            String grandChildQName = grandChild.getQualifiedName();
                            if ( grandChildQName != null && grandChildQName.length() > 0 ) {
                                if (childDescriptor.isWrapCollectionsInElement()) {
                                    path += '/' + grandChildQName;
                                   
                                } else {
                                    path = prefix + (prefix.endsWith("/")?"":"/") + grandChildQName;
                                }
                            }
                        }
                       
                        // maybe we are adding a primitve type to a collection/array
                        Class beanClass = childDescriptor.getSingularPropertyType();
                        if ( XMLIntrospectorHelper.isPrimitiveType( beanClass ) ) {
                            addPrimitiveTypeRule(path, childDescriptor);
                           
                        } else {
                            Rule rule = new BeanCreateRule(
                                                        childDescriptor,
                                                        context,
                                                        path + '/',
                                                        matchIDs );
                            addRule( path, rule );
View Full Code Here

     *
     * @param path digester path where this rule will be attached
     * @param childDescriptor update this <code>ElementDescriptor</code> with the body text
     */
    protected void addPrimitiveTypeRule(String path, final ElementDescriptor childDescriptor) {
        Rule rule = new Rule() {
            public void body(String text) throws Exception {
                childDescriptor.getUpdater().update( context, text );
            }       
        };
        addRule( path, rule );
View Full Code Here

     * working.
     */
    private void addOldArgRules(Digester digester) {

        // Create a new rule to process args elements
        Rule rule = new Rule() {
            public void begin(String namespace, String name,
                               Attributes attributes) throws Exception {
                // Create the Arg
                Arg arg = new Arg();
                arg.setKey(attributes.getValue("key"));
View Full Code Here

        // <binding> inside <component>

        pattern = rootElementName + "/component/binding";

        Rule createBindingSpecificationRule = new CreateBindingSpecificationRule();

        digester.addRule(pattern, createBindingSpecificationRule);
        digester.addInitializeProperty(pattern, "type", BindingType.DYNAMIC);
        digester.addSetExtendedProperty(pattern, "expression", "value", true);
        digester.addConnectChild(pattern, "setBinding", "name");

        // <field-binding> inside <component>
        // For compatibility with 1.3 DTD only, removed in 3.0 DTD

        pattern = rootElementName + "/component/field-binding";

        digester.addRule(pattern, createBindingSpecificationRule);
        digester.addInitializeProperty(pattern, "type", BindingType.FIELD);
        digester.addSetExtendedProperty(pattern, "field-name", "value", true);
        digester.addConnectChild(pattern, "setBinding", "name");

        // <inherited-binding> inside <component>

        pattern = rootElementName + "/component/inherited-binding";

        digester.addRule(pattern, createBindingSpecificationRule);
        digester.addInitializeProperty(pattern, "type", BindingType.INHERITED);
        digester.addSetLimitedProperties(pattern, "parameter-name", "value");
        digester.addConnectChild(pattern, "setBinding", "name");

        // <static-binding> inside <component>

        pattern = rootElementName + "/component/static-binding";

        digester.addRule(pattern, createBindingSpecificationRule);
        digester.addInitializeProperty(pattern, "type", BindingType.STATIC);
        digester.addSetExtendedProperty(pattern, "value", "value", true);
        digester.addConnectChild(pattern, "setBinding", "name");

        // <string-binding> inside <component>
        // Maintained just for 1.3 DTD compatibility

        pattern = rootElementName + "/component/string-binding";

        digester.addRule(pattern, createBindingSpecificationRule);
        digester.addInitializeProperty(pattern, "type", BindingType.STRING);
        digester.addSetLimitedProperties(pattern, "key", "value");
        digester.addConnectChild(pattern, "setBinding", "name");
       
        // Renamed to <message-binding> in the 3.0 DTD
       
    pattern = rootElementName + "/component/message-binding";

    digester.addRule(pattern, createBindingSpecificationRule);
    digester.addInitializeProperty(pattern, "type", BindingType.STRING);
    digester.addSetLimitedProperties(pattern, "key", "value");
    digester.addConnectChild(pattern, "setBinding", "name");       

        // <listener-binding> inside <component>

        pattern = rootElementName + "/component/listener-binding";

        digester.addRule(pattern, new CreateListenerBindingSpecificationRule());
        digester.addSetLimitedProperties(pattern, "language", "language");
        digester.addBody(pattern, "value");
        digester.addConnectChild(pattern, "setBinding", "name");

        // <external-asset>

        pattern = rootElementName + "/external-asset";

        Rule createAssetSpecificationRule = new CreateAssetSpecificationRule();

        digester.addRule(pattern, createAssetSpecificationRule);
        digester.addInitializeProperty(pattern, "type", AssetType.EXTERNAL);
        digester.addValidate(
            pattern,
View Full Code Here

        if (currTextSegment.length() > 0) {
            String segment = currTextSegment.toString();
            List parentMatches = (List) matches.peek();
            int len = parentMatches.size();
            for(int i=0; i<len; ++i) {
                Rule r = (Rule) parentMatches.get(i);
                if (r instanceof TextSegmentHandler) {
                    TextSegmentHandler h = (TextSegmentHandler) r;
                    try {
                        h.textSegment(segment);
                    } catch(Exception e) {
View Full Code Here

TOP

Related Classes of org.apache.commons.digester.Rule

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.