List of usage examples for javax.servlet ServletOutputStream flush
public void flush() throws IOException
From source file:com.topsec.tsm.sim.asset.web.AssetListController.java
/** * ?//from w w w .ja v a2 s. c o m * @param request * @param response * @throws Exception */ @RequestMapping("downloadAssetModel") public void downloadAssetModel(HttpServletRequest request, HttpServletResponse response) throws Exception { try { InputStream inputStream = this.getClass().getClassLoader() .getResourceAsStream("resource/asset/assetModel.xls"); response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment; filename=\"assetModel.xls\""); ServletOutputStream out = response.getOutputStream(); byte[] b = new byte[1024]; int len = -1; while ((len = inputStream.read(b)) != -1) { out.write(b, 0, len); } out.flush(); inputStream.close(); } catch (Exception e) { } }
From source file:org.openmrs.module.pmtct.util.FileExporter.java
/** * Auto generated method comment//from w w w .j a v a 2 s .c o m * * @param request * @param response * @param drugOrderList * @param filename * @param title * @throws Exception */ public void exportDrugToCSVFile(HttpServletRequest request, HttpServletResponse response, List<DrugOrder> drugOrderList, String filename, String title) throws Exception { ServletOutputStream outputStream = null; try { outputStream = response.getOutputStream(); Patient p = (drugOrderList != null) ? drugOrderList.get(0).getPatient() : null; int count = 0; response.setContentType("text/plain"); response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\""); outputStream.println("" + title); outputStream.println(); if (null != p) { outputStream.println("Identifier, " + p.getActiveIdentifiers().get(0).getIdentifier()); outputStream.println("Names, " + p.getPersonName()); outputStream.println("Gender, " + p.getGender()); } outputStream.println(); outputStream.println( "No., Item ordered, Dose/Units, Frequency, Instructions, Start date, Discontinued date"); outputStream.println(); for (DrugOrder drugOrder : drugOrderList) { count += 1; outputStream.println(count + ", " + drugOrder.getDrug().getName() + ", " + drugOrder.getDose() + " " + drugOrder.getDoseUnits().getName().getName() + ", " + drugOrder.getFrequency() + ", " + drugOrder.getInstructions() + ", " + sdf.format(drugOrder.getEffectiveStartDate()) + ", " + sdf.format(drugOrder.getEffectiveStopDate())); } outputStream.flush(); } catch (Exception e) { log.error(e.getMessage()); } finally { if (null != outputStream) outputStream.close(); } }
From source file:org.opencms.frontend.templateone.form.CmsCaptchaField.java
/** * Writes a Captcha JPEG image to the servlet response output stream. * <p>// www . j ava 2 s . c om * * @param cms an initialized Cms JSP action element * @throws IOException if something goes wrong */ public void writeCaptchaImage(CmsJspActionElement cms) throws IOException { ByteArrayOutputStream captchaImageOutput = new ByteArrayOutputStream(); ServletOutputStream out = null; BufferedImage captchaImage = null; int maxTries = 10; do { try { maxTries--; String sessionId = cms.getRequest().getSession().getId(); Locale locale = cms.getRequestContext().getLocale(); captchaImage = CmsCaptchaServiceCache.getSharedInstance() .getCaptchaService(m_captchaSettings, cms.getCmsObject()) .getImageChallengeForID(sessionId, locale); } catch (CaptchaException cex) { if (LOG.isErrorEnabled()) { LOG.error(cex); LOG.error(Messages.get().getBundle().key(Messages.LOG_ERR_CAPTCHA_CONFIG_IMAGE_SIZE_2, new Object[] { m_captchaSettings.getPresetPath(), new Integer(maxTries) })); } m_captchaSettings.setImageHeight(m_captchaSettings.getImageHeight() + 40); m_captchaSettings.setImageWidth(m_captchaSettings.getImageWidth() + 80); } } while (captchaImage == null && maxTries > 0); try { ImageIO.write(captchaImage, "jpg", captchaImageOutput); CmsFlexController controller = CmsFlexController.getController(cms.getRequest()); HttpServletResponse response = controller.getTopResponse(); response.setHeader("Cache-Control", "no-store"); response.setHeader("Pragma", "no-cache"); response.setDateHeader("Expires", 0); response.setContentType("image/jpeg"); out = cms.getResponse().getOutputStream(); out.write(captchaImageOutput.toByteArray()); out.flush(); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error(e.getLocalizedMessage(), e); } cms.getResponse().sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } finally { try { if (out != null) { out.close(); } } catch (Throwable t) { // intentionally left blank } } }
From source file:org.openmrs.module.pmtct.util.FileExporter.java
/** * Auto generated method comment/*from ww w . j a v a 2s .com*/ * * @param request * @param response * @param patientList * @param filename * @param title * @throws Exception */ public void exportExpectedPatientInMaternityToCSVFile(HttpServletRequest request, HttpServletResponse response, List<Object> patientList, String filename, String title) throws Exception { ServletOutputStream outputStream = null; try { outputStream = response.getOutputStream(); Patient p; PatientService ps = Context.getPatientService(); response.setContentType("text/plain"); response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\""); outputStream.println("" + title); outputStream.println("Number of Patients: " + patientList.size()); outputStream.println(); outputStream.println("No. ,Identifier, Names, Enrollment Date, DPA, HIV Status, HIV Status of Partner"); outputStream.println(); int ids = 0; Encounter cpnEnc; for (Object patient : patientList) { Object[] o = (Object[]) patient; p = ps.getPatient(Integer.parseInt(o[0].toString())); cpnEnc = pmtctTag.getCPNEncounterInfo(p.getPatientId()); ids += 1; outputStream.println(ids + "," + p.getActiveIdentifiers().get(0).getIdentifier() + "," + p.getPersonName() + "," + o[3].toString() + "," + pmtctTag.observationValueByConcept(cpnEnc, PMTCTConstants.PREGNANT_DUE_DATE) + "," + pmtctTag.lastObsValueByConceptId(p.getPatientId(), PMTCTConstants.RESULT_OF_HIV_TEST) + "," + pmtctTag.observationValueByConcept(cpnEnc, PMTCTConstants.TESTING_STATUS_OF_PARTNER)); } outputStream.flush(); } catch (Exception e) { log.error(e.getMessage()); } finally { if (null != outputStream) outputStream.close(); } }
From source file:org.openmrs.module.pmtct.util.FileExporter.java
/** * Auto generated method comment/*w w w . j av a 2 s . c om*/ * * @param request * @param response * @param patientList * @param filename * @param title * @throws Exception */ public void exportPatientTestedInDeliveryRoomToCSVFile(HttpServletRequest request, HttpServletResponse response, List<Object> patientList, String filename, String title) throws Exception { ServletOutputStream outputStream = null; try { outputStream = response.getOutputStream(); Patient p; PatientService ps = Context.getPatientService(); response.setContentType("text/plain"); response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\""); outputStream.println("" + title); outputStream.println("Number of Patients: " + patientList.size()); outputStream.println(); outputStream.println( "No. ,Identifier, Names, Enrollment Date, DPA, Delivery Date, Result of HIV in Delivery room"); outputStream.println(); int ids = 0; Encounter cpnEnc, matEnc; for (Object patient : patientList) { Object[] o = (Object[]) patient; p = ps.getPatient(Integer.parseInt(o[0].toString())); cpnEnc = pmtctTag.getCPNEncounterInfo(p.getPatientId()); matEnc = pmtctTag.getMaternityEncounterInfo(p.getPatientId()); ids += 1; outputStream.println(ids + "," + p.getActiveIdentifiers().get(0).getIdentifier() + "," + p.getPersonName() + "," + o[3].toString() + "," + pmtctTag.observationValueByConcept(cpnEnc, PMTCTConstants.PREGNANT_DUE_DATE) + "," + pmtctTag.observationValueByConcept(matEnc, PMTCTConstants.DATE_OF_CONFINEMENT) + "," + pmtctTag.observationValueByConcept(matEnc, PMTCTConstants.RESULT_OF_HIV_TEST)); } outputStream.flush(); } catch (Exception e) { log.error(e.getMessage()); } finally { if (null != outputStream) outputStream.close(); } }
From source file:net.urosk.reportEngine.ReportsServlet.java
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String reportDesign = request.getParameter("__report"); String type = request.getParameter("__format"); String outputFilename = request.getParameter("__filename"); String attachment = request.getParameter("attachment"); //check parameters StringBuffer msg = new StringBuffer(); // checkers// ww w. jav a2 s. c o m if (isEmpty(reportDesign)) { msg.append("<BR>__report can not be empty"); } OutputType outputType = null; try { outputType = OutputType.valueOf(type.toUpperCase()); } catch (Exception e) { msg.append("Undefined report __format: " + type + ". Set __format=" + OutputType.values()); } // checkers if (isEmpty(outputFilename)) { msg.append("<BR>__filename can not be empty"); } try { ServletOutputStream out = response.getOutputStream(); ServletContext context = request.getSession().getServletContext(); // output error if (StringUtils.isNotEmpty(msg.toString())) { out.print(msg.toString()); return; } ReportDef def = new ReportDef(); def.setDesignFileName(reportDesign); def.setOutputType(outputType); @SuppressWarnings("unchecked") Map<String, String[]> params = request.getParameterMap(); Iterator<String> i = params.keySet().iterator(); while (i.hasNext()) { String key = i.next(); String value = params.get(key)[0]; def.getParameters().put(key, value); } try { String createdFile = birtReportEngine.createReport(def); File file = new File(createdFile); String mimetype = context.getMimeType(file.getAbsolutePath()); String inlineOrAttachment = (attachment != null) ? "attachment" : "inline"; response.setContentType((mimetype != null) ? mimetype : "application/octet-stream"); response.setContentLength((int) file.length()); response.setHeader("Content-Disposition", inlineOrAttachment + "; filename=\"" + outputFilename + "\""); DataInputStream in = new DataInputStream(new FileInputStream(file)); byte[] bbuf = new byte[1024]; int length; while ((in != null) && ((length = in.read(bbuf)) != -1)) { out.write(bbuf, 0, length); } in.close(); } catch (Exception e) { logger.error(e, e); out.print(e.getMessage()); } finally { out.flush(); out.close(); } logger.info("Free memory: " + (Runtime.getRuntime().freeMemory() / 1024L * 1024L)); } catch (Exception e) { logger.error(e, e); } finally { } }
From source file:eu.earthobservatory.org.StrabonEndpoint.QueryBean.java
/** * Processes the request made by a client of the endpoint that uses it as a service. * /* w ww . ja v a 2 s . c o m*/ * @param request * @param response * @throws IOException */ private void processRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { ServletOutputStream out = response.getOutputStream(); // get desired formats (we check only the Accept header) List<stSPARQLQueryResultFormat> formats = parseMultiValuedAcceptHeader(request.getHeader("accept")); // get the query and the limit String query = request.getParameter("query"); String maxLimit = request.getParameter("maxLimit"); // check for required parameters if (formats.size() == 0 || query == null) { logger.error("[StrabonEndpoint.QueryBean] {}", PARAM_ERROR); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); out.print(ResponseMessages.getXMLHeader()); out.print(ResponseMessages.getXMLException(PARAM_ERROR)); out.print(ResponseMessages.getXMLFooter()); } else { // just use the first specified format stSPARQLQueryResultFormat format = formats.get(0); // decode the query query = URLDecoder.decode(request.getParameter("query"), "UTF-8"); response.setContentType(format.getDefaultMIMEType()); try { query = strabonWrapper.addLimit(query, maxLimit); strabonWrapper.query(query, format.getName(), out); response.setStatus(HttpServletResponse.SC_OK); } catch (Exception e) { logger.error("[StrabonEndpoint.QueryBean] Error during querying.", e); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); out.print(ResponseMessages.getXMLHeader()); out.print(ResponseMessages.getXMLException(e.getMessage())); out.print(ResponseMessages.getXMLFooter()); } } out.flush(); }
From source file:com.carfinance.module.common.controller.DocumentDownloadController.java
/** * ???PDF/*from ww w . j a v a2 s . c o m*/ * @param model * @param request * @param response */ @RequestMapping(value = "/pdfcontrace", method = RequestMethod.GET) public void pdfContrace(Model model, HttpServletRequest request, HttpServletResponse response) { String contrace_id_str = request.getParameter("contrace_id"); long contrace_type = Long.valueOf(request.getParameter("contrace_type"));//??1-2-? long vehicle_contrace_id = Long.valueOf(request.getParameter("vehicle_contrace_id")); String org_id = ""; String contrace_no = ""; String customer_name = ""; String license_plate = ""; String vehicle_model = ""; String engine_no = ""; String carframe_no = ""; double guide_price = 0; String color = ""; String begin_time = ""; String end_time = ""; String driving_user_name = ""; String driving_user_license_no = ""; String daily_price = ""; String daily_available_km = ""; String over_km_price = ""; String over_hour_price = ""; String month_price = ""; String month_available_km = ""; String pre_payment = ""; String deposit = ""; String monthly_day = ""; String vehicle_id = ""; if (contrace_type == 1) { VehicleContraceInfo vehicleContraceInfo = this.vehicleServiceManageService .getVehicleContraceInfoById(Long.valueOf(contrace_id_str)); if (vehicleContraceInfo != null) { org_id = String.valueOf(vehicleContraceInfo.getOrg_id()); contrace_no = vehicleContraceInfo.getContrace_no(); customer_name = vehicleContraceInfo.getCustomer_name(); // List<VehicleContraceVehsInfo> vehsList = this.vehicleServiceManageService.getVehicleContraceVehsListByContraceId(vehicleContraceInfo.getId()); // if(vehsList != null) { // VehicleContraceVehsInfo vehsInfo = vehsList.get(0); VehicleContraceVehsInfo vehsInfo = this.vehicleServiceManageService .getContraceVehicleByid(vehicle_contrace_id); VehicleInfo vehicleInfo = this.vehicleManageService.getVehicleInfoByid(vehsInfo.getVehicle_id()); license_plate = vehicleInfo.getLicense_plate(); vehicle_model = vehicleInfo.getModel(); engine_no = vehicleInfo.getEngine_no(); carframe_no = vehicleInfo.getCarframe_no(); guide_price = vehicleInfo.getGuide_price(); color = vehicleInfo.getColor(); driving_user_name = vehsInfo.getDriving_user_name(); driving_user_license_no = vehsInfo.getDriving_user_license_no(); daily_price = vehicleInfo.getDaily_price() + ""; vehicle_id = vehicleInfo.getId() + ""; // } begin_time = vehicleContraceInfo.getUse_begin(); end_time = vehicleContraceInfo.getUse_end(); daily_available_km = vehicleContraceInfo.getDaily_available_km() + ""; over_km_price = vehicleContraceInfo.getOver_km_price() + ""; over_hour_price = vehicleContraceInfo.getOver_hour_price() + ""; month_price = vehicleContraceInfo.getMonth_price() + ""; month_available_km = vehicleContraceInfo.getMonth_available_km() + ""; pre_payment = vehicleContraceInfo.getPre_payment() + ""; deposit = vehicleContraceInfo.getDeposit() + ""; monthly_day = vehicleContraceInfo.getMonthly_day() + ""; } } else if (contrace_type == 2) { PropertyContraceInfo propertyContraceInfo = this.vehicleServiceManageService .getPropertyContraceInfoById(Long.valueOf(contrace_id_str)); if (propertyContraceInfo != null) { org_id = String.valueOf(propertyContraceInfo.getOrg_id()); contrace_no = propertyContraceInfo.getContrace_no(); customer_name = propertyContraceInfo.getCustomer_name(); } } //1.ContentType response.setContentType("multipart/form-data"); //2.????(??a.pdf) response.setHeader("Content-Disposition", "attachment;fileName=" + contrace_no + "_" + vehicle_id + ".pdf"); Document pdfDoc = new Document(PageSize.A4, 50, 50, 50, 50); // ?? pdf ? try { BaseFont bfChinese = BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H", false); Font bold_fontChinese = new Font(bfChinese, 18, Font.BOLD, BaseColor.BLACK); Font normal_fontChinese = new Font(bfChinese, 12, Font.NORMAL, BaseColor.BLACK); Font normal_desc_fontChinese = new Font(bfChinese, 6, Font.NORMAL, BaseColor.BLACK); FileOutputStream pdfFile = new FileOutputStream(new File( appProps.get("normal.contrace.download.path") + contrace_no + "_" + vehicle_id + ".pdf")); // pdf ? Paragraph paragraph1 = new Paragraph("???", bold_fontChinese); paragraph1.setAlignment(Element.ALIGN_CENTER); Chunk customer_name_underline = new Chunk(customer_name); customer_name_underline.setUnderline(1f, 3f); Chunk license_plate_underline = new Chunk(license_plate); license_plate_underline.setUnderline(1f, 3f); Chunk vehicle_model_underline = new Chunk(vehicle_model); vehicle_model_underline.setUnderline(1f, 3f); Chunk engine_no_underline = new Chunk(engine_no); engine_no_underline.setUnderline(1f, 3f); Chunk carframe_no_underline = new Chunk(carframe_no); carframe_no_underline.setUnderline(1f, 3f); Chunk guide_price_underline = new Chunk(guide_price / 10000 + ""); guide_price_underline.setUnderline(1f, 3f); Chunk color_underline = new Chunk(color); color_underline.setUnderline(1f, 3f); Chunk begin_time_underline = new Chunk(begin_time); begin_time_underline.setUnderline(1f, 3f); Chunk end_time_underline = new Chunk(end_time); end_time_underline.setUnderline(1f, 3f); Chunk driving_user_name_underline = new Chunk( driving_user_name == null ? "___/___" : driving_user_name); driving_user_name_underline.setUnderline(1f, 3f); Chunk driving_user_license_no_underline = new Chunk( driving_user_license_no == null ? "_____/_____" : driving_user_license_no); driving_user_license_no_underline.setUnderline(1f, 3f); Chunk daily_price_underline = new Chunk(daily_price); daily_price_underline.setUnderline(1f, 3f); Chunk daily_available_km_underline = new Chunk(daily_available_km); daily_available_km_underline.setUnderline(1f, 3f); Chunk over_km_price_underline = new Chunk(over_km_price); over_km_price_underline.setUnderline(1f, 3f); Chunk over_hour_price_underline = new Chunk(over_hour_price); over_hour_price_underline.setUnderline(1f, 3f); Chunk month_price_underline = new Chunk(month_price == null ? "_____/_____" : month_price); month_price_underline.setUnderline(1f, 3f); Chunk month_available_km_underline = new Chunk( month_available_km == null ? "_____/_____" : month_available_km); month_available_km_underline.setUnderline(1f, 3f); Chunk pre_payment_underline = new Chunk(pre_payment); pre_payment_underline.setUnderline(1f, 3f); Chunk deposit_underline = new Chunk(deposit); deposit_underline.setUnderline(1f, 3f); Chunk monthly_day_underline = new Chunk(monthly_day == null ? "___/___" : monthly_day); monthly_day_underline.setUnderline(1f, 3f); Paragraph paragraph2 = new Paragraph( "??? ???" + contrace_no, normal_fontChinese); Paragraph paragraph3 = new Paragraph("" + customer_name_underline + " ( 20____________", normal_fontChinese); Paragraph paragraph4 = new Paragraph( "??? ??????????", normal_fontChinese); Paragraph paragraph5 = new Paragraph("???____" + license_plate_underline + "____?____" + vehicle_model_underline + "________" + color_underline + "____??____" + engine_no_underline + "____?____" + carframe_no_underline + "____??____" + guide_price_underline + "____", normal_fontChinese); Paragraph paragraph6 = new Paragraph("?____" + begin_time_underline + "____?____" + end_time_underline + "____", normal_fontChinese); Paragraph paragraph7 = new Paragraph("??____" + driving_user_name_underline + "____??____" + driving_user_license_no_underline + "____?", normal_fontChinese); Paragraph paragraph8 = new Paragraph("????", normal_fontChinese); Paragraph paragraph9 = new Paragraph("1????____" + daily_price_underline + "____??____" + daily_available_km_underline + "____??____" + over_km_price_underline + "____??____" + over_hour_price_underline + "____??30????____" + month_price_underline + "____??____" + month_available_km_underline + "____30", normal_fontChinese); Paragraph paragraph10 = new Paragraph( "2??????8:00---20:00", normal_fontChinese); Paragraph paragraph11 = new Paragraph( "3??????", normal_fontChinese); Paragraph paragraph12 = new Paragraph( "4????____" + pre_payment_underline + "____??____" + monthly_day_underline + "____?", normal_fontChinese); Paragraph paragraph13 = new Paragraph("5???____" + deposit_underline + "____(???)???????", normal_fontChinese); Paragraph paragraph14 = new Paragraph( "6????1%????????", normal_fontChinese); Image image = Image.getInstance(appProps.get("normal.contrace.download.path") + "chekuang.jpg"); Paragraph paragraph15 = new Paragraph("?", normal_desc_fontChinese); Paragraph paragraph16 = new Paragraph( "1?????????", normal_desc_fontChinese); Paragraph paragraph17 = new Paragraph( "2????5000?200", normal_desc_fontChinese); Paragraph paragraph18 = new Paragraph( "3????", normal_desc_fontChinese); Paragraph paragraph19 = new Paragraph( "4???????????????", normal_desc_fontChinese); Paragraph paragraph20 = new Paragraph( "5?????????", normal_desc_fontChinese); Paragraph paragraph21 = new Paragraph( "6????????????", normal_desc_fontChinese); Paragraph paragraph22 = new Paragraph("?", normal_desc_fontChinese); Paragraph paragraph23 = new Paragraph( "1???????", normal_desc_fontChinese); Paragraph paragraph24 = new Paragraph( "2?????????????????????????", normal_desc_fontChinese); Paragraph paragraph25 = new Paragraph( "3????????????????????????", normal_desc_fontChinese); Paragraph paragraph26 = new Paragraph( "4?????????????????", normal_desc_fontChinese); Paragraph paragraph27 = new Paragraph( "5????????????????????", normal_desc_fontChinese); Paragraph paragraph28 = new Paragraph( "6?????????????????????620%?30%??????????????????????", normal_desc_fontChinese); Paragraph paragraph29 = new Paragraph( "7???????????", normal_desc_fontChinese); Paragraph paragraph30 = new Paragraph( "8????????", normal_desc_fontChinese); Paragraph paragraph31 = new Paragraph( "9??????????????????????", normal_desc_fontChinese); Paragraph paragraph32 = new Paragraph( "10????????????", normal_desc_fontChinese); Paragraph paragraph33 = new Paragraph( "11???????????500-1000", normal_desc_fontChinese); Paragraph paragraph34 = new Paragraph( "12??????????", normal_desc_fontChinese); Paragraph paragraph35 = new Paragraph( "13?????_________________________________7??????????\n", normal_desc_fontChinese); Paragraph paragraph36 = new Paragraph( "14?????????????????", normal_desc_fontChinese); Paragraph paragraph37 = new Paragraph( "15?????????5000????????????????400?500100????", normal_desc_fontChinese); Paragraph paragraph38 = new Paragraph( "16???????????????????????????", normal_desc_fontChinese); Paragraph paragraph39 = new Paragraph("?", normal_desc_fontChinese); Paragraph paragraph40 = new Paragraph( "1??????????????", normal_desc_fontChinese); Paragraph paragraph41 = new Paragraph( "2????????????", normal_desc_fontChinese); Paragraph paragraph42 = new Paragraph( "3????", normal_desc_fontChinese); Paragraph paragraph43 = new Paragraph( "4??????????50%?????????", normal_desc_fontChinese); Paragraph paragraph44 = new Paragraph( "5???????????????????", normal_desc_fontChinese); Paragraph paragraph45 = new Paragraph( "6???????????????", normal_desc_fontChinese); Paragraph paragraph46 = new Paragraph( "7?????????50%", normal_desc_fontChinese); Paragraph paragraph47 = new Paragraph( "8???7????????????", normal_desc_fontChinese); Paragraph paragraph48 = new Paragraph( "9???_____/?40??8????_____??", normal_desc_fontChinese); Paragraph paragraph49 = new Paragraph( "10?????___?????", normal_desc_fontChinese); Paragraph paragraph50 = new Paragraph( "11????", normal_desc_fontChinese); Paragraph paragraph51 = new Paragraph("??", normal_desc_fontChinese); Paragraph paragraph52 = new Paragraph( "1?????????20%????", normal_desc_fontChinese); Paragraph paragraph53 = new Paragraph( "2???????????????????", normal_desc_fontChinese); Paragraph paragraph54 = new Paragraph( "?????___________________\n", normal_desc_fontChinese); Paragraph paragraph55 = new Paragraph( "???????????????", normal_desc_fontChinese); Paragraph paragraph56 = new Paragraph( "???????", normal_desc_fontChinese); Paragraph paragraph57 = new Paragraph("?????????", normal_desc_fontChinese); Paragraph paragraph58 = new Paragraph( "??? ?", normal_desc_fontChinese); Paragraph paragraph59 = new Paragraph( " ??? ??", normal_desc_fontChinese); // Document ?File PdfWriter ? PdfWriter.getInstance(pdfDoc, pdfFile); pdfDoc.open(); // Document // ?? pdfDoc.add(paragraph1); pdfDoc.add(new Chunk("\n\n")); pdfDoc.add(paragraph2); pdfDoc.add(paragraph3); pdfDoc.add(paragraph4); pdfDoc.add(paragraph5); pdfDoc.add(paragraph6); pdfDoc.add(paragraph7); pdfDoc.add(paragraph8); pdfDoc.add(paragraph9); pdfDoc.add(paragraph10); pdfDoc.add(paragraph11); pdfDoc.add(paragraph12); pdfDoc.add(paragraph13); pdfDoc.add(paragraph14); pdfDoc.add(image); pdfDoc.newPage(); pdfDoc.add(paragraph15); pdfDoc.add(paragraph16); pdfDoc.add(paragraph17); pdfDoc.add(paragraph18); pdfDoc.add(paragraph19); pdfDoc.add(paragraph20); pdfDoc.add(paragraph21); pdfDoc.add(paragraph22); pdfDoc.add(paragraph23); pdfDoc.add(paragraph24); pdfDoc.add(paragraph25); pdfDoc.add(paragraph26); pdfDoc.add(paragraph27); pdfDoc.add(paragraph28); pdfDoc.add(paragraph29); pdfDoc.add(paragraph30); pdfDoc.add(paragraph31); pdfDoc.add(paragraph32); pdfDoc.add(paragraph33); pdfDoc.add(paragraph34); pdfDoc.add(paragraph35); pdfDoc.add(paragraph36); pdfDoc.add(paragraph37); pdfDoc.add(paragraph38); pdfDoc.add(paragraph39); pdfDoc.add(paragraph40); pdfDoc.add(paragraph41); pdfDoc.add(paragraph42); pdfDoc.add(paragraph43); pdfDoc.add(paragraph44); pdfDoc.add(paragraph45); pdfDoc.add(paragraph46); pdfDoc.add(paragraph47); pdfDoc.add(paragraph48); pdfDoc.add(paragraph49); pdfDoc.add(paragraph50); pdfDoc.add(paragraph51); pdfDoc.add(paragraph52); pdfDoc.add(paragraph53); pdfDoc.add(paragraph54); pdfDoc.add(paragraph55); pdfDoc.add(paragraph56); pdfDoc.add(paragraph57); pdfDoc.add(paragraph58); pdfDoc.add(paragraph59); pdfDoc.close(); ServletOutputStream out; //File(?download.pdf) File file = new File( appProps.get("normal.contrace.download.path") + contrace_no + "_" + vehicle_id + ".pdf"); try { FileInputStream inputStream = new FileInputStream(file); //3.response?ServletOutputStream(out) out = response.getOutputStream(); int b = 0; byte[] buffer = new byte[512]; while (b != -1) { b = inputStream.read(buffer); //4.?(out) out.write(buffer, 0, b); } inputStream.close(); out.close(); out.flush(); } catch (IOException e) { e.printStackTrace(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.kuali.ole.module.purap.document.web.struts.PurchaseOrderAction.java
/** * Print the list of PO Quote requests.//from ww w .java 2 s.c o m * * @param mapping An ActionMapping * @param form An ActionForm * @param request The HttpServletRequest * @param response The HttpServletResponse * @return An ActionForward * @throws Exception */ public ActionForward printPoQuoteListOnly(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String poDocId = request.getParameter("docId"); ByteArrayOutputStream baosPDF = new ByteArrayOutputStream(); try { StringBuffer sbFilename = new StringBuffer(); sbFilename.append("PURAP_PO_QUOTE_LIST_"); sbFilename.append(poDocId); sbFilename.append("_"); sbFilename.append(System.currentTimeMillis()); sbFilename.append(".pdf"); boolean success = SpringContext.getBean(PurchaseOrderService.class) .printPurchaseOrderQuoteRequestsListPDF(poDocId, baosPDF); if (!success) { if (baosPDF != null) { baosPDF.reset(); } return mapping.findForward(OLEConstants.MAPPING_PORTAL); } response.setHeader("Cache-Control", "max-age=30"); response.setContentType("application/pdf"); StringBuffer sbContentDispValue = new StringBuffer(); String useJavascript = request.getParameter("useJavascript"); if (useJavascript == null || useJavascript.equalsIgnoreCase("false")) { sbContentDispValue.append("attachment"); } else { sbContentDispValue.append("inline"); } sbContentDispValue.append("; filename="); sbContentDispValue.append(sbFilename); response.setHeader("Content-disposition", sbContentDispValue.toString()); response.setContentLength(baosPDF.size()); ServletOutputStream sos; sos = response.getOutputStream(); baosPDF.writeTo(sos); sos.flush(); } finally { if (baosPDF != null) { baosPDF.reset(); } } return null; }
From source file:org.kuali.ole.module.purap.document.web.struts.PurchaseOrderAction.java
/** * Creates a PDF document based on the PO information and the items that were selected by the user on the Purchase Order * Retransmit Document page to be retransmitted, then display the PDF to the browser. * * @param mapping An ActionMapping//from www. ja v a 2 s . c om * @param form An ActionForm * @param request The HttpServletRequest * @param response The HttpServletResponse * @return An ActionForward * @throws Exception */ public ActionForward printingRetransmitPoOnly(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String selectedItemIndexes = request.getParameter("selectedItemIndexes"); String documentNumber = request.getParameter("poDocumentNumberForRetransmit"); PurchaseOrderDocument po = SpringContext.getBean(PurchaseOrderService.class) .getPurchaseOrderByDocumentNumber(documentNumber); String retransmitHeader = request.getParameter("retransmitHeader"); // setting the isItemSelectedForRetransmitIndicator items of the PO obtained from the database based on its value from // the po from the form setItemSelectedForRetransmitIndicatorFromPOInForm(selectedItemIndexes, po.getItems()); po.setRetransmitHeader(retransmitHeader); ByteArrayOutputStream baosPDF = new ByteArrayOutputStream(); try { StringBuffer sbFilename = new StringBuffer(); sbFilename.append("PURAP_PO_"); sbFilename.append(po.getPurapDocumentIdentifier()); sbFilename.append("_"); sbFilename.append(System.currentTimeMillis()); sbFilename.append(".pdf"); // below method will throw ValidationException if errors are found SpringContext.getBean(PurchaseOrderService.class).retransmitPurchaseOrderPDF(po, baosPDF); response.setHeader("Cache-Control", "max-age=30"); response.setContentType("application/pdf"); StringBuffer sbContentDispValue = new StringBuffer(); sbContentDispValue.append("inline"); sbContentDispValue.append("; filename="); sbContentDispValue.append(sbFilename); response.setHeader("Content-disposition", sbContentDispValue.toString()); response.setContentLength(baosPDF.size()); ServletOutputStream sos; sos = response.getOutputStream(); baosPDF.writeTo(sos); sos.flush(); } catch (ValidationException e) { LOG.warn("Caught ValidationException while trying to retransmit PO with doc id " + po.getDocumentNumber()); return mapping.findForward(OLEConstants.MAPPING_ERROR); } finally { if (baosPDF != null) { baosPDF.reset(); } } return null; }