List of usage examples for android.util Xml newSerializer
public static XmlSerializer newSerializer()
From source file:net.vexelon.bgrates.Utils.java
/** * Parse org.w3c.dom Document and serialized to a String using Android Util.xml * @param document - org.w3c.dom Xml Document * @return//from www . ja v a2 s.c o m * @throws RuntimeException */ public static String getXmlDoc(Document document) throws RuntimeException { XmlSerializer serializer = Xml.newSerializer(); StringWriter writer = new StringWriter(1024); try { serializer.setOutput(writer); serializeXml(document, serializer); } catch (Exception e) { throw new RuntimeException("Failed converting Xml to String!", e); } return writer.toString(); }
From source file:net.vexelon.bgrates.Utils.java
/** * Parse org.w3c.dom Document and serialized to a file using Android Util.xml * @param document - org.w3c.dom Xml Document * @param file//from w w w . ja v a2s . c om * @throws RuntimeException */ public static void saveXmlDoc(Document document, File file) throws RuntimeException { XmlSerializer serializer = Xml.newSerializer(); try { FileWriter writer = new FileWriter(file); serializer.setOutput(writer); serializeXml(document, serializer); } catch (Exception e) { throw new RuntimeException("Failed save Xml to " + file.getName(), e); } }
From source file:de.teunito.android.cyclelife.RennradNewsShare.java
private String generateXML(TrackInfo trackInfo) { XmlSerializer serializer = Xml.newSerializer(); StringWriter writer = new StringWriter(); try {/* w ww . j a v a2s . c o m*/ serializer.setOutput(writer); serializer.startDocument("UTF-8", true); serializer.startTag("", "request"); serializer.startTag("", "key"); serializer.text(APIKey); serializer.endTag("", "key"); serializer.startTag("", "unit"); serializer.startTag("", "title"); serializer.text(trackInfo.getTitle()); serializer.endTag("", "title"); serializer.startTag("", "unitdate"); serializer.text(trackInfo.getDate()); serializer.endTag("", "unitdate"); serializer.startTag("", "category_id"); serializer.text(sportsID); // 1=Radfahren, 2=Laufen, 3=Kraftsport 4=Schwimmen, 5=Sonstige, 6=Skilanglauf serializer.endTag("", "category_id"); serializer.startTag("", "bike_id"); if (bikeId != "") { serializer.text(bikeId); } serializer.endTag("", "bike_id"); serializer.startTag("", "unittype_id"); serializer.text(zoneId); // Trainingsbereich: 1=Regeneration, ... serializer.endTag("", "unittype_id"); serializer.startTag("", "condition_id"); serializer.text(weatherId); // Wetter: 1=sonnig, 2=heiter ... serializer.endTag("", "condition_id"); serializer.startTag("", "mood_id"); serializer.text(moodId); // Stimmung: 1=sehr gut, 2=gut, ... serializer.endTag("", "mood_id"); serializer.startTag("", "temperature"); serializer.text(temperature); serializer.endTag("", "temperature"); serializer.startTag("", "length"); serializer.text("180"); // Dauer der Einheit in Minuten serializer.endTag("", "length"); serializer.startTag("", "distance"); serializer.text(String.valueOf(trackInfo.getDistance())); serializer.endTag("", "distance"); serializer.startTag("", "climbing"); serializer.text(String.valueOf(trackInfo.getAltitudeUp())); // Hoehenmeter der Einheit in Meter serializer.endTag("", "climbing"); serializer.startTag("", "heartrate_avg"); serializer.text(String.valueOf(trackInfo.getAvgHeartBeat())); serializer.endTag("", "heartrate_avg"); serializer.startTag("", "heartrate_max"); serializer.text(String.valueOf(trackInfo.getMaxHeartBeat())); serializer.endTag("", "heartrate_max"); serializer.startTag("", "cadence"); serializer.text(String.valueOf(trackInfo.getAvgCadence())); serializer.endTag("", "cadence"); serializer.startTag("", "weight"); if (weight == "") { serializer.text("0"); } else serializer.text(weight); serializer.endTag("", "weight"); serializer.startTag("", "maxspeed"); serializer.text(String.valueOf(trackInfo.getMaxSpeed())); serializer.endTag("", "maxspeed"); serializer.startTag("", "description"); serializer.text(trackInfo.getDescription()); serializer.endTag("", "description"); serializer.startTag("", "public"); serializer.text("0"); // 0 = nicht ffentlich, 1 = ffentlich serializer.endTag("", "public"); serializer.startTag("", "publish_wp"); serializer.text("0"); // im Winterpokal verffentlichen? 1= true, 0= false serializer.endTag("", "publish_wp"); serializer.endTag("", "unit"); serializer.endTag("", "request"); serializer.endDocument(); String xml = writer.toString(); return xml; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.android.exchange.EasSyncService.java
/** * Use the Exchange 2007 AutoDiscover feature to try to retrieve server information using * only an email address and the password * * @param userName the user's email address * @param password the user's password//from w w w .j a va 2 s . c o m * @return a HostAuth ready to be saved in an Account or null (failure) */ public Bundle tryAutodiscover(String userName, String password) throws RemoteException { XmlSerializer s = Xml.newSerializer(); ByteArrayOutputStream os = new ByteArrayOutputStream(1024); HostAuth hostAuth = new HostAuth(); Bundle bundle = new Bundle(); bundle.putInt(EmailServiceProxy.AUTO_DISCOVER_BUNDLE_ERROR_CODE, MessagingException.NO_ERROR); try { // Build the XML document that's sent to the autodiscover server(s) s.setOutput(os, "UTF-8"); s.startDocument("UTF-8", false); s.startTag(null, "Autodiscover"); s.attribute(null, "xmlns", AUTO_DISCOVER_SCHEMA_PREFIX + "requestschema/2006"); s.startTag(null, "Request"); s.startTag(null, "EMailAddress").text(userName).endTag(null, "EMailAddress"); s.startTag(null, "AcceptableResponseSchema"); s.text(AUTO_DISCOVER_SCHEMA_PREFIX + "responseschema/2006"); s.endTag(null, "AcceptableResponseSchema"); s.endTag(null, "Request"); s.endTag(null, "Autodiscover"); s.endDocument(); String req = os.toString(); // Initialize the user name and password mUserName = userName; mPassword = password; // Make sure the authentication string is recreated and cached cacheAuthAndCmdString(); // Split out the domain name int amp = userName.indexOf('@'); // The UI ensures that userName is a valid email address if (amp < 0) { throw new RemoteException(); } String domain = userName.substring(amp + 1); // There are up to four attempts here; the two URLs that we're supposed to try per the // specification, and up to one redirect for each (handled in postAutodiscover) // Note: The expectation is that, of these four attempts, only a single server will // actually be identified as the autodiscover server. For the identified server, // we may also try a 2nd connection with a different format (bare name). // Try the domain first and see if we can get a response HttpPost post = new HttpPost("https://" + domain + AUTO_DISCOVER_PAGE); setHeaders(post, false); post.setHeader("Content-Type", "text/xml"); post.setEntity(new StringEntity(req)); HttpClient client = getHttpClient(COMMAND_TIMEOUT); HttpResponse resp; try { resp = postAutodiscover(client, post, true /*canRetry*/); } catch (IOException e1) { userLog("IOException in autodiscover; trying alternate address"); // We catch the IOException here because we have an alternate address to try post.setURI(URI.create("https://autodiscover." + domain + AUTO_DISCOVER_PAGE)); // If we fail here, we're out of options, so we let the outer try catch the // IOException and return null resp = postAutodiscover(client, post, true /*canRetry*/); } // Get the "final" code; if it's not 200, just return null int code = resp.getStatusLine().getStatusCode(); userLog("Code: " + code); if (code != HttpStatus.SC_OK) return null; // At this point, we have a 200 response (SC_OK) HttpEntity e = resp.getEntity(); InputStream is = e.getContent(); try { // The response to Autodiscover is regular XML (not WBXML) // If we ever get an error in this process, we'll just punt and return null XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); XmlPullParser parser = factory.newPullParser(); parser.setInput(is, "UTF-8"); int type = parser.getEventType(); if (type == XmlPullParser.START_DOCUMENT) { type = parser.next(); if (type == XmlPullParser.START_TAG) { String name = parser.getName(); if (name.equals("Autodiscover")) { hostAuth = new HostAuth(); parseAutodiscover(parser, hostAuth); // On success, we'll have a server address and login if (hostAuth.mAddress != null) { // Fill in the rest of the HostAuth // We use the user name and password that were successful during // the autodiscover process hostAuth.mLogin = mUserName; hostAuth.mPassword = mPassword; hostAuth.mPort = 443; hostAuth.mProtocol = "eas"; hostAuth.mFlags = HostAuth.FLAG_SSL | HostAuth.FLAG_AUTHENTICATE; bundle.putParcelable(EmailServiceProxy.AUTO_DISCOVER_BUNDLE_HOST_AUTH, hostAuth); } else { bundle.putInt(EmailServiceProxy.AUTO_DISCOVER_BUNDLE_ERROR_CODE, MessagingException.UNSPECIFIED_EXCEPTION); } } } } } catch (XmlPullParserException e1) { // This would indicate an I/O error of some sort // We will simply return null and user can configure manually } // There's no reason at all for exceptions to be thrown, and it's ok if so. // We just won't do auto-discover; user can configure manually } catch (IllegalArgumentException e) { bundle.putInt(EmailServiceProxy.AUTO_DISCOVER_BUNDLE_ERROR_CODE, MessagingException.UNSPECIFIED_EXCEPTION); } catch (IllegalStateException e) { bundle.putInt(EmailServiceProxy.AUTO_DISCOVER_BUNDLE_ERROR_CODE, MessagingException.UNSPECIFIED_EXCEPTION); } catch (IOException e) { userLog("IOException in Autodiscover", e); bundle.putInt(EmailServiceProxy.AUTO_DISCOVER_BUNDLE_ERROR_CODE, MessagingException.IOERROR); } catch (MessagingException e) { bundle.putInt(EmailServiceProxy.AUTO_DISCOVER_BUNDLE_ERROR_CODE, MessagingException.AUTHENTICATION_FAILED); } return bundle; }
From source file:it.bradipao.berengar.DbTool.java
public static int db2xml(SQLiteDatabase mDB, File xmlFile) { // vars/*from ww w . j a v a2 s . c om*/ final String XML_DATABASE = "database"; final String XML_DBNAME = "dbname"; final String XML_TABLES = "tables"; final String XML_TABLE = "table"; final String XML_TABLENAME = "tablename"; final String XML_TABLESQL = "tablesql"; final String XML_COLSNAME = "colsname"; final String XML_ROWS = "rows"; final String XML_ROW = "r"; final String XML_COL = "c"; // tables list query and cursor int iTableNum = 0; FileWriter fw = null; BufferedWriter bw = null; XmlSerializer sr = Xml.newSerializer(); String tblquery = "select * from sqlite_master"; Cursor tblcur = mDB.rawQuery(tblquery, null); String rowquery = ""; Cursor rowcur = null; // file writers try { fw = new FileWriter(xmlFile); bw = new BufferedWriter(fw); sr.setOutput(bw); } catch (FileNotFoundException e) { Log.e(LOGTAG, "error in db2gson file writers", e); } catch (IOException e) { Log.e(LOGTAG, "error in db2gson file writers", e); } // xml serializer try { // prepare xml document sr.startDocument("UTF-8", true); sr.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); // start document sr.startTag("", XML_DATABASE); sr.startTag("", XML_DBNAME); sr.text(xmlFile.getName()); sr.endTag("", XML_DBNAME); sr.startTag("", XML_TABLES); // iterate through tables String sTableName = ""; String sTableSql = ""; while (tblcur.moveToNext()) { sTableName = tblcur.getString(tblcur.getColumnIndex("name")); sTableSql = tblcur.getString(tblcur.getColumnIndex("sql")); if (GOLOG) Log.d(LOGTAG, "TABLE NAME : " + sTableName); // skip metadata, sequence, and uidx before exporting tables if (!sTableName.equals("android_metadata") && !sTableName.equals("sqlite_sequence") && !sTableName.startsWith("uidx") && !sTableName.startsWith("idx_") && !sTableName.startsWith("_idx")) { // table query and cursor iTableNum++; rowquery = "select * from " + sTableName; rowcur = mDB.rawQuery(rowquery, null); // exporting table sr.startTag("", XML_TABLE); sr.startTag("", XML_TABLENAME); sr.text(sTableName); sr.endTag("", XML_TABLENAME); if ((sTableSql != null) && (!sTableSql.isEmpty())) { sr.startTag("", XML_TABLESQL); sr.text(sTableSql); sr.endTag("", XML_TABLESQL); } // iteratew through rows int i = -1; while (rowcur.moveToNext()) { // at first element store column names if (i == -1) { sr.startTag("", XML_COLSNAME); for (i = 0; i < rowcur.getColumnCount(); i++) { sr.startTag("", XML_COL); sr.text(rowcur.getColumnName(i)); sr.endTag("", XML_COL); } sr.endTag("", XML_COLSNAME); sr.startTag("", XML_ROWS); } // get values sr.startTag("", XML_ROW); for (i = 0; i < rowcur.getColumnCount(); i++) { sr.startTag("", XML_COL); sr.text(rowcur.getString(i)); sr.endTag("", XML_COL); } sr.endTag("", XML_ROW); } // finishing table query rowcur.close(); sr.endTag("", XML_ROWS); sr.endTag("", XML_TABLE); } } // finishing table query tblcur.close(); sr.endTag("", XML_TABLES); sr.endTag("", XML_DATABASE); // finishing sr.endDocument(); sr.flush(); } catch (Exception e) { Log.e(LOGTAG, "error in db2xml", e); } return iTableNum; }
From source file:eu.operando.operandoapp.database.DatabaseHelper.java
public String exportAllPermissionsPerDomain() { List<String[]> result1 = getAllPermissionsPerAllowedDomain(); List<String[]> result2 = getAllPermissionsPerBlockedDomain(); XmlSerializer serializer = Xml.newSerializer(); StringWriter sw = new StringWriter(); try {//from w w w . j ava2s .c o m serializer.setOutput(sw); serializer.startDocument("UTF-8", true); serializer.startTag("", "settings"); //allowed serializer.startTag("", "allowed"); for (String[] s : result1) { serializer.startTag("", "app"); serializer.attribute("", "app_name", s[0].replaceAll("\\(.*?\\)", "")); serializer.startTag("", "app_info"); serializer.text(s[0]); serializer.endTag("", "app_info"); serializer.startTag("", "permissions"); serializer.text(s[1]); serializer.endTag("", "permissions"); serializer.endTag("", "app"); } serializer.endTag("", "allowed"); //blocked serializer.startTag("", "blocked"); for (String[] s : result2) { serializer.startTag("", "app"); serializer.attribute("", "app_name", s[0].replaceAll("\\(.*?\\)", "")); serializer.startTag("", "app_info"); serializer.text(s[0]); serializer.endTag("", "app_info"); serializer.startTag("", "permissions"); serializer.text(s[1]); serializer.endTag("", "permissions"); serializer.endTag("", "app"); } serializer.endTag("", "blocked"); serializer.endTag("", "settings"); serializer.endDocument(); serializer.flush(); } catch (Exception e) { e.printStackTrace(); return null; } return sw.toString(); }
From source file:eu.faircode.adblocker.ActivitySettings.java
private void xmlExport(OutputStream out) throws IOException { XmlSerializer serializer = Xml.newSerializer(); serializer.setOutput(out, "UTF-8"); serializer.startDocument(null, true); serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); serializer.startTag(null, "adblocker"); serializer.startTag(null, "application"); xmlExport(PreferenceManager.getDefaultSharedPreferences(this), serializer); serializer.endTag(null, "application"); serializer.startTag(null, "wifi"); xmlExport(getSharedPreferences("wifi", Context.MODE_PRIVATE), serializer); serializer.endTag(null, "wifi"); serializer.startTag(null, "mobile"); xmlExport(getSharedPreferences("other", Context.MODE_PRIVATE), serializer); serializer.endTag(null, "mobile"); serializer.startTag(null, "screen_wifi"); xmlExport(getSharedPreferences("screen_wifi", Context.MODE_PRIVATE), serializer); serializer.endTag(null, "screen_wifi"); serializer.startTag(null, "screen_other"); xmlExport(getSharedPreferences("screen_other", Context.MODE_PRIVATE), serializer); serializer.endTag(null, "screen_other"); serializer.startTag(null, "apply"); xmlExport(getSharedPreferences("apply", Context.MODE_PRIVATE), serializer); serializer.endTag(null, "apply"); serializer.startTag(null, "notify"); xmlExport(getSharedPreferences("notify", Context.MODE_PRIVATE), serializer); serializer.endTag(null, "notify"); serializer.startTag(null, "filter"); filterExport(serializer);//from w w w . j av a 2s .co m serializer.endTag(null, "filter"); serializer.startTag(null, "forward"); forwardExport(serializer); serializer.endTag(null, "forward"); serializer.endTag(null, "adblocker"); serializer.endDocument(); serializer.flush(); }
From source file:com.master.metehan.filtereagle.ActivitySettings.java
private void xmlExport(OutputStream out) throws IOException { XmlSerializer serializer = Xml.newSerializer(); serializer.setOutput(out, "UTF-8"); serializer.startDocument(null, true); serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); serializer.startTag(null, "filtereagle"); serializer.startTag(null, "application"); xmlExport(PreferenceManager.getDefaultSharedPreferences(this), serializer); serializer.endTag(null, "application"); serializer.startTag(null, "wifi"); xmlExport(getSharedPreferences("wifi", Context.MODE_PRIVATE), serializer); serializer.endTag(null, "wifi"); serializer.startTag(null, "mobile"); xmlExport(getSharedPreferences("other", Context.MODE_PRIVATE), serializer); serializer.endTag(null, "mobile"); serializer.startTag(null, "screen_wifi"); xmlExport(getSharedPreferences("screen_wifi", Context.MODE_PRIVATE), serializer); serializer.endTag(null, "screen_wifi"); serializer.startTag(null, "screen_other"); xmlExport(getSharedPreferences("screen_other", Context.MODE_PRIVATE), serializer); serializer.endTag(null, "screen_other"); serializer.startTag(null, "apply"); xmlExport(getSharedPreferences("apply", Context.MODE_PRIVATE), serializer); serializer.endTag(null, "apply"); serializer.startTag(null, "notify"); xmlExport(getSharedPreferences("notify", Context.MODE_PRIVATE), serializer); serializer.endTag(null, "notify"); serializer.startTag(null, "filter"); filterExport(serializer);// w ww. j a v a 2 s.co m serializer.endTag(null, "filter"); serializer.startTag(null, "forward"); forwardExport(serializer); serializer.endTag(null, "forward"); serializer.endTag(null, "filtereagle"); serializer.endDocument(); serializer.flush(); }
From source file:eu.faircode.netguard.ActivitySettings.java
private void xmlExport(OutputStream out) throws IOException { XmlSerializer serializer = Xml.newSerializer(); serializer.setOutput(out, "UTF-8"); serializer.startDocument(null, true); serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); serializer.startTag(null, "netguard"); serializer.startTag(null, "application"); xmlExport(PreferenceManager.getDefaultSharedPreferences(this), serializer); serializer.endTag(null, "application"); serializer.startTag(null, "wifi"); xmlExport(getSharedPreferences("wifi", Context.MODE_PRIVATE), serializer); serializer.endTag(null, "wifi"); serializer.startTag(null, "mobile"); xmlExport(getSharedPreferences("other", Context.MODE_PRIVATE), serializer); serializer.endTag(null, "mobile"); serializer.startTag(null, "screen_wifi"); xmlExport(getSharedPreferences("screen_wifi", Context.MODE_PRIVATE), serializer); serializer.endTag(null, "screen_wifi"); serializer.startTag(null, "screen_other"); xmlExport(getSharedPreferences("screen_other", Context.MODE_PRIVATE), serializer); serializer.endTag(null, "screen_other"); serializer.startTag(null, "roaming"); xmlExport(getSharedPreferences("roaming", Context.MODE_PRIVATE), serializer); serializer.endTag(null, "roaming"); serializer.startTag(null, "lockdown"); xmlExport(getSharedPreferences("lockdown", Context.MODE_PRIVATE), serializer); serializer.endTag(null, "lockdown"); serializer.startTag(null, "apply"); xmlExport(getSharedPreferences("apply", Context.MODE_PRIVATE), serializer); serializer.endTag(null, "apply"); serializer.startTag(null, "notify"); xmlExport(getSharedPreferences("notify", Context.MODE_PRIVATE), serializer); serializer.endTag(null, "notify"); serializer.startTag(null, "filter"); filterExport(serializer);//w w w . ja v a 2 s . c o m serializer.endTag(null, "filter"); serializer.startTag(null, "forward"); forwardExport(serializer); serializer.endTag(null, "forward"); serializer.endTag(null, "netguard"); serializer.endDocument(); serializer.flush(); }
From source file:android_network.hetnet.vpn_service.ActivitySettings.java
private void xmlExport(OutputStream out) throws IOException { XmlSerializer serializer = Xml.newSerializer(); serializer.setOutput(out, "UTF-8"); serializer.startDocument(null, true); serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); serializer.startTag(null, "netguard"); serializer.startTag(null, "application"); xmlExport(PreferenceManager.getDefaultSharedPreferences(this), serializer); serializer.endTag(null, "application"); serializer.startTag(null, "wifi"); xmlExport(getSharedPreferences("wifi", Context.MODE_PRIVATE), serializer); serializer.endTag(null, "wifi"); serializer.startTag(null, "mobile"); xmlExport(getSharedPreferences("other", Context.MODE_PRIVATE), serializer); serializer.endTag(null, "mobile"); serializer.startTag(null, "screen_wifi"); xmlExport(getSharedPreferences("screen_wifi", Context.MODE_PRIVATE), serializer); serializer.endTag(null, "screen_wifi"); serializer.startTag(null, "screen_other"); xmlExport(getSharedPreferences("screen_other", Context.MODE_PRIVATE), serializer); serializer.endTag(null, "screen_other"); serializer.startTag(null, "apply"); xmlExport(getSharedPreferences("apply", Context.MODE_PRIVATE), serializer); serializer.endTag(null, "apply"); serializer.startTag(null, "notify"); xmlExport(getSharedPreferences("notify", Context.MODE_PRIVATE), serializer); serializer.endTag(null, "notify"); serializer.startTag(null, "filter"); filterExport(serializer);// w w w . j a v a2 s . c o m serializer.endTag(null, "filter"); serializer.startTag(null, "forward"); forwardExport(serializer); serializer.endTag(null, "forward"); serializer.endTag(null, "netguard"); serializer.endDocument(); serializer.flush(); }