public void cacheGrammars(String grammarType, Grammar[] grammars) { if(!fPoolIsLocked) { for (int i = 0; i < grammars.length; i++) { if(DEBUG) { System.out.println("CACHED GRAMMAR " + (i+1) ) ; Grammar temp = grammars[i] ; //print(temp.getGrammarDescription()); } putGrammar(grammars[i]); } } } // cacheGrammars(String, Grammar[]);
/** * @see org.apache.xerces.util.XMLGrammarPoolImpl#putGrammar(org.apache.xerces.xni.grammars.Grammar) */ @Override public void putGrammar(Grammar grammar) { //Avoid caching any type of XSD grammar if (grammar instanceof org.apache.xerces.impl.xs.SchemaGrammar) { return; } super.putGrammar(grammar); }
XMLGrammarPoolImpl pool = new XMLGrammarPoolImpl(); pool.putGrammar(grammar); XMLSchema11Factory factory = new XMLSchema11Factory(); Schema schema = factory.newSchema(pool); Validator validator = schema.newValidator(); DOMSource source = new DOMSource(document); validator.validate(source);
public void putGrammar(Grammar grammar) { if (grammar == null) return; // we overide this method to perform 'selective' caching of schemas XMLGrammarDescription description = grammar.getGrammarDescription(); if (!fPoolIsLocked && !containsGrammar(grammar.getGrammarDescription())) { // in order to avoid caching the inline schemas // we ensure the literal system id does not end with wsdl // before we attempt to 'put' the grammar String litSysId = description.getLiteralSystemId(); String basSysId = description.getBaseSystemId(); if (litSysId != null && litSysId.endsWith("xsd") && basSysId != null && basSysId.endsWith("wsdl")) { /* * System.out.println("putGramamr : " + * schemaDescription.getNamespace() + ", " + * schemaDescription.getExpandedSystemId() + ", " + * schemaDescription.getBaseSystemId()); */ super.putGrammar(grammar); } } } }
pool.putGrammar(oldGrammar);