protected void doHeaders(RenderRequest request, RenderResponse response) { super.doHeaders(request, response); PortalContext portalContext = request.getPortalContext(); String portalInfo = portalContext.getPortalInfo(); // -- adding DOM element to head is supported by JetSpeed 2.2 if (portalInfo.contains(Constants.JETSPEED)) { // -- add CSS Element cssElement = response.createElement("link"); // --encoding URLs is important cssElement.setAttribute( "href", response.encodeURL((request.getContextPath() + "/css/bookCatalog.css"))); cssElement.setAttribute("rel", "stylesheet"); cssElement.setAttribute("type", "text/css"); response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, cssElement); // -- add JavaScript Element jsElement = response.createElement("script"); // --encoding URLs to resources is important jsElement.setAttribute( "src", response.encodeURL((request.getContextPath() + "/js/bookCatalog.js"))); jsElement.setAttribute("type", "text/javascript"); response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, jsElement); } }
private void showPrintableCatalog(RenderRequest request, RenderResponse response) throws PortletException, IOException { PortletRequestDispatcher dispatcher = request .getPortletSession() .getPortletContext() .getRequestDispatcher(response.encodeURL("/myservlet/bookServlet")); dispatcher.include(request, response); }
private void showPrefsInfo(RenderRequest request, RenderResponse response) throws PortletException, IOException { PortletRequestDispatcher dispatcher = request .getPortletSession() .getPortletContext() .getRequestDispatcher(response.encodeURL("/WEB-INF/jsp/preferences.jsp")); dispatcher.include(request, response); }
/** * Starting from the module <code>buttonsSB</code> object, creates all buttons for the jsp list. * * @param buttons The list of the buttons * @throws JspException If any exception occurs. */ protected StringBuffer makeButton(List buttons) throws JspException { StringBuffer htmlStream = new StringBuffer(); Iterator iter = buttons.listIterator(); while (iter.hasNext()) { SourceBeanAttribute buttonSBA = (SourceBeanAttribute) iter.next(); SourceBean buttonSB = (SourceBean) buttonSBA.getValue(); List parameters = buttonSB.getAttributeAsList("PARAMETER"); HashMap paramsMap = getParametersMap(parameters, null); String name = (String) buttonSB.getAttribute("name"); String img = (String) buttonSB.getAttribute("image"); String labelCode = (String) buttonSB.getAttribute("label"); String label = msgBuilder.getMessage(labelCode, _bundle, httpRequest); PortletURL buttonUrl = createUrl(paramsMap); htmlStream.append("<td class=\"header-button-column-portlet-section\">\n"); htmlStream.append( "<input type='image' " + "name='" + name + "' " + "title='" + label + "' " + "class='header-button-image-portlet-section'" + "src ='" + renderResponse.encodeURL(renderRequest.getContextPath() + img) + "' " + "alt='" + label + "'>\n"); htmlStream.append("</td>\n"); } return htmlStream; }
public String encodeURL(String path) { return response.encodeURL(path); }
@SuppressWarnings("unchecked") @RenderMode(name = "VIEW") public void showBooks(RenderRequest request, RenderResponse response) throws IOException, PortletException { logger.info("Entering showBooks method"); PortalContext context = request.getPortalContext(); printSupportedPortletModes(context); printSupportedWindowStates(context); // --get user attributes user.name.given and user.name.family Map<String, Object> userAttributeMap = (Map<String, Object>) request.getAttribute(PortletRequest.USER_INFO); String firstName = ""; String lastName = ""; if (userAttributeMap != null) { firstName = (String) userAttributeMap.get("user.name.given"); lastName = (String) userAttributeMap.get("user.name.family"); request.setAttribute("firstName", firstName); request.setAttribute("lastName", lastName); } String portalInfo = context.getPortalInfo(); request.setAttribute("portalInfo", portalInfo); // --generate all the URLs that will be used by the portlet generateUrls(request, response); String myaction = request.getParameter("myaction"); if (myaction != null) { logger.info("myaction parameter is not null. Value is " + myaction); request.getPortletSession().setAttribute("myaction", myaction, PortletSession.PORTLET_SCOPE); } else { // -- if myaction is NULL then show the home page of Book // catalog // page request .getPortletSession() .setAttribute("myaction", "showCatalog", PortletSession.PORTLET_SCOPE); } // -- send myaction as a request attribute to the BookServlet. request.setAttribute("myaction", request.getPortletSession().getAttribute("myaction")); // --dynamically obtain the title for the portlet, based on myaction String titleKey = "portlet.title." + (String) request.getPortletSession().getAttribute("myaction"); response.setTitle(getResourceBundle(request.getLocale()).getString(titleKey)); // --if the action is uploadTocForm then store the ISBN number of // the // --book for which the TOC is being uploaded. The upload action // will use the ISBN number to create file name -- refer home.jsp // page if (((String) request.getAttribute("myaction")).equalsIgnoreCase("uploadTocForm")) { request.getPortletSession().setAttribute("isbnNumber", request.getParameter("isbnNumber")); } if (((String) request.getPortletSession().getAttribute("myaction")) .equalsIgnoreCase("showSearchResults")) { request.setAttribute( "matchingBooks", request.getPortletSession().getAttribute("matchingBooks")); } // its important to encode URLs PortletRequestDispatcher dispatcher = request .getPortletSession() .getPortletContext() .getRequestDispatcher(response.encodeURL("/myservlet/bookServlet")); dispatcher.include(request, response); }
/** * Builds list navigation buttons inside the list tag. If the number of elements is higher than * 10, they are divided into pages; this methods creates forward and backward arrows and page * number information for navigation. * * @throws JspException If any Exception occurs */ protected void makeNavigationButton() throws JspException { String pageNumberString = (String) _content.getAttribute("PAGED_LIST.PAGE_NUMBER"); if (_session.getAttribute("PAGE_NUMBER") != null) _session.delAttribute("PAGE_NUMBER"); _session.setAttribute("PAGE_NUMBER", pageNumberString); int pageNumber = 1; try { pageNumber = Integer.parseInt(pageNumberString); } catch (NumberFormatException ex) { TracerSingleton.log( Constants.NOME_MODULO, TracerSingleton.WARNING, "ListTag::makeNavigationButton:: PAGE_NUMBER nullo"); } String pagesNumberString = (String) _content.getAttribute("PAGED_LIST.PAGES_NUMBER"); int pagesNumber = 1; try { pagesNumber = Integer.parseInt(pagesNumberString); } catch (NumberFormatException ex) { TracerSingleton.log( Constants.NOME_MODULO, TracerSingleton.WARNING, "ListTag::makeNavigationButton:: PAGES_NUMBER nullo"); } int prevPage = pageNumber - 1; if (prevPage < 1) prevPage = 1; int nextPage = pageNumber + 1; if (nextPage > pagesNumber) nextPage = pagesNumber; // get the right parameters of the request // HashMap paramsMap = getQueryStringParameter(); // add the parameter for the provider // paramsMap.putAll(_providerUrlMap); _htmlStream.append(" <TABLE CELLPADDING=0 CELLSPACING=0 WIDTH='100%' BORDER=0>\n"); _htmlStream.append(" <TR>\n"); _htmlStream.append( " <TD class='portlet-section-footer' valign='center' align='left' width='14'>\n"); // create link for previous page HashMap prevParamsMap = new HashMap(); prevParamsMap.putAll(_providerUrlMap); prevParamsMap.put("MESSAGE", "LIST_PAGE"); prevParamsMap.put("LIST_PAGE", String.valueOf(prevPage)); PortletURL prevUrl = createUrl(prevParamsMap); HashMap nextParamsMap = new HashMap(); nextParamsMap.putAll(_providerUrlMap); nextParamsMap.put("MESSAGE", "LIST_PAGE"); nextParamsMap.put("LIST_PAGE", String.valueOf(nextPage)); PortletURL nextUrl = createUrl(nextParamsMap); // identity string for object of the page UUIDGenerator uuidGen = UUIDGenerator.getInstance(); UUID uuid = uuidGen.generateTimeBasedUUID(); String requestIdentity = uuid.toString(); requestIdentity = requestIdentity.replaceAll("-", ""); String formId = "formFilter" + requestIdentity; String valueFilter = (String) _serviceRequest.getAttribute(SpagoBIConstants.VALUE_FILTER); String columnFilter = (String) _serviceRequest.getAttribute(SpagoBIConstants.COLUMN_FILTER); String typeFilter = (String) _serviceRequest.getAttribute(SpagoBIConstants.TYPE_FILTER); if (valueFilter != null && columnFilter != null && typeFilter != null) { prevUrl.setParameter(SpagoBIConstants.VALUE_FILTER, valueFilter); prevUrl.setParameter(SpagoBIConstants.COLUMN_FILTER, columnFilter); prevUrl.setParameter(SpagoBIConstants.TYPE_FILTER, typeFilter); nextUrl.setParameter(SpagoBIConstants.VALUE_FILTER, valueFilter); nextUrl.setParameter(SpagoBIConstants.COLUMN_FILTER, columnFilter); nextUrl.setParameter(SpagoBIConstants.TYPE_FILTER, typeFilter); } else { valueFilter = ""; columnFilter = ""; typeFilter = ""; } if (pageNumber != 1) { // _htmlStream.append(" <A href=\""+prevUrl.toString()+"\"><IMG // src='"+renderResponse.encodeURL(renderRequest.getContextPath() + "/img/prevPage.gif")+"' // ALIGN=RIGHT border=0></a>\n"); _htmlStream.append( "<input type='image' " + "name='" + "prevPage" + "' " + "src ='" + renderResponse.encodeURL(renderRequest.getContextPath() + "/img/prevPage.gif") + "' " + "align='left' border=0" + "alt='" + "GO To Previous Page" + "'>\n"); } else { _htmlStream.append( " <IMG src='" + renderResponse.encodeURL(renderRequest.getContextPath() + "/img/prevPage.gif") + "' ALIGN=RIGHT border=0>\n"); } _htmlStream.append(" </TD>\n"); // create center blank cell // _htmlStream.append(" <TD class='portlet-section-footer'> </TD>\n"); // visualize page numbers String pageLabel = msgBuilder.getMessage("ListTag.pageLable", _bundle, httpRequest); String pageOfLabel = msgBuilder.getMessage("ListTag.pageOfLable", _bundle, httpRequest); _htmlStream.append(" <TD class='portlet-section-footer' align='center'>\n"); _htmlStream.append( " <font class='aindice'> " + pageLabel + " " + pageNumber + " " + pageOfLabel + " " + pagesNumber + " </font>\n"); _htmlStream.append(" \n"); // Form for list filtering; if not specified, the filter is enabled if (_filter == null || _filter.equalsIgnoreCase("enabled")) { PortletURL allUrl = createUrl(_providerUrlMap); PortletURL filterURL = createUrl(_providerUrlMap); String label = msgBuilder.getMessage("SBIListLookPage.labelFilter", _bundle, httpRequest); String labelStart = msgBuilder.getMessage("SBIListLookPage.startWith", _bundle, httpRequest); ; String labelEnd = msgBuilder.getMessage("SBIListLookPage.endWith", _bundle, httpRequest); ; String labelContain = msgBuilder.getMessage("SBIListLookPage.contains", _bundle, httpRequest); ; String labelEqual = msgBuilder.getMessage("SBIListLookPage.isEquals", _bundle, httpRequest); ; String labelFilter = msgBuilder.getMessage("SBIListLookPage.filter", _bundle, httpRequest); String labelAll = msgBuilder.getMessage("SBIListLookPage.all", _bundle, httpRequest); _htmlStream.append(" <br/><br/>\n"); _htmlStream.append( " <form action='" + filterURL + "' id='" + formId + "' method='post'>\n"); _htmlStream.append(" " + label + "\n"); _htmlStream.append(" <select name='" + SpagoBIConstants.COLUMN_FILTER + "'>\n"); for (int i = 0; i < _columns.size(); i++) { String nameColumn = (String) ((SourceBean) _columns.elementAt(i)).getAttribute("NAME"); String labelColumnCode = (String) ((SourceBean) _columns.elementAt(i)).getAttribute("LABEL"); String labelColumn = new String(nameColumn); if (labelColumnCode != null) labelColumn = msgBuilder.getMessage(labelColumnCode, _bundle, httpRequest); String selected = ""; if (nameColumn.equalsIgnoreCase(columnFilter)) selected = " selected='selected' "; _htmlStream.append( " <option value='" + nameColumn + "' " + selected + " >" + labelColumn + "</option>\n"); } String selected = ""; _htmlStream.append(" </select>\n"); _htmlStream.append(" <select name='" + SpagoBIConstants.TYPE_FILTER + "'>\n"); if (typeFilter.equalsIgnoreCase(SpagoBIConstants.START_FILTER)) selected = " selected='selected' "; else selected = ""; _htmlStream.append( " <option value='" + SpagoBIConstants.START_FILTER + "' " + selected + " >" + labelStart + "</option>\n"); if (typeFilter.equalsIgnoreCase(SpagoBIConstants.END_FILTER)) selected = " selected='selected' "; else selected = ""; _htmlStream.append( " <option value='" + SpagoBIConstants.END_FILTER + "' " + selected + " >" + labelEnd + "</option>\n"); if (typeFilter.equalsIgnoreCase(SpagoBIConstants.EQUAL_FILTER)) selected = " selected='selected' "; else selected = ""; _htmlStream.append( " <option value='" + SpagoBIConstants.EQUAL_FILTER + "' " + selected + " >" + labelEqual + "</option>\n"); if (typeFilter.equalsIgnoreCase(SpagoBIConstants.CONTAIN_FILTER)) selected = " selected='selected' "; else selected = ""; _htmlStream.append( " <option value='" + SpagoBIConstants.CONTAIN_FILTER + "' " + selected + " >" + labelContain + "</option>\n"); _htmlStream.append(" </select>\n"); _htmlStream.append( " <input type=\"text\" name=\"" + SpagoBIConstants.VALUE_FILTER + "\" size=\"10\" value=\"" + valueFilter + "\" /> \n"); _htmlStream.append( " <a href='javascript:document.getElementById(\"" + formId + "\").submit()'>" + labelFilter + "</a> \n"); _htmlStream.append(" <a href='" + allUrl.toString() + "'>" + labelAll + "</a> \n"); _htmlStream.append(" </form> \n"); } // create link for next page _htmlStream.append( " <TD class='portlet-section-footer' valign='center' align='right' width='14'>\n"); if (pageNumber != pagesNumber) { // _htmlStream.append(" <A href=\""+nextUrl.toString()+"\"><IMG // src='"+renderResponse.encodeURL(renderRequest.getContextPath() + "/img/nextPage.gif")+"' // ALIGN=RIGHT border=0></a>\n"); _htmlStream.append( "<input type='image' " + "name='" + "nextPage" + "' " + "src ='" + renderResponse.encodeURL(renderRequest.getContextPath() + "/img/nextPage.gif") + "' " + "align='right' border='0'" + "alt='" + "GO To Next Page" + "'>\n"); } else { _htmlStream.append( " <IMG src='" + renderResponse.encodeURL(renderRequest.getContextPath() + "/img/nextPage.gif") + "' ALIGN=RIGHT border=0>\n"); } _htmlStream.append(" </TD>\n"); _htmlStream.append(" </TR>\n"); _htmlStream.append("</TABLE>\n"); }