use of org.xml.sax.XMLReader in project poi by apache.
the class FromHowTo method processFirstSheet.
public void processFirstSheet(String filename) throws Exception {
OPCPackage pkg = OPCPackage.open(filename, PackageAccess.READ);
try {
XSSFReader r = new XSSFReader(pkg);
SharedStringsTable sst = r.getSharedStringsTable();
XMLReader parser = fetchSheetParser(sst);
// process the first sheet
InputStream sheet2 = r.getSheetsData().next();
InputSource sheetSource = new InputSource(sheet2);
parser.parse(sheetSource);
sheet2.close();
} finally {
pkg.close();
}
}
use of org.xml.sax.XMLReader in project poi by apache.
the class TestSAXHelper method testXMLReader.
@Test
public void testXMLReader() throws Exception {
XMLReader reader = SAXHelper.newXMLReader();
assertNotSame(reader, SAXHelper.newXMLReader());
assertTrue(reader.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING));
assertEquals(SAXHelper.IGNORING_ENTITY_RESOLVER, reader.getEntityResolver());
assertNotNull(reader.getProperty("http://apache.org/xml/properties/security-manager"));
reader.parse(new InputSource(new ByteArrayInputStream("<xml></xml>".getBytes("UTF-8"))));
}
use of org.xml.sax.XMLReader in project jackrabbit by apache.
the class SerializationTest method createXMLReader.
/**
* Creates an XMLReader for the given content handler.
*
* @param handler the content handler.
* @return an XMLReader for the given content handler.
* @throws SAXException if the reader cannot be created.
*/
private XMLReader createXMLReader(ContentHandler handler) throws SAXException {
XMLReader reader = XMLReaderFactory.createXMLReader();
reader.setFeature("http://xml.org/sax/features/namespaces", true);
reader.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
reader.setContentHandler(handler);
reader.setErrorHandler(new DefaultHandler());
return reader;
}
use of org.xml.sax.XMLReader in project jmeter by apache.
the class DefaultSamplerCreator method isPotentialXml.
/**
* Tries parsing to see if content is xml
* @param postData String
* @return boolean
*/
private static boolean isPotentialXml(String postData) {
try {
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser saxParser = spf.newSAXParser();
XMLReader xmlReader = saxParser.getXMLReader();
ErrorDetectionHandler detectionHandler = new ErrorDetectionHandler();
xmlReader.setContentHandler(detectionHandler);
xmlReader.setErrorHandler(detectionHandler);
xmlReader.parse(new InputSource(new StringReader(postData)));
return !detectionHandler.isErrorDetected();
} catch (ParserConfigurationException | SAXException | IOException e) {
return false;
}
}
use of org.xml.sax.XMLReader in project jmeter by apache.
the class XMLAssertion method getResult.
/**
* Returns the result of the Assertion.
* Here it checks whether the Sample data is XML.
* If so an AssertionResult containing a FailureMessage will be returned.
* Otherwise the returned AssertionResult will reflect the success of the Sample.
*/
@Override
public AssertionResult getResult(SampleResult response) {
// no error as default
AssertionResult result = new AssertionResult(getName());
String resultData = response.getResponseDataAsString();
if (resultData.length() == 0) {
return result.setResultForNull();
}
result.setFailure(false);
XMLReader builder = XML_READER.get();
if (builder != null) {
try {
builder.setErrorHandler(new LogErrorHandler());
builder.parse(new InputSource(new StringReader(resultData)));
} catch (SAXException | IOException e) {
result.setError(true);
result.setFailure(true);
result.setFailureMessage(e.getMessage());
}
} else {
result.setError(true);
result.setFailureMessage("Cannot initialize XMLReader in element:" + getName() + ", check jmeter.log file");
}
return result;
}
Aggregations