package BMActivityStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.HashMap; import java.util.Vector; import java.util.Enumeration; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.UUID; import org.apache.commons.io.IOUtils; import java.util.Iterator; import java.util.Set; import com.sun.net.httpserver.Headers; import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.io.OutputStream; import java.net.InetSocketAddress; import java.net.URLDecoder; import java.net.URI; import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; import com.sun.net.httpserver.HttpServer; import com.sun.net.httpserver.Filter; import com.sun.net.httpserver.HttpContext; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilder; import org.w3c.dom.Document; import org.w3c.dom.NodeList; import org.w3c.dom.Node; import org.w3c.dom.Element; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import java.io.ByteArrayInputStream; import org.apache.commons.codec.binary.Base64; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import org.apache.http.entity.StringEntity; import org.apache.http.util.EntityUtils; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; import org.json.simple.parser.ContainerFactory; import org.json.simple.parser.ContentHandler; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; import java.io.*; import java.util.Hashtable; import javax.mail.*; import javax.mail.internet.*; import javax.mail.util.*; import javax.activation.*; public class BMActivityStream { private static ActivityStreamdb db = null; public static void main(String[] args) throws Exception { try { db = new ActivityStreamdb("db_file_activitystream"); } catch (Exception ex1) { ex1.printStackTrace(); return; // bye bye } try { System.out.println("Creating database entries"); db.update("CREATE TABLE bm_table ( msgid VARCHAR(64), address VARCHAR(38), application VARCHAR(64), message LONGVARCHAR, dtstamp TIMESTAMP)"); System.out.println("Created bm_table"); } catch (SQLException ex2) { System.out.println("Table bm_table in place"); } try { db.update("CREATE TABLE bm_mail ( msgid VARCHAR(64), ackdata VARCHAR(64), read BOOLEAN, folder VARCHAR(64), toaddress VARCHAR(38), fromaddress VARCHAR(38), subject LONGVARCHAR, message LONGVARCHAR, encodingtype INTEGER, dtstamp TIMESTAMP)"); System.out.println("Created bm_mail"); } catch (SQLException ex2) { System.out.println("Table bm_mail in place"); } try { db.update("CREATE TABLE bm_mail_folders ( folder VARCHAR(64))"); System.out.println("Created bm_mail_folders"); try { String INSERT_RECORD = "INSERT INTO bm_mail_folders(folder) VALUES(?)"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, "Inbox"); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } try { String INSERT_RECORD = "INSERT INTO bm_mail_folders(folder) VALUES(?)"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, "Sent"); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } try { String INSERT_RECORD = "INSERT INTO bm_mail_folders(folder) VALUES(?)"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, "Drafts"); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } try { String INSERT_RECORD = "INSERT INTO bm_mail_folders(folder) VALUES(?)"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, "Spam"); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } try { String INSERT_RECORD = "INSERT INTO bm_mail_folders(folder) VALUES(?)"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, "Trash"); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } } catch (SQLException ex2) { System.out.println("Table bm_mail_folders in place"); } try { db.update("CREATE TABLE bm_profiles ( address VARCHAR(38), follower BOOLEAN, follower_msgid VARCHAR(64), following BOOLEAN, following_msgid VARCHAR(64), label VARCHAR(128), notes LONGVARCHAR, dtstamp TIMESTAMP)"); System.out.println("Created bm_profiles"); } catch (SQLException ex2) { System.out.println("Table bm_profiles in place"); } try { db.update("CREATE TABLE bm_profiles_lists ( address VARCHAR(38), list LONGVARCHAR)"); System.out.println("Created bm_profiles_lists"); } catch (SQLException ex2) { System.out.println("Table bm_profiles_lists in place"); } try { db.update("CREATE TABLE bm_alerts ( msgid VARCHAR(64), message LONGVARCHAR, dtstamp TIMESTAMP)"); System.out.println("Created bm_alerts"); } catch (SQLException ex2) { System.out.println("Table bm_alerts in place"); } try { db.update("CREATE TABLE bm_groups ( address VARCHAR(38), label LONGVARCHAR, know_members VARCHAR(38))"); System.out.println("Created bm_groups"); } catch (SQLException ex2) { System.out.println("Table bm_groups in place"); } try { db.update("CREATE TABLE bm_lastclick ( wpage VARCHAR(64), dtstamp TIMESTAMP)"); System.out.println("Created bm_lastclick"); try { String INSERT_RECORD = "INSERT INTO bm_lastclick(wpage,dtstamp) VALUES(?,?)"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, "MESSAGES"); java.sql.Timestamp sqlDate = new java.sql.Timestamp(new java.util.Date().getTime()); pstmt.setTimestamp(2, sqlDate); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } try { String INSERT_RECORD = "INSERT INTO bm_lastclick(wpage,dtstamp) VALUES(?,?)"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, "FOLLOWERS"); java.sql.Timestamp sqlDate = new java.sql.Timestamp(new java.util.Date().getTime()); pstmt.setTimestamp(2, sqlDate); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } try { String INSERT_RECORD = "INSERT INTO bm_lastclick(wpage,dtstamp) VALUES(?,?)"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, "ALERTS"); java.sql.Timestamp sqlDate = new java.sql.Timestamp(new java.util.Date().getTime()); pstmt.setTimestamp(2, sqlDate); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } } catch (SQLException ex2) { System.out.println("Table bm_lastclick in place"); } try { db.update("CREATE TABLE bm_settings ( setting LONGVARCHAR, value LONGVARCHAR)"); System.out.println("Created bm_settings"); try { String INSERT_RECORD = "INSERT INTO bm_settings(setting,value) VALUES(?,?)"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, "bmapi_ip"); pstmt.setString(2, "localhost"); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } try { String INSERT_RECORD = "INSERT INTO bm_settings(setting,value) VALUES(?,?)"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, "bmapi_port"); pstmt.setString(2, "8442"); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } try { String INSERT_RECORD = "INSERT INTO bm_settings(setting,value) VALUES(?,?)"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, "bmapi_user"); pstmt.setString(2, "default"); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } try { String INSERT_RECORD = "INSERT INTO bm_settings(setting,value) VALUES(?,?)"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, "bmapi_password"); pstmt.setString(2, "default"); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } try { String INSERT_RECORD = "INSERT INTO bm_settings(setting,value) VALUES(?,?)"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, "bmapi_client"); pstmt.setString(2, "false"); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } } catch (SQLException ex2) { System.out.println("Table bm_settings in place"); } HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0); HttpContext context = server.createContext("/", new MainHandler(db)); context.getFilters().add(new ParameterFilter()); context = server.createContext("/alerts", new AlertsHandler(db)); context.getFilters().add(new ParameterFilter()); context = server.createContext("/followers", new ProfilesHandler(db)); context.getFilters().add(new ParameterFilter()); context = server.createContext("/message", new MessageHandler(db)); context.getFilters().add(new ParameterFilter()); context = server.createContext("/messages", new MessagesHandler(db)); context.getFilters().add(new ParameterFilter()); context = server.createContext("/profile", new ProfileHandler(db)); context.getFilters().add(new ParameterFilter()); context = server.createContext("/send", new SendHandler(db)); context.getFilters().add(new ParameterFilter()); context = server.createContext("/send_message", new SendMessageHandler(db)); context.getFilters().add(new ParameterFilter()); context = server.createContext("/settings", new SettingsHandler(db)); context.getFilters().add(new ParameterFilter()); context = server.createContext("/logout", new LogoutHandler(db, server)); context.getFilters().add(new ParameterFilter()); server.setExecutor(null); // creates a default executor System.out.println("HttpServer started"); server.start(); } static class MainHandler implements HttpHandler { private ActivityStreamdb db = null; public MainHandler(ActivityStreamdb db) { this.db = db; } public void handle(HttpExchange t) throws IOException { String response = ""; String application = "news"; String mid = ""; processMessages processor = new processMessages(db); processor.process(); HTMLBuilder html = new HTMLBuilder(); html.appendHTMLHead(); html.appendHTMLStyle(); html.appendHTMLScript(); html.appendHTMLHeadEndNews(); html.appendNAVBar(); html.appendMainLeftMenu(); html.appendEndDiv(); html.appendMainStart(); @SuppressWarnings("unchecked") Map params = (Map)t.getAttribute("parameters"); if (params.containsKey("application")) { application = (String)params.get("application"); } if (params.containsKey("msgid")) { mid = (String)params.get("msgid"); } NewsPostForm postform = new NewsPostForm(); if (mid.equals("")) { response = response + postform.getNewsPostForm(); } int offset = 0; int maxPages = 1; int page = 1; if (mid.equals("")) { int count = 0; String csql = "SELECT COUNT(*) AS rowcount FROM bm_table WHERE application=?"; try { PreparedStatement pstmt = db.conn.prepareStatement(csql); pstmt.setString(1, application); ResultSet rs = pstmt.executeQuery(); rs.next(); count = rs.getInt(1); pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } maxPages = (count/100); if (maxPages*100 < count) { maxPages = maxPages + 1; } page = 1; if (params.containsKey("page")) { String spage = (String)params.get("page"); page = Integer.parseInt(spage); } offset = (page*100) - 100; } if (application.equals("news")) { String like = ""; String addressFrom = ""; String target = ""; String inReplyTo = ""; if (params.containsKey("like")) { like = (String)params.get("like"); addressFrom = (String)params.get("address"); target = (String)params.get("target"); inReplyTo = (String)params.get("inReplyTo"); Node activity = null; try { String query = "SELECT message FROM bm_table WHERE msgid='" + target + "'"; ResultSet dbq = db.query(query); Object o = null; for (; dbq.next(); ) { o = dbq.getObject(1); String message = o.toString(); try { DocumentBuilderFactory dbFactory2 = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder2 = dbFactory2.newDocumentBuilder(); Document doc2 = dBuilder2.parse(new ByteArrayInputStream(message.getBytes())); doc2.getDocumentElement().normalize(); activity = doc2.getElementsByTagName("activity").item(0); } catch (Exception e) { e.printStackTrace(); } } db.st.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } Like liker = new Like(activity, addressFrom, target, inReplyTo); liker.like(); } InputStream is = t.getRequestBody(); if (t.getRequestMethod().equalsIgnoreCase("POST")) { stream2File fstream = new stream2File(); File tmpfile = fstream.getstream2file(is); try { DataSource ds = new FileDataSource(tmpfile); FormdataMultipart forminput = new FormdataMultipart(ds); Hashtable paramsa = forminput.getParameters(); if (paramsa.containsKey("comment")) { String[] commenta = (String[])paramsa.get("comment"); String comment = commenta[0]; comment = ""; String[] addressFroma = (String[])paramsa.get("address"); addressFrom = addressFroma[0]; String[] targeta = (String[])paramsa.get("targetid"); target = targeta[0]; String[] inReplyToa = (String[])paramsa.get("inreplytoid"); inReplyTo = inReplyToa[0]; String[] comment_typea = (String[])paramsa.get("comment_type"); String comment_type = comment_typea[0]; Node activity = null; try { String query = "SELECT message FROM bm_table WHERE msgid='" + target + "'"; ResultSet dbq = db.query(query); Object o = null; for (; dbq.next(); ) { o = dbq.getObject(1); String message = o.toString(); try { DocumentBuilderFactory dbFactory2 = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder2 = dbFactory2.newDocumentBuilder(); Document doc2 = dBuilder2.parse(new ByteArrayInputStream(message.getBytes())); doc2.getDocumentElement().normalize(); activity = doc2.getElementsByTagName("activity").item(0); } catch (Exception e) { e.printStackTrace(); } } db.st.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } Comment commenter = new Comment(activity, addressFrom, target, inReplyTo, comment, comment_type); commenter.comment(); } if (paramsa.containsKey("share_post")) { String[] commenta = (String[])paramsa.get("share_post"); String comment = commenta[0]; comment = ""; ArrayList images = new ArrayList(); for (int i=0; i< forminput.getCount(); i++) { BodyPart bodprt = forminput.getBodyPart(i); DataHandler blah = bodprt.getDataHandler(); InputStream is4 = blah.getInputStream(); String imagein = "data:" + blah.getContentType() + ";base64,"; base64processor encoded = new base64processor(); imagein = imagein + encoded.toString(IOUtils.toByteArray(is4)); images.add(imagein); } String[] ToAddress = (String[])paramsa.get("To"); String[] followersa = (String[])paramsa.get("followers"); String ToAddressType = followersa[0]; Post poster = new Post(ToAddressType, ToAddress, comment, images); poster.post(); } } catch (Exception e) { e.printStackTrace(); } } try { String query = ""; if (mid.equals("")) { query = "SELECT msgid, address, message FROM bm_table WHERE application='news' ORDER BY dtstamp DESC LIMIT 100 OFFSET " + Integer.toString(offset) + ""; } else { query = "SELECT msgid, address, message FROM bm_table WHERE application='news' AND msgid='" + mid + "'"; } ResultSet dbq = db.query(query); Object o = null; for (; dbq.next(); ) { o = dbq.getObject(1); String msgid = o.toString(); o = dbq.getObject(2); String address = o.toString(); o = dbq.getObject(3); String message = o.toString(); response = response + "
" + address + "
"; try { DocumentBuilderFactory dbFactory2 = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder2 = dbFactory2.newDocumentBuilder(); Document doc2 = dBuilder2.parse(new ByteArrayInputStream(message.getBytes())); doc2.getDocumentElement().normalize(); NodeList nList2 = doc2.getElementsByTagName("activity"); String content = ""; String image = ""; int likes = 0; String likers = ""; int commentnumber = 0; ArrayList recipients = new ArrayList(); ArrayList commenters = new ArrayList(); ArrayList contents = new ArrayList(); for (int temp2 = 0; temp2 < nList2.getLength(); temp2++) { Node nNode2 = nList2.item(temp2); if (nNode2.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode2; NodeList toNodeList = eElement.getElementsByTagName("to"); for (int temp3 = 0; temp3 < toNodeList.getLength(); temp3++) { Node toCNode = toNodeList.item(temp3); Element toE = (Element) toCNode; NodeList toCNodeList = toE.getChildNodes(); for (int temp4 = 0; temp4 < toCNodeList.getLength(); temp4++) { Node cnode = toCNodeList.item(temp4); if (cnode.getNodeName().equals("id")) { recipients.add(cnode.getTextContent()); } } } NodeList objectNodeList = eElement.getElementsByTagName("object"); for (int temp3 = 0; temp3 < objectNodeList.getLength(); temp3++) { Node objectCNode = objectNodeList.item(temp3); if (objectCNode.getNodeType() == Node.ELEMENT_NODE) { Element cElement = (Element) objectCNode; NodeList objectCNodeList = cElement.getChildNodes(); for (int temp4=0; temp4", ">"); response = response + "
" + content + "
"; } } for (int temp4=0; temp4 0) { response = response + "

"; } } } for (int temp4=0; temp4Like (" + likes + ") Comment (" + commentnumber + ")"; for (int temp4=0; temp4
" + commenter + "
"; } } for (int temp6 = 0; temp6" + contento + ""; } } for (int temp6 = 0; temp6Like (" + clikes + ") Comment (" + commentnumber2 + ")"; for (int temp6 = 0; temp6

"; } } } } } } } response = response + "
"; response = response + "
"; response = response + ""; response = response + ""; response = response + ""; response = response + ""; bmasAddresses useraddress = new bmasAddresses(); String user = useraddress.getChan(); if ((address.equals(user)) || (recipients.contains(user))) { response = response + ""; } else { response = response + ""; } response = response + "
"; response = response + "
"; } catch (Exception e) { e.printStackTrace(); } } db.st.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } } if (mid.equals("")) { response = response + "

"; if (page > 1) { response = response + "First "; response = response + "Previous "; } int opage = page; while ((opage <= page + 9) && (opage <= maxPages)) { response = response + "" + opage + " "; opage = opage + 1; } if (page < maxPages) { response = response + "Next "; } response = response + "Last "; response = response + "

"; } html.append(response); html.appendEndDiv(); html.appendEndBody(); t.sendResponseHeaders(200, html.getHTML().length()); OutputStream os = t.getResponseBody(); os.write(html.getHTML().getBytes()); os.close(); } public String processComment(Node itemN, String address, String msgid, String application, int page, String response) { int clikes = 0; String clikers = ""; String commentID = ""; Element itemE = (Element) itemN; NodeList itemCNL = itemE.getChildNodes(); for (int temp6 = 0; temp6
" + commenter + "
"; } } for (int temp6 = 0; temp6" + contento + ""; } } for (int temp6 = 0; temp6Like (" + clikes + ") Comment (" + commentnumber2 + ")"; for (int temp6 = 0; temp6

"; return response; } } static class AlertsHandler implements HttpHandler { private ActivityStreamdb db = null; public AlertsHandler(ActivityStreamdb db) { this.db = db; } public void handle(HttpExchange t) throws IOException { String response = ""; processMessages processor = new processMessages(db); processor.process(); try { String INSERT_RECORD = "UPDATE bm_lastclick SET dtstamp=? WHERE wpage=?"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); java.sql.Timestamp sqlDate = new java.sql.Timestamp(new java.util.Date().getTime()); pstmt.setTimestamp(1, sqlDate); pstmt.setString(2, "ALERTS"); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } HTMLBuilder html = new HTMLBuilder(); html.appendDefaultStart(); html.appendEndDiv(); html.appendMainStart(); @SuppressWarnings("unchecked") Map params = (Map)t.getAttribute("parameters"); int offset = 0; int maxPages = 1; int page = 1; int count = 0; String csql = "SELECT COUNT(*) AS rowcount FROM bm_alerts"; try { PreparedStatement pstmt = db.conn.prepareStatement(csql); ResultSet rs = pstmt.executeQuery(); rs.next(); count = rs.getInt(1); pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } maxPages = (count/100); if (maxPages*100 < count) { maxPages = maxPages + 1; } page = 1; if (params.containsKey("page")) { String spage = (String)params.get("page"); page = Integer.parseInt(spage); } offset = (page*100) - 100; try { String query = ""; query = "SELECT msgid, message, dtstamp FROM bm_alerts ORDER BY dtstamp DESC LIMIT 100 OFFSET " + Integer.toString(offset) + ""; ResultSet dbq = db.query(query); Object o = null; for (; dbq.next(); ) { o = dbq.getObject(1); String msgid = o.toString(); o = dbq.getObject(2); String message = o.toString(); o = dbq.getObject(3); String datestamp = o.toString(); String application = ""; String query2 = "SELECT application FROM bm_table WHERE msgid='" + msgid +"'"; ResultSet dbq2 = db.query(query2); Object o2 = null; for (; dbq2.next(); ) { o2 = dbq2.getObject(1); application = o2.toString(); } response = response + "
"; response = response + "" + message + " " + datestamp + "
"; } db.st.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } response = response + "

"; if (page > 1) { response = response + "First "; response = response + "Previous "; } int opage = page; while ((opage <= page + 9) && (opage <= maxPages)) { response = response + "" + opage + " "; opage = opage + 1; } if (page < maxPages) { response = response + "Next "; } response = response + "Last "; response = response + "

"; html.append(response); html.appendEndDiv(); html.appendEndBody(); t.sendResponseHeaders(200, html.getHTML().length()); OutputStream os = t.getResponseBody(); os.write(html.getHTML().getBytes()); os.close(); } } static class LogoutHandler implements HttpHandler { private ActivityStreamdb db = null; private HttpServer server = null; public LogoutHandler(ActivityStreamdb db, HttpServer server) { this.db = db; this.server = server; } public void handle(HttpExchange t) throws IOException { String response = ""; HTMLBuilder html = new HTMLBuilder(); html.appendHTMLHead(); html.appendHTMLStyle(); html.appendHTMLScript(); html.appendHTMLHeadEnd(); html.appendMainStart(); html.append("
GoodBye
"); html.appendEndDiv(); html.appendEndBody(); t.sendResponseHeaders(200, html.getHTML().length()); OutputStream os = t.getResponseBody(); os.write(html.getHTML().getBytes()); os.close(); System.out.println("Database shutdown start"); try { db.shutdown(); } catch (Exception e) { e.printStackTrace(); } System.out.println("Database shutdown complete"); System.out.println("HttpServer shutdown start"); server.stop(0); System.out.println("HttpServer shutdown complete"); } } static class SettingsHandler implements HttpHandler { private ActivityStreamdb db = null; public SettingsHandler(ActivityStreamdb db) { this.db = db; } public void handle(HttpExchange t) throws IOException { String response = ""; String setting = ""; processMessages processor = new processMessages(db); processor.process(); HTMLBuilder html = new HTMLBuilder(); html.appendDefaultStart(); html.appendSettingsLeftMenu(); html.appendEndDiv(); html.appendMainStart(); @SuppressWarnings("unchecked") Map params = (Map)t.getAttribute("parameters"); if (params.containsKey("setting")) { setting = (String)params.get("setting"); } if (t.getRequestMethod().equalsIgnoreCase("POST")) { InputStream is = t.getRequestBody(); stream2File fstream = new stream2File(); File tmpfile = fstream.getstream2file(is); try { DataSource ds = new FileDataSource(tmpfile); FormdataMultipart forminput = new FormdataMultipart(ds); Hashtable paramsa = forminput.getParameters(); if (paramsa.containsKey("add_hashtag")) { String[] hasharr = (String[])paramsa.get("hashtag_name"); String hashtag = hasharr[0]; String INSERT_RECORD = "INSERT INTO bm_settings(setting,value) VALUES(?,?)"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, "hashtag"); pstmt.setString(2, hashtag); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } if (paramsa.containsKey("del_hashtag")) { String[] hasharr = (String[])paramsa.get("hashtag_name"); String hashtag = hasharr[0]; String INSERT_RECORD = "DELETE FROM bm_settings WHERE value=?"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, hashtag); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } if (paramsa.containsKey("upd_bmapi")) { String[] bmapi_iparr = (String[])paramsa.get("bmapi_ip"); String bmapi_ip = bmapi_iparr[0]; String INSERT_RECORD = "UPDATE bm_settings SET value=? WHERE setting=?"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, bmapi_ip); pstmt.setString(2, "bmapi_ip"); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); String[] bmapi_portarr = (String[])paramsa.get("bmapi_port"); String bmapi_port = bmapi_portarr[0]; INSERT_RECORD = "UPDATE bm_settings SET value=? WHERE setting=?"; pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, bmapi_port); pstmt.setString(2, "bmapi_port"); i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); String[] bmapi_userarr = (String[])paramsa.get("bmapi_user"); String bmapi_user = bmapi_userarr[0]; INSERT_RECORD = "UPDATE bm_settings SET value=? WHERE setting=?"; pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, bmapi_user); pstmt.setString(2, "bmapi_user"); i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); String[] bmapi_passwordarr = (String[])paramsa.get("bmapi_password"); String bmapi_password = bmapi_passwordarr[0]; INSERT_RECORD = "UPDATE bm_settings SET value=? WHERE setting=?"; pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, bmapi_password); pstmt.setString(2, "bmapi_password"); i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); String[] bmapi_clientarr = (String[])paramsa.get("bmapi_client"); String bmapi_client = bmapi_clientarr[0]; INSERT_RECORD = "UPDATE bm_settings SET value=? WHERE setting=?"; pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, bmapi_client); pstmt.setString(2, "bmapi_client"); i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } } catch (Exception e) { e.printStackTrace(); } } if (setting.equals("hashtags")) { response = response + "
"; response = response + "Hashtag:

"; response = response + ""; response = response + "
"; response = response + "
"; response = response + "
"; response = response + "Hashtag Name:
"; response = response + "
"; response = response + "
"; } if (setting.equals("bm_api")) { response = response + "
"; try { String query = "SELECT value FROM bm_settings WHERE setting='bmapi_ip'"; ResultSet dbq = db.query(query); Object o = null; for (; dbq.next(); ) { o = dbq.getObject(1); String bmapi_ip = (String)o; response = response + "BM API Host:

"; } } catch (SQLException ex3) { ex3.printStackTrace(); } try { String query = "SELECT value FROM bm_settings WHERE setting='bmapi_port'"; ResultSet dbq = db.query(query); Object o = null; for (; dbq.next(); ) { o = dbq.getObject(1); String bmapi_port = (String)o; response = response + "BM API Port Number:

"; } } catch (SQLException ex3) { ex3.printStackTrace(); } try { String query = "SELECT value FROM bm_settings WHERE setting='bmapi_user'"; ResultSet dbq = db.query(query); Object o = null; for (; dbq.next(); ) { o = dbq.getObject(1); String bmapi_user = (String)o; response = response + "BM API User:

"; } } catch (SQLException ex3) { ex3.printStackTrace(); } try { String query = "SELECT value FROM bm_settings WHERE setting='bmapi_password'"; ResultSet dbq = db.query(query); Object o = null; for (; dbq.next(); ) { o = dbq.getObject(1); String bmapi_password = (String)o; response = response + "BM API Password:

"; } } catch (SQLException ex3) { ex3.printStackTrace(); } try { String query = "SELECT value FROM bm_settings WHERE setting='bmapi_client'"; ResultSet dbq = db.query(query); Object o = null; for (; dbq.next(); ) { o = dbq.getObject(1); String bmapi_client = (String)o; if (bmapi_client.equals("false")) { response = response + "Use browser interface as mail clientNoYes
"; } else { response = response + "Use browser interface as mail clientNoYes
"; } } } catch (SQLException ex3) { ex3.printStackTrace(); } response = response + ""; response = response + "
"; } html.append(response); html.appendEndDiv(); html.appendEndBody(); t.sendResponseHeaders(200, html.getHTML().length()); OutputStream os = t.getResponseBody(); os.write(html.getHTML().getBytes()); os.close(); } } static class MessagesHandler implements HttpHandler { private ActivityStreamdb db = null; public MessagesHandler(ActivityStreamdb db) { this.db = db; } public void handle(HttpExchange t) throws IOException { String response = ""; processMessages processor = new processMessages(db); processor.process(); try { String INSERT_RECORD = "UPDATE bm_lastclick SET dtstamp=? WHERE wpage=?"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); java.sql.Timestamp sqlDate = new java.sql.Timestamp(new java.util.Date().getTime()); pstmt.setTimestamp(1, sqlDate); pstmt.setString(2, "MESSAGES"); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } if (t.getRequestMethod().equalsIgnoreCase("POST")) { InputStream is = t.getRequestBody(); String mfolder = ""; String mread = ""; stream2File fstream = new stream2File(); File tmpfile = fstream.getstream2file(is); try { DataSource ds = new FileDataSource(tmpfile); FormdataMultipart forminput = new FormdataMultipart(ds); Hashtable params = forminput.getParameters(); if (params.containsKey("bmove_folder")) { String[] mfolderarr = (String[])params.get("move_folder"); mfolder = mfolderarr[0]; String[] mmsgid = (String[])params.get("chkmsg"); for (int i=0; i params = (Map)t.getAttribute("parameters"); String folder = "Inbox"; if (params.containsKey("folder")) { folder = (String)params.get("folder"); } int count = 0; String csql = "SELECT COUNT(*) AS rowcount FROM bm_mail WHERE folder=?"; try { PreparedStatement pstmt = db.conn.prepareStatement(csql); pstmt.setString(1, folder); ResultSet rs = pstmt.executeQuery(); rs.next(); count = rs.getInt(1); pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } int maxPages = (count/100); if (maxPages*100 < count) { maxPages = maxPages + 1; } int page = 1; if (params.containsKey("page")) { String spage = (String)params.get("page"); page = Integer.parseInt(spage); } int offset = (page*100) - 100; if (!folder.equals("Sent")) { if (folder.equals("")) { folder = "Inbox"; } response = response + "
"; response = response + ""; response = response + ""; response = response + ""; response = response + ""; response = response + ""; response = response + ""; int i = 0; try { String query = "SELECT msgid, read, subject, fromaddress, dtstamp FROM bm_mail WHERE folder='" + folder + "' ORDER BY dtstamp DESC LIMIT 100 OFFSET " + Integer.toString(offset) + ""; ResultSet dbq = db.query(query); Object o = null; for (; dbq.next(); ) { response = response + ""; String meh = ""; o = dbq.getObject(1); String ref = o.toString(); response = response + ""; o = dbq.getObject(2); Boolean mread = (Boolean)o; o = dbq.getObject(4); meh = o.toString(); response = response + ""; o = dbq.getObject(3); meh = o.toString(); byte[] decoded = Base64.decodeBase64(meh); String meh2 = null; try { meh2 = new String(decoded, "UTF-8"); } catch (Exception e) { e.printStackTrace(); } response = response + ""; o = dbq.getObject(5); meh = o.toString(); response = response + ""; response = response + ""; i++; } db.st.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } } else { if (folder.equals("")) { folder = "Inbox"; } response = response + ""; response = response + ""; response = response + ""; response = response + ""; response = response + ""; response = response + ""; response = response + "
SenderSubjectReceived at
"; if (!mread) { response = response + ""; } response = response + meh; if (!mread) { response = response + ""; } response = response + ""; if (!mread) { response = response + ""; } meh2 = meh2.replaceAll("<", "<"); meh2 = meh2.replaceAll(">", ">"); response = response + meh2; if (!mread) { response = response + ""; } response = response + ""; if (!mread) { response = response + ""; } response = response + meh; if (!mread) { response = response + ""; } response = response + "
"; int i = 0; try { String query = "SELECT msgid, read, subject, fromaddress, dtstamp, ackdata FROM bm_mail WHERE folder='" + folder + "' ORDER BY dtstamp DESC LIMIT 100 OFFSET " + Integer.toString(offset) + ""; ResultSet dbq = db.query(query); Object o = null; for (; dbq.next(); ) { response = response + ""; String meh = ""; o = dbq.getObject(1); String ref = o.toString(); o = dbq.getObject(6); String ref2 = o.toString(); if (!ref.equals("null")) { response = response + ""; } else { response = response + ""; } o = dbq.getObject(2); Boolean mread = (Boolean)o; o = dbq.getObject(4); meh = o.toString(); response = response + ""; o = dbq.getObject(3); meh = o.toString(); byte[] decoded = Base64.decodeBase64(meh); String meh2 = null; try { meh2 = new String(decoded, "UTF-8"); } catch (Exception e) { e.printStackTrace(); } response = response + ""; o = dbq.getObject(5); meh = o.toString(); response = response + ""; response = response + ""; i++; } db.st.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } } response = response + "
SenderSubjectReceived at
"; if (!ref.equals("null")) { response = response + ""; } if (!mread) { response = response + ""; } response = response + meh; if (!mread) { response = response + ""; } if (!ref.equals("null")) { response = response + ""; } response = response + ""; if (!ref.equals("null")) { response = response + ""; } if (!mread) { response = response + ""; } meh2 = meh2.replaceAll("<", "<"); meh2 = meh2.replaceAll(">", ">"); response = response + meh2; if (!mread) { response = response + ""; } if (!ref.equals("null")) { response = response + ""; } response = response + ""; if (!ref.equals("null")) { response = response + ""; } if (!mread) { response = response + ""; } response = response + meh; if (!mread) { response = response + ""; } if (!ref.equals("null")) { response = response + ""; } response = response + "
"; response = response + "
"; response = response + "

"; if (page > 1) { response = response + "First "; response = response + "Previous "; } int opage = page; while ((opage <= page + 9) && (opage <= maxPages)) { response = response + "" + opage + " "; opage = opage + 1; } if (page < maxPages) { response = response + "Next "; } response = response + "Last "; response = response + "

"; response = response + "
"; response = response + ""; html.append(response); t.sendResponseHeaders(200, html.getHTML().length()); OutputStream os = t.getResponseBody(); os.write(html.getHTML().getBytes()); os.close(); } } static class MessageHandler implements HttpHandler { private ActivityStreamdb db = null; public MessageHandler(ActivityStreamdb db) { this.db = db; } public void handle(HttpExchange t) throws IOException { String response = ""; String msgid=""; @SuppressWarnings("unchecked") Map params = (Map)t.getAttribute("parameters"); msgid = (String)params.get("msgid"); if (t.getRequestMethod().equalsIgnoreCase("POST")) { InputStream is = t.getRequestBody(); String mfolder = ""; stream2File fstream = new stream2File(); File tmpfile = fstream.getstream2file(is); try { DataSource ds = new FileDataSource(tmpfile); FormdataMultipart forminput = new FormdataMultipart(ds); Hashtable paramsa = forminput.getParameters(); if (paramsa.containsKey("bmove_folder")) { String[] mfolderarr = (String[])paramsa.get("move_folder"); mfolder = mfolderarr[0]; String INSERT_RECORD = "UPDATE bm_mail SET folder=? WHERE msgid=?"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, mfolder); pstmt.setString(2, msgid); int d = pstmt.executeUpdate(); if (d == -1) { System.out.println("db error : " ); } pstmt.close(); } if (paramsa.containsKey("add_address")) { String[] addressarr = (String[])paramsa.get("address"); String address = addressarr[0]; String INSERT_RECORD = "INSERT INTO bm_profiles(address,following,follower,dtstamp) VALUES(?,?,?,?)"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, address); pstmt.setBoolean(2, false); pstmt.setBoolean(3, false); java.sql.Timestamp sqlDate = new java.sql.Timestamp(new java.util.Date().getTime()); pstmt.setTimestamp(4, sqlDate); int d = pstmt.executeUpdate(); if (d == -1) { System.out.println("db error : " ); } pstmt.close(); } } catch (Exception e) { e.printStackTrace(); } } try { String UPDATE_RECORD = "UPDATE bm_mail SET read=? WHERE msgid=?"; PreparedStatement pstmtu = db.conn.prepareStatement(UPDATE_RECORD); pstmtu.setBoolean(1, true); pstmtu.setString(2, msgid); int du = pstmtu.executeUpdate(); if (du == -1) { System.out.println("db error : " ); } pstmtu.close(); } catch (Exception e) { e.printStackTrace(); } processMessages processor = new processMessages(db); processor.process(); HTMLBuilder html = new HTMLBuilder(); html.appendDefaultStart(); html.appendMailLeftMenu(); html.appendEndDiv(); html.appendMainStart(); response = response + ""; response = response + "
"; response = response + "
"; response = response + ""; response = response + ""; response = response + ""; response = response + "
"; response = response + "
"; response = response + ""; response = response + ""; response = response + "
"; try { String qstring = "SELECT toaddress, fromaddress, subject, message FROM bm_mail WHERE msgid='" + msgid + "'"; ResultSet dbq = db.query(qstring); Object o = null; for (; dbq.next(); ) { response = response + "
TO: "; o = dbq.getObject(1); String meh = o.toString(); response = response + meh + "

"; response = response + "
FROM: "; o = dbq.getObject(2); meh = o.toString(); response = response + meh + "
"; int count = 0; String csql = "SELECT COUNT(*) AS rowcount FROM bm_profiles WHERE address=?"; try { PreparedStatement pstmt = db.conn.prepareStatement(csql); pstmt.setString(1, meh); ResultSet rs = pstmt.executeQuery(); rs.next(); count = rs.getInt(1); pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } if (count == 0) { response = response + "
"; response = response + ""; response = response + ""; response = response + "
"; } response = response + "
"; response = response + "
SUBJECT: "; o = dbq.getObject(3); meh = o.toString(); byte[] decoded = Base64.decodeBase64(meh); String meh2 = null; try { meh2 = new String(decoded, "UTF-8"); } catch (Exception e) { e.printStackTrace(); } response = response + meh2 + "

"; response = response + "
MESSAGE:
";
					o = dbq.getObject(4);
					meh = o.toString();
					decoded = Base64.decodeBase64(meh);
					meh2 = null;		
					try {
						meh2 = new String(decoded, "UTF-8");
					} catch (Exception e) {
						e.printStackTrace();
					}
					meh2 = meh2.replace("&", "&");
					meh2 = meh2.replace("\"", """);
					meh2 = meh2.replace("<", "<");
					meh2 = meh2.replace(">", ">");

					response = response + meh2 + "

"; } db.st.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } response = response + "
"; html.append(response); t.sendResponseHeaders(200, html.getHTML().length()); OutputStream os = t.getResponseBody(); os.write(html.getHTML().getBytes()); os.close(); } } static class SendMessageHandler implements HttpHandler { private ActivityStreamdb db = null; public SendMessageHandler(ActivityStreamdb db) { this.db = db; } public void handle(HttpExchange t) throws IOException { String To = ""; String From = ""; String Subject = ""; String Message = ""; @SuppressWarnings("unchecked") Map params = (Map)t.getAttribute("parameters"); if (t.getRequestMethod().equalsIgnoreCase("GET")) { if (params.size() > 0) { To = (String)params.get("To"); From = (String)params.get("From"); Subject = (String)params.get("Subject"); Message = (String)params.get("Message"); } } if (t.getRequestMethod().equalsIgnoreCase("POST")) { InputStream is = t.getRequestBody(); stream2File fstream = new stream2File(); File tmpfile = fstream.getstream2file(is); try { DataSource ds = new FileDataSource(tmpfile); FormdataMultipart forminput = new FormdataMultipart(ds); Hashtable paramsa = forminput.getParameters(); if (paramsa.containsKey("send")) { try { String[] msgida = (String[])paramsa.get("msgid"); String[] senda = (String[])paramsa.get("send"); String qstring = "SELECT toaddress, fromaddress, subject, message FROM bm_mail WHERE msgid='" + msgida[0] + "'"; ResultSet dbq = db.query(qstring); Object o = null; for (; dbq.next(); ) { if (senda[0].equals("Reply")) { o = dbq.getObject(2); To = o.toString(); } o = dbq.getObject(3); String meh = o.toString(); byte[] decoded = Base64.decodeBase64(meh); Subject = null; try { Subject = new String(decoded, "UTF-8"); } catch (Exception e) { e.printStackTrace(); } o = dbq.getObject(4); meh = o.toString(); decoded = Base64.decodeBase64(meh); Message = null; try { Message = new String(decoded, "UTF-8"); } catch (Exception e) { e.printStackTrace(); } } db.st.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } } processMessages processor = new processMessages(db); processor.process(); String response = ""; HTMLBuilder html = new HTMLBuilder(); html.appendDefaultStart(); html.appendMailLeftMenu(); html.appendEndDiv(); html.appendMainStart(); response = response + "
"; if (!To.equals("")) { response = response + ""; } else { response = response + ""; } response = response + ""; response = response + ""; response = response + ""; response = response + "
To:
To:
From:
Subject:
Message:
"; response = response + "
"; html.append(response); html.appendEndDiv(); html.appendEndBody(); t.sendResponseHeaders(200, html.getHTML().length()); OutputStream os = t.getResponseBody(); os.write(html.getHTML().getBytes()); os.close(); } } static class SendHandler implements HttpHandler { private ActivityStreamdb db = null; public SendHandler(ActivityStreamdb db) { this.db = db; } public void handle(HttpExchange t) throws IOException { String response = ""; InputStream is = t.getRequestBody(); if (t.getRequestMethod().equalsIgnoreCase("POST")) { String toaddress = ""; String fromaddress = ""; String subject = ""; String message = ""; stream2File fstream = new stream2File(); File tmpfile = fstream.getstream2file(is); try { DataSource ds = new FileDataSource(tmpfile); FormdataMultipart forminput = new FormdataMultipart(ds); Hashtable params = forminput.getParameters(); String[] toarr = (String[])params.get("To"); for (int a=0; a\n"; } message = message + response; message = encoded.toString(message.getBytes()); Send sender = new Send(toaddress, fromaddress, subject, message); String response2 = sender.sendMessage(); System.out.println("Actkdata from send " + response2); try { String INSERT_RECORD = "INSERT INTO bm_mail(ackdata,read,folder,toaddress,fromaddress,subject,message,encodingtype,dtstamp,msgid) VALUES(?,?,?,?,?,?,?,?,?,?)"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, response2); pstmt.setBoolean(2, true); pstmt.setString(3, "Sent"); pstmt.setString(4, toaddress); pstmt.setString(5, fromaddress); pstmt.setString(6, subject); pstmt.setString(7, message); pstmt.setInt(8, 2); java.sql.Timestamp sqlDate = new java.sql.Timestamp(new java.util.Date().getTime()); pstmt.setTimestamp(9, sqlDate); pstmt.setString(10, "null"); int d = pstmt.executeUpdate(); if (d == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } } processOutMessages processor = new processOutMessages(db); processor.process(); response = ""; response = response + ""; response = response + " "; response = response + " "; response = response + " "; response = response + " "; response = response + " Page Redirection"; response = response + " "; response = response + " "; response = response + " "; response = response + ""; t.sendResponseHeaders(200, response.length()); OutputStream os = t.getResponseBody(); os.write(response.getBytes()); os.close(); } } static class ProfilesHandler implements HttpHandler { private ActivityStreamdb db = null; public ProfilesHandler(ActivityStreamdb db) { this.db = db; } public void handle(HttpExchange t) throws IOException { String response = ""; String page = "follower"; @SuppressWarnings("unchecked") Map params = (Map)t.getAttribute("parameters"); if (params.containsKey("page")) { page = (String)params.get("page"); } if (t.getRequestMethod().equalsIgnoreCase("POST")) { InputStream is = t.getRequestBody(); stream2File fstream = new stream2File(); File tmpfile = fstream.getstream2file(is); try { DataSource ds = new FileDataSource(tmpfile); FormdataMultipart forminput = new FormdataMultipart(ds); Hashtable paramsa = forminput.getParameters(); if (paramsa.containsKey("add_address")) { String[] addressarr = (String[])paramsa.get("address"); String address = addressarr[0]; String[] followerarr = (String[])paramsa.get("follower"); String follower = followerarr[0]; String[] followingarr = (String[])paramsa.get("following"); String following = followingarr[0]; int count = 0; String csql = "SELECT COUNT(*) AS rowcount FROM bm_profiles WHERE address=?"; try { PreparedStatement pstmt = db.conn.prepareStatement(csql); pstmt.setString(1, address); ResultSet rs = pstmt.executeQuery(); rs.next(); count = rs.getInt(1); pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } if (count == 0) { String INSERT_RECORD = "INSERT INTO bm_profiles(address,follower,following) VALUES(?,?,?)"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, address); pstmt.setBoolean(2, Boolean.parseBoolean(follower)); pstmt.setBoolean(3, Boolean.parseBoolean(following)); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } if (Boolean.parseBoolean(following)) { Follow follow = new Follow(address); follow.follow(); } } if (paramsa.containsKey("add_list")) { String[] listarr = (String[])paramsa.get("list_name"); String list = listarr[0]; String INSERT_RECORD = "INSERT INTO bm_profiles_lists(list,address) VALUES(?,?)"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, list); pstmt.setString(2, "dummy"); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } if (paramsa.containsKey("del_list")) { String[] listarr = (String[])paramsa.get("list_name"); String list = listarr[0]; String INSERT_RECORD = "DELETE FROM bm_profiles_lists WHERE list=?"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, list); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } } catch (Exception e) { e.printStackTrace(); } } processMessages processor = new processMessages(db); processor.process(); try { String INSERT_RECORD = "UPDATE bm_lastclick SET dtstamp=? WHERE wpage=?"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); java.sql.Timestamp sqlDate = new java.sql.Timestamp(new java.util.Date().getTime()); pstmt.setTimestamp(1, sqlDate); pstmt.setString(2, "FOLLOWERS"); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } HTMLBuilder html = new HTMLBuilder(); html.appendDefaultStart(); html.appendProfilesLeftMenu(); html.appendEndDiv(); html.appendMainStart(); int offset = 0; if (page.equals("follower") || page.equals("following")) { if (page.equals("following")) { response = response + "
"; response = response + "Address:

"; response = response + ""; response = response + ""; response = response + ""; response = response + "
"; } try { String query = "SELECT address, label FROM bm_profiles WHERE " + page + "=true ORDER BY dtstamp DESC LIMIT 100 OFFSET " + Integer.toString(offset) + ""; System.out.println("Retreive " + page + " details"); ResultSet dbq = db.query(query); Object o = null; int count = 0; response = response + ""; for (; dbq.next(); ) { count++; if (count == 1) { response = response + ""; } o = dbq.getObject(1); String address = (String)o; o = dbq.getObject(2); String label = (String)o; response = response + ""; if (count == 3) { response = response + ""; count = 0; } } if ((count == 1) || (count == 2)) { response = response + ""; } response = response + "
"; response = response + label + "
"; response = response + ""+ address + ""; response = response + "
"; db.st.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } } if (page.equals("mail_contacts")) { response = response + "
"; response = response + "Address:

"; response = response + ""; response = response + ""; response = response + ""; response = response + "
"; try { String query = "SELECT address, label FROM bm_profiles WHERE follower=false AND following=false ORDER BY dtstamp DESC LIMIT 100 OFFSET " + Integer.toString(offset) + ""; System.out.println("Retreive " + page + " details"); ResultSet dbq = db.query(query); Object o = null; int count = 0; response = response + ""; for (; dbq.next(); ) { count++; if (count == 1) { response = response + ""; } o = dbq.getObject(1); String address = (String)o; o = dbq.getObject(2); String label = (String)o; response = response + ""; if (count == 3) { response = response + ""; count = 0; } } if ((count == 1) || (count == 2)) { response = response + ""; } response = response + "
"; response = response + label + "
"; response = response + ""+ address + ""; response = response + "
"; db.st.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } } if (page.equals("lists")) { response = response + "
"; response = response + "List Name:

"; response = response + ""; response = response + "
"; response = response + "
"; response = response + "
"; response = response + "List Name:
"; response = response + "
"; response = response + "
"; } response = response + ""; html.append(response); t.sendResponseHeaders(200, html.getHTML().length()); OutputStream os = t.getResponseBody(); os.write(html.getHTML().getBytes()); os.close(); } } static class ProfileHandler implements HttpHandler { private ActivityStreamdb db = null; public ProfileHandler(ActivityStreamdb db) { this.db = db; } public void handle(HttpExchange t) throws IOException { String response = ""; @SuppressWarnings("unchecked") Map params = (Map)t.getAttribute("parameters"); String address = (String)params.get("address"); if (t.getRequestMethod().equalsIgnoreCase("POST")) { InputStream is = t.getRequestBody(); stream2File fstream = new stream2File(); File tmpfile = fstream.getstream2file(is); try { DataSource ds = new FileDataSource(tmpfile); FormdataMultipart forminput = new FormdataMultipart(ds); Hashtable paramsa = forminput.getParameters(); if (paramsa.containsKey("update")) { String[] labelarr = (String[])paramsa.get("label"); String label = labelarr[0]; String[] notesarr = (String[])paramsa.get("notes"); String notes = notesarr[0]; String INSERT_RECORD = "UPDATE bm_profiles SET label=?, notes=? WHERE address=?"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, label); pstmt.setString(2, notes); pstmt.setString(3, address); int d = pstmt.executeUpdate(); if (d == -1) { System.out.println("db error : " ); } pstmt.close(); } if (paramsa.containsKey("follow")) { Follow follow = new Follow(address); follow.follow(); } if (paramsa.containsKey("unfollow")) { Follow follow = new Follow(address); follow.unfollow(); } if (paramsa.containsKey("delete")) { Follow follow = new Follow(address); follow.unfollow(); String INSERT_RECORD = "DELETE FROM bm_profiles WHERE address=?"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, address); int d = pstmt.executeUpdate(); if (d == -1) { System.out.println("db error : " ); } pstmt.close(); } if (paramsa.containsKey("add_to_list")) { String[] listarr = (String[])paramsa.get("list_name"); String list = listarr[0]; String INSERT_RECORD = "INSERT INTO bm_profiles_lists(list, address) VALUES(?,?)"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, list); pstmt.setString(2, address); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } if (paramsa.containsKey("del_from_list")) { String[] listarr = (String[])paramsa.get("list_name"); String list = listarr[0]; String INSERT_RECORD = "DELETE FROM bm_profiles_lists WHERE list=? AND address=?"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, list); pstmt.setString(2, address); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } } catch (Exception e) { e.printStackTrace(); } } processMessages processor = new processMessages(db); processor.process(); HTMLBuilder html = new HTMLBuilder(); html.appendDefaultStart(); html.appendProfilesLeftMenu(); html.appendEndDiv(); html.appendMainStart(); String label = ""; String notes = ""; Boolean follower = false; Boolean following = false; try { String query = "SELECT label, notes, follower, following FROM bm_profiles WHERE address='" + address + "'"; System.out.println("Retrieving address details"); ResultSet dbq = db.query(query); Object o = null; int count = 0; response = response + ""; for (; dbq.next(); ) { count++; if (count == 1) { response = response + ""; } o = dbq.getObject(1); label = (String)o; o = dbq.getObject(2); notes = (String)o; o = dbq.getObject(3); follower = (Boolean)o; o = dbq.getObject(4); following = (Boolean)o; } db.st.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } response = response + "
" + address + "
"; if (follower) { response = response + "
(Follower)
"; } response = response + ""; response = response + "Label:

"; response = response + "Notes:

"; response = response + ""; response = response + ""; response = response + ""; response = response + ""; response = response + ""; response = response + ""; response = response + ""; response = response + ""; response = response + ""; response = response + ""; if (follower) { ArrayList addlist = new ArrayList(); ArrayList dellist = new ArrayList(); try { String query = "SELECT list FROM bm_profiles_lists WHERE address='" + address + "'"; System.out.println("Checking follower list "+ address + " belongs to"); ResultSet dbq = db.query(query); Object o = null; for (; dbq.next(); ) { o = dbq.getObject(1); String list = (String)o; dellist.add(list); } } catch (SQLException ex3) { ex3.printStackTrace(); } try { String query = "SELECT DISTINCT list FROM bm_profiles_lists"; System.out.println("Checking available lists"); ResultSet dbq = db.query(query); Object o = null; for (; dbq.next(); ) { o = dbq.getObject(1); String list = (String)o; if (!dellist.contains(list)) { addlist.add(list); } } } catch (SQLException ex3) { ex3.printStackTrace(); } response = response + "
"; response = response + ""; response = response + ""; response = response + ""; response = response + "
"; response = response + ""; response = response + ""; response = response + ""; if (!following) { response = response + "
"; response = response + ""; response = response + ""; } } if (following) { response = response + "
"; response = response + ""; response = response + ""; } if (!follower) { response = response + "
"; response = response + ""; response = response + ""; } response = response + ""; html.append(response); t.sendResponseHeaders(200, html.getHTML().length()); OutputStream os = t.getResponseBody(); os.write(html.getHTML().getBytes()); os.close(); } } static class Send { private String toAddress = ""; private String fromAddress = ""; private String Subject = ""; private String Message = ""; public Send(String toAddress, String fromAddress, String Subject, String Message) { this.toAddress = toAddress; this.fromAddress = fromAddress; this.Subject = Subject; this.Message = Message; } public String sendMessage() { String xml = "sendMessage" + toAddress + "" + fromAddress + "" + Subject + "" + Message + ""; APIcall sendCall = new APIcall(); String response2 = sendCall.getAPIcall(xml); try { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(new ByteArrayInputStream(response2.getBytes())); doc.getDocumentElement().normalize(); NodeList nList = doc.getElementsByTagName("param"); for (int temp = 0; temp < nList.getLength(); temp++) { Node nNode = nList.item(temp); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; response2 = eElement.getElementsByTagName("string").item(0).getTextContent(); } } } catch (Exception e) { e.printStackTrace(); } return response2; } } static class Follow { String address = ""; String user = ""; public Follow(String address) { this.address = address; bmasAddresses useraddress = new bmasAddresses(); this.user = useraddress.getUser(); } public void follow() { try { String INSERT_RECORD = "UPDATE bm_profiles SET following=? WHERE address=?"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setBoolean(1, true); pstmt.setString(2, address); int d = pstmt.executeUpdate(); if (d == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (Exception e) { e.printStackTrace(); } base64processor encoded = new base64processor(); String subjectp = "[BM-ActivityStream]"; String subject = encoded.toString(subjectp.getBytes()); String messagep = ""; String uuid = UUID.randomUUID().toString(); messagep = messagep + "person" + address + "person" + user + "followers" + uuid + "followperson" + address + ""; String message = encoded.toString(messagep.getBytes()); Send sender = new Send(address, user, subject, message); sender.sendMessage(); try { String INSERT_RECORD = "INSERT INTO bm_table(msgid,address,application,message,dtstamp) VALUES(?,?,?,?,?)"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, uuid); pstmt.setString(2, user); pstmt.setString(3, "followers"); pstmt.setString(4, messagep); java.sql.Timestamp sqlDate = new java.sql.Timestamp(new java.util.Date().getTime()); System.out.println(sqlDate); pstmt.setTimestamp(5, sqlDate); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (SQLException e) { e.printStackTrace(); } } public void unfollow() { base64processor encoded = new base64processor(); String subjectp = "[BM-ActivityStream]"; String subject = encoded.toString(subjectp.getBytes()); String messagep = ""; String uuid = UUID.randomUUID().toString(); messagep = messagep + "person" + address + "person" + user + "followers" + uuid + "unfollowperson" + address + ""; String message = encoded.toString(messagep.getBytes()); Send sender = new Send(address, user, subject, message); sender.sendMessage(); try { String INSERT_RECORD = "UPDATE bm_profiles SET following=? WHERE address=?"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setBoolean(1, false); pstmt.setString(2, address); int d = pstmt.executeUpdate(); if (d == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (Exception e) { e.printStackTrace(); } try { String INSERT_RECORD = "INSERT INTO bm_table(msgid,address,application,message,dtstamp) VALUES(?,?,?,?,?)"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, uuid); pstmt.setString(2, user); pstmt.setString(3, "followers"); pstmt.setString(4, messagep); java.sql.Timestamp sqlDate = new java.sql.Timestamp(new java.util.Date().getTime()); System.out.println(sqlDate); pstmt.setTimestamp(5, sqlDate); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (SQLException e) { e.printStackTrace(); } } } static class Follower { String address = ""; public Follower(String address) { this.address = address; } public void followed() { try { System.out.println("Setting follower to true for " + address); String INSERT_RECORD = "UPDATE bm_profiles SET follower=? WHERE address=?"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setBoolean(1, true); pstmt.setString(2, address); int d = pstmt.executeUpdate(); if (d == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (Exception e) { e.printStackTrace(); } } public void unfollowed() { try { System.out.println("Setting follower to false for " + address); String INSERT_RECORD = "UPDATE bm_profiles SET follower=? WHERE address=?"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setBoolean(1, false); pstmt.setString(2, address); int d = pstmt.executeUpdate(); if (d == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (Exception e) { e.printStackTrace(); } } } static class Like { Node activity = null; String address = ""; String targetid = ""; String replyid = ""; String user = ""; public Like(Node activity, String address, String targetid, String replyid) { this.activity = activity; this.address = address; this.targetid = targetid; this.replyid = replyid; bmasAddresses useraddress = new bmasAddresses(); this.user = useraddress.getUser(); } public void like() { String messagep = ""; ArrayList recipients = new ArrayList(); if ((!recipients.contains(address)) && (!address.equals(user))) { recipients.add(address); } Element activityE = (Element) activity; NodeList toNL = activityE.getElementsByTagName("to"); for (int z = 0; z"; messagep = messagep + ""; for (int y =0; yperson" + recipients.get(y) + ""; } messagep = messagep + "person" + user + "news" + targetid + "like" + replyid + "" + replyid + "." + UUID.randomUUID().toString() + ""; String message = encoded.toString(messagep.getBytes()); for (int y =0; y recipients = new ArrayList(); if ((!recipients.contains(address)) && (!address.equals(user))) { recipients.add(address); } Element activityE = (Element) activity; NodeList toNL = activityE.getElementsByTagName("to"); for (int z = 0; z"; messagep = messagep + ""; for (int y =0; yperson" + recipients.get(y) + ""; } messagep = messagep + "person" + user + "news" + targetid + "comment" + replyid + "" + replyid + "." + UUID.randomUUID().toString() + "" + comment + ""; String message = encoded.toString(messagep.getBytes()); if (comment_type.equals("Anonymous")) { bmasAddresses chanaddress = new bmasAddresses(); this.user = chanaddress.getChan(); } for (int y =0; y images = new ArrayList(); String user = ""; String comment = ""; public Post(String addresstype, String[] addressees, String content, ArrayList images) { this.addresstype = addresstype; this.addressees = addressees; this.content = content; this.images = images; bmasAddresses useraddress = new bmasAddresses(); this.user = useraddress.getUser(); } public void post() { String messagep = ""; ArrayList recipients = new ArrayList(); if (addresstype.equals("Followers")) { for (int z = 0; z 0) { base64processor encoded = new base64processor(); String subjectp = "[BM-ActivityStream]"; String subject = encoded.toString(subjectp.getBytes()); messagep = ""; messagep = messagep + ""; for (int y =0; yperson" + recipients.get(y) + ""; } messagep = messagep + "person" + user + "news" + UUID.randomUUID().toString() + "post" + content + ""; if (images.size() > 0) { messagep = messagep + "" + images.get(0) + ""; } messagep = messagep + ""; String message = encoded.toString(messagep.getBytes()); for (int y =0; y"; String response2 = apicall.getAPIcall(xml2); } pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } } } else { System.out.println("Activity Stream Message"); byte[] bdcMessage = Base64.decodeBase64(ecMessage); String message = new String(bdcMessage, "UTF-8"); DocumentBuilderFactory dbFactory2 = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder2 = dbFactory2.newDocumentBuilder(); Document doc2 = dBuilder2.parse(new ByteArrayInputStream(message.getBytes())); doc2.getDocumentElement().normalize(); NodeList nList2 = doc2.getElementsByTagName("activity"); String application = ""; for (int temp2 = 0; temp2 < nList2.getLength(); temp2++) { Node nNode2 = nList2.item(temp2); if (nNode2.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode2; Node targetNode = eElement.getElementsByTagName("target").item(0); Element targetElement = (Element) targetNode; application = targetElement.getElementsByTagName("objectType").item(0).getTextContent(); if (application.equals("followers")) { bmasAddresses bmasaddresses = new bmasAddresses(); String useraddress = bmasaddresses.getUser(); String chanaddress = bmasaddresses.getChan(); if (toAddress.equals(useraddress)) { FollowersProcessor followprocess = new FollowersProcessor(fromAddress, receivedTime, nNode2, message); Boolean processed = followprocess.process(); if (processed) { APIcall apicall2 = new APIcall(); String xml2 = "trashMessage" + msgid + ""; String apiout = apicall2.getAPIcall(xml2); bm_as_processed = true; } } } if (application.equals("news")) { bmasAddresses bmasaddresses = new bmasAddresses(); String useraddress = bmasaddresses.getUser(); String chanaddress = bmasaddresses.getChan(); if ((toAddress.equals(useraddress)) || (toAddress.equals(chanaddress))) { NewsProcessor newsprocess = new NewsProcessor(fromAddress, receivedTime, nNode2, message); Boolean processed = newsprocess.process(); if (processed) { APIcall apicall2 = new APIcall(); String xml2 = "trashMessage" + msgid + ""; String apiout = apicall2.getAPIcall(xml2); bm_as_processed = true; } } } } } } } else { finder1.endJSON(); } } } catch(ParseException pe) { pe.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } } } } static class processOutMessages { private ActivityStreamdb db = null; public processOutMessages(ActivityStreamdb db) { this.db = db; } public void process() { APIcall apicall = new APIcall(); String xml = "getAllSentMessages"; String response = apicall.getAPIcall(xml); try { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(new ByteArrayInputStream(response.getBytes())); doc.getDocumentElement().normalize(); NodeList nList = doc.getElementsByTagName("param"); for (int temp = 0; temp < nList.getLength(); temp++) { Node nNode = nList.item(temp); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; response = eElement.getElementsByTagName("string").item(0).getTextContent(); } JSONParser parser1 = new JSONParser(); JSONParser parser2 = new JSONParser(); JSONParser parser3 = new JSONParser(); JSONParser parser4 = new JSONParser(); JSONParser parser5 = new JSONParser(); JSONParser parser6 = new JSONParser(); JSONParser parser7 = new JSONParser(); JSONParser parser8 = new JSONParser(); JSONParser parser9 = new JSONParser(); KeyFinder finder1 = new KeyFinder(); KeyFinder finder2 = new KeyFinder(); KeyFinder finder3 = new KeyFinder(); KeyFinder finder4 = new KeyFinder(); KeyFinder finder5 = new KeyFinder(); KeyFinder finder6 = new KeyFinder(); KeyFinder finder7 = new KeyFinder(); KeyFinder finder8 = new KeyFinder(); KeyFinder finder9 = new KeyFinder(); finder1.setMatchKey("msgid"); finder2.setMatchKey("toAddress"); finder3.setMatchKey("fromAddress"); finder4.setMatchKey("subject"); finder5.setMatchKey("message"); finder6.setMatchKey("encodingType"); finder7.setMatchKey("lastActionTime"); finder8.setMatchKey("status"); finder9.setMatchKey("ackData"); try { while(!finder1.isEnd()) { parser1.parse(response, finder1, true); parser2.parse(response, finder2, true); parser3.parse(response, finder3, true); parser4.parse(response, finder4, true); parser5.parse(response, finder5, true); parser6.parse(response, finder6, true); parser7.parse(response, finder7, true); parser8.parse(response, finder8, true); parser9.parse(response, finder9, true); if(finder1.isFound()) { finder1.setFound(false); String msgid = (String)finder1.getValue(); String toAddress = (String)finder2.getValue(); String fromAddress = (String)finder3.getValue(); String ecSubject = (String)finder4.getValue(); byte[] bdcSubject = Base64.decodeBase64(ecSubject); String subject = new String(bdcSubject, "UTF-8"); String ecMessage = (String)finder5.getValue(); long encodingTypel = (long)finder6.getValue(); int encodingType = (int)encodingTypel; long receivedTime = (long)finder7.getValue(); String status = (String)finder8.getValue(); String ackdata = (String)finder9.getValue(); if (!msgid.equals("")) { try { String INSERT_RECORD = "UPDATE bm_mail SET msgid=? WHERE ackdata=?"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, msgid); pstmt.setString(2, ackdata); int d = pstmt.executeUpdate(); if (d == -1) { System.out.println("db error : " ); } else { APIcall apicall2 = new APIcall(); String xml2 = "trashMessage" + msgid + ""; String apiout = apicall2.getAPIcall(xml2); } pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } } } else { finder1.endJSON(); } } } catch(ParseException pe) { pe.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } } } static class FollowersProcessor { private Node nNode2; private String fromAddress = ""; private long receivedTime = 0; private String inMessage = ""; public FollowersProcessor(String fromAddress, long receivedTime, Node nNode2, String inMessage) { this.fromAddress = fromAddress; this.receivedTime = receivedTime; this.nNode2 = nNode2; this.inMessage = inMessage; } public Boolean process() { Boolean processed = false; String verb = ""; String id = ""; if (nNode2.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode2; verb = eElement.getElementsByTagName("verb").item(0).getTextContent(); Node targetNode = eElement.getElementsByTagName("target").item(0); Element targetElement = (Element) targetNode; id = targetElement.getElementsByTagName("id").item(0).getTextContent(); } System.out.println("Processing follower message"); if (verb.equals("follow")) { System.out.println("Follower message verb follow"); int mcount = 0; String csql = "SELECT COUNT(*) AS rowcount FROM bm_profiles WHERE address=?"; try { PreparedStatement pstmt = db.conn.prepareStatement(csql); pstmt.setString(1, fromAddress); ResultSet rs = pstmt.executeQuery(); rs.next(); mcount = rs.getInt(1); // System.out.println(mcount); pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } if (mcount == 0) { mcount = 0; csql = "SELECT COUNT(*) AS rowcount FROM bm_table WHERE msgid=?"; try { PreparedStatement pstmt = db.conn.prepareStatement(csql); pstmt.setString(1, id); ResultSet rs = pstmt.executeQuery(); rs.next(); mcount = rs.getInt(1); // System.out.println(mcount); pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } if (mcount == 0) { System.out.println("Address not found in profiles - creating"); try { String INSERT_RECORD = "INSERT INTO bm_profiles(address,follower,following,dtstamp) VALUES(?,?,?,?,?)"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, fromAddress); pstmt.setBoolean(2, true); pstmt.setBoolean(3, false); java.sql.Timestamp sqlDate = new java.sql.Timestamp(receivedTime*1000L); System.out.println(sqlDate); pstmt.setTimestamp(4, sqlDate); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (SQLException e) { e.printStackTrace(); } System.out.println("Message not seen before adding message to bm_table"); try { String INSERT_RECORD = "INSERT INTO bm_table(msgid,address,application,message,dtstamp) VALUES(?,?,?,?,?)"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, id); pstmt.setString(2, fromAddress); pstmt.setString(3, "followers"); pstmt.setString(4, inMessage); java.sql.Timestamp sqlDate = new java.sql.Timestamp(receivedTime*1000L); System.out.println(sqlDate); pstmt.setTimestamp(5, sqlDate); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (SQLException e) { e.printStackTrace(); } } processed = true; } else { System.out.println("Address found in profiles - processing"); mcount = 0; csql = "SELECT COUNT(*) AS rowcount FROM bm_profiles WHERE address=? AND follower=?"; try { PreparedStatement pstmt = db.conn.prepareStatement(csql); pstmt.setString(1, fromAddress); pstmt.setBoolean(2, false); ResultSet rs = pstmt.executeQuery(); rs.next(); mcount = rs.getInt(1); pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } if (mcount == 1) { mcount = 0; csql = "SELECT COUNT(*) AS rowcount FROM bm_table WHERE msgid=?"; try { PreparedStatement pstmt = db.conn.prepareStatement(csql); pstmt.setString(1, id); ResultSet rs = pstmt.executeQuery(); rs.next(); mcount = rs.getInt(1); // System.out.println(mcount); pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } if (mcount == 0) { System.out.println("Address not a follower - updating to be"); Follower follower = new Follower(fromAddress); follower.followed(); System.out.println("Message not seen before adding message to bm_table"); try { String INSERT_RECORD = "INSERT INTO bm_table(msgid,address,application,message,dtstamp) VALUES(?,?,?,?,?)"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, id); pstmt.setString(2, fromAddress); pstmt.setString(3, "followers"); pstmt.setString(4, inMessage); java.sql.Timestamp sqlDate = new java.sql.Timestamp(receivedTime*1000L); System.out.println(sqlDate); pstmt.setTimestamp(5, sqlDate); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (SQLException e) { e.printStackTrace(); } } processed = true; } } } if (verb.equals("unfollow")) { System.out.println("Follower message verb unfollow"); int mcount = 0; String csql = "SELECT COUNT(*) AS rowcount FROM bm_profiles WHERE address=? AND follower=?"; try { PreparedStatement pstmt = db.conn.prepareStatement(csql); pstmt.setString(1, fromAddress); pstmt.setBoolean(2, true); ResultSet rs = pstmt.executeQuery(); rs.next(); mcount = rs.getInt(1); // System.out.println(mcount); pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } if (mcount == 1) { System.out.println("Address is a follower - updating to not be"); Follower follower = new Follower(fromAddress); follower.unfollowed(); } mcount = 0; csql = "SELECT COUNT(*) AS rowcount FROM bm_table WHERE msgid=?"; try { PreparedStatement pstmt = db.conn.prepareStatement(csql); pstmt.setString(1, id); ResultSet rs = pstmt.executeQuery(); rs.next(); mcount = rs.getInt(1); // System.out.println(mcount); pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } System.out.println("mcount " + mcount); if (mcount == 0) { System.out.println("Message not seen before adding message to bm_table"); try { String INSERT_RECORD = "INSERT INTO bm_table(msgid,address,application,message,dtstamp) VALUES(?,?,?,?,?)"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, id); pstmt.setString(2, fromAddress); pstmt.setString(3, "followers"); pstmt.setString(4, inMessage); java.sql.Timestamp sqlDate = new java.sql.Timestamp(receivedTime*1000L); pstmt.setTimestamp(5, sqlDate); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (SQLException e) { e.printStackTrace(); } } processed = true; } return processed; } } static class NewsProcessor { private Node nNode2; private String fromAddress = ""; private long receivedTime = 0; private String inMessage = ""; public NewsProcessor(String fromAddress, long receivedTime, Node nNode2, String inMessage) { this.fromAddress = fromAddress; this.receivedTime = receivedTime; this.nNode2 = nNode2; this.inMessage = inMessage; } public Boolean process() { Boolean processed = false; String verb = ""; String id = ""; String object = ""; String postactor = ""; if (nNode2.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode2; verb = eElement.getElementsByTagName("verb").item(0).getTextContent(); object = eElement.getElementsByTagName("object").item(0).getTextContent(); Node targetNode = eElement.getElementsByTagName("target").item(0); Element targetElement = (Element) targetNode; id = targetElement.getElementsByTagName("id").item(0).getTextContent(); Node actorNode = eElement.getElementsByTagName("actor").item(0); Element actorElement = (Element) actorNode; postactor = actorElement.getElementsByTagName("id").item(0).getTextContent(); } if (verb.equals("post")) { int mcount = 0; String csql = "SELECT COUNT(*) AS rowcount FROM bm_table WHERE msgid=?"; try { PreparedStatement pstmt = db.conn.prepareStatement(csql); pstmt.setString(1, id); ResultSet rs = pstmt.executeQuery(); rs.next(); mcount = rs.getInt(1); pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } if (mcount == 0) { int count = 0; String csql2 = "SELECT COUNT(*) AS rowcount FROM bm_profiles WHERE address=? AND following=?"; try { PreparedStatement pstmt = db.conn.prepareStatement(csql2); pstmt.setString(1, fromAddress); pstmt.setBoolean(2, true); ResultSet rs = pstmt.executeQuery(); rs.next(); count = rs.getInt(1); // System.out.println(count); pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } boolean containsHashTag = false; if (count == 0) { Element eElementa = (Element) nNode2; Node objectNode = eElementa.getElementsByTagName("object").item(0); Element objectElement = (Element) objectNode; String postContent = objectElement.getElementsByTagName("content").item(0).getTextContent(); try { String query = "SELECT value FROM bm_settings WHERE setting='hashtag'"; ResultSet dbq = db.query(query); Object o = null; for (; dbq.next(); ) { o = dbq.getObject(1); String hashtag = (String)o; hashtag = hashtag + " "; if (postContent.indexOf(hashtag) > -1) { containsHashTag = true; } } db.st.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } } System.out.println("Contains hashtag: " + containsHashTag); bmasAddresses bmasaddresses = new bmasAddresses(); String useraddress = bmasaddresses.getUser(); if ((count == 1) || (containsHashTag) || useraddress.equals(fromAddress)) { try { String INSERT_RECORD = "INSERT INTO bm_table(msgid,address,application,message,dtstamp) VALUES(?,?,?,?,?)"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, id); pstmt.setString(2, fromAddress); pstmt.setString(3, "news"); pstmt.setString(4, inMessage); java.sql.Timestamp sqlDate = new java.sql.Timestamp(receivedTime*1000L); pstmt.setTimestamp(5, sqlDate); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (SQLException e) { e.printStackTrace(); } } } processed = true; } if (verb.equals("comment")) { System.out.println("Processing Comment"); Element eElementa = (Element) nNode2; Node objectNode = eElementa.getElementsByTagName("object").item(0); Element objectElement = (Element) objectNode; String inReplyTo = objectElement.getElementsByTagName("inReplyTo").item(0).getTextContent(); String commentID = objectElement.getElementsByTagName("id").item(0).getTextContent(); String commentContent = objectElement.getElementsByTagName("content").item(0).getTextContent(); try { String query = "SELECT message FROM bm_table WHERE msgid='" + id + "'"; ResultSet dbq = db.query(query); Object o = null; for (; dbq.next(); ) { o = dbq.getObject(1); String message = o.toString(); try { DocumentBuilderFactory dbFactory2 = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder2 = dbFactory2.newDocumentBuilder(); Document doc2 = dBuilder2.parse(new ByteArrayInputStream(message.getBytes())); doc2.getDocumentElement().normalize(); NodeList nList2 = doc2.getElementsByTagName("activity"); for (int temp2 = 0; temp2 < nList2.getLength(); temp2++) { Node nNode2 = nList2.item(temp2); if (nNode2.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode2; NodeList objectNodeList = eElement.getElementsByTagName("object"); for (int temp3 = 0; temp3 < objectNodeList.getLength(); temp3++) { Node objectCNode = objectNodeList.item(temp3); if (objectCNode.getNodeType() == Node.ELEMENT_NODE) { Element cElement = (Element) objectCNode; if (id.equals(inReplyTo)) { System.out.println("Object in reply to found"); NodeList objectCNodeList = cElement.getElementsByTagName("comments"); if (objectCNodeList.getLength() == 0) { Element comments = doc2.createElement("comments"); Element commentcount = doc2.createElement("totalItems"); commentcount.appendChild(doc2.createTextNode("0")); Element commentItems = doc2.createElement("items"); comments.appendChild(commentcount); comments.appendChild(commentItems); objectCNode.appendChild(comments); } Node commentsN = cElement.getElementsByTagName("comments").item(0); Element commentsE = (Element) commentsN; Node commentCountN = commentsE.getElementsByTagName("totalItems").item(0); Element commentCountE = (Element) commentCountN; Node commentItemsN = commentsE.getElementsByTagName("items").item(0); Element commentItemsE = (Element) commentItemsN; NodeList commentItemL = commentItemsE.getChildNodes(); int found = 0; for (int itemno = 0; itemno < commentItemL.getLength(); itemno++) { Node itemN = commentItemL.item(itemno); Element itemE = (Element) itemN; NodeList itemNL = itemE.getChildNodes(); for (int itemno2 = 0; itemno2 < itemNL.getLength(); itemno2++) { Node cnode = itemNL.item(itemno2); if (cnode.getNodeName().equals("id")) { String itemid = itemNL.item(itemno2).getTextContent(); if (itemid.equals(commentID)) { found++; } } } } if (found > 0) { System.out.println("Comment has been previously processed"); processed = true; } if (!processed) { System.out.println("Comment has not been previously processed"); int commentCount = Integer.parseInt(commentsE.getElementsByTagName("totalItems").item(0).getTextContent()); commentCount = commentCount + 1; commentCountN.setTextContent(Integer.toString(commentCount)); Element commentItem = doc2.createElement("item"); Element actorItem = doc2.createElement("actor"); Element objectTypeItem = doc2.createElement("objectType"); objectTypeItem.appendChild(doc2.createTextNode("person")); Element actorIdItem = doc2.createElement("id"); actorIdItem.appendChild(doc2.createTextNode(fromAddress)); actorItem.appendChild(objectTypeItem); actorItem.appendChild(actorIdItem); Element idItem = doc2.createElement("id"); idItem.appendChild(doc2.createTextNode(commentID)); Element inReplyToItem = doc2.createElement("inReplyTo"); inReplyToItem.appendChild(doc2.createTextNode(inReplyTo)); Element contentItem = doc2.createElement("content"); contentItem.appendChild(doc2.createTextNode(commentContent)); commentItem.appendChild(actorItem); commentItem.appendChild(idItem); commentItem.appendChild(inReplyToItem); commentItem.appendChild(contentItem); commentItemsE.appendChild(commentItem); bmasAddresses bmasaddresses = new bmasAddresses(); String useraddress = bmasaddresses.getUser(); if ((!useraddress.equals(fromAddress)) && (useraddress.equals(postactor))) { try { String msg = fromAddress + " commented on your post"; String INSERT_RECORD = "INSERT INTO bm_alerts(msgid,message,dtstamp) VALUES(?,?,?)"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, id); pstmt.setString(2, msg); java.sql.Timestamp sqlDate = new java.sql.Timestamp(receivedTime*1000L); pstmt.setTimestamp(3, sqlDate); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } } processed = true; } } else { NodeList commentsNL = cElement.getElementsByTagName("comments"); if (commentsNL.getLength() > 0) { Node commentsN = cElement.getElementsByTagName("comments").item(0); Element commentsE = (Element) commentsN; Node commentCountN = commentsE.getElementsByTagName("totalItems").item(0); Element commentCountE = (Element) commentCountN; Node commentItemsN = commentsE.getElementsByTagName("items").item(0); Element commentItemsE = (Element) commentItemsN; NodeList commentItemL = commentItemsE.getChildNodes(); for (int itemno = 0; itemno < commentItemL.getLength() && !processed; itemno++) { Node itemo = commentItemL.item(itemno); processed = processComment(processed, itemo, doc2, commentID, inReplyTo, commentContent, id); } } } } } } } TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); // transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); // transformer.setOutputProperty(OutputKeys.CDATA-SECTION-ELEMENTS, "content"); StringWriter writer = new StringWriter(); transformer.transform(new DOMSource(doc2), new StreamResult(writer)); String output = writer.getBuffer().toString(); try { String INSERT_RECORD = "UPDATE bm_table SET message=? WHERE msgid=?"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, output); pstmt.setString(2, id); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } } db.st.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } } if (verb.equals("like")) { System.out.println("Processing Like"); Element eElementa = (Element) nNode2; Node objectNode = eElementa.getElementsByTagName("object").item(0); Element objectElement = (Element) objectNode; String inReplyTo = objectElement.getElementsByTagName("inReplyTo").item(0).getTextContent(); String likeID = objectElement.getElementsByTagName("id").item(0).getTextContent(); try { String query = "SELECT message FROM bm_table WHERE msgid='" + id + "'"; ResultSet dbq = db.query(query); Object o = null; for (; dbq.next(); ) { o = dbq.getObject(1); String message = o.toString(); try { DocumentBuilderFactory dbFactory2 = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder2 = dbFactory2.newDocumentBuilder(); Document doc2 = dBuilder2.parse(new ByteArrayInputStream(message.getBytes())); doc2.getDocumentElement().normalize(); NodeList nList2 = doc2.getElementsByTagName("activity"); String totalItems = ""; String item = ""; for (int temp2 = 0; temp2 < nList2.getLength(); temp2++) { Node nNode2 = nList2.item(temp2); if (nNode2.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode2; NodeList objectNodeList = eElement.getElementsByTagName("object"); for (int temp3 = 0; temp3 < objectNodeList.getLength(); temp3++) { Node objectCNode = objectNodeList.item(temp3); if (objectCNode.getNodeType() == Node.ELEMENT_NODE) { Element cElement = (Element) objectCNode; if (id.equals(inReplyTo)) { System.out.println("Object in reply to found"); NodeList objectCNodeList = cElement.getElementsByTagName("likes"); if (objectCNodeList.getLength() == 0) { Element likes = doc2.createElement("likes"); Element likecount = doc2.createElement("totalItems"); likecount.appendChild(doc2.createTextNode("0")); Element likeItems = doc2.createElement("items"); likes.appendChild(likecount); likes.appendChild(likeItems); objectCNode.appendChild(likes); } Node likesN = cElement.getElementsByTagName("likes").item(0); Element likesE = (Element) likesN; Node likeCountN = likesE.getElementsByTagName("totalItems").item(0); Element likeCountE = (Element) likeCountN; Node likeItemsN = likesE.getElementsByTagName("items").item(0); Element likeItemsE = (Element) likeItemsN; NodeList likeItemL = likeItemsE.getChildNodes(); int found = 0; for (int temp4 = 0; temp4 < likeItemL.getLength(); temp4++) { Node itemN = likeItemL.item(temp4); Element itemE = (Element) itemN; Node actorN = itemE.getElementsByTagName("actor").item(0); Element actorE = (Element) actorN; String liker = actorE.getElementsByTagName("id").item(0).getTextContent(); System.out.println("Previous liker " + liker + " comparing to " + fromAddress); if (liker.equals(fromAddress)) { System.out.println("Liked by Address previously"); found++; } NodeList itemNL = itemE.getChildNodes(); for (int itemno2 = 0; itemno2 < itemNL.getLength(); itemno2++) { Node cnode = itemNL.item(itemno2); if (cnode.getNodeName().equals("id")) { String itemid = itemNL.item(itemno2).getTextContent(); System.out.println("Previous itemid " + itemid + " comparing to " + likeID); if (itemid.equals(likeID)) { System.out.println("Previously processed itemid " + itemid); found++; } } } } if (found > 0) { System.out.println("Like has been previously processed"); processed = true; } if (found == 0) { System.out.println("Like has not been previously processed"); int likeCount = Integer.parseInt(likesE.getElementsByTagName("totalItems").item(0).getTextContent()); likeCount = likeCount + 1; likeCountN.setTextContent(Integer.toString(likeCount)); Element likeItem = doc2.createElement("item"); Element actorItem = doc2.createElement("actor"); Element objectTypeItem = doc2.createElement("objectType"); objectTypeItem.appendChild(doc2.createTextNode("person")); Element actorIdItem = doc2.createElement("id"); actorIdItem.appendChild(doc2.createTextNode(fromAddress)); actorItem.appendChild(objectTypeItem); actorItem.appendChild(actorIdItem); Element idItem = doc2.createElement("id"); idItem.appendChild(doc2.createTextNode(likeID)); Element inReplyToItem = doc2.createElement("inReplyTo"); inReplyToItem.appendChild(doc2.createTextNode(inReplyTo)); likeItem.appendChild(actorItem); likeItem.appendChild(idItem); likeItem.appendChild(inReplyToItem); likeItemsE.appendChild(likeItem); bmasAddresses bmasaddresses = new bmasAddresses(); String useraddress = bmasaddresses.getUser(); if ((!useraddress.equals(fromAddress)) && (useraddress.equals(postactor))) { try { String msg = fromAddress + " liked your post"; String INSERT_RECORD = "INSERT INTO bm_alerts(msgid,message,dtstamp) VALUES(?,?,?)"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, id); pstmt.setString(2, msg); java.sql.Timestamp sqlDate = new java.sql.Timestamp(receivedTime*1000L); pstmt.setTimestamp(3, sqlDate); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } } processed = true; } } else { NodeList objectCNodeList = cElement.getElementsByTagName("comments"); if (objectCNodeList.getLength() != 0) { Node commentsN = cElement.getElementsByTagName("comments").item(0); Element commentsE = (Element) commentsN; Node commentCountN = commentsE.getElementsByTagName("totalItems").item(0); Element commentCountE = (Element) commentCountN; Node commentItemsN = commentsE.getElementsByTagName("items").item(0); Element commentItemsE = (Element) commentItemsN; NodeList commentItemL = commentItemsE.getChildNodes(); for (int z = 0; z 0) { System.out.println("Comment has been previously processed"); processed = true; } if (!processed) { System.out.println("Comment has not been previously processed"); int commentCount = Integer.parseInt(commentsE.getElementsByTagName("totalItems").item(0).getTextContent()); commentCount = commentCount + 1; commentCountN.setTextContent(Integer.toString(commentCount)); Element commentItem = doc2.createElement("item"); Element actorItem = doc2.createElement("actor"); Element objectTypeItem = doc2.createElement("objectType"); objectTypeItem.appendChild(doc2.createTextNode("person")); Element actorIdItem = doc2.createElement("id"); actorIdItem.appendChild(doc2.createTextNode(fromAddress)); actorItem.appendChild(objectTypeItem); actorItem.appendChild(actorIdItem); Element idItem = doc2.createElement("id"); idItem.appendChild(doc2.createTextNode(commentID)); Element inReplyToItem = doc2.createElement("inReplyTo"); inReplyToItem.appendChild(doc2.createTextNode(inReplyTo)); Element contentItem = doc2.createElement("content"); contentItem.appendChild(doc2.createTextNode(commentContent)); commentItem.appendChild(actorItem); commentItem.appendChild(idItem); commentItem.appendChild(inReplyToItem); commentItem.appendChild(contentItem); commentItemsE.appendChild(commentItem); bmasAddresses bmasaddresses = new bmasAddresses(); String useraddress = bmasaddresses.getUser(); if ((!useraddress.equals(fromAddress)) && (useraddress.equals(postactor))) { try { String msg = fromAddress + " commented on your comment"; String INSERT_RECORD = "INSERT INTO bm_alerts(msgid,message,dtstamp) VALUES(?,?,?)"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, msgid); pstmt.setString(2, msg); java.sql.Timestamp sqlDate = new java.sql.Timestamp(receivedTime*1000L); pstmt.setTimestamp(3, sqlDate); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } } processed = true; } } else { NodeList commentsNL = cElement.getElementsByTagName("comments"); if (commentsNL.getLength() > 0) { Node commentsN = cElement.getElementsByTagName("comments").item(0); Element commentsE = (Element) commentsN; Node commentCountN = commentsE.getElementsByTagName("totalItems").item(0); Element commentCountE = (Element) commentCountN; Node commentItemsN = commentsE.getElementsByTagName("items").item(0); Element commentItemsE = (Element) commentItemsN; NodeList commentItemL = commentItemsE.getChildNodes(); for (int itemno = 0; itemno < commentItemL.getLength() && !processed; itemno++) { Node itemo = commentItemL.item(itemno); Boolean processedo = processComment(processed, itemo, doc2, commentID, inReplyTo, commentContent, msgid); processed = processedo; } } } return processed; } public Boolean processLike(Boolean processed, Node objectCNode, Document doc2, String likeID, String inReplyTo, String msgid) { String id = ""; NodeList objectCNodeNL = objectCNode.getChildNodes(); for (int i = 0; i 0) { System.out.println("Like has been previously processed"); processed = true; } if (found == 0) { System.out.println("Like has not been previously processed"); int likeCount = Integer.parseInt(likesE.getElementsByTagName("totalItems").item(0).getTextContent()); likeCount = likeCount + 1; likeCountN.setTextContent(Integer.toString(likeCount)); Element likeItem = doc2.createElement("item"); Element actorItem = doc2.createElement("actor"); Element objectTypeItem = doc2.createElement("objectType"); objectTypeItem.appendChild(doc2.createTextNode("person")); Element actorIdItem = doc2.createElement("id"); actorIdItem.appendChild(doc2.createTextNode(fromAddress)); actorItem.appendChild(objectTypeItem); actorItem.appendChild(actorIdItem); Element idItem = doc2.createElement("id"); idItem.appendChild(doc2.createTextNode(likeID)); Element inReplyToItem = doc2.createElement("inReplyTo"); inReplyToItem.appendChild(doc2.createTextNode(inReplyTo)); likeItem.appendChild(actorItem); likeItem.appendChild(idItem); likeItem.appendChild(inReplyToItem); likeItemsE.appendChild(likeItem); bmasAddresses bmasaddresses = new bmasAddresses(); String useraddress = bmasaddresses.getUser(); if ((!useraddress.equals(fromAddress)) && (useraddress.equals(postactor))) { try { String msg = fromAddress + " liked your comment"; String INSERT_RECORD = "INSERT INTO bm_alerts(msgid,message,dtstamp) VALUES(?,?,?)"; PreparedStatement pstmt = db.conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, msgid); pstmt.setString(2, msg); java.sql.Timestamp sqlDate = new java.sql.Timestamp(receivedTime*1000L); pstmt.setTimestamp(3, sqlDate); int i = pstmt.executeUpdate(); if (i == -1) { System.out.println("db error : " ); } pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } } processed = true; } } else { NodeList objectCNodeList = cElement.getElementsByTagName("comments"); if (objectCNodeList.getLength() != 0) { Node commentsN = cElement.getElementsByTagName("comments").item(0); Element commentsE = (Element) commentsN; Node commentCountN = commentsE.getElementsByTagName("totalItems").item(0); Element commentCountE = (Element) commentCountN; Node commentItemsN = commentsE.getElementsByTagName("items").item(0); Element commentItemsE = (Element) commentItemsN; NodeList commentItemL = commentItemsE.getChildNodes(); for (int z = 0; z=0;i--)" + " { selectbox.remove(i);" + " }" + "}" + "function addOption(selectbox, value, text )" + "{ var optn = document.createElement('OPTION');" + " optn.text = text;" + " optn.value = value;" + " selectbox.options.add(optn);" + "}" + "function move(tbFrom, tbTo)" + "{ var arrFrom = new Array();" + " var arrTo = new Array();" + " var arrLU = new Array();" + "if(document.share.followers.value == 'Public')" + "{" + " if (tbFrom.id != 'To')" + " {" + " var zz; for (zz = 0; zz< tbFrom.options.length; zz++)" + " {" + " if (tbFrom.options[zz].selected && tbFrom.options[zz].value== 'Anonymous')" + " {" + " removeAllOptions(document.share.To);" + " removeAllOptions(document.share.FromLB);" + " addOption(document.share.FromLB,'Signed', 'Signed');" + " addOption(document.share.To,'Anonymous', 'Anonymous');" + " }" + " if (tbFrom.options[zz].selected && tbFrom.options[zz].value == 'Signed')" + " {" + " removeAllOptions(document.share.To);" + " removeAllOptions(document.share.FromLB);" + " addOption(document.share.FromLB,'Anonymous', 'Anonymous');" + " addOption(document.share.To,'Signed', 'Signed');" + " }" + " }" + " }" + "}" + " var i; for (i = 0; i < tbTo.options.length; i++)" + " { arrLU[tbTo.options[i].text] = tbTo.options[i].value;" + " arrTo[i] = tbTo.options[i].text;" + " }" + " var fLength = 0;" + " var tLength = arrTo.length;" + " for(i = 0; i < tbFrom.options.length; i++)" + " { arrLU[tbFrom.options[i].text] = tbFrom.options[i].value;" + " if (tbFrom.options[i].selected && tbFrom.options[i].value != '')" + " { arrTo[tLength] = tbFrom.options[i].text;" + " tLength++;" + " } else {" + " arrFrom[fLength] = tbFrom.options[i].text;" + " fLength++;" + " }" + "}" + "tbFrom.length = 0;" + "tbTo.length = 0;" + "var ii;" + "for(ii = 0; ii < arrFrom.length; ii++)" + " { var no = new Option();" + " no.value = arrLU[arrFrom[ii]];" + " no.text = arrFrom[ii];" + " tbFrom[ii] = no;" + "}" + " for(ii = 0; ii < arrTo.length; ii++)" + " { var no = new Option();" + " no.value = arrLU[arrTo[ii]];" + " no.text = arrTo[ii];" + " tbTo[ii] = no;" + "}" + "}" + "var loadImageFile = (function () {" + " if (window.FileReader) {" + " var oPreviewImg = null, oFReader = new window.FileReader()," + " rFilter = /^(?:image\\/" + "bmp|image\\" + "/cis\\-cod|image\\" + "/gif|image\\" + "/ief|image\\" + "/jpeg|image\\/" + "jpeg|image\\/" + "jpeg|image\\/" + "pipeg|image\\/" + "png|" + "image\\/" + "svg\\+xml|image\\/" + "tiff|image\\/" + "x\\-cmu\\-raster|image\\/" + "x\\-cmx|image\\/" + "x\\-icon|image\\/" + "x\\-portable\\-anymap|image\\/" + "x\\-portable\\-bitmap|image" + "\\/" + "x\\-portable\\-graymap|image\\/" + "x\\-portable\\-pixmap|image\\/" + "x\\-rgb|image\\/" + "x\\-xbitmap|image\\/" + "x\\-xpixmap|image\\/" + "x\\-xwindowdump)$/" + "i;" + " oFReader.onload = function (oFREvent) {" + " if (!oPreviewImg) {" + " var newPreview = document.getElementById('imagePreview');" + " oPreviewImg = new Image();" + " oPreviewImg.style.visibility = \"visible\";" + " newPreview.appendChild(oPreviewImg);" + " }" + " oPreviewImg.src = oFREvent.target.result; }; return function () { var aFiles = document.getElementById('imagefile').files; if (aFiles.length === 0) { return; } if (!rFilter.test(aFiles[0].type)) { alert('You must select a valid image file!'); return; } oFReader.readAsDataURL(aFiles[0]); } } if (navigator.appName === 'Microsoft Internet Explorer') { return function () { document.getElementById('imagePreview').filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = document.getElementById('imagefile').value; } }})();" + " function unloadImageFile(){" + " var list=document.getElementById('imagePreview');" + " list.removeChild(list.childNodes[0]);" + " }" + ""; return startDoc; } } static class NAVBar { public NAVBar() { } public String getNAVBar() { int mcount = 0; ResultSet rs = null; java.sql.Timestamp msgdtstamp = new java.sql.Timestamp(new java.util.Date().getTime()); String tsql = "SELECT dtstamp FROM bm_lastclick WHERE wpage=?"; try { PreparedStatement pstmt = db.conn.prepareStatement(tsql); pstmt.setString(1, "MESSAGES"); rs = pstmt.executeQuery(); rs.next(); msgdtstamp = rs.getTimestamp(1); // System.out.println("msgdtstamp " + msgdtstamp); pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } // System.out.println("nav query 1"); String csql = "SELECT COUNT(*) AS rowcount FROM bm_mail WHERE read=? and dtstamp>?"; try { PreparedStatement pstmt = db.conn.prepareStatement(csql); pstmt.setBoolean(1, false); pstmt.setTimestamp(2, msgdtstamp); rs = pstmt.executeQuery(); rs.next(); mcount = rs.getInt(1); // System.out.println("mcount " + mcount); pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } // System.out.println("nav query 2"); String msgclass = "norm"; if (mcount > 0) { msgclass = "red"; } String startDoc =""; return startDoc; } } static class MainStart { public MainStart() { } public String getMainStart() { String startDoc ="
"; return startDoc; } } static class MainLeftMenu { public MainLeftMenu() { } public String getMainLeftMenu() { String startDoc ="
News
"; return startDoc; } } static class MailLeftMenu { ActivityStreamdb db = null; public MailLeftMenu(ActivityStreamdb db) { this.db = db; } public String getMailLeftMenu() { String startDoc ="
"; startDoc = startDoc + "New Message

"; try { int count = 0; ResultSet dbq = db.query("SELECT folder FROM bm_mail_folders"); Object o = null; for (; dbq.next(); ) { o = dbq.getObject(1); String folder = o.toString(); String csql = "SELECT COUNT(*) AS rowcount FROM bm_mail WHERE folder=? AND read=?"; try { PreparedStatement pstmt = db.conn.prepareStatement(csql); pstmt.setString(1, folder); pstmt.setBoolean(2, false); ResultSet rs = pstmt.executeQuery(); rs.next(); count = rs.getInt(1); // System.out.println(count); pstmt.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } startDoc = startDoc + "" + folder; if (count > 0) { startDoc = startDoc + " (" + count + ")"; } startDoc = startDoc + "
"; } db.st.close(); } catch (SQLException ex3) { ex3.printStackTrace(); } startDoc = startDoc + "
"; startDoc = startDoc + "
"; startDoc = startDoc + ""; startDoc = startDoc + ""; startDoc = startDoc + ""; return startDoc; } } static class ProfilesLeftMenu { ActivityStreamdb db = null; public ProfilesLeftMenu(ActivityStreamdb db) { this.db = db; } public String getProfilesLeftMenu() { String startDoc ="
"; startDoc = startDoc + "Followers
"; startDoc = startDoc + "Following
"; startDoc = startDoc + "Follower Lists
"; startDoc = startDoc + "Mail Contacts
"; return startDoc; } } static class SettingsLeftMenu { public SettingsLeftMenu() { } public String getSettingsLeftMenu() { String startDoc ="
BM API Settings
"; startDoc = startDoc + "Hashtags
"; return startDoc; } } static class NewsPostForm { public NewsPostForm() { } public String getNewsPostForm() { String startDoc ="
Share something:

with:


"; return startDoc; } } static class EndDiv { public EndDiv() { } public String getEndDiv() { String startDoc =""; return startDoc; } } static class EndBody { public EndBody() { } public String getEndBody() { String startDoc =""; return startDoc; } } static class base64processor { public base64processor() { } public String toString(byte[] input) { byte[] b = Base64.encodeBase64(input); String c = ""; try { c = new String(b, "UTF-8"); } catch (Exception e) { e.printStackTrace(); } return c; } } static class stream2File { public stream2File() { } public File getstream2file(InputStream in) throws IOException { String PREFIX = "stream2file"; String SUFFIX = ".tmp"; File tempFile = File.createTempFile(PREFIX, SUFFIX); tempFile.deleteOnExit(); try (FileOutputStream out = new FileOutputStream(tempFile)) { IOUtils.copy(in, out); } return tempFile; } } static class ActivityStreamdb { Connection conn; Statement st; ResultSet rs; public ActivityStreamdb(String db_file_name_prefix) throws Exception { Class.forName("org.hsqldb.jdbcDriver"); conn = DriverManager.getConnection("jdbc:hsqldb:" + db_file_name_prefix, "sa", ""); } public void shutdown() throws SQLException { Statement st = conn.createStatement(); st.execute("SHUTDOWN"); conn.close(); } public synchronized ResultSet query(String expression) throws SQLException { ResultSet rs = null; st = conn.createStatement(); rs = st.executeQuery(expression); return rs; } public synchronized void update(String expression) throws SQLException { Statement st = null; st = conn.createStatement(); int i = st.executeUpdate(expression); if (i == -1) { System.out.println("db error : " + expression); } st.close(); } public static String dump(ResultSet rs) throws SQLException { ResultSetMetaData meta = rs.getMetaData(); int colmax = meta.getColumnCount(); int i; Object o = null; String blah = ""; for (; rs.next(); ) { for (i = 0; i < colmax; ++i) { o = rs.getObject(i + 1); // Is SQL the first column is indexed String meh = o.toString(); byte[] decoded = Base64.decodeBase64(meh); String meh2 = null; try { meh2 = new String(decoded, "UTF-8"); } catch (Exception e) { e.printStackTrace(); } blah = blah + meh2; } } return blah; } } static class KeyFinder implements ContentHandler{ private Object value; private boolean found = false; private boolean end = false; private String key; private String matchKey; public void setMatchKey(String matchKey){ this.matchKey = matchKey; } public Object getValue(){ return value; } public boolean isEnd(){ return end; } public void setFound(boolean found){ this.found = found; } public boolean isFound(){ return found; } public void startJSON() throws ParseException, IOException { found = false; end = false; } public void endJSON() throws ParseException, IOException { end = true; } public boolean primitive(Object value) throws ParseException, IOException { if(key != null){ if(key.equals(matchKey)){ found = true; this.value = value; key = null; return false; } } return true; } public boolean startArray() throws ParseException, IOException { return true; } public boolean startObject() throws ParseException, IOException { return true; } public boolean startObjectEntry(String key) throws ParseException, IOException { this.key = key; return true; } public boolean endArray() throws ParseException, IOException { return false; } public boolean endObject() throws ParseException, IOException { return true; } public boolean endObjectEntry() throws ParseException, IOException { return true; } } public static class FormdataMultipart extends MimeMultipart { //logging //instance attributes private Hashtable m_Params = new Hashtable(); private boolean m_Removed = false; /** * Constructs a FormdataMultipart instance.
* This implementation just calls the superclass constructor. * * @return the newly created FormdataMultipart instance. */ public FormdataMultipart() { super(); }//constructor /** * Constructs a FormdataMultipart instance.
* Automatically processes the body parts to extract parameters, * and attachments. * * @param DataSource to construct the Multipart from, will be a * MultipartInputStream. * * @return the newly created FormdataMultipart instance. */ public FormdataMultipart(DataSource ds) throws MessagingException, IOException { super(ds); processBodyParts(); updateHeaders(); //System.out.println("Created"); }//constructor /** * Returns the extracted parameters (with the extrcted values) * as Hashtable. * * @return the extracted parameter data as Hashtable */ public Hashtable getParameters() { return m_Params; }//getParameters /** * Processes the body parts of the form-data. * Extracts parameters and set values, and * leaves over the attachments. * * @throws IOException if i/o operations fail. * @throws MessagingException if parsing or part handling with * Mail API classes fails. */ public void processBodyParts() throws IOException, MessagingException { //if write out to log for debug reasons! //ByteArrayOutputStream bout=new ByteArrayOutputStream(); //writeTo(bout); //JwmaKernel.getReference().debugLog().write(bout.toString()); //System.out.println("Count : " + getCount()); for (int i = 0; i < getCount(); i++) { // System.out.println("Count : " + getCount() + " " + i); MimeBodyPart mbp = (MimeBodyPart) getBodyPart(i); processBodyPart(mbp); if (m_Removed) { m_Removed = false; //decrease index i approbiately i--; } } setSubType("mixed"); //JwmaKernel.getReference().debugLog().write( // "Processed multipart/form-data. Attachment parts:"+getCount() //); }//processParts /** * Processes a body part of the form-data. * Extracts parameters and set values, and * leaves over the attachments. * * @param mbp the MimeBodyPart to be processed. * * @throws IOException if i/o operations fail. * @throws MessagingException if parsing or part handling with * Mail API classes fails. */ private void processBodyPart(MimeBodyPart mbp) throws MessagingException, IOException { //String contenttype=new String(mbp.getContentType()); //JwmaKernel.getReference().debugLog().write("Processing "+contenttype); //check if a content-type is given String[] cts = mbp.getHeader("Content-Type"); if (cts == null || cts.length == 0) { //this is a parameter, get it out and //remove the part. String controlname = extractName( (mbp.getHeader("Content-Disposition"))[0]); // System.out.println("Processing control: "+controlname); //retrieve value observing encoding InputStream in = mbp.getInputStream(); String[] encoding = mbp.getHeader("Content-Transfer-Encoding"); if (encoding != null && encoding.length > 0) { in = MimeUtility.decode(in, encoding[0]); } String value = extractValue(in); if (value != null || !value.trim().equals("")) { addParameter(controlname, value); } //flag removal m_Removed = true; removeBodyPart(mbp); } else { String filename = extractFileName( (mbp.getHeader("Content-Disposition"))[0]); //normally without file the control should be not successful. //but neither netscape nor mircosoft iexploder care much. //the only feature is an empty filename. if (filename.equals("")) { //kick it out too m_Removed = true; removeBodyPart(mbp); } else { //JwmaKernel.getReference().debugLog().write("Incoming filename="+filename); //IExploder sends files with complete path. //jwma doesnt want this. int lastindex = filename.lastIndexOf("\\"); if (lastindex != -1) { filename = filename.substring(lastindex + 1, filename.length()); } //JwmaKernel.getReference().debugLog().write("Outgoing filename="+filename); //Observe a possible encoding InputStream in = mbp.getInputStream(); String[] encoding = mbp.getHeader("Content-Transfer-Encoding"); if (encoding != null && encoding.length > 0) { in = MimeUtility.decode(in, encoding[0]); } ByteArrayOutputStream bout = new ByteArrayOutputStream(); OutputStream out = (OutputStream) bout; int i = 0; while ((i = in.read()) != -1) { //maybe more efficient in buffers, but well out.write(i); } out.flush(); out.close(); //create the datasource MimeBodyPartDataSource mbpds = new MimeBodyPartDataSource( // contenttype,filename,bout.toByteArray() cts[0], filename, bout.toByteArray() ); //Re-set the Content-Disposition header, in case //the file name was changed mbp.removeHeader("Content-Disposition"); mbp.addHeader( "Content-Disposition", "attachment; filename=\"" + filename + "\"" ); //set a base64 transferencoding und the data handler mbp.addHeader("Content-Transfer-Encoding", "base64"); mbp.setDataHandler(new DataHandler(mbpds)); } } }//processBodyPart /** * Returns the name of a parameter by extracting it * from the content-disposition header line. * * @param disposition the content-disposition header line as * String. * * @return the name of the parameter as String. * * @throws IOException if the header line is malformed. */ private String extractName(String disposition) throws IOException { int end = 0; int start = -1; start = disposition.indexOf("name=\""); end = disposition.indexOf("\"", start + 7); //offset is to skip name=\" if (start == -1 || end == -1) { throw new IOException("Mime header malformed."); } return disposition.substring(start + 6, end); }//extractName /** * Returns the filename of an attachment by extracting it * from the content-disposition header line. * * @param disposition the content-disposition header line as * String. * * @return the filename of the attachment as String. * * @throws IOException if the header line is malformed. */ private String extractFileName(String disposition) throws IOException { int end = 0; int start = -1; start = disposition.indexOf("filename=\""); end = disposition.indexOf("\"", start + 10); //offset is to skip filename=\" if (start == -1 || end == -1) { throw new IOException("Mime header malformed."); } return disposition.substring(start + 10, end); }//extractFileName /** * Returns the value of a parameter by extracting it * from the InputStream that represents the content * of the (parameter) part. * * @param in InputStream that reads from the content * of the (parameter) part. * * @return the value of the parameter as String. * * @throws IOException if reading from the stream fails. */ private String extractValue(InputStream in) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); int i = 0; while ((i = in.read()) != -1) { out.write(i); } out.flush(); out.close(); in.close(); //JwmaKernel.getReference().debugLog().write("Retrieved value="+out.toString()); //apply a little bit of magic when returning return out.toString("iso-8859-1"); }//extractValue /** * Adds a parameter and mapped value to the parameters collection. * If the parameter already exists, it adds another value to * an already existing parameter by extending the array of strings. * * @param name the name of the parameter as String. * @param value the value of the parameter as String. */ private void addParameter(String name, String value) { String values[]; //JwmaKernel.getReference().debugLog().write("Adding "+name+"="+value); if (m_Params.containsKey(name)) { String oldValues[] = (String[]) m_Params.get(name); values = new String[oldValues.length + 1]; for (int i = 0; i < oldValues.length; i++) { values[i] = oldValues[i]; } values[oldValues.length] = value; } else { values = new String[1]; values[0] = value; } m_Params.put(name, values); }//addParameter }//FormdataMultipart public static class MimeBodyPartDataSource implements DataSource { private String m_Type; private String m_Name; private byte[] m_Data; public MimeBodyPartDataSource(String type, String name, byte[] data) { m_Type = type; m_Name = name; m_Data = data; }//constructore public String getContentType() { return m_Type; }//getContentTyp public String getName() { return m_Name; }//getName public InputStream getInputStream() throws IOException { return new ByteArrayInputStream(m_Data); }//getInputStream public OutputStream getOutputStream() throws IOException { throw new IOException("Not supported."); }//getOutputStream }//class MimeBodyPartDataSource public static class ParameterFilter extends Filter { @Override public String description() { return "Parses the requested URI for parameters"; } @Override public void doFilter(HttpExchange exchange, Chain chain) throws IOException { parseGetParameters(exchange); // parsePostParameters(exchange); chain.doFilter(exchange); } private void parseGetParameters(HttpExchange exchange) throws UnsupportedEncodingException { Map parameters = new HashMap(); URI requestedUri = exchange.getRequestURI(); String query = requestedUri.getRawQuery(); parseQuery(query, parameters); exchange.setAttribute("parameters", parameters); } private void parsePostParameters(HttpExchange exchange) throws IOException { if ("post".equalsIgnoreCase(exchange.getRequestMethod())) { @SuppressWarnings("unchecked") Map parameters = (Map)exchange.getAttribute("parameters"); InputStreamReader isr = new InputStreamReader(exchange.getRequestBody(),"utf-8"); BufferedReader br = new BufferedReader(isr); String query = br.readLine(); parseQuery(query, parameters); } } @SuppressWarnings("unchecked") private void parseQuery(String query, Map parameters) throws UnsupportedEncodingException { if (query != null) { String pairs[] = query.split("[&]"); for (String pair : pairs) { String param[] = pair.split("[=]"); String key = null; String value = null; if (param.length > 0) { key = URLDecoder.decode(param[0], System.getProperty("file.encoding")); } if (param.length > 1) { value = URLDecoder.decode(param[1], System.getProperty("file.encoding")); } if (parameters.containsKey(key)) { Object obj = parameters.get(key); if(obj instanceof List) { List values = (List)obj; values.add(value); } else if(obj instanceof String) { List values = new ArrayList(); values.add((String)obj); values.add(value); parameters.put(key, values); } } else { parameters.put(key, value); } } } } } }