private static ValidationFailure badDate(String msg, CharSequence value) { ValidationFailure err = new ValidationFailure( "Invalid dateTime value " + Err.wrap(value, Err.VALUE) + " (" + msg + ")"); err.setErrorCode("FORG0001"); return err; }
/** * Convert the value to a built-in subtype of xs:dateTime * * @param subtype the target subtype * @return null if the conversion succeeds; a ValidationFailure describing the failure if it * fails. */ public ValidationFailure convertToSubType(BuiltInAtomicType subtype) { if (subtype.getFingerprint() == StandardNames.XS_DATE_TIME_STAMP) { if (hasTimezone()) { setTypeLabel(subtype); return null; } else { ValidationFailure err = new ValidationFailure( "The value " + Err.depict(this) + " is not a valid xs:dateTimeStamp: it has no timezone"); err.setErrorCode("FORG0001"); return err; } } else { throw new IllegalArgumentException("Unknown subtype of xs:dateTime"); } }
/** Supporting routine to load one external file given a URI (href) and a baseURI */ public CharSequence readFile(String href, String baseURI, String encoding, XPathContext context) throws XPathException { final Configuration config = context.getConfiguration(); NameChecker checker = config.getNameChecker(); // Use the URI machinery to validate and resolve the URIs URI absoluteURI = getAbsoluteURI(href, baseURI); Reader reader; try { reader = context .getController() .getUnparsedTextURIResolver() .resolve(absoluteURI, encoding, config); } catch (XPathException err) { err.maybeSetErrorCode("XTDE1170"); err.maybeSetLocation(this); throw err; } try { return readFile(checker, reader); } catch (java.io.UnsupportedEncodingException encErr) { XPathException e = new XPathException("Unknown encoding " + Err.wrap(encoding), encErr); e.setErrorCode("XTDE1190"); throw e; } catch (java.io.IOException ioErr) { // System.err.println("ProxyHost: " + System.getProperty("http.proxyHost")); // System.err.println("ProxyPort: " + System.getProperty("http.proxyPort")); XPathException e = handleIOError(absoluteURI, ioErr); e.setLocator(this); throw e; } }
public void prepareAttributes() throws XPathException { AttributeCollection atts = getAttributeList(); String nameAtt = null; String namespaceAtt = null; String selectAtt = null; String separatorAtt = null; String validationAtt = null; String typeAtt = null; for (int a = 0; a < atts.getLength(); a++) { int nc = atts.getNameCode(a); String f = getNamePool().getClarkName(nc); if (f == StandardNames.NAME) { nameAtt = Whitespace.trim(atts.getValue(a)); } else if (f == StandardNames.NAMESPACE) { namespaceAtt = Whitespace.trim(atts.getValue(a)); } else if (f == StandardNames.SELECT) { selectAtt = atts.getValue(a); } else if (f == StandardNames.SEPARATOR) { separatorAtt = atts.getValue(a); } else if (f == StandardNames.VALIDATION) { validationAtt = Whitespace.trim(atts.getValue(a)); } else if (f == StandardNames.TYPE) { typeAtt = Whitespace.trim(atts.getValue(a)); } else { checkUnknownAttribute(nc); } } if (nameAtt == null) { reportAbsence("name"); return; } attributeName = makeAttributeValueTemplate(nameAtt); if (attributeName instanceof StringLiteral) { if (!getConfiguration() .getNameChecker() .isQName(((StringLiteral) attributeName).getStringValue())) { invalidAttributeName("Attribute name " + Err.wrap(nameAtt) + " is not a valid QName"); } if (nameAtt.equals("xmlns")) { if (namespace == null) { invalidAttributeName("Invalid attribute name: xmlns"); } } if (nameAtt.startsWith("xmlns:")) { if (namespaceAtt == null) { invalidAttributeName("Invalid attribute name: " + Err.wrap(nameAtt)); } else { // ignore the prefix "xmlns" nameAtt = nameAtt.substring(6); attributeName = new StringLiteral(nameAtt); } } } if (namespaceAtt != null) { namespace = makeAttributeValueTemplate(namespaceAtt); if (namespace instanceof StringLiteral) { if (!AnyURIValue.isValidURI(((StringLiteral) namespace).getStringValue())) { compileError("The value of the namespace attribute must be a valid URI", "XTDE0865"); } } } if (selectAtt != null) { select = makeExpression(selectAtt); } if (separatorAtt == null) { if (selectAtt == null) { separator = new StringLiteral(StringValue.EMPTY_STRING); } else { separator = new StringLiteral(StringValue.SINGLE_SPACE); } } else { separator = makeAttributeValueTemplate(separatorAtt); } if (validationAtt != null) { validationAction = Validation.getCode(validationAtt); if (validationAction != Validation.STRIP && !getExecutable().isSchemaAware()) { validationAction = Validation.STRIP; compileError("To perform validation, a schema-aware XSLT processor is needed", "XTSE1660"); } if (validationAction == Validation.INVALID) { compileError("Invalid value of validation attribute", "XTSE0020"); validationAction = getContainingStylesheet().getDefaultValidation(); } } else { validationAction = getContainingStylesheet().getDefaultValidation(); } if (typeAtt != null) { if (!getExecutable().isSchemaAware()) { compileError( "The @type attribute is available only with a schema-aware XSLT processor", "XTSE1660"); } else { SchemaType type = getSchemaType(typeAtt); if (type == null) { compileError("Unknown attribute type " + typeAtt, "XTSE1520"); } else { if (type.isSimpleType()) { schemaType = (SimpleType) type; } else { compileError("Type annotation for attributes must be a simple type", "XTSE1530"); type = null; } } validationAction = Validation.BY_TYPE; } } if (typeAtt != null && validationAtt != null) { compileError("The validation and type attributes are mutually exclusive", "XTSE1505"); validationAction = getContainingStylesheet().getDefaultValidation(); schemaType = null; } }