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); } }
/** @return the baseUrl */ public String getBaseUrl() { if (baseUrl == null) { this.getRenderRequest(); baseUrl = renderRequest.getScheme() + "://" + renderRequest.getServerName() + ":" + renderRequest.getServerPort() + renderRequest.getContextPath() + "/"; } return baseUrl; }
public String doView(RenderRequest request, RenderResponse response) throws Exception { // The JSP to show upon success String defaultView = VIEW_PAGE; String ctx = request.getContextPath(); // Determine the project container to use Project project = findProject(request); // Check the user's permissions User user = getUser(request); if (!ProjectUtils.hasAccess(project.getId(), user, "project-discussion-topics-view")) { throw new PortletException("Unauthorized to view in this project"); } // Retrieve parameters int forumId = PortalUtils.getPageViewAsInt(request); String resetList = request.getParameter("resetList"); // Build a list of records Connection db = useConnection(request); // Paging will be used for remembering several list view settings if ("true".equals(resetList)) { // deletePagedListInfo(request, "projectIssuesInfo"); } PagedListInfo pagedListInfo = getPagedListInfo(request, PAGED_LIST_INFO); pagedListInfo.setLink(ctx + "/show/" + project.getUniqueId() + "/forum/" + forumId); if (pagedListInfo.getInitializationLevel() == PagedListInfo.LEVEL_INITIALIZED) { pagedListInfo.setColumnToSortBy("i.last_reply_date"); pagedListInfo.setSortOrder("desc"); } // Load the category info Forum forum = new Forum(db, forumId, project.getId()); request.setAttribute(FORUM, forum); PortalUtils.setGeneratedData(request, FORUM, forum); // Load the records TopicList topicList = new TopicList(); topicList.setProjectId(project.getId()); topicList.setCategoryId(forum.getId()); topicList.setPagedListInfo(pagedListInfo); topicList.buildList(db); request.setAttribute(TOPIC_LIST, topicList); // JSP view return defaultView; }
/** * 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 void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { try { String ctx = request.getContextPath(); String defaultView = VIEW_PAGE; // Get portal items String queryString = (String) request.getAttribute(BASE_QUERY_STRING); IIndexerSearch searcher = (IIndexerSearch) request.getAttribute(SEARCHER); ProjectCategoryList categories = (ProjectCategoryList) request.getAttribute(PROJECT_CATEGORY_LIST); SearchBean searchBean = (SearchBean) request.getAttribute(SEARCH_BEAN); // Get preferences String category = request.getPreferences().getValue(PREF_CATEGORY_NAME, null); request.setAttribute(TITLE, request.getPreferences().getValue(TITLE, "Projects")); int recordLimit = Integer.parseInt(request.getPreferences().getValue(PREF_RECORD_LIMIT, "10")); request.setAttribute(RECORD_LIMIT, recordLimit); boolean hasPaging = "true".equals(request.getPreferences().getValue(PREF_HAS_PAGING, null)); if (hasPaging) { request.setAttribute(HAS_PAGING, hasPaging); } if (category != null && categories.getIdFromValue(category) == -1) { // don't display anything because the category does not exist in the category list } else { // If the searchbean category is not this category, then provide a link to that category // page if (category != null && categories.getIdFromValue(category) != searchBean.getCategoryId()) { request.setAttribute( HAS_MORE_URL, request .getPreferences() .getValue( PREF_HAS_MORE_URL, searchBean.getUrlByCategory(categories.getIdFromValue(category)))); } else { request.setAttribute( HAS_MORE_URL, request.getPreferences().getValue(PREF_HAS_MORE_URL, "")); } request.setAttribute( HAS_MORE_TITLE, request.getPreferences().getValue(PREF_HAS_MORE_TITLE, "Browse more items")); // Request items request.setAttribute(SEARCH_BEAN_ATTRIBUTE, searchBean); // Customize the string queryString += " AND (type:project) " + (category != null ? "AND (projectCategoryId:" + categories.getIdFromValue(category) + ") " : ""); // Efficient unsorted list /* TopDocCollector collector = new TopDocCollector(50); searcher.search(query, collector); ScoreDoc[] hits = collector.topDocs().scoreDocs; */ // IndexerQueryResultList hits = new IndexerQueryResultList(); hits.setQueryString(queryString); hits.getPagedListInfo().setItemsPerPage(recordLimit); // Use paging if requested PagedListInfo searchBeanInfo = new PagedListInfo(); if (hasPaging) { searchBeanInfo.setLink("/search"); String offsetStr = request.getParameter("offset"); int offset = offsetStr == null ? 0 : Integer.parseInt(offsetStr); searchBeanInfo.setCurrentOffset(offset); searchBeanInfo.setRenderParameters(searchBean.getParameterMap()); searchBeanInfo.setNamespace(response.getNamespace()); searchBeanInfo.setContextPath(ctx); searchBeanInfo.setItemsPerPage(recordLimit); hits.setPagedListInfo(searchBeanInfo); } // Configure the parameters for the search results if (searchBean.getFilter() == SearchBean.NEWLY_ADDED) { // Newly Added (parse in reverse) hits.getPagedListInfo().setColumnToSortBy("entered"); hits.getPagedListInfo().setSortOrder("desc"); searcher.search(hits); } else if (searchBean.getFilter() == SearchBean.HIGHEST_RATED) { // Highest Rated (parse in reverse) hits.getPagedListInfo().setColumnToSortBy("ratingAverage"); hits.getPagedListInfo().setSortOrder("desc"); searcher.search(hits); } else if (searchBean.getFilter() == SearchBean.MOST_REVIEWED) { // Most Reviewed (parse in reverse) hits.getPagedListInfo().setColumnToSortBy("ratingCount"); hits.getPagedListInfo().setSortOrder("desc"); searcher.search(hits); } else { // Best Match searcher.search(hits); } if (hits.getPagedListInfo().moreRecordsExist()) { request.setAttribute(HAS_MORE_RECORDS, "true"); } // Set the results for the view request.setAttribute(HITS, hits); // This portlet can provide data to other portlets for (String event : PortalUtils.getDashboardPortlet(request).getGenerateDataEvents()) { PortalUtils.setGeneratedData(request, event, hits); } if (hits.size() > 0) { // JSP view PortletContext context = getPortletContext(); PortletRequestDispatcher requestDispatcher = context.getRequestDispatcher(defaultView); requestDispatcher.include(request, response); } } } catch (Exception e) { e.printStackTrace(System.out); throw new PortletException(e); } }
/** * 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"); }