• 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();
    		}
    	}
    
  • 相关阅读:
    stm32 SPI DMA读取ADS8345数据
    Minigui3.0.12完美安装,折腾了一天。终于看到了
    qvfb2的安装,在ubuntu10.4上安装成功
    户口从杭州人才市场迁移到武汉万科魅力之城的过程
    禁止minigui 3.0的屏幕保护
    想穿越回到儿时记录那些幸福
    TIM2定时闪灯程序。。。
    关于minigui的皮肤控件无法显示问题
    插件框架内核的设计
    用“序列图”描述技术方案
  • 原文地址:https://www.cnblogs.com/itxuexiwang/p/6386256.html
Copyright © 2020-2023  润新知