zoukankan      html  css  js  c++  java
  • spring 源码分析

    检验 xml scheme 是dtd 还是XSD

    XmlValidationModeDetector

    public class XmlValidationModeDetector {
    
    	/**
    	 * Indicates that the validation should be disabled.
    	 */
    	public static final int VALIDATION_NONE = 0;
    
    	/**
    	 * Indicates that the validation mode should be auto-guessed, since we cannot find
    	 * a clear indication (probably choked on some special characters, or the like).
    	 */
    	public static final int VALIDATION_AUTO = 1;
    
    	/**
    	 * Indicates that DTD validation should be used (we found a "DOCTYPE" declaration).
    	 */
    	public static final int VALIDATION_DTD = 2;
    
    	/**
    	 * Indicates that XSD validation should be used (found no "DOCTYPE" declaration).
    	 */
    	public static final int VALIDATION_XSD = 3;
    
    
    	/**
    	 * The token in a XML document that declares the DTD to use for validation
    	 * and thus that DTD validation is being used.
    	 */
    	private static final String DOCTYPE = "DOCTYPE";
    
    	/**
    	 * The token that indicates the start of an XML comment.
    	 */
    	private static final String START_COMMENT = "<!--";
    
    	/**
    	 * The token that indicates the end of an XML comment.
    	 */
    	private static final String END_COMMENT = "-->";
    
    
    	/**
    	 * Indicates whether or not the current parse position is inside an XML comment.
    	 */
    	private boolean inComment;
    

    看代码 判断很简单 有doctype 为dtd

    没有为xsd

    	public int detectValidationMode(InputStream inputStream) throws IOException {
    		// Peek into the file to look for DOCTYPE.
    		BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
    		try {
    			boolean isDtdValidated = false;
    			String content;
    			while ((content = reader.readLine()) != null) {
    				content = consumeCommentTokens(content);
    				if (this.inComment || !StringUtils.hasText(content)) {
    					continue;
    				}
    				if (hasDoctype(content)) {
    					isDtdValidated = true;
    					break;
    				}
    				if (hasOpeningTag(content)) {
    					// End of meaningful data...
    					break;
    				}
    			}
    			return (isDtdValidated ? VALIDATION_DTD : VALIDATION_XSD);
    		}
    		catch (CharConversionException ex) {
    			// Choked on some character encoding...
    			// Leave the decision up to the caller.
    			return VALIDATION_AUTO;
    		}
    		finally {
    			reader.close();
    		}
    	}
    
  • 相关阅读:
    BZOJ 1251 序列终结者(Splay)
    ZOJ 2112 Dynamic Rankings(动态区间第 k 大+块状链表)
    POJ 2887 Big String(块状链表)
    BZOJ 1093 [ZJOI2007] 最大半连通子图(强联通缩点+DP)
    Codeforces Beta Round #13 C. Sequence (DP)
    Codeforces Round #184 (Div. 2) E. Playing with String(博弈)
    MemSQL start[c]up Round 2
    Codeforces Round #195 A B C 三题合集 (Div. 2)
    哈密尔顿回路总结
    最大团问题
  • 原文地址:https://www.cnblogs.com/itxuexiwang/p/6386256.html
Copyright © 2011-2022 走看看