List of usage examples for javax.xml.parsers SAXParserFactory newInstance
public static SAXParserFactory newInstance()
From source file:com.connectsdk.service.NetcastTVService.java
private JSONArray parseApplicationsXmlToJSON(String data) { SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); try {/*from w ww . j a v a 2s .com*/ InputStream stream = new ByteArrayInputStream(data.getBytes("UTF-8")); SAXParser saxParser = saxParserFactory.newSAXParser(); NetcastApplicationsParser handler = new NetcastApplicationsParser(); saxParser.parse(stream, handler); return handler.getApplications(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:android_network.hetnet.vpn_service.ActivitySettings.java
private void xmlImport(InputStream in) throws IOException, SAXException, ParserConfigurationException { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); prefs.unregisterOnSharedPreferenceChangeListener(this); prefs.edit().putBoolean("enabled", false).apply(); ServiceSinkhole.stop("import", this); XMLReader reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader(); XmlImportHandler handler = new XmlImportHandler(this); reader.setContentHandler(handler);/*from w w w .j a va2 s. c o m*/ reader.parse(new InputSource(in)); xmlImport(handler.application, prefs); xmlImport(handler.wifi, getSharedPreferences("wifi", Context.MODE_PRIVATE)); xmlImport(handler.mobile, getSharedPreferences("other", Context.MODE_PRIVATE)); xmlImport(handler.unused, getSharedPreferences("unused", Context.MODE_PRIVATE)); xmlImport(handler.screen_wifi, getSharedPreferences("screen_wifi", Context.MODE_PRIVATE)); xmlImport(handler.screen_other, getSharedPreferences("screen_other", Context.MODE_PRIVATE)); xmlImport(handler.roaming, getSharedPreferences("roaming", Context.MODE_PRIVATE)); xmlImport(handler.apply, getSharedPreferences("apply", Context.MODE_PRIVATE)); xmlImport(handler.notify, getSharedPreferences("notify", Context.MODE_PRIVATE)); // Upgrade imported settings Receiver.upgrade(true, this); // Refresh UI prefs.edit().putBoolean("imported", true).apply(); prefs.registerOnSharedPreferenceChangeListener(this); }
From source file:at.vcity.androidim.services.IMService.java
private void parseFriendInfo(String xml) { try {// w w w . j a v a 2s .c o m SAXParser sp = SAXParserFactory.newInstance().newSAXParser(); sp.parse(new ByteArrayInputStream(xml.getBytes()), new XMLHandler(IMService.this)); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:at.vcity.androidim.services.IMService.java
private void parseMessageInfo(String xml) { try {/*from www. ja va2 s .c o m*/ SAXParser sp = SAXParserFactory.newInstance().newSAXParser(); sp.parse(new ByteArrayInputStream(xml.getBytes()), new XMLHandler(IMService.this)); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.ac.vct.pharmacylog.services.IMService.java
public void parseFriendInfo(String xml) { try {//from w w w .j av a 2s .c o m SAXParser sp = SAXParserFactory.newInstance().newSAXParser(); sp.parse(new ByteArrayInputStream(xml.getBytes()), new XMLHandler(IMService.this)); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.ac.vct.pharmacylog.services.IMService.java
public void parseMessageInfo(String xml) { //Log.v("IMService", "Parse Message Info"); try {/* w w w .jav a 2s . c o m*/ SAXParser sp = SAXParserFactory.newInstance().newSAXParser(); sp.parse(new ByteArrayInputStream(xml.getBytes()), new XMLHandler(IMService.this)); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.anysoftkeyboard.ui.settings.wordseditor.RestoreUserWordsAsyncTask.java
@Override protected Void doAsyncTask(Void[] params) throws Exception { final Fragment owner = getOwner(); if (owner == null) return null; final Context context = owner.getContext(); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); final FileInputStream fileInputStream = new FileInputStream(new File(getBackupFolder(context), mFilename)); try {//from ww w . j a va 2s.c om parser.parse(fileInputStream, new DefaultHandler() { private boolean mInWord = false; private int mFreq = 1; private String mWord = ""; @Override public void characters(char[] ch, int start, int length) throws SAXException { super.characters(ch, start, length); if (mInWord) { mWord += new String(ch, start, length); } } @Override public void startElement(String uri, String localName, String qualifiedName, Attributes attributes) throws SAXException { super.startElement(uri, localName, qualifiedName, attributes); if (localName.equals("w")) { mInWord = true; mWord = ""; mFreq = Integer.parseInt(attributes.getValue("f")); } if (localName.equals("wordlist")) { mLocale = attributes.getValue("locale"); Logger.d(TAG, "Building dictionary for locale " + mLocale); if (mDictionary != null) { mDictionary.close(); } mDictionary = new UserDictionary(context, mLocale); mDictionary.loadDictionary(); Logger.d(TAG, "Starting restore to locale " + mLocale); } } @Override public void endElement(String uri, String localName, String qualifiedName) throws SAXException { if (mInWord && localName.equals("w")) { if (!TextUtils.isEmpty(mWord)) { Logger.d(TAG, "Restoring mWord '" + mWord + "' with mFreq " + mFreq); // Disallow duplicates mDictionary.deleteWord(mWord); mDictionary.addWord(mWord, mFreq); } mInWord = false; } super.endElement(uri, localName, qualifiedName); } }); } finally { fileInputStream.close(); } return null; }
From source file:com.baidar.androidChatter.serve.MessagingService.java
private void parseFriendInfo(String xml) { try {//from ww w .j a va 2 s . com SAXParser sp = SAXParserFactory.newInstance().newSAXParser(); sp.parse(new ByteArrayInputStream(xml.getBytes()), new HandlerXML(MessagingService.this)); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.baidar.androidChatter.serve.MessagingService.java
private void parseMessageInfo(String xml) { try {/*from w w w. j a v a 2 s. c o m*/ SAXParser sp = SAXParserFactory.newInstance().newSAXParser(); sp.parse(new ByteArrayInputStream(xml.getBytes()), new HandlerXML(MessagingService.this)); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.jiahuan.svgmapview.core.helper.map.SVGParser.java
static SVG parse(InputSource data, SVGHandler handler) throws SVGParseException { try {/* www .j av a 2 s . com*/ final Picture picture = new Picture(); handler.setPicture(picture); SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); xr.setContentHandler(handler); xr.setFeature("http://xml.org/sax/features/validation", false); if (DISALLOW_DOCTYPE_DECL) { try { xr.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); } catch (SAXNotRecognizedException e) { DISALLOW_DOCTYPE_DECL = false; } } xr.parse(data); SVG result = new SVG(picture, handler.bounds); // Skip bounds if it was an empty pic if (!Float.isInfinite(handler.limits.top)) { result.setLimits(handler.limits); } return result; } catch (Exception e) { Log.e(TAG, "Failed to parse SVG.", e); throw new SVGParseException(e); } }