List of usage examples for java.io PrintWriter write
public void write(String s)
From source file:com.jeans.iservlet.controller.impl.ImportController.java
private void showInfo(PrintWriter out, String message) { out.write("<script>parent.__info('" + message + "');</script>"); out.flush();/*from www . jav a2 s . com*/ }
From source file:seava.j4e.web.controller.data.AbstractDsReadController.java
/** * Returns information about the given resource ( data-source ) * //from ww w . j a v a2 s . c o m * @param resourceName * @param dataFormat * @param request * @param response * @return * @throws Exception */ @RequestMapping(params = Constants.REQUEST_PARAM_ACTION + "=" + Constants.DS_ACTION_INFO) public String info(@PathVariable String resourceName, @PathVariable String dataFormat, HttpServletRequest request, HttpServletResponse response) throws Exception { try { StopWatch stopWatch = new StopWatch(); stopWatch.start(); if (logger.isInfoEnabled()) { logger.info("Processing request: {}.{} -> action = {} ", new Object[] { resourceName, dataFormat, Constants.DS_ACTION_INFO }); } this.prepareRequest(request, response); String out = null; IDsDefinition def = null; if (this.getSettings().get(Constants.PROP_DEPLOYMENT).equals(Constants.PROP_DEPLOYMENT_JEE)) { IDsDefinitions defs = this.getApplicationContext().getBean(IDsDefinitions.class); if (defs.containsDs(resourceName)) { def = defs.getDsDefinition(resourceName); } } else { @SuppressWarnings("unchecked") List<IDsDefinitions> defsList = (List<IDsDefinitions>) this.getApplicationContext() .getBean("osgiDsDefinitions"); for (IDsDefinitions defs : defsList) { if (defs.containsDs(resourceName)) { def = defs.getDsDefinition(resourceName); } } } def.getModelFields(); def.getFilterFields(); def.getParamFields(); IDsService<M, F, P> service = this.findDsService(resourceName); if (dataFormat.equals(IDsMarshaller.JSON)) { IDsMarshaller<M, F, P> marshaller = service.createMarshaller(dataFormat); response.setContentType("text/plain; charset=UTF-8"); out = ((ObjectMapper) marshaller.getDelegate()).writeValueAsString(def); PrintWriter w = response.getWriter(); w.write(out); w.flush(); return null; } else if (dataFormat.equals(IDsMarshaller.XML)) { // IDsMarshaller<M, F, P> marshaller = service // .createMarshaller(dataFormat); // StringWriter writer = new StringWriter(); // // // ((XmlMarshaller<M, F, P>) // marshaller).createMarshaller( // def.getClass()).marshal(def, writer); // // // response.setContentType("text/xml; charset=UTF-8"); // out = writer.toString(); // PrintWriter w = response.getWriter(); // w.write(out); // w.flush(); // return null; } else if (dataFormat.equals("html")) { IDsMarshaller<M, F, P> marshaller = service.createMarshaller(IDsMarshaller.XML); StringWriter writer = new StringWriter(); ((XmlMarshaller<M, F, P>) marshaller).createMarshaller(def.getClass()).marshal(def, writer); out = writer.toString(); String t1 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"; String t2 = "<?xml-stylesheet type=\"text/xsl\" href=\"/seava/resources/xsl/ds-info.xsl\"?>"; out = out.replace(t1, t1 + '\n' + t2); response.setContentType("text/xml; charset=UTF-8"); PrintWriter w = response.getWriter(); w.write(out); w.flush(); return null; } throw new Exception("Data-source " + resourceName + " cannot be found."); } catch (Exception e) { return this.handleException(e, response); } finally { this.finishRequest(); } }
From source file:com.liferay.portal.osgi.web.portlet.container.upload.test.UploadPortletTest.java
@Before @Override// ww w.j a v a 2 s. c o m public void setUp() throws Exception { super.setUp(); _testUploadPortlet = new TestUploadPortlet() { @Override public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws IOException { PrintWriter printWriter = resourceResponse.getWriter(); PortletURL portletURL = resourceResponse.createActionURL(); String queryString = HttpUtil.getQueryString(portletURL.toString()); Map<String, String[]> parameterMap = HttpUtil.getParameterMap(queryString); String portalAuthenticationToken = MapUtil.getString(parameterMap, "p_auth"); printWriter.write(portalAuthenticationToken); } }; registerMVCActionCommand(new TestUploadMVCActionCommand(_testUploadPortlet)); registerMVCPortlet(_testUploadPortlet); }
From source file:com.iorga.webappwatcher.EventLogManager.java
public void writeEventLogsToHttpServletResponse(final HttpServletResponse httpResponse, final Iterable<String> fileNames) throws IOException { // First, we check if the given paths are in the log path final Set<String> eventLogs = Sets.newHashSet(listEventLogsNameInThePath()); ArchiveOutputStream outputStream = null; try {/*from ww w . j a v a 2s.c o m*/ for (final String fileName : fileNames) { if (eventLogs.contains(fileName) && new File(getLogPathDirectory(), fileName).exists()) { outputStream = writeEventLogToHttpServletResponse(httpResponse, fileName, outputStream); } } } finally { if (outputStream != null) { outputStream.close(); } } if (outputStream == null) { // No file were appended httpResponse.setStatus(HttpServletResponse.SC_NO_CONTENT); final PrintWriter writer = httpResponse.getWriter(); writer.write("No log available at the moment."); } }
From source file:com.jeans.iservlet.controller.impl.ImportController.java
private void showProgress(PrintWriter out, String tip, double value) { out.write("<script>parent.__progress('" + tip + "', " + value + ");</script>"); out.flush();// w w w . j av a2 s. c om }
From source file:com.hp.avmon.home.web.HomeController.java
@RequestMapping(value = "main/menuTree") public void getMenuTree(HttpServletRequest request, PrintWriter writer) throws Exception { String userId = Utils.getCurrentUserId(request); String type = request.getParameter("type"); String parentId = request.getParameter("id"); if (parentId == null || parentId.equals("")) { parentId = "root"; }//from w w w.j a va 2 s.co m Object obj = homeService.getMenuTree(userId, parentId, type); String json = JackJson.fromObjectToJson(obj); //System.out.println(json); writer.write(json); writer.flush(); writer.close(); }
From source file:com.log4ic.compressor.servlet.CompressionServlet.java
@Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setCharacterEncoding("utf8"); PrintWriter writer = resp.getWriter(); //TODO ?,?//from www . ja va 2 s . co m try { Compressor.compress(req, resp, cacheManager, fileDomain); } catch (QueryStringEmptyException e) { logger.error("?.", e); //501 - Not Implemented ????? resp.setStatus(501); writer.write("?." + e.getMessage()); } catch (UnsupportedFileTypeException e) { logger.error("???.", e); //501 - Not Implemented ????? resp.setStatus(501); writer.write("???." + e.getMessage()); } catch (CompressionException e) { logger.error("?.", e); //501 - Not Implemented ????? resp.setStatus(501); writer.write("?." + e.getMessage()); } catch (GssParserException e) { logger.error("?,CSS.", e); //501 - Not Implemented ????? resp.setStatus(501); writer.write("?,CSS." + e.getMessage()); } catch (LessException e) { logger.error("?,CSS.", e); //501 - Not Implemented ????? resp.setStatus(501); writer.write("?,CSS." + e.getMessage()); } }
From source file:com.iorga.webappwatcher.EventLogManager.java
public void writeEventLogToHttpServletResponse(final HttpServletResponse httpResponse) throws IOException { synchronized (objectOutputStreamLogLock) { if (objectOutputStreamLog != null) { // before trying to download the log, we must first flush it // warning : as the footer of the xz will never be written, that file will be inconsistent for properly reading it flushLog();/*from ww w.j a v a 2 s . c o m*/ } if (logFile != null && logFile.exists()) { httpResponse.setStatus(HttpServletResponse.SC_OK); httpResponse.setContentType("application/x-gzip"); httpResponse.setHeader("Content-Disposition", "attachment; filename=\"" + logFile.getName() + ".gz\""); final FileInputStream inputStream = new FileInputStream(logFile); final OutputStream outputStream = new GZIPOutputStream(httpResponse.getOutputStream()); try { IOUtils.copy(inputStream, outputStream); } finally { inputStream.close(); outputStream.close(); } } else { httpResponse.setStatus(HttpServletResponse.SC_NO_CONTENT); final PrintWriter writer = httpResponse.getWriter(); writer.write("No log available at the moment."); } } }
From source file:com.hp.avmon.home.web.HomeController.java
@RequestMapping(value = "/registLicense") public void registLicense(HttpServletRequest request, PrintWriter writer) { String data = ""; try {//from w ww .ja v a 2 s .c om String license = request.getParameter("license"); licenseService.saveOrUpdateLicense(license); System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + license); data = "{success:true,msg:'?!'}"; } catch (Exception e) { logger.error("Exception: {}", e); data = "{success:false,msg:'!'}"; } writer.write(data); writer.flush(); writer.close(); }
From source file:com.imagelake.android.changephoneno.Servlet_ChangePhoneno.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PrintWriter out = response.getWriter(); try {//w ww.j a v a2s . c o m String type = request.getParameter("type"); if (type != null) { String uid = request.getParameter("uid"); if (type.equals("load_phone")) { if (uid != null) { User u = udi.getUser(Integer.parseInt(uid)); if (u != null) { JSONObject jo = new JSONObject(); jo.put("phn", u.getPhone()); System.out.println(jo.toJSONString()); out.write("json=" + jo.toJSONString()); } else { out.write("msg=Internal server error,Please try again later."); } } else { out.write("msg=Internal server error,Please try again later."); } } else if (type.equals("update_phone")) { String phn = request.getParameter("phn"); if (phn != null) { boolean k = udi.updatePhoneNo(Integer.parseInt(uid), phn); if (k) { out.write("msg=Successfully Completed."); } else { out.write("msg=Unable to complete the action,Please try again later."); } } else { out.write("msg=Internal server error,Please try again later."); } } } else { out.write("msg=Internal server error,Please try again later."); } } catch (Exception e) { e.printStackTrace(); } }