xmlschemavalidator.java
来自「JAVA 所有包」· Java 代码 · 共 1,737 行 · 第 1/5 页
JAVA
1,737 行
// Schema Normalization private static final boolean DEBUG_NORMALIZATION = false; // temporary empty string buffer. private final XMLString fEmptyXMLStr = new XMLString(null, 0, -1); // temporary character buffer, and empty string buffer. private static final int BUFFER_SIZE = 20; private final XMLString fNormalizedStr = new XMLString(); private boolean fFirstChunk = true; // got first chunk in characters() (SAX) private boolean fTrailing = false; // Previous chunk had a trailing space private short fWhiteSpace = -1; //whiteSpace: preserve/replace/collapse private boolean fUnionType = false; /** Schema grammar resolver. */ private final XSGrammarBucket fGrammarBucket = new XSGrammarBucket(); private final SubstitutionGroupHandler fSubGroupHandler = new SubstitutionGroupHandler(fGrammarBucket); /** the DV usd to convert xsi:type to a QName */ // REVISIT: in new simple type design, make things in DVs static, // so that we can QNameDV.getCompiledForm() private final XSSimpleType fQNameDV = (XSSimpleType) SchemaGrammar.SG_SchemaNS.getGlobalTypeDecl(SchemaSymbols.ATTVAL_QNAME); private final CMNodeFactory nodeFactory = new CMNodeFactory(); /** used to build content models */ // REVISIT: create decl pool, and pass it to each traversers private final CMBuilder fCMBuilder = new CMBuilder(nodeFactory); // Schema grammar loader private final XMLSchemaLoader fSchemaLoader = new XMLSchemaLoader( fXSIErrorReporter.fErrorReporter, fGrammarBucket, fSubGroupHandler, fCMBuilder); // state /** String representation of the validation root. */ // REVISIT: what do we store here? QName, XPATH, some ID? use rawname now. private String fValidationRoot; /** Skip validation: anything below this level should be skipped */ private int fSkipValidationDepth; /** anything above this level has validation_attempted != full */ private int fNFullValidationDepth; /** anything above this level has validation_attempted != none */ private int fNNoneValidationDepth; /** Element depth: -2: validator not in pipeline; >= -1 current depth. */ private int fElementDepth; /** Seen sub elements. */ private boolean fSubElement; /** Seen sub elements stack. */ private boolean[] fSubElementStack = new boolean[INITIAL_STACK_SIZE]; /** Current element declaration. */ private XSElementDecl fCurrentElemDecl; /** Element decl stack. */ private XSElementDecl[] fElemDeclStack = new XSElementDecl[INITIAL_STACK_SIZE]; /** nil value of the current element */ private boolean fNil; /** nil value stack */ private boolean[] fNilStack = new boolean[INITIAL_STACK_SIZE]; /** notation value of the current element */ private XSNotationDecl fNotation; /** notation stack */ private XSNotationDecl[] fNotationStack = new XSNotationDecl[INITIAL_STACK_SIZE]; /** Current type. */ private XSTypeDefinition fCurrentType; /** type stack. */ private XSTypeDefinition[] fTypeStack = new XSTypeDefinition[INITIAL_STACK_SIZE]; /** Current content model. */ private XSCMValidator fCurrentCM; /** Content model stack. */ private XSCMValidator[] fCMStack = new XSCMValidator[INITIAL_STACK_SIZE]; /** the current state of the current content model */ private int[] fCurrCMState; /** stack to hold content model states */ private int[][] fCMStateStack = new int[INITIAL_STACK_SIZE][]; /** whether the curret element is strictly assessed */ private boolean fStrictAssess = true; /** strict assess stack */ private boolean[] fStrictAssessStack = new boolean[INITIAL_STACK_SIZE]; /** Temporary string buffers. */ private final StringBuffer fBuffer = new StringBuffer(); /** Whether need to append characters to fBuffer */ private boolean fAppendBuffer = true; /** Did we see any character data? */ private boolean fSawText = false; /** stack to record if we saw character data */ private boolean[] fSawTextStack = new boolean[INITIAL_STACK_SIZE]; /** Did we see non-whitespace character data? */ private boolean fSawCharacters = false; /** Stack to record if we saw character data outside of element content*/ private boolean[] fStringContent = new boolean[INITIAL_STACK_SIZE]; /** temporary qname */ private final QName fTempQName = new QName(); /** temporary validated info */ private ValidatedInfo fValidatedInfo = new ValidatedInfo(); // used to validate default/fixed values against xsi:type // only need to check facets, so we set extraChecking to false (in reset) private ValidationState fState4XsiType = new ValidationState(); // used to apply default/fixed values // only need to check id/idref/entity, so we set checkFacets to false private ValidationState fState4ApplyDefault = new ValidationState(); // identity constraint information /** * Stack of active XPath matchers for identity constraints. All * active XPath matchers are notified of startElement * and endElement callbacks in order to perform their matches. * <p> * For each element with identity constraints, the selector of * each identity constraint is activated. When the selector matches * its XPath, then all the fields of the identity constraint are * activated. * <p> * <strong>Note:</strong> Once the activation scope is left, the * XPath matchers are automatically removed from the stack of * active matchers and no longer receive callbacks. */ protected XPathMatcherStack fMatcherStack = new XPathMatcherStack(); /** Cache of value stores for identity constraint fields. */ protected ValueStoreCache fValueStoreCache = new ValueStoreCache(); // // Constructors // /** Default constructor. */ public XMLSchemaValidator() { fState4XsiType.setExtraChecking(false); fState4ApplyDefault.setFacetChecking(false); } // <init>() /* * Resets the component. The component can query the component manager * about any features and properties that affect the operation of the * component. * * @param componentManager The component manager. * * @throws SAXException Thrown by component on finitialization error. * For example, if a feature or property is * required for the operation of the component, the * component manager may throw a * SAXNotRecognizedException or a * SAXNotSupportedException. */ public void reset(XMLComponentManager componentManager) throws XMLConfigurationException { fIdConstraint = false; //reset XSDDescription fLocationPairs.clear(); // cleanup id table fValidationState.resetIDTables(); //pass the component manager to the factory.. nodeFactory.reset(componentManager); // reset schema loader fSchemaLoader.reset(componentManager); // initialize state fCurrentElemDecl = null; fCurrentCM = null; fCurrCMState = null; fSkipValidationDepth = -1; fNFullValidationDepth = -1; fNNoneValidationDepth = -1; fElementDepth = -1; fSubElement = false; fSchemaDynamicValidation = false; // datatype normalization fEntityRef = false; fInCDATA = false; fMatcherStack.clear(); if (!fMayMatchFieldMap.isEmpty()) { // should only clear this if the last schema had identity constraints. fMayMatchFieldMap.clear(); } // get error reporter fXSIErrorReporter.reset((XMLErrorReporter) componentManager.getProperty(ERROR_REPORTER)); boolean parser_settings; try { parser_settings = componentManager.getFeature(PARSER_SETTINGS); } catch (XMLConfigurationException e){ parser_settings = true; } if (!parser_settings){ // parser settings have not been changed fValidationManager.addValidationState(fValidationState); // Re-parse external schema location properties. XMLSchemaLoader.processExternalHints( fExternalSchemas, fExternalNoNamespaceSchema, fLocationPairs, fXSIErrorReporter.fErrorReporter); return; } // get symbol table. if it's a new one, add symbols to it. SymbolTable symbolTable = (SymbolTable) componentManager.getProperty(SYMBOL_TABLE); if (symbolTable != fSymbolTable) { fSymbolTable = symbolTable; } try { fDynamicValidation = componentManager.getFeature(DYNAMIC_VALIDATION); } catch (XMLConfigurationException e) { fDynamicValidation = false; } if (fDynamicValidation) { fDoValidation = true; } else { try { fDoValidation = componentManager.getFeature(VALIDATION); } catch (XMLConfigurationException e) { fDoValidation = false; } } if (fDoValidation) { try { fDoValidation = componentManager.getFeature(XMLSchemaValidator.SCHEMA_VALIDATION); } catch (XMLConfigurationException e) { } } try { fFullChecking = componentManager.getFeature(SCHEMA_FULL_CHECKING); } catch (XMLConfigurationException e) { fFullChecking = false; } try { fNormalizeData = componentManager.getFeature(NORMALIZE_DATA); } catch (XMLConfigurationException e) { fNormalizeData = false; } try { fSchemaElementDefault = componentManager.getFeature(SCHEMA_ELEMENT_DEFAULT); } catch (XMLConfigurationException e) { fSchemaElementDefault = false; } try { fAugPSVI = componentManager.getFeature(SCHEMA_AUGMENT_PSVI); } catch (XMLConfigurationException e) { fAugPSVI = true; } try { fSchemaType = (String) componentManager.getProperty( Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE); } catch (XMLConfigurationException e) { fSchemaType = null; } try { fUseGrammarPoolOnly = componentManager.getFeature(USE_GRAMMAR_POOL_ONLY); } catch (XMLConfigurationException e) { fUseGrammarPoolOnly = false; } fEntityResolver = (XMLEntityResolver) componentManager.getProperty(ENTITY_MANAGER); fValidationManager = (ValidationManager) componentManager.getProperty(VALIDATION_MANAGER); fValidationManager.addValidationState(fValidationState); fValidationState.setSymbolTable(fSymbolTable); // get schema location properties try { fExternalSchemas = (String) componentManager.getProperty(SCHEMA_LOCATION); fExternalNoNamespaceSchema = (String) componentManager.getProperty(SCHEMA_NONS_LOCATION); } catch (XMLConfigurationException e) { fExternalSchemas = null; fExternalNoNamespaceSchema = null; } // store the external schema locations. they are set when reset is called, // so any other schemaLocation declaration for the same namespace will be // effectively ignored. becuase we choose to take first location hint // available for a particular namespace. XMLSchemaLoader.processExternalHints( fExternalSchemas, fExternalNoNamespaceSchema, fLocationPairs, fXSIErrorReporter.fErrorReporter); try { fJaxpSchemaSource = componentManager.getProperty(JAXP_SCHEMA_SOURCE); } catch (XMLConfigurationException e) { fJaxpSchemaSource = null; } // clear grammars, and put the one for schema namespace there try { fGrammarPool = (XMLGrammarPool) componentManager.getProperty(XMLGRAMMAR_POOL);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?