com.ctc.wstx.api.WstxInputProperties Java Examples

The following examples show how to use com.ctc.wstx.api.WstxInputProperties. 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: TestCharacterLimits.java    From woodstox with Apache License 2.0 6 votes vote down vote up
public void testLongElementText() throws Exception {
    try {
        Reader reader = createLongReader("", "", false);
        XMLInputFactory factory = getNewInputFactory();
        factory.setProperty(WstxInputProperties.P_MAX_TEXT_LENGTH, Integer.valueOf(100000));
        XMLStreamReader xmlreader = factory.createXMLStreamReader(reader);
        while (xmlreader.next() != XMLStreamReader.START_ELEMENT) {
        }
        assertEquals(XMLStreamReader.CHARACTERS, xmlreader.next());
        while (xmlreader.next() != XMLStreamReader.START_ELEMENT) {
        }
        fail("Should have failed");
    } catch (XMLStreamException ex) {
        _verifyTextLimitException(ex);
    }
}
 
Example #2
Source File: TestCharacterLimits.java    From woodstox with Apache License 2.0 6 votes vote down vote up
public void testLongWhitespace() throws Exception {
    try {
        Reader reader = createLongReader("", "", true);
        XMLInputFactory factory = getNewInputFactory();
        factory.setProperty(WstxInputProperties.P_MAX_TEXT_LENGTH, Integer.valueOf(50000));
        XMLStreamReader xmlreader = factory.createXMLStreamReader(reader);
        while (xmlreader.next() != XMLStreamReader.START_ELEMENT) {
        }
        assertEquals(XMLStreamReader.CHARACTERS, xmlreader.next());
        while (xmlreader.next() != XMLStreamReader.START_ELEMENT) {
        }
        fail("Should have failed");
    } catch (XMLStreamException ex) {
        _verifyTextLimitException(ex);
    }
}
 
Example #3
Source File: TestDefaultNamespacePrefix.java    From woodstox with Apache License 2.0 6 votes vote down vote up
public void testDefaultNamespacePrefixAsNull() throws Exception
    {
        String XML = "<blah xmlns=\"http://blah.org\"><foo>foo</foo></blah>";
//        System.setProperty("com.ctc.wstx.returnNullForDefaultNamespace", "true");
        XMLInputFactory factory = getNewInputFactory();

        assertEquals(Boolean.FALSE, factory.getProperty(WstxInputProperties.P_RETURN_NULL_FOR_DEFAULT_NAMESPACE));
        
        factory.setProperty(WstxInputProperties.P_RETURN_NULL_FOR_DEFAULT_NAMESPACE, true);
        XMLStreamReader r = factory.createXMLStreamReader(new StringReader(XML));
        assertTokenType(START_ELEMENT, r.next());
        String prefix = r.getNamespacePrefix(0);
        if (prefix != null) {
            fail("Null value is not returned for the default namespace prefix while "
                    + WstxInputProperties.P_RETURN_NULL_FOR_DEFAULT_NAMESPACE + " is set true");
        }
    }
 
Example #4
Source File: TestCharacterLimits.java    From woodstox with Apache License 2.0 6 votes vote down vote up
public void testLongCDATA() throws Exception {
    try {
        Reader reader = createLongReader("<![CDATA[", "]]>", true);
        XMLInputFactory factory = getNewInputFactory();
        factory.setProperty(WstxInputProperties.P_MAX_TEXT_LENGTH, Integer.valueOf(50000));
        XMLStreamReader xmlreader = factory.createXMLStreamReader(reader);
        while (xmlreader.next() != XMLStreamReader.START_ELEMENT) {
        }
        assertEquals(XMLStreamReader.CDATA, xmlreader.next());
        while (xmlreader.next() != XMLStreamReader.START_ELEMENT) {
        }
        fail("Should have failed");
    } catch (XMLStreamException ex) {
        _verifyTextLimitException(ex);
    }
}
 
Example #5
Source File: TestParsingModeForTokens.java    From woodstox with Apache License 2.0 6 votes vote down vote up
public void testMultiDocumentMode() throws XMLStreamException
{
    // First the main valid case:
    streamThroughOk(getReader(XML_MULTI_DOC,
                              WstxInputProperties.PARSING_MODE_DOCUMENTS),
                    "multi-doc input in multi-doc mode");

    // But the alternate cases should actually work too:
    streamThroughOk(getReader(XML_SINGLE_DOC,
                            WstxInputProperties.PARSING_MODE_DOCUMENTS),
                    "single-doc input in multi-doc mode");
    streamThroughOk(getReader(XML_FRAGMENT,
                              WstxInputProperties.PARSING_MODE_DOCUMENTS),
                    "fragment input in multi-doc mode");


    // Except for some fragment cases:
    streamThroughFailing(getReader(XML_FRAGMENT2,
                                   WstxInputProperties.PARSING_MODE_DOCUMENTS),
                         "Expected an exception for fragments with root-level textual content");

    // And broken one not
    streamThroughFailing(getReader(XML_UNBALANCED,
            WstxInputProperties.PARSING_MODE_DOCUMENTS),
                         "Expected an exception for unbalanced xml content");
}
 
Example #6
Source File: TestParsingModeForTokens.java    From woodstox with Apache License 2.0 6 votes vote down vote up
public void testSingleDocumentMode()
    throws XMLStreamException
{
    // First the valid case:
    streamThrough(getReader(XML_SINGLE_DOC,
                            WstxInputProperties.PARSING_MODE_DOCUMENT));

    // Others will fail though
    streamThroughFailing(getReader(XML_FRAGMENT,
                                   WstxInputProperties.PARSING_MODE_DOCUMENT),
                         "Expected an exception for fragment (non-single root) input, in single-document mode");
    streamThroughFailing(getReader(XML_FRAGMENT2,
                                   WstxInputProperties.PARSING_MODE_DOCUMENT),
                         "Expected an exception for fragment (root-level text) input, in single-document mode");
    streamThroughFailing(getReader(XML_MULTI_DOC,
                                   WstxInputProperties.PARSING_MODE_DOCUMENT),
                         "Expected an exception for multi-document input, in single-document mode");


    // As should the generally invalid ones:
    streamThroughFailing(getReader(XML_UNBALANCED,
                                   WstxInputProperties.PARSING_MODE_DOCUMENT),
                         "Expected an exception for unbalanced xml content");
}
 
Example #7
Source File: TestAttributeLimits.java    From woodstox with Apache License 2.0 6 votes vote down vote up
public void testShorterAttribute() throws Exception
{
    XMLInputFactory factory = getNewInputFactory();
    factory.setProperty(WstxInputProperties.P_MAX_ATTRIBUTE_SIZE, 4);

    // First: ok document
    XMLStreamReader r = factory.createXMLStreamReader(new StringReader(
            "<root attr='1234' other='ab' x='yz&amp;0' />"));
    assertTokenType(START_ELEMENT, r.next());
    assertEquals(3, r.getAttributeCount());
    assertTokenType(END_ELEMENT, r.next());
    r.close();

    // then not so much
    r = factory.createXMLStreamReader(new StringReader(
            "<root attr='1234' other='abcde'  />"));
    try {
        r.next();
        fail("Should not pass");
    } catch (XMLStreamException ex) {
        verifyException(ex, "Maximum attribute size limit (4)");
    }
}
 
Example #8
Source File: TestCharacterLimits.java    From woodstox with Apache License 2.0 6 votes vote down vote up
public void testLongCDATANextTag() throws Exception {
    Reader reader = createLongReader("<![CDATA[", "]]>", true);
    XMLInputFactory factory = getNewInputFactory();
    factory.setProperty(WstxInputProperties.P_MAX_TEXT_LENGTH, Integer.valueOf(1000));
    XMLStreamReader xmlreader = factory.createXMLStreamReader(reader);
    try {
        int tokens = 0;
        while (xmlreader.next() != XMLStreamReader.START_ELEMENT) {
            ++tokens;
        }
        int code = xmlreader.nextTag();
        fail("Should have failed: instead got "+tokens+" tokens; and one following START_ELEMENT: "+code);
    } catch (XMLStreamException ex) {
        _verifyTextLimitException(ex);
    }
}
 
Example #9
Source File: TestCharacterLimits.java    From woodstox with Apache License 2.0 5 votes vote down vote up
public void testLongCommentCoalescing() throws Exception {
    try {
        Reader reader = createLongReader("<!--", "-->", true);
        XMLInputFactory factory = getNewInputFactory();
        factory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
        factory.setProperty(WstxInputProperties.P_MAX_TEXT_LENGTH, Integer.valueOf(1000));
        XMLStreamReader xmlreader = factory.createXMLStreamReader(reader);
        while (xmlreader.next() != XMLStreamReader.START_ELEMENT) {
        }
        xmlreader.nextTag();
        fail("Should have failed");
    } catch (XMLStreamException ex) {
        _verifyTextLimitException(ex);
    }
}
 
Example #10
Source File: TestCharacterLimits.java    From woodstox with Apache License 2.0 5 votes vote down vote up
public void testLongWhitespaceNextTag() throws Exception {
    try {
        Reader reader = createLongReader("", "", true);
        XMLInputFactory factory = getNewInputFactory();
        factory.setProperty(WstxInputProperties.P_MAX_TEXT_LENGTH, Integer.valueOf(1000));
        XMLStreamReader xmlreader = factory.createXMLStreamReader(reader);
        while (xmlreader.next() != XMLStreamReader.START_ELEMENT) {
        }
        xmlreader.nextTag();
        fail("Should have failed");
    } catch (XMLStreamException ex) {
        _verifyTextLimitException(ex);
    }
}
 
Example #11
Source File: TestCharacterLimits.java    From woodstox with Apache License 2.0 5 votes vote down vote up
public void testLongComment() throws Exception {
    try {
        Reader reader = createLongReader("<!--", "-->", true);
        XMLInputFactory factory = getNewInputFactory();
        factory.setProperty(WstxInputProperties.P_MAX_TEXT_LENGTH, Integer.valueOf(1000));
        XMLStreamReader xmlreader = factory.createXMLStreamReader(reader);
        while (xmlreader.next() != XMLStreamReader.COMMENT) {
        }
        // important, due to lazy handling only triggers problem here:
        String str = xmlreader.getText();
        fail("Should have failed; instead got: "+str);
    } catch (Exception ex) {
        _verifyTextLimitException(ex);
    }
}
 
Example #12
Source File: TestCharacterLimits.java    From woodstox with Apache License 2.0 5 votes vote down vote up
public void testLongCommentNextTag() throws Exception {
    try {
        Reader reader = createLongReader("<!--", "-->", true);
        XMLInputFactory factory = getNewInputFactory();
        factory.setProperty(WstxInputProperties.P_MAX_TEXT_LENGTH, Integer.valueOf(1000));
        XMLStreamReader xmlreader = factory.createXMLStreamReader(reader);
        while (xmlreader.next() != XMLStreamReader.COMMENT) {
        }
        xmlreader.nextTag();
        fail("Should have failed");
    } catch (XMLStreamException ex) {
        _verifyTextLimitException(ex);
    }
}
 
Example #13
Source File: TestCharacterLimits.java    From woodstox with Apache License 2.0 5 votes vote down vote up
public void testLongGetElementText() throws Exception {
    try {
        Reader reader = createLongReader("", "", false);
        XMLInputFactory factory = getNewInputFactory();
        factory.setProperty(WstxInputProperties.P_MAX_TEXT_LENGTH, Integer.valueOf(1000));
        XMLStreamReader xmlreader = factory.createXMLStreamReader(reader);
        while (xmlreader.next() != XMLStreamReader.START_ELEMENT) {
        }
        System.out.println(xmlreader.getElementText());
        fail("Should have failed");
    } catch (XMLStreamException ex) {
        _verifyTextLimitException(ex);
    }
}
 
Example #14
Source File: TestCharacterLimits.java    From woodstox with Apache License 2.0 5 votes vote down vote up
public void testLongWhitespaceCoalescing() throws Exception {
    try {
        Reader reader = createLongReader("", "", true);
        XMLInputFactory factory = getNewInputFactory();
        factory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
        factory.setProperty(WstxInputProperties.P_MAX_TEXT_LENGTH, Integer.valueOf(1000));
        XMLStreamReader xmlreader = factory.createXMLStreamReader(reader);
        while (xmlreader.next() != XMLStreamReader.START_ELEMENT) {
        }
        xmlreader.nextTag();
        fail("Should have failed");
    } catch (XMLStreamException ex) {
        _verifyTextLimitException(ex);
    }
}
 
Example #15
Source File: TestParsingModeForEvents.java    From woodstox with Apache License 2.0 5 votes vote down vote up
public void testMultiDocumentWithEventReader() throws XMLStreamException
{
    XMLInputFactory f = getInputFactory();
    setCoalescing(f, true);
    f.setProperty(WstxInputProperties.P_INPUT_PARSING_MODE, WstxInputProperties.PARSING_MODE_DOCUMENTS);
    XMLEventReader2 er = constructEventReader(f, XML_MULTI_DOC);

    _checkEventDoc(er, 0);
    _checkEventDoc(er, 1);
    _checkEventDoc(er, 2);
    _checkEventDoc(er, 3);

    // and then the end
    assertFalse(er.hasNextEvent());
}
 
Example #16
Source File: TestEventReader.java    From woodstox with Apache License 2.0 5 votes vote down vote up
/**
 * As of Stax 3.0 (Woodstox 4.0+), there is additional info for
 * NotationDeclarations (base URI). Let's verify it gets properly
 * populated.
 */
public void testDtdNotations()
    throws Exception
{
    final String URI = "http://test";

    /* Ok. And here we should just check that we do not get 2 adjacent
     * separate Characters event. We can try to trigger this by long
     * segment and a set of char entities...
     */
    final String XML = "<?xml version='1.0'?>"
        +"<!DOCTYPE root [\n"
        +"<!ELEMENT root EMPTY>\n"
        +"<!NOTATION not PUBLIC 'some-public-id'>\n"
        +"]>"
        +"<root/>";
	
    // Need to disable coalescing though for test to work:
    XMLEventReader2 er = getReader(XML, false);
    // Need to set Base URI; can do it for factory or instance
    er.setProperty(WstxInputProperties.P_BASE_URL, new URL(URI));
    assertTrue(er.nextEvent().isStartDocument());
    XMLEvent evt = er.nextEvent(); // DTD
    assertTokenType(DTD, evt.getEventType());

    DTD dtd = (DTD) evt;
    List<?> nots = dtd.getNotations();
    assertEquals(1, nots.size());
    NotationDeclaration2 notDecl = (NotationDeclaration2) nots.get(0);

    assertEquals(URI, notDecl.getBaseURI());
}
 
Example #17
Source File: TestDefaultNamespacePrefix.java    From woodstox with Apache License 2.0 5 votes vote down vote up
public void testDefaultNamespacePrefixAsEmptyString() throws Exception
    {
        String XML = "<blah xmlns=\"http://blah.org\"><foo>foo</foo></blah>";
//        System.setProperty("com.ctc.wstx.returnNullForDefaultNamespace", "false");
        XMLInputFactory factory = getNewInputFactory();
        assertEquals(Boolean.FALSE, factory.getProperty(WstxInputProperties.P_RETURN_NULL_FOR_DEFAULT_NAMESPACE));
//        factory.setProperty(WstxInputProperties.P_RETURN_NULL_FOR_DEFAULT_NAMESPACE, false);
        XMLStreamReader r = factory.createXMLStreamReader(new StringReader(XML));
        assertTokenType(START_ELEMENT, r.next());
        String prefix = r.getNamespacePrefix(0);
        if (!"".equals(prefix)) {
            fail("Null value is returned for the default namespace prefix while "
                    + WstxInputProperties.P_RETURN_NULL_FOR_DEFAULT_NAMESPACE + " is set false");
        }
    }
 
Example #18
Source File: TestOutputFactory.java    From woodstox with Apache License 2.0 5 votes vote down vote up
public void testMisc()
    throws XMLStreamException
{
    /* This is silly, but coverage testing is not happy that our
     * constant-defining classes are never constructed. So here we go,
     * just to mark it off the list...
     */
    WstxInputProperties fooin = new WstxInputProperties();
    WstxOutputProperties fooout = new WstxOutputProperties();
 
    // These just to keep compilers/FindBugs etc happy
    assertNotNull(fooin);
    assertNotNull(fooout);
}
 
Example #19
Source File: BasicSerializableRepository.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
private XmlMapper createXMLMapper() {
    final XMLInputFactory ifactory = new WstxInputFactory();
    ifactory.setProperty(WstxInputProperties.P_MAX_ATTRIBUTE_SIZE, 32000);
    ifactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false);

    final XMLOutputFactory ofactory = new WstxOutputFactory();
    ofactory.setProperty(WstxOutputProperties.P_OUTPUT_CDATA_AS_TEXT, true);
    ofactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true);

    final XmlFactory xf = new XmlFactory(ifactory, ofactory);

    final XmlMapper mapper = new XmlMapper(xf);
    mapper.registerModules(new JavaTimeModule());
    return mapper;
}
 
Example #20
Source File: TestElementLimits.java    From woodstox with Apache License 2.0 5 votes vote down vote up
public void testCharacterLimit() throws Exception {
    try {
        XMLInputFactory factory = getNewInputFactory();
        factory.setProperty(WstxInputProperties.P_MAX_CHARACTERS, Integer.valueOf(100));
        XMLStreamReader xmlreader = factory.createXMLStreamReader(createManyElementReader());
        while (xmlreader.next() != XMLStreamReader.END_DOCUMENT) {
        }
        fail("Should have failed");
    } catch (XMLStreamException ex) {
        verifyException(ex, "Maximum document characters limit");
    }        
}
 
Example #21
Source File: TestParsingModeForTokens.java    From woodstox with Apache License 2.0 5 votes vote down vote up
private XMLStreamReader getReader(String contents, WstxInputProperties.ParsingMode mode)
    throws XMLStreamException
{
    XMLInputFactory f = getInputFactory();
    f.setProperty(WstxInputProperties.P_INPUT_PARSING_MODE, mode);
    return constructStreamReader(f, contents);
}
 
Example #22
Source File: TestParsingModeForTokens.java    From woodstox with Apache License 2.0 5 votes vote down vote up
public void testFragmentMode()
    throws XMLStreamException
{
    // First the main valid case2:
    streamThroughOk(getReader(XML_FRAGMENT,
                              WstxInputProperties.PARSING_MODE_FRAGMENT),
                    "fragment input in fragment mode");
    streamThroughOk(getReader(XML_FRAGMENT2,
                              WstxInputProperties.PARSING_MODE_FRAGMENT),
                    "fragment input in fragment mode");

    /* The single doc case actually works, since the xml declaration
     * gets handled by the bootstrapper... (kind of implementation
     * side effect)
     */
    streamThroughOk(getReader(XML_SINGLE_DOC,
                              WstxInputProperties.PARSING_MODE_FRAGMENT),
                    "single-doc input in fragment mode");

    // But multi-doc will fail, due to second xml declaration
    streamThroughFailing(getReader(XML_MULTI_DOC,
                                   WstxInputProperties.PARSING_MODE_FRAGMENT),
                         "Expected an exception for multi-document input, in fragment mode");


    // But not the invalid one:
    streamThroughFailing(getReader(XML_UNBALANCED,
                                   WstxInputProperties.PARSING_MODE_FRAGMENT),
                         "Expected an exception for unbalanced xml content");
}
 
Example #23
Source File: TestEntityLimits.java    From woodstox with Apache License 2.0 5 votes vote down vote up
public void testMaxEntityNesting() throws XMLStreamException
{
    String XML = "<!DOCTYPE root [\n"
            +" <!ENTITY top '&middle;'>\n"
            +" <!ENTITY middle '&bottom;'>\n"
            +" <!ENTITY bottom 'yay!'>\n"
            +"]><root>&top;</root>"
           ;

    // First: with default limits (high), should be fine
    XMLInputFactory f = getNewInputFactory();
    XMLStreamReader sr = f.createXMLStreamReader(new StringReader(XML));
    assertTokenType(DTD, sr.next());
    assertTokenType(START_ELEMENT, sr.next());
    assertTokenType(CHARACTERS, sr.next());
    assertTokenType(END_ELEMENT, sr.next());
    sr.close();

    // and with max depth of 3 as well
    f.setProperty(WstxInputProperties.P_MAX_ENTITY_DEPTH, Integer.valueOf(3));
    sr = f.createXMLStreamReader(new StringReader(XML));
    assertTokenType(DTD, sr.next());
    assertTokenType(START_ELEMENT, sr.next());
    assertTokenType(CHARACTERS, sr.next());
    assertTokenType(END_ELEMENT, sr.next());
    sr.close();

    // but not with 2
    f.setProperty(WstxInputProperties.P_MAX_ENTITY_DEPTH, Integer.valueOf(2));
    sr = f.createXMLStreamReader(new StringReader(XML));
    assertTokenType(DTD, sr.next());
    assertTokenType(START_ELEMENT, sr.next());
    try {
        sr.next();
        fail("Should have failed with entity depth limit extension");
    } catch (XMLStreamException e) {
        verifyException(e, "Maximum entity expansion depth");
    }
    sr.close();
}
 
Example #24
Source File: TestConfig.java    From woodstox with Apache License 2.0 5 votes vote down vote up
public void testSettingResolvers()
    throws XMLStreamException
{
    XMLInputFactory ifact = getNewInputFactory();
    // Default should be "no custom resolvers"
    assertNull(ifact.getProperty(WstxInputProperties.P_DTD_RESOLVER));
    assertNull(ifact.getProperty(WstxInputProperties.P_ENTITY_RESOLVER));

    // But if and when they are set, they should stick for both factory:
    XMLResolver dtdR = new DTDResolver();
    XMLResolver entityR = new EntityResolver();

    ifact.setProperty(WstxInputProperties.P_DTD_RESOLVER, dtdR);
    ifact.setProperty(WstxInputProperties.P_ENTITY_RESOLVER, entityR);

    Object gotDtdR = ifact.getProperty(WstxInputProperties.P_DTD_RESOLVER);
    Object gotEntityR = ifact.getProperty(WstxInputProperties.P_ENTITY_RESOLVER);
    assertTrue("DTD resolver set for factory should stick: didn't except value ["+gotDtdR+"]",
               dtdR == gotDtdR);
    assertTrue("Entity resolver set for factory should stick: didn't except value ["+gotEntityR+"]",
               entityR == gotEntityR);

    // and for the instances as well:
    XMLStreamReader sr = constructStreamReader(ifact, "<root />");
    gotDtdR = sr.getProperty(WstxInputProperties.P_DTD_RESOLVER);
    gotEntityR = sr.getProperty(WstxInputProperties.P_ENTITY_RESOLVER);

    assertTrue("DTD resolver set should be passed to instance by factory: didn't except value ["+gotDtdR+"]",
               dtdR == gotDtdR);
    assertTrue("Entity resolver set should be passed to instance by factory: didn't except value ["+gotEntityR+"]",
               entityR == gotEntityR);
}
 
Example #25
Source File: TestAllowXml11EscapedCharsInXml10.java    From woodstox with Apache License 2.0 5 votes vote down vote up
/**
 * Unit test to verify workaround for XML 1.1 escaped chars in XML 1.0 file.
 */
public void testAllowXml11EscapedCharsInXml10() throws Exception {
    XMLInputFactory2 f = getInputFactory();
    setNamespaceAware(f, true);
    setCoalescing(f, true);
    f.setProperty(WstxInputProperties.P_ALLOW_XML11_ESCAPED_CHARS_IN_XML10, true);
    XMLStreamReader sr = constructStreamReader(f, "<?xml version=\"1.0\" encoding=\"utf-8\"?><root>&#x2;</root>");
    assertTokenType(START_ELEMENT, sr.next());
    assertTokenType(CHARACTERS, sr.next());
    assertTokenType(END_ELEMENT, sr.next());
}
 
Example #26
Source File: BasicSerializableRepository.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
private XmlMapper createXMLMapper() {
    final XMLInputFactory ifactory = new WstxInputFactory();
    ifactory.setProperty(WstxInputProperties.P_MAX_ATTRIBUTE_SIZE, 32000);
    ifactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false);

    final XMLOutputFactory ofactory = new WstxOutputFactory();
    ofactory.setProperty(WstxOutputProperties.P_OUTPUT_CDATA_AS_TEXT, true);
    ofactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true);

    final XmlFactory xf = new XmlFactory(ifactory, ofactory);

    final XmlMapper mapper = new XmlMapper(xf);
    mapper.registerModules(new JavaTimeModule());
    return mapper;
}
 
Example #27
Source File: DTDValidatorBase.java    From woodstox with Apache License 2.0 5 votes vote down vote up
@Override
public String getAttributeType(int index)
{
    DTDAttribute attr = mAttrSpecs[index];
    return (attr == null) ? WstxInputProperties.UNKNOWN_ATTR_TYPE : 
        attr.getValueTypeString();
}
 
Example #28
Source File: InputElementStack.java    From woodstox with Apache License 2.0 5 votes vote down vote up
/**
 * @return Schema (DTD, RNG, W3C Schema) based type of the attribute
 *   in specified index
 */
@Override
public final String getAttributeType(int index)
{
    if (index == mIdAttrIndex && index >= 0) { // second check to ensure -1 is not passed
        return "ID";
    }
    return (mValidator == null) ? WstxInputProperties.UNKNOWN_ATTR_TYPE : 
        mValidator.getAttributeType(index);
}
 
Example #29
Source File: XmlDumpParser.java    From wikiforia with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor used by Multistream parser
 * @param header   parsed header
 * @param xmlInput parallel input stream
 */
public XmlDumpParser(Header header, InputStream xmlInput) {
    try {
        this.header = header;

        XMLInputFactory2 factory = (XMLInputFactory2) XMLInputFactory2.newInstance();
        factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);
        factory.setProperty(WstxInputProperties.P_INPUT_PARSING_MODE, WstxInputProperties.PARSING_MODE_FRAGMENT);

        xmlReader = (XMLStreamReader2)factory.createXMLStreamReader(xmlInput);

    } catch (XMLStreamException e) {
        throw new IOError(e);
    }
}
 
Example #30
Source File: XmlDumpParser.java    From wikiforia with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Standalone constructor
 * @param xmlInput the stream to read from
 */
public XmlDumpParser(InputStream xmlInput) {
    try {
        XMLInputFactory2 factory = (XMLInputFactory2) XMLInputFactory2.newInstance();
        factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);
        factory.setProperty(WstxInputProperties.P_INPUT_PARSING_MODE, WstxInputProperties.PARSING_MODE_FRAGMENT);

        xmlReader = (XMLStreamReader2) factory.createXMLStreamReader(xmlInput);
        this.header = readHeader(xmlReader);
    } catch (XMLStreamException e) {
        throw new IOError(e);
    }
}