List of usage examples for javax.servlet.jsp PageContext getRequest
abstract public ServletRequest getRequest();
From source file:com.redhat.rhn.frontend.taglibs.list.AlphaBarHelper.java
/** * Write the alpha bar to the current pageContext * @param pageContext the pageContext to write to * @param activeChars a Set of characters that are active in the alpha bar * @param listName the name of the list to write the alpha bar for. * @throws JspException jspException from the super class *//* w ww.j a va 2s .c o m*/ public void writeAlphaBar(PageContext pageContext, Set<Character> activeChars, String listName) throws JspException { ListTagUtil.write(pageContext, "<ul class=\"spacewalk-alphabar pagination pagination-sm\">"); List<String> alphabet = LocalizationService.getInstance().getAlphabet(); List<String> numbers = LocalizationService.getInstance().getDigits(); for (String numberString : numbers) { char number = numberString.charAt(0); if (activeChars.contains(number)) { ListTagUtil.write(pageContext, renderEnabledAlpha(number, listName, pageContext.getRequest())); } else { ListTagUtil.write(pageContext, renderDisabledAlph(number)); } } for (String letterString : alphabet) { char letter = letterString.charAt(0); if (activeChars.contains(letter)) { ListTagUtil.write(pageContext, renderEnabledAlpha(letter, listName, pageContext.getRequest())); } else { ListTagUtil.write(pageContext, renderDisabledAlph(letter)); } } ListTagUtil.write(pageContext, "</ul>"); }
From source file:com.nec.nsgui.action.statis.STDataRender4NasSwitch.java
public String getCellRender(int rowIndex, String colName) throws Exception { PageContext context = getSortTagInfo().getPageContext(); AbstractList exportsList = ((ListSTModel) getTableModel()).getDataList(); NasSwitchSubItemInfoBean exportObj = (NasSwitchSubItemInfoBean) exportsList.get(rowIndex); String isWhichNode = exportObj.getIsWhichNode(); String checked = ""; List subItemList_checked = (List) NSActionUtil.getSessionAttribute( (HttpServletRequest) context.getRequest(), SESSION_STATIS_NASSWITCH_SUBITEMLIST_CHECKED); if (subItemList_checked != null) { for (int i = 0; i < subItemList_checked.size(); i++) { NasSwitchSubItemInfoBean temp = (NasSwitchSubItemInfoBean) subItemList_checked.get(i); if (exportObj.getSubItem().equals(temp.getSubItem())) { checked = "checked"; break; }/* ww w . j a va 2 s . c o m*/ } } if (colName.equals("subItemCheckbox")) { StringBuffer cellStr = new StringBuffer( "<input name=\"subItemCheckbox\" type=\"checkbox\" " + " value=\""); cellStr.append(exportObj.getSequence()); cellStr.append("\" id=\"subItemCheckbox" + rowIndex); cellStr.append("\" " + checked); cellStr.append(" onClick=\"return checkNum("); cellStr.append(");\">"); cellStr.append("<script language=\"javascript\">"); cellStr.append("subItem['" + exportObj.getSequence() + "']='" + exportObj.getInterval() + "';"); cellStr.append("</script>"); if (isWhichNode.equals("both")) { return "<td nowrap align=center rowspan=\"2\">" + cellStr.toString() + "</td>"; } else { return "<td nowrap align=center>" + cellStr.toString() + "</td>"; } } if (colName.equals("subItem")) { String subItem = NSActionUtil .sanitize(NSActionUtil.perl2Page(exportObj.getSubItem(), NSActionConst.ENCODING_EUC_JP)); if (isWhichNode.equals("both")) { return "<td nowrap align=left rowspan=\"2\">" + "<label for=\"subItemCheckbox" + rowIndex + "\">" + subItem + "</label>" + "</td>"; } else { return "<td nowrap align=left>" + "<label for=\"subItemCheckbox" + rowIndex + "\">" + subItem + "</label>" + "</td>"; } } if (colName.equals("node")) { String node_message = ""; String collectionId = (String) NSActionUtil .getSessionAttribute((HttpServletRequest) context.getRequest(), SESSION_COLLECTION_ID); if (collectionId.trim().equals(NSW_NFS_Virtual_Export)) { node_message = TagUtils.getInstance().message(context, null, null, "statis.nasswitch.group"); } if (collectionId.trim().equals(NSW_NFS_Server)) { node_message = TagUtils.getInstance().message(context, null, null, "statis.nasswitch.node"); } if (isWhichNode.equals("both") || isWhichNode.equals("group0")) return "<td nowrap align=left>" + node_message + "0</td>"; if (isWhichNode.equals("both") || isWhichNode.equals("group1")) return "<td nowrap align=left>" + node_message + "1</td>"; } if (colName.equals("access_average") || colName.equals("access_max") || colName.equals("response_average") || colName.equals("response_max") || colName.equals("rover_average") || colName.equals("rover_max")) { NasSwitchMaxAverBean nodeInfo = new NasSwitchMaxAverBean(); if (isWhichNode.equals("both") || isWhichNode.equals("group0")) { nodeInfo = exportObj.getBean4Node0(); } else { nodeInfo = exportObj.getBean4Node1(); } String content = PropertyUtils.getProperty(nodeInfo, colName).toString(); if (content.equals("--")) { return "<td nowrap align=center>" + content + "</td>"; } else { return "<td nowrap align=right>" + content + "</td>"; } } if (colName.equals("stockPeriod")) { String stockPeriod = exportObj.getStockPeriod(); if (!isWhichNode.equals("both") && stockPeriod.trim().equals("--")) { return "<td nowrap align=center>" + stockPeriod + "</td>"; } else if (!isWhichNode.equals("both") && !stockPeriod.trim().equals("--")) { return "<td nowrap align=right>" + stockPeriod + "</td>"; } else if (isWhichNode.equals("both") && stockPeriod.trim().equals("--")) { return "<td nowrap align=center rowspan=\"2\">" + stockPeriod + "</td>"; } else if (isWhichNode.equals("both") && !stockPeriod.trim().equals("--")) { return "<td nowrap align=right rowspan=\"2\">" + stockPeriod + "</td>"; } } if (colName.equals("interval")) { String interval = exportObj.getInterval(); StringBuffer cell = new StringBuffer(); if (!isWhichNode.equals("both") && interval.trim().equals("--")) { return "<td nowrap align=center>" + interval + "</td>"; } else if (!isWhichNode.equals("both") && !interval.trim().equals("--")) { return "<td nowrap align=right>" + Integer.parseInt(interval) / 60 + "</td>"; } else if (isWhichNode.equals("both") && interval.trim().equals("--")) { cell.append("<td nowrap align=center rowspan=\"2\">" + interval + "</td>"); } else if (isWhichNode.equals("both") && !interval.trim().equals("--")) { cell.append("<td nowrap align=right rowspan=\"2\">" + Integer.parseInt(interval) / 60 + "</td>"); } if (isWhichNode.equals("both")) { NasSwitchMaxAverBean node1Info = exportObj.getBean4Node1(); String access_average = node1Info.getAccess_average(); String access_max = node1Info.getAccess_max(); String response_average = node1Info.getResponse_average(); String response_max = node1Info.getResponse_max(); String rover_average = node1Info.getRover_average(); String rover_max = node1Info.getRover_max(); String node_message = ""; String collectionId = (String) NSActionUtil .getSessionAttribute((HttpServletRequest) context.getRequest(), SESSION_COLLECTION_ID); if (collectionId.equals(NSW_NFS_Virtual_Export)) { node_message = TagUtils.getInstance().message(context, null, null, "statis.nasswitch.group"); } if (collectionId.equals(NSW_NFS_Server)) { node_message = TagUtils.getInstance().message(context, null, null, "statis.nasswitch.node"); } cell.append("</tr><tr><td nowrap align=center>"); cell.append(node_message); cell.append("1</td>"); if (access_average.equals("--")) { cell.append("<td nowrap align=center>" + access_average + "</td>"); } else { cell.append("<td nowrap align=right>" + access_average + "</td>"); } if (access_max.equals("--")) { cell.append("<td nowrap align=center>" + access_max + "</td>"); } else { cell.append("<td nowrap align=right>" + access_max + "</td>"); } if (response_average.equals("--")) { cell.append("<td nowrap align=center>" + response_average + "</td>"); } else { cell.append("<td nowrap align=right>" + response_average + "</td>"); } if (response_max.equals("--")) { cell.append("<td nowrap align=center>" + response_max + "</td>"); } else { cell.append("<td nowrap align=right>" + response_max + "</td>"); } if (rover_average.equals("--")) { cell.append("<td nowrap align=center>" + rover_average + "</td>"); } else { cell.append("<td nowrap align=right>" + rover_average + "</td>"); } if (rover_max.equals("--")) { cell.append("<td nowrap align=center>" + rover_max + "</td>"); } else { cell.append("<td nowrap align=right>" + rover_max + "</td>"); } } return cell.toString(); } return ""; }
From source file:net.ontopia.topicmaps.nav2.servlets.TreeWidget.java
/** * EXPERIMENTAL: Runs the widget, producing the output. *///from w ww. j av a2 s. co m public void run(PageContext ctxt, Writer writer) throws IOException, InvalidQueryException, NavigatorRuntimeException { context = FrameworkUtils.getContextTag(ctxt); HttpServletRequest request = (HttpServletRequest) ctxt.getRequest(); Map parameters = request.getParameterMap(); // check that query has been parsed if (query == null) query = processor.parse(querystr); // get current node TopicIF current = null; if (parameters.containsKey("current")) current = getTopic(get(parameters, "current")); int action = getAction(parameters); if (action == EXPAND_ALL) openNodes = new UniversalSet(); else if (action == CLOSE_ALL) openNodes = new HashSet(); else { openNodes = getOpenNodes(request); if (action == OPEN) openNodes.add(current); else if (action == CLOSE) openNodes.remove(current); } int topline = 0; if (parameters.containsKey("topline")) { try { topline = Integer.parseInt(get(parameters, "topline")); } catch (NumberFormatException e) { } } try { doQuery(topline, writer); } catch (InvalidQueryException e) { throw new net.ontopia.utils.OntopiaRuntimeException(e); } setOpenNodes(request, openNodes); }
From source file:com.jslsolucoes.tagria.lib.tag.html.GridTag.java
@Override public void doTag() throws JspException, IOException { if (rendered != null && rendered) { PageContext pageContext = (PageContext) getJspContext(); HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); if (simple) { search = Boolean.FALSE; export = Boolean.FALSE; paginate = Boolean.FALSE; }/*w w w.j a va 2 s.co m*/ TagUtil.flushBody(getJspBody()); Div grid = new Div(); grid.add(Attribute.ID, TagUtil.getId()); Div panel = new Div(); panel.add(Attribute.CLASS, "panel panel-primary"); if (!StringUtils.isEmpty(label)) { Div panelHead = new Div(); panelHead.add(Attribute.CLASS, "panel-heading"); H3 h3 = new H3(); h3.add(Attribute.CLASS, "panel-title"); h3.add(TagUtil.getLocalized(label, getJspContext())); panelHead.add(h3); panel.add(panelHead); } Div panelBody = new Div(); panelBody.add(Attribute.CLASS, "panel-body"); if (checkAll) { Div checkAllBox = new Div(); checkAllBox.add(Attribute.CLASS, "m-5"); Ul ul = new Ul(); ul.add(Attribute.CLASS, "list-group"); Li li = new Li(); li.add(Attribute.CLASS, "list-group-item"); Input input = new Input(); input.add(Attribute.TYPE, "checkbox"); input.add(Attribute.CLASS, "bs-grid-check-all"); li.add(input); li.add(" " + TagUtil.getLocalizedForLib("grid.check.all", getJspContext())); ul.add(li); checkAllBox.add(ul); panelBody.add(checkAllBox); } panel.add(panelBody); Div div = new Div(); div.add(Attribute.CLASS, "clearfix"); if (!StringUtils.isEmpty(toolbar)) { Div divForToolbar = new Div(); divForToolbar.add(Attribute.CLASS, "pull-left m-5 bs-button-group"); divForToolbar.add(toolbar); div.add(divForToolbar); } panelBody.add(div); if (!CollectionUtils.isEmpty(data)) { if (totalResults == null) { totalResults = data.size(); } if (export) { Div divForExportation = new Div(); divForExportation.add(Attribute.CLASS, "pull-right m-5"); Div buttonGroup = new Div(); buttonGroup.add(Attribute.CLASS, "btn-group"); Button pdf = new Button(); pdf.add(Attribute.CLASS, "btn btn-default waves-effect waves-light bs-grid-export-pdf"); pdf.add(Attribute.TITLE, TagUtil.getLocalizedForLib("grid.export.pdf", getJspContext())); pdf.add(new Span().add(Attribute.CLASS, "fa fa-file-pdf-o")); buttonGroup.add(pdf); Button excel = new Button(); excel.add(Attribute.CLASS, "btn btn-default waves-effect waves-light bs-grid-export-excel"); excel.add(Attribute.TITLE, TagUtil.getLocalizedForLib("grid.export.xls", getJspContext())); excel.add(new Span().add(Attribute.CLASS, "fa fa-file-excel-o")); buttonGroup.add(excel); Button csv = new Button(); csv.add(Attribute.CLASS, "btn btn-default waves-effect waves-light bs-grid-export-csv"); csv.add(Attribute.TITLE, TagUtil.getLocalizedForLib("grid.export.csv", getJspContext())); csv.add(new Span().add(Attribute.CLASS, "fa fa-file-text-o")); buttonGroup.add(csv); Button xml = new Button(); xml.add(Attribute.CLASS, "btn btn-default waves-effect waves-light bs-grid-export-xml"); xml.add(Attribute.TITLE, TagUtil.getLocalizedForLib("grid.export.xml", getJspContext())); xml.add(new Span().add(Attribute.CLASS, "fa fa-file-code-o")); buttonGroup.add(xml); divForExportation.add(buttonGroup); div.add(divForExportation); } if (search) { Div divForSearch = new Div(); divForSearch.add(Attribute.CLASS, "pull-right m-5"); Input input = new Input(); input.add(Attribute.TYPE, "search"); input.add(Attribute.CLASS, "bs-grid-search form-control"); input.add(Attribute.PLACEHOLDER, TagUtil.getLocalizedForLib("grid.search", getJspContext())); divForSearch.add(input); div.add(divForSearch); } Table table = new Table(); table.add(Attribute.CLASS, "table table-striped table-hover"); Thead thead = new Thead(); Tr tr = new Tr(); thead.add(tr); tr.add(this.ths); table.add(thead); Tbody tbody = new Tbody(); int index = 0; for (Object row : data) { getJspContext().setAttribute(var, row); if (!StringUtils.isEmpty(varStatus)) { getJspContext().setAttribute(varStatus, index); } Tr line = new Tr(); line.add(TagUtil.getBody(getJspBody())); tbody.add(line); index++; } getJspContext().setAttribute(var, null); if (!StringUtils.isEmpty(varStatus)) { getJspContext().setAttribute(varStatus, null); } table.add(tbody); panelBody.add(table); if (!simple) { Div panelFooter = new Div(); panelFooter.add(Attribute.CLASS, "panel-footer"); Div clearfix = new Div(); clearfix.add(Attribute.CLASS, "clearfix"); Integer page = (request.getParameter("page") != null ? Integer.valueOf(request.getParameter("page")) : 1); Integer resultsPerPage = (request.getParameter("resultsPerPage") != null ? Integer.valueOf(request.getParameter("resultsPerPage")) : this.resultsPerPage); Integer toResult = page * resultsPerPage; Integer fromResult = (toResult + 1) - resultsPerPage; if (toResult >= totalResults) { toResult = totalResults; } Div display = new Div(); display.add(Attribute.CLASS, "pull-left m-5"); display.add(new H5().add(TagUtil.getLocalizedForLib("grid.page.viewing", getJspContext(), fromResult, toResult, totalResults))); clearfix.add(display); if (paginate) { Div divForResultsPerPage = new Div(); divForResultsPerPage.add(Attribute.CLASS, "pull-right m-5"); Div dropdown = new Div(); dropdown.add(Attribute.CLASS, "dropup"); dropdown.add(Attribute.TITLE, TagUtil.getLocalizedForLib("grid.results.per.page", getJspContext())); Button button = new Button(); button.add(Attribute.CLASS, "btn btn-default waves-effect waves-light dropdown-toggle"); button.add(Attribute.DATA_TOGGLE, "dropdown"); button.add(" " + resultsPerPage + " "); Span span = new Span(); span.add(Attribute.CLASS, "caret"); button.add(span); dropdown.add(button); Ul results = new Ul(); results.add(Attribute.CLASS, "dropdown-menu dropdown-menu-right"); Integer iteration = 100; while (iteration >= 20) { Li li = new Li(); li.add(Attribute.CLASS, "bs-grid-results-per-page-item"); if (iteration == resultsPerPage) { li.add(Attribute.CLASS, "active"); } A a = new A(); a.add(Attribute.HREF, "#"); a.add(String.valueOf(iteration)); li.add(a); results.add(li); iteration -= 20; } dropdown.add(results); divForResultsPerPage.add(dropdown); clearfix.add(divForResultsPerPage); Integer totalOfPages = (int) Math .ceil(Double.valueOf(totalResults) / Double.valueOf(resultsPerPage)); Div pagination = new Div(); pagination.add(Attribute.CLASS, "pull-right m-5"); Nav nav = new Nav(); nav.add(Attribute.CLASS, "pull-left"); Ul ul = new Ul(); ul.add(Attribute.CLASS, "pagination"); for (int i = 1; i <= totalOfPages; i++) { Li li = new Li(); li.add(Attribute.CLASS, "bs-grid-paginate-item"); if (i == page) { li.add(Attribute.CLASS, "active"); } A a = new A(); a.add(Attribute.HREF, "#"); a.add(String.valueOf(i)); li.add(a); ul.add(li); } nav.add(ul); pagination.add(nav); clearfix.add(pagination); } panelFooter.add(clearfix); panel.add(panelFooter); } } else { Div noRow = new Div(); noRow.add(Attribute.CLASS, "alert alert-info"); noRow.add(Attribute.ROLE, "alert"); noRow.add((!StringUtils.isEmpty(noRowText) ? TagUtil.getLocalized(noRowText, getJspContext()) : TagUtil.getLocalizedForLib("grid.no.row", getJspContext()))); panelBody.add(noRow); } grid.add(panel); if (export) { Div exporter = new Div(); exporter.add(Attribute.CLASS, "hidden"); Form form = new Form(); form.add(Attribute.METHOD, "post"); form.add(Attribute.TARGET, "_blank"); form.add(Attribute.CLASS, "bs-grid-export-form"); form.add(Attribute.ACTION, TagUtil.getPathForUrl(getJspContext(), "/tagria/exporter")); Input type = new Input(); type.add(Attribute.TYPE, "hidden"); type.add(Attribute.NAME, "type"); type.add(Attribute.CLASS, "bs-grid-export-type"); form.add(type); Input html = new Input(); html.add(Attribute.TYPE, "hidden"); html.add(Attribute.NAME, "json"); html.add(Attribute.CLASS, "bs-grid-export-json"); form.add(html); exporter.add(form); grid.add(exporter); } TagUtil.out(getJspContext(), grid); Script script = new Script(); script.add(Attribute.TYPE, "text/javascript"); script.add("$('#" + grid.get(Attribute.ID) + "').grid({ url : '" + TagUtil.getPathForUrl(getJspContext(), url) + "',queryString : '" + TagUtil.queryString(request, Arrays.asList("page", "property", "direction", "resultsPerPage")) + "'});"); TagUtil.out(getJspContext(), script); } }
From source file:com.ecyrd.jspwiki.ui.TemplateManager.java
/** * List all installed i18n language properties * //from w ww . java 2 s . co m * @param pageContext * @return map of installed Languages (with help of Juan Pablo Santos Rodriguez) * @since 2.7.x */ public Map listLanguages(PageContext pageContext) { LinkedHashMap<String, String> resultMap = new LinkedHashMap<String, String>(); String clientLanguage = ((HttpServletRequest) pageContext.getRequest()).getLocale().toString(); JarInputStream jarStream = null; try { JarEntry entry; InputStream inputStream = pageContext.getServletContext().getResourceAsStream(I18NRESOURCE_PATH); jarStream = new JarInputStream(inputStream); while ((entry = jarStream.getNextJarEntry()) != null) { String name = entry.getName(); if (!entry.isDirectory() && name.startsWith(I18NRESOURCE_PREFIX) && name.endsWith(I18NRESOURCE_SUFFIX)) { name = name.substring(I18NRESOURCE_PREFIX.length(), name.lastIndexOf(I18NRESOURCE_SUFFIX)); Locale locale = new Locale(name.substring(0, 2), ((name.indexOf("_") == -1) ? "" : name.substring(3, 5))); String defaultLanguage = ""; if (clientLanguage.startsWith(name)) { defaultLanguage = LocaleSupport.getLocalizedMessage(pageContext, I18NDEFAULT_LOCALE); } resultMap.put(name, locale.getDisplayName(locale) + " " + defaultLanguage); } } } catch (IOException ioe) { if (log.isDebugEnabled()) log.debug("Could not search jar file '" + I18NRESOURCE_PATH + "'for properties files due to an IOException: \n" + ioe.getMessage()); } finally { if (jarStream != null) { try { jarStream.close(); } catch (IOException e) { } } } return resultMap; }
From source file:net.ontopia.topicmaps.nav2.utils.DynamicTreeWidget.java
/** * PUBLIC: Runs the widget, producing the output. *//*from w ww. jav a 2 s. c om*/ public void run(PageContext ctxt, Writer writer) throws IOException, InvalidQueryException, NavigatorRuntimeException { run((HttpServletRequest) ctxt.getRequest(), writer); }
From source file:com.ecyrd.jspwiki.ui.TemplateManager.java
/** * Attempts to locate a resource under the given template. If that template * does not exist, or the page does not exist under that template, will * attempt to locate a similarly named file under the default template. * <p>/* w w w. ja va 2 s . co m*/ * Even though the name suggests only JSP files can be located, but in fact * this method can find also other resources than JSP files. * * @param pageContext The JSP PageContext * @param template From which template we should seek initially? * @param name Which resource are we looking for (e.g. "ViewTemplate.jsp") * @return path to the JSP page; null, if it was not found. */ public String findJSP(PageContext pageContext, String template, String name) { if (name == null || template == null) { log.fatal("findJSP() was asked to find a null template or name (" + template + "," + name + ")." + " JSP page '" + ((HttpServletRequest) pageContext.getRequest()).getRequestURI() + "'"); throw new InternalWikiException("Illegal arguments to findJSP(); please check logs."); } return findResource(pageContext.getServletContext(), template, name); }
From source file:com.silverpeas.tags.navigation.links.CachedLinkGeneratorImpl.java
/** * Construction de l'url de l'item./*from w w w . j a va 2 s . co m*/ * @param pageContext * @param themetracker * @param node * @param idsTopicsRoots * @param pub * @param prefixId * @return * @throws RemoteException */ public String generateFullSemanticPath(PageContext pageContext, KmeliaTagUtil themetracker, NodeDetail node, String idsTopicsRoots, PublicationDetail pub, String prefixId) throws RemoteException { String cacheActivate = Configurateur.getConfigValue("urlCache"); String refreshDelay = Configurateur.getConfigValue("urlCache.refreshDelay"); if (refreshDelay == null) refreshDelay = "3600"; if (cacheActivate == null) cacheActivate = "true"; if ((System.currentTimeMillis() - cacheAge >= Long.valueOf(refreshDelay) * 1000) || cacheActivate.equals("false")) { cache.clear(); cacheAge = System.currentTimeMillis(); } String cachedValue = cache.get(node.getId()); if (cachedValue == null) { StringBuffer path = new StringBuffer(); path.append(((HttpServletRequest) pageContext.getRequest()).getContextPath()); path.append("/"); StringTokenizer nodes = new StringTokenizer(node.getPath(), "/"); boolean beginPath = false; while (nodes.hasMoreTokens()) { String nodeId = nodes.nextToken(); if (beginPath) { NodeDetail n = KmeliaCaching.getInstance(themetracker).getTopic(Integer.valueOf(nodeId)); path.append(tranformName(n.getName())); path.append("/"); } else { beginPath = isRootTopic(nodeId, idsTopicsRoots); } } path.append(tranformName(node.getName())); path.append("/"); if (pub != null) { path.append(tranformName(pub.getName())); path.append("/"); } if (prefixId != null) { path.append(prefixId); } path.append(node.getId()); // Mise en cache cache.put(node.getId(), path.toString()); return path.toString(); } else { return cachedValue; } }
From source file:com.ecyrd.jspwiki.preferences.Preferences.java
/** * Reloads the preferences from the PageContext into the WikiContext. * //from www .j a v a 2 s . c om * @param pageContext The page context. */ // FIXME: The way that date preferences are chosen is currently a bit wacky: it all // gets saved to the cookie based on the browser state with which the user // happened to first arrive to the site with. This, unfortunately, means that // even if the user changes e.g. language preferences (like in a web cafe), // the old preferences still remain in a site cookie. public static void reloadPreferences(PageContext pageContext) { Preferences prefs = new Preferences(); Properties props = PropertyReader.loadWebAppProps(pageContext.getServletContext()); WikiContext ctx = WikiContext.findContext(pageContext); prefs.put("SkinName", TextUtil.getStringProperty(props, "jspwiki.defaultprefs.template.skinname", "PlainVanilla")); prefs.put("DateFormat", TextUtil.getStringProperty(props, "jspwiki.defaultprefs.template.dateformat", ctx.getEngine().getInternationalizationManager().get( InternationalizationManager.CORE_BUNDLE, getLocale(ctx), "common.datetimeformat"))); prefs.put("TimeZone", TextUtil.getStringProperty(props, "jspwiki.defaultprefs.template.timezone", java.util.TimeZone.getDefault().getID())); prefs.put("Orientation", TextUtil.getStringProperty(props, "jspwiki.defaultprefs.template.orientation", "fav-left")); prefs.put("Language", TextUtil.getStringProperty(props, "jspwiki.defaultprefs.template.language", getLocale(ctx).toString())); prefs.put("SectionEditing", TextUtil.getStringProperty(props, "jspwiki.defaultprefs.template.sectionediting", "")); // FIXME: "editor" property does not get registered, may be related with http://bugs.jspwiki.org/show_bug.cgi?id=117 // disabling it until knowing why it's happening // FIXME: editormanager reads jspwiki.editor -- which of both properties should continue prefs.put("editor", TextUtil.getStringProperty(props, "jspwiki.defaultprefs.template.editor", "plain")); parseJSONPreferences((HttpServletRequest) pageContext.getRequest(), prefs); pageContext.getSession().setAttribute(SESSIONPREFS, prefs); }
From source file:mercury.tags.SetInitialLocale.java
@Override public void doTag() throws JspException { try {/*from w w w . j av a 2s .c o m*/ PageContext pageContext = (PageContext) getJspContext(); if (pageContext.getServletContext().getAttribute("FIRST_EXECUTION") != null) { pageContext.getServletContext().removeAttribute("FIRST_EXECUTION"); pageContext.getSession().removeAttribute("LAST_VISITED_PAGE"); pageContext.getSession().removeAttribute("MESSAGE_TEXT"); pageContext.getSession().removeAttribute("MESSAGE_LEVEL"); pageContext.getSession().setAttribute("MESSAGE_TEXT", "DIALOG_VOID"); pageContext.getSession().setAttribute("MESSAGE_LEVEL", "NORMAL"); } String lastVisitedPage = (String) pageContext.getSession().getAttribute("LAST_VISITED_PAGE"); if (lastVisitedPage == null || lastVisitedPage.trim().equals("")) { lastVisitedPage = errorJsp; pageContext.getSession().setAttribute("LAST_VISITED_PAGE", lastVisitedPage); } if ((String) pageContext.getSession().getAttribute("I18N") == null) { String locale = pageContext.getRequest().getLocale().toString(); Properties languages = (Properties) pageContext.getServletContext().getAttribute("LANGUAGES"); if (StringUtils.isNotBlank(locale) && languages.containsKey(locale)) { pageContext.getSession().setAttribute("I18N", locale); } else { pageContext.getSession().setAttribute("I18N", defaultLanguage); } } } catch (Exception ex) { log.error(ex.getMessage(), ex); throw new JspException("[mercury.SetInitialLocale.doTag()] Exception: " + ex.getMessage()); } }