private boolean existingGrammars(Vector grammars) { int length = grammars.size(); final XSDDescription desc = new XSDDescription(); for (int i=0; i < length; i++) { final SchemaGrammar sg1 = (SchemaGrammar)grammars.elementAt(i); desc.setNamespace(sg1.getTargetNamespace()); final SchemaGrammar sg2 = findGrammar(desc, false); if (sg2 != null) { return true; } } return false; }
String loc = null; if (desc.getContextType() == XSDDescription.CONTEXT_IMPORT || desc.fromInstance()) { String namespace = desc.getTargetNamespace(); String ns = namespace == null ? XMLSymbols.EMPTY_STRING : namespace; String[] hints = desc.getLocationHints(); if (hints != null && hints.length > 0) loc = hints[0]; String expandedLoc = XMLEntityManager.expandSystemId(loc, desc.getBaseSystemId(), false); desc.setLiteralSystemId(loc); desc.setExpandedSystemId(expandedLoc); return entityResolver.resolveEntity(desc);
public XMLGrammarDescription getGrammarDescription() { return fGrammarDescription.makeClone(); } // getGrammarDescription(): XMLGrammarDescription
private Element resolveSchema(XMLInputSource schemaSource, XSDDescription desc, boolean mustResolve, Element referElement) { if (schemaSource instanceof DOMInputSource) { return getSchemaDocument(desc.getTargetNamespace(), (DOMInputSource) schemaSource, mustResolve, desc.getContextType(), referElement); } // DOMInputSource else if (schemaSource instanceof SAXInputSource) { return getSchemaDocument(desc.getTargetNamespace(), (SAXInputSource) schemaSource, mustResolve, desc.getContextType(), referElement); } // SAXInputSource else if (schemaSource instanceof StAXInputSource) { return getSchemaDocument(desc.getTargetNamespace(), (StAXInputSource) schemaSource, mustResolve, desc.getContextType(), referElement); } // StAXInputSource else if (schemaSource instanceof XSInputSource) { return getSchemaDocument((XSInputSource) schemaSource, desc); } // XSInputSource return getSchemaDocument(desc.getTargetNamespace(), schemaSource, mustResolve, desc.getContextType(), referElement); }
protected XSDocumentInfo constructTrees(Element schemaRoot, String locationHint, XSDDescription desc, boolean nsCollision) { if (schemaRoot == null) return null; String callerTNS = desc.getTargetNamespace(); short referType = desc.getContextType(); desc.setTargetNamespace(currSchemaInfo.fTargetNamespace); callerTNS = currSchemaInfo.fTargetNamespace; sg = findGrammar(desc, false); if(sg == null) { sg = new SchemaGrammar(currSchemaInfo.fTargetNamespace, desc.makeClone(), fSymbolTable, fSchemaVersion); fGrammarBucket.putGrammar(sg); sg = new SchemaGrammar(currSchemaInfo.fTargetNamespace, desc.makeClone(), fSymbolTable, fSchemaVersion); fGrammarBucket.putGrammar(sg); fSchemaGrammarDescription.reset(); fSchemaGrammarDescription.setContextType(XSDDescription.CONTEXT_IMPORT); fSchemaGrammarDescription.setBaseSystemId(doc2SystemId(schemaRoot)); fSchemaGrammarDescription.setLiteralSystemId(schemaHint); fSchemaGrammarDescription.setLocationHints(new String[]{schemaHint}); fSchemaGrammarDescription.setTargetNamespace(schemaNamespace); if (fNamespaceGrowth) { try { if (isg.getDocumentLocations().contains(XMLEntityManager.expandSystemId(schemaHint, fSchemaGrammarDescription.getBaseSystemId(), false))) { continue; fSchemaGrammarDescription.reset(); fSchemaGrammarDescription.setContextType(refType);
if (mustResolve) { reportSchemaError("schema_reference.4", new Object[]{desc.getLocationHints()[0]}, referElement); new Object[]{desc.getLocationHints()[0]}, referElement); return getSchemaDocument(desc.getTargetNamespace(), (DOMInputSource) schemaSource, mustResolve, desc.getContextType(), referElement); return getSchemaDocument(desc.getTargetNamespace(), (SAXInputSource) schemaSource, mustResolve, desc.getContextType(), referElement); return getSchemaDocument(desc.getTargetNamespace(), (StAXInputSource) schemaSource, mustResolve, desc.getContextType(), referElement); return getSchemaDocument(desc.getTargetNamespace(), schemaSource, mustResolve, desc.getContextType(), referElement);
fXSDDescription.setNamespace(namespace); if (fGrammarPool != null) { grammar = (SchemaGrammar) fGrammarPool.retrieveGrammar(fXSDDescription); fXSDDescription.reset(); fXSDDescription.fContextType = contextType; fXSDDescription.setNamespace(namespace); fXSDDescription.fEnclosedElementName = enclosingElement; fXSDDescription.fTriggeringComponent = triggeringComponent; fXSDDescription.fAttributes = attributes; if (fLocator != null) { fXSDDescription.setBaseSystemId(fLocator.getExpandedSystemId()); final String [] locationHints = fXSDDescription.getLocationHints(); fXSIErrorReporter.fErrorReporter.reportError( XSMessageFormatter.SCHEMA_DOMAIN,
SchemaGrammar grammar = null; String schemaNamespace = null; short referType = desc.getContextType(); grammar = fGrammarBucket.getGrammar(desc.getTargetNamespace()); schemaNamespace = desc.getTargetNamespace(); desc.setTargetNamespace(schemaNamespace);
fXSDDescription.reset(); xis = xsdToXMLInputSource(fJAXPSource); sid = xis.getSystemId(); fXSDDescription.fContextType = XSDDescription.CONTEXT_PREPARSE; if (sid != null) { fXSDDescription.setBaseSystemId(xis.getBaseSystemId()); fXSDDescription.setLiteralSystemId(sid); fXSDDescription.setExpandedSystemId(sid); fXSDDescription.fLocationHints = new String[]{sid}; fXSDDescription.reset(); xis = xsdToXMLInputSource(objArr[i]); sid = xis.getSystemId(); fXSDDescription.fContextType = XSDDescription.CONTEXT_PREPARSE; if (sid != null) { fXSDDescription.setBaseSystemId(xis.getBaseSystemId()); fXSDDescription.setLiteralSystemId(sid); fXSDDescription.setExpandedSystemId(sid); fXSDDescription.fLocationHints = new String[]{sid};
XSDDescription desc = new XSDDescription(); desc.fContextType = XSDDescription.CONTEXT_PREPARSE; desc.setBaseSystemId(source.getBaseSystemId()); desc.setLiteralSystemId( source.getSystemId());
private boolean isExistingGrammar(XSDDescription desc, boolean ignoreConflict) { SchemaGrammar sg = fGrammarBucket.getGrammar(desc.getTargetNamespace()); if (sg == null) { return findGrammar(desc, ignoreConflict) != null; } else if (sg.isImmutable()) { return true; } else { try { return sg.getDocumentLocations().contains(XMLEntityManager.expandSystemId(desc.getLiteralSystemId(), desc.getBaseSystemId(), false)); } catch (MalformedURIException e) { return false; } } }
public XSDHandler (XSGrammarBucket gBucket, short schemaVersion, XSConstraints xsConstraints) { this(schemaVersion, xsConstraints); fGrammarBucket = gBucket; // Note: don't use SchemaConfiguration internally // we will get stack overflaw because // XMLSchemaValidator will be instantiating XSDHandler... fSchemaGrammarDescription = new XSDDescription(); } // end constructor
short referType = desc.getContextType(); addGrammars(expandedGrammars); if (referType == XSDDescription.CONTEXT_PREPARSE) { desc.setTargetNamespace(grammars[0].getTargetNamespace()); addGlobalComponents(expandedComponents, importDependencies); if (referType == XSDDescription.CONTEXT_PREPARSE) { desc.setTargetNamespace(components[0].getNamespace());
private SchemaGrammar getSchemaGrammar(XSDDescription desc) { SchemaGrammar sg = findGrammar(desc, fNamespaceGrowth); if (sg == null) { sg = new SchemaGrammar(desc.getNamespace(), desc.makeClone(), fSymbolTable); fGrammarBucket.putGrammar(sg); } else if (sg.isImmutable()){ sg = createGrammarFrom(sg); } return sg; }
private XMLInputSource resolveSchemaSource(XSDDescription desc, boolean mustResolve, Element referElement, boolean usePairs) { XMLInputSource schemaSource = null; try { Hashtable pairs = usePairs ? fLocationPairs : EMPTY_TABLE; schemaSource = XMLSchemaLoader.resolveDocument(desc, pairs, fEntityResolver); } catch (IOException ex) { if (mustResolve) { reportSchemaError("schema_reference.4", new Object[]{desc.getLocationHints()[0]}, referElement); } else { reportSchemaWarning("schema_reference.4", new Object[]{desc.getLocationHints()[0]}, referElement); } } return schemaSource; }
/** * First try to find a grammar in the bucket, if failed, consult the * grammar pool. If a grammar is found in the pool, then add it (and all * imported ones) into the bucket. */ protected SchemaGrammar findGrammar(XSDDescription desc, boolean ignoreConflict) { SchemaGrammar sg = fGrammarBucket.getGrammar(desc.getTargetNamespace()); if (sg == null) { if (fGrammarPool != null) { sg = (SchemaGrammar)fGrammarPool.retrieveGrammar(desc); if (sg != null) { // put this grammar into the bucket, along with grammars // imported by it (directly or indirectly) if (!fGrammarBucket.putGrammar(sg, true, ignoreConflict)) { // REVISIT: a conflict between new grammar(s) and grammars // in the bucket. What to do? A warning? An exception? reportSchemaWarning("GrammarConflict", null, null); sg = null; } } } } return sg; }
private boolean isValidTargetUriForIncludeOrOverride(String schemaId, String locationHint) { boolean isUriValid = true; try { String expandedLoctionHint = XMLEntityManager.expandSystemId(locationHint, fSchemaGrammarDescription.getBaseSystemId(), false); isUriValid = !("".equals(schemaId) || ((expandedLoctionHint != null) ? expandedLoctionHint.equals(schemaId) : true)); } catch (MalformedURIException ex) { isUriValid = false; } return isUriValid; } // isValidTargetUriForIncludeOrOverride
public XSDDescription makeClone() { XSDDescription desc = new XSDDescription(); desc.fAttributes = this.fAttributes; desc.fBaseSystemId = this.fBaseSystemId; desc.fContextType = this.fContextType; desc.fEnclosedElementName = this.fEnclosedElementName; desc.fExpandedSystemId = this.fExpandedSystemId; desc.fLiteralSystemId = this.fLiteralSystemId; desc.fLocationHints = this.fLocationHints; desc.fPublicId = this.fPublicId; desc.fNamespace = this.fNamespace; desc.fTriggeringComponent = this.fTriggeringComponent; return desc; }
private void addGrammars(Vector grammars) { int length = grammars.size(); XSDDescription desc = new XSDDescription(); for (int i=0; i < length; i++) { final SchemaGrammar sg1 = (SchemaGrammar)grammars.elementAt(i); desc.setNamespace(sg1.getTargetNamespace()); final SchemaGrammar sg2 = findGrammar(desc, fNamespaceGrowth); if (sg1 != sg2) { addGrammarComponents(sg1, sg2); } } }