Package org.apache.cocoon.forms

Examples of org.apache.cocoon.forms.FormsException


    throws FormsException {
        String attrValue = getAttribute(element, attributeName);
        try {
            return Integer.parseInt(attrValue);
        } catch (NumberFormatException e) {
            throw new FormsException("Cannot parse the value '" + attrValue + "' " +
                                     "as an integer in the attribute '" + attributeName + "'," +
                                     DomHelper.getLocationObject(element));
        }
    }
View Full Code Here


        }

        try {
            return Integer.parseInt(attrValue);
        } catch (NumberFormatException e) {
            throw new FormsException("Cannot parse the value '" + attrValue + "' " +
                                     "as an integer in the attribute '" + attributeName + "'," +
                                     DomHelper.getLocationObject(element));
        }
    }
View Full Code Here

       
        String beanRefId = DomHelper.getAttribute(treeModelElement, "ref");
        try {
            Class clazz = beanFactory.getType(beanRefId);
            if (!TreeModel.class.isAssignableFrom(clazz)) {
                throw new FormsException("Spring Bean '" + beanRefId + "' doesn't implement TreeModel.",
                                         DomHelper.getLocationObject(treeModelElement));
            }
        } catch(NoSuchBeanDefinitionException nsbde) {
            throw new FormsException("Spring Bean '" + beanRefId + "' doesn't exists.",
                                     DomHelper.getLocationObject(treeModelElement));
        }

        JavaTreeModelDefinition definition = new JavaTreeModelDefinition();
        definition.setBeanFactory( beanFactory );
View Full Code Here

        } else if ("multiple".equals(selection)) {
            definition.setSelectionModel(Tree.MULTIPLE_SELECTION);
        } else if ("single".equals(selection)) {
            definition.setSelectionModel(Tree.SINGLE_SELECTION);
        } else {
            throw new FormsException("Invalid value selection value '" + selection + "'.",
                                     DomHelper.getLocationObject(widgetElement));
        }

        // Get the model optional element
        Element modelElt = DomHelper.getChildElement(widgetElement, FormsConstants.DEFINITION_NS, "tree-model", false);
View Full Code Here

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

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

        RepeaterDefinition other = (RepeaterDefinition) definition;
        this.initialSize = other.initialSize;
View Full Code Here

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

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

        FieldDefinition other = (FieldDefinition) definition;

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

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

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

        ActionDefinition other = (ActionDefinition) definition;

View Full Code Here

                String localeValue = DomHelper.getAttribute(initialValueElement, "locale", null);
                Locale locale = localeValue == null ? Locale.getDefault() : I18nUtils.parseLocale(localeValue);
                String value = DomHelper.getElementText(initialValueElement);
                ConversionResult result = datatype.convertFromString(value, locale);
                if (!result.isSuccessful()) {
                    throw new FormsException("Cannot parse initial value '" + value + "'.",
                                             DomHelper.getLocationObject(initialValueElement));
                }
                initialValue = result.getResult();
            }
View Full Code Here

                                               String name)
    throws Exception {
        Element selectionListElement = DomHelper.getChildElement(widgetElement, FormsConstants.DEFINITION_NS, name);

        if (selectionListElement != null && definition.getDatatype() == null) {
            throw new FormsException("A widget with a selection list requires a datatype.",
                                     DomHelper.getLocationObject(widgetElement));
        }

        if (selectionListElement == null) {
            return null;
        }

        // listType can be null, meaning we will use the default selection list
        String listType = selectionListElement.getAttribute("type");
        if ("".equals(listType)) {
            listType = defaultSelectionListBuilder;
        }

        // Get an appropriate list builder
        SelectionListBuilder builder = (SelectionListBuilder)selectionListBuilders.get(listType);
        if( builder == null) {
            throw new FormsException("Unknown selection list builder: " + listType);
        }
        return builder.build(selectionListElement, definition.getDatatype());
    }
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.