List of usage examples for java.io PrintWriter print
public void print(Object obj)
From source file:de.viaboxx.nlstools.formats.BundleWriterFlexClass.java
void writeDoNotAlter(PrintWriter pw) { pw.println("/**");// w w w . j a v a 2 s .com pw.print(" * contains keys of resource bundle "); pw.print(currentBundle.getBaseName()); pw.println('.'); pw.println(" * THIS FILE HAS BEEN GENERATED AUTOMATICALLY - DO NOT ALTER!"); pw.println(" */"); }
From source file:com.grantedbyme.example.ServletAjax.java
public void doProcess(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json; charset=UTF-8"); String operation = request.getParameter("operation"); int challengeType = Integer.valueOf(request.getParameter("challenge_type")); Boolean isSuccess = false;//ww w. ja v a 2 s.c o m JSONObject result = null; JSONObject defaultResult = null; try { defaultResult = (JSONObject) new JSONParser().parse("{\"success\": false, \"error\": 0}"); } catch (Exception e) { e.printStackTrace(); } if (operation != null) { _log(operation); GrantedByMe sdk = ServletUtils.getSDK(this); //sdk.setDebugMode(true); // process operation String challenge = null; if (operation.equals("getChallenge")) { result = sdk.getChallenge(challengeType); } else if (operation.equals("getChallengeState")) { challenge = request.getParameter("challenge"); result = sdk.getChallengeState(challenge); if (challengeType == GrantedByMe.CHALLENGE_AUTHORIZE) { handleGetAccountState(result, challenge, sdk); } else if (challengeType == GrantedByMe.CHALLENGE_AUTHENTICATE) { handleGetSessionState(result); } else if (challengeType == GrantedByMe.CHALLENGE_PROFILE) { handleGetRegisterState(result, challenge, sdk); } } } if (result == null) { result = defaultResult; } PrintWriter out = response.getWriter(); out.print(result.toJSONString()); out.close(); }
From source file:org.busko.routemanager.services.RouteOutlineServiceImpl.java
private void createGtfsTxt(File directory, List gtfsEntities) throws Exception { if (gtfsEntities.isEmpty()) return;// w ww . ja v a 2s . c o m GtfsFormatted gtfsFormatted = (GtfsFormatted) gtfsEntities.get(0); File file = createFile(directory, gtfsFormatted.getGtfsFileName(), null); PrintWriter writer = null; try { writer = new PrintWriter(FileUtils.openOutputStream(file)); writer.print(gtfsFormatted.getGtfsFileHeader()); writer.print("\n"); String testData = NewZealandTestData.getTestData(gtfsFormatted.getGtfsFileName()); if (testData != null) { writer.print(testData); writer.print("\n"); } for (Object object : gtfsEntities) { writer.print(((GtfsFormatted) object).getGtfsData()); writer.print("\n"); } } finally { if (writer != null) { writer.close(); } } }
From source file:it.cilea.osd.jdyna.utils.ClassificationExportUtils.java
/** * Metodo di supporto per esportare un albero classificatorio nella sua * "bean definition". //FIXME valutare la possibilita' di utilizzare il * polimorfismo implementando un'interfaccia IExportableBeanDefinition * /*from w w w. j a va2 s. co m*/ * @param writer * @param albero * l'albero da esportare */ public void alberoClassificatorioToXML(PrintWriter writer, AlberoClassificatorio albero) { writer.print(" <bean id=\"" + AlberoClassificatorio.class.getSimpleName() + albero.getId() + "\" class=\"" + AlberoClassificatorio.class.getCanonicalName() + "\">\n"); writer.print(" <property name=\"nome\" value=\"" + albero.getNome() + "\" />\n"); writer.print(" <property name=\"attiva\" value=\"" + albero.isAttiva() + "\" />\n"); if (albero.getDescrizione() != null) { writer.print(" <property name=\"descrizione\"><value><![CDATA[" + albero.getDescrizione() + "]]></value></property>\n"); } // writer // .print(" <property name=\"classificazioni\">\n" // + " <list>\n"); // for (Classificazione classificazione : albero.getClassificazioni()) { // // considero solo le classificazioni di primo livello // if (classificazione.getPadre() == null) { // toXML(writer, classificazione); // } // } // writer.print(" </list>\n"); // writer.print(" </property>\n"); writer.print(" </bean>\n\n"); writer.print(" <!-- Classificazioni dell'albero:" + albero.getNome() + " -->\n\n"); for (Classificazione classificazione : albero.getTopClassificazioni()) { // considero solo le classificazioni di primo livello if (classificazione.getPadre() == null) { classificazioneToXML(writer, classificazione); } } writer.print(" <!-- FINE Classificazioni dell'albero:" + albero.getNome() + " -->\n\n"); }
From source file:mack.servlets.TransfServlet.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, TransformerException { geraXSL();//from ww w . j a v a2 s . c o m geraXML(); Source xmlSource = new StreamSource("/temp/posicao.xml"); File xslFile = new File("/temp/gpx.xsl"); TransformerFactory transFact = TransformerFactory.newInstance(); Transformer trans = transFact.newTransformer(new StreamSource(xslFile)); ByteArrayOutputStream bos = new ByteArrayOutputStream(); trans.transform(xmlSource, new StreamResult(bos)); PrintWriter w = new PrintWriter("/temp/posicao_proc.gpx", "UTF-8"); w.print(bos); w.close(); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ out.println(new String(bos.toByteArray())); } // response.getWriter().print(bos); // request.getRequestDispatcher("mapaTeste.html").forward(request, response); }
From source file:byps.test.servlet.BypsServlet.java
@Override protected void makeHtmlUploadResult(HttpServletRequest request, HttpServletResponse response, Collection<HFileUploadItem> items) throws IOException { String uploadHandler = request.getParameter("uploadHandler"); if (uploadHandler.equals("htmlform")) { super.makeHtmlUploadResult(request, response, items); } else if (uploadHandler.equals("blueimp")) { // File upload solution from Sebastian Tschan. // see https://github.com/blueimp/jQuery-File-Upload/wiki/Setup String acceptHeader = request.getHeader("Accept"); if (acceptHeader != null && acceptHeader.indexOf("application/json") >= 0) { response.setContentType("application/json"); } else {/*from w w w . j a v a 2 s. co m*/ response.setContentType("text/html"); } PrintWriter wr = response.getWriter(); wr.print("{\"files\":["); boolean first = true; for (HFileUploadItem item : items) { if (first) first = !first; else wr.println(","); wr.print("{"); wr.print("\"name\":\""); wr.print(item.fileName); wr.print("\","); wr.print("\"size\":\""); wr.print(item.contentLength); wr.print("\","); wr.print("\"streamId\":\""); wr.print(item.streamId); wr.print("\""); wr.print("}"); } wr.print("]}"); response.getWriter().close(); } }
From source file:eu.stratosphere.pact.client.web.PactJobJSONServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("application/json"); String jobName = req.getParameter(JOB_PARAM_NAME); if (jobName == null) { LOG.warn("Received request without job parameter name."); resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return;/*www . j ava 2s.com*/ } // check, if the jar exists File jarFile = new File(jobStoreDirectory, jobName); if (!jarFile.exists()) { LOG.warn("Received request for non-existing jar file."); resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } // create the pact plan PactProgram pactProgram; try { pactProgram = new PactProgram(jarFile, new String[0]); } catch (Throwable t) { LOG.info("Instantiating the PactProgram for '" + jarFile.getName() + "' failed.", t); resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); resp.getWriter().print(t.getMessage()); return; } String jsonPlan = null; String programDescription = null; try { jsonPlan = Client.getPreviewAsJSON(pactProgram); } catch (Throwable t) { LOG.error("Failed to create json dump of pact program.", t); } try { programDescription = pactProgram.getDescription(); } catch (Throwable t) { LOG.error("Failed to create description of pact program.", t); } if (jsonPlan == null && programDescription == null) { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } else { resp.setStatus(HttpServletResponse.SC_OK); PrintWriter wrt = resp.getWriter(); wrt.print("{ \"jobname\": \""); wrt.print(jobName); if (jsonPlan != null) { wrt.print("\", \"plan\": "); wrt.println(jsonPlan); } if (programDescription != null) { wrt.print(", \"description\": \""); wrt.print(escapeString(programDescription)); } wrt.print("\""); wrt.println("}"); } }
From source file:org.openmrs.module.hospitalcore.web.controller.patientsearch.PatientSearchController.java
@RequestMapping(value = "/module/hospitalcore/getPatientResultCount.form", method = RequestMethod.POST) public void getPatientResultCount(@RequestParam("query") String query, HttpServletResponse response) throws IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); BigInteger count = Context.getService(HospitalCoreService.class).getPatientSearchResultCount(query); out.print(count); }
From source file:com.sp2p.system.interceptor.FrontUserSeesionInterceptor.java
@Override public String intercept(ActionInvocation invocation) throws Exception { request = ServletActionContext.getRequest(); response = ServletActionContext.getResponse(); session = request.getSession();//from w ww .ja v a 2s .c o m String retUrl = request.getHeader("Referer"); log.info("-------------------" + retUrl); log.info(request.getRequestURL()); int index = request.getContextPath().length() + 1; String uri = request.getRequestURI().substring(index); //? ? if (regisCodeList.contains(uri)) { //ConnectionManager cm = ConnectionManager.getInstance(); //String cmm = cm.getMID(); if (!"MID-22824-47058-95091-87448-87678".equals(IConstants.ZCM)) { response.setCharacterEncoding("UTF-8"); response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); out.print("<script>alert('?,??!');window.history.go(-1);</script>"); return null; } } if (!IConstants.USER_SESSION_SWITCH) { return invocation.invoke(); } if (isAjaxRequest()) { return ajaxIntercept(invocation); } return _intercept(invocation); }
From source file:ob.servlet.getmessage.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* ww w. ja va2s . co m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { outinfo = "fail"; String loginedUserName = (String) request.getSession().getAttribute("username"); if (loginedUserName != null && !loginedUserName.equals("")) { int loginedUserid = (Integer) request.getSession().getAttribute("userid"); po = dao.getinfo(loginedUserid); if (po != null) { if (po.getUsername().equals(loginedUserName)) {//?? FilterProvider filters = new SimpleFilterProvider().addFilter("smsFilter", SimpleBeanPropertyFilter.serializeAllExcept("uid")); outinfo = mapper.writer(filters).writeValueAsString(po.getSms()); } } } response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { /* TODO output your page here. You may use following sample code. */ out.print(outinfo); } finally { out.close(); } }