Search in sources :

Example 1 with WstxInputFactory

use of com.ctc.wstx.stax.WstxInputFactory in project webservices-axiom by apache.

the class Parsable method getXMLStreamReader.

@Override
final XMLStreamReader getXMLStreamReader(boolean expandEntityReferences) throws XMLStreamException {
    WstxInputFactory factory = new WstxInputFactory();
    factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.valueOf(expandEntityReferences));
    factory.setProperty(WstxInputFactory.P_AUTO_CLOSE_INPUT, Boolean.TRUE);
    factory.setProperty(WstxInputFactory.P_REPORT_PROLOG_WHITESPACE, Boolean.TRUE);
    factory.setProperty(WstxInputFactory.P_REPORT_CDATA, Boolean.TRUE);
    factory.setProperty(WstxInputProperties.P_MIN_TEXT_SEGMENT, Integer.MAX_VALUE);
    return createXMLStreamReader(factory);
}
Also used : WstxInputFactory(com.ctc.wstx.stax.WstxInputFactory)

Example 2 with WstxInputFactory

use of com.ctc.wstx.stax.WstxInputFactory in project corelib by europeana.

the class SampleRecordCreator method main.

/**
 * @param args
 */
public static void main(String[] args) {
    File file = new File("src/test/resources/09102_Ag_EU_MIMO_EDM.xml");
    File saveFolder = new File("src/test/resources/records");
    saveFolder.mkdir();
    XMLInputFactory inFactory = new WstxInputFactory();
    Source source;
    try {
        source = new StreamSource(new FileInputStream(file), "UTF-8");
        XMLStreamReader xml = inFactory.createXMLStreamReader(source);
        int records = 0;
        File recordFile = null;
        StringBuffer xmlString = new StringBuffer();
        while (xml.hasNext()) {
            switch(xml.getEventType()) {
                case XMLStreamConstants.START_DOCUMENT:
                    System.out.println("Started parsing the document...");
                    break;
                case XMLStreamConstants.START_ELEMENT:
                    if (StringUtils.equals("edm:ProvidedCHO", xml.getName().getPrefix() + ":" + xml.getName().getLocalPart())) {
                        recordFile = new File(saveFolder.getAbsolutePath() + "/09102_Ag_EU_MIMO_EDM_record" + records + ".xml");
                        xmlString = new StringBuffer();
                        xmlString.append(START_DOCUMENT);
                        records++;
                    }
                    if (!StringUtils.equals("rdf:RDF", xml.getName().getPrefix() + ":" + xml.getName().getLocalPart())) {
                        xmlString.append("<").append(xml.getName().getPrefix()).append(":").append(xml.getName().getLocalPart()).append("");
                        if (xml.getAttributeCount() > 0) {
                            xmlString.append(" ").append(xml.getAttributePrefix(0)).append(":").append(xml.getAttributeLocalName(0)).append("=\"").append(xml.getAttributeValue(0)).append("\">");
                        } else {
                            xmlString.append(">");
                        }
                    }
                    break;
                case XMLStreamConstants.CHARACTERS:
                    String normalized = StringUtils.replace(xml.getText(), "&", "&amp;");
                    normalized = StringUtils.replace(normalized, "\"", StringUtils.replace(xml.getText(), "&", "&quot;"));
                    xmlString.append(normalized);
                    break;
                case XMLStreamConstants.END_ELEMENT:
                    xmlString.append("</").append(xml.getName().getPrefix()).append(":").append(xml.getName().getLocalPart()).append(">");
                    if (StringUtils.equals("ore:Aggregation", xml.getName().getPrefix() + ":" + xml.getName().getLocalPart())) {
                        xmlString.append("</rdf:RDF>");
                        saveFile(recordFile, xmlString);
                    }
                    break;
                case XMLStreamConstants.END_DOCUMENT:
                    break;
            }
            xml.next();
        }
        System.out.println("Finished parsing documents...");
        System.out.println("Found " + records + " records");
    } catch (XMLStreamException | IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) StreamSource(javax.xml.transform.stream.StreamSource) IOException(java.io.IOException) WstxInputFactory(com.ctc.wstx.stax.WstxInputFactory) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) FileInputStream(java.io.FileInputStream) XMLStreamException(javax.xml.stream.XMLStreamException) File(java.io.File) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 3 with WstxInputFactory

use of com.ctc.wstx.stax.WstxInputFactory in project iaf by ibissource.

the class XmlUtils method getVersionInfo.

public static Map<String, String> getVersionInfo() {
    Map<String, String> map = new LinkedHashMap<>();
    SAXParserFactory spFactory = getSAXParserFactory();
    map.put("SAXParserFactory-class", spFactory.getClass().getName());
    DocumentBuilderFactory domFactory1 = getDocumentBuilderFactory(false);
    map.put("DocumentBuilderFactory1-class", domFactory1.getClass().getName());
    DocumentBuilderFactory domFactory2 = getDocumentBuilderFactory(true);
    map.put("DocumentBuilderFactory2-class", domFactory2.getClass().getName());
    TransformerFactory tFactory1 = getTransformerFactory(1);
    map.put("TransformerFactory1-class", tFactory1.getClass().getName());
    TransformerFactory tFactory2 = getTransformerFactory(2);
    map.put("TransformerFactory2-class", tFactory2.getClass().getName());
    XMLEventFactory xmlEventFactory = XMLEventFactory.newInstance();
    map.put("XMLEventFactory-class", xmlEventFactory.getClass().getName());
    XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
    map.put("XMLInputFactory-class", xmlInputFactory.getClass().getName());
    XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
    map.put("XMLOutputFactory-class", xmlOutputFactory.getClass().getName());
    try {
        MessageFactory messageFactory = MessageFactory.newInstance();
        map.put("MessageFactory-class", messageFactory.getClass().getName());
    } catch (SOAPException e) {
        log.warn("unable to create MessageFactory", e);
        map.put("MessageFactory-class", "unable to create MessageFactory (" + e.getClass().getName() + "): " + e.getMessage() + ")");
    }
    try {
        map.put("Xerces-Version", org.apache.xerces.impl.Version.getVersion());
    } catch (Throwable t) {
        log.warn("could not get Xerces version", t);
        map.put("Xerces-Version", "not found (" + t.getClass().getName() + "): " + t.getMessage() + ")");
    }
    try {
        String xalanVersion = org.apache.xalan.Version.getVersion();
        map.put("Xalan-Version", xalanVersion);
    } catch (Throwable t) {
        log.warn("could not get Xalan version", t);
        map.put("Xalan-Version", "not found (" + t.getClass().getName() + "): " + t.getMessage() + ")");
    }
    try {
        String saxonVersion = net.sf.saxon.Version.getProductTitle();
        map.put("Saxon-Version", saxonVersion);
    } catch (Throwable t) {
        log.warn("could not get Saxon version", t);
        map.put("Saxon-Version", "not found (" + t.getClass().getName() + "): " + t.getMessage() + ")");
    }
    try {
        if (xmlInputFactory instanceof WstxInputFactory) {
            ReaderConfig woodstoxConfig = ((WstxInputFactory) xmlInputFactory).createPrivateConfig();
            String woodstoxVersion = ReaderConfig.getImplName() + " " + ReaderConfig.getImplVersion() + "; xml1.1 " + (woodstoxConfig.isXml11() ? "" : "not ") + "enabled";
            map.put("Woodstox-Version", woodstoxVersion);
        }
    } catch (Throwable t) {
        log.warn("could not get Woodstox version", t);
        map.put("Woodstox-Version", "not found (" + t.getClass().getName() + "): " + t.getMessage() + ")");
    }
    return map;
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TransformerFactory(javax.xml.transform.TransformerFactory) MessageFactory(javax.xml.soap.MessageFactory) XMLEventFactory(javax.xml.stream.XMLEventFactory) WstxInputFactory(com.ctc.wstx.stax.WstxInputFactory) LinkedHashMap(java.util.LinkedHashMap) SOAPException(javax.xml.soap.SOAPException) ReaderConfig(com.ctc.wstx.api.ReaderConfig) XMLInputFactory(javax.xml.stream.XMLInputFactory) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 4 with WstxInputFactory

use of com.ctc.wstx.stax.WstxInputFactory in project data-access by pentaho.

the class AnalysisServiceXxeAttackTest method setUp.

@Before
public void setUp() throws Exception {
    analysisService = mock(AnalysisService.class);
    doCallRealMethod().when(analysisService).getSchemaName(anyString(), any(InputStream.class));
    doReturn(new WstxInputFactory()).when(analysisService).getXMLInputFactory();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) WstxInputFactory(com.ctc.wstx.stax.WstxInputFactory) Before(org.junit.Before)

Aggregations

WstxInputFactory (com.ctc.wstx.stax.WstxInputFactory)4 XMLInputFactory (javax.xml.stream.XMLInputFactory)2 ReaderConfig (com.ctc.wstx.api.ReaderConfig)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 LinkedHashMap (java.util.LinkedHashMap)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 SAXParserFactory (javax.xml.parsers.SAXParserFactory)1 MessageFactory (javax.xml.soap.MessageFactory)1 SOAPException (javax.xml.soap.SOAPException)1 XMLEventFactory (javax.xml.stream.XMLEventFactory)1 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 Source (javax.xml.transform.Source)1 TransformerFactory (javax.xml.transform.TransformerFactory)1 StreamSource (javax.xml.transform.stream.StreamSource)1