Java Code Examples for javax.servlet.http.HttpServletRequest.getLocales()

The following are Jave code examples for showing how to use getLocales() of the javax.servlet.http.HttpServletRequest class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: com-liferay-apio-architect   File: LanguageProvider.java   View Source Code Vote up 6 votes
@Override
public Language createContext(HttpServletRequest httpServletRequest) {
	return new Language() {

		@Override
		public Stream<Locale> getLocales() {
			Enumeration<Locale> locales = httpServletRequest.getLocales();

			return Collections.list(locales).stream();
		}

		@Override
		public Locale getPreferredLocale() {
			return httpServletRequest.getLocale();
		}

	};
}
 
Example 2
Project: tomcat7   File: HostManagerServlet.java   View Source Code Vote up 5 votes
/**
 * @deprecated Use {@link StringManager#getManager(String, Enumeration)}.
 *             This method will be removed in Tomcat 8.
 */
@Deprecated
protected StringManager getStringManager(HttpServletRequest req) {
    Enumeration<Locale> requestedLocales = req.getLocales();
    while (requestedLocales.hasMoreElements()) {
        Locale locale = requestedLocales.nextElement();
        StringManager result = StringManager.getManager(Constants.Package,
                locale);
        if (result.getLocale().equals(locale)) {
            return result;
        }
    }
    // Return the default
    return sm;
}
 
Example 3
Project: tomcat7   File: ManagerServlet.java   View Source Code Vote up 5 votes
/**
 * @deprecated Use {@link StringManager#getManager(String, Enumeration)}.
 *             This method will be removed in Tomcat 8.
 */
@Deprecated
protected StringManager getStringManager(HttpServletRequest req) {
    Enumeration<Locale> requestedLocales = req.getLocales();
    while (requestedLocales.hasMoreElements()) {
        Locale locale = requestedLocales.nextElement();
        StringManager result = StringManager.getManager(Constants.Package,
                locale);
        if (result.getLocale().equals(locale)) {
            return result;
        }
    }
    // Return the default
    return sm;
}
 
Example 4
Project: jerrydog   File: FormAuthenticator.java   View Source Code Vote up 5 votes
/**
 * Save the original request information into our session.
 *
 * @param request The request to be saved
 * @param session The session to contain the saved information
 */
private void saveRequest(HttpRequest request, Session session) {

    // Create and populate a SavedRequest object for this request
    HttpServletRequest hreq = (HttpServletRequest) request.getRequest();
    SavedRequest saved = new SavedRequest();
    Cookie cookies[] = hreq.getCookies();
    if (cookies != null) {
        for (int i = 0; i < cookies.length; i++)
            saved.addCookie(cookies[i]);
    }
    Enumeration names = hreq.getHeaderNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        Enumeration values = hreq.getHeaders(name);
        while (values.hasMoreElements()) {
            String value = (String) values.nextElement();
            saved.addHeader(name, value);
        }
    }
    Enumeration locales = hreq.getLocales();
    while (locales.hasMoreElements()) {
        Locale locale = (Locale) locales.nextElement();
        saved.addLocale(locale);
    }
    Map parameters = hreq.getParameterMap();
    Iterator paramNames = parameters.keySet().iterator();
    while (paramNames.hasNext()) {
        String paramName = (String) paramNames.next();
        String paramValues[] = (String[]) parameters.get(paramName);
        saved.addParameter(paramName, paramValues);
    }
    saved.setMethod(hreq.getMethod());
    saved.setQueryString(hreq.getQueryString());
    saved.setRequestURI(hreq.getRequestURI());

    // Stash the SavedRequest in our session for later use
    session.setNote(Constants.FORM_REQUEST_NOTE, saved);

}
 
Example 5
Project: apache-tomcat-7.0.73-with-comment   File: HostManagerServlet.java   View Source Code Vote up 5 votes
/**
 * @deprecated Use {@link StringManager#getManager(String, Enumeration)}.
 *             This method will be removed in Tomcat 8.
 */
@Deprecated
protected StringManager getStringManager(HttpServletRequest req) {
    Enumeration<Locale> requestedLocales = req.getLocales();
    while (requestedLocales.hasMoreElements()) {
        Locale locale = requestedLocales.nextElement();
        StringManager result = StringManager.getManager(Constants.Package,
                locale);
        if (result.getLocale().equals(locale)) {
            return result;
        }
    }
    // Return the default
    return sm;
}
 
Example 6
Project: apache-tomcat-7.0.73-with-comment   File: ManagerServlet.java   View Source Code Vote up 5 votes
/**
 * @deprecated Use {@link StringManager#getManager(String, Enumeration)}.
 *             This method will be removed in Tomcat 8.
 */
@Deprecated
protected StringManager getStringManager(HttpServletRequest req) {
    Enumeration<Locale> requestedLocales = req.getLocales();
    while (requestedLocales.hasMoreElements()) {
        Locale locale = requestedLocales.nextElement();
        StringManager result = StringManager.getManager(Constants.Package,
                locale);
        if (result.getLocale().equals(locale)) {
            return result;
        }
    }
    // Return the default
    return sm;
}
 
Example 7
Project: lazycat   File: HostManagerServlet.java   View Source Code Vote up 5 votes
/**
 * @deprecated Use {@link StringManager#getManager(String, Enumeration)}.
 *             This method will be removed in Tomcat 8.
 */
@Deprecated
protected StringManager getStringManager(HttpServletRequest req) {
	Enumeration<Locale> requestedLocales = req.getLocales();
	while (requestedLocales.hasMoreElements()) {
		Locale locale = requestedLocales.nextElement();
		StringManager result = StringManager.getManager(Constants.Package, locale);
		if (result.getLocale().equals(locale)) {
			return result;
		}
	}
	// Return the default
	return sm;
}
 
Example 8
Project: lazycat   File: ManagerServlet.java   View Source Code Vote up 5 votes
/**
 * @deprecated Use {@link StringManager#getManager(String, Enumeration)}.
 *             This method will be removed in Tomcat 8.
 */
@Deprecated
protected StringManager getStringManager(HttpServletRequest req) {
	Enumeration<Locale> requestedLocales = req.getLocales();
	while (requestedLocales.hasMoreElements()) {
		Locale locale = requestedLocales.nextElement();
		StringManager result = StringManager.getManager(Constants.Package, locale);
		if (result.getLocale().equals(locale)) {
			return result;
		}
	}
	// Return the default
	return sm;
}
 
Example 9
Project: gitplex-mit   File: ServletRequestCopy.java   View Source Code Vote up 4 votes
public ServletRequestCopy(HttpServletRequest request) {
	this.servletPath = request.getServletPath();
	this.contextPath = request.getContextPath();
	this.pathInfo = request.getPathInfo();
	this.requestUri = request.getRequestURI();
	this.requestURL = request.getRequestURL();
	this.method = request.getMethod();
	this.serverName = request.getServerName();
	this.serverPort = request.getServerPort();
	this.protocol = request.getProtocol();
	this.scheme = request.getScheme();
	
	
	/*
	 * have to comment out below two lines as otherwise web socket will
	 * report UnSupportedOperationException upon connection
	 */
	//this.characterEncoding = request.getCharacterEncoding();
	//this.contentType = request.getContentType();
	//this.requestedSessionId = request.getRequestedSessionId();
	this.characterEncoding = null;
	this.contentType = null;
	this.requestedSessionId = null;
	
	this.locale = request.getLocale();
	this.locales = request.getLocales();
	this.isSecure = request.isSecure();
	this.remoteUser = request.getRemoteUser();
	this.remoteAddr = request.getRemoteAddr();
	this.remoteHost = request.getRemoteHost();
	this.remotePort = request.getRemotePort();
	this.localAddr = request.getLocalAddr();
	this.localName = request.getLocalName();
	this.localPort = request.getLocalPort();
	this.pathTranslated = request.getPathTranslated();
	this.principal = request.getUserPrincipal();

	HttpSession session = request.getSession(true);
	httpSession = new HttpSessionCopy(session);

	String s;
	Enumeration<String> e = request.getHeaderNames();
	while (e != null && e.hasMoreElements()) {
		s = e.nextElement();
		Enumeration<String> headerValues = request.getHeaders(s);
		this.headers.put(s, headerValues);
	}

	e = request.getAttributeNames();
	while (e != null && e.hasMoreElements()) {
		s = e.nextElement();
		attributes.put(s, request.getAttribute(s));
	}

	e = request.getParameterNames();
	while (e != null && e.hasMoreElements()) {
		s = e.nextElement();
		parameters.put(s, request.getParameterValues(s));
	}
}