use of javax.xml.parsers.SAXParser in project Openfire by igniterealtime.
the class SimplePresence method parse.
// public Presence convertSIPPresenceToXMPP(String sipPresence) {
// Presence xmppPresence = new Presence();
//
// SAXParser saxParser;
// try {
// SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
// saxParser = saxParserFactory.newSAXParser();
//
// } catch (Exception e) {
// Log.debug("Unable to load parser to parse SIP presence to XMPP Presence.", e);
// return xmppPresence;
// }
//
// return xmppPresence;
// }
// public String convertXMPPPresenceToSIP(Presence xmppPresence) {
// String sipPresence = "";
// String basic = "open";
// String rpid = "unknown";
// String dmNote = "";
//
// if (!xmppPresence.isAvailable()) {
// // Prepare "closed" basic presence.
// basic = "closed";
// } else {
// Presence.Show xmppPresenceShow = xmppPresence.getShow();
// if (xmppPresenceShow.equals(Presence.Show.away)) {
// rpid = "away";
// } else if (xmppPresenceShow.equals(Presence.Show.chat)) {
// rpid = "away";
// } else if (xmppPresenceShow.equals(Presence.Show.dnd)) {
// rpid = "busy";
// } else if (xmppPresenceShow.equals(Presence.Show.xa)) {
// rpid = "away";
// } else {
// rpid = "";
// }
// }
//
// sipPresence = "<?xml version='1.0' encoding='UTF-8'?>"
// + "<presence xmlns='urn:ietf:params:xml:ns:pidf' xmlns:dm='urn:ietf:params:xml:ns:pidf:data-model' "
// + "xmlns:rpid='urn:ietf:params:xml:ns:pidf:rpid' xmlns:c='urn:ietf:params:xml:ns:pidf:cipid' "
// + "entity='pres:sip:sipdemo1@192.168.1.199'>"
// + "<tuple><status><basic>" + basic + "</basic></status></tuple>"
// + "<dm:person id='p3e32d940'><rpid:activities><rpid:" + rpid + "/></rpid:activities></dm:person></presence>";
//
// return sipPresence;
// }
public void parse(String simplePresenceXml) throws Exception {
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
SAXParser saxParser = saxParserFactory.newSAXParser();
ByteArrayInputStream bais = new ByteArrayInputStream(simplePresenceXml.getBytes());
saxParser.parse(bais, new SimplePresenceParser());
bais.close();
}
use of javax.xml.parsers.SAXParser in project musicbrainz-android by jdamcd.
the class ResponseParser method parse.
protected void parse(InputStream stream, DefaultHandler handler) throws IOException {
try {
SAXParser parser = factory.newSAXParser();
XMLReader reader = parser.getXMLReader();
InputSource source = new InputSource(stream);
reader.setContentHandler(handler);
reader.parse(source);
} catch (SAXException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
}
use of javax.xml.parsers.SAXParser in project languagetool by languagetool-org.
the class XMLValidator method validateInternal.
private void validateInternal(String xml, String dtdPath, String docType) throws SAXException, IOException, ParserConfigurationException {
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(true);
SAXParser saxParser = factory.newSAXParser();
//used for removing existing DOCTYPE from grammar.xml files
String cleanXml = xml.replaceAll("<!DOCTYPE.+>", "");
String decl = "<?xml version=\"1.0\"";
String endDecl = "?>";
URL dtdUrl = this.getClass().getResource(dtdPath);
if (dtdUrl == null) {
throw new RuntimeException("DTD not found in classpath: " + dtdPath);
}
String dtd = "<!DOCTYPE " + docType + " PUBLIC \"-//W3C//DTD Rules 0.1//EN\" \"" + dtdUrl + "\">";
int pos = cleanXml.indexOf(decl);
int endPos = cleanXml.indexOf(endDecl);
if (pos == -1) {
throw new IOException("No XML declaration found in '" + cleanXml.substring(0, Math.min(100, cleanXml.length())) + "...'");
}
String newXML = cleanXml.substring(0, endPos + endDecl.length()) + "\r\n" + dtd + cleanXml.substring(endPos + endDecl.length());
InputSource is = new InputSource(new StringReader(newXML));
saxParser.parse(is, new ErrorHandler());
}
use of javax.xml.parsers.SAXParser in project AndEngine by nicolasgramlich.
the class LevelLoader method loadLevelFromStream.
public void loadLevelFromStream(final InputStream pInputStream) throws IOException {
try {
final SAXParserFactory spf = SAXParserFactory.newInstance();
final SAXParser sp = spf.newSAXParser();
final XMLReader xr = sp.getXMLReader();
this.onBeforeLoadLevel();
final LevelParser levelParser = new LevelParser(this.mDefaultEntityLoader, this.mEntityLoaders);
xr.setContentHandler(levelParser);
xr.parse(new InputSource(new BufferedInputStream(pInputStream)));
this.onAfterLoadLevel();
} catch (final SAXException se) {
Debug.e(se);
/* Doesn't happen. */
} catch (final ParserConfigurationException pe) {
Debug.e(pe);
/* Doesn't happen. */
} finally {
StreamUtils.close(pInputStream);
}
}
use of javax.xml.parsers.SAXParser in project AndEngine by nicolasgramlich.
the class TexturePackLoader method load.
public TexturePack load(final InputStream pInputStream, final String pAssetBasePath) throws TexturePackParseException {
try {
final SAXParserFactory spf = SAXParserFactory.newInstance();
final SAXParser sp = spf.newSAXParser();
final XMLReader xr = sp.getXMLReader();
final TexturePackParser texturePackParser = new TexturePackParser(this.mAssetManager, pAssetBasePath, this.mTextureManager);
xr.setContentHandler(texturePackParser);
xr.parse(new InputSource(new BufferedInputStream(pInputStream)));
return texturePackParser.getTexturePack();
} catch (final SAXException e) {
throw new TexturePackParseException(e);
} catch (final ParserConfigurationException pe) {
/* Doesn't happen. */
return null;
} catch (final IOException e) {
throw new TexturePackParseException(e);
} finally {
StreamUtils.close(pInputStream);
}
}
Aggregations