Package org.apache.xerces.impl.dv

Examples of org.apache.xerces.impl.dv.InvalidDatatypeValueException


     */
    public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException{
        try{
            return parse(content, null);
        } catch(Exception ex){
            throw new InvalidDatatypeValueException("not a valid yearMonth");
        }
    }
View Full Code Here


     */
    public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException{
        try{
            return parse(content, null);
        } catch(Exception ex){
            throw new InvalidDatatypeValueException("not a valid month");
        }
    }
View Full Code Here

    public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException{
        try{
            return parse(content, null);
        } catch (Exception ex) {
            throw new InvalidDatatypeValueException("not a valid duration");
        }
    }
View Full Code Here

    }

    public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
        String decoded = Base64.decode(content);
        if (decoded == null)
            throw new InvalidDatatypeValueException("Value '"+content+"' is not encoded in base64");

        return decoded;
    }
View Full Code Here

        try{
            return fValueOf(content);
        } catch (Exception ex){
            //throw new InvalidDatatypeValueException(DatatypeMessageProvider.fgMessageKeys[DatatypeMessageProvider.NOT_FLOAT ],
            //                                        new Object[]{content});
            throw new InvalidDatatypeValueException("'" + content + "' is not a valid float value");
        }
    }//getActualValue()
View Full Code Here

     */
    public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException{
        try{
            return parse(content, null);
        } catch(Exception ex){
            throw new InvalidDatatypeValueException("not a valid time");
        }
    }
View Full Code Here

            localpart = content;
        }

        // both prefix (if any) and localpart must be valid NCName
        if (prefix.length() > 0 && !XMLChar.isValidNCName(prefix))
            throw new InvalidDatatypeValueException("Value '"+content+"' is not a valid QName: '" + prefix + "' is not an NCName");

        if(!XMLChar.isValidNCName(localpart))
            throw new InvalidDatatypeValueException("Value '"+content+"' is not a valid QName: '" + localpart + "' is not an NCName");

        // resove prefix to a uri, report an error if failed
        String uri = context.getURI(prefix);
        if (prefix.length() > 0 && uri == null)
            throw new InvalidDatatypeValueException("Value '"+content+"' is not a valid QName: cannot resolve the prefix to a namespace uri");

        return new QName(prefix, context.getSymbol(localpart), context.getSymbol(content), uri);

    }
View Full Code Here

                // According to Java 1.1: URLs may also be specified with a
                // String and the URL object that it is related to.
                new URI(tempURI, content );
            }
        } catch URI.MalformedURIException ex ) {
            throw new InvalidDatatypeValueException("Value '"+content+"' is a Malformed URI");
        }

        // REVISIT: do we need to return the new URI object?
        return content;
    }
View Full Code Here

        int length = fDVs[fValidationDV].getDataLength(ob);

        // maxLength
        if ( (fFacetsDefined & FACET_MAXLENGTH) != 0 ) {
            if ( length > fMaxLength ) {
                throw new InvalidDatatypeValueException("Value '"+content+
                                                        "' with length '"+length+
                                                        "' exceeds maximum length facet of '"+fMaxLength+"'");
            }
        }

        //minLength
        if ( (fFacetsDefined & FACET_MINLENGTH) != 0 ) {
            if ( length < fMinLength ) {
                throw new InvalidDatatypeValueException("Value '"+content+
                                                        "' with length '"+length+
                                                        "' is less than minimum length facet of '"+fMinLength+"'" );
            }
        }

        //length
        if ( (fFacetsDefined & FACET_LENGTH) != 0 ) {
            if ( length != fLength ) {
                throw new InvalidDatatypeValueException("Value '"+content+
                                                        "' with length '"+length+
                                                        "' is not equal to length facet '"+fLength+"'");
            }
        }

        //enumeration
        if ( ((fFacetsDefined & FACET_ENUMERATION) != 0 ) ) {
            boolean present = false;
            for (int i = 0; i < fEnumeration.size(); i++) {
                if (isEqual(ob, fEnumeration.elementAt(i))) {
                    present = true;
                    break;
                }
            }
            if(!present){
                throw new InvalidDatatypeValueException(DatatypeMessageProvider.fgMessageKeys[DatatypeMessageProvider.NOT_ENUM_VALUE],
                                                        new Object [] {content});
            }
        }

        //fractionDigits
        if ((fFacetsDefined & FACET_FRACTIONDIGITS) != 0) {
            int scale = fDVs[fValidationDV].getFractionDigits(ob);
            if (scale > fFractionDigits) {
                throw new InvalidDatatypeValueException(DatatypeMessageProvider.fgMessageKeys[DatatypeMessageProvider.FRACTION_EXCEEDED],
                                           new Object[] {
                                               "'" + content + "'" + " with fractionDigits = '"+ scale +"'",
                                               "'" + fFractionDigits + "'"
                                           });
            }
        }

        //totalDigits
        if ((fFacetsDefined & FACET_TOTALDIGITS)!=0) {
            int totalDigits = fDVs[fValidationDV].getTotalDigits(ob);
            if (totalDigits > fTotalDigits) {
                throw new InvalidDatatypeValueException(DatatypeMessageProvider.fgMessageKeys[DatatypeMessageProvider.TOTALDIGITS_EXCEEDED],
                                           new Object[] {
                                               "'" + content + "'" + " with totalDigits = '"+ totalDigits +"'",
                                               "'" + fTotalDigits + "'"
                                           });
            }
        }


        // REVISIT this part for error reporting

        boolean minOk = true;
        boolean maxOk = true;
        String  upperBound="";

        String  lowerBound="";
        String  lowerBoundIndicator = "";
        String  upperBoundIndicator = "";
        int compare;

        //maxinclusive
        if ( (fFacetsDefined & FACET_MAXINCLUSIVE) != 0 ) {
            compare = fDVs[fValidationDV].compare(ob, fMaxInclusive);
            maxOk = (compare == -1 || compare == 0);
            upperBound   = fMaxInclusive.toString();
            if ( upperBound != null ) {
                upperBoundIndicator = "<=";
            }
            else {
                upperBound="";
            }
        }

        //maxExclusive
        if ( (fFacetsDefined & FACET_MAXEXCLUSIVE) != 0 ) {
            compare = fDVs[fValidationDV].compare(ob,  fMaxExclusive );
            maxOk = (compare == -1);
            upperBound = fMaxExclusive.toString();
            if ( upperBound != null ) {
                upperBoundIndicator = "<";
            }
            else {
                upperBound = "";
            }
        }

        //minInclusive
        if ( (fFacetsDefined & FACET_MININCLUSIVE) != 0 ) {
            compare = fDVs[fValidationDV].compare(ob, fMinInclusive);
            minOk = (compare == 1 || compare == 0);
            lowerBound = fMinInclusive.toString();
            if ( lowerBound != null ) {
                lowerBoundIndicator = "<=";
            }
            else {
                lowerBound = "";
            }
        }

        //minExclusive
        if ( (fFacetsDefined & FACET_MINEXCLUSIVE) != 0 ) {
            compare = fDVs[fValidationDV].compare(ob, fMinExclusive);
            minOk = (compare == 1);
            lowerBound = fMinExclusive.toString();
            if ( lowerBound != null ) {
                lowerBoundIndicator = "<";
            }
            else {
                lowerBound = "";
            }
        }

        if ( !(minOk && maxOk) ){
            throw new InvalidDatatypeValueException(DatatypeMessageProvider.fgMessageKeys[DatatypeMessageProvider.OUT_OF_BOUNDS],
                new Object [] { ob.toString(), lowerBound, upperBound, lowerBoundIndicator, upperBoundIndicator});
        }

    }
View Full Code Here

                    // PATTERN "[\\i-[:]][\\c-[:]]*"
                    // REVISIT: !!!NOT IMPLEMENTED in XMLChar
                    seenErr = !XMLChar.isValidNCName(nvalue);
                }
                if (seenErr) {
                    throw new InvalidDatatypeValueException("Value '"+nvalue+"' is not a valid " +
                                                            SPECIAL_TOKEN_STRING[fTokenType]);
                }
            }

            if ( (fFacetsDefined & FACET_PATTERN ) != 0 ) {
                RegularExpression regex;
                for (int idx = fPattern.size()-1; idx >= 0; idx--) {
                    regex = (RegularExpression)fPattern.elementAt(idx);
                    if (!regex.matches(nvalue)){
                        throw new InvalidDatatypeValueException("Value '"+content+
                                                                "' does not match regular expression facet '" + fPattern + "'" );
                    }
                }
            }

            Object avalue = fDVs[fValidationDV].getActualValue(nvalue, context);

            validatedInfo.actualValue = avalue;
            validatedInfo.normalizedValue = nvalue;

            return avalue;

        } else if (fVariety == VARIETY_LIST) {

            String nvalue = normalize(content, fWhiteSpace);
            StringTokenizer parsedList = new StringTokenizer(nvalue);
            int countOfTokens = parsedList.countTokens() ;
            Object[] avalue = new Object[countOfTokens];
            XSSimpleTypeDecl[] memberTypes = new XSSimpleTypeDecl[countOfTokens];
            for(int i = 0 ; i < countOfTokens ; i ++){
                // we can't call fItemType.validate(), otherwise checkExtraRules()
                // will be called twice: once in fItemType.validate, once in
                // validate method of this type.
                // so we take two steps to get the actual value:
                // 1. fItemType.getActualValue()
                // 2. fItemType.chekcFacets()
                avalue[i] = fItemType.getActualValue(parsedList.nextToken(), context, validatedInfo);
                if (context.needFacetChecking() &&
                    (fItemType.fFacetsDefined != 0 && fItemType.fFacetsDefined != FACET_WHITESPACE)) {
                    fItemType.checkFacets(validatedInfo);
                }
                memberTypes[i] = (XSSimpleTypeDecl)validatedInfo.memberType;
            }

            validatedInfo.actualValue = avalue;
            validatedInfo.normalizedValue = nvalue;
            validatedInfo.memberTypes = memberTypes;

            return avalue;

        } else { // (fVariety == VARIETY_UNION)
            for(int i = 0 ; i < fMemberTypes.length; i++) {
                try {
                    // we can't call fMemberType[i].validate(), otherwise checkExtraRules()
                    // will be called twice: once in fMemberType[i].validate, once in
                    // validate method of this type.
                    // so we take two steps to get the actual value:
                    // 1. fMemberType[i].getActualValue()
                    // 2. fMemberType[i].chekcFacets()
                    Object aValue = fMemberTypes[i].getActualValue(content, context, validatedInfo);
                    if (context.needFacetChecking() &&
                        (fMemberTypes[i].fFacetsDefined != 0 && fMemberTypes[i].fFacetsDefined != FACET_WHITESPACE)) {
                        fMemberTypes[i].checkFacets(validatedInfo);
                    }
                    validatedInfo.memberType = fMemberTypes[i];
                    return aValue;
                } catch(InvalidDatatypeValueException invalidValue) {
                }
            }

            String msg  = " content = " + content + " doesnt't match any of the member types " ;
            throw new InvalidDatatypeValueException(msg);
        }

    }//getActualValue()
View Full Code Here

TOP

Related Classes of org.apache.xerces.impl.dv.InvalidDatatypeValueException

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.