use of org.xml.sax.helpers.DefaultHandler in project jdk8u_jdk by JetBrains.
the class SupplementaryChars method testInvalid.
@Test(dataProvider = "unsupported", expectedExceptions = SAXParseException.class)
public void testInvalid(String xml) throws Exception {
ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes("UTF-8"));
getParser().parse(stream, new DefaultHandler());
stream.close();
}
use of org.xml.sax.helpers.DefaultHandler in project jdk8u_jdk by JetBrains.
the class TestCase method main.
public static void main(String[] args) throws Exception {
File testcases = new File(System.getProperty("test.src", "."), "testcases");
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
DefaultHandler dh = new VmIdentifierTestHandler();
sp.parse(testcases, dh);
}
use of org.xml.sax.helpers.DefaultHandler in project jabref by JabRef.
the class OAI2Fetcher method importOai2Entry.
/**
* Import an entry from an OAI2 archive. The BibEntry provided has to
* have the field OAI2_IDENTIFIER_FIELD set to the search string.
*
* @param key
* The OAI2 key to fetch from ArXiv.
* @return The imported BibEntry or null if none.
*/
protected BibEntry importOai2Entry(String key) throws IOException, SAXException {
/**
* Fix for problem reported in mailing-list:
* https://sourceforge.net/forum/message.php?msg_id=4087158
*/
String fixedKey = OAI2Fetcher.fixKey(key);
String url = constructUrl(fixedKey);
URL oai2Url = new URL(url);
HttpURLConnection oai2Connection = (HttpURLConnection) oai2Url.openConnection();
oai2Connection.setRequestProperty("User-Agent", "JabRef");
/* create an empty BibEntry and set the oai2identifier field */
BibEntry entry = new BibEntry("article");
entry.setField(OAI2Fetcher.OAI2_IDENTIFIER_FIELD, fixedKey);
DefaultHandler handlerBase = new OAI2Handler(entry);
try (InputStream inputStream = oai2Connection.getInputStream()) {
/* parse the result */
saxParser.parse(inputStream, handlerBase);
/* Correct line breaks and spacing */
for (String name : entry.getFieldNames()) {
entry.getField(name).ifPresent(content -> entry.setField(name, OAI2Handler.correctLineBreaks(content)));
}
if (fixedKey.matches("\\d\\d\\d\\d\\..*")) {
entry.setField(FieldName.YEAR, "20" + fixedKey.substring(0, 2));
int monthNumber = Integer.parseInt(fixedKey.substring(2, 4));
Optional<Month> month = Month.getMonthByNumber(monthNumber);
month.ifPresent(entry::setMonth);
}
}
return entry;
}
use of org.xml.sax.helpers.DefaultHandler in project jabref by JabRef.
the class MrDLibImporter method isRecognizedFormat.
@Override
public boolean isRecognizedFormat(BufferedReader input) throws IOException {
String recommendationsAsString = convertToString(input);
// check for valid format
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
DefaultHandler handler = new DefaultHandler() {
};
try (InputStream stream = new ByteArrayInputStream(recommendationsAsString.getBytes())) {
saxParser.parse(stream, handler);
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
return false;
}
} catch (ParserConfigurationException | SAXException e) {
LOGGER.error(e.getMessage(), e);
return false;
}
return true;
}
use of org.xml.sax.helpers.DefaultHandler in project android_frameworks_base by ResurrectionRemix.
the class ExpatPerformanceTest method runSax.
private void runSax() throws IOException, SAXException {
long start = System.currentTimeMillis();
Xml.parse(newInputStream(), Xml.Encoding.UTF_8, new DefaultHandler());
long elapsed = System.currentTimeMillis() - start;
Log.i(TAG, "expat SAX: " + elapsed + "ms");
}
Aggregations