List of usage examples for java.util ArrayList toString
public String toString()
From source file:com.krawler.esp.servlets.FileImporterServlet.java
public static void mapImportedRes(String resmapval, HashMap mp) throws ServiceException { Connection conn = null;/*from w w w .j av a 2 s .co m*/ try { conn = DbPool.getConnection(); com.krawler.utils.json.base.JSONArray jsonArray = new com.krawler.utils.json.base.JSONArray(resmapval); com.krawler.utils.json.base.JSONObject jobj = new com.krawler.utils.json.base.JSONObject(); for (int k = 0; k < jsonArray.length(); k++) { jobj = jsonArray.getJSONObject(k); if (jobj.getString("resourceid").length() > 0 && mp.containsKey(jobj.getString("tempid"))) { ArrayList taskids = (ArrayList) mp.get(jobj.getString("tempid")); String tasks = taskids.toString(); tasks = tasks.substring(1, tasks.lastIndexOf("]")); projdb.insertimportedtaskResources(conn, tasks, jobj.getString("resourceid")); } } conn.commit(); } catch (JSONException ex) { DbPool.quietRollback(conn); } catch (ServiceException ex) { DbPool.quietRollback(conn); } catch (Exception ex) { DbPool.quietRollback(conn); } finally { DbPool.quietClose(conn); } }
From source file:controllers.ContestUserController.java
public static Result addUser() { JsonNode json = request().body().asJson(); if (json == null) { return badRequest("Expecting Json data"); }/*from w w w . j a v a 2s . c om*/ checkDao(); Gson gson = new Gson(); ContestUser user = gson.fromJson(request().body().asJson().toString(), ContestUser.class); ArrayList<String> error = new ArrayList<String>(); boolean result = contestUserDao.addUser(user); if (!result) { error.add(user.getUserName()); } // Can this error have more than one name in it? I don't understand why error needs to be a list. if (error.size() == 0) { System.out.println("user saved"); return ok("user saved"); } else { System.out.println("user not saved: " + error.toString()); return ok("user not saved: " + error.toString()); } }
From source file:controllers.ContestUserController.java
public static Result deleteUser(String userName, String pwd) { checkDao();/*www. ja v a 2 s .co m*/ ArrayList<String> error = new ArrayList<String>(); boolean result = contestUserDao.deleteUser(userName, pwd); if (!result) { error.add(userName); } // Can this error have more than one name in it? I don't understand why error needs to be a list. if (error.size() == 0) { System.out.println("user deleted"); return ok("user deleted"); } else { System.out.println("user not deleted: " + error.toString()); return ok("user not deleted: " + error.toString()); } }
From source file:controllers.ContestUserController.java
public static Result updateUser() { JsonNode json = request().body().asJson(); if (json == null) { return badRequest("Expecting Json data"); }/*w w w . j a v a2 s .c o m*/ checkDao(); Gson gson = new Gson(); ContestUser user = gson.fromJson(request().body().asJson().toString(), ContestUser.class); ArrayList<String> error = new ArrayList<String>(); boolean result = contestUserDao.updateUser(user); if (!result) { error.add(user.getUserName()); } // Can this error have more than one name in it? I don't understand why error needs to be a list. if (error.size() == 0) { System.out.println("user updated"); return ok("user updated"); } else { System.out.println("user not updated: " + error.toString()); return ok("user not updated: " + error.toString()); } }
From source file:org.structr.csv.ToCsvFunction.java
private static String escapeForCsv(final Object value, final char quoteChar) { String result;//from w w w . j a v a2 s .co m if (value == null) { result = ""; } else if (value instanceof String[]) { // Special handling for StringArrays ArrayList<String> quotedStrings = new ArrayList(); for (final String str : Arrays.asList((String[]) value)) { // The strings can contain quotes - these need to be escaped with 3 slashes in the output quotedStrings.add("\\" + quoteChar + StringUtils.replace(str, "" + quoteChar, "\\\\\\" + quoteChar) + "\\" + quoteChar); } result = quotedStrings.toString(); } else if (value instanceof Collection) { // Special handling for collections of nodes ArrayList<String> quotedStrings = new ArrayList(); for (final Object obj : (Collection) value) { quotedStrings.add("\\" + quoteChar + obj.toString() + "\\" + quoteChar); } result = quotedStrings.toString(); } else if (value instanceof Date) { result = DatePropertyParser.format((Date) value, DateProperty.getDefaultFormat()); } else { result = StringUtils.replace(value.toString(), "" + quoteChar, "\\" + quoteChar); } return "".concat("" + quoteChar) .concat(StringUtils.replace(StringUtils.replace(result, "\r\n", "\\n"), "\r", "\\n")) .concat("" + quoteChar); }
From source file:com.example.cpulocal.myapplication_sample.samplesync.client.NetworkUtilities.java
/** * Perform 2-way sync with the server-side contacts. We send a request that * includes all the locally-dirty contacts so that the server can process * those changes, and we receive (and return) a list of contacts that were * updated on the server-side that need to be updated locally. * * @param account The account being synced * @param authtoken The authtoken stored in the AccountManager for this * account/*from w ww. j a va 2 s . c o m*/ * @param serverSyncState A token returned from the server on the last sync * @param dirtyContacts A list of the contacts to send to the server * @return A list of contacts that we need to update locally */ public static List<RawContact> syncContacts(Account account, String authtoken, long serverSyncState, List<RawContact> dirtyContacts) throws JSONException, ParseException, IOException, AuthenticationException { // Convert our list of User objects into a list of JSONObject List<JSONObject> jsonContacts = new ArrayList<JSONObject>(); for (RawContact rawContact : dirtyContacts) { jsonContacts.add(rawContact.toJSONObject()); } // Create a special JSONArray of our JSON contacts JSONArray buffer = new JSONArray(jsonContacts); // Create an array that will hold the server-side contacts // that have been changed (returned by the server). final ArrayList<RawContact> serverDirtyList = new ArrayList<RawContact>(); // Prepare our POST data final ArrayList<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair(PARAM_USERNAME, account.name)); params.add(new BasicNameValuePair(PARAM_AUTH_TOKEN, authtoken)); params.add(new BasicNameValuePair(PARAM_CONTACTS_DATA, buffer.toString())); if (serverSyncState > 0) { params.add(new BasicNameValuePair(PARAM_SYNC_STATE, Long.toString(serverSyncState))); } Log.i(TAG, params.toString()); HttpEntity entity = new UrlEncodedFormEntity(params); // Send the updated friends data to the server Log.i(TAG, "Syncing to: " + SYNC_CONTACTS_URI); final HttpPost post = new HttpPost(SYNC_CONTACTS_URI); post.addHeader(entity.getContentType()); post.setEntity(entity); final HttpResponse resp = getHttpClient().execute(post); final String response = EntityUtils.toString(resp.getEntity()); if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { // Our request to the server was successful - so we assume // that they accepted all the changes we sent up, and // that the response includes the contacts that we need // to update on our side... final JSONArray serverContacts = new JSONArray(response); Log.d(TAG, response); for (int i = 0; i < serverContacts.length(); i++) { RawContact rawContact = RawContact.valueOf(serverContacts.getJSONObject(i)); if (rawContact != null) { serverDirtyList.add(rawContact); } } } else { if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { Log.e(TAG, "Authentication exception in sending dirty contacts"); throw new AuthenticationException(); } else { Log.e(TAG, "Server error in sending dirty contacts: " + resp.getStatusLine()); throw new IOException(); } } return serverDirtyList; }
From source file:nl.hardijzer.bitonsync.client.NetworkUtilities.java
/** * Fetches the list of friend data updates from the server * // w w w .j ava 2 s . c om * @param account The account being synced. * @param authtoken The authtoken stored in AccountManager for this account * @param lastUpdated The last time that sync was performed * @return list The list of updates received from the server. */ public static List<User> fetchFriendUpdates(Account account, String authtoken) throws ParseException, IOException, AuthenticationException { ArrayList<User> friendList = new ArrayList<User>(); final ArrayList<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair(PARAM_USERNAME, account.name)); params.add(new BasicNameValuePair(PARAM_PASSWORD, authtoken)); params.add(new BasicNameValuePair(PARAM_METHOD, DATA_METHOD)); Log.i(TAG, params.toString()); HttpEntity entity = null; entity = new UrlEncodedFormEntity(params); final HttpPost post = new HttpPost(SYNC_URI);//FETCH_FRIEND_UPDATES_URI post.addHeader(entity.getContentType()); post.setEntity(entity); maybeCreateHttpClient(); final HttpResponse resp = mHttpClient.execute(post); //final HttpResponse resp = mHttpClient.execute(new HttpGet(FETCH_FRIEND_UPDATES_URI)); if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { // Succesfully connected to the samplesyncadapter server and // authenticated. // Extract friends data in json format. final String response = EntityUtils.toString(resp.getEntity()); boolean loggedin = response.startsWith("OK "); if (loggedin) { String data = response.substring(3); GsonBuilder bld = new GsonBuilder(); bld.registerTypeAdapter(User.class, User.deserializer); Gson gson = bld.create(); friendList = gson.fromJson(data, new TypeToken<ArrayList<User>>() { }.getType()); /* String[] parts=response.split("<td class=''>"); for (int i=1; i<parts.length; i++) { int end=parts[i].indexOf("</td>"); if (end>=0) parts[i]=parts[i].substring(0,end); parts[i]=unhtmlify(parts[i]); } for (int i=1; i+6<=parts.length; i+=6) { Matcher naammatcher=Pattern.compile("(^.+) \\((.+?)\\) (.+$)").matcher(parts[i]); String naam,voornaam,achternaam; if (naammatcher.find()) { voornaam=parts[i].substring(naammatcher.start(2),naammatcher.end(2)); naam=parts[i].substring(naammatcher.start(1),naammatcher.end(1)); achternaam=parts[i].substring(naammatcher.start(3),naammatcher.end(3)); } else { voornaam=parts[i]; achternaam=""; int split=voornaam.indexOf(" "); if (split>=0) { achternaam=voornaam.substring(split+1); voornaam=voornaam.substring(0,split); } naam=voornaam; } String telefoon=parts[i+1]; String mobiel=parts[i+2]; if (telefoon.startsWith("0")) { telefoon="+31"+telefoon.substring(1); } if (mobiel.startsWith("0")) { mobiel="+31"+mobiel.substring(1); } String geboorte=parts[i+5]; String[] geboorte_parts=geboorte.split(" "); if (geboorte_parts.length==3) { String dag=geboorte_parts[0]; String jaar=geboorte_parts[2]; String maand=geboorte_parts[1]; if (dag.length()<2) dag="00".substring(dag.length())+dag; if (jaar.length()==2) jaar="19"+jaar; //januari 1 ja //februari 2 f //maart 3 ma //april 4 ap //mei 5 me //juni 6 jun //juli 7 jul //aug 8 au //sep 9 s //okt 12 o //nov 11 n //dec 12 d if (maand.startsWith("ja")) geboorte=jaar+"-01-"+dag; else if (maand.startsWith("f")) geboorte=jaar+"-02-"+dag; else if (maand.startsWith("ma")) geboorte=jaar+"-03-"+dag; else if (maand.startsWith("ap")) geboorte=jaar+"-04-"+dag; else if (maand.startsWith("me")) geboorte=jaar+"-05-"+dag; else if (maand.startsWith("jun")) geboorte=jaar+"-06-"+dag; else if (maand.startsWith("jul")) geboorte=jaar+"-07-"+dag; else if (maand.startsWith("au")) geboorte=jaar+"-08-"+dag; else if (maand.startsWith("s")) geboorte=jaar+"-09-"+dag; else if (maand.startsWith("o")) geboorte=jaar+"-10-"+dag; else if (maand.startsWith("n")) geboorte=jaar+"-11-"+dag; else if (maand.startsWith("d")) geboorte=jaar+"-12-"+dag; } friendList.add(new User(naam, voornaam, achternaam, telefoon, mobiel, parts[i+3], parts[i+4], geboorte)); }*/ } else { Log.e(TAG, "Authentication exception in fetching remote contacts (content)"); throw new AuthenticationException(); } } else { if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { Log.e(TAG, "Authentication exception in fetching remote contacts"); throw new AuthenticationException(); } else { Log.e(TAG, "Server error in fetching remote contacts: " + resp.getStatusLine()); throw new IOException(); } } if (friendList.isEmpty()) { Log.e(TAG, "No friends found, auth error?: " + resp.getStatusLine()); throw new AuthenticationException(); } return friendList; }
From source file:com.cprassoc.solr.auth.SolrAuthActionController.java
public static String addRole(String user, ArrayList<String> roles) { String result = ""; String data = ""; try {//w ww. j a v a2 s . c o m String path = SOLR.getSolrBaseUrl() + SolrHttpHandler.AUTHORIZATION_URL_PART; if (roles == null) { // case for null role and null array data = "{ \"set-user-role\": {\"" + user + "\" : null }}"; } else if (roles.size() > 1) { // case for multiple roles data = "{ \"set-user-role\": {\"" + user + "\" : \"" + roles.toString() + "\" }}"; } else if (roles.size() == 1 && roles.get(0).trim().equals("null")) { // case for null role data = "{ \"set-user-role\": {\"" + user + "\" : " + roles.get(0) + " }}"; } else { // case for single role data = "{ \"set-user-role\": {\"" + user + "\" : \"" + roles.get(0) + "\" }}"; } /* curl --user solr:SolrRocks http://localhost:8983/solr/admin/authorization -H 'Content-type:application/json' -d '{ "set-user-role": {"tom":["admin","dev"}, "set-user-role": {"harry":null} }' */ result = SOLR.post(path, data); } catch (Exception e) { e.printStackTrace(); } return result; }
From source file:app.sunstreak.yourpisd.net.Parser.java
public static int studentIdPinnacle(ArrayList<String> cookies) { // System.out.println("Cookies size = " + cookies.size()); for (String c : cookies) if (c.substring(0, c.indexOf('=')).equals("PinnacleWeb.StudentId")) return Integer.parseInt(c.substring(c.indexOf('=') + 1)); throw new RuntimeException("Student ID not found. Cookies: " + cookies.toString()); }
From source file:edu.cmu.android.restaurant.authentication.NetworkUtilities.java
/** * Fetches the list of friend data updates from the server * //from w w w.j a v a2 s.co m * @param account * The account being synced. * @param authtoken * The authtoken stored in AccountManager for this account * @param lastUpdated * The last time that sync was performed * @return list The list of updates received from the server. */ public static List<User> fetchFriendUpdates(Account account, String authtoken, Date lastUpdated) throws JSONException, ParseException, IOException, AuthenticationException { final ArrayList<User> friendList = new ArrayList<User>(); final ArrayList<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair(PARAM_USERNAME, account.name)); params.add(new BasicNameValuePair(PARAM_PASSWORD, authtoken)); if (lastUpdated != null) { final SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm"); formatter.setTimeZone(TimeZone.getTimeZone("UTC")); params.add(new BasicNameValuePair(PARAM_UPDATED, formatter.format(lastUpdated))); } Log.i(TAG, params.toString()); HttpEntity entity = null; entity = new UrlEncodedFormEntity(params); final HttpPost post = new HttpPost(FETCH_FRIEND_UPDATES_URI); post.addHeader(entity.getContentType()); post.setEntity(entity); maybeCreateHttpClient(); final HttpResponse resp = mHttpClient.execute(post); final String response = EntityUtils.toString(resp.getEntity()); if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { // Succesfully connected to the samplesyncadapter server and // authenticated. // Extract friends data in json format. final JSONArray friends = new JSONArray(response); Log.d(TAG, response); for (int i = 0; i < friends.length(); i++) { friendList.add(User.valueOf(friends.getJSONObject(i))); } } else { if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { Log.e(TAG, "Authentication exception in fetching remote contacts"); throw new AuthenticationException(); } else { Log.e(TAG, "Server error in fetching remote contacts: " + resp.getStatusLine()); throw new IOException(); } } return friendList; }