Example usage for javax.servlet.jsp.jstl.fmt LocaleSupport getLocalizedMessage

List of usage examples for javax.servlet.jsp.jstl.fmt LocaleSupport getLocalizedMessage

Introduction

In this page you can find the example usage for javax.servlet.jsp.jstl.fmt LocaleSupport getLocalizedMessage.

Prototype

public static String getLocalizedMessage(PageContext pageContext, String key) 

Source Link

Document

Retrieves the localized message corresponding to the given key.

Usage

From source file:org.dspace.app.webui.jsptag.ItemTag.java

/**
 * List bitstreams in the item/*from  w w  w.  java 2 s .com*/
 */
private void listBitstreams() throws IOException {
    JspWriter out = pageContext.getOut();
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

    out.print("<table align=\"center\" class=\"miscTable\"><tr>");
    out.println("<td class=\"evenRowEvenCol\"><p><strong>"
            + LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.ItemTag.files")
            + "</strong></p>");

    try {
        Bundle[] bundles = item.getBundles("ORIGINAL");

        boolean filesExist = false;

        for (Bundle bnd : bundles) {
            filesExist = bnd.getBitstreams().length > 0;
            if (filesExist) {
                break;
            }
        }

        // if user already has uploaded at least one file
        if (!filesExist) {
            out.println("<p>" + LocaleSupport.getLocalizedMessage(pageContext,
                    "org.dspace.app.webui.jsptag.ItemTag.files.no") + "</p>");
        } else {
            boolean html = false;
            String handle = item.getHandle();
            Bitstream primaryBitstream = null;

            Bundle[] bunds = item.getBundles("ORIGINAL");
            Bundle[] thumbs = item.getBundles("THUMBNAIL");

            // if item contains multiple bitstreams, display bitstream
            // description
            boolean multiFile = false;
            Bundle[] allBundles = item.getBundles();

            for (int i = 0, filecount = 0; (i < allBundles.length) && !multiFile; i++) {
                filecount += allBundles[i].getBitstreams().length;
                multiFile = (filecount > 1);
            }

            // check if primary bitstream is html
            if (bunds[0] != null) {
                Bitstream[] bits = bunds[0].getBitstreams();

                for (int i = 0; (i < bits.length) && !html; i++) {
                    if (bits[i].getID() == bunds[0].getPrimaryBitstreamID()) {
                        html = bits[i].getFormat().getMIMEType().equals("text/html");
                        primaryBitstream = bits[i];
                    }
                }
            }

            out.println("<table cellpadding=\"6\"><tr><th id=\"t1\" class=\"standard\">"
                    + LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.ItemTag.file")
                    + "</th>");

            if (multiFile) {

                out.println("<th id=\"t2\" class=\"standard\">" + LocaleSupport.getLocalizedMessage(pageContext,
                        "org.dspace.app.webui.jsptag.ItemTag.description") + "</th>");
            }

            out.println("<th id=\"t3\" class=\"standard\">"
                    + LocaleSupport.getLocalizedMessage(pageContext,
                            "org.dspace.app.webui.jsptag.ItemTag.filesize")
                    + "</th><th id=\"t4\" class=\"standard\">" + LocaleSupport.getLocalizedMessage(pageContext,
                            "org.dspace.app.webui.jsptag.ItemTag.fileformat")
                    + "</th></tr>");

            // if primary bitstream is html, display a link for only that one to
            // HTMLServlet
            if (html) {
                // If no real Handle yet (e.g. because Item is in workflow)
                // we use the 'fake' Handle db-id/1234 where 1234 is the
                // database ID of the item.
                if (handle == null) {
                    handle = "db-id/" + item.getID();
                }

                out.print("<tr><td headers=\"t1\" class=\"standard\">");
                out.print("<a target=\"_blank\" href=\"");
                out.print(request.getContextPath());
                out.print("/html/");
                out.print(handle + "/");
                out.print(UIUtil.encodeBitstreamName(primaryBitstream.getName(), Constants.DEFAULT_ENCODING));
                out.print("\">");
                out.print(primaryBitstream.getName());
                out.print("</a>");

                if (multiFile) {
                    out.print("</td><td headers=\"t2\" class=\"standard\">");

                    String desc = primaryBitstream.getDescription();
                    out.print((desc != null) ? desc : "");
                }

                out.print("</td><td headers=\"t3\" class=\"standard\">");
                out.print(UIUtil.formatFileSize(primaryBitstream.getSize()));
                out.print("</td><td headers=\"t4\" class=\"standard\">");
                out.print(primaryBitstream.getFormatDescription());
                out.print("</td><td class=\"standard\"><a target=\"_blank\" href=\"");
                out.print(request.getContextPath());
                out.print("/html/");
                out.print(handle + "/");
                out.print(UIUtil.encodeBitstreamName(primaryBitstream.getName(), Constants.DEFAULT_ENCODING));
                out.print("\">" + LocaleSupport.getLocalizedMessage(pageContext,
                        "org.dspace.app.webui.jsptag.ItemTag.view") + "</a></td></tr>");
            } else {
                for (int i = 0; i < bundles.length; i++) {
                    Bitstream[] bitstreams = bundles[i].getBitstreams();

                    for (int k = 0; k < bitstreams.length; k++) {
                        // Skip internal types
                        if (!bitstreams[k].getFormat().isInternal()) {

                            // Work out what the bitstream link should be
                            // (persistent
                            // ID if item has Handle)
                            String bsLink = "<a target=\"_blank\" href=\"" + request.getContextPath();

                            if ((handle != null) && (bitstreams[k].getSequenceID() > 0)) {
                                bsLink = bsLink + "/bitstream/" + item.getHandle() + "/"
                                        + bitstreams[k].getSequenceID() + "/";
                            } else {
                                bsLink = bsLink + "/retrieve/" + bitstreams[k].getID() + "/";
                            }

                            bsLink = bsLink + UIUtil.encodeBitstreamName(bitstreams[k].getName(),
                                    Constants.DEFAULT_ENCODING) + "\">";

                            out.print("<tr><td headers=\"t1\" class=\"standard\">");
                            out.print(bsLink);
                            out.print(bitstreams[k].getName());
                            out.print("</a>");

                            if (multiFile) {
                                out.print("</td><td headers=\"t2\" class=\"standard\">");

                                String desc = bitstreams[k].getDescription();
                                out.print((desc != null) ? desc : "");
                            }

                            out.print("</td><td headers=\"t3\" class=\"standard\">");
                            out.print(UIUtil.formatFileSize(bitstreams[k].getSize()));
                            out.print("</td><td headers=\"t4\" class=\"standard\">");
                            out.print(bitstreams[k].getFormatDescription());
                            out.print("</td><td class=\"standard\" align=\"center\">");

                            // is there a thumbnail bundle?
                            if ((thumbs.length > 0) && showThumbs) {
                                String tName = bitstreams[k].getName() + ".jpg";
                                String tAltText = LocaleSupport.getLocalizedMessage(pageContext,
                                        "org.dspace.app.webui.jsptag.ItemTag.thumbnail");
                                Bitstream tb = thumbs[0].getBitstreamByName(tName);

                                if (tb != null) {
                                    String myPath = request.getContextPath() + "/retrieve/" + tb.getID() + "/"
                                            + UIUtil.encodeBitstreamName(tb.getName(),
                                                    Constants.DEFAULT_ENCODING);

                                    out.print(bsLink);
                                    out.print("<img src=\"" + myPath + "\" ");
                                    out.print("alt=\"" + tAltText + "\" /></a><br />");
                                }
                            }

                            out.print(bsLink + LocaleSupport.getLocalizedMessage(pageContext,
                                    "org.dspace.app.webui.jsptag.ItemTag.view") + "</a></td></tr>");
                        }
                    }
                }
            }

            out.println("</table>");
        }
    } catch (SQLException sqle) {
        throw new IOException(sqle.getMessage(), sqle);
    }

    out.println("</td></tr></table>");
}

From source file:org.dspace.app.webui.jsptag.ItemTag.java

/**
 * Link to the item licence//from w  w w . java  2  s  .c om
 */
private void showLicence() throws IOException {
    JspWriter out = pageContext.getOut();
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

    Bundle[] bundles = null;
    try {
        bundles = item.getBundles("LICENSE");
    } catch (SQLException sqle) {
        throw new IOException(sqle.getMessage(), sqle);
    }

    out.println("<table align=\"center\" class=\"attentionTable\"><tr>");

    out.println("<td class=\"attentionCell\"><p><strong>" + LocaleSupport.getLocalizedMessage(pageContext,
            "org.dspace.app.webui.jsptag.ItemTag.itemprotected") + "</strong></p>");

    for (int i = 0; i < bundles.length; i++) {
        Bitstream[] bitstreams = bundles[i].getBitstreams();

        for (int k = 0; k < bitstreams.length; k++) {
            out.print("<div align=\"center\" class=\"standard\">");
            out.print("<strong><a target=\"_blank\" href=\"");
            out.print(request.getContextPath());
            out.print("/retrieve/");
            out.print(bitstreams[k].getID() + "/");
            out.print(UIUtil.encodeBitstreamName(bitstreams[k].getName(), Constants.DEFAULT_ENCODING));
            out.print("\">" + LocaleSupport.getLocalizedMessage(pageContext,
                    "org.dspace.app.webui.jsptag.ItemTag.viewlicence") + "</a></strong></div>");
        }
    }

    out.println("</td></tr></table>");
}

From source file:org.dspace.app.webui.jsptag.LayoutTag.java

public int doStartTag() throws JspException {
    ServletRequest request = pageContext.getRequest();

    // Sort out location bar
    if (locbar == null) {
        locbar = "auto";
    }// ww w . j a v  a 2  s  .  c o  m

    // These lists will contain titles and links to put in the location
    // bar
    List<String> parents = new ArrayList<String>();
    List<String> parentLinks = new ArrayList<String>();

    if (locbar.equalsIgnoreCase("off")) {
        // No location bar
        request.setAttribute("dspace.layout.locbar", Boolean.FALSE);
    } else {
        // We'll always add "DSpace Home" to the a location bar
        parents.add(ConfigurationManager.getProperty("dspace.name"));

        if (locbar.equalsIgnoreCase("nolink")) {
            parentLinks.add("");
        } else {
            parentLinks.add("/");
        }

        // Add other relevant components to the location bar
        if (locbar.equalsIgnoreCase("link")) {
            // "link" mode - next thing in location bar is taken from
            // parameters of tag, with a link
            if (parentTitle != null) {
                parents.add(parentTitle);
                parentLinks.add(parentLink);
            } else if (parentTitleKey != null) {
                parents.add(LocaleSupport.getLocalizedMessage(pageContext, parentTitleKey));
                parentLinks.add(parentLink);
            }

        } else if (locbar.equalsIgnoreCase("commLink")) {
            // "commLink" mode - show all parent communities
            Community[] comms = (Community[]) request.getAttribute("dspace.communities");

            if (comms != null) {
                for (int i = 0; i < comms.length; i++) {
                    parents.add(comms[i].getMetadata("name"));
                    parentLinks.add("/handle/" + comms[i].getHandle());
                }
            }
        } else if (locbar.equalsIgnoreCase("nolink")) {
            // "nolink" mode - next thing in location bar is taken from
            // parameters of tag, with no link
            if (parentTitle != null) {
                parents.add(parentTitle);
                parentLinks.add("");
            }
        } else {
            // Grab parents from the URL - these should have been picked up
            // by the HandleServlet
            Collection col = (Collection) request.getAttribute("dspace.collection");
            Community[] comms = (Community[]) request.getAttribute("dspace.communities");

            if (comms != null) {
                for (int i = 0; i < comms.length; i++) {
                    parents.add(comms[i].getMetadata("name"));
                    parentLinks.add("/handle/" + comms[i].getHandle());
                }

                if (col != null) {
                    parents.add(col.getMetadata("name"));
                    parentLinks.add("/handle/" + col.getHandle());
                }
            }
        }

        request.setAttribute("dspace.layout.locbar", Boolean.TRUE);
    }

    request.setAttribute("dspace.layout.parenttitles", parents);
    request.setAttribute("dspace.layout.parentlinks", parentLinks);

    // Navigation bar: "default" is default :)
    if (navbar == null) {
        navbar = "default";
    }

    if (navbar.equals("off")) {
        request.setAttribute("dspace.layout.navbar", "off");
    } else {
        request.setAttribute("dspace.layout.navbar", templatePath + "navbar-" + navbar + ".jsp");
    }

    // Set title
    if (title != null) {
        request.setAttribute("dspace.layout.title", title);
    } else if (titleKey != null) {
        request.setAttribute("dspace.layout.title", LocaleSupport.getLocalizedMessage(pageContext, titleKey));
    } else {
        request.setAttribute("dspace.layout.title", "NO TITLE");
    }

    // Set feedData if present
    if (feedData != null && !"NONE".equals(feedData)) {
        // set the links' reference - community or collection
        boolean commLinks = feedData.startsWith("comm:");
        boolean collLinks = feedData.startsWith("coll:");
        if (commLinks) {
            Community com = (Community) request.getAttribute("dspace.community");
            request.setAttribute("dspace.layout.feedref", com.getHandle());
        } else if (collLinks) {
            Collection col = (Collection) request.getAttribute("dspace.collection");
            request.setAttribute("dspace.layout.feedref", col.getHandle());
        } else //feed is across all of DSpace and not Community/Collection specific
        {
            request.setAttribute("dspace.layout.feedref", FeedServlet.SITE_FEED_KEY);
        }

        // build a list of link attributes for each link format
        String[] formats = feedData.substring(feedData.indexOf(':') + 1).split(",");
        List<String> linkParts = new ArrayList<String>();
        // each link has a mime-type, title, and format (used in href URL)
        for (int i = 0; i < formats.length; i++) {
            if ("rss_1.0".equals(formats[i])) {
                linkParts.add("rdf+xml");
            } else {
                linkParts.add("rss+xml");
            }

            if (commLinks) {
                linkParts.add("Items in Community");
            } else if (collLinks) {
                linkParts.add("Items in Collection");
            } else {
                linkParts.add("Items in " + ConfigurationManager.getProperty("dspace.name"));
            }

            linkParts.add(formats[i]);
        }
        request.setAttribute("dspace.layout.linkparts", linkParts);
    } else {
        request.setAttribute("dspace.layout.feedref", "NONE");
    }

    return EVAL_BODY_BUFFERED;
}

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 ww .j av a2  s  . 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\">&nbsp;</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  ww.  j  a v a 2s. c  o  m
        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=\"\">&nbsp;</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;
}

From source file:org.dspace.app.webui.jsptag.SelectGroupTag.java

public int doStartTag() throws JspException {
    try {/*from w  w  w  .j  av  a  2 s . c  o m*/
        JspWriter out = pageContext.getOut();
        HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();

        out.print(
                "<table><tr><td colspan=\"2\" align=\"center\"><select multiple=\"multiple\" name=\"group_ids\" size=\"");
        out.print(multiple ? "10" : "1");
        out.println("\">");

        //ensure that if no group is selected that a blank option is displayed - xhtml compliance 
        if (groups == null || groups.length == 0) {
            out.print("<option value=\"\">&nbsp;</option>");
        }

        if (groups != null) {
            for (int i = 0; i < groups.length; i++) {
                out.print("<option value=\"" + groups[i].getID() + "\">");
                out.print(groups[i].getName() + " (" + groups[i].getID() + ")");
                out.println("</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.SelectGroupTag.selectGroups")
                : LocaleSupport.getLocalizedMessage(pageContext,
                        "org.dspace.app.webui.jsptag.SelectGroupTag.selectGroup"));
        out.print("<input type=\"button\" value=\"" + p + "\" onclick=\"javascript:popup_window('"
                + req.getContextPath() + "/tools/group-select-list?multiple=" + multiple
                + "', 'group_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.SelectGroupTag.removeSelected")
                    + "\" onclick=\"javascript:removeSelected(window.document.epersongroup.group_ids);\"/>");
        }

        out.println("</td></tr></table>");
    } catch (IOException ie) {
        throw new JspException(ie);
    }

    return SKIP_BODY;
}

From source file:org.gbif.portal.web.tag.TagUtils.java

/**
 * Returns a i18n string for the supplied key.
 * @param messageKey/*from  ww  w .  j a  v  a 2 s  . c o m*/
 * @param defaultValue
 * @param pageContext
 * @return the i18n string for the supplied key
 */
public static String getMessage(String messageKey, String defaultValue, PageContext pageContext) {
    // if messageKey isn't defined either, use defaultValue
    String key = (messageKey != null) ? messageKey : defaultValue;
    String message = LocaleSupport.getLocalizedMessage(pageContext, key);
    return message;
}