public void toFile(String file) { try { PrintStream ps = new PrintStream(new FileOutputStream(file), true); ps.print(sw.toString()); } catch (Exception e) { System.err.println(e.toString()); } }
public P6SpyDriver3() throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException { super(P6SpyDriver3.class.getName(), new P6CoreFactory()); Throwable t = new Throwable(); StringWriter sw = new StringWriter(); t.printStackTrace(new PrintWriter(sw)); P6LogQuery.debug("new spy driver: " + sw.toString()); }
/** * Called to invoke the stored procedure. Will only be called a single time per instance. Can * throw CustomProcedureException or SQLException if there is an error during invoke. */ public void invoke(Object[] inputValues) throws CustomProcedureException, SQLException { String arg1 = (inputValues[0] != null ? ((String) inputValues[0]).toString() : ""); Tidy tidy = new Tidy(); tidy.setXmlOut(true); tidy.setShowErrors(0); tidy.setQuiet(true); tidy.setShowWarnings(false); tidy.setDocType("omit"); StringWriter writer = new StringWriter(); tidy.parseDOM(new StringReader(arg1), writer); result = writer.toString(); }
/** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ @SuppressWarnings("unchecked") protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); response.setHeader("Cache-Control", "nocache"); response.setCharacterEncoding("utf-8"); PrintWriter out = response.getWriter(); StringWriter result = new StringWriter(); // get received JSON data from request BufferedReader br = new BufferedReader(new InputStreamReader(request.getInputStream())); String postData = ""; if (br != null) { postData = br.readLine(); } try { JSONObject json = (JSONObject) new JSONParser().parse(postData); JSONObject resultObj = new JSONObject(); JSONArray list = new JSONArray(); List<Tracking> trackingList = new ArrayList<Tracking>(); // get the website list if (json.get("type").equals("websiteslist")) { trackingList = trackingDao.websiteList(pool); for (Tracking item : trackingList) { list.add(item.getWebsite()); } } // render report else if (json.get("type").equals("submit")) { if (json.get("criteria").equals("date")) { // render repoty by date trackingList = trackingDao.getListByDate(pool, json.get("date").toString()); } else if (json.get("criteria").equals("daterange")) { // render repoty by date range trackingList = trackingDao.getListByDateRange( pool, json.get("fromdate").toString(), json.get("todate").toString()); } else if (json.get("criteria").equals("website")) { // render repoty by website String website = (json.get("website") == null ? "" : json.get("website").toString()); trackingList = trackingDao.getListByWebsite(pool, website); } for (Tracking item : trackingList) { JSONObject trackingObj = new JSONObject(); trackingObj.put("date", item.getDate()); trackingObj.put("website", item.getWebsite()); trackingObj.put("visit", item.getVisit()); list.add(trackingObj); } } resultObj.put("result", list); resultObj.writeJSONString(result); // finally output the json string out.print(result.toString()); } catch (ParseException | SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public String getXSAMS() { return sw.toString(); }