List of usage examples for javax.servlet.http HttpServletResponse getLocale
public Locale getLocale();
From source file:org.codelabor.system.file.web.struts.action.FileUploadAction.java
public ActionForward view(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); FileManager fileManager = (FileManager) ctx.getBean("fileManager"); Map<String, Object> paramMap = RequestUtils.getParameterMap(request); logger.debug("paramMap: {}", paramMap.toString()); String fileId = (String) paramMap.get("fileId"); StringBuilder sb = new StringBuilder(); FileDTO fileDTO;/*from w w w . j a va 2 s . c om*/ fileDTO = fileManager.selectFileByFileId(fileId); logger.debug("fileDTO: {}", fileDTO); String repositoryPath = fileDTO.getRepositoryPath(); String uniqueFilename = fileDTO.getUniqueFilename(); String realFilename = fileDTO.getRealFilename(); InputStream inputStream = null; if (StringUtils.isNotEmpty(repositoryPath)) { // FILE_SYSTEM sb.setLength(0); sb.append(repositoryPath); if (!repositoryPath.endsWith(File.separator)) { sb.append(File.separator); } sb.append(uniqueFilename); File file = new File(sb.toString()); inputStream = new FileInputStream(file); } else { // DATABASE byte[] bytes = new byte[] {}; if (fileDTO.getFileSize() > 0) { bytes = fileDTO.getBytes(); } inputStream = new ByteArrayInputStream(bytes); } response.setContentType(fileDTO.getContentType()); // set response contenttype, header String encodedRealFilename = URLEncoder.encode(realFilename, "UTF-8"); logger.debug("realFilename: {}", realFilename); logger.debug("encodedRealFilename: {}", encodedRealFilename); logger.debug("character encoding: {}", response.getCharacterEncoding()); logger.debug("content type: {}", response.getContentType()); logger.debug("bufferSize: {}", response.getBufferSize()); logger.debug("locale: {}", response.getLocale()); BufferedInputStream bufferdInputStream = new BufferedInputStream(inputStream); ServletOutputStream servletOutputStream = response.getOutputStream(); BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(servletOutputStream); int bytesRead; byte buffer[] = new byte[2048]; while ((bytesRead = bufferdInputStream.read(buffer)) != -1) { bufferedOutputStream.write(buffer, 0, bytesRead); } // flush stream bufferedOutputStream.flush(); // close stream inputStream.close(); bufferdInputStream.close(); servletOutputStream.close(); bufferedOutputStream.close(); return null; }
From source file:org.everit.jira.hr.admin.SchemeUsersComponent.java
private void processDelete(final HttpServletRequest req, final HttpServletResponse resp) { Long userSchemeId = Long.parseLong(req.getParameter("scheme-user-userscheme-id")); delete(userSchemeId);/*ww w . j av a 2 s. c o m*/ Long userCount = schemeUserCount(req.getParameter("schemeId")); try (PartialResponseBuilder prb = new PartialResponseBuilder(resp)) { prb.replace("#scheme-user-table", render(req, resp.getLocale(), "scheme-user-table")); prb.replace("#delete-schema-validation-dialog", (writer) -> { DeleteSchemaValidationComponent.INSTANCE.render(writer, resp.getLocale(), userCount); }); } }
From source file:org.everit.jira.hr.admin.SchemeUsersComponent.java
private void processEdit(final HttpServletRequest req, final HttpServletResponse resp) { long recordId = Long.parseLong(req.getParameter("record-id")); long schemeId = Long.parseLong(req.getParameter("schemeId")); String userName = req.getParameter("user"); Date startDate = Date.valueOf(req.getParameter("start-date")); Date endDate = Date.valueOf(req.getParameter("end-date")); Date endDateExcluded = DateUtil.addDays(endDate, 1); Long userId = getUserId(userName); if (userId == null) { renderAlert("User does not exist", "error", resp); resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return;//from w w w . j a va 2s .c o m } if (startDate.compareTo(endDate) > 0) { renderAlert("Start date must not be after end date", "error", resp); resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } Set<String> schemeNamesWithOverlappingTimeRange = getSchemeNamesWithOverlappingTimeRange(userId, startDate, endDateExcluded, recordId); if (!schemeNamesWithOverlappingTimeRange.isEmpty()) { renderAlert( "The user is assigned overlapping with the specified date range to the" + " following scheme(s): " + schemeNamesWithOverlappingTimeRange.toString(), "error", resp); resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } update(recordId, schemeId, userId, startDate, endDateExcluded); try (PartialResponseBuilder prb = new PartialResponseBuilder(resp)) { renderAlertOnPrb("Updating user successful", "info", prb, resp.getLocale()); prb.replace("#scheme-user-table", render(req, resp.getLocale(), "scheme-user-table")); } }
From source file:org.everit.jira.hr.admin.SchemeUsersComponent.java
private void processFilter(final HttpServletRequest req, final HttpServletResponse resp) { try (PartialResponseBuilder prb = new PartialResponseBuilder(resp)) { prb.replace("#scheme-user-table", render(req, resp.getLocale(), "scheme-user-table")); }//w ww . j a v a 2s .co m }
From source file:org.everit.jira.hr.admin.SchemeUsersComponent.java
private void processSave(final HttpServletRequest req, final HttpServletResponse resp) { long schemeId = Long.parseLong(req.getParameter("schemeId")); String userName = req.getParameter("user"); Date startDate = Date.valueOf(req.getParameter("start-date")); Date endDate = Date.valueOf(req.getParameter("end-date")); Date endDateExcluded = DateUtil.addDays(endDate, 1); Long userId = getUserId(userName); if (userId == null) { renderAlert("User does not exist", "error", resp); resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return;/*from ww w.java 2 s . co m*/ } if (startDate.compareTo(endDate) > 0) { renderAlert("Start date must not be after end date", "error", resp); resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } Set<String> schemeNamesWithOverlappingTimeRange = getSchemeNamesWithOverlappingTimeRange(userId, startDate, endDateExcluded, null); if (!schemeNamesWithOverlappingTimeRange.isEmpty()) { renderAlert( "The user is assigned overlapping with the specified date range to the" + " following scheme(s): " + schemeNamesWithOverlappingTimeRange.toString(), "error", resp); resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } save(schemeId, userName, startDate, endDateExcluded); Long userCount = schemeUserCount(String.valueOf(schemeId)); try (PartialResponseBuilder prb = new PartialResponseBuilder(resp)) { renderAlertOnPrb("Assiging user successful", "info", prb, resp.getLocale()); prb.replace("#scheme-user-table", render(req, resp.getLocale(), "scheme-user-table")); prb.replace("#delete-schema-validation-dialog", (writer) -> { DeleteSchemaValidationComponent.INSTANCE.render(writer, resp.getLocale(), userCount); }); } }
From source file:org.everit.jira.hr.admin.SchemeUsersComponent.java
private void renderAlert(final String message, final String alertType, final HttpServletResponse resp) { try (PartialResponseBuilder prb = new PartialResponseBuilder(resp)) { renderAlertOnPrb(message, alertType, prb, resp.getLocale()); }/* w w w. j av a2s . c o m*/ }
From source file:org.everit.jira.hr.admin.SchemeUsersComponent.java
public String renderInitialFragments(final HttpServletRequest req, final HttpServletResponse resp) { StringWriter writer = new StringWriter(); Map<String, Object> vars = new HashMap<>(); vars.put("request", req); vars.put("response", resp); TEMPLATE.render(writer, vars, resp.getLocale(), "dialogs"); return writer.toString(); }
From source file:org.olat.core.gui.media.ServletUtil.java
/** * @param response/*from w w w . ja v a2 s. c o m*/ * @param result */ public static void serveStringResource(HttpServletRequest httpReq, HttpServletResponse response, String result) { setStringResourceHeaders(response); // log the response headers prior to sending the output boolean isDebug = log.isDebug(); if (isDebug) { log.debug( "\nResponse headers (some)\ncontent type:" + response.getContentType() + "\ncharacterencoding:" + response.getCharacterEncoding() + "\nlocale:" + response.getLocale()); } try { long rstart = 0; if (isDebug) { rstart = System.currentTimeMillis(); } // make a ByteArrayOutputStream to be able to determine the length. // buffer size: assume average length of a char in bytes is max 2 ByteArrayOutputStream baos = new ByteArrayOutputStream(result.length() * 2); // we ignore the accept-charset from the request and always write in // utf-8: // we have lots of different languages (content) in one application to // support, and more importantly, // a blend of olat translations and content by authors which can be in // different languages. OutputStreamWriter osw = new OutputStreamWriter(baos, "utf-8"); osw.write(result); osw.close(); // the data is now utf-8 encoded in the bytearray -> push it into the outputstream int encLen = baos.size(); response.setContentLength(encLen); OutputStream os; if (Settings.isDebuging()) { SlowBandWidthSimulator sbs = Windows .getWindows(CoreSpringFactory.getImpl(UserSessionManager.class).getUserSession(httpReq)) .getSlowBandWidthSimulator(); os = sbs.wrapOutputStream(response.getOutputStream()); } else { os = response.getOutputStream(); } byte[] bout = baos.toByteArray(); os.write(bout); os.close(); if (isDebug) { long rstop = System.currentTimeMillis(); log.debug("time to serve inline-resource " + result.length() + " chars / " + encLen + " bytes: " + (rstop - rstart)); } } catch (IOException e) { if (isDebug) { log.warn("client browser abort when serving inline", e); } } }
From source file:org.olat.core.gui.media.ServletUtil.java
public static void serveStringResource(HttpServletResponse response, StringOutput result) { setStringResourceHeaders(response);//from w w w. j a v a 2 s. co m // log the response headers prior to sending the output boolean isDebug = log.isDebug(); if (isDebug) { log.debug( "\nResponse headers (some)\ncontent type:" + response.getContentType() + "\ncharacterencoding:" + response.getCharacterEncoding() + "\nlocale:" + response.getLocale()); } try { long rstart = 0; if (isDebug || true) { rstart = System.currentTimeMillis(); } // make a ByteArrayOutputStream to be able to determine the length. // buffer size: assume average length of a char in bytes is max 2 int encLen = result.length(); Reader reader = result.getReader(); //response.setContentLength(encLen); set the number of characters, must be number of bytes PrintWriter os = response.getWriter(); IOUtils.copy(reader, os); os.close(); if (isDebug) { log.debug("time to serve inline-resource " + result.length() + " chars / " + encLen + " bytes: " + (System.currentTimeMillis() - rstart)); } } catch (IOException e) { if (isDebug) { log.warn("client browser abort when serving inline", e); } } }