List of usage examples for javax.servlet.http Cookie setPath
public void setPath(String uri)
From source file:com.ylife.shoppingcart.service.impl.ShoppingCartServiceImpl.java
/** * /* ww w. j a v a 2s.com*/ * * @param shoppingCartId * id * @param marketingId * ??id * @param marketingActivityId * id * @return int */ @Override public int changeShoppingCartMarket(Long shoppingCartId, Long marketingId, Long marketingActivityId, HttpServletRequest request, HttpServletResponse response) { Long marketingIdNew = marketingId; Long marketingActivityIdNew = marketingActivityId; Long customerId = (Long) request.getSession().getAttribute(CUSTOMERID); // ? if (customerId != null) { ShoppingCart sc = new ShoppingCart(); sc.setShoppingCartId(shoppingCartId); // ??id0??? if (marketingIdNew != null && marketingIdNew == 0) { marketingIdNew = null; } sc.setMarketingId(marketingIdNew); // id0? if (marketingActivityIdNew != null && marketingActivityIdNew == 0) { marketingActivityIdNew = null; } sc.setMarketingActivityId(marketingActivityIdNew); return shoppingCartMapper.changeShoppingCartMarket(sc); } else { Cookie[] cookies = request.getCookies(); StringBuilder newMid = new StringBuilder(); if (null != cookies) { for (Cookie cookie : cookies) { if (cookie != null && NPSTORE_MID.equals(cookie.getName()) && cookie.getValue() != null && !"".equals(cookie.getValue())) { String[] mIds = cookie.getValue().split("-"); // ?cookie for (int j = 0; j < mIds.length; j++) { String[] mid = mIds[j].split("e"); // ?? if (mid[0] != null) { if (mid[0].equals(shoppingCartId.toString())) { newMid.append(shoppingCartId); newMid.append("e"); newMid.append(marketingIdNew); newMid.append("e"); newMid.append(marketingActivityIdNew); newMid.append("e"); newMid.append("1"); newMid.append("-"); } else { newMid.append(mIds[j]); newMid.append("-"); } } } } } Cookie cookie = new Cookie(NPSTORE_MID, newMid.toString()); cookie.setMaxAge(15 * 24 * 3600); cookie.setPath("/"); response.addCookie(cookie); } return 0; } }
From source file:org.hoteia.qalingo.core.web.util.RequestUtil.java
public void addOrUpdateRecentProductToCookie(final HttpServletRequest request, final HttpServletResponse response, final String catalogCode, final String virtualCategoryCode, final String productMarketingCode, final String productSkuCode) throws Exception { Cookie info = null; String cookieProductValue = catalogCode + Constants.SEMI_COLON + virtualCategoryCode + Constants.SEMI_COLON + productMarketingCode + Constants.SEMI_COLON + productSkuCode; Cookie[] cookies = request.getCookies(); Boolean found = false;//www. ja va2s . c o m String domain = request.getServerName(); if (cookies != null) { for (Cookie cooky : cookies) { info = cooky; if (getRecentProductsCookieName().equals(info.getName())) { found = true; break; } } } if (found) { Boolean flag = false; String value = URLDecoder.decode(info.getValue(), Constants.UTF8); if (value.contains(Constants.PIPE)) { String[] splits = value.split(Constants.PIPE); for (String cookieProductValueIt : splits) { if (cookieProductValueIt.contains(Constants.SEMI_COLON)) { if (cookieProductValueIt.contains(cookieProductValue)) { flag = true; } } else { // VALUE DOESN'T CONTAIN SEMI COLON : CLEAN THE COOKIE - NON COMPATIBLE VALUE info.setValue(""); info.setPath("/"); info.setMaxAge(Constants.COOKIES_LENGTH); info.setDomain(domain); response.addCookie(info); } } } else { if (value.contains(Constants.SEMI_COLON)) { if (value.contains(cookieProductValue)) { flag = true; } } else { // VALUE DOESN'T CONTAIN SEMI COLON : CLEAN THE COOKIE - NON COMPATIBLE VALUE value = ""; info.setValue(""); info.setPath("/"); info.setMaxAge(Constants.COOKIES_LENGTH); info.setDomain(domain); response.addCookie(info); } } if (!flag) { String values = value; if (StringUtils.isNotEmpty(values)) { values += Constants.PIPE; } values += cookieProductValue; info.setValue(URLEncoder.encode(values, Constants.UTF8)); info.setPath("/"); info.setMaxAge(Constants.COOKIES_LENGTH); info.setDomain(domain); response.addCookie(info); } } else { info = new Cookie(getRecentProductsCookieName(), cookieProductValue); info.setPath("/"); info.setMaxAge(Constants.COOKIES_LENGTH); info.setDomain(domain); response.addCookie(info); } }
From source file:de.tu_dortmund.ub.api.paia.core.PaiaCoreEndpoint.java
/** * PAIA core services: Prfe jeweils die scopes und liefere die Daten *///from ww w .ja va 2 s . com private void provideService(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String patronid, String service, String format, String language, String redirect_url, DocumentList documents) throws IOException { httpServletResponse.setHeader("Access-Control-Allow-Origin", config.getProperty("Access-Control-Allow-Origin")); httpServletResponse.setHeader("Cache-Control", config.getProperty("Cache-Control")); ObjectMapper mapper = new ObjectMapper(); if (Lookup.lookupAll(IntegratedLibrarySystem.class).size() > 0) { try { IntegratedLibrarySystem integratedLibrarySystem = Lookup.lookup(IntegratedLibrarySystem.class); // init ILS integratedLibrarySystem.init(this.config); switch (service) { case "patron": { Patron patron = integratedLibrarySystem.patron(patronid, false); if (patron != null) { StringWriter json = new StringWriter(); mapper = new ObjectMapper(); mapper.writeValue(json, patron); this.logger.debug("[" + this.config.getProperty("service.name") + "] " + json); httpServletResponse.setHeader("X-Accepted-OAuth-Scopes", "read_patron"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); if (format.equals("html")) { if (Lookup.lookupAll(ObjectToHtmlTransformation.class).size() > 0) { try { ObjectToHtmlTransformation htmlTransformation = Lookup .lookup(ObjectToHtmlTransformation.class); // init transformator htmlTransformation.init(this.config); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", language); parameters.put("service", service); httpServletResponse.setContentType("text/html;charset=UTF-8"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.getWriter() .println(htmlTransformation.transform(patron, parameters)); } catch (TransformationException e) { httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message."); } } else { this.logger.error("ObjectToHtmlTransformation not configured! Switch to JSON."); format = "json"; } } // XML-Ausgabe mit JAXB if (format.equals("xml")) { try { JAXBContext context = JAXBContext.newInstance(Patron.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // Write to HttpResponse httpServletResponse.setContentType("application/xml;charset=UTF-8"); m.marshal(patron, httpServletResponse.getWriter()); } catch (JAXBException e) { this.logger.error(e.getMessage(), e.getCause()); httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } } // JSON-Ausgabe mit Jackson if (format.equals("json")) { httpServletResponse.setContentType("application/json;charset=UTF-8"); mapper.writeValue(httpServletResponse.getWriter(), patron); } } else { // Error handling mit suppress_response_codes=true if (httpServletRequest.getParameter("suppress_response_codes") != null) { httpServletResponse.setStatus(HttpServletResponse.SC_OK); } // Error handling mit suppress_response_codes=false (=default) else { httpServletResponse.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } break; } case "fullpatron": { Patron patron = integratedLibrarySystem.patron(patronid, true); if (patron != null) { StringWriter json = new StringWriter(); mapper = new ObjectMapper(); mapper.writeValue(json, patron); this.logger.debug("[" + this.config.getProperty("service.name") + "] " + json); httpServletResponse.setHeader("X-Accepted-OAuth-Scopes", "write_patron"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); if (format.equals("html")) { if (Lookup.lookupAll(ObjectToHtmlTransformation.class).size() > 0) { try { ObjectToHtmlTransformation htmlTransformation = Lookup .lookup(ObjectToHtmlTransformation.class); // init transformator htmlTransformation.init(this.config); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", language); parameters.put("service", service); httpServletResponse.setContentType("text/html;charset=UTF-8"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.getWriter() .println(htmlTransformation.transform(patron, parameters)); } catch (TransformationException e) { httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message."); } } else { this.logger.error("ObjectToHtmlTransformation not configured! Switch to JSON."); format = "json"; } } // XML-Ausgabe mit JAXB if (format.equals("xml")) { try { JAXBContext context = JAXBContext.newInstance(Patron.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // Write to HttpResponse httpServletResponse.setContentType("application/xml;charset=UTF-8"); m.marshal(patron, httpServletResponse.getWriter()); } catch (JAXBException e) { this.logger.error(e.getMessage(), e.getCause()); httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } } // JSON-Ausgabe mit Jackson if (format.equals("json")) { httpServletResponse.setContentType("application/json;charset=UTF-8"); mapper.writeValue(httpServletResponse.getWriter(), patron); } } else { // Error handling mit suppress_response_codes=true if (httpServletRequest.getParameter("suppress_response_codes") != null) { httpServletResponse.setStatus(HttpServletResponse.SC_OK); } // Error handling mit suppress_response_codes=false (=default) else { httpServletResponse.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } break; } case "items": { DocumentList documentList = integratedLibrarySystem.items(patronid, "all"); if (documentList != null) { StringWriter json = new StringWriter(); mapper = new ObjectMapper(); mapper.writeValue(json, documentList); this.logger.debug("[" + this.config.getProperty("service.name") + "] " + json); httpServletResponse.setHeader("X-Accepted-OAuth-Scopes", "read_items"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); if (format.equals("html")) { if (Lookup.lookupAll(ObjectToHtmlTransformation.class).size() > 0) { try { ObjectToHtmlTransformation htmlTransformation = Lookup .lookup(ObjectToHtmlTransformation.class); // init transformator htmlTransformation.init(this.config); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", language); parameters.put("service", service); httpServletResponse.setContentType("text/html;charset=UTF-8"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.getWriter() .println(htmlTransformation.transform(documentList, parameters)); } catch (TransformationException e) { httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message."); } } else { this.logger.error("ObjectToHtmlTransformation not configured! Switch to JSON."); format = "json"; } } // XML-Ausgabe mit JAXB if (format.equals("xml")) { try { JAXBContext context = JAXBContext.newInstance(DocumentList.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // Write to HttpResponse httpServletResponse.setContentType("application/xml;charset=UTF-8"); m.marshal(documentList, httpServletResponse.getWriter()); } catch (JAXBException e) { this.logger.error(e.getMessage(), e.getCause()); httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } } // JSON-Ausgabe mit Jackson if (format.equals("json")) { httpServletResponse.setContentType("application/json;charset=UTF-8"); mapper.writeValue(httpServletResponse.getWriter(), documentList); } } else { // Error handling mit suppress_response_codes=true if (httpServletRequest.getParameter("suppress_response_codes") != null) { httpServletResponse.setStatus(HttpServletResponse.SC_OK); } // Error handling mit suppress_response_codes=false (=default) else { httpServletResponse.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } break; } case "items/borrowed": { DocumentList documentList = integratedLibrarySystem.items(patronid, "borrowed"); if (documentList != null) { StringWriter json = new StringWriter(); mapper = new ObjectMapper(); mapper.writeValue(json, documentList); this.logger.debug("[" + this.config.getProperty("service.name") + "] " + json); httpServletResponse.setHeader("X-Accepted-OAuth-Scopes", "read_items"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); if (format.equals("html")) { if (Lookup.lookupAll(ObjectToHtmlTransformation.class).size() > 0) { try { ObjectToHtmlTransformation htmlTransformation = Lookup .lookup(ObjectToHtmlTransformation.class); // init transformator htmlTransformation.init(this.config); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", language); parameters.put("service", service); httpServletResponse.setContentType("text/html;charset=UTF-8"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.getWriter() .println(htmlTransformation.transform(documentList, parameters)); } catch (TransformationException e) { httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message."); } } else { this.logger.error("ObjectToHtmlTransformation not configured! Switch to JSON."); format = "json"; } } // XML-Ausgabe mit JAXB if (format.equals("xml")) { try { JAXBContext context = JAXBContext.newInstance(DocumentList.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // Write to HttpResponse httpServletResponse.setContentType("application/xml;charset=UTF-8"); m.marshal(documentList, httpServletResponse.getWriter()); } catch (JAXBException e) { this.logger.error(e.getMessage(), e.getCause()); httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } } // JSON-Ausgabe mit Jackson if (format.equals("json")) { httpServletResponse.setContentType("application/json;charset=UTF-8"); mapper.writeValue(httpServletResponse.getWriter(), documentList); } } else { // Error handling mit suppress_response_codes=true if (httpServletRequest.getParameter("suppress_response_codes") != null) { httpServletResponse.setStatus(HttpServletResponse.SC_OK); } // Error handling mit suppress_response_codes=false (=default) else { httpServletResponse.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } break; } case "items/borrowed/ill": { DocumentList documentList = integratedLibrarySystem.items(patronid, "borrowed", "ill"); if (documentList != null) { StringWriter json = new StringWriter(); mapper = new ObjectMapper(); mapper.writeValue(json, documentList); this.logger.debug("[" + this.config.getProperty("service.name") + "] " + json); httpServletResponse.setHeader("X-Accepted-OAuth-Scopes", "read_items"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); if (format.equals("html")) { if (Lookup.lookupAll(ObjectToHtmlTransformation.class).size() > 0) { try { ObjectToHtmlTransformation htmlTransformation = Lookup .lookup(ObjectToHtmlTransformation.class); // init transformator htmlTransformation.init(this.config); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", language); parameters.put("service", service); httpServletResponse.setContentType("text/html;charset=UTF-8"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.getWriter() .println(htmlTransformation.transform(documentList, parameters)); } catch (TransformationException e) { httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message."); } } else { this.logger.error("ObjectToHtmlTransformation not configured! Switch to JSON."); format = "json"; } } // XML-Ausgabe mit JAXB if (format.equals("xml")) { try { JAXBContext context = JAXBContext.newInstance(DocumentList.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // Write to HttpResponse httpServletResponse.setContentType("application/xml;charset=UTF-8"); m.marshal(documentList, httpServletResponse.getWriter()); } catch (JAXBException e) { this.logger.error(e.getMessage(), e.getCause()); httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } } // JSON-Ausgabe mit Jackson if (format.equals("json")) { httpServletResponse.setContentType("application/json;charset=UTF-8"); mapper.writeValue(httpServletResponse.getWriter(), documentList); } } else { // Error handling mit suppress_response_codes=true if (httpServletRequest.getParameter("suppress_response_codes") != null) { httpServletResponse.setStatus(HttpServletResponse.SC_OK); } // Error handling mit suppress_response_codes=false (=default) else { httpServletResponse.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } break; } case "items/borrowed/renewed": { DocumentList documentList = integratedLibrarySystem.items(patronid, "borrowed", "renewed"); if (documentList != null) { StringWriter json = new StringWriter(); mapper = new ObjectMapper(); mapper.writeValue(json, documentList); this.logger.debug("[" + this.config.getProperty("service.name") + "] " + json); httpServletResponse.setHeader("X-Accepted-OAuth-Scopes", "read_items"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); if (format.equals("html")) { if (Lookup.lookupAll(ObjectToHtmlTransformation.class).size() > 0) { try { ObjectToHtmlTransformation htmlTransformation = Lookup .lookup(ObjectToHtmlTransformation.class); // init transformator htmlTransformation.init(this.config); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", language); parameters.put("service", service); httpServletResponse.setContentType("text/html;charset=UTF-8"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.getWriter() .println(htmlTransformation.transform(documentList, parameters)); } catch (TransformationException e) { httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message."); } } else { this.logger.error("ObjectToHtmlTransformation not configured! Switch to JSON."); format = "json"; } } // XML-Ausgabe mit JAXB if (format.equals("xml")) { try { JAXBContext context = JAXBContext.newInstance(DocumentList.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // Write to HttpResponse httpServletResponse.setContentType("application/xml;charset=UTF-8"); m.marshal(documentList, httpServletResponse.getWriter()); } catch (JAXBException e) { this.logger.error(e.getMessage(), e.getCause()); httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } } // JSON-Ausgabe mit Jackson if (format.equals("json")) { httpServletResponse.setContentType("application/json;charset=UTF-8"); mapper.writeValue(httpServletResponse.getWriter(), documentList); } } else { // Error handling mit suppress_response_codes=true if (httpServletRequest.getParameter("suppress_response_codes") != null) { httpServletResponse.setStatus(HttpServletResponse.SC_OK); } // Error handling mit suppress_response_codes=false (=default) else { httpServletResponse.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } break; } case "items/borrowed/recalled": { DocumentList documentList = integratedLibrarySystem.items(patronid, "borrowed", "recalled"); if (documentList != null) { StringWriter json = new StringWriter(); mapper = new ObjectMapper(); mapper.writeValue(json, documentList); this.logger.debug("[" + this.config.getProperty("service.name") + "] " + json); httpServletResponse.setHeader("X-Accepted-OAuth-Scopes", "read_items"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); if (format.equals("html")) { if (Lookup.lookupAll(ObjectToHtmlTransformation.class).size() > 0) { try { ObjectToHtmlTransformation htmlTransformation = Lookup .lookup(ObjectToHtmlTransformation.class); // init transformator htmlTransformation.init(this.config); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", language); parameters.put("service", service); httpServletResponse.setContentType("text/html;charset=UTF-8"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.getWriter() .println(htmlTransformation.transform(documentList, parameters)); } catch (TransformationException e) { httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message."); } } else { this.logger.error("ObjectToHtmlTransformation not configured! Switch to JSON."); format = "json"; } } // XML-Ausgabe mit JAXB if (format.equals("xml")) { try { JAXBContext context = JAXBContext.newInstance(DocumentList.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // Write to HttpResponse httpServletResponse.setContentType("application/xml;charset=UTF-8"); m.marshal(documentList, httpServletResponse.getWriter()); } catch (JAXBException e) { this.logger.error(e.getMessage(), e.getCause()); httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } } // JSON-Ausgabe mit Jackson if (format.equals("json")) { httpServletResponse.setContentType("application/json;charset=UTF-8"); mapper.writeValue(httpServletResponse.getWriter(), documentList); } } else { // Error handling mit suppress_response_codes=true if (httpServletRequest.getParameter("suppress_response_codes") != null) { httpServletResponse.setStatus(HttpServletResponse.SC_OK); } // Error handling mit suppress_response_codes=false (=default) else { httpServletResponse.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } break; } case "items/ordered": { DocumentList documentList = integratedLibrarySystem.items(patronid, "ordered"); if (documentList != null) { StringWriter json = new StringWriter(); mapper = new ObjectMapper(); mapper.writeValue(json, documentList); this.logger.debug("[" + this.config.getProperty("service.name") + "] " + json); httpServletResponse.setHeader("X-Accepted-OAuth-Scopes", "read_items"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); if (format.equals("html")) { if (Lookup.lookupAll(ObjectToHtmlTransformation.class).size() > 0) { try { ObjectToHtmlTransformation htmlTransformation = Lookup .lookup(ObjectToHtmlTransformation.class); // init transformator htmlTransformation.init(this.config); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", language); parameters.put("service", service); httpServletResponse.setContentType("text/html;charset=UTF-8"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.getWriter() .println(htmlTransformation.transform(documentList, parameters)); } catch (TransformationException e) { httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message."); } } else { this.logger.error("ObjectToHtmlTransformation not configured! Switch to JSON."); format = "json"; } } // XML-Ausgabe mit JAXB if (format.equals("xml")) { try { JAXBContext context = JAXBContext.newInstance(DocumentList.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // Write to HttpResponse httpServletResponse.setContentType("application/xml;charset=UTF-8"); m.marshal(documentList, httpServletResponse.getWriter()); } catch (JAXBException e) { this.logger.error(e.getMessage(), e.getCause()); httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } } // JSON-Ausgabe mit Jackson if (format.equals("json")) { httpServletResponse.setContentType("application/json;charset=UTF-8"); mapper.writeValue(httpServletResponse.getWriter(), documentList); } } else { // Error handling mit suppress_response_codes=true if (httpServletRequest.getParameter("suppress_response_codes") != null) { httpServletResponse.setStatus(HttpServletResponse.SC_OK); } // Error handling mit suppress_response_codes=false (=default) else { httpServletResponse.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } break; } case "items/reserved": { DocumentList documentList = integratedLibrarySystem.items(patronid, "reserved"); if (documentList != null) { StringWriter json = new StringWriter(); mapper = new ObjectMapper(); mapper.writeValue(json, documentList); this.logger.debug("[" + this.config.getProperty("service.name") + "] " + json); httpServletResponse.setHeader("X-Accepted-OAuth-Scopes", "read_items"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); if (format.equals("html")) { if (Lookup.lookupAll(ObjectToHtmlTransformation.class).size() > 0) { try { ObjectToHtmlTransformation htmlTransformation = Lookup .lookup(ObjectToHtmlTransformation.class); // init transformator htmlTransformation.init(this.config); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", language); parameters.put("service", service); httpServletResponse.setContentType("text/html;charset=UTF-8"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.getWriter() .println(htmlTransformation.transform(documentList, parameters)); } catch (TransformationException e) { httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message."); } } else { this.logger.error("ObjectToHtmlTransformation not configured! Switch to JSON."); format = "json"; } } // XML-Ausgabe mit JAXB if (format.equals("xml")) { try { JAXBContext context = JAXBContext.newInstance(DocumentList.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // Write to HttpResponse httpServletResponse.setContentType("application/xml;charset=UTF-8"); m.marshal(documentList, httpServletResponse.getWriter()); } catch (JAXBException e) { this.logger.error(e.getMessage(), e.getCause()); httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } } // JSON-Ausgabe mit Jackson if (format.equals("json")) { httpServletResponse.setContentType("application/json;charset=UTF-8"); mapper.writeValue(httpServletResponse.getWriter(), documentList); } } else { // Error handling mit suppress_response_codes=true if (httpServletRequest.getParameter("suppress_response_codes") != null) { httpServletResponse.setStatus(HttpServletResponse.SC_OK); } // Error handling mit suppress_response_codes=false (=default) else { httpServletResponse.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } break; } case "request": { DocumentList documentList = integratedLibrarySystem.request(patronid, documents); if (documentList != null) { StringWriter json = new StringWriter(); mapper.writeValue(json, documentList); this.logger.debug("[" + this.config.getProperty("service.name") + "] " + json); // set Cookie with new value for urlencoded DocumentList-JSON StringWriter stringWriter = new StringWriter(); mapper.writeValue(stringWriter, documents); Cookie cookie = new Cookie("PaiaServiceDocumentList", URLEncoder.encode(stringWriter.toString(), "UTF-8")); if (this.config.getProperty("service.cookie.domain") != null && !this.config.getProperty("service.cookie.domain").equals("")) { cookie.setDomain(this.config.getProperty("service.cookie.domain")); } cookie.setMaxAge(-1); cookie.setPath("/"); httpServletResponse.addCookie(cookie); httpServletResponse.setHeader("X-Accepted-OAuth-Scopes", "write_items"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); if (format.equals("html")) { if (Lookup.lookupAll(ObjectToHtmlTransformation.class).size() > 0) { this.logger.info("redirect_url = " + redirect_url); if (!redirect_url.equals("")) { httpServletResponse.sendRedirect(redirect_url); } else { try { ObjectToHtmlTransformation htmlTransformation = Lookup .lookup(ObjectToHtmlTransformation.class); // init transformator htmlTransformation.init(this.config); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", language); parameters.put("service", service); httpServletResponse.setContentType("text/html;charset=UTF-8"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.getWriter() .println(htmlTransformation.transform(documentList, parameters)); } catch (TransformationException e) { httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message."); } } } else { this.logger.error("ObjectToHtmlTransformation not configured! Switch to JSON."); format = "json"; } } // XML-Ausgabe mit JAXB if (format.equals("xml")) { try { JAXBContext context = JAXBContext.newInstance(DocumentList.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // Write to HttpResponse httpServletResponse.setContentType("application/xml;charset=UTF-8"); m.marshal(documentList, httpServletResponse.getWriter()); } catch (JAXBException e) { this.logger.error(e.getMessage(), e.getCause()); httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } } // JSON-Ausgabe mit Jackson if (format.equals("json")) { httpServletResponse.setContentType("application/json;charset=UTF-8"); mapper.writeValue(httpServletResponse.getWriter(), documentList); } } else { // Error handling mit suppress_response_codes=true if (httpServletRequest.getParameter("suppress_response_codes") != null) { httpServletResponse.setStatus(HttpServletResponse.SC_OK); } // Error handling mit suppress_response_codes=false (=default) else { httpServletResponse.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } break; } case "renew": { DocumentList documentList = integratedLibrarySystem.renew(patronid, documents); if (documentList != null) { StringWriter json = new StringWriter(); mapper.writeValue(json, documentList); this.logger.debug("[" + this.config.getProperty("service.name") + "] " + json); // delete DocumentList cookie Cookie cookie = new Cookie("PaiaServiceDocumentList", null); if (this.config.getProperty("service.cookie.domain") != null && !this.config.getProperty("service.cookie.domain").equals("")) { cookie.setDomain(this.config.getProperty("service.cookie.domain")); } cookie.setMaxAge(0); httpServletResponse.addCookie(cookie); httpServletResponse.setHeader("X-Accepted-OAuth-Scopes", "write_items"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); if (format.equals("html")) { if (Lookup.lookupAll(ObjectToHtmlTransformation.class).size() > 0) { try { ObjectToHtmlTransformation htmlTransformation = Lookup .lookup(ObjectToHtmlTransformation.class); // init transformator htmlTransformation.init(this.config); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", language); parameters.put("service", service); httpServletResponse.setContentType("text/html;charset=UTF-8"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.getWriter() .println(htmlTransformation.transform(documentList, parameters)); } catch (TransformationException e) { httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message."); } } else { this.logger.error("ObjectToHtmlTransformation not configured! Switch to JSON."); format = "json"; } } // XML-Ausgabe mit JAXB if (format.equals("xml")) { try { JAXBContext context = JAXBContext.newInstance(DocumentList.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // Write to HttpResponse httpServletResponse.setContentType("application/xml;charset=UTF-8"); m.marshal(documentList, httpServletResponse.getWriter()); } catch (JAXBException e) { this.logger.error(e.getMessage(), e.getCause()); httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } } // JSON-Ausgabe mit Jackson if (format.equals("json")) { httpServletResponse.setContentType("application/json;charset=UTF-8"); mapper.writeValue(httpServletResponse.getWriter(), documentList); } } else { // Error handling mit suppress_response_codes=true if (httpServletRequest.getParameter("suppress_response_codes") != null) { httpServletResponse.setStatus(HttpServletResponse.SC_OK); } // Error handling mit suppress_response_codes=false (=default) else { httpServletResponse.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } break; } case "cancel": { DocumentList documentList = integratedLibrarySystem.cancel(patronid, documents); if (documentList != null) { StringWriter json = new StringWriter(); mapper.writeValue(json, documentList); this.logger.debug("[" + this.config.getProperty("service.name") + "] " + json); // delete DocumentList cookie Cookie cookie = new Cookie("PaiaServiceDocumentList", null); if (this.config.getProperty("service.cookie.domain") != null && !this.config.getProperty("service.cookie.domain").equals("")) { cookie.setDomain(this.config.getProperty("service.cookie.domain")); } cookie.setMaxAge(0); httpServletResponse.addCookie(cookie); httpServletResponse.setHeader("X-Accepted-OAuth-Scopes", "write_items"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); if (format.equals("html")) { if (Lookup.lookupAll(ObjectToHtmlTransformation.class).size() > 0) { try { ObjectToHtmlTransformation htmlTransformation = Lookup .lookup(ObjectToHtmlTransformation.class); // init transformator htmlTransformation.init(this.config); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", language); parameters.put("service", service); httpServletResponse.setContentType("text/html;charset=UTF-8"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.getWriter() .println(htmlTransformation.transform(documentList, parameters)); } catch (TransformationException e) { httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message."); } } else { this.logger.error("ObjectToHtmlTransformation not configured! Switch to JSON."); format = "json"; } } // XML-Ausgabe mit JAXB if (format.equals("xml")) { try { JAXBContext context = JAXBContext.newInstance(DocumentList.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // Write to HttpResponse httpServletResponse.setContentType("application/xml;charset=UTF-8"); m.marshal(documentList, httpServletResponse.getWriter()); } catch (JAXBException e) { this.logger.error(e.getMessage(), e.getCause()); httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } } // JSON-Ausgabe mit Jackson if (format.equals("json")) { httpServletResponse.setContentType("application/json;charset=UTF-8"); mapper.writeValue(httpServletResponse.getWriter(), documentList); } } else { // Error handling mit suppress_response_codes=true if (httpServletRequest.getParameter("suppress_response_codes") != null) { httpServletResponse.setStatus(HttpServletResponse.SC_OK); } // Error handling mit suppress_response_codes=false (=default) else { httpServletResponse.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } break; } case "fees": { FeeList feeList = integratedLibrarySystem.fees(patronid); if (feeList != null) { StringWriter json = new StringWriter(); mapper = new ObjectMapper(); mapper.writeValue(json, feeList); this.logger.debug("[" + this.config.getProperty("service.name") + "] " + json); httpServletResponse.setHeader("X-Accepted-OAuth-Scopes", "read_fees"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); if (format.equals("html")) { if (Lookup.lookupAll(ObjectToHtmlTransformation.class).size() > 0) { try { ObjectToHtmlTransformation htmlTransformation = Lookup .lookup(ObjectToHtmlTransformation.class); // init transformator htmlTransformation.init(this.config); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", language); parameters.put("service", service); httpServletResponse.setContentType("text/html;charset=UTF-8"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.getWriter() .println(htmlTransformation.transform(feeList, parameters)); } catch (TransformationException e) { httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message."); } } else { this.logger.error("ObjectToHtmlTransformation not configured! Switch to JSON."); format = "json"; } } // XML-Ausgabe mit JAXB if (format.equals("xml")) { try { JAXBContext context = JAXBContext.newInstance(FeeList.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // Write to HttpResponse httpServletResponse.setContentType("application/xml;charset=UTF-8"); m.marshal(feeList, httpServletResponse.getWriter()); } catch (JAXBException e) { this.logger.error(e.getMessage(), e.getCause()); httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } } // JSON-Ausgabe mit Jackson if (format.equals("json")) { httpServletResponse.setContentType("application/json;charset=UTF-8"); mapper.writeValue(httpServletResponse.getWriter(), feeList); } } else { // Error handling mit suppress_response_codes=true if (httpServletRequest.getParameter("suppress_response_codes") != null) { httpServletResponse.setStatus(HttpServletResponse.SC_OK); } // Error handling mit suppress_response_codes=false (=default) else { httpServletResponse.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } break; } } } catch (ILSException e) { StringWriter json = new StringWriter(); // TODO Frage nach "570-unknown patron" ist nicht gut! Lsung: Welche Typen von ILSExceptions treten auf? Erzeuge fr jeden Typ eine eigene Exception! if (e.getMessage().contains("570-unknown patron")) { this.logger.error("[" + this.config.getProperty("service.name") + "] " + HttpServletResponse.SC_NOT_FOUND + ": '" + patronid + "'"); // Error handling mit suppress_response_codes=true if (httpServletRequest.getParameter("suppress_response_codes") != null) { httpServletResponse.setStatus(HttpServletResponse.SC_OK); } // Error handling mit suppress_response_codes=false (=default) else { httpServletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError( this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_NOT_FOUND))); requestError.setCode(HttpServletResponse.SC_NOT_FOUND); requestError.setDescription(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_NOT_FOUND) + ".description")); requestError.setErrorUri(this.config .getProperty("error." + Integer.toString(HttpServletResponse.SC_NOT_FOUND) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } else { this.logger.error("[" + this.config.getProperty("service.name") + "] " + HttpServletResponse.SC_SERVICE_UNAVAILABLE + ": ILS!"); // Error handling mit suppress_response_codes=true if (httpServletRequest.getParameter("suppress_response_codes") != null) { httpServletResponse.setStatus(HttpServletResponse.SC_OK); } // Error handling mit suppress_response_codes=false (=default) else { httpServletResponse.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config .getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } } catch (Exception e) { e.printStackTrace(); } } else { this.logger.error("[" + this.config.getProperty("service.name") + "] " + HttpServletResponse.SC_SERVICE_UNAVAILABLE + ": Config Error!"); // Error handling mit suppress_response_codes=true if (httpServletRequest.getParameter("suppress_response_codes") != null) { httpServletResponse.setStatus(HttpServletResponse.SC_OK); } // Error handling mit suppress_response_codes=false (=default) else { httpServletResponse.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config .getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config .getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } }
From source file:com.ylife.shoppingcart.service.impl.ShoppingCartServiceImpl.java
/** * cookie?//from w w w . ja va2s . co m * * @param request * * @param response * * @return ? * @throws UnsupportedEncodingException */ public int delCookShopCar(Long productId, HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException { Integer count = 0; Cookie[] cookies = request.getCookies(); String oldCar = ""; String[] cars = null; String[] car = null; Cookie cook; String newMid = ""; StringBuilder bufOldCar = new StringBuilder(); StringBuilder bufNewMid = new StringBuilder(); try { if (null != cookies) { for (Cookie cookie : cookies) { if (null != cookie && NPSTORE_SHOPCAR.equals(cookie.getName())) { oldCar = URLDecoder.decode(cookie.getValue(), "utf-8"); if (oldCar.indexOf("," + productId + "-") != -1) { oldCar = oldCar.substring(1, oldCar.length()); oldCar = oldCar.substring(0, oldCar.length() - 1); cars = oldCar.split("e,"); oldCar = ""; for (int j = 0; j < cars.length; j++) { car = cars[j].split("-"); if (!car[0].equals(productId.toString())) { bufOldCar.append(oldCar); bufOldCar.append(","); bufOldCar.append(car[0]); bufOldCar.append("-"); bufOldCar.append(car[1]); bufOldCar.append("e"); oldCar += bufOldCar.toString(); } } } } if (cookie != null && NPSTORE_MID.equals(cookie.getName()) && cookie.getValue() != null && !"".equals(cookie.getValue())) { String[] mIds = cookie.getValue().split("-"); // ?cookie for (int j = 0; j < mIds.length; j++) { String[] mid = mIds[j].split("e"); // ?? if (mid[0] != null && !mid[0].equals(productId.toString())) { bufNewMid.append(mIds[j]); bufNewMid.append("-"); newMid += bufNewMid.toString(); } } } } } cook = new Cookie(NPSTORE_SHOPCAR, URLEncoder.encode(oldCar, "utf-8")); cook.setMaxAge(15 * 24 * 3600); cook.setPath("/"); response.addCookie(cook); Cookie cookie = new Cookie(NPSTORE_MID, URLEncoder.encode(newMid, "utf-8")); cookie.setMaxAge(15 * 24 * 3600); cookie.setPath("/"); response.addCookie(cookie); return count; } finally { cook = null; cars = null; car = null; cookies = null; oldCar = null; } }
From source file:de.innovationgate.wgpublisher.WGPDispatcher.java
public void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException { if (!isServePages()) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "Website is currently updating configuration. Please try again later."); return;/*w ww. j ava2s. c om*/ } Date startDate = new Date(); if (this._contextPath == null) { this._contextPath = request.getContextPath(); this._listenPort = request.getServerPort(); } WGARequestInformation reqInfo = (WGARequestInformation) request .getAttribute(WGARequestInformation.REQUEST_ATTRIBUTENAME); try { // Parse request WGPRequestPath path = WGPRequestPath.parseRequest(this, request, response); request.setAttribute(WGACore.ATTRIB_REQUESTPATH, path); // If database login failed or access was denied exit immediately if (!path.isProceedRequest()) { return; } // Set access logging for this request if (path.getDatabase() != null) { String accessLoggingEnabled = (String) path.getDatabase() .getAttribute(WGACore.DBATTRIB_ENABLE_ACCESSLOGGING); if (accessLoggingEnabled != null) { if (reqInfo != null) { reqInfo.setLoggingEnabled(Boolean.parseBoolean(accessLoggingEnabled)); } } } int iPathType = path.getPathType(); // Treatment of special URL types String dbKey = path.getDatabaseKey(); if (iPathType == WGPRequestPath.TYPE_INVALID) { throw new HttpErrorException(404, "Invalid path: " + path.getBasePath(), dbKey); } if (iPathType == WGPRequestPath.TYPE_INVALID_DB) { throw new HttpErrorException(404, "Specified application '" + dbKey + "' is unknown", null); } if (iPathType == WGPRequestPath.TYPE_UNKNOWN_CONTENT) { sendNoContentNotification(path, request, response, path.getDatabase()); return; } if (iPathType == WGPRequestPath.TYPE_GOTO_HOMEPAGE) { iPathType = determineHomepage(request, path, iPathType); } if (iPathType == WGPRequestPath.TYPE_UNAVAILABLE_DB) { throw new HttpErrorException(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "The website is currently unavailable", path.getDatabaseKey()); } if (iPathType == WGPRequestPath.TYPE_UNDEFINED_HOMEPAGE) { throw new HttpErrorException( HttpServletResponse.SC_NOT_FOUND, "No home page was defined for app '" + path.getDatabaseKey() + "'. Please specify an explicit content path.", path.getDatabaseKey()); } if (iPathType == WGPRequestPath.TYPE_TMLDEBUG) { _tmlDebugger.performDebugMode(request, response, request.getSession()); return; } if (iPathType == WGPRequestPath.TYPE_JOBLOG) { sendJobLog(request, response, request.getSession()); return; } if (iPathType == WGPRequestPath.TYPE_LOGOUT) { WGDatabase db = (WGDatabase) _core.getContentdbs().get(dbKey); String domain = (String) db.getAttribute(WGACore.DBATTRIB_DOMAIN); _core.logout(domain, request.getSession(), request, response, true); removeSessionCookie(response, request.getSession(), db); iPathType = WGPRequestPath.TYPE_REDIRECT; } if (iPathType == WGPRequestPath.TYPE_FAVICON) { String faviconPath = determineFavicon(request); if (faviconPath != null) { iPathType = WGPRequestPath.TYPE_REDIRECT; path.setResourcePath(faviconPath); } else { response.sendError(HttpServletResponse.SC_NOT_FOUND, "Favicon not defined"); return; } } if (iPathType == WGPRequestPath.TYPE_TMLFORM) { dispatchTmlFormRequest(path, request, response); return; } // Treatment of base URL Types if (iPathType == WGPRequestPath.TYPE_REDIRECT) { String url = path.getResourcePath(); if (path.appendQueryString() == true && request.getQueryString() != null && !request.getQueryString().equals("")) { if (url.indexOf("?") != -1) { url += "&" + request.getQueryString(); } else { url += "?" + request.getQueryString(); } } if (path.isPermanentRedirect()) { sendPermanentRedirect(response, url); } else { sendRedirect(request, response, url); } } else if (iPathType != WGPRequestPath.TYPE_RESOURCE && iPathType != WGPRequestPath.TYPE_STATICTML && !_core.getContentdbs().containsKey(path.getDatabaseKey())) { throw new HttpErrorException(404, "Database '" + dbKey + "' is unknown", null); } else { String requestMethod = request.getMethod().toLowerCase(); switch (iPathType) { case (WGPRequestPath.TYPE_TML): case (WGPRequestPath.TYPE_TITLE_PATH): // Fetch the redirect cookie Cookie lastRedirectCookie = null; Cookie[] cookies = request.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if (cookie.getName().equals(COOKIE_LASTREDIRECT)) { lastRedirectCookie = cookie; break; } } } // If path is not complete redirect it to the complete path, if possible. Set redirect cookie to prevent endless redirections if (!path.isCompletePath()) { String redirectPath = path.expandToCompletePath(request); if (isRedirectable(request, redirectPath, lastRedirectCookie)) { lastRedirectCookie = new WGCookie(COOKIE_LASTREDIRECT, Hex.encodeHexString(redirectPath.getBytes("UTF-8"))); lastRedirectCookie.setMaxAge(-1); lastRedirectCookie.setPath("/"); ((WGCookie) lastRedirectCookie).addCookieHeader(response); sendRedirect(request, response, redirectPath); break; } } // Delete redirect cookie when exists on normal dispatching if (lastRedirectCookie != null) { lastRedirectCookie = new WGCookie(COOKIE_LASTREDIRECT, ""); lastRedirectCookie.setMaxAge(0); lastRedirectCookie.setPath("/"); ((WGCookie) lastRedirectCookie).addCookieHeader(response); } // Dispatch dispatchTmlRequest(path, request, response, startDate); break; case (WGPRequestPath.TYPE_FILE): dispatchFileRequest(path, request, response); break; case (WGPRequestPath.TYPE_CSS): case (WGPRequestPath.TYPE_JS): dispatchCssjsRequest(path, request, response); break; case (WGPRequestPath.TYPE_RESOURCE): dispatchResourceRequest(path, request, response); break; case (WGPRequestPath.TYPE_STATICTML): dispatchStaticTmlRequest(path, request, response); break; default: throw new HttpErrorException(500, "Invalid url format", dbKey); } } // moved from finally block to ensure errorpage can be displayed commitResponse(response); } catch (ClientAccessException exc) { response.sendError(403, exc.getMessage()); } catch (AjaxFailureException exc) { handleAjaxFailure(exc, request, response); } catch (HttpErrorException exc) { request.setAttribute(WGACore.ATTRIB_EXCEPTION, exc); ProblemOccasion occ = new PathDispatchingOccasion(request, exc.getDbHint()); _core.getProblemRegistry().addProblem( Problem.create(occ, "dispatching.http404#" + request.getRequestURL(), ProblemSeverity.LOW)); if (!response.isCommitted()) { // throw exception to display errorpage - with senderror() the // applicationserver use the buildin errorpage if (exc.getCode() == HttpServletResponse.SC_NOT_FOUND || exc.getCode() == HttpServletResponse.SC_FORBIDDEN || exc.getCode() == HttpServletResponse.SC_PRECONDITION_FAILED) { response.sendError(exc.getCode(), exc.getMessage()); } else { _log.error("Exception in processing request from " + request.getRemoteAddr() + " to URL " + String.valueOf(request.getRequestURL())); throw new ServletException(exc); } } } catch (SocketException exc) { _log.warn("Socket Exception: " + exc.getMessage()); } catch (Exception exc) { _log.error("Exception in processing of request URL " + String.valueOf(request.getRequestURL()), exc); request.setAttribute(WGACore.ATTRIB_EXCEPTION, exc); throw new ServletException(exc); } catch (Error err) { _log.error("Error in processing of request URL " + String.valueOf(request.getRequestURL()), err); request.setAttribute(WGACore.ATTRIB_EXCEPTION, err); throw new ServletException(err); } finally { if (reqInfo != null) { reqInfo.setCommited(true); } } }
From source file:com.ylife.shoppingcart.service.impl.ShoppingCartServiceImpl.java
/** * /* w w w . ja va2 s . c o m*/ * * @param shoppingCart * @return int * @throws UnsupportedEncodingException */ @Override @Transactional public int addShoppingCart(ShoppingCart shoppingCart, HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException { Long custId = (Long) request.getSession().getAttribute(CUSTOMERID); if (null != custId) { Map<String, Object> map = new HashMap<>(); map.put("customerId", custId); int sum = shoppingCartMapper.selectSumByCustomerId(map); if (sum >= 20) { return -1; } shoppingCart.setCustomerId(custId); shoppingCart.setDelFlag("0"); shoppingCart.setShoppingCartTime(new Date()); int count = shoppingCartMapper.selectCountByReady(shoppingCart); if (count == 0) { return shoppingCartMapper.addShoppingCart(shoppingCart); } else { ShoppingCart sc = shoppingCartMapper.selectShopingByParam(shoppingCart); // ? if (sc.getGoodsNum() == 99) { return 0; } return shoppingCartMapper.updateShoppingCart(shoppingCart); } } else { num = ""; Cookie[] cookies = request.getCookies(); String oldCar = ""; String mId = ""; Cookie cook; if (null != cookies) { for (Cookie cookie : cookies) { if (null != cookie && NPSTORE_SHOPCAR.equals(cookie.getName())) { oldCar = URLDecoder.decode(cookie.getValue(), "utf-8"); if (oldCar.indexOf("," + shoppingCart.getGoodsInfoId() + "-") != -1) { num = oldCar.substring(oldCar.indexOf("," + shoppingCart.getGoodsInfoId() + "-"), oldCar.indexOf("," + shoppingCart.getGoodsInfoId() + "-") + oldCar .substring(oldCar.indexOf("," + shoppingCart.getGoodsInfoId() + "-"), oldCar.length() - 1) .indexOf("&")); num = num.substring(num.indexOf("-") + 1, num.length()); oldCar = oldCar.replace("," + shoppingCart.getGoodsInfoId() + "-" + num + "&" + shoppingCart.getDistinctId() + "e", ""); if (oldCar.indexOf("," + shoppingCart.getGoodsInfoId() + "-" + num + "&" + shoppingCart.getDistinctId()) != -1) { oldCar = oldCar.replace("," + shoppingCart.getGoodsInfoId() + "-" + num + "&" + shoppingCart.getDistinctId(), ""); } } } if (cookie != null && NPSTORE_MID.equals(cookie.getName()) && cookie.getValue() != null && !"".equals(cookie.getValue())) { String[] mIds = cookie.getValue().split("-"); // ?cookie for (int j = 0; j < mIds.length; j++) { String[] mid = mIds[j].split("e"); // ?? if (mid[0] != null && "".equals(mIds[0]) && !mid[0].equals(shoppingCart.getGoodsInfoId().toString())) { mId = cookie.getValue(); } } } } } if (!"".equals(num)) { num = String.valueOf(Long.parseLong(num) + shoppingCart.getGoodsNum()); } else { num = String.valueOf(shoppingCart.getGoodsNum()); } oldCar += "," + shoppingCart.getGoodsInfoId() + "-" + num + "&" + shoppingCart.getDistinctId() + "e"; GoodsDetailBean goodsDetailBean = null; if (shoppingCart.getFitId() == null) { goodsDetailBean = goodsProductService.queryDetailBeanByProductId(shoppingCart.getGoodsInfoId(), Long.parseLong("0"), null); } cook = new Cookie(NPSTORE_SHOPCAR, URLEncoder.encode(oldCar, "utf-8")); cook.setMaxAge(15 * 24 * 3600); cook.setPath("/"); response.addCookie(cook); Cookie cookie = new Cookie(NPSTORE_MID, mId); cookie.setMaxAge(15 * 24 * 3600); cookie.setPath("/"); response.addCookie(cookie); return 1; } }
From source file:com.xpn.xwiki.XWiki.java
/** * First try to find the current language in use from the XWiki context. If none is used and if the wiki is not * multilingual use the default language defined in the XWiki preferences. If the wiki is multilingual try to get * the language passed in the request. If none was passed try to get it from a cookie. If no language cookie exists * then use the user default language and barring that use the browser's "Accept-Language" header sent in HTTP * request. If none is defined use the default language. * /* www. j a v a 2 s . c o m*/ * @return the language to use */ public String getLanguagePreference(XWikiContext context) { // First we try to get the language from the XWiki Context. This is the current language // being used. String language = context.getLanguage(); if (language != null) { return language; } String defaultLanguage = getDefaultLanguage(context); // If the wiki is non multilingual then the language is the default language. if (!context.getWiki().isMultiLingual(context)) { language = defaultLanguage; context.setLanguage(language); return language; } // As the wiki is multilingual try to find the language to use from the request by looking // for a language parameter. If the language value is "default" use the default language // from the XWiki preferences settings. Otherwise set a cookie to remember the language // in use. try { language = Util.normalizeLanguage(context.getRequest().getParameter("language")); if ((language != null) && (!language.equals(""))) { if (language.equals("default")) { // forgetting language cookie Cookie cookie = new Cookie("language", ""); cookie.setMaxAge(0); cookie.setPath("/"); context.getResponse().addCookie(cookie); language = defaultLanguage; } else { // setting language cookie Cookie cookie = new Cookie("language", language); cookie.setMaxAge(60 * 60 * 24 * 365 * 10); cookie.setPath("/"); context.getResponse().addCookie(cookie); } context.setLanguage(language); return language; } } catch (Exception e) { } // As no language parameter was passed in the request, try to get the language to use // from a cookie. try { // First we get the language from the cookie language = Util.normalizeLanguage(getUserPreferenceFromCookie("language", context)); if ((language != null) && (!language.equals(""))) { context.setLanguage(language); return language; } } catch (Exception e) { } // Next from the default user preference try { String user = context.getUser(); XWikiDocument userdoc = null; userdoc = getDocument(user, context); if (userdoc != null) { language = Util.normalizeLanguage(userdoc.getStringValue("XWiki.XWikiUsers", "default_language")); if (!language.equals("")) { context.setLanguage(language); return language; } } } catch (XWikiException e) { } // If the default language is preferred, and since the user didn't explicitly ask for a // language already, then use the default wiki language. if (Param("xwiki.language.preferDefault", "0").equals("1") || getSpacePreference("preferDefaultLanguage", "0", context).equals("1")) { language = defaultLanguage; context.setLanguage(language); return language; } // Then from the navigator language setting if (context.getRequest() != null) { String acceptHeader = context.getRequest().getHeader("Accept-Language"); // If the client didn't specify some languages, skip this phase if ((acceptHeader != null) && (!acceptHeader.equals(""))) { List<String> acceptedLanguages = getAcceptedLanguages(context.getRequest()); // We can force one of the configured languages to be accepted if (Param("xwiki.language.forceSupported", "0").equals("1")) { List<String> available = Arrays.asList(getXWikiPreference("languages", context).split("[, |]")); // Filter only configured languages acceptedLanguages.retainAll(available); } if (acceptedLanguages.size() > 0) { // Use the "most-preferred" language, as requested by the client. context.setLanguage(acceptedLanguages.get(0)); return acceptedLanguages.get(0); } // If none of the languages requested by the client is acceptable, skip to next // phase (use default language). } } // Finally, use the default language from the global preferences. context.setLanguage(defaultLanguage); return defaultLanguage; }
From source file:com.xpn.xwiki.XWiki.java
public String getDocLanguagePreferenceNew(XWikiContext context) { // Get context language String contextLanguage = context.getLanguage(); // If the language exists in the context, it was previously set by another call if (contextLanguage != null && contextLanguage != "") { return contextLanguage; }//from w w w . j a v a 2 s . c o m String language = "", requestLanguage = "", userPreferenceLanguage = "", navigatorLanguage = "", cookieLanguage = ""; boolean setCookie = false; if (!context.getWiki().isMultiLingual(context)) { language = context.getWiki().getXWikiPreference("default_language", "", context); context.setLanguage(language); return language; } // Get request language try { requestLanguage = Util.normalizeLanguage(context.getRequest().getParameter("language")); } catch (Exception ex) { } // Get user preference try { String user = context.getUser(); XWikiDocument userdoc = getDocument(user, context); if (userdoc != null) { userPreferenceLanguage = userdoc.getStringValue("XWiki.XWikiUsers", "default_language"); } } catch (XWikiException e) { } // Get navigator language setting if (context.getRequest() != null) { String accept = context.getRequest().getHeader("Accept-Language"); if ((accept != null) && (!accept.equals(""))) { String[] alist = StringUtils.split(accept, ",;-"); if ((alist != null) && !(alist.length == 0)) { context.setLanguage(alist[0]); navigatorLanguage = alist[0]; } } } // Get language from cookie try { cookieLanguage = Util.normalizeLanguage(getUserPreferenceFromCookie("language", context)); } catch (Exception e) { } // Determine which language to use // First we get the language from the request if ((requestLanguage != null) && (!requestLanguage.equals(""))) { if (requestLanguage.equals("default")) { setCookie = true; } else { language = requestLanguage; context.setLanguage(language); Cookie cookie = new Cookie("language", language); cookie.setMaxAge(60 * 60 * 24 * 365 * 10); cookie.setPath("/"); context.getResponse().addCookie(cookie); return language; } } // Next we get the language from the cookie if (cookieLanguage != null && cookieLanguage != "") { language = cookieLanguage; } // Next from the default user preference else if (userPreferenceLanguage != null && userPreferenceLanguage != "") { language = userPreferenceLanguage; } // Then from the navigator language setting else if (navigatorLanguage != null && navigatorLanguage != "") { language = navigatorLanguage; } context.setLanguage(language); if (setCookie) { Cookie cookie = new Cookie("language", language); cookie.setMaxAge(60 * 60 * 24 * 365 * 10); cookie.setPath("/"); context.getResponse().addCookie(cookie); } return language; }
From source file:com.xpn.xwiki.XWiki.java
public String getInterfaceLanguagePreference(XWikiContext context) { String language = "", requestLanguage = "", userPreferenceLanguage = "", navigatorLanguage = "", cookieLanguage = "", contextLanguage = ""; boolean setCookie = false; if (!context.getWiki().isMultiLingual(context)) { language = Util//from www . j a va2 s .c o m .normalizeLanguage(context.getWiki().getXWikiPreference("default_language", "", context)); context.setInterfaceLanguage(language); return language; } // Get request language try { requestLanguage = Util.normalizeLanguage(context.getRequest().getParameter("interfacelanguage")); } catch (Exception ex) { } // Get context language contextLanguage = context.getInterfaceLanguage(); // Get user preference try { String user = context.getUser(); XWikiDocument userdoc = null; userdoc = getDocument(user, context); if (userdoc != null) { userPreferenceLanguage = userdoc.getStringValue("XWiki.XWikiUsers", "default_interface_language"); } } catch (XWikiException e) { } // Get navigator language setting if (context.getRequest() != null) { String accept = context.getRequest().getHeader("Accept-Language"); if ((accept != null) && (!accept.equals(""))) { String[] alist = StringUtils.split(accept, ",;-"); if ((alist != null) && !(alist.length == 0)) { context.setLanguage(alist[0]); navigatorLanguage = alist[0]; } } } // Get language from cookie try { cookieLanguage = Util.normalizeLanguage(getUserPreferenceFromCookie("interfacelanguage", context)); } catch (Exception e) { } // Determine which language to use // First we get the language from the request if ((requestLanguage != null) && (!requestLanguage.equals(""))) { if (requestLanguage.equals("default")) { setCookie = true; } else { language = requestLanguage; context.setLanguage(language); Cookie cookie = new Cookie("interfacelanguage", language); cookie.setMaxAge(60 * 60 * 24 * 365 * 10); cookie.setPath("/"); context.getResponse().addCookie(cookie); return language; } } // Next we get the language from the context if (contextLanguage != null && contextLanguage != "") { language = contextLanguage; } // Next we get the language from the cookie else if (cookieLanguage != null && cookieLanguage != "") { language = cookieLanguage; } // Next from the default user preference else if (userPreferenceLanguage != null && userPreferenceLanguage != "") { language = userPreferenceLanguage; } // Then from the navigator language setting else if (navigatorLanguage != null && navigatorLanguage != "") { language = navigatorLanguage; } context.setLanguage(language); if (setCookie) { Cookie cookie = new Cookie("interfacelanguage", language); cookie.setMaxAge(60 * 60 * 24 * 365 * 10); cookie.setPath("/"); context.getResponse().addCookie(cookie); } return language; }