use of javax.xml.parsers.SAXParserFactory in project robovm by robovm.
the class SimpleParserTest method testWorkingFile2.
public void testWorkingFile2() throws Exception {
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(false);
factory.setNamespaceAware(false);
factory.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
SAXParser parser = factory.newSAXParser();
parser.getXMLReader().setContentHandler(contentHandler);
parser.parse(getClass().getResourceAsStream("/SimpleParserTest.xml"), (DefaultHandler) null);
assertFalse(parser.isNamespaceAware());
assertEquals("The:quick,brown:fox", instructions.toString());
assertEquals("t:stuff,nestedStuff,nestedStuff,nestedStuff", elements2.toString());
assertEquals("Some text here,some more here...", text.toString());
assertEquals("eins", attributes2.get("one"));
assertEquals("zwei", attributes2.get("two"));
assertEquals("drei", attributes2.get("three"));
assertEquals(0, namespaces2.size());
}
use of javax.xml.parsers.SAXParserFactory in project Cloud9 by lintool.
the class ParallelCorpusReader method parseXMLDocument.
public static void parseXMLDocument(String file, PChunkCallback cb) {
//get a factory
ParallelCorpusReader pcr = new ParallelCorpusReader(cb);
final SAXParserFactory spf = SAXParserFactory.newInstance();
try {
//get a new instance of parser
final SAXParser sp = spf.newSAXParser();
//parse the file and also register this class for call backs
sp.parse(file, pcr);
} catch (final SAXException se) {
se.printStackTrace();
} catch (final ParserConfigurationException pce) {
pce.printStackTrace();
} catch (final IOException ie) {
ie.printStackTrace();
}
}
use of javax.xml.parsers.SAXParserFactory in project languagetool by languagetool-org.
the class FalseFriendRuleLoader method getRules.
public final List<AbstractPatternRule> getRules(InputStream stream, Language textLanguage, Language motherTongue) throws ParserConfigurationException, SAXException, IOException {
FalseFriendRuleHandler handler = new FalseFriendRuleHandler(textLanguage, motherTongue);
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
saxParser.getXMLReader().setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
saxParser.parse(stream, handler);
List<AbstractPatternRule> rules = handler.getRules();
// Add suggestions to each rule:
ResourceBundle messages = ResourceBundle.getBundle(JLanguageTool.MESSAGE_BUNDLE, motherTongue.getLocale());
MessageFormat msgFormat = new MessageFormat(messages.getString("false_friend_suggestion"));
for (AbstractPatternRule rule : rules) {
List<String> suggestions = handler.getSuggestionMap().get(rule.getId());
if (suggestions != null) {
String[] msg = { formatSuggestions(suggestions) };
rule.setMessage(rule.getMessage() + " " + msgFormat.format(msg));
}
}
return rules;
}
use of javax.xml.parsers.SAXParserFactory in project languagetool by languagetool-org.
the class PatternRuleLoader method getRules.
/**
* @param is stream with the XML rules
* @param filename used only for verbose exception message - should refer to where the stream comes from
*/
public final List<AbstractPatternRule> getRules(InputStream is, String filename) throws IOException {
try {
PatternRuleHandler handler = new PatternRuleHandler();
handler.setRelaxedMode(relaxedMode);
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
Tools.setPasswordAuthenticator();
saxParser.getXMLReader().setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
saxParser.parse(is, handler);
return handler.getRules();
} catch (Exception e) {
throw new IOException("Cannot load or parse input stream of '" + filename + "'", e);
}
}
use of javax.xml.parsers.SAXParserFactory in project languagetool by languagetool-org.
the class BitextPatternRuleLoader method getRules.
public final List<BitextPatternRule> getRules(InputStream is, String filename) throws IOException {
List<BitextPatternRule> rules;
try {
BitextPatternRuleHandler handler = new BitextPatternRuleHandler();
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
saxParser.getXMLReader().setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
saxParser.parse(is, handler);
rules = handler.getBitextRules();
return rules;
} catch (Exception e) {
throw new IOException("Cannot load or parse '" + filename + "'", e);
}
}
Aggregations