类 XmlValidationModeDetector

java.lang.Object
cn.taketoday.util.xml.XmlValidationModeDetector

public class XmlValidationModeDetector extends Object
Detects whether an XML stream is using DTD- or XSD-based validation.
从以下版本开始:
4.0
作者:
Rob Harrop, Juergen Hoeller, Sam Brannen
  • 字段概要

    字段
    修饰符和类型
    字段
    说明
    private static final String
    The token in an XML document that declares the DTD to use for validation and thus that DTD validation is being used.
    private static final String
    The token that indicates the end of an XML comment.
    private boolean
    Indicates whether or not the current parse position is inside an XML comment.
    private static final String
    The token that indicates the start of an XML comment.
    static final int
    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).
    static final int
    Indicates that DTD validation should be used (we found a "DOCTYPE" declaration).
    static final int
    Indicates that the validation should be disabled.
    static final int
    Indicates that XSD validation should be used (found no "DOCTYPE" declaration).
  • 构造器概要

    构造器
    构造器
    说明
     
  • 方法概要

    修饰符和类型
    方法
    说明
    private int
    commentToken(String line, String token, boolean inCommentIfPresent)
    Try to consume the supplied token against the supplied content and update the "in comment" parse state to the supplied value.
    private String
    Consume the next comment token, update the "inComment" flag, and return the remaining content.
    private String
    Consume all comments in the given String and return the remaining content, which may be empty since the supplied content might be all comment data.
    int
    Detect the validation mode for the XML document in the supplied InputStream.
    private int
    Try to consume the END_COMMENT token.
    private boolean
    hasDoctype(String content)
    Does the content contain the DTD DOCTYPE declaration?
    private boolean
    Determine if the supplied content contains an XML opening tag.
    private int
    Try to consume the START_COMMENT token.

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 字段详细资料

    • VALIDATION_NONE

      public static final int VALIDATION_NONE
      Indicates that the validation should be disabled.
      另请参阅:
    • VALIDATION_AUTO

      public static final int VALIDATION_AUTO
      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).
      另请参阅:
    • VALIDATION_DTD

      public static final int VALIDATION_DTD
      Indicates that DTD validation should be used (we found a "DOCTYPE" declaration).
      另请参阅:
    • VALIDATION_XSD

      public static final int VALIDATION_XSD
      Indicates that XSD validation should be used (found no "DOCTYPE" declaration).
      另请参阅:
    • DOCTYPE

      private static final String DOCTYPE
      The token in an XML document that declares the DTD to use for validation and thus that DTD validation is being used.
      另请参阅:
    • START_COMMENT

      private static final String START_COMMENT
      The token that indicates the start of an XML comment.
      另请参阅:
    • END_COMMENT

      private static final String END_COMMENT
      The token that indicates the end of an XML comment.
      另请参阅:
    • inComment

      private boolean inComment
      Indicates whether or not the current parse position is inside an XML comment.
  • 构造器详细资料

    • XmlValidationModeDetector

      public XmlValidationModeDetector()
  • 方法详细资料

    • detectValidationMode

      public int detectValidationMode(InputStream inputStream) throws IOException
      Detect the validation mode for the XML document in the supplied InputStream.

      Note that the supplied InputStream is closed by this method before returning.

      参数:
      inputStream - the InputStream to parse
      抛出:
      IOException - in case of I/O failure
      另请参阅:
    • hasDoctype

      private boolean hasDoctype(String content)
      Does the content contain the DTD DOCTYPE declaration?
    • hasOpeningTag

      private boolean hasOpeningTag(String content)
      Determine if the supplied content contains an XML opening tag.

      It is expected that all comment tokens will have been consumed for the supplied content before passing the remainder to this method. However, as a sanity check, if the parse state is currently in an XML comment this method always returns false.

    • consumeCommentTokens

      private String consumeCommentTokens(String line)
      Consume all comments in the given String and return the remaining content, which may be empty since the supplied content might be all comment data.

      This method takes the current "in comment" parsing state into account.

    • consume

      @Nullable private String consume(String line)
      Consume the next comment token, update the "inComment" flag, and return the remaining content.
    • startComment

      private int startComment(String line)
      Try to consume the START_COMMENT token.
      另请参阅:
    • endComment

      private int endComment(String line)
      Try to consume the END_COMMENT token.
      另请参阅:
    • commentToken

      private int commentToken(String line, String token, boolean inCommentIfPresent)
      Try to consume the supplied token against the supplied content and update the "in comment" parse state to the supplied value.

      Returns the index into the content which is after the token or -1 if the token is not found.