Package org.apache.cocoon.forms

Examples of org.apache.cocoon.forms.FormsException


            for (int i = 0; i < list.getLength(); i++) {
                if (list.item(i).getNodeType() == Node.ELEMENT_NODE) {
                    Element listenerElement = (Element)list.item(i);
                    WidgetListenerBuilder builder = (WidgetListenerBuilder) widgetListenerBuilders.get(listenerElement.getLocalName());
                    if (builder == null) {
                        throw new FormsException("Unknown kind of eventlistener '" + listenerElement.getLocalName() + "'.",
                                                 DomHelper.getLocationObject(listenerElement));
                    }
                    WidgetListener listener = builder.buildListener(listenerElement, listenerClass);
                    if (result == null) {
                        result = new ArrayList();
View Full Code Here


                if (list.item(i).getNodeType() == Node.ELEMENT_NODE) {
                    Element element = (Element)list.item(i);
                    String name = element.getLocalName();
                    WidgetValidatorBuilder builder = (WidgetValidatorBuilder)this.widgetValidatorBuilders.get(name);
                    if (builder == null) {
                        throw new FormsException("Unknown kind of validator '" + name + "'.",
                                                 DomHelper.getLocationObject(element));
                    }

                    widgetDefinition.addValidator(builder.build(element, widgetDefinition));
                }
View Full Code Here

     */
    public void initializeFrom(WidgetDefinition definition) throws Exception {
        super.initializeFrom(definition);

        if (!(definition instanceof AbstractContainerDefinition)) {
            throw new FormsException("Parent definition " + definition.getClass().getName() + " is not an AbstractContainerDefinition.",
                                     getLocation());
        }

        AbstractContainerDefinition other = (AbstractContainerDefinition) definition;

View Full Code Here

    public void addWidgetDefinition(WidgetDefinition definition) throws Exception, DuplicateIdException {
        // Check that no child is named "submit" if this form has no id. This causes some weird behaviour
        // in HTML as it collides with the submit() function on the <form> element...
        if ("submit".equals(definition.getId()) && StringUtils.isEmpty(this.getId())) {
            throw new FormsException("Top-level widgets should not be named 'submit' to avoid problems " +
                                     "with HTML <form> elements.", definition.getLocation());
        }

        super.addWidgetDefinition(definition);
    }
View Full Code Here

     * Imports a new library
     */
    public WidgetDefinition buildWidgetDefinition(Element widgetElement, WidgetDefinitionBuilderContext context)
    throws Exception {
        if (context.getLocalLibrary() == null) {
            throw new FormsException("Import statement seen and context is empty.",
                                     DomHelper.getLocationObject(widgetElement));
        }

        Library lib = context.getLocalLibrary();
        String prefix = DomHelper.getAttribute(widgetElement, PREFIX_ATTRIBUTE);
        String uri = DomHelper.getAttribute(widgetElement, URI_ATTRIBUTE);

        if (!lib.includeAs(prefix, uri)) {
            throw new FormsException("Import statement did not succeed (probably used ':' in the prefix?).",
                                     DomHelper.getLocationObject(widgetElement));
        }

        return null;
    }
View Full Code Here

     */
    public void initializeFrom(WidgetDefinition definition) throws Exception {
        super.initializeFrom(definition);

        if (!(definition instanceof AbstractDatatypeWidgetDefinition)) {
            throw new FormsException("Ancestor definition " + definition.getClass().getName() + " is not an AbstractDatatypeWidgetDefinition.",
                                     getLocation());
        }

        AbstractDatatypeWidgetDefinition other = (AbstractDatatypeWidgetDefinition) definition;

View Full Code Here

                    break;
                }
                if (widgetDefinition == containerDefinition) {
                    Location location = containerDefinition.getLocation();
                    if (parent instanceof FormDefinition) {
                        throw new FormsException("Container: Non-terminating recursion detected in form definition.",
                                                 location);
                    }

                    throw new FormsException("Container: Non-terminating recursion detected in widget definition: " + parent.getId(),
                                             location);
                }
            }
        }
    }
View Full Code Here

                                        DomHelper.getLocation(widgetElement));
            }
        }

        if (actionCommand == null) {
            throw new FormsException("Required attribute 'command' is missing.",
                                     DomHelper.getLocationObject(widgetElement));
        }


        RepeaterActionDefinition definition = createDefinition(widgetElement, actionCommand);
        super.setupDefinition(widgetElement, definition);
        setDisplayData(widgetElement, definition);

        definition.setActionCommand(actionCommand);

        // Warn of the mis-named 'on-action' that existed initially
        Element buggyOnActivate = DomHelper.getChildElement(widgetElement, FormsConstants.DEFINITION_NS, "on-activate", false);
        if (buggyOnActivate != null) {
            throw new FormsException("Use 'on-action' instead of 'on-activate' on row-action.",
                                     DomHelper.getLocationObject(buggyOnActivate));
        }

        Iterator i = buildEventListeners(widgetElement, "on-action", ActionListener.class).iterator();
        while (i.hasNext()) {
View Full Code Here

       
        } else if ("page-custom".equals(actionCommand)) {
            return new RepeaterActionDefinition.ChangePageActionDefinition(repeater, RepeaterActionDefinition.ChangePageActionDefinition.CUSTOM);

        } else {
            throw new FormsException("Unknown repeater action '" + actionCommand + "'.",
                                     DomHelper.getLocationObject(element));
        }
    }
View Full Code Here

            Perl5Compiler compiler = new Perl5Compiler();
            Pattern pattern;
            try {
                pattern = compiler.compile(patternString, Perl5Compiler.READ_ONLY_MASK);
            } catch (MalformedPatternException e) {
                throw new FormsException("Invalid regular expression '" + patternString + "'.",
                                         e, DomHelper.getLocationObject(splitElement));
            }
            definition.setSplitPattern(pattern, patternString);
        }

        // read split mappings
        Element[] mapElements = DomHelper.getChildElements(splitElement, FormsConstants.DEFINITION_NS, "map");
        for (int i = 0; i < mapElements.length; i++) {
            int group = DomHelper.getAttributeAsInteger(mapElements[i], "group");
            String field = DomHelper.getAttribute(mapElements[i], "field");
            // check that this field exists
            if (!definition.hasWidget(field)) {
                throw new FormsException("Unknown widget id '" + field + "' referenced.",
                                         DomHelper.getLocationObject(mapElements[i]));
            }

            try {
                definition.addSplitMapping(group, field);
            } catch(RuntimeException e) {
                throw new FormsException("Two groups are mapped to the same widget id '" + field + "'.",
                                         DomHelper.getLocationObject(mapElements[i]));
            }
        }

        // read split fail message (if any)
        Element failMessageElement = DomHelper.getChildElement(splitElement, FormsConstants.DEFINITION_NS, "failmessage");
        if (failMessageElement != null) {
            XMLizable failMessage = DomHelper.compileElementContent(failMessageElement);
            definition.setSplitFailMessage(failMessage);
        }

        // compile combine expression
        Element combineElement = DomHelper.getChildElement(widgetElement, FormsConstants.DEFINITION_NS, "combine", true);
        if(combineElement!=null) {
            String combineExprString = DomHelper.getAttribute(combineElement, "expression");
            Expression combineExpr;
            try {
                combineExpr = expressionManager.parse(combineExprString);
            } catch (Exception e) {
                throw new FormsException("Invalid combine expression '" + combineExprString + "'.",
                                         e, DomHelper.getLocationObject(combineElement));
            }
            Class clazz = definition.getDatatype().getTypeClass();
            if (combineExpr.getResultType() != null && !clazz.isAssignableFrom(combineExpr.getResultType())) {
                throw new FormsException("The result of the combine expression should be '" + clazz.getName() + "', not '" + combineExpr.getResultType().getName() + "'.",
                                         DomHelper.getLocationObject(combineElement));
            }
            definition.setCombineExpression(combineExpr);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.cocoon.forms.FormsException

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.