Package org.apache.cocoon.forms.datatype.convertor

Examples of org.apache.cocoon.forms.datatype.convertor.ConversionResult


            for (int i = 0; i < size; i++) {
                ValueJXPathBinding vBinding = (ValueJXPathBinding)childBindings[i];
                Object value = rowContext.getValue(vBinding.getXPath());
                if (value != null && vBinding.getConvertor() != null) {
                    if (value instanceof String) {
                        ConversionResult conversionResult = vBinding.getConvertor().convertFromString(
                                (String)value, vBinding.getConvertorLocale(), null);
                        if (conversionResult.isSuccessful())
                            value = conversionResult.getResult();
                        else
                            value = null;
                    } else {
                        if (getLogger().isWarnEnabled()) {
                            getLogger().warn("Convertor ignored on backend-value " +
View Full Code Here


        }

        Object value = jxpc.getValue(this.xpath);
        if (value != null && convertor != null) {
            if (value instanceof String) {
                ConversionResult conversionResult = convertor.convertFromString((String)value, convertorLocale, null);
                if (conversionResult.isSuccessful())
                    value = conversionResult.getResult();
                else
                    value = null;
            } else {
                getLogger().warn("Convertor ignored on backend-value which isn't of type String.");
            }
View Full Code Here

                    String unparsedValue = attributes.getValue("value");
                    if (unparsedValue == null || "".equals(unparsedValue)) {
                        // Empty (or null) value translates into the empty string
                        currentValueAsString = "";
                    } else {
                        ConversionResult conversionResult = convertor.convertFromString(unparsedValue, locale, fromFormatCache);
                        if (!conversionResult.isSuccessful()) {
                            throw new SAXException("Could not interpret the following value: \"" + unparsedValue + "\".");
                        }
                        currentValue = conversionResult.getResult();
                        currentValueAsString = datatype.getConvertor().convertToString(currentValue, locale, toFormatCache);
                    }
                    AttributesImpl attrs = new AttributesImpl();
                    attrs.addCDATAAttribute("value", currentValueAsString);
                    super.startElement(Constants.INSTANCE_NS, localName, Constants.INSTANCE_PREFIX_COLON + localName, attrs);
View Full Code Here

                Object value;
                if ("".equals(stringValue)) {
                    // Empty value translates into the null object
                    value = null;
                } else {
                    ConversionResult conversionResult = convertor.convertFromString(stringValue, Locale.US, formatCache);
                    if (!conversionResult.isSuccessful()) {
                        throw new Exception("Could not convert the value \"" + stringValue +
                                            "\" to the type " + datatype.getDescriptiveName() +
                                            ", defined at " + DomHelper.getLocation(element));
                    }
                    value = conversionResult.getResult();
                }

                XMLizable label = null;
                Element labelEl = DomHelper.getChildElement(element, Constants.DEFINITION_NS, "label");
                if (labelEl != null) {
View Full Code Here

        // Clear value, it will be recomputed
        this.value = null;
        this.validationError = null;
        if (this.enteredValue != null) {
            // Parse the value
            ConversionResult conversionResult = getDatatype().convertFromString(this.enteredValue, getForm().getLocale());
            if (conversionResult.isSuccessful()) {
                this.value = conversionResult.getResult();
                this.valueState = VALUE_PARSED;
            } else {
                // Conversion failed
                this.validationError = conversionResult.getValidationError();
                // No need for further validation (and need to keep the above error)
                this.valueState = VALUE_PARSE_ERROR;
            }
        } else {
            // No value: needs to be validated
View Full Code Here

            for (int i = 0; i < size; i++) {
                ValueJXPathBinding vBinding = (ValueJXPathBinding)childBindings[i];
                Object value = rowContext.getValue(vBinding.getXPath());
                if (value != null && vBinding.getConvertor() != null) {
                    if (value instanceof String) {
                        ConversionResult conversionResult = vBinding.getConvertor().convertFromString(
                                (String)value, vBinding.getConvertorLocale(), null);
                        if (conversionResult.isSuccessful())
                            value = conversionResult.getResult();
                        else
                            value = null;
                    } else {
                        if (getLogger().isWarnEnabled()) {
                            getLogger().warn("Convertor ignored on backend-value " +
View Full Code Here

            // never fail. But it could fail if users start messing around with
            // request parameters.
            Object[] tempValues = (Object[])Array.newInstance(getDatatype().getTypeClass(), enteredValues.length);
            for (int i = 0; i < enteredValues.length; i++) {
                String param = enteredValues[i];
                ConversionResult conversionResult = definition.getDatatype().convertFromString(param, formContext.getLocale());
                if (conversionResult.isSuccessful()) {
                    tempValues[i] = conversionResult.getResult();
                } else {
                    conversionFailed = true;
                    break;
                }
            }
View Full Code Here

        Element initialValueElement = DomHelper.getChildElement(widgetElement, Constants.DEFINITION_NS, "initial-value", false);
        if (initialValueElement != null) {
            String localeValue = DomHelper.getAttribute(initialValueElement, "locale", null);
            Locale locale = localeValue == null ? null : I18nUtils.parseLocale(localeValue);
            String value = DomHelper.getElementText(initialValueElement);
            ConversionResult result = datatype.convertFromString(value, locale);
            if (!result.isSuccessful()) {
                throw new Exception("Cannot parse initial value '" + value + "' at " +
                        DomHelper.getLocation(initialValueElement));
            }
            initialValue = result.getResult();
        }
       
        definition.setDatatype(datatype, initialValue);
       
        //---- parse "selection-list"
View Full Code Here

            while (rowPointers.hasNext()) {
                Object value = rowPointers.next();

                if (value != null && convertor != null) {
                    if (value instanceof String) {
                        ConversionResult conversionResult = convertor.convertFromString((String)value, convertorLocale, null);
                        if (conversionResult.isSuccessful())
                            value = conversionResult.getResult();
                        else
                            value = null;
                    } else {
                        getLogger().warn("Convertor ignored on backend-value which isn't of type String.");
                    }
View Full Code Here

            return;

        if (this.currentWidget instanceof MultiValueField && isMultiValueItem) {
            MultiValueField field = (MultiValueField)this.currentWidget;
            Datatype type = field.getDatatype();
            ConversionResult conv =
                type.convertFromString(input, this.locale);
            if (conv.isSuccessful()) {
                Object[] values = (Object[])field.getValue();
                int valLen = values == null ? 0 : values.length;
                Object[] newValues = new Object[valLen + 1];
                for (int i = 0; i < valLen; i++)
                    newValues[i] = values[i];
                newValues[valLen] = conv.getResult();
                field.setValues(newValues);
            } else
                throw new SAXException("Could not convert: " + input +
                                       " to " + type.getTypeClass());
        } else if (this.currentWidget instanceof DataWidget) {
            DataWidget data = (DataWidget)this.currentWidget;
            Datatype type = data.getDatatype();
            ConversionResult conv =
                type.convertFromString(input, this.locale);
            if (conv.isSuccessful()) {
                data.setValue(conv.getResult());
            } else
                throw new SAXException("Could not convert: " + input +
                                       " to " + type.getTypeClass());
        } else if (this.currentWidget instanceof BooleanField) {
            // FIXME: BooleanField should implement DataWidget, which
View Full Code Here

TOP

Related Classes of org.apache.cocoon.forms.datatype.convertor.ConversionResult

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.