當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。