当前位置: 首页>>代码示例>>Java>>正文


Java ValidatorHandler.setContentHandler方法代码示例

本文整理汇总了Java中javax.xml.validation.ValidatorHandler.setContentHandler方法的典型用法代码示例。如果您正苦于以下问题:Java ValidatorHandler.setContentHandler方法的具体用法?Java ValidatorHandler.setContentHandler怎么用?Java ValidatorHandler.setContentHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.xml.validation.ValidatorHandler的用法示例。


在下文中一共展示了ValidatorHandler.setContentHandler方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseAndValidate

import javax.xml.validation.ValidatorHandler; //导入方法依赖的package包/类
private void parseAndValidate(InputStream input, Schema schema) throws XmlParseException, IOException {
    ValidatorHandler vHandler = schema.newValidatorHandler();
    vHandler.setContentHandler(this);
    vHandler.setErrorHandler(this);

    InputSource is = new InputSource(new InputStreamReader(input, "UTF-8"));
    is.setEncoding("UTF-8");

    try {
        XMLReader parser = XMLReaderFactory.createXMLReader();
        parser.setContentHandler(vHandler);
        parser.setErrorHandler(this);

        vHandler.setFeature("http://apache.org/xml/features/continue-after-fatal-error", false);

        parser.setFeature("http://apache.org/xml/features/validation/id-idref-checking", false);
        parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error", false);
        parser.setFeature("http://xml.org/sax/features/external-general-entities", false);
        parser.setFeature("http://xml.org/sax/features/external-parameter-entities", false);

        parser.parse(is);
    } catch (SAXException e) {
        throw new XmlParseException(e.getMessage(), e);
    }
}
 
开发者ID:inbloom,项目名称:secure-data-service,代码行数:26,代码来源:EdfiRecordParserImpl2.java

示例2: parseAndAssertInstance

import javax.xml.validation.ValidatorHandler; //导入方法依赖的package包/类
private XmlConfigHandler parseAndAssertInstance(String xmlInstance) throws SAXException, IOException {
    InputStream schemaStream = XmlConfigHandlerTest.class.getResourceAsStream(CONFIG_TEST_2_XSD);

    XMLSchemaFactory xmlSchemaFactory = new XMLSchemaFactory();
    Schema schema = xmlSchemaFactory.newSchema(new StreamSource(schemaStream));

    ValidatorHandler validatorHandler = schema.newValidatorHandler();
    final TypeInfoProvider typeInfoProvider = validatorHandler.getTypeInfoProvider();
    XmlConfigHandler xmlConfigHandler = new XmlConfigHandler(typeInfoProvider);
    validatorHandler.setContentHandler(xmlConfigHandler);

    XMLReader parser = XMLReaderFactory.createXMLReader();
    parser.setContentHandler(validatorHandler);
    InputStream xmlStream = XmlConfigHandlerTest.class.getResourceAsStream(xmlInstance);
    parser.parse(new InputSource(xmlStream));

    assertInstance(validatorHandler, xmlConfigHandler, xmlInstance);
    return xmlConfigHandler;
}
 
开发者ID:avast,项目名称:syringe,代码行数:20,代码来源:XmlConfigHandlerTest.java

示例3: readTypeForProperty

import javax.xml.validation.ValidatorHandler; //导入方法依赖的package包/类
private TypeInfo readTypeForProperty(final String propertyName) throws SAXException, IOException {
    InputStream schemaStream = XmlConfigHandlerTest.class.getResourceAsStream(CONFIG_TEST_2_XSD);

    XMLSchemaFactory xmlSchemaFactory = new XMLSchemaFactory();
    Schema schema = xmlSchemaFactory.newSchema(new StreamSource(schemaStream));

    final AtomicReference<TypeInfo> propertyTypeInfo = new AtomicReference<TypeInfo>();

    ValidatorHandler validatorHandler = schema.newValidatorHandler();
    final TypeInfoProvider typeInfoProvider = validatorHandler.getTypeInfoProvider();
    validatorHandler.setContentHandler(new DefaultHandler() {
        @Override
        public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
            if (propertyName.equals(localName)) {
                propertyTypeInfo.set(typeInfoProvider.getElementTypeInfo());
            }
        }
    });

    XMLReader parser = XMLReaderFactory.createXMLReader();
    parser.setContentHandler(validatorHandler);
    InputStream xmlStream = XmlConfigHandlerTest.class.getResourceAsStream(CONFIG_TEST_2_XML);
    parser.parse(new InputSource(xmlStream));

    return propertyTypeInfo.get();
}
 
开发者ID:avast,项目名称:syringe,代码行数:27,代码来源:XmlConfigHandlerTest.java

示例4: test

import javax.xml.validation.ValidatorHandler; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
    XMLReader xmlReader = createXMLReader();
    final ValidatorHandler validatorHandler = createValidatorHandler(XSD);
    xmlReader.setContentHandler(validatorHandler);

    DefaultHandler handler = new DefaultHandler() {
        public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
            if (!"ns:test".equals(qName)) {
                return;
            }

            TypeInfoProvider infoProvider = validatorHandler.getTypeInfoProvider();
            if (infoProvider == null) {
                throw new SAXException("Can't obtain TypeInfoProvider object.");
            }

            int index = attributes.getIndex("id");
            if (index == -1) {
                throw new SAXException("The attribute 'id' is not in the list.");
            }

            Assert.assertTrue(infoProvider.isSpecified(index));

            index = attributes.getIndex("date");
            if (index == -1) {
                throw new SAXException("The attribute 'date' is not in the list.");
            }

            Assert.assertFalse(infoProvider.isSpecified(index));

            System.out.println("OK");
        }
    };
    validatorHandler.setContentHandler(handler);

    parse(xmlReader, XML);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:39,代码来源:Bug4970951.java

示例5: test1

import javax.xml.validation.ValidatorHandler; //导入方法依赖的package包/类
@Test
public void test1() throws Exception {
    XMLReader xmlReader = createXMLReader();
    final ValidatorHandler validatorHandler = createValidatorHandler(XSD);
    xmlReader.setContentHandler(validatorHandler);

    DefaultHandler handler = new DefaultHandler() {
        public void characters(char[] ch, int start, int length) throws SAXException {
            TypeInfoProvider infoProvider = null;
            synchronized (validatorHandler) {
                infoProvider = validatorHandler.getTypeInfoProvider();
            }
            if (infoProvider == null) {
                Assert.fail("Can't obtain TypeInfo object.");
            }

            try {
                infoProvider.getElementTypeInfo();
                Assert.fail("IllegalStateException was not thrown.");
            } catch (IllegalStateException e) {
                // as expected
                System.out.println("OK");
            }
        }
    };
    validatorHandler.setContentHandler(handler);

    parse(xmlReader, XML);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:Bug4969732.java

示例6: testContentHandler

import javax.xml.validation.ValidatorHandler; //导入方法依赖的package包/类
@Test
public void testContentHandler() {
    ValidatorHandler validatorHandler = getValidatorHandler();
    assertNull(validatorHandler.getContentHandler(), "When ValidatorHandler is created, initially ContentHandler should not be set.");

    ContentHandler handler = new DefaultHandler();
    validatorHandler.setContentHandler(handler);
    assertSame(validatorHandler.getContentHandler(), handler);

    validatorHandler.setContentHandler(null);
    assertNull(validatorHandler.getContentHandler());

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:ValidatorHandlerTest.java

示例7: XmlAligner

import javax.xml.validation.ValidatorHandler; //导入方法依赖的package包/类
public XmlAligner(ValidatorHandler psviProvidingValidatorHandler) {
	this((PSVIProvider)psviProvidingValidatorHandler);
	psviProvidingValidatorHandler.setContentHandler(this);
}
 
开发者ID:ibissource,项目名称:iaf,代码行数:5,代码来源:XmlAligner.java

示例8: ToXml

import javax.xml.validation.ValidatorHandler; //导入方法依赖的package包/类
public ToXml(ValidatorHandler validatorHandler) {
	super((PSVIProvider)validatorHandler);
	validatorHandler.setContentHandler(this);
	this.validatorHandler=validatorHandler;
}
 
开发者ID:ibissource,项目名称:iaf,代码行数:6,代码来源:ToXml.java

示例9: parseAndValidate

import javax.xml.validation.ValidatorHandler; //导入方法依赖的package包/类
@Override
protected void parseAndValidate(InputStream input, ValidatorHandler vHandler) throws XmlParseException, IOException {
    vHandler.setContentHandler(this);

    super.parseAndValidate(input, vHandler);
}
 
开发者ID:inbloom,项目名称:secure-data-service,代码行数:7,代码来源:EdfiRecordUnmarshaller.java


注:本文中的javax.xml.validation.ValidatorHandler.setContentHandler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。