com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeValueException Java Examples

The following examples show how to use com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeValueException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XSSimpleTypeDecl.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * validate an actual value against this DV
 *
 * @param context       the validation context
 * @param validatedInfo used to provide the actual value and member types
 */
public void validate(ValidationContext context, ValidatedInfo validatedInfo)
    throws InvalidDatatypeValueException {

    if (context == null)
        context = fEmptyContext;

    // then validate the actual value against the facets
    if (context.needFacetChecking() &&
            (fFacetsDefined != 0 && fFacetsDefined != FACET_WHITESPACE)) {
        checkFacets(validatedInfo);
    }

    // now check extra rules: for ID/IDREF/ENTITY
    if (context.needExtraChecking()) {
        checkExtraRules(context, validatedInfo);
    }

}
 
Example #2
Source File: AnyURIDV.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
    // check 3.2.17.c0 must: URI (rfc 2396/2723)
    try {
        if( content.length() != 0 ) {
            // encode special characters using XLink 5.4 algorithm
            final String encoded = encode(content);
            // Support for relative URLs
            // According to Java 1.1: URLs may also be specified with a
            // String and the URL object that it is related to.
            new URI(BASE_URI, encoded );
        }
    } catch (URI.MalformedURIException ex) {
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "anyURI"});
    }

    // REVISIT: do we need to return the new URI object?
    return content;
}
 
Example #3
Source File: AnyURIDV.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
    // check 3.2.17.c0 must: URI (rfc 2396/2723)
    try {
        if( content.length() != 0 ) {
            // encode special characters using XLink 5.4 algorithm
            final String encoded = encode(content);
            // Support for relative URLs
            // According to Java 1.1: URLs may also be specified with a
            // String and the URL object that it is related to.
            new URI(BASE_URI, encoded );
        }
    } catch (URI.MalformedURIException ex) {
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "anyURI"});
    }

    // REVISIT: do we need to return the new URI object?
    return content;
}
 
Example #4
Source File: XSSimpleTypeDecl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * validate an actual value against this DV
 *
 * @param context       the validation context
 * @param validatedInfo used to provide the actual value and member types
 */
public void validate(ValidationContext context, ValidatedInfo validatedInfo)
    throws InvalidDatatypeValueException {

    if (context == null)
        context = fEmptyContext;

    // then validate the actual value against the facets
    if (context.needFacetChecking() &&
            (fFacetsDefined != 0 && fFacetsDefined != FACET_WHITESPACE)) {
        checkFacets(validatedInfo);
    }

    // now check extra rules: for ID/IDREF/ENTITY
    if (context.needExtraChecking()) {
        checkExtraRules(context, validatedInfo);
    }

}
 
Example #5
Source File: Base64BinaryDV.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
    byte[] decoded = Base64.decode(content);
    if (decoded == null)
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "base64Binary"});

    return new XBase64(decoded);
}
 
Example #6
Source File: DurationDV.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException{
    try{
        return parse(content, DURATION_TYPE);
    } catch (Exception ex) {
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "duration"});
    }
}
 
Example #7
Source File: Base64BinaryDV.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
    byte[] decoded = Base64.decode(content);
    if (decoded == null)
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "base64Binary"});

    return new XBase64(decoded);
}
 
Example #8
Source File: YearDV.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Convert a string to a compiled form
 *
 * @param  content The lexical representation of time
 * @return a valid and normalized time object
 */
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException{
    try{
        return parse(content);
    } catch(Exception ex){
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "gYear"});
    }
}
 
Example #9
Source File: BooleanDV.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
    Boolean ret = null;

    if (content.equals(fValueSpace[0]) || content.equals(fValueSpace[2]))
        ret = Boolean.FALSE;
    else if (content.equals(fValueSpace[1]) || content.equals(fValueSpace[3]))
        ret = Boolean.TRUE;
    else
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "boolean"});
    return ret;
}
 
Example #10
Source File: QNameDV.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public Object getActualValue(String content, ValidationContext context)
    throws InvalidDatatypeValueException {

    // "prefix:localpart" or "localpart"
    // get prefix and local part out of content
    String prefix, localpart;
    int colonptr = content.indexOf(":");
    if (colonptr > 0) {
        prefix = context.getSymbol(content.substring(0,colonptr));
        localpart = content.substring(colonptr+1);
    } else {
        prefix = EMPTY_STRING;
        localpart = content;
    }

    // both prefix (if any) a nd localpart must be valid NCName
    if (prefix.length() > 0 && !XMLChar.isValidNCName(prefix))
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "QName"});

    if(!XMLChar.isValidNCName(localpart))
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "QName"});

    // resove prefix to a uri, report an error if failed
    String uri = context.getURI(prefix);
    if (prefix.length() > 0 && uri == null)
        throw new InvalidDatatypeValueException("UndeclaredPrefix", new Object[]{content, prefix});

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

}
 
Example #11
Source File: HexBinaryDV.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
    byte[] decoded = HexBin.decode(content);
    if (decoded == null)
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "hexBinary"});

    return new XHex(decoded);
}
 
Example #12
Source File: DayTimeDurationDV.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Object getActualValue(String content, ValidationContext context)
    throws InvalidDatatypeValueException {
    try {
        return parse(content, DurationDV.DAYTIMEDURATION_TYPE);
    }
    catch (Exception ex) {
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "dayTimeDuration"});
    }
}
 
Example #13
Source File: DayTimeDurationDV.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public Object getActualValue(String content, ValidationContext context)
    throws InvalidDatatypeValueException {
    try {
        return parse(content, DurationDV.DAYTIMEDURATION_TYPE);
    }
    catch (Exception ex) {
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "dayTimeDuration"});
    }
}
 
Example #14
Source File: MonthDV.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Convert a string to a compiled form
 *
 * @param  content The lexical representation of gMonth
 * @return a valid and normalized gMonth object
 */
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException{
    try{
        return parse(content);
    } catch(Exception ex){
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "gMonth"});
    }
}
 
Example #15
Source File: YearMonthDurationDV.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Object getActualValue(String content, ValidationContext context)
    throws InvalidDatatypeValueException {
    try {
        return parse(content, DurationDV.YEARMONTHDURATION_TYPE);
    }
    catch (Exception ex) {
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "yearMonthDuration"});
    }
}
 
Example #16
Source File: IntegerDV.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
    try {
        return new XDecimal(content, true);
    } catch (NumberFormatException nfe) {
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "integer"});
    }
}
 
Example #17
Source File: YearMonthDV.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Convert a string to a compiled form
 *
 * @param  content The lexical representation of gYearMonth
 * @return a valid and normalized gYearMonth object
 */
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException{
    try{
        return parse(content);
    } catch(Exception ex){
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "gYearMonth"});
    }
}
 
Example #18
Source File: YearDV.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Convert a string to a compiled form
 *
 * @param  content The lexical representation of time
 * @return a valid and normalized time object
 */
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException{
    try{
        return parse(content);
    } catch(Exception ex){
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "gYear"});
    }
}
 
Example #19
Source File: EntityDV.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
    if (!XMLChar.isValidNCName(content)) {
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "NCName"});
    }

    return content;
}
 
Example #20
Source File: DurationDV.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException{
    try{
        return parse(content, DURATION_TYPE);
    } catch (Exception ex) {
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "duration"});
    }
}
 
Example #21
Source File: DateTimeDV.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
    try{
        return parse(content);
    } catch(Exception ex){
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "dateTime"});
    }
}
 
Example #22
Source File: MonthDayDV.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Convert a string to a compiled form
 *
 * @param  content The lexical representation of gMonthDay
 * @return a valid and normalized gMonthDay object
 */
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
    try{
        return parse(content);
    } catch(Exception ex){
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "gMonthDay"});
    }
}
 
Example #23
Source File: PrecisionDecimalDV.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object getActualValue(String content, ValidationContext context)
throws InvalidDatatypeValueException {
    try {
        return new XPrecisionDecimal(content);
    } catch (NumberFormatException nfe) {
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "precisionDecimal"});
    }
}
 
Example #24
Source File: PrecisionDecimalDV.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
@Override
public Object getActualValue(String content, ValidationContext context)
throws InvalidDatatypeValueException {
    try {
        return new XPrecisionDecimal(content);
    } catch (NumberFormatException nfe) {
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "precisionDecimal"});
    }
}
 
Example #25
Source File: TimeDV.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Convert a string to a compiled form
 *
 * @param  content The lexical representation of time
 * @return a valid and normalized time object
 */
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException{
    try{
        return parse(content);
    } catch(Exception ex){
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "time"});
    }
}
 
Example #26
Source File: DayDV.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
    try{
        return parse(content);
    } catch(Exception ex){
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "gDay"});
    }
}
 
Example #27
Source File: XMLSchemaValidator.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
Object elementLocallyValidType(QName element, Object textContent) {
    if (fCurrentType == null)
        return null;

    Object retValue = null;
    // Element Locally Valid (Type)
    // 3 The appropriate case among the following must be true:
    // 3.1 If the type definition is a simple type definition, then all of the following must be true:
    if (fCurrentType.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
        // 3.1.2 The element information item must have no element information item [children].
        if (fSubElement)
            reportSchemaError("cvc-type.3.1.2", new Object[] { element.rawname });
        // 3.1.3 If clause 3.2 of Element Locally Valid (Element) (3.3.4) did not apply, then the normalized value must be valid with respect to the type definition as defined by String Valid (3.14.4).
        if (!fNil) {
            XSSimpleType dv = (XSSimpleType) fCurrentType;
            try {
                if (!fNormalizeData || fUnionType) {
                    fValidationState.setNormalizationRequired(true);
                }
                retValue = dv.validate(textContent, fValidationState, fValidatedInfo);
            } catch (InvalidDatatypeValueException e) {
                reportSchemaError(e.getKey(), e.getArgs());
                reportSchemaError(
                    "cvc-type.3.1.3",
                    new Object[] { element.rawname, textContent });
            }
        }
    } else {
        // 3.2 If the type definition is a complex type definition, then the element information item must be valid with respect to the type definition as per Element Locally Valid (Complex Type) (3.4.4);
        retValue = elementLocallyValidComplexType(element, textContent);
    }

    return retValue;
}
 
Example #28
Source File: QNameDV.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Object getActualValue(String content, ValidationContext context)
    throws InvalidDatatypeValueException {

    // "prefix:localpart" or "localpart"
    // get prefix and local part out of content
    String prefix, localpart;
    int colonptr = content.indexOf(":");
    if (colonptr > 0) {
        prefix = context.getSymbol(content.substring(0,colonptr));
        localpart = content.substring(colonptr+1);
    } else {
        prefix = EMPTY_STRING;
        localpart = content;
    }

    // both prefix (if any) a nd localpart must be valid NCName
    if (prefix.length() > 0 && !XMLChar.isValidNCName(prefix))
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "QName"});

    if(!XMLChar.isValidNCName(localpart))
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "QName"});

    // resove prefix to a uri, report an error if failed
    String uri = context.getURI(prefix);
    if (prefix.length() > 0 && uri == null)
        throw new InvalidDatatypeValueException("UndeclaredPrefix", new Object[]{content, prefix});

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

}
 
Example #29
Source File: DateDV.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
    try{
        return parse(content);
    } catch(Exception ex){
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "date"});
    }
}
 
Example #30
Source File: XSSimpleTypeDecl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void checkExtraRules(ValidationContext context, ValidatedInfo validatedInfo) throws InvalidDatatypeValueException {

        Object ob = validatedInfo.actualValue;

        if (fVariety == VARIETY_ATOMIC) {

            fDVs[fValidationDV].checkExtraRules(ob, context);

        } else if (fVariety == VARIETY_LIST) {

            ListDV.ListData values = (ListDV.ListData)ob;
            XSSimpleType memberType = validatedInfo.memberType;
            int len = values.getLength();
            try {
                if (fItemType.fVariety == VARIETY_UNION) {
                    XSSimpleTypeDecl[] memberTypes = (XSSimpleTypeDecl[])validatedInfo.memberTypes;
                    for (int i = len-1; i >= 0; i--) {
                        validatedInfo.actualValue = values.item(i);
                        validatedInfo.memberType = memberTypes[i];
                        fItemType.checkExtraRules(context, validatedInfo);
                    }
                } else { // (fVariety == VARIETY_ATOMIC)
                    for (int i = len-1; i >= 0; i--) {
                        validatedInfo.actualValue = values.item(i);
                        fItemType.checkExtraRules(context, validatedInfo);
                    }
                }
            }
            finally {
                validatedInfo.actualValue = values;
                validatedInfo.memberType = memberType;
            }

        } else { // (fVariety == VARIETY_UNION)

            ((XSSimpleTypeDecl)validatedInfo.memberType).checkExtraRules(context, validatedInfo);

        }

    }