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();
    		}
    	}
    
  • 相关阅读:
    转 GFlags 使用详解
    printf 格式输出
    XCODE unknown type name __declspec 错误的解决方法
    Boost提示'cl' 不是内部或外部命令,也不是可运行的程序 或批处理文件
    DOLServer
    游戏AI的开发框架组件 behaviac
    mongodb 数据导入和导出
    Makefile经典教程
    g++ 编译动态链接库和静态链接库
    excel 公式
  • 原文地址:https://www.cnblogs.com/itxuexiwang/p/6386256.html
Copyright © 2011-2022 走看看