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);
}
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(), "&", "&");
normalized = StringUtils.replace(normalized, "\"", StringUtils.replace(xml.getText(), "&", """));
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();
}
}
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;
}
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();
}
Aggregations