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


Java SAXParser.setProperty方法代码示例

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


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

示例1: newSAXParser

import javax.xml.parsers.SAXParser; //导入方法依赖的package包/类
/**
 * Create a <code>SAXParser</code> configured to support XML Schema and DTD
 * 
 * @param properties
 *            parser specific properties/features
 * @return an XML Schema/DTD enabled <code>SAXParser</code>
 */
public static SAXParser newSAXParser(Properties properties)
		throws ParserConfigurationException, SAXException, SAXNotRecognizedException {

	SAXParserFactory factory = (SAXParserFactory) properties.get("SAXParserFactory");
	SAXParser parser = factory.newSAXParser();
	String schemaLocation = (String) properties.get("schemaLocation");
	String schemaLanguage = (String) properties.get("schemaLanguage");

	try {
		if (schemaLocation != null) {
			parser.setProperty(JAXP_SCHEMA_LANGUAGE, schemaLanguage);
			parser.setProperty(JAXP_SCHEMA_SOURCE, schemaLocation);
		}
	} catch (SAXNotRecognizedException e) {
		log.info(parser.getClass().getName() + ": " + e.getMessage() + " not supported.");
	}
	return parser;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:26,代码来源:GenericParser.java

示例2: configureOldXerces

import javax.xml.parsers.SAXParser; //导入方法依赖的package包/类
/**
 * Configure schema validation as recommended by the JAXP 1.2 spec.
 * The <code>properties</code> object may contains information about
 * the schema local and language. 
 * @param properties parser optional info
 */
private static void configureOldXerces(SAXParser parser, 
                                       Properties properties) 
        throws ParserConfigurationException, 
               SAXNotSupportedException {

    String schemaLocation = (String)properties.get("schemaLocation");
    String schemaLanguage = (String)properties.get("schemaLanguage");

    try{
        if (schemaLocation != null) {
            parser.setProperty(JAXP_SCHEMA_LANGUAGE, schemaLanguage);
            parser.setProperty(JAXP_SCHEMA_SOURCE, schemaLocation);
        }
    } catch (SAXNotRecognizedException e){
        log.info(parser.getClass().getName() + ": " 
                                    + e.getMessage() + " not supported."); 
    }

}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:26,代码来源:XercesParser.java

示例3: newSAXParser

import javax.xml.parsers.SAXParser; //导入方法依赖的package包/类
/**
 * Create a <code>SAXParser</code> configured to support XML Schema and DTD
 * @param properties parser specific properties/features
 * @return an XML Schema/DTD enabled <code>SAXParser</code>
 */
public static SAXParser newSAXParser(Properties properties)
        throws ParserConfigurationException, 
               SAXException,
               SAXNotRecognizedException{ 

    SAXParserFactory factory = 
                    (SAXParserFactory)properties.get("SAXParserFactory");
    SAXParser parser = factory.newSAXParser();
    String schemaLocation = (String)properties.get("schemaLocation");
    String schemaLanguage = (String)properties.get("schemaLanguage");

    try{
        if (schemaLocation != null) {
            parser.setProperty(JAXP_SCHEMA_LANGUAGE, schemaLanguage);
            parser.setProperty(JAXP_SCHEMA_SOURCE, schemaLocation);
        }
    } catch (SAXNotRecognizedException e){
        log.info(parser.getClass().getName() + ": "  
                                    + e.getMessage() + " not supported."); 
    }
    return parser;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:28,代码来源:GenericParser.java

示例4: testCheckSchemaSupport3

import javax.xml.parsers.SAXParser; //导入方法依赖的package包/类
/**
 * Test the default functionality of schema support method. In
 * this case the schema source property is set.
 * @throws Exception If any errors occur.
 */
@Test(dataProvider = "schema-source")
public void testCheckSchemaSupport3(Object schemaSource) throws Exception {
    try {
        SAXParserFactory spf = SAXParserFactory.newInstance();
        spf.setValidating(true);
        spf.setNamespaceAware(true);
        SAXParser sp = spf.newSAXParser();
        sp.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
                W3C_XML_SCHEMA_NS_URI);
        sp.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", schemaSource);
        DefaultHandler dh = new DefaultHandler();
        // Not expect any unrecoverable error here.
        sp.parse(new File(XML_DIR, "test1.xml"), dh);
    } finally {
        if (schemaSource instanceof Closeable) {
            ((Closeable) schemaSource).close();
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:DocumentBuilderFactoryTest.java

示例5: allowFileAccess

import javax.xml.parsers.SAXParser; //导入方法依赖的package包/类
private static SAXParser allowFileAccess(SAXParser saxParser, boolean disableSecureProcessing) throws SAXException {

        // if feature secure processing enabled, nothing to do, file is allowed,
        // or user is able to control access by standard JAXP mechanisms
        if (disableSecureProcessing) {
            return saxParser;
        }

        try {
            saxParser.setProperty(ACCESS_EXTERNAL_SCHEMA, "file");
            LOGGER.log(Level.FINE, Messages.format(Messages.JAXP_SUPPORTED_PROPERTY, ACCESS_EXTERNAL_SCHEMA));
        } catch (SAXException ignored) {
            // nothing to do; support depends on version JDK or SAX implementation
            LOGGER.log(Level.CONFIG, Messages.format(Messages.JAXP_UNSUPPORTED_PROPERTY, ACCESS_EXTERNAL_SCHEMA), ignored);
        }
        return saxParser;
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:JAXPParser.java

示例6: testLargeMaxOccurs

import javax.xml.parsers.SAXParser; //导入方法依赖的package包/类
@Test
public final void testLargeMaxOccurs() {

    String XML_FILE_NAME = "Bug4674384_MAX_OCCURS_Test.xml";

    try {
        // create and initialize the parser
        SAXParserFactory spf = SAXParserFactory.newInstance();
        spf.setNamespaceAware(true);
        spf.setValidating(true);

        SAXParser parser = spf.newSAXParser();
        parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");

        File xmlFile = new File(getClass().getResource(XML_FILE_NAME).getPath());

        parser.parse(xmlFile, new DefaultHandler());
    } catch (Exception e) {
        System.err.println("Failure: File " + XML_FILE_NAME + " was parsed with a large value of maxOccurs.");
        e.printStackTrace();
        Assert.fail("Failure: File " + XML_FILE_NAME + " was parsed with a large value of maxOccurs.  " + e.getMessage());
    }

    System.out.println("Success: File " + XML_FILE_NAME + " was parsed with a large value of maxOccurs.");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:Bug4674384_MAX_OCCURS_Test.java

示例7: configureOldXerces

import javax.xml.parsers.SAXParser; //导入方法依赖的package包/类
/**
 * Configure schema validation as recommended by the JAXP 1.2 spec. The
 * <code>properties</code> object may contains information about the schema
 * local and language.
 * 
 * @param properties
 *            parser optional info
 */
private static void configureOldXerces(SAXParser parser, Properties properties)
		throws ParserConfigurationException, SAXNotSupportedException {

	String schemaLocation = (String) properties.get("schemaLocation");
	String schemaLanguage = (String) properties.get("schemaLanguage");

	try {
		if (schemaLocation != null) {
			parser.setProperty(JAXP_SCHEMA_LANGUAGE, schemaLanguage);
			parser.setProperty(JAXP_SCHEMA_SOURCE, schemaLocation);
		}
	} catch (SAXNotRecognizedException e) {
		log.info(parser.getClass().getName() + ": " + e.getMessage() + " not supported.");
	}

}
 
开发者ID:how2j,项目名称:lazycat,代码行数:25,代码来源:XercesParser.java

示例8: test

import javax.xml.parsers.SAXParser; //导入方法依赖的package包/类
@Test
public void test() throws IOException, SAXException, ParserConfigurationException {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setValidating(false);
    SAXParser parser = factory.newSAXParser();
    parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", XMLConstants.W3C_XML_SCHEMA_NS_URI);

    String filename = XML_DIR + "Bug4848653.xml";
    InputSource is = new InputSource(filenameToURL(filename));
    XMLReader xmlReader = parser.getXMLReader();
    xmlReader.setErrorHandler(new MyErrorHandler());
    xmlReader.parse(is);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:Bug4848653.java

示例9: convert

import javax.xml.parsers.SAXParser; //导入方法依赖的package包/类
public void convert(Reader reader, OutputStream finf) throws Exception {
    InputSource is = new InputSource(reader);

    SAXParser saxParser = getParser();
    SAXDocumentSerializer documentSerializer = getSerializer(finf);

    saxParser.setProperty("http://xml.org/sax/properties/lexical-handler", documentSerializer);
    saxParser.parse(is, documentSerializer);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:XML_SAX_FI.java

示例10: enableFileAccess

import javax.xml.parsers.SAXParser; //导入方法依赖的package包/类
/**
 * Configure the parser to allow access to DTDs on the file system.
 */
private static void enableFileAccess(SAXParser parser) throws SAXNotSupportedException {
    try {
        parser.setProperty("http://javax.xml.XMLConstants/property/accessExternalDTD", "file");
    } catch (SAXNotRecognizedException ignore) {
        // property requires >= JAXP 1.5
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:CLDRConverter.java

示例11: main

import javax.xml.parsers.SAXParser; //导入方法依赖的package包/类
public static void main(String[] args) throws Throwable {
    System.setSecurityManager(new SecurityManager());
    try {
        SAXParserFactory spf = SAXParserFactory.newInstance();
        spf.setNamespaceAware(true);
        spf.setValidating(true);
        SAXParser sp = spf.newSAXParser();
        // The following line shouldn't throw a
        // java.security.AccessControlException.
        sp.setProperty("foo", "bar");
    } catch (SAXNotRecognizedException e) {
        // Ignore this expected exception.
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:15,代码来源:Bug6359330.java

示例12: getXMLReader

import javax.xml.parsers.SAXParser; //导入方法依赖的package包/类
private XMLReader getXMLReader() throws Exception {
    SAXParser parser = spf.newSAXParser();
    parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI);
    parser.setProperty(JAXP_SCHEMA_SOURCE, "catalog.xsd");
    XMLReader catparser = parser.getXMLReader();
    catparser.setErrorHandler(new CatalogErrorHandler());
    return catparser;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:AstroProcessor.java

示例13: createParser

import javax.xml.parsers.SAXParser; //导入方法依赖的package包/类
protected static SAXParser createParser() throws Exception {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);
    spf.setValidating(true);
    SAXParser parser = spf.newSAXParser();
    parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");

    return parser;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:Bug4991946.java

示例14: testProperty06

import javax.xml.parsers.SAXParser; //导入方法依赖的package包/类
/**
 * Test to set and get the declaration-handler.
 *
 * @param saxparser a SAXParser instance.
 * @throws SAXException If any parse errors occur.
 */
@Test(dataProvider = "parser-provider")
public void testProperty06(SAXParser saxparser) throws SAXException {
    MyDeclHandler myDeclHandler = new MyDeclHandler();
    saxparser.setProperty(DECL_HANDLER, myDeclHandler);
    assertTrue(saxparser.getProperty(DECL_HANDLER) instanceof DeclHandler);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:SAXParserTest02.java

示例15: testSystemMaxOccurLimitWithoutSecureProcessing

import javax.xml.parsers.SAXParser; //导入方法依赖的package包/类
public void testSystemMaxOccurLimitWithoutSecureProcessing() {
    if (isSecureMode())
        return; // jaxp secure feature can not be turned off when security
                // manager is present
    try {
        SAXParserFactory spf = SAXParserFactory.newInstance();
        spf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, false);
        spf.setValidating(true);
        setSystemProperty("maxOccurLimit", "2");
        // Set the properties for Schema Validation
        String SCHEMA_LANG = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
        String SCHEMA_TYPE = "http://www.w3.org/2001/XMLSchema";
        // Get the Schema location as a File object
        File schemaFile = new File(this.getClass().getResource("toys.xsd").toURI());
        // Get the parser
        SAXParser parser = spf.newSAXParser();
        parser.setProperty(SCHEMA_LANG, SCHEMA_TYPE);
        parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", schemaFile);

        InputStream is = this.getClass().getResourceAsStream("toys.xml");
        MyErrorHandler eh = new MyErrorHandler();
        parser.parse(is, eh);
        Assert.assertFalse(eh.errorOccured, "Not Expected Error");
        setSystemProperty("maxOccurLimit", "");
    } catch (Exception e) {
        Assert.fail("Exception occured: " + e.getMessage());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:Bug6309988.java


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