Java Code Examples for javax.portlet.PortletConfig#getResourceBundle()

The following examples show how to use javax.portlet.PortletConfig#getResourceBundle() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PortletModeDropDownTag.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
/**
   * Obtains decoration name for a portlet managed mode from the portlet's resource bundle
   * as defined in PLT.8.4 of the JSR-286 spec using the key 
   * javax.portlet.app.custom-portlet-mode.<custom mode>.decoration-name where
   * custom mode is the name of the custom mode as defined in portlet.xml
   * (//portlet-app/custom-portlet-mode/portlet-mode element). If the decoration
   * name is not found in the resource bundle, this method returns the uppercased
   * mode name.
   * 
   * @param driverConfig the driver config object found in the session.
   * @param mode the portlet managed custom mode that will be searched for decoration name
   * in the resource bundle.
   * @return the decoration name for a portlet managed mode in the resource bundle
   * using the key javax.portlet.app.custom-portlet-mode.<custom mode>.decoration-name 
   * where custom mode is the name of the custom mode as defined in portlet.xml
   * (//portlet-app/custom-portlet-mode/portlet-mode element). If the decoration
   * name is not found in the resource bundle, the uppercased
   * mode name is returned.
   */
  private String getCustomModeDecorationName(DriverConfiguration driverConfig, 
  		PortletMode mode) {
  	//decoration name is mode name by default
String decorationName = mode.toString().toUpperCase();
ResourceBundle bundle;
StringBuffer res;
try {
	PortletConfig config = driverConfig.getPortletConfig(evaluatedPortletId);
	ServletRequest request = pageContext.getRequest();
	Locale defaultLocale = request.getLocale();
	bundle = config.getResourceBundle(defaultLocale);
	res = new StringBuffer();
	res.append("javax.portlet.app.custom-portlet-mode.");
	res.append(mode.toString());
	res.append(".decoration-name");
	decorationName = bundle.getString(res.toString());
} catch (Exception e) {
	LOG.debug("Problem finding decoration-name for custom mode: " + mode.toString());
}
return decorationName;
  }
 
Example 2
Source File: ResourceBundleTest.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
protected TestResult checkResourceBundleExists(PortletConfig config,
                                               PortletRequest request) {
    TestResult result = new TestResult();
    result.setDescription("Ensure the resource bundle is not null.");

    ResourceBundle bundle = config.getResourceBundle(request.getLocale());
    if (bundle != null) {
    	result.setReturnCode(TestResult.PASSED);
    } else {
    	result.setReturnCode(TestResult.FAILED);
        result.setResultMessage("Unable to retrieve resource bundle "
        		+ "for locale: " + request.getLocale());
    }
    return result;
}
 
Example 3
Source File: ResourceBundleTest.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
protected TestResult checkGetNames(PortletConfig config,
                                   PortletRequest request) {
    TestResult result = new TestResult();
    result.setDescription("Retrieve the property names and ensure that "
    		+ "the required keys are present.");

    List<String> requiredKeys = new ArrayList<String>();
    requiredKeys.add(TITLE_KEY);
    requiredKeys.add(SHORT_TITLE_KEY);
    requiredKeys.add(KEYWORDS_KEY);

    ResourceBundle bundle = config.getResourceBundle(request.getLocale());
    if (bundle == null) {
    	result.setReturnCode(TestResult.WARNING);
    	result.setResultMessage("A function upon which this test depends "
    			+ "failed to execute as expected. "
    			+ "Check the other test results in this test suite.");
    	return result;
    }

    for (Enumeration<String> en = bundle.getKeys(); 
    			en.hasMoreElements(); ) {
        String key = (String) en.nextElement();
        requiredKeys.remove(key);
    }

    if (requiredKeys.isEmpty()) {
    	result.setReturnCode(TestResult.PASSED);
    } else {
    	result.setReturnCode(TestResult.FAILED);
        StringBuffer buffer = new StringBuffer();
        for (Iterator<String> it = requiredKeys.iterator(); it.hasNext(); ) {
        	buffer.append(it.next()).append(", ");
        }
        result.setResultMessage("Required keys [" + buffer.toString()
        		+ "] are missing in the resource bundle.");
    }
    return result;
}
 
Example 4
Source File: ResourceBundleTest.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
private TestResult doGenericLocaleRequiredFields(PortletConfig config,
                                                 PortletRequest request,
                                                 Locale locale) {
    TestResult result = new TestResult();
    result.setDescription("Retrieve the title and ensure it's set properly "
    		+ "under locale " + locale);

    // Retrieve title, short title and keywords from portlet resource bundle.
    ResourceBundle bundle = config.getResourceBundle(locale);
    if (bundle == null) {
    	result.setReturnCode(TestResult.WARNING);
    	result.setResultMessage("A function upon which this test depends "
    			+ "failed to execute as expected. "
    			+ "Check the other test results in this test suite.");
    	return result;
    }
    String title = bundle.getString(TITLE_KEY);
    String shortTitle = bundle.getString(SHORT_TITLE_KEY);
    String keywords = bundle.getString(KEYWORDS_KEY);

    // Retrieve expected title, short title and keywords from test config.
    String suffix = isBundleDeclared() ? ("_" + locale.getLanguage()) : "";
    Map<String, String> initParams = getInitParameters();
    String expectedTitle = (String) initParams.get(
    		TITLE_PARAM + suffix);
    String expectedShortTitle = (String) initParams.get(
    		SHORT_TITLE_PARAM + suffix);
    String expectedKeywords = (String) initParams.get(
    		KEYWORDS_PARAM + suffix);

    // Assert that values retrieved from resource bundler are expected.
    boolean inconsistent = false;
    StringBuffer buffer = new StringBuffer();
    buffer.append("The following information is not correct: ");
    if (title == null || expectedTitle == null
    		|| !title.trim().equals(expectedTitle.trim())) {
    	inconsistent = true;
        buffer.append("Inconsistent title: '")
        		.append(title).append("' != '")
        		.append(expectedTitle).append("'; ");
    }
    if (shortTitle == null || expectedShortTitle == null
    		|| !shortTitle.trim().equals(expectedShortTitle.trim())) {
    	inconsistent = true;
        buffer.append("Inconsistent short title: '")
        		.append(shortTitle).append("' != '")
        		.append(expectedShortTitle).append("'; ");
    }
    if (keywords == null || expectedKeywords == null
    		|| !keywords.trim().equals(expectedKeywords.trim())) {
    	inconsistent = true;
        buffer.append("Inconsistent keywords: '")
        		.append(keywords).append("' != '")
        		.append(expectedKeywords).append("'; ");
    }

    if (!inconsistent) {
    	result.setReturnCode(TestResult.PASSED);
    } else {
    	result.setReturnCode(TestResult.FAILED);
        result.setResultMessage(buffer.toString());
    }
    return result;
}
 
Example 5
Source File: PortletTitleTag.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
/**
 * Method invoked when the start tag is encountered. This method retrieves the portlet title and print it to the
 * page.
 * 
 * @see org.apache.pluto.container.services.PortalCallbackService#setTitle(HttpServletRequest, PortletWindow, String)
 * @see org.apache.pluto.driver.services.container.PortalCallbackServiceImpl#setTitle(HttpServletRequest,
 *      PortletWindow, String)
 * 
 * @throws JspException
 */
@SuppressWarnings("unchecked")
public int doStartTag() throws JspException {

   // Ensure that the portlet title tag resides within a portlet tag.
   PortletTag parentTag = (PortletTag) TagSupport.findAncestorWithClass(this, PortletTag.class);
   if (parentTag == null) {
      throw new JspException("Portlet title tag may only reside " + "within a pluto:portlet tag.");
   }

   // Print out the portlet title to page.
   try {

      Map<String, String> titles = (Map<String, String>) pageContext.getRequest().getAttribute(AttributeKeys.PORTLET_TITLE);

      String portletId = parentTag.getEvaluatedPortletId();

      String title = null;
      if (titles != null) {
         title = titles.get(portletId);
      }

      if (title == null) {

         PortletWindowConfig windowConfig = PortletWindowConfig.fromId(portletId);

         try {
            ServletContext servletContext = pageContext.getServletContext();
            DriverConfiguration driverConfig = (DriverConfiguration) servletContext.getAttribute(AttributeKeys.DRIVER_CONFIG);
            PortletConfig config = driverConfig.getPortletConfig(portletId);
            ServletRequest request = pageContext.getRequest();
            Locale defaultLocale = request.getLocale();
            ResourceBundle bundle = config.getResourceBundle(defaultLocale);
            title = bundle.getString("javax.portlet.title");
         } catch (Throwable th) {
            if (LOG.isDebugEnabled()) {
               StringBuilder txt = new StringBuilder(128);
               txt.append("Could not obtain title for: " + windowConfig.getPortletName() + "\n");
               StringWriter sw = new StringWriter();
               PrintWriter pw = new PrintWriter(sw);
               th.printStackTrace(pw);
               pw.flush();
               txt.append(sw.toString());
               LOG.warn(txt.toString());
            }
         }

         if (title == null) {
            title = "[ " + windowConfig.getPortletName() + " ]";
         }
      }

      pageContext.getOut().print(title);
   } catch (IOException ex) {
      throw new JspException(ex);
   }
   return SKIP_BODY;
}