List of usage examples for java.lang Exception toString
public String toString()
From source file:org.androidnerds.reader.util.api.Tags.java
/** * This method grabs the labels and puts them in an ArrayList to return * back to the caller, basically labels are folders which have different * subscribed feeds in them; See {@link org.androidnerds.feeds.reader.Subscriptions#subscriptionsInLabel} * for how to pull the subscribed feeds for a given label. * * @param sid the Google Reader authentication string. * @return labels the ArrayList of labels *///from www.java 2 s. c o m public static ArrayList<Label> getLabels(String sid) { JSONArray tags = pullTags(sid); int size = tags.length(); ArrayList<Label> labels = new ArrayList<Label>(size); try { for (int i = 0; i < size; i++) { if (!tags.isNull(i)) { JSONObject tag = tags.getJSONObject(i); String id = tag.getString("id"); if (id.contains("label")) { String label = id.substring(id.lastIndexOf("/") + 1); Label l = new Label(label, id); l.setSortId(tag.getString("sortid")); labels.add(l); } } } } catch (Exception e) { Log.d(TAG, "Exception caught:: " + e.toString()); } return labels; }
From source file:Main.java
/** * Converts a plain text file into TE3-input file * * @param plainfile/*www . ja v a2 s. c o m*/ * @return */ public static String Plain2TE3(String plainfile) { String outputfile = null; try { String line; boolean textfound = false; String header = ""; String footer = ""; String text = ""; //process header (and dct)/text/footer outputfile = plainfile + ".TE3input"; BufferedWriter te3writer = new BufferedWriter(new FileWriter(new File(outputfile))); BufferedReader inputReader = new BufferedReader(new FileReader(new File(plainfile))); try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String dctvalue = sdf.format(new Date()); te3writer.write("<?xml version=\"1.0\" ?>"); te3writer.write( "\n<TimeML xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://timeml.org/timeMLdocs/TimeML_1.2.1.xsd\">\n"); te3writer.write("\n<DOCID>" + (new File(plainfile)).getName() + "</DOCID>\n"); te3writer.write("\n<DCT><TIMEX3 tid=\"t0\" type=\"DATE\" value=\"" + dctvalue + "\" temporalFunction=\"false\" functionInDocument=\"CREATION_TIME\">" + dctvalue + "</TIMEX3></DCT>\n"); // read out text while ((line = inputReader.readLine()) != null) { text += line + "\n"; } te3writer.write("\n<TEXT>\n" + text + "</TEXT>\n"); te3writer.write("</TimeML>\n"); } finally { if (inputReader != null) { inputReader.close(); } if (te3writer != null) { te3writer.close(); } } } catch (Exception e) { System.err.println("Errors found (TML_file_utils):\n\t" + e.toString() + "\n"); if (System.getProperty("DEBUG") != null && System.getProperty("DEBUG").equalsIgnoreCase("true")) { e.printStackTrace(System.err); } return null; } return outputfile; }
From source file:com.dbmojo.Util.java
/** Given an error meesage return a JSONObject formatted appropriately. *///from ww w . j a v a2 s . c o m public static HashMap getError(String message) { HashMap jObj = new HashMap(); try { jObj.put("status", "error"); jObj.put("message", message); jObj.put("rows", new ArrayList()); jObj.put("types", new ArrayList()); jObj.put("cols", new ArrayList()); } catch (Exception e) { System.out.println(e.toString()); } return jObj; }
From source file:com.dbmojo.Util.java
public static JSONArray getErrorJson(String message) { JSONObject jObj = new JSONObject(); try {//from w w w . jav a 2 s. co m jObj.put("status", "error"); jObj.put("message", message); jObj.put("rows", new JSONArray()); jObj.put("types", new JSONArray()); jObj.put("cols", new JSONArray()); } catch (Exception e) { System.out.println(e.toString()); } JSONArray jArr = new JSONArray(); jArr.put(jObj); return jArr; }
From source file:com.quietlycoding.android.reader.util.api.Tags.java
/** * This method grabs the labels and puts them in an ArrayList to return back * to the caller, basically labels are folders which have different * subscribed feeds in them; See//from w w w .j a v a 2 s .c om * {@link org.androidnerds.feeds.reader.Subscriptions#subscriptionsInLabel} * for how to pull the subscribed feeds for a given label. * * @param sid * the Google Reader authentication string. * @return labels the ArrayList of labels */ public static ArrayList<Label> getLabels(String sid) { final JSONArray tags = pullTags(sid); final int size = tags.length(); final ArrayList<Label> labels = new ArrayList<Label>(size); try { for (int i = 0; i < size; i++) { if (!tags.isNull(i)) { final JSONObject tag = tags.getJSONObject(i); final String id = tag.getString("id"); if (id.contains("label")) { final String label = id.substring(id.lastIndexOf("/") + 1); final Label l = new Label(label, id); l.setSortId(tag.getString("sortid")); labels.add(l); } } } } catch (final Exception e) { Log.d(TAG, "Exception caught:: " + e.toString()); } return labels; }
From source file:org.androidnerds.reader.util.api.Tags.java
/** * This method pulls the tags from Google Reader, its used by the * methods in this class to communicate before parsing the specific * results./*from ww w. j av a 2 s. c om*/ * * @param sid the Google Reader authentication string. * @return arr JSONArray of the items from the server. */ private static JSONArray pullTags(String sid) { DefaultHttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet(URL); BasicClientCookie cookie = Authentication.buildCookie(sid); try { client.getCookieStore().addCookie(cookie); HttpResponse response = client.execute(get); HttpEntity respEntity = response.getEntity(); Log.d(TAG, "Response from server: " + response.getStatusLine()); InputStream in = respEntity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line = ""; String arr = ""; while ((line = reader.readLine()) != null) { arr += line; } JSONObject obj = new JSONObject(arr); JSONArray array = obj.getJSONArray("tags"); return array; } catch (Exception e) { Log.d(TAG, "Exception caught:: " + e.toString()); return null; } }
From source file:com.keybox.manage.db.UserThemeDB.java
/** * saves user theme/*from w w w . ja v a 2s .co m*/ * * @param userId object */ public static void saveTheme(Long userId, UserSettings theme) { Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement("delete from user_theme where user_id=?"); stmt.setLong(1, userId); stmt.execute(); DBUtils.closeStmt(stmt); if (org.apache.commons.lang.StringUtils.isNotEmpty(theme.getPlane()) || org.apache.commons.lang.StringUtils.isNotEmpty(theme.getTheme())) { stmt = con.prepareStatement( "insert into user_theme(user_id, bg, fg, d1, d2, d3, d4, d5, d6, d7, d8, b1, b2, b3, b4, b5, b6, b7, b8) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); stmt.setLong(1, userId); stmt.setString(2, theme.getBg()); stmt.setString(3, theme.getFg()); //if contains all 16 theme colors insert if (theme.getColors() != null && theme.getColors().length == 16) { for (int i = 0; i < 16; i++) { stmt.setString(i + 4, theme.getColors()[i]); } //else set to null } else { for (int i = 0; i < 16; i++) { stmt.setString(i + 4, null); } } stmt.execute(); DBUtils.closeStmt(stmt); } } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); }
From source file:io.agi.framework.persistence.jdbc.JdbcUtil.java
public static Connection GetConnection(String dbUrl, String user, String password) { if (_dataSource == null) { CreateDataSource(dbUrl, user, password, JdbcPersistence.DRIVER_POSTGRESQL); }/*from www .j a v a 2s .com*/ try { Connection c = _dataSource.getConnection(); return c; } catch (Exception e) { logger.error(e.toString(), e); return null; } }
From source file:markson.visuals.sitapp.JSONfunctions.java
public static JSONObject getJSONfromURL(String url) { //initialize//from ww w . j a v a 2 s . c om InputStream is = null; String result = ""; JSONObject jArray = null; //http post try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(url); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = entity.getContent(); } catch (Exception e) { Log.e("log_tag", "Error in http connection " + e.toString()); } //convert response to string try { BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); result = sb.toString(); } catch (Exception e) { Log.e("log_tag", "Error converting result " + e.toString()); } //try parse the string to a JSON object try { jArray = new JSONObject(result); } catch (JSONException e) { Log.e("log_tag", "Error parsing data " + e.toString()); } return jArray; }
From source file:org.roman.findme.RegistrationIntentService.java
public static void makeResponse(List<NameValuePair> nameValuePairs) { String url = "http://task-master.zzz.com.ua/server.php"; Log.d(TAG, "sendRequest"); try {//www. ja v a 2 s . c o m HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(url); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); InputStream in = response.getEntity().getContent(); StringBuilder stringbuilder = new StringBuilder(); BufferedReader bfrd = new BufferedReader(new InputStreamReader(in), 1024); String line; while ((line = bfrd.readLine()) != null) stringbuilder.append(line); String downloadedString = stringbuilder.toString(); Log.d(TAG, downloadedString); } catch (Exception e) { Log.d(TAG, e.toString()); } }