/** * Creates a new <code>XSModelAnalyzer</code> for the given (Xerces) XML schema infoset. * * @param xmlSchema * schema infoset, must not be <code>null</code> */ public XMLSchemaInfoSet( XSModel xmlSchema ) { this.xsModel = xmlSchema; init(); }
/** * Creates a new {@link XMLSchemaInfoSet} instance that reads the schema documents from the given URLs. * * @param schemaUrls * locations of the schema documents, must not be <code>null</code> and contain at least one entry * @throws ClassCastException * @throws ClassNotFoundException * @throws InstantiationException * @throws IllegalAccessException */ public XMLSchemaInfoSet( String... schemaUrls ) throws ClassCastException, ClassNotFoundException, InstantiationException, IllegalAccessException { xsModel = loadModel( schemaUrls ); init(); }
@SuppressWarnings("synthetic-access") @Override public void error( String domain, String key, XMLParseException e ) throws XNIException { errors.add( new SchemaValidationEvent( domain, key, e ) ); }
RedirectingEntityResolver resolver = new RedirectingEntityResolver(); if ( schemaUris != null ) { for ( int i = 0; i < schemaUris.length; i++ ) { schemaUris[i] = resolver.redirect( schemaUris[i] ); GrammarPool grammarPool = ( schemaUris == null ? null : GrammarPoolManager.getGrammarPool( schemaUris ) ); XMLParserConfiguration parserConfig = createValidatingParser( new RedirectingEntityResolver(), grammarPool ); parserConfig.setErrorHandler( new XMLErrorHandler() { @SuppressWarnings("synthetic-access") public void error( String domain, String key, XMLParseException e ) throws XNIException { errors.add( new SchemaValidationEvent( domain, key, e ) ); public void fatalError( String domain, String key, XMLParseException e ) throws XNIException { errors.add( new SchemaValidationEvent( domain, key, e ) ); public void warning( String domain, String key, XMLParseException e ) throws XNIException { errors.add( new SchemaValidationEvent( domain, key, e ) ); errors.add( new SchemaValidationEvent( e ) );
/** * Validates the specified XML instance document according to the contained schema references ( * <code>xsi:schemaLocation</code> attribute) and/or to the explicitly specified schema references. * * @param source * provides the XML document to be validated, must not be null * @param schemaUris * URIs of schema documents to be considered, can be null (only the <code>xsi:schemaLocation</code> * attribute is considered then) * @return list of validation events (errors/warnings) that occured, never null, size of 0 means valid document */ public static List<SchemaValidationEvent> validate( InputStream source, String... schemaUris ) { return validate( new XMLInputSource( null, null, null, source, null ), schemaUris ); }
/** * Validates the specified XML schema document, additionally in conjunction with more schemas. * * @param inputSchemaUri * provides the XML schema document to be validated, must not be null * @param additionalUris * additional schema documents to be considered, can be null * @return list of validation events (errors/warnings) that occured, never null, size of 0 means valid document */ public static List<String> validateSchema( String inputSchemaUri, String... additionalUris ) { LSInput input = new DOMInputImpl( null, inputSchemaUri, null ); LSInput[] additionalSchemas = new LSInput[additionalUris.length]; for ( int i = 0; i < additionalUris.length; i++ ) { additionalSchemas[i] = new DOMInputImpl( null, additionalUris[i], null ); } return validateSchema( input, additionalSchemas ); }
/** * Returns all namespaces that participate in this infoset. * * @return all namespaces, never <code>null</code> */ public Set<String> getSchemaNamespaces() { return getNSMap().keySet(); }
public XSTypeDefinition getTypeDef( String localName, String namespace ) { return getTypeDef( new QName( namespace, localName ) ); }
public XSElementDeclaration getElementDecl( String localName, String namespace ) { return getElementDecl( new QName( namespace, localName ) ); }
/** * Returns the declarations of all elements that are substitutable for a given element name. * * @param elementName * qualified name of the element, must not be <code>null</code> * @param namespace * only element declarations in this namespace are returned, set to <code>null</code> for all namespaces * @param transitive * if true, also substitutions for substitutions (and so one) are included * @param onlyConcrete * if true, only concrete (non-abstract) declarations are returned * @return the declarations of all substitution elements in the requested namespace */ public List<XSElementDeclaration> getSubstitutions( QName elementName, String namespace, boolean transitive, boolean onlyConcrete ) { XSElementDeclaration elementDecl = nameToElDecl.get( elementName ); if ( elementDecl == null ) { String msg = "The schema does not declare a top-level element with name '" + elementName + "'."; throw new IllegalArgumentException( msg ); } return getSubstitutions( elementDecl, namespace, transitive, onlyConcrete ); }
@Override public XMLInputSource resolveEntity( XMLResourceIdentifier identifier ) throws XNIException, IOException { String systemId = identifier.getExpandedSystemId(); String redirectedSystemId = systemId != null ? redirect( systemId ) : null; LOG.debug( "'" + systemId + "' -> '" + redirectedSystemId + "'" ); return new XMLInputSource( null, redirectedSystemId, null ); }
private static XMLParserConfiguration createValidatingParser( XMLEntityResolver entityResolver, GrammarPool grammarPool ) throws XNIException { XMLParserConfiguration parserConfiguration = null; if ( grammarPool == null ) { parserConfiguration = new XIncludeAwareParserConfiguration(); } else { parserConfiguration = new XIncludeAwareParserConfiguration( grammarPool.getSymbolTable(), grammarPool ); } parserConfiguration.setFeature( NAMESPACES_FEATURE_ID, true ); parserConfiguration.setFeature( VALIDATION_FEATURE_ID, true ); parserConfiguration.setFeature( SCHEMA_VALIDATION_FEATURE_ID, true ); parserConfiguration.setFeature( SCHEMA_FULL_CHECKING_FEATURE_ID, true ); // NOTE: don't set to true, or validation of WFS GetFeature responses will fail (Xerces error?)! parserConfiguration.setFeature( HONOUR_ALL_SCHEMA_LOCATIONS_ID, false ); if ( entityResolver != null ) { parserConfiguration.setEntityResolver( entityResolver ); } return parserConfiguration; } }
/** * Creates a new {@link XMLSchemaInfoSet} instance that reads the schema documents from the given inputs. * * @param inputs * schema documents, must not be <code>null</code> and contain at least one entry * @throws ClassCastException * @throws ClassNotFoundException * @throws InstantiationException * @throws IllegalAccessException */ public XMLSchemaInfoSet( LSInput... inputs ) throws ClassCastException, ClassNotFoundException, InstantiationException, IllegalAccessException { xsModel = loadModel( inputs ); init(); }
/** * Validates the specified XML schema document, additionally in conjunction with more schemas. * * @param inputSchema * provides the XML schema document to be validated, must not be null * @param additionalUris * additional schema documents to be considered, can be null * @return list of validation events (errors/warnings) that occured, never null, size of 0 means valid document */ public static List<String> validateSchema( InputStream inputSchema, String... additionalUris ) { LSInput input = new DOMInputImpl( null, null, null, inputSchema, null ); LSInput[] additionalSchemas = new LSInput[additionalUris.length]; for ( int i = 0; i < additionalUris.length; i++ ) { additionalSchemas[i] = new DOMInputImpl( null, additionalUris[i], null ); } return validateSchema( input, additionalSchemas ); }
@SuppressWarnings("synthetic-access") @Override public void fatalError( String domain, String key, XMLParseException e ) throws XNIException { errors.add( new SchemaValidationEvent( domain, key, e ) ); }
/** * Returns the locations of all schema files that contributed to the given namespace. * * @param namespace * namespace, must not be <code>null</code> * @return the locations of the schema files, or <code>null</code> if the namespace does not belong to the schema */ public List<String> getComponentLocations( String namespace ) { return getNSMap().get( namespace ); }
@SuppressWarnings("synthetic-access") @Override public void warning( String domain, String key, XMLParseException e ) throws XNIException { errors.add( new SchemaValidationEvent( domain, key, e ) ); } } );