Java Code Examples for javax.xml.parsers.SAXParser#getProperty()

The following examples show how to use javax.xml.parsers.SAXParser#getProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SymbolTableResetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private void parseAndCheckReset(boolean setFeature, boolean value) throws Exception {
    // Expected result based on system property and feature
    boolean resetExpected = setFeature && value;
    // Indicates if system property is set
    boolean spSet = runWithAllPerm(() -> System.getProperty(RESET_FEATURE)) != null;
    // Dummy xml input for parser
    String input = "<dummy>Test</dummy>";

    // Check if system property is set only when feature setting is not requested
    // and estimate if reset of symbol table is expected
    if (!setFeature && spSet) {
        resetExpected = runWithAllPerm(() -> Boolean.getBoolean(RESET_FEATURE));
    }

    // Create SAXParser and set feature if it is requested
    SAXParserFactory spf = SAXParserFactory.newInstance();
    if (setFeature) {
        spf.setFeature(RESET_FEATURE, value);
    }
    SAXParser p = spf.newSAXParser();

    // First parse iteration
    p.parse(new InputSource(new StringReader(input)), new DefaultHandler());
    // Get first symbol table reference
    Object symTable1 = p.getProperty(SYMBOL_TABLE_PROPERTY);

    // reset parser
    p.reset();

    // Second parse iteration
    p.parse(new InputSource(new StringReader(input)), new DefaultHandler());
    // Get second symbol table reference
    Object symTable2 = p.getProperty(SYMBOL_TABLE_PROPERTY);

    // Check symbol table references after two subsequent parse operations
    if (resetExpected) {
        Assert.assertNotSame(symTable1, symTable2, "Symbol table references");
    } else {
        Assert.assertSame(symTable1, symTable2, "Symbol table references");
    }
}
 
Example 2
Source File: SAXParserTest02.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Test whether the xml-string property is not supported.
 *
 * @param saxparser a SAXParser instance.
 * @throws SAXException If any parse errors occur.
 */
@Test(expectedExceptions = SAXNotSupportedException.class,
        dataProvider = "parser-provider")
public void testProperty01(SAXParser saxparser) throws SAXException {
    saxparser.getProperty(XML_STRING);
}
 
Example 3
Source File: SAXParserTest02.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Test whether the dom-node property is not supported.
 *
 * @param saxparser a SAXParser instance.
 * @throws SAXException If any parse errors occur.
 */
@Test(expectedExceptions = SAXNotSupportedException.class,
        dataProvider = "parser-provider")
public void testProperty02(SAXParser saxparser) throws SAXException {
    saxparser.getProperty(DOM_NODE);
}