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();
    		}
    	}
    
  • 相关阅读:
    session验证登陆- 页面跳转
    SQL 语句
    MD5加密
    【JS】布尔逻辑
    一道题
    正则表达式
    被搁置的生活 by刘瑜
    LoadRunner 12下载和安装教程
    Delphi Idhttp Post提交 Aspx/Asp.net 时 500错误的解决办法。
    phpmyadmin 4.x 版本无法看到登录框的处理
  • 原文地址:https://www.cnblogs.com/itxuexiwang/p/6386256.html
Copyright © 2011-2022 走看看