org.codehaus.stax2.validation.XMLValidator类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(133)

本文整理了Java中org.codehaus.stax2.validation.XMLValidator类的一些代码示例,展示了XMLValidator类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XMLValidator类的具体详情如下:
包路径:org.codehaus.stax2.validation.XMLValidator
类名称:XMLValidator

XMLValidator介绍

[英]Class that defines interface that individual (possibly) stateful validator instances have to implement, and that both javax.xml.stream.XMLStreamReader and javax.xml.stream.XMLStreamWriter instances can call to validate xml documents.

Validator instances are created from and by non-stateful XMLValidationSchema instances. A new validator instance has to be created for each document read or written, ie. can not be shared or reused, unlike schema instances which can be.
[中]类,该类定义了单个(可能)有状态验证器实例必须实现的接口,以及。xml。流动XMLStreamReader和javax。xml。流动XMLStreamWriter实例可以调用验证xml文档。
验证程序实例由非状态XMLValidationSchema实例创建。必须为读取或写入的每个文档创建一个新的验证器实例,即不能共享或重用,而模式实例可以被共享。

代码示例

代码示例来源:origin: org.codehaus.woodstox/woodstox-core-asl

mVldContent = mValidator.validateElementAndAttributes();
  mVldContent = mValidator.validateElementEnd(localName, XmlConsts.ELEM_NO_NS_URI, XmlConsts.ELEM_NO_PREFIX);

代码示例来源:origin: org.codehaus.woodstox/woodstox-core-asl

protected void writeStartOrEmpty(String prefix, String localName, String nsURI)
  throws XMLStreamException
{
  checkStartElement(localName, prefix);
  if (mValidator != null) {
    mValidator.validateElementStart(localName, nsURI, prefix);
  }
  if (mOutputElemPool != null) {
    SimpleOutputElement newCurr = mOutputElemPool;
    mOutputElemPool = newCurr.reuseAsChild(mCurrElem, prefix, localName, nsURI);
    --mPoolSize;
    mCurrElem = newCurr;
  } else {
    mCurrElem = mCurrElem.createChild(prefix, localName, nsURI);
  }
  doWriteStartTag(prefix, localName);
}

代码示例来源:origin: org.codehaus.woodstox/woodstox-core-asl

public final void writeTypedElement(AsciiValueEncoder enc,
                  XMLValidator validator, char[] copyBuffer)
  throws IOException, XMLStreamException
{
  if (mOut == null) {
    return;
  }
  int free = mOutputBufLen - mOutputPtr;
  if (enc.bufferNeedsFlush(free)) {
    flush();
  }
  int start = mOutputPtr;
  while (true) {
    mOutputPtr = enc.encodeMore(mOutputBuffer, mOutputPtr, mOutputBufLen);
    // False -> can't be sure it's the whole remaining text
    validator.validateText(mOutputBuffer, start, mOutputPtr, false);
    if (enc.isCompleted()) {
      break;
    }
    flush();
    start = mOutputPtr;
  }
}

代码示例来源:origin: org.codehaus.woodstox/woodstox-core-asl

/**
 * Method called after parsing (but before returning) end element,
 * to allow for pluggable validators to verify correctness of
 * the content model for the closing element.
 *
 * @return Validation state that should be effective for the parent
 *   element state
 */
public int validateEndElement()
  throws XMLStreamException
{
  if (mValidator == null) { // should never be null if we get here
    return XMLValidator.CONTENT_ALLOW_ANY_TEXT;
  }
  int result =  mValidator.validateElementEnd
    (mCurrElement.mLocalName, mCurrElement.mNamespaceURI, mCurrElement.mPrefix);
  if (mDepth == 1) { // root closing
    mValidator.validationCompleted(true);
  }
  return result;
}

代码示例来源:origin: org.codehaus.woodstox/woodstox-core-asl

public XMLValidator stopValidatingAgainst(XMLValidationSchema schema)
  throws XMLStreamException
{
  XMLValidator[] results = new XMLValidator[2];
  if (ValidatorPair.removeValidator(mValidator, schema, results)) { // found
    XMLValidator found = results[0];
    mValidator = results[1];
    found.validationCompleted(false);
    return found;
  }
  return null;
}

代码示例来源:origin: org.codehaus.woodstox/woodstox-core-asl

/**
 * Validating version of typed write method
 */
public final void writeTypedElement(AsciiValueEncoder enc,
                  XMLValidator validator, char[] copyBuffer)
  throws IOException, XMLStreamException
{
  if (mSurrogate != 0) {
    throwUnpairedSurrogate();
  }
  /* Ok, this gets trickier: can't use efficient direct-to-bytes
   * encoding since validator won't be able to use it. Instead
   * have to use temporary copy buffer.
   */
  final int copyBufferLen = copyBuffer.length;
  // Copy buffer should never be too small, no need to check up front
  do {
    int ptr = enc.encodeMore(copyBuffer, 0, copyBufferLen);
    // False -> can't be sure it's the whole remaining text
    validator.validateText(copyBuffer, 0, ptr, false);
    writeRawAscii(copyBuffer, 0, ptr);
  } while (!enc.isCompleted());
}

代码示例来源:origin: org.codehaus.woodstox/woodstox-core-asl

if (enc.bufferNeedsFlush(free)) {
  flush();
mOutputPtr = enc.encodeMore(mOutputBuffer, mOutputPtr, mOutputBufLen);
if (enc.isCompleted()) { // yup
  validator.validateAttribute(localName, nsURI, prefix, mOutputBuffer, start, mOutputPtr);
  return;
validator.validateAttribute(localName, nsURI, prefix, valueStr);

代码示例来源:origin: org.codehaus.woodstox/woodstox-core-asl

int last = enc.encodeMore(copyBuffer, 0, copyBufferLen);
writeRawAscii(copyBuffer, 0, last);
if (enc.isCompleted()) {
  validator.validateAttribute(localName, nsURI, prefix, copyBuffer, 0, last);
  return;
sb.append(copyBuffer, 0, last);
do {
  last = enc.encodeMore(copyBuffer, 0, copyBufferLen);
  writeRawAscii(copyBuffer, 0, last);
  sb.append(copyBuffer, 0, last);
validator.validateAttribute(localName, nsURI, prefix, valueStr);

代码示例来源:origin: org.codehaus.woodstox/woodstox-core-asl

public final void validateText(String contents, boolean lastTextSegment)
  throws XMLStreamException
{
  mValidator.validateText(contents, lastTextSegment);
}

代码示例来源:origin: org.codehaus.woodstox/woodstox-core-asl

/**
 * Default implementation just indicates it does not know of such
 * attributes; this because that requires DTD information that only
 * some implementations have.
 */
public final int getIdAttributeIndex()
{
  if (mIdAttrIndex >= 0) {
    return mIdAttrIndex;
  }
  return (mValidator == null) ? -1 : mValidator.getIdAttrIndex();
}

代码示例来源:origin: org.codehaus.woodstox/woodstox-core-asl

/**
 * Default implementation just indicates it does not know of such
 * attributes; this because that requires DTD information that only
 * some implementations have.
 */
public final int getNotationAttributeIndex()
{
  return (mValidator == null) ? -1 :
    mValidator.getNotationAttrIndex();
}

代码示例来源:origin: org.codehaus.woodstox/woodstox-core-asl

/**
   * @return Schema (DTD, RNG, W3C Schema) based type of the attribute
   *   in specified index
   */
  public final String getAttributeType(int index)
  {
    if (index == mIdAttrIndex && index >= 0) { // second check to ensure -1 is not passed
      return "ID";
    }
    return (mValidator == null) ? WstxInputProperties.UNKNOWN_ATTR_TYPE : 
      mValidator.getAttributeType(index);
  }
}

代码示例来源:origin: org.codehaus.woodstox/woodstox-core-asl

mValidator.validateAttribute(localName, XmlConsts.ATTR_NO_NS_URI, XmlConsts.ATTR_NO_PREFIX, value);

代码示例来源:origin: org.codehaus.woodstox/woodstox-core-asl

vld.validateElementStart
  (mCurrElement.mLocalName, mCurrElement.mNamespaceURI, mCurrElement.mPrefix);
return mValidator.validateElementAndAttributes();

代码示例来源:origin: woodstox/wstx-asl

public int validateElementEnd(String localName, String uri, String prefix)
  throws XMLValidationException
{
  int textType1 = mFirst.validateElementEnd(localName, uri, prefix);
  int textType2 = mSecond.validateElementEnd(localName, uri, prefix);
  // As with earlier, let's return stricter of the two
  return (textType1 < textType2) ? textType1 : textType2;
}

代码示例来源:origin: woodstox/wstx-asl

public static boolean removeValidator(XMLValidator root, XMLValidationSchema schema, XMLValidator[] results)
{
  if (root instanceof ValidatorPair) {
    return ((ValidatorPair) root).doRemoveValidator(schema, results);
  } else {
    if (root.getSchema() == schema) {
      results[0] = root;
      results[1] = null;
      return true;
    }
  }
  return false;
}

代码示例来源:origin: woodstox/wstx-asl

public int validateElementAndAttributes()
  throws XMLValidationException
{
  int textType1 = mFirst.validateElementAndAttributes();
  int textType2 = mSecond.validateElementAndAttributes();
  /* Here, let's choose the stricter (more restrictive) of the two.
   * Since constants are order from strictest to most lenient,
   * we'll just take smaller of values
   */
  return (textType1 < textType2) ? textType1 : textType2;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.woodstox

/**
 * Returns type of schema that was used to construct this
 * validator instance.
 *
 * @return One of external schema identifier values (such as
 *   {@link XMLValidationSchema#SCHEMA_ID_DTD}).
 */
public String getSchemaType() {
  XMLValidationSchema sch = getSchema();
  return (sch == null) ? null : sch.getSchemaType();
}

代码示例来源:origin: org.codehaus.woodstox/woodstox-core-asl

public XMLValidator stopValidatingAgainst(XMLValidator validator)
  throws XMLStreamException
{
  XMLValidator[] results = new XMLValidator[2];
  if (ValidatorPair.removeValidator(mValidator, validator, results)) { // found
    XMLValidator found = results[0];
    mValidator = results[1];
    found.validationCompleted(false);
    return found;
  }
  return null;
}

代码示例来源:origin: com.fasterxml.woodstox/woodstox-core

/**
 * Validating version of typed write method
 */
@Override
public final void writeTypedElement(AsciiValueEncoder enc,
    XMLValidator validator, char[] copyBuffer)
  throws IOException, XMLStreamException
{
  if (mSurrogate != 0) {
    throwUnpairedSurrogate();
  }
  /* Ok, this gets trickier: can't use efficient direct-to-bytes
   * encoding since validator won't be able to use it. Instead
   * have to use temporary copy buffer.
   */
  final int copyBufferLen = copyBuffer.length;
  // Copy buffer should never be too small, no need to check up front
  do {
    int ptr = enc.encodeMore(copyBuffer, 0, copyBufferLen);
    // False -> can't be sure it's the whole remaining text
    validator.validateText(copyBuffer, 0, ptr, false);
    writeRawAscii(copyBuffer, 0, ptr);
  } while (!enc.isCompleted());
}

相关文章