List of usage examples for java.lang Exception toString
public String toString()
From source file:com.bearstech.android.myownsync.client.User.java
/** * Creates and returns an instance of the user from the provided JSON data. * /*from ww w . j ava2s . c om*/ * @param user The JSONObject containing user data * @return user The new instance of Voiper user created from the JSON data. */ public static User valueOf(JSONObject user) { try { final int userId = user.getInt("user_id"); final boolean deleted = user.has("d") ? user.getBoolean("d") : false; final String userName = user.getString("username"); final String firstName = opt_get(user, "firstname"); final String lastName = opt_get(user, "lastname"); final String middleName = opt_get(user, "middlename"); final String nameSuffix = opt_get(user, "namesuffix"); final String pGivenName = opt_get(user, "phonetic_given_name"); final String pMiddleName = opt_get(user, "phonetic_middle_name"); final String pFamilyName = opt_get(user, "phonetic_family_name"); final String nickname = opt_get(user, "nickname"); final String website = opt_get(user, "website"); final String status = opt_get(user, "status"); User u = new User(userName, firstName, lastName, middleName, nameSuffix, pGivenName, pMiddleName, pFamilyName, nickname, website, status, deleted, userId); if (user.has("orga")) { final JSONArray orgas = user.getJSONArray("orga"); for (int i = 0; i < orgas.length(); ++i) { JSONObject orga = orgas.getJSONObject(i); u.addOrga(orga.getString("name"), orga.getString("role")); } } if (user.has("phone")) { final JSONArray phones = user.getJSONArray("phone"); for (int i = 0; i < phones.length(); ++i) { JSONObject phone = phones.getJSONObject(i); u.addPhone(phone.getString("phonetype"), phone.getString("phone")); } } if (user.has("email")) { final JSONArray emails = user.getJSONArray("email"); for (int i = 0; i < emails.length(); ++i) { JSONObject email = emails.getJSONObject(i); u.addEmail(email.getString("emailtype"), email.getString("email")); } } if (user.has("address")) { final JSONArray addresses = user.getJSONArray("address"); for (int i = 0; i < addresses.length(); ++i) { JSONObject address = addresses.getJSONObject(i); u.addAddress(opt_get(address, "addrtype"), opt_get(address, "street"), opt_get(address, "postcode"), opt_get(address, "city"), opt_get(address, "country")); } } if (user.has("IM")) { final JSONArray IMs = user.getJSONArray("IM"); for (int i = 0; i < IMs.length(); ++i) { JSONObject IM = IMs.getJSONObject(i); u.addIM(IM.getString("type"), IM.getString("handle")); } } Log.d("User", "JSON object: " + user); Log.d("User", "resulted user is " + u.getLastName()); return u; } catch (final Exception ex) { Log.i("User", "Error parsing JSON user object" + ex.toString()); } return null; }
From source file:com.intuit.tank.harness.AmazonUtil.java
/** * gets logging profile form user data/*from w ww.j a v a 2s.c o m*/ * * @return LoggingProfile */ public static LoggingProfile getLoggingProfile() { LoggingProfile ret = LoggingProfile.STANDARD; try { String lp = getUserDataAsMap().get(TankConstants.KEY_LOGGING_PROFILE); if (lp != null) { ret = LoggingProfile.valueOf(lp); } } catch (Exception e) { LOG.warn("Error getting LoggingProfile: " + e.toString()); } return ret; }
From source file:com.endlessloopsoftware.ego.client.graph.GraphData.java
public static void writeImage(File imageFile, String format) { int width = GraphRenderer.getVv().getWidth(); int height = GraphRenderer.getVv().getHeight(); BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = bi.createGraphics(); GraphRenderer.getVv().paint(graphics); graphics.dispose();/* w w w .j a va 2 s. c o m*/ try { ImageIO.write(bi, format, imageFile); } catch (Exception ex) { logger.error(ex.toString()); } }
From source file:gdt.data.grain.Locator.java
/** * Convert the locator string into the Properties object. * @param locator$ the locator string. * @return the Properties object. /* w ww . j ava2s . c o m*/ */ public static Properties toProperties(String locator$) { // System.out.println("Locator:toProperties:locator="+locator$); if (locator$ == null) { //Logger.getLogger(Locator.class.getName()).severe(":toProperties:locator is null"); return null; } Properties props = new Properties(); String[] sa = locator$.split(NAME_DELIMITER); if (sa == null) { Logger.getLogger(Locator.class.getName()).severe(":toProperties:cannot split fields"); return null; } String[] na; for (int i = 0; i < sa.length; i++) { try { na = sa[i].split(VALUE_DELIMITER); if (na == null || na.length < 2) continue; props.setProperty(na[0], na[1]); } catch (Exception e) { Logger.getLogger(Locator.class.getName()).severe(":toProperties:" + e.toString()); } } if (props.isEmpty()) { Logger.getLogger(Locator.class.getName()).severe(":toProperties:empty"); return null; } return props; }
From source file:com.keybox.manage.db.AuthDB.java
/** * returns user based on auth token// w w w.j a va 2 s . c o m * * @param authToken auth token * @return user */ public static User getUserByAuthToken(String authToken) { User user = null; Connection con = null; try { con = DBUtils.getConn(); user = getUserByAuthToken(con, authToken); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); return user; }
From source file:com.tethrnet.manage.db.UserDB.java
/** * updates existing user//from ww w.ja v a2s . c om * @param user user object */ public static void updateUserNoCredentials(User user) { Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con .prepareStatement("update users set email=?, username=?, user_type=? where id=?"); stmt.setString(1, user.getEmail()); stmt.setString(2, user.getUsername()); stmt.setString(3, user.getUserType()); stmt.setLong(4, user.getId()); stmt.execute(); DBUtils.closeStmt(stmt); if (User.ADMINISTRATOR.equals(user.getUserType())) { PublicKeyDB.deleteUnassignedKeysByUser(con, user.getId()); } } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); }
From source file:gdt.data.entity.BaseHandler.java
/** * Create an empty database//w w w . ja v a2 s . c o m * @param entihome$ the path of the new database * @return return null if succeed or an error message otherwise. */ public static String createBlankDatabase(String entihome$) { try { System.out.println("BaseHandler:createBlankDatabase.entihome=" + entihome$); File entihome = new File(entihome$); if (!entihome.exists()) { entihome.mkdir(); } File propertyBase = new File(entihome$ + "/" + Entigrator.PROPERTY_BASE + "/data/"); if (!propertyBase.exists()) propertyBase.mkdirs(); File propertyMap = new File(entihome$ + "/" + Entigrator.PROPERTY_MAP + "/data/"); if (!propertyMap.exists()) propertyMap.mkdirs(); File entityBase = new File(entihome$ + "/" + Entigrator.PROPERTY_BASE + "/data/"); if (!entityBase.exists()) entityBase.mkdirs(); Entigrator entigrator = new Entigrator(new String[] { entihome$ }); String[] sa = entigrator.indx_listEntities("label", "Icons"); Sack folder = null; if (sa == null) { folder = entigrator.ent_new("folder", "Icons", Entigrator.ICONS); folder.putAttribute(new Core(null, "icon", "folder.png")); entigrator.save(folder); folder = entigrator.ent_assignProperty(folder, "folder", folder.getProperty("label")); } File folderHome = new File(entihome$ + "/" + Entigrator.ICONS); if (!folderHome.exists()) folderHome.mkdir(); Sack dependencies = entigrator.ent_new("folder", "Dependencies", Entigrator.DEPENDENCIES); dependencies.putAttribute(new Core(null, "icon", "folder.png")); entigrator.save(dependencies); folder = entigrator.ent_assignProperty(folder, "folder", folder.getProperty("label")); folderHome = new File(entihome$ + "/" + Entigrator.DEPENDENCIES); if (!folderHome.exists()) folderHome.mkdir(); System.out.println("BaseHandler:createBlankDatabase:1"); InputStream is = ExtensionHandler.class.getResourceAsStream("commons-codec-1.10.jar"); if (is == null) System.out.println("BaseHandler:createBlankDatabase:cannot get input stream"); else { System.out.println("BaseHandler:createBlankDatabase:found input stream"); File out = new File(entihome$ + "/" + Entigrator.DEPENDENCIES + "/commons-codec-1.10.jar"); FileOutputStream fos = new FileOutputStream(out); byte[] b = new byte[1024]; int bytesRead = 0; while ((bytesRead = is.read(b)) != -1) { fos.write(b, 0, bytesRead); } fos.close(); is.close(); } is = ExtensionHandler.class.getResourceAsStream("commons-compress-1.10.jar"); if (is == null) System.out.println("BaseHandler:createBlankDatabase:cannot get input stream"); else { System.out.println("BaseHandler:createBlankDatabase:found input stream"); File out = new File(entihome$ + "/" + Entigrator.DEPENDENCIES + "/commons-compress-1.10.jar"); FileOutputStream fos = new FileOutputStream(out); byte[] b = new byte[1024]; int bytesRead = 0; while ((bytesRead = is.read(b)) != -1) { fos.write(b, 0, bytesRead); } fos.close(); is.close(); } return null; } catch (Exception e) { Logger.getLogger(BaseHandler.class.getName()).severe(e.toString()); return e.toString(); } }
From source file:com.keybox.manage.db.AuthDB.java
/** * updates shared secret based on auth token * * @param secret OTP shared secret/* ww w .ja v a2s . c o m*/ * @param authToken auth token */ public static void updateSharedSecret(String secret, String authToken) { Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement("update users set otp_secret=? where auth_token=?"); stmt.setString(1, EncryptionUtil.encrypt(secret)); stmt.setString(2, authToken); stmt.execute(); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); }
From source file:com.keybox.manage.db.AuthDB.java
/** * get salt by user name/*from w w w .j a v a 2s. co m*/ * * @param con DB connection * @param username username * @return salt */ private static String getSaltByUsername(Connection con, String username) { String salt = ""; try { PreparedStatement stmt = con .prepareStatement("select salt from users where enabled=true and username=?"); stmt.setString(1, username); ResultSet rs = stmt.executeQuery(); if (rs.next() && rs.getString("salt") != null) { salt = rs.getString("salt"); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return salt; }
From source file:com.keybox.manage.db.AuthDB.java
/** * get salt by authentication token//from w ww .j a v a 2 s. c o m * * @param con DB connection * @param authToken auth token * @return salt */ private static String getSaltByAuthToken(Connection con, String authToken) { String salt = ""; try { PreparedStatement stmt = con .prepareStatement("select salt from users where enabled=true and auth_token=?"); stmt.setString(1, authToken); ResultSet rs = stmt.executeQuery(); if (rs.next() && rs.getString("salt") != null) { salt = rs.getString("salt"); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return salt; }