List of usage examples for javax.servlet.jsp.jstl.core Config FMT_LOCALE
String FMT_LOCALE
To view the source code for javax.servlet.jsp.jstl.core Config FMT_LOCALE.
Click Source Link
From source file:com.jslsolucoes.tagria.lib.util.TagUtil.java
public static Locale locale(JspContext jspContext) { HttpSession httpSession = ((PageContext) jspContext).getSession(); Locale locale = Locale.forLanguageTag(getInitParam(TagriaConfigParameter.LOCALE)); if (Config.get(httpSession, Config.FMT_LOCALE) != null) { locale = (Locale) Config.get(httpSession, Config.FMT_LOCALE); }/* w w w . j av a 2 s. c o m*/ return locale; }
From source file:com.jslsolucoes.tagria.lib.servlet.Tagria.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String uri = request.getRequestURI().replaceAll(";jsessionid=.*", ""); String etag = DigestUtils.sha256Hex(uri); if (uri.endsWith("blank")) { response.setStatus(HttpServletResponse.SC_OK); return;//from w w w . ja v a 2 s .co m } if (uri.endsWith("locale")) { Config.set(request.getSession(), Config.FMT_LOCALE, Locale.forLanguageTag(request.getParameter("locale"))); response.setStatus(HttpServletResponse.SC_OK); return; } if (request.getHeader("If-None-Match") != null && etag.equals(request.getHeader("If-None-Match"))) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return; } String charset = "utf-8"; if (TagUtil.getInitParam(TagriaConfigParameter.ENCODING) != null) { charset = TagUtil.getInitParam(TagriaConfigParameter.ENCODING); } response.setCharacterEncoding(charset); try { DateTime today = new DateTime(); DateTime expires = new DateTime().plusDays(CACHE_EXPIRES_DAY); if (uri.endsWith(".css")) { response.setContentType("text/css"); } else if (uri.endsWith(".js")) { response.setContentType("text/javascript"); } else if (uri.endsWith(".png")) { response.setContentType("image/png"); } SimpleDateFormat sdf = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss 'GMT'", Locale.ENGLISH); if (Boolean.valueOf(TagUtil.getInitParam(TagriaConfigParameter.CDN_ENABLED))) { response.setHeader(HttpHeaderParameter.ACCESS_CONTROL_ALLOW_ORIGIN.getName(), "*"); } response.setHeader(HttpHeaderParameter.ETAG.getName(), etag); response.setHeader(HttpHeaderParameter.EXPIRES.getName(), sdf.format(expires.toDate())); response.setHeader(HttpHeaderParameter.CACHE_CONTROL.getName(), "public,max-age=" + Seconds.secondsBetween(today, expires).getSeconds()); String url = "/com/jslsolucoes" + uri.replaceFirst(request.getContextPath(), "").replaceAll(";jsessionid=.*", ""); InputStream in = getClass().getResourceAsStream(url); IOUtils.copy(in, response.getOutputStream()); in.close(); } catch (Exception exception) { logger.error("Could not load resource", exception); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } }
From source file:org.openmrs.contrib.metadatarepository.webapp.filter.LocaleFilter.java
/** * This method looks for a "locale" request parameter. If it finds one, it sets it as the preferred locale * and also configures it to work with JSTL. * /*ww w .j a va2 s.c om*/ * @param request the current request * @param response the current response * @param chain the chain * @throws IOException when something goes wrong * @throws ServletException when a communication failure happens */ @SuppressWarnings("unchecked") public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { String locale = request.getParameter("locale"); Locale preferredLocale = null; if (locale != null) { int indexOfUnderscore = locale.indexOf('_'); if (indexOfUnderscore != -1) { String language = locale.substring(0, indexOfUnderscore); String country = locale.substring(indexOfUnderscore + 1); preferredLocale = new Locale(language, country); } else { preferredLocale = new Locale(locale); } } HttpSession session = request.getSession(false); if (session != null) { if (preferredLocale == null) { preferredLocale = (Locale) session.getAttribute(Constants.PREFERRED_LOCALE_KEY); } else { session.setAttribute(Constants.PREFERRED_LOCALE_KEY, preferredLocale); Config.set(session, Config.FMT_LOCALE, preferredLocale); } if (preferredLocale != null && !(request instanceof LocaleRequestWrapper)) { request = new LocaleRequestWrapper(request, preferredLocale); LocaleContextHolder.setLocale(preferredLocale); } } String theme = request.getParameter("theme"); if (theme != null && request.isUserInRole(Constants.ADMIN_ROLE)) { Map<String, Object> config = (Map) getServletContext().getAttribute(Constants.CONFIG); config.put(Constants.CSS_THEME, theme); } chain.doFilter(request, response); // Reset thread-bound LocaleContext. LocaleContextHolder.setLocaleContext(null); }
From source file:org.musicrecital.webapp.filter.LocaleFilter.java
/** * This method looks for a "locale" request parameter. If it finds one, it sets it as the preferred locale * and also configures it to work with JSTL. * //from w w w . ja v a 2 s. co m * @param request the current request * @param response the current response * @param chain the chain * @throws IOException when something goes wrong * @throws ServletException when a communication failure happens */ @SuppressWarnings("unchecked") public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { String locale = request.getParameter("locale"); Locale preferredLocale = null; if (locale != null) { int indexOfUnderscore = locale.indexOf('_'); if (indexOfUnderscore != -1) { String language = locale.substring(0, indexOfUnderscore); String country = locale.substring(indexOfUnderscore + 1); preferredLocale = new Locale(language, country); } else { preferredLocale = new Locale(locale); } } HttpSession session = request.getSession(false); if (session != null) { if (preferredLocale == null) { preferredLocale = (Locale) session.getAttribute(Constants.PREFERRED_LOCALE_KEY); } else { session.setAttribute(Constants.PREFERRED_LOCALE_KEY, preferredLocale); Config.set(session, Config.FMT_LOCALE, preferredLocale); } if (preferredLocale != null && !(request instanceof LocaleRequestWrapper)) { request = new LocaleRequestWrapper(request, preferredLocale); LocaleContextHolder.setLocale(preferredLocale); } } chain.doFilter(request, response); // Reset thread-bound LocaleContext. LocaleContextHolder.setLocaleContext(null); }
From source file:ejportal.webapp.filter.LocaleFilter.java
/** * This method looks for a "locale" request parameter. If it finds one, it * sets it as the preferred locale and also configures it to work with JSTL. * /*from w w w . ja v a 2 s .c o m*/ * @param request * the current request * @param response * the current response * @param chain * the chain * @throws IOException * when something goes wrong * @throws ServletException * when a communication failure happens */ @Override @SuppressWarnings("unchecked") public void doFilterInternal(HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) throws IOException, ServletException { final String locale = request.getParameter("locale"); Locale preferredLocale = null; if (locale != null) { final int indexOfUnderscore = locale.indexOf('_'); if (indexOfUnderscore != -1) { final String language = locale.substring(0, indexOfUnderscore); final String country = locale.substring(indexOfUnderscore + 1); preferredLocale = new Locale(language, country); } else { preferredLocale = new Locale(locale); } } final HttpSession session = request.getSession(false); if (session != null) { if (preferredLocale == null) { preferredLocale = (Locale) session.getAttribute(Constants.PREFERRED_LOCALE_KEY); } else { session.setAttribute(Constants.PREFERRED_LOCALE_KEY, preferredLocale); Config.set(session, Config.FMT_LOCALE, preferredLocale); } if ((preferredLocale != null) && !(request instanceof LocaleRequestWrapper)) { request = new LocaleRequestWrapper(request, preferredLocale); LocaleContextHolder.setLocale(preferredLocale); } } final String theme = request.getParameter("theme"); // if (theme != null && request.isUserInRole(Constants.ADMIN_ROLE)) { // TOD hartkodiert if ((theme != null) && request.isUserInRole("ROLE_SYSTEMADMIN")) { final Map<String, Object> config = (Map) this.getServletContext().getAttribute(Constants.CONFIG); config.put(Constants.CSS_THEME, theme); } chain.doFilter(request, response); // Reset thread-bound LocaleContext. LocaleContextHolder.setLocaleContext(null); }
From source file:alpha.portal.webapp.filter.LocaleFilter.java
/** * This method looks for a "locale" request parameter. If it finds one, it * sets it as the preferred locale and also configures it to work with JSTL. * /* www .j a v a2 s . c o m*/ * @param request * the current request * @param response * the current response * @param chain * the chain * @throws IOException * when something goes wrong * @throws ServletException * when a communication failure happens */ @Override @SuppressWarnings("unchecked") public void doFilterInternal(HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) throws IOException, ServletException { final String locale = request.getParameter("locale"); Locale preferredLocale = null; if (locale != null) { final int indexOfUnderscore = locale.indexOf('_'); if (indexOfUnderscore != -1) { final String language = locale.substring(0, indexOfUnderscore); final String country = locale.substring(indexOfUnderscore + 1); preferredLocale = new Locale(language, country); } else { preferredLocale = new Locale(locale); } } final HttpSession session = request.getSession(false); if (session != null) { if (preferredLocale == null) { preferredLocale = (Locale) session.getAttribute(Constants.PREFERRED_LOCALE_KEY); } else { session.setAttribute(Constants.PREFERRED_LOCALE_KEY, preferredLocale); Config.set(session, Config.FMT_LOCALE, preferredLocale); } if ((preferredLocale != null) && !(request instanceof LocaleRequestWrapper)) { request = new LocaleRequestWrapper(request, preferredLocale); LocaleContextHolder.setLocale(preferredLocale); } } final String theme = request.getParameter("theme"); if ((theme != null) && request.isUserInRole(Constants.ADMIN_ROLE)) { final Map<String, Object> config = (Map) this.getServletContext().getAttribute(Constants.CONFIG); config.put(Constants.CSS_THEME, theme); } chain.doFilter(request, response); // Reset thread-bound LocaleContext. LocaleContextHolder.setLocaleContext(null); }
From source file:org.openmrs.contrib.metadatarepository.webapp.filter.LocaleFilterTest.java
public void testJstlLocaleIsSet() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("locale", "es"); MockHttpServletResponse response = new MockHttpServletResponse(); request.setSession(new MockHttpSession(null)); filter.doFilter(request, response, new MockFilterChain()); assertNotNull(Config.get(request.getSession(), Config.FMT_LOCALE)); }
From source file:alpha.portal.webapp.filter.LocaleFilterTest.java
/** * Test jstl locale is set.// w w w .j a va2 s . co m * * @throws Exception * the exception */ public void testJstlLocaleIsSet() throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("locale", "es"); final MockHttpServletResponse response = new MockHttpServletResponse(); request.setSession(new MockHttpSession(null)); this.filter.doFilter(request, response, new MockFilterChain()); Assert.assertNotNull(Config.get(request.getSession(), Config.FMT_LOCALE)); }
From source file:com.sun.faces.application.ViewHandlerImpl.java
public void renderView(FacesContext context, UIViewRoot viewToRender) throws IOException, FacesException { if (null == context || null == viewToRender) { String message = Util.getExceptionMessageString(Util.NULL_PARAMETERS_ERROR_MESSAGE_ID); message = message + " context " + context + " viewToRender " + viewToRender; throw new NullPointerException(message); }/*w w w.j a v a2s . c om*/ ApplicationAssociate associate = ApplicationAssociate.getInstance(context.getExternalContext()); if (null != associate) { associate.responseRendered(); } String requestURI = viewToRender.getViewId(); if (log.isDebugEnabled()) { log.debug("About to render view " + requestURI); } String mapping = getFacesMapping(context); String newViewId = requestURI; // If we have a valid mapping (meaning we were invoked via the // FacesServlet) and we're extension mapped, do the replacement. if (mapping != null && !isPrefixMapped(mapping)) { if (log.isDebugEnabled()) { log.debug("Found URL pattern mapping to FacesServlet " + mapping); } newViewId = convertViewId(context, requestURI); } else { if (log.isDebugEnabled()) { log.debug("Found no URL patterns mapping to FacesServlet "); } } viewToRender.setViewId(newViewId); // update the JSTL locale attribute in request scope so that JSTL // picks up the locale from viewRoot. This attribute must be updated // before the JSTL setBundle tag is called because that is when the // new LocalizationContext object is created based on the locale. // PENDING: this only works for servlet based requests if (context.getExternalContext().getRequest() instanceof ServletRequest) { Config.set((ServletRequest) context.getExternalContext().getRequest(), Config.FMT_LOCALE, context.getViewRoot().getLocale()); } if (log.isTraceEnabled()) { log.trace("Before dispacthMessage to newViewId " + newViewId); } context.getExternalContext().dispatch(newViewId); if (log.isTraceEnabled()) { log.trace("After dispacthMessage to newViewId " + newViewId); } }
From source file:com.edgenius.core.webapp.filter.LocaleFilter.java
public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { // if(log.isDebugEnabled()){ // log.debug("Request URL: " + request.getRequestURI()); // }//from w ww . j av a 2 s . c o m //charset encoding if (!StringUtils.isEmpty(this.encoding)) request.setCharacterEncoding(encoding); else request.setCharacterEncoding(Constants.UTF8); String direction = null; Locale preferredLocale = null; TimeZone timezone = null; HttpSession session = request.getSession(false); if (getUserService() != null) { //for Install mode, it will return null User user = getUserService().getUserByName(request.getRemoteUser()); if (user != null && !user.isAnonymous()) { //locale UserSetting set = user.getSetting(); String userLang = set.getLocaleLanguage(); String userCountry = set.getLocaleCountry(); if (userLang != null && userCountry != null) { preferredLocale = new Locale(userLang, userCountry); } //text direction in HTML direction = set.getDirection(); //timezone if (set.getTimeZone() != null) timezone = TimeZone.getTimeZone(set.getTimeZone()); } } if (preferredLocale == null) { if (Global.DetectLocaleFromRequest) { Locale locale = request.getLocale(); if (locale != null) { preferredLocale = locale; } } if (preferredLocale == null) { preferredLocale = Global.getDefaultLocale(); } } if (direction == null) { direction = Global.DefaultDirection; } if (timezone == null) { if (session != null) { //try to get timezone from HttpSession, which will be intial set in SecurityControllerImpl.checkLogin() method timezone = (TimeZone) session.getAttribute(Constants.TIMEZONE); } if (timezone == null) timezone = TimeZone.getTimeZone(Global.DefaultTimeZone); } //set locale for STURTS and JSTL // set the time zone - must be set for dates to display the time zone if (session != null) { Config.set(session, Config.FMT_LOCALE, preferredLocale); session.setAttribute(Constants.DIRECTION, direction); Config.set(session, Config.FMT_TIME_ZONE, timezone); } //replace request by LocaleRequestWrapper if (!(request instanceof LocaleRequestWrapper)) { request = new LocaleRequestWrapper(request, preferredLocale); LocaleContextConfHolder.setLocale(preferredLocale); } if (chain != null) { request.setAttribute(PREFERRED_LOCALE, preferredLocale.toString()); chain.doFilter(request, response); } // Reset thread-bound LocaleContext. LocaleContextConfHolder.setLocaleContext(null); }