List of usage examples for javax.servlet.jsp JspException JspException
public JspException(Throwable cause)
JspException
with the specified cause. From source file:org.displaytag.render.TableWriterTemplate.java
/** * Given a table model, this method creates a table, sorting and grouping it per its configuration, while delegating * where and how it writes the table to subclass objects. (Background: This method refactors * TableTagData.writeHTMLData method. See above.) * @param model The table model used to build the table. * @param id This table's page id.// w w w .j av a2s . com * @throws JspException if any exception thrown while constructing the tablei, it is caught and rethrown as a * JspException. Extension classes may throw all sorts of exceptions, depending on their respective formats and * destinations. */ public void writeTable(TableModel model, String id) throws JspException { try { // table id used for logging this.id = id; TableProperties properties = model.getProperties(); if (log.isDebugEnabled()) { log.debug("[" + this.id + "] writeTable called for table [" + this.id + "]"); } // Handle empty table boolean noItems = model.getRowListPage().size() == 0; if (noItems && !properties.getEmptyListShowTable()) { writeEmptyListMessage(properties.getEmptyListMessage()); return; } // Put the page stuff there if it needs to be there... if (properties.getAddPagingBannerTop()) { // search result and navigation bar writeTopBanner(model); } // open table writeTableOpener(model); // render caption if (model.getCaption() != null) { writeCaption(model); } // render headers if (model.getProperties().getShowHeader()) { writeTableHeader(model); } // render footer prior to body if (model.getFooter() != null) { writePreBodyFooter(model); } // open table body writeTableBodyOpener(model); // render table body writeTableBody(model); // close table body writeTableBodyCloser(model); // render footer after body if (model.getFooter() != null) { writePostBodyFooter(model); } // close table writeTableCloser(model); if (model.getTableDecorator() != null) { writeDecoratedTableFinish(model); } writeBottomBanner(model); if (log.isDebugEnabled()) { log.debug("[" + this.id + "] writeTable end"); } } catch (Exception e) { throw new JspException(e); } }
From source file:org.dspace.app.webui.jsptag.AccessSettingTag.java
public int doStartTag() throws JspException { String legend = LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.access-setting.legend"); String label_name = LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.access-setting.label_name"); String label_group = LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.access-setting.label_group"); String label_embargo = LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.access-setting.label_embargo"); String label_date = LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.access-setting.label_date"); String radio0 = LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.access-setting.radio0"); String radio1 = LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.access-setting.radio1"); String radio_help = LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.access-setting.radio_help"); String label_reason = LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.access-setting.label_reason"); String button_confirm = LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.access-setting.button_confirm"); String help_name = LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.access-setting.name_help"); String help_reason = LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.access-setting.reason_help"); JspWriter out = pageContext.getOut(); StringBuffer sb = new StringBuffer(); try {/* w ww. j a v a 2s . c om*/ HttpServletRequest hrq = (HttpServletRequest) pageContext.getRequest(); Context context = UIUtil.obtainContext(hrq); // get startDate and reason of the resource policy of the target DSpaceObject List<ResourcePolicy> policies = null; if (!advanced && dso != null) { policies = AuthorizeManager.findPoliciesByDSOAndType(context, dso, ResourcePolicy.TYPE_CUSTOM); } else if (rp != null) { policies = new ArrayList<ResourcePolicy>(); policies.add(rp); } String name = ""; int group_id = 0; String startDate = ""; String reason = ""; String radio0Checked = " checked=\"checked\""; String radio1Checked = ""; String disabled = " disabled=\"disabled\""; if (policies != null && policies.size() > 0) { ResourcePolicy rp = policies.get(0); name = (rp.getRpName() == null ? "" : rp.getRpName()); group_id = rp.getGroup().getID(); startDate = (rp.getStartDate() != null ? DateFormatUtils.format(rp.getStartDate(), "yyyy-MM-dd") : ""); reason = (rp.getRpDescription() == null ? "" : rp.getRpDescription()); if (!startDate.equals("")) { radio0Checked = ""; radio1Checked = " checked=\"checked\""; disabled = ""; } } // if advanced embargo is disabled, embargo date and reason fields are always enabled if (!advanced) { disabled = ""; } if (embargo) { // Name sb.append("<div class=\"form-group\">"); sb.append(label_name).append("\n"); sb.append("<p class=\"help-block\">").append(help_name).append("</p>").append("\n"); sb.append( "<input class=\"form-control\" name=\"name\" id=\"policy_name\" type=\"text\" maxlength=\"30\" value=\"") .append(name).append("\" />\n"); sb.append("</div>"); // Group sb.append("<div class=\"form-group\">"); sb.append(label_group).append("\n"); sb.append("<select class=\"form-control\" name=\"group_id\" id=\"select_group\">\n"); Group[] groups = getGroups(context, hrq, subInfo); if (groups != null) { for (Group group : groups) { sb.append("<option value=\"").append(group.getID()).append("\""); if (group_id == group.getID()) { sb.append(" selected=\"selected\""); } sb.append(">").append(group.getName()).append("</option>\n"); } } else { sb.append("<option value=\"0\" selected=\"selected\">Anonymous</option>\n"); } sb.append("</select>\n"); sb.append("</div>"); // Select open or embargo sb.append(label_embargo).append("\n"); sb.append("<div class=\"radio\">"); sb.append("<label><input name=\"open_access_radios\" type=\"radio\" value=\"0\"") .append(radio0Checked).append(" />").append(radio0).append("</label>\n"); sb.append("</div>"); sb.append("<div class=\"radio\">"); sb.append("<label><input name=\"open_access_radios\" type=\"radio\" value=\"1\"") .append(radio1Checked).append(" />").append(radio1).append("</label>\n"); sb.append("</div>"); } // Embargo Date if (hidden) { sb.append( "<input name=\"embargo_until_date\" id=\"embargo_until_date_hidden\" type=\"hidden\" value=\"") .append(startDate).append("\" />\n"); ; sb.append("<input name=\"reason\" id=\"reason_hidden\" type=\"hidden\" value=\"").append(reason) .append("\" />\n"); } else { sb.append("<div class=\"form-group col-md-12\">"); sb.append("<div class=\"col-md-2\">"); sb.append(label_date); sb.append("</div>"); sb.append("<div class=\"col-md-2\">"); sb.append( "<input class=\"form-control\" name=\"embargo_until_date\" id=\"embargo_until_date\" maxlength=\"10\" size=\"10\" type=\"text\" value=\"") .append(startDate).append("\"").append(disabled).append(" />\n"); sb.append("</div>"); sb.append("<div class=\"col-md-8\">"); sb.append("<span class=\"help-block\">" + radio_help + "</span>"); sb.append("</div>"); sb.append("</div>"); // Reason sb.append("<div class=\"form-group col-md-12\">"); sb.append("<div class=\"col-md-12\">"); sb.append(label_reason).append("\n"); sb.append("</div>"); sb.append("<div class=\"col-md-12\">"); sb.append("<p class=\"help-block\">").append(help_reason).append("</p>").append("\n"); sb.append("</div>"); sb.append("<div class=\"col-md-12\">"); sb.append("<textarea class=\"form-control\" name=\"reason\" id=\"reason\" cols=\"30\" rows=\"5\"") .append(disabled).append(">").append(reason).append("</textarea>\n"); sb.append("</div>"); sb.append("</div>"); } // Add policy button if (addpolicy) { sb.append( "<input class=\"btn btn-success col-md-offset-5\" name=\"submit_add_policy\" type=\"submit\" value=\"") .append(button_confirm).append("\" />\n"); } out.println(sb.toString()); } catch (IOException ie) { throw new JspException(ie); } catch (SQLException e) { throw new JspException(e); } return SKIP_BODY; }
From source file:org.dspace.app.webui.jsptag.BrowseListTag.java
public int doStartTag() throws JspException { JspWriter out = pageContext.getOut(); HttpServletRequest hrq = (HttpServletRequest) pageContext.getRequest(); /* just leave this out now boolean emphasiseDate = false;/*from w w w . j a va2s . c o m*/ boolean emphasiseTitle = false; if (emphColumn != null) { emphasiseDate = emphColumn.equalsIgnoreCase("date"); emphasiseTitle = emphColumn.equalsIgnoreCase("title"); } */ // get the elements to display String browseListLine = null; String browseWidthLine = null; // As different indexes / sort options may require different columns to be displayed // try to obtain a custom configuration based for the browse that has been performed if (browseInfo != null) { SortOption so = browseInfo.getSortOption(); BrowseIndex bix = browseInfo.getBrowseIndex(); // We have obtained the index that was used for this browse if (bix != null) { // First, try to get a configuration for this browse and sort option combined if (so != null && browseListLine == null) { browseListLine = ConfigurationManager.getProperty( "webui.itemlist.browse." + bix.getName() + ".sort." + so.getName() + ".columns"); browseWidthLine = ConfigurationManager.getProperty( "webui.itemlist.browse." + bix.getName() + ".sort." + so.getName() + ".widths"); } // We haven't got a sort option defined, so get one for the index // - it may be required later if (so == null) { so = bix.getSortOption(); } } // If no config found, attempt to get one for this sort option if (so != null && browseListLine == null) { browseListLine = ConfigurationManager .getProperty("webui.itemlist.sort." + so.getName() + ".columns"); browseWidthLine = ConfigurationManager .getProperty("webui.itemlist.sort." + so.getName() + ".widths"); } // If no config found, attempt to get one for this browse index if (bix != null && browseListLine == null) { browseListLine = ConfigurationManager .getProperty("webui.itemlist.browse." + bix.getName() + ".columns"); browseWidthLine = ConfigurationManager .getProperty("webui.itemlist.browse." + bix.getName() + ".widths"); } // If no config found, attempt to get a general one, using the sort name if (so != null && browseListLine == null) { browseListLine = ConfigurationManager.getProperty("webui.itemlist." + so.getName() + ".columns"); browseWidthLine = ConfigurationManager.getProperty("webui.itemlist." + so.getName() + ".widths"); } // If no config found, attempt to get a general one, using the index name if (bix != null && browseListLine == null) { browseListLine = ConfigurationManager.getProperty("webui.itemlist." + bix.getName() + ".columns"); browseWidthLine = ConfigurationManager.getProperty("webui.itemlist." + bix.getName() + ".widths"); } } if (browseListLine == null) { browseListLine = ConfigurationManager.getProperty("webui.itemlist.columns"); browseWidthLine = ConfigurationManager.getProperty("webui.itemlist.widths"); } // Have we read a field configration from dspace.cfg? if (browseListLine != null) { // If thumbnails are disabled, strip out any thumbnail column from the configuration if (!showThumbs && browseListLine.contains("thumbnail")) { // Ensure we haven't got any nulls browseListLine = browseListLine == null ? "" : browseListLine; browseWidthLine = browseWidthLine == null ? "" : browseWidthLine; // Tokenize the field and width lines StringTokenizer bllt = new StringTokenizer(browseListLine, ","); StringTokenizer bwlt = new StringTokenizer(browseWidthLine, ","); StringBuilder newBLLine = new StringBuilder(); StringBuilder newBWLine = new StringBuilder(); while (bllt.hasMoreTokens() || bwlt.hasMoreTokens()) { String browseListTok = bllt.hasMoreTokens() ? bllt.nextToken() : null; String browseWidthTok = bwlt.hasMoreTokens() ? bwlt.nextToken() : null; // Only use the Field and Width tokens, if the field isn't 'thumbnail' if (browseListTok == null || !browseListTok.trim().equals("thumbnail")) { if (browseListTok != null) { if (newBLLine.length() > 0) { newBLLine.append(","); } newBLLine.append(browseListTok); } if (browseWidthTok != null) { if (newBWLine.length() > 0) { newBWLine.append(","); } newBWLine.append(browseWidthTok); } } } // Use the newly built configuration file browseListLine = newBLLine.toString(); browseWidthLine = newBWLine.toString(); } } else { browseListLine = DEFAULT_LIST_FIELDS; browseWidthLine = DEFAULT_LIST_WIDTHS; } // Arrays used to hold the information we will require when outputting each row String[] fieldArr = browseListLine == null ? new String[0] : browseListLine.split("\\s*,\\s*"); String[] widthArr = browseWidthLine == null ? new String[0] : browseWidthLine.split("\\s*,\\s*"); boolean isDate[] = new boolean[fieldArr.length]; boolean emph[] = new boolean[fieldArr.length]; boolean isAuthor[] = new boolean[fieldArr.length]; boolean viewFull[] = new boolean[fieldArr.length]; String[] browseType = new String[fieldArr.length]; String[] cOddOrEven = new String[fieldArr.length]; try { // Get the interlinking configuration too CrossLinks cl = new CrossLinks(); // Get a width for the table String tablewidth = ConfigurationManager.getProperty("webui.itemlist.tablewidth"); // If we have column widths, try to use a fixed layout table - faster for browsers to render // but not if we have to add an 'edit item' button - we can't know how big it will be if (widthArr.length > 0 && widthArr.length == fieldArr.length && !linkToEdit) { // If the table width has been specified, we can make this a fixed layout if (!StringUtils.isEmpty(tablewidth)) { out.println("<table style=\"width: " + tablewidth + "; table-layout: fixed;\" align=\"center\" class=\"miscTable\" summary=\"This table browses all dspace content\">"); } else { // Otherwise, don't constrain the width out.println( "<table align=\"center\" class=\"miscTable\" summary=\"This table browses all dspace content\">"); } // Output the known column widths out.print("<colgroup>"); for (int w = 0; w < widthArr.length; w++) { out.print("<col width=\""); // For a thumbnail column of width '*', use the configured max width for thumbnails if (fieldArr[w].equals("thumbnail") && widthArr[w].equals("*")) { out.print(thumbItemListMaxWidth); } else { out.print(StringUtils.isEmpty(widthArr[w]) ? "*" : widthArr[w]); } out.print("\" />"); } out.println("</colgroup>"); } else if (!StringUtils.isEmpty(tablewidth)) { out.println("<table width=\"" + tablewidth + "\" align=\"center\" class=\"miscTable\" summary=\"This table browses all dspace content\">"); } else { out.println( "<table align=\"center\" class=\"miscTable\" summary=\"This table browses all dspace content\">"); } // Output the table headers out.println("<tr>"); for (int colIdx = 0; colIdx < fieldArr.length; colIdx++) { String field = fieldArr[colIdx].toLowerCase().trim(); cOddOrEven[colIdx] = (((colIdx + 1) % 2) == 0 ? "Odd" : "Even"); // find out if the field is a date if (field.indexOf("(date)") > 0) { field = field.replaceAll("\\(date\\)", ""); isDate[colIdx] = true; } // Cache any modifications to field fieldArr[colIdx] = field; // find out if this is the author column if (field.equals(authorField)) { isAuthor[colIdx] = true; } // find out if this field needs to link out to other browse views if (cl.hasLink(field)) { browseType[colIdx] = cl.getLinkType(field); viewFull[colIdx] = BrowseIndex.getBrowseIndex(browseType[colIdx]).isItemIndex(); } // find out if we are emphasising this field /* if ((field.equals(dateField) && emphasiseDate) || (field.equals(titleField) && emphasiseTitle)) { emph[colIdx] = true; } */ if (field.equals(emphColumn)) { emph[colIdx] = true; } // prepare the strings for the header String id = "t" + Integer.toString(colIdx + 1); String css = "oddRow" + cOddOrEven[colIdx] + "Col"; String message = "itemlist." + field; // output the header out.print("<th id=\"" + id + "\" class=\"" + css + "\">" + (emph[colIdx] ? "<strong>" : "") + LocaleSupport.getLocalizedMessage(pageContext, message) + (emph[colIdx] ? "</strong>" : "") + "</th>"); } if (linkToEdit) { String id = "t" + Integer.toString(cOddOrEven.length + 1); String css = "oddRow" + cOddOrEven[cOddOrEven.length - 2] + "Col"; // output the header out.print("<th id=\"" + id + "\" class=\"" + css + "\">" + (emph[emph.length - 2] ? "<strong>" : "") + " " //LocaleSupport.getLocalizedMessage(pageContext, message) + (emph[emph.length - 2] ? "</strong>" : "") + "</th>"); } out.print("</tr>"); // now output each item row for (int i = 0; i < items.length; i++) { out.print("<tr>"); // now prepare the XHTML frag for this division String rOddOrEven; if (i == highlightRow) { rOddOrEven = "highlight"; } else { rOddOrEven = ((i & 1) == 1 ? "odd" : "even"); } for (int colIdx = 0; colIdx < fieldArr.length; colIdx++) { String field = fieldArr[colIdx]; // get the schema and the element qualifier pair // (Note, the schema is not used for anything yet) // (second note, I hate this bit of code. There must be // a much more elegant way of doing this. Tomcat has // some weird problems with variations on this code that // I tried, which is why it has ended up the way it is) StringTokenizer eq = new StringTokenizer(field, "."); String[] tokens = { "", "", "" }; int k = 0; while (eq.hasMoreTokens()) { tokens[k] = eq.nextToken().toLowerCase().trim(); k++; } String schema = tokens[0]; String element = tokens[1]; String qualifier = tokens[2]; // first get hold of the relevant metadata for this column DCValue[] metadataArray; if (qualifier.equals("*")) { metadataArray = items[i].getMetadata(schema, element, Item.ANY, Item.ANY); } else if (qualifier.equals("")) { metadataArray = items[i].getMetadata(schema, element, null, Item.ANY); } else { metadataArray = items[i].getMetadata(schema, element, qualifier, Item.ANY); } // save on a null check which would make the code untidy if (metadataArray == null) { metadataArray = new DCValue[0]; } // now prepare the content of the table division String metadata = "-"; if (field.equals("thumbnail")) { metadata = getThumbMarkup(hrq, items[i]); } else if (metadataArray.length > 0) { // format the date field correctly if (isDate[colIdx]) { DCDate dd = new DCDate(metadataArray[0].value); metadata = UIUtil.displayDate(dd, false, false, hrq); } // format the title field correctly for withdrawn items (ie. don't link) else if (field.equals(titleField) && items[i].isWithdrawn()) { metadata = Utils.addEntities(metadataArray[0].value); } // format the title field correctly (as long as the item isn't withdrawn, link to it) else if (field.equals(titleField)) { metadata = "<a href=\"" + hrq.getContextPath() + "/handle/" + items[i].getHandle() + "\">" + Utils.addEntities(metadataArray[0].value) + "</a>"; } // format all other fields else { // limit the number of records if this is the author field (if // -1, then the limit is the full list) boolean truncated = false; int loopLimit = metadataArray.length; if (isAuthor[colIdx]) { int fieldMax = (authorLimit == -1 ? metadataArray.length : authorLimit); loopLimit = (fieldMax > metadataArray.length ? metadataArray.length : fieldMax); truncated = (fieldMax < metadataArray.length); log.debug("Limiting output of field " + field + " to " + Integer.toString(loopLimit) + " from an original " + Integer.toString(metadataArray.length)); } StringBuffer sb = new StringBuffer(); for (int j = 0; j < loopLimit; j++) { String startLink = ""; String endLink = ""; if (!StringUtils.isEmpty(browseType[colIdx]) && !disableCrossLinks) { String argument; String value; if (metadataArray[j].authority != null && metadataArray[j].confidence >= MetadataAuthorityManager.getManager() .getMinConfidence(metadataArray[j].schema, metadataArray[j].element, metadataArray[j].qualifier)) { argument = "authority"; value = metadataArray[j].authority; } else { argument = "value"; value = metadataArray[j].value; } if (viewFull[colIdx]) { argument = "vfocus"; } startLink = "<a href=\"" + hrq.getContextPath() + "/browse?type=" + browseType[colIdx] + "&" + argument + "=" + URLEncoder.encode(value, "UTF-8"); if (metadataArray[j].language != null) { startLink = startLink + "&" + argument + "_lang=" + URLEncoder.encode(metadataArray[j].language, "UTF-8"); } if ("authority".equals(argument)) { startLink += "\" class=\"authority " + browseType[colIdx] + "\">"; } else { startLink = startLink + "\">"; } endLink = "</a>"; } sb.append(startLink); sb.append(Utils.addEntities(metadataArray[j].value)); sb.append(endLink); if (j < (loopLimit - 1)) { sb.append("; "); } } if (truncated) { String etal = LocaleSupport.getLocalizedMessage(pageContext, "itemlist.et-al"); sb.append(", ").append(etal); } metadata = "<em>" + sb.toString() + "</em>"; } } // prepare extra special layout requirements for dates String extras = ""; if (isDate[colIdx]) { extras = "nowrap=\"nowrap\" align=\"right\""; } String id = "t" + Integer.toString(colIdx + 1); out.print("<td headers=\"" + id + "\" class=\"" + rOddOrEven + "Row" + cOddOrEven[colIdx] + "Col\" " + extras + ">" + (emph[colIdx] ? "<strong>" : "") + metadata + (emph[colIdx] ? "</strong>" : "") + "</td>"); } // Add column for 'edit item' links if (linkToEdit) { String id = "t" + Integer.toString(cOddOrEven.length + 1); out.print("<td headers=\"" + id + "\" class=\"" + rOddOrEven + "Row" + cOddOrEven[cOddOrEven.length - 2] + "Col\" nowrap>" + "<form method=\"get\" action=\"" + hrq.getContextPath() + "/tools/edit-item\">" + "<input type=\"hidden\" name=\"handle\" value=\"" + items[i].getHandle() + "\" />" + "<input type=\"submit\" value=\"Edit Item\" /></form>" + "</td>"); } out.println("</tr>"); } // close the table out.println("</table>"); } catch (IOException ie) { throw new JspException(ie); } catch (SQLException e) { throw new JspException(e); } catch (BrowseException e) { throw new JspException(e); } return SKIP_BODY; }
From source file:org.dspace.app.webui.jsptag.CollectionListTag.java
public int doStartTag() throws JspException { JspWriter out = pageContext.getOut(); try {// ww w .ja va 2 s. c o m out.println("<table align=\"center\" class=\"miscTable\" title=\"Collection List\">"); // Write column headings out.print("<tr><th id=\"t4\" class=\"oddRowOddCol\">" + LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.CollectionListTag.collectionName") + "</th></tr>"); // Row: toggles between Odd and Even String row = "even"; for (int i = 0; i < collections.length; i++) { // name String name = collections[i].getMetadata("name"); // first and only column is 'name' out.print("<tr><td headers=\"t4\" class=\"" + row + "RowEvenCol\">"); out.print("<a href=\""); HttpServletRequest hrq = (HttpServletRequest) pageContext.getRequest(); out.print(hrq.getContextPath() + "/handle/"); out.print(collections[i].getHandle()); out.print("\">"); out.print(name); out.print("</a>"); out.println("</td></tr>"); row = (row.equals("odd") ? "even" : "odd"); } out.println("</table>"); } catch (IOException ie) { throw new JspException(ie); } return SKIP_BODY; }
From source file:org.dspace.app.webui.jsptag.CommunityListTag.java
public int doStartTag() throws JspException { JspWriter out = pageContext.getOut(); try {/*from ww w . j ava2 s. c o m*/ out.println("<table align=\"center\" class=\"miscTable\" title=\"Community List\">"); // Write column headings out.print("<tr><th id=\"t5\" class=\"oddRowOddCol\">" + LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.CommunityListTag.communityName") + "</th></tr>"); // Row: toggles between Odd and Even String row = "even"; for (int i = 0; i < communities.length; i++) { // name String name = communities[i].getMetadata("name"); // first and only column is 'name' out.print("<tr><td headers=\"t5\" class=\"" + row + "RowEvenCol\">"); out.print("<a href=\""); HttpServletRequest hrq = (HttpServletRequest) pageContext.getRequest(); out.print(hrq.getContextPath() + "/handle/"); out.print(communities[i].getHandle()); out.print("\">"); out.print(name); out.print("</a>"); out.println("</td></tr>"); row = (row.equals("odd") ? "even" : "odd"); } out.println("</table>"); } catch (IOException ie) { throw new JspException(ie); } return SKIP_BODY; }
From source file:org.dspace.app.webui.jsptag.ItemListTag.java
public int doStartTag() throws JspException { JspWriter out = pageContext.getOut(); HttpServletRequest hrq = (HttpServletRequest) pageContext.getRequest(); boolean emphasiseDate = false; boolean emphasiseTitle = false; if (emphColumn != null) { emphasiseDate = emphColumn.equalsIgnoreCase("date"); emphasiseTitle = emphColumn.equalsIgnoreCase("title"); }//from w ww .j av a2s .c o m // get the elements to display String configLine = null; String widthLine = null; if (sortOption != null) { if (configLine == null) { configLine = ConfigurationManager .getProperty("webui.itemlist.sort." + sortOption.getName() + ".columns"); widthLine = ConfigurationManager .getProperty("webui.itemlist.sort." + sortOption.getName() + ".widths"); } if (configLine == null) { configLine = ConfigurationManager .getProperty("webui.itemlist." + sortOption.getName() + ".columns"); widthLine = ConfigurationManager.getProperty("webui.itemlist." + sortOption.getName() + ".widths"); } } if (configLine == null) { configLine = ConfigurationManager.getProperty("webui.itemlist.columns"); widthLine = ConfigurationManager.getProperty("webui.itemlist.widths"); } // Have we read a field configration from dspace.cfg? if (configLine != null) { // If thumbnails are disabled, strip out any thumbnail column from the configuration if (!showThumbs && configLine.contains("thumbnail")) { // Ensure we haven't got any nulls configLine = configLine == null ? "" : configLine; widthLine = widthLine == null ? "" : widthLine; // Tokenize the field and width lines StringTokenizer llt = new StringTokenizer(configLine, ","); StringTokenizer wlt = new StringTokenizer(widthLine, ","); StringBuilder newLLine = new StringBuilder(); StringBuilder newWLine = new StringBuilder(); while (llt.hasMoreTokens() || wlt.hasMoreTokens()) { String listTok = llt.hasMoreTokens() ? llt.nextToken() : null; String widthTok = wlt.hasMoreTokens() ? wlt.nextToken() : null; // Only use the Field and Width tokens, if the field isn't 'thumbnail' if (listTok == null || !listTok.trim().equals("thumbnail")) { if (listTok != null) { if (newLLine.length() > 0) { newLLine.append(","); } newLLine.append(listTok); } if (widthTok != null) { if (newWLine.length() > 0) { newWLine.append(","); } newWLine.append(widthTok); } } } // Use the newly built configuration file configLine = newLLine.toString(); widthLine = newWLine.toString(); } } else { configLine = DEFAULT_LIST_FIELDS; widthLine = DEFAULT_LIST_WIDTHS; } // Arrays used to hold the information we will require when outputting each row String[] fieldArr = configLine == null ? new String[0] : configLine.split("\\s*,\\s*"); String[] widthArr = widthLine == null ? new String[0] : widthLine.split("\\s*,\\s*"); boolean isDate[] = new boolean[fieldArr.length]; boolean emph[] = new boolean[fieldArr.length]; boolean isAuthor[] = new boolean[fieldArr.length]; boolean viewFull[] = new boolean[fieldArr.length]; String[] browseType = new String[fieldArr.length]; String[] cOddOrEven = new String[fieldArr.length]; try { // Get the interlinking configuration too CrossLinks cl = new CrossLinks(); // Get a width for the table String tablewidth = ConfigurationManager.getProperty("webui.itemlist.tablewidth"); // If we have column widths, output a fixed layout table - faster for browsers to render // but not if we have to add an 'edit item' button - we can't know how big it will be if (widthArr.length > 0 && widthArr.length == fieldArr.length && !linkToEdit) { // If the table width has been specified, we can make this a fixed layout if (!StringUtils.isEmpty(tablewidth)) { out.println("<table style=\"width: " + tablewidth + "; table-layout: fixed;\" align=\"center\" class=\"miscTable\" summary=\"This table browses all dspace content\">"); } else { // Otherwise, don't constrain the width out.println( "<table align=\"center\" class=\"miscTable\" summary=\"This table browses all dspace content\">"); } // Output the known column widths out.print("<colgroup>"); for (int w = 0; w < widthArr.length; w++) { out.print("<col width=\""); // For a thumbnail column of width '*', use the configured max width for thumbnails if (fieldArr[w].equals("thumbnail") && widthArr[w].equals("*")) { out.print(thumbItemListMaxWidth); } else { out.print(StringUtils.isEmpty(widthArr[w]) ? "*" : widthArr[w]); } out.print("\" />"); } out.println("</colgroup>"); } else if (!StringUtils.isEmpty(tablewidth)) { out.println("<table width=\"" + tablewidth + "\" align=\"center\" class=\"miscTable\" summary=\"This table browses all dspace content\">"); } else { out.println( "<table align=\"center\" class=\"miscTable\" summary=\"This table browses all dspace content\">"); } // Output the table headers out.println("<tr>"); for (int colIdx = 0; colIdx < fieldArr.length; colIdx++) { String field = fieldArr[colIdx].toLowerCase().trim(); cOddOrEven[colIdx] = (((colIdx + 1) % 2) == 0 ? "Odd" : "Even"); // find out if the field is a date if (field.indexOf("(date)") > 0) { field = field.replaceAll("\\(date\\)", ""); isDate[colIdx] = true; } // Cache any modifications to field fieldArr[colIdx] = field; // find out if this is the author column if (field.equals(authorField)) { isAuthor[colIdx] = true; } // find out if this field needs to link out to other browse views if (cl.hasLink(field)) { browseType[colIdx] = cl.getLinkType(field); viewFull[colIdx] = BrowseIndex.getBrowseIndex(browseType[colIdx]).isItemIndex(); } // find out if we are emphasising this field if (field.equals(emphColumn)) { emph[colIdx] = true; } else if ((field.equals(dateField) && emphasiseDate) || (field.equals(titleField) && emphasiseTitle)) { emph[colIdx] = true; } // prepare the strings for the header String id = "t" + Integer.toString(colIdx + 1); String css = "oddRow" + cOddOrEven[colIdx] + "Col"; String message = "itemlist." + field; // output the header out.print("<th id=\"" + id + "\" class=\"" + css + "\">" + (emph[colIdx] ? "<strong>" : "") + LocaleSupport.getLocalizedMessage(pageContext, message) + (emph[colIdx] ? "</strong>" : "") + "</th>"); } if (linkToEdit) { String id = "t" + Integer.toString(cOddOrEven.length + 1); String css = "oddRow" + cOddOrEven[cOddOrEven.length - 2] + "Col"; // output the header out.print("<th id=\"" + id + "\" class=\"" + css + "\">" + (emph[emph.length - 2] ? "<strong>" : "") + " " //LocaleSupport.getLocalizedMessage(pageContext, message) + (emph[emph.length - 2] ? "</strong>" : "") + "</th>"); } out.print("</tr>"); // now output each item row for (int i = 0; i < items.length; i++) { // now prepare the XHTML frag for this division out.print("<tr>"); String rOddOrEven; if (i == highlightRow) { rOddOrEven = "highlight"; } else { rOddOrEven = ((i & 1) == 1 ? "odd" : "even"); } for (int colIdx = 0; colIdx < fieldArr.length; colIdx++) { String field = fieldArr[colIdx]; // get the schema and the element qualifier pair // (Note, the schema is not used for anything yet) // (second note, I hate this bit of code. There must be // a much more elegant way of doing this. Tomcat has // some weird problems with variations on this code that // I tried, which is why it has ended up the way it is) StringTokenizer eq = new StringTokenizer(field, "."); String[] tokens = { "", "", "" }; int k = 0; while (eq.hasMoreTokens()) { tokens[k] = eq.nextToken().toLowerCase().trim(); k++; } String schema = tokens[0]; String element = tokens[1]; String qualifier = tokens[2]; // first get hold of the relevant metadata for this column DCValue[] metadataArray; if (qualifier.equals("*")) { metadataArray = items[i].getMetadata(schema, element, Item.ANY, Item.ANY); } else if (qualifier.equals("")) { metadataArray = items[i].getMetadata(schema, element, null, Item.ANY); } else { metadataArray = items[i].getMetadata(schema, element, qualifier, Item.ANY); } // save on a null check which would make the code untidy if (metadataArray == null) { metadataArray = new DCValue[0]; } // now prepare the content of the table division String metadata = "-"; if (field.equals("thumbnail")) { metadata = getThumbMarkup(hrq, items[i]); } if (metadataArray.length > 0) { // format the date field correctly if (isDate[colIdx]) { DCDate dd = new DCDate(metadataArray[0].value); metadata = UIUtil.displayDate(dd, false, false, hrq); } // format the title field correctly for withdrawn items (ie. don't link) else if (field.equals(titleField) && items[i].isWithdrawn()) { metadata = Utils.addEntities(metadataArray[0].value); } // format the title field correctly else if (field.equals(titleField)) { metadata = "<a href=\"" + hrq.getContextPath() + "/handle/" + items[i].getHandle() + "\">" + Utils.addEntities(metadataArray[0].value) + "</a>"; } // format all other fields else { // limit the number of records if this is the author field (if // -1, then the limit is the full list) boolean truncated = false; int loopLimit = metadataArray.length; if (isAuthor[colIdx]) { int fieldMax = (authorLimit > 0 ? authorLimit : metadataArray.length); loopLimit = (fieldMax > metadataArray.length ? metadataArray.length : fieldMax); truncated = (fieldMax < metadataArray.length); log.debug("Limiting output of field " + field + " to " + Integer.toString(loopLimit) + " from an original " + Integer.toString(metadataArray.length)); } StringBuffer sb = new StringBuffer(); for (int j = 0; j < loopLimit; j++) { String startLink = ""; String endLink = ""; if (!StringUtils.isEmpty(browseType[colIdx]) && !disableCrossLinks) { String argument; String value; if (metadataArray[j].authority != null && metadataArray[j].confidence >= MetadataAuthorityManager.getManager() .getMinConfidence(metadataArray[j].schema, metadataArray[j].element, metadataArray[j].qualifier)) { argument = "authority"; value = metadataArray[j].authority; } else { argument = "value"; value = metadataArray[j].value; } if (viewFull[colIdx]) { argument = "vfocus"; } startLink = "<a href=\"" + hrq.getContextPath() + "/browse?type=" + browseType[colIdx] + "&" + argument + "=" + URLEncoder.encode(value, "UTF-8"); if (metadataArray[j].language != null) { startLink = startLink + "&" + argument + "_lang=" + URLEncoder.encode(metadataArray[j].language, "UTF-8"); } if ("authority".equals(argument)) { startLink += "\" class=\"authority " + browseType[colIdx] + "\">"; } else { startLink = startLink + "\">"; } endLink = "</a>"; } sb.append(startLink); sb.append(Utils.addEntities(metadataArray[j].value)); sb.append(endLink); if (j < (loopLimit - 1)) { sb.append("; "); } } if (truncated) { String etal = LocaleSupport.getLocalizedMessage(pageContext, "itemlist.et-al"); sb.append(", ").append(etal); } metadata = "<em>" + sb.toString() + "</em>"; } } // prepare extra special layout requirements for dates String extras = ""; if (isDate[colIdx]) { extras = "nowrap=\"nowrap\" align=\"right\""; } String id = "t" + Integer.toString(colIdx + 1); out.print("<td headers=\"" + id + "\" class=\"" + rOddOrEven + "Row" + cOddOrEven[colIdx] + "Col\" " + extras + ">" + (emph[colIdx] ? "<strong>" : "") + metadata + (emph[colIdx] ? "</strong>" : "") + "</td>"); } // Add column for 'edit item' links if (linkToEdit) { String id = "t" + Integer.toString(cOddOrEven.length + 1); out.print("<td headers=\"" + id + "\" class=\"" + rOddOrEven + "Row" + cOddOrEven[cOddOrEven.length - 2] + "Col\" nowrap>" + "<form method=\"get\" action=\"" + hrq.getContextPath() + "/tools/edit-item\">" + "<input type=\"hidden\" name=\"handle\" value=\"" + items[i].getHandle() + "\" />" + "<input type=\"submit\" value=\"Edit Item\" /></form>" + "</td>"); } out.println("</tr>"); } // close the table out.println("</table>"); } catch (IOException ie) { throw new JspException(ie); } catch (BrowseException e) { throw new JspException(e); } return SKIP_BODY; }
From source file:org.dspace.app.webui.jsptag.ItemTag.java
public int doStartTag() throws JspException { try {// w w w .ja v a2 s . c o m if (style == null || style.equals("")) { style = styleSelection.getStyleForItem(item); } if (style.equals("full")) { renderFull(); } else { render(); } } catch (SQLException sqle) { throw new JspException(sqle); } catch (IOException ie) { throw new JspException(ie); } catch (DCInputsReaderException ex) { throw new JspException(ex); } return SKIP_BODY; }
From source file:org.dspace.app.webui.jsptag.LayoutTag.java
public int doEndTag() throws JspException { // Context objects ServletRequest request = pageContext.getRequest(); HttpServletResponse response = (HttpServletResponse) pageContext.getResponse(); ServletConfig config = pageContext.getServletConfig(); // header file String header = templatePath + "header-default.jsp"; // Choose default style unless one is specified if (style != null) { header = templatePath + "header-" + style.toLowerCase() + ".jsp"; }/*from www . ja v a 2 s.c o m*/ if (sidebar != null) { request.setAttribute("dspace.layout.sidebar", sidebar); } // Now include the header try { // Set headers to prevent browser caching, if appropriate if ((noCache != null) && noCache.equalsIgnoreCase("true")) { response.addDateHeader("expires", 1); response.addHeader("Pragma", "no-cache"); response.addHeader("Cache-control", "no-store"); } // Ensure the HTTP header will declare that UTF-8 is used // in the response. response.setContentType("text/html; charset=UTF-8"); RequestDispatcher rd = config.getServletContext().getRequestDispatcher(header); rd.include(request, response); //pageContext.getOut().write(getBodyContent().getString()); getBodyContent().writeOut(pageContext.getOut()); } catch (IOException ioe) { throw new JspException("Got IOException: " + ioe); } catch (ServletException se) { log.warn("Exception", se.getRootCause()); throw new JspException("Got ServletException: " + se); } // Footer file to use String footer = templatePath + "footer-default.jsp"; // Choose default flavour unless one is specified if (style != null) { footer = templatePath + "footer-" + style.toLowerCase() + ".jsp"; } try { // Ensure body is included before footer pageContext.getOut().flush(); RequestDispatcher rd = config.getServletContext().getRequestDispatcher(footer); rd.include(request, response); } catch (ServletException se) { throw new JspException("Got ServletException: " + se); } catch (IOException ioe) { throw new JspException("Got IOException: " + ioe); } style = null; title = null; sidebar = null; navbar = null; locbar = null; parentTitle = null; parentLink = null; noCache = null; feedData = null; return EVAL_PAGE; }
From source file:org.dspace.app.webui.jsptag.PoliciesListTag.java
public int doStartTag() throws JspException { String label_name = LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.policies-list.label_name"); String label_action = LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.policies-list.label_action"); String label_group = LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.policies-list.label_group"); String label_sdate = LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.policies-list.label_sdate"); String label_edate = LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.policies-list.label_edate"); String label_emptypolicies = LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.policies-list.no_policies"); JspWriter out = pageContext.getOut(); StringBuffer sb = new StringBuffer(); try {//from w w w. j a v a 2s . co m if (policies != null && policies.size() > 0) { sb.append("<div class=\"table-responsive\">\n"); sb.append("<table class=\"table\">\n"); sb.append("<tr>\n"); sb.append("<th class=\"accessHeadOdd\">").append(label_name).append("</th>\n"); sb.append("<th class=\"accessHeadEven\">").append(label_action).append("</th>\n"); sb.append("<th class=\"accessHeadOdd\">").append(label_group).append("</th>\n"); sb.append("<th class=\"accessHeadEven\">").append(label_sdate).append("</th>\n"); sb.append("<th class=\"accessHeadOdd\">").append(label_edate).append("</th>\n"); if (showButton) { sb.append("<th class=\"accessButton\"> </th>\n"); } sb.append("</tr>\n"); String column1 = "Even"; String column2 = "Odd"; for (ResourcePolicy policy : policies) { column1 = (column1.equals("Even") ? "Odd" : "Even"); column2 = (column2.equals("Even") ? "Odd" : "Even"); String rpName = (policy.getRpName() == null ? "" : policy.getRpName()); String startDate = (policy.getStartDate() == null ? "" : DateFormatUtils.format(policy.getStartDate(), "yyyy-MM-dd")); String endDate = (policy.getEndDate() == null ? "" : DateFormatUtils.format(policy.getEndDate(), "yyyy-MM-dd")); sb.append("<tr>\n"); sb.append("<td class=\"access").append(column1).append("\">").append(rpName).append("</td>\n"); sb.append("<td class=\"access").append(column2).append("\">").append(policy.getActionText()) .append("</td>\n"); sb.append("<td class=\"access").append(column1).append("\">") .append(policy.getGroup().getName()).append("</td>\n"); sb.append("<td class=\"access").append(column2).append("\">").append(startDate) .append("</td>\n"); sb.append("<td class=\"access").append(column1).append("\">").append(endDate).append("</td>\n"); if (showButton) { sb.append("<td class=\"accessButton\">\n"); sb.append("<input class=\"btn btn-default\" name=\"submit_edit_edit_policies_") .append(policy.getID()) .append("\" type=\"submit\" value=\"Edit\" /> <input class=\"btn btn-danger\" name=\"submit_delete_edit_policies_") .append(policy.getID()).append("\" type=\"submit\" value=\"Remove\" />\n"); sb.append("</td>\n"); } sb.append("</tr>\n"); } sb.append("</table>\n"); sb.append("</div>\n"); } else { sb.append("<div class=\"alert alert-warning\">").append(label_emptypolicies).append("</div>") .append("\n"); } out.println(sb.toString()); } catch (IOException ie) { throw new JspException(ie); } catch (SQLException e) { throw new JspException(e); } return SKIP_BODY; }
From source file:org.dspace.app.webui.jsptag.SelectEPersonTag.java
public int doStartTag() throws JspException { try {//from w w w . j a v a 2s . com JspWriter out = pageContext.getOut(); HttpServletRequest req = (HttpServletRequest) pageContext.getRequest(); out.print( "<table><tr><td colspan=\"2\" align=\"center\"><select multiple=\"multiple\" name=\"eperson_id\" size=\""); out.print(multiple ? "10" : "1"); out.println("\">"); // ensure that if no eperson is selected that a blank option is displayed - xhtml compliance if (epeople == null || epeople.length == 0) { out.print("<option value=\"\"> </option>"); } if (epeople != null) { for (int i = 0; i < epeople.length; i++) { out.print("<option value=\"" + epeople[i].getID() + "\">"); out.print(epeople[i].getFullName() + " (" + epeople[i].getEmail() + ")"); out.println("</option>"); } } // add blank option value if no person selected to ensure that code is xhtml compliant //out.print("<option/>"); out.print("</select></td>"); if (multiple) { out.print("</tr><tr><td width=\"50%\" align=\"center\">"); } else { out.print("<td>"); } String p = (multiple ? LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.SelectEPersonTag.selectPeople") : LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.SelectEPersonTag.selectPerson")); out.print("<input type=\"button\" value=\"" + p + "\" onclick=\"javascript:popup_window('" + req.getContextPath() + "/tools/eperson-list?multiple=" + multiple + "', 'eperson_popup');\" />"); if (multiple) { out.print("</td><td width=\"50%\" align=\"center\">"); out.print("<input type=\"button\" value=\"" + LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.SelectEPersonTag.removeSelected") + "\" onclick=\"javascript:removeSelected(window.document.epersongroup.eperson_id);\"/>"); } out.println("</td></tr></table>"); } catch (IOException ie) { throw new JspException(ie); } return SKIP_BODY; }