• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ValidatorHandler类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: newValidator

import javax.xml.validation.ValidatorHandler; //导入依赖的package包/类
public ValidatorHandler newValidator() {
    synchronized(this) {
        if(schema==null) {
            try {
                // do not disable secure processing - these are well-known schemas
                SchemaFactory sf = XmlFactory.createSchemaFactory(XMLConstants.W3C_XML_SCHEMA_NS_URI, false);
                schema = allowExternalAccess(sf, "file", false).newSchema(source);
            } catch (SAXException e) {
                // we make sure that the schema is correct before we ship.
                throw new AssertionError(e);
            }
        }
    }

    ValidatorHandler handler = schema.newValidatorHandler();
    return handler;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:SchemaCache.java


示例2: apply

import javax.xml.validation.ValidatorHandler; //导入依赖的package包/类
/**
 * Applies the additional binding customizations.
 */
public void apply(XSSchemaSet schema, ErrorReceiver errorReceiver) {
    if(topLevel!=null) {
        this.errorReceiver = errorReceiver;
        Unmarshaller u =  BindInfo.getCustomizationUnmarshaller();
        this.unmarshaller = u.getUnmarshallerHandler();
        ValidatorHandler v = BindInfo.bindingFileSchema.newValidator();
        v.setErrorHandler(errorReceiver);
        loader = new ForkContentHandler(v,unmarshaller);

        topLevel.applyAll(schema.getSchemas());

        this.loader = null;
        this.unmarshaller = null;
        this.errorReceiver = null;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:SCDBasedBindingSet.java


示例3: test1

import javax.xml.validation.ValidatorHandler; //导入依赖的package包/类
@Test
public void test1() throws Exception {
    SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
    ValidatorHandler validatorHandler = schemaFactory.newSchema().newValidatorHandler();

    try {
        validatorHandler.getFeature("unknown1234");
        Assert.fail("SAXNotRecognizedException was not thrown.");
    } catch (SAXNotRecognizedException e) {
        ; // expected
    }

    if (!validatorHandler.getFeature("http://xml.org/sax/features/namespace-prefixes")) {
        // as expected
        System.out.println("getFeature(namespace-prefixes): OK");
    } else {
        Assert.fail("Expected false, returned true.");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:Bug4970380.java


示例4: newValidator

import javax.xml.validation.ValidatorHandler; //导入依赖的package包/类
public ValidatorHandler newValidator() {
        synchronized(this) {
            if(schema==null) {
                try {
                    schema = SchemaFactory.newInstance(WellKnownNamespace.XML_SCHEMA).newSchema(source);
                } catch (SAXException e) {
                    // we make sure that the schema is correct before we ship.
                    throw new AssertionError(e);
                }
            }
        }

        ValidatorHandler handler = schema.newValidatorHandler();
//        fixValidatorBug6246922(handler);

        return handler;
    }
 
开发者ID:alexkasko,项目名称:openjdk-icedtea7,代码行数:18,代码来源:SchemaCache.java


示例5: apply

import javax.xml.validation.ValidatorHandler; //导入依赖的package包/类
/**
 * Applies the additional binding customizations.
 */
public void apply(XSSchemaSet schema, ErrorReceiver errorReceiver) {
    if(topLevel!=null) {
        this.errorReceiver = errorReceiver;
        UnmarshallerImpl u = BindInfo.getJAXBContext().createUnmarshaller();
        this.unmarshaller = u.getUnmarshallerHandler();
        ValidatorHandler v = BindInfo.bindingFileSchema.newValidator();
        v.setErrorHandler(errorReceiver);
        loader = new ForkContentHandler(v,unmarshaller);

        topLevel.applyAll(schema.getSchemas());

        this.loader = null;
        this.unmarshaller = null;
        this.errorReceiver = null;
    }
}
 
开发者ID:alexkasko,项目名称:openjdk-icedtea7,代码行数:20,代码来源:SCDBasedBindingSet.java


示例6: translate

import javax.xml.validation.ValidatorHandler; //导入依赖的package包/类
public static void translate(String xml, URL schemaURL, DocumentContainer documentContainer) throws SAXException, IOException {

		// create the ValidatorHandler
    	SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
		Schema schema = sf.newSchema(schemaURL); 
		ValidatorHandler validatorHandler = schema.newValidatorHandler();
 	
    	// create the parser, setup the chain
    	XMLReader parser = new SAXParser();
    	XmlAligner aligner = new XmlAligner(validatorHandler);
    	XmlTo<DocumentContainer> xml2object = new XmlTo<DocumentContainer>(aligner, documentContainer);   	
    	parser.setContentHandler(validatorHandler);
    	aligner.setContentHandler(xml2object);
	
    	// start translating
    	InputSource is = new InputSource(new StringReader(xml));
		parser.parse(is);
	}
 
开发者ID:ibissource,项目名称:iaf,代码行数:19,代码来源:XmlTo.java


示例7: parseAndValidate

import javax.xml.validation.ValidatorHandler; //导入依赖的package包/类
/**
 * Parse and Validate an XML represented by the input stream against provided XSD and reports validation issues.
 *
 * @param input XML to parse and validate
 * @param vHandler Validator handler
 * @throws IOException If a IO error occurs during XML parsing.
 * @throws XmlParseException If a SAX error occurs during XML parsing.
 */
protected void parseAndValidate(InputStream input, ValidatorHandler vHandler) throws XmlParseException, IOException {
    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);

        // Commented out the following line, as Java 1.6.0_45 throws an exception on this.
        //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,代码行数:33,代码来源:EdfiRecordParser.java


示例8: 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


示例9: 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


示例10: assertInstance

import javax.xml.validation.ValidatorHandler; //导入依赖的package包/类
private void assertInstance(ValidatorHandler validatorHandler, XmlConfigHandler xmlConfigHandler, String xmlInstance) throws SAXException, IOException {

        Map<String,Property> properties = xmlConfigHandler.getProperties();
        Assert.assertEquals(4, properties.size());
        Assert.assertEquals("port", properties.get("port").getName());
        Assert.assertEquals("100", properties.get("port").getValues().get(0).getValue());
        Assert.assertEquals("ref", properties.get("ref").getName());
        Assert.assertEquals("FileRepHandler", properties.get("ref").getValues().get(0).getValue());
        Assert.assertEquals("com.avast.cloud.RequestHandler", (properties.get("ref").getValues().get(0)).getRefType());
        Assert.assertEquals("list", properties.get("list").getName());
        Assert.assertEquals("aaa", properties.get("list").getValues().get(0).getValue());
        Assert.assertEquals("bbb", properties.get("list").getValues().get(1).getValue());
        Assert.assertEquals("ccc", properties.get("list").getValues().get(2).getValue());
        Assert.assertEquals("map", properties.get("map").getName());
        Assert.assertEquals("a", ((MapEntry)properties.get("map").getValues().get(0)).getKey());
        Assert.assertEquals("1", properties.get("map").getValues().get(0).getValue());
        Assert.assertEquals("b", ((MapEntry)properties.get("map").getValues().get(1)).getKey());
        Assert.assertEquals("2", properties.get("map").getValues().get(1).getValue());
        Assert.assertEquals("c", ((MapEntry)properties.get("map").getValues().get(2)).getKey());
        Assert.assertEquals("3", properties.get("map").getValues().get(2).getValue());
    }
 
开发者ID:avast,项目名称:syringe,代码行数:22,代码来源:XmlConfigHandlerTest.java


示例11: 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


示例12: parseAndGetConfig

import javax.xml.validation.ValidatorHandler; //导入依赖的package包/类
/**
 * Parses an xml config file and returns a Config object.
 *
 * @param xmlFile
 *        The xml config file which is passed by the user to annotation processing
 * @return
 *        A non null Config object
 */
private Config parseAndGetConfig (File xmlFile, ErrorHandler errorHandler, boolean disableSecureProcessing) throws SAXException, IOException {
    XMLReader reader;
    try {
        SAXParserFactory factory = XmlFactory.createParserFactory(disableSecureProcessing);
        reader = factory.newSAXParser().getXMLReader();
    } catch (ParserConfigurationException e) {
        // in practice this will never happen
        throw new Error(e);
    }
    NGCCRuntimeEx runtime = new NGCCRuntimeEx(errorHandler);

    // set up validator
    ValidatorHandler validator = configSchema.newValidator();
    validator.setErrorHandler(errorHandler);

    // the validator will receive events first, then the parser.
    reader.setContentHandler(new ForkContentHandler(validator,runtime));

    reader.setErrorHandler(errorHandler);
    Config config = new Config(runtime);
    runtime.setRootHandler(config);
    reader.parse(new InputSource(xmlFile.toURL().toExternalForm()));
    runtime.reset();

    return config;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:35,代码来源:ConfigReader.java


示例13: newValidator

import javax.xml.validation.ValidatorHandler; //导入依赖的package包/类
public ValidatorHandler newValidator() {
    if (schema==null) {
        synchronized (this) {
            if (schema == null) {

                ResourceResolver resourceResolver = null;
                try (InputStream is = clazz.getResourceAsStream(resourceName)) {

                    StreamSource source = new StreamSource(is);
                    source.setSystemId(resourceName);
                    // do not disable secure processing - these are well-known schemas

                    SchemaFactory sf = XmlFactory.createSchemaFactory(XMLConstants.W3C_XML_SCHEMA_NS_URI, false);
                    SchemaFactory schemaFactory = allowExternalAccess(sf, "file", false);

                    if (createResolver) {
                        resourceResolver = new ResourceResolver(clazz);
                        schemaFactory.setResourceResolver(resourceResolver);
                    }
                    schema = schemaFactory.newSchema(source);

                } catch (IOException | SAXException e) {
                    InternalError ie = new InternalError(e.getMessage());
                    ie.initCause(e);
                    throw ie;
                } finally {
                    if (resourceResolver != null) resourceResolver.closeStreams();
                }
            }
        }
    }
    return schema.newValidatorHandler();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:SchemaCache.java


示例14: test1

import javax.xml.validation.ValidatorHandler; //导入依赖的package包/类
@Test
public void test1() throws Exception {
    SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
    ValidatorHandler validatorHandler = schemaFactory.newSchema().newValidatorHandler();
    validatorHandler.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
    validatorHandler.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:Bug4970400.java


示例15: test

import javax.xml.validation.ValidatorHandler; //导入依赖的package包/类
@Test
public void test() throws Exception {
    SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
    ValidatorHandler validatorHandler = schemaFactory.newSchema().newValidatorHandler();
    try {
        validatorHandler.setFeature(null, false);
        Assert.fail("should report an error");
    } catch (NullPointerException e) {
        ; // expected
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:Bug4970383.java


示例16: createValidatorHandler

import javax.xml.validation.ValidatorHandler; //导入依赖的package包/类
private ValidatorHandler createValidatorHandler(String xsd) throws SAXException {
    SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");

    StringReader reader = new StringReader(xsd);
    StreamSource xsdSource = new StreamSource(reader);

    Schema schema = schemaFactory.newSchema(xsdSource);
    return schema.newValidatorHandler();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:Bug4970402.java


示例17: test1

import javax.xml.validation.ValidatorHandler; //导入依赖的package包/类
@Test
public void test1() throws Exception {
    SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");

    ValidatorHandler validatorHandler = schemaFactory.newSchema().newValidatorHandler();

    try {
        validatorHandler.getFeature(null);
        Assert.fail();
    } catch (NullPointerException e) {
        e.printStackTrace();
        ; // as expected
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:Bug4971607.java


示例18: 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


示例19: createValidatorHandler

import javax.xml.validation.ValidatorHandler; //导入依赖的package包/类
private ValidatorHandler createValidatorHandler(String xsd) throws SAXException {
    SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");

    InputStreamReader reader = new InputStreamReader(new ByteArrayInputStream(xsd.getBytes()));
    StreamSource xsdSource = new StreamSource(reader);

    Schema schema = schemaFactory.newSchema(xsdSource);
    return schema.newValidatorHandler();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:Bug6509668.java


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ExceptionHandlingAsyncTaskExecutor类代码示例发布时间:2022-05-21
下一篇:
Java TestingCluster类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap