Package javax.portlet

Examples of javax.portlet.PortletPreferences


        TestResult result = new TestResult();
        result.setDescription("Ensure the first value set to a given "
            + "preference is returned first by PortletPreferences.getValue().");
        result.setSpecPLT("14.1");
       
        PortletPreferences preferences = request.getPreferences();
        try {
            preferences.setValues("TEST", new String[] { "FIRST", "SECOND" });
        } catch (ReadOnlyException ex) {
          TestUtils.failOnException("Unable to set preference values.", ex, result);
          return result;
        }

        String value = preferences.getValue("TEST", DEF_VALUE);
        if (value != null && value.equals("FIRST")) {
          result.setReturnCode(TestResult.PASSED);
        } else {
          TestUtils.failOnAssertion("preference value", value, "FIRST", result);
        }
View Full Code Here


    protected TestResult checkResetPreferenceToDefault(PortletRequest request) {
      TestResult result = new TestResult();
      result.setDescription("Ensure preferences are properly reset.");
      result.setSpecPLT("14.1");
       
        PortletPreferences preferences = request.getPreferences();
        boolean setOccured = false;
        boolean resetOccured = false;
       
        try {
          // Set new value to overwrite the default value.
            preferences.setValue(PREF_NAME, NEW_VALUE);
            String value = preferences.getValue(PREF_NAME, DEF_VALUE);
            if (NEW_VALUE.equals(value)) {
                setOccured = true;
            }
            // Reset the preference so that default value is restored.
            preferences.reset(PREF_NAME);
            value =  preferences.getValue(PREF_NAME, DEF_VALUE);
            if (PREF_VALUE.equals(value)) {
                resetOccured = true;
            }
        } catch (ReadOnlyException ex) {
          TestUtils.failOnException("Unable to set preference value.", ex, result);
View Full Code Here

      TestResult result = new TestResult();
        result.setDescription("Ensure preferences are properly reset (removed) "
            + "when the default value is not defined.");
        result.setSpecPLT("14.1");
       
        PortletPreferences preferences = request.getPreferences();
        boolean setOccured = false;
        boolean resetOccured = false;
       
        try {
          // Set preference value to overwrite the original (null).
            preferences.setValue(BOGUS_KEY, NEW_VALUE);
            String value = preferences.getValue(BOGUS_KEY, DEF_VALUE);
            if (NEW_VALUE.equals(value)) {
                setOccured = true;
            }
            // Reset preference value to null.
            preferences.reset(BOGUS_KEY);
            value =  preferences.getValue(BOGUS_KEY, DEF_VALUE);
            if (DEF_VALUE.equals(value)) {
                resetOccured = true;
            }
        } catch (ReadOnlyException ex) {
          TestUtils.failOnException("Unable to set preference value.", ex, result);
View Full Code Here

        result.setDescription("Ensure that setValue() / setValues() / reset() "
            + "methods throw ReadOnlyException when invoked "
            + "on read-only preferences.");
        result.setSpecPLT("14.1");
       
        PortletPreferences preferences = request.getPreferences();
        if (!preferences.isReadOnly(READ_ONLY_PREF_NAME)) {
          result.setReturnCode(TestResult.WARNING);
          result.setResultMessage("Preference " + READ_ONLY_PREF_NAME
              + " is not a read-only preference. "
              + "This may be due to misconfiuration.");
          return result;
        }
       
        boolean setValueOK = false;
        boolean setValuesOK = false;
        boolean resetOK = false;
       
        // Check setValue() method.
        try {
            preferences.setValue(READ_ONLY_PREF_NAME, "written");
        } catch (ReadOnlyException ex) {
            setValueOK = true;
        }
       
        // Check setValues() method.
        try {
          preferences.setValues(READ_ONLY_PREF_NAME, new String[] { "written" });
        } catch (ReadOnlyException ex) {
          setValuesOK = true;
        }
       
        // Check reset() method.
        try {
          preferences.reset(READ_ONLY_PREF_NAME);
        } catch (ReadOnlyException ex) {
          resetOK = true;
        }
       
        if (setValueOK && setValuesOK && resetOK) {
View Full Code Here

    protected TestResult checkGetPreferenceNames(PortletRequest request) {
        TestResult result = new TestResult();
        result.setDescription("Ensure returned enumeration is valid.");
        result.setSpecPLT("14.1");
       
        PortletPreferences preferences = request.getPreferences();
        Map prefMap = preferences.getMap();
        boolean hasAll = true;
        for (Enumeration en = preferences.getNames(); en.hasMoreElements(); ) {
            if (!prefMap.containsKey(en.nextElement())) {
                hasAll = false;
                break;
            }
        }
View Full Code Here

      TestResult result = new TestResult();
      result.setDescription("Preferences values are not modified if "
          + "the values in the returned preference Map are altered.");
      result.setSpecPLT("14.1");
     
      PortletPreferences preferences = request.getPreferences();
        if (LOG.isDebugEnabled()) {
          LOG.debug("Original Preferences:");
          logPreferences(preferences);
        }
       
        // Modify the returned preference map.
      Map prefMap = preferences.getMap();
      String[] values = (String[]) prefMap.get(PREF_NAME);
      String originalValue = null;
      String modifiedValue = "Value modified in preferences map.";
      if (values != null && values.length == 1) {
        originalValue = values[0];
        values[0] = modifiedValue;
      }
     
      // Check if the value held by portlet preferences is modified.
        if (LOG.isDebugEnabled()) {
          LOG.debug("Modified Preferences:");
          logPreferences(preferences);
        }
      String newValue = preferences.getValue(PREF_NAME, DEF_VALUE);
      if (newValue != null && newValue.equals(originalValue)) {
        result.setReturnCode(TestResult.PASSED);
      } else {
        result.setReturnCode(TestResult.FAILED);
        result.setResultMessage("Preference value modified according to "
View Full Code Here

        return this.request.getAuthType();
    }

    private synchronized void wrapCookies() {
        this.wrappedCookieMap = new HashMap();
        PortletPreferences cookies = this.request.getPreferences();
        if (cookies != null) {
            this.wrappedCookies = new Cookie[cookies.getMap().size()];
            int i = 0;
            for (Enumeration e = cookies.getNames(); e.hasMoreElements(); i++) {
                String name = (String) e.nextElement();
                PortletCookie cookie = new PortletCookie(name, cookies.getValue(name, null));
                this.wrappedCookies[i] = cookie;
                this.wrappedCookieMap.put(cookie.getName(), cookie);
            }
        }
        this.wrappedCookieMap = Collections.unmodifiableMap(this.wrappedCookieMap);
View Full Code Here

     * @see javax.portlet.Portlet#processAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse)
     */
    public void processAction(ActionRequest req, ActionResponse res)
    throws PortletException, IOException {

        PortletPreferences prefs = req.getPreferences();
        String key = req.getParameter("name");
        String value = req.getParameter("value");
        if (key != null && value != null) {
            prefs.setValue(key, value);
            try {
              prefs.store();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
         // nothing to do
View Full Code Here

        writer.write("<p>This is a Cocoon test portlet.</p>\n");
        writer.write("<p>I'm running in: " + req.getPortalContext().getPortalInfo());
        writer.write("<p>Current portlet mode: " + req.getPortletMode() + "</p>");
        writer.write("<p>Current window state: " + req.getWindowState() + "</p>");
        writer.write("<p>Portlet Preferences:</p>");
        PortletPreferences prefs = req.getPreferences();
        Map map = prefs.getMap();
        for (Iterator iter = map.entrySet().iterator(); iter.hasNext(); ) {
            Map.Entry me = (Map.Entry)iter.next();
            String key = (String)me.getKey();
            String[] values = (String [])me.getValue();
            if (values.length == 1) {
View Full Code Here

        Context context = this.getContext(request);

        String sortColName = request.getParameter(SORT_COLUMN_NAME);
        int start = getStartVariable(request, START, sortColName, iterator);
       
        PortletPreferences prefs = request.getPreferences();

        windowSize = Integer.parseInt(prefs.getValue(WINDOW_SIZE, "10"));
       
        StatusMessage message = (StatusMessage)PortletMessaging.consume(request, "DatabaseBrowserPortlet", "action");
        if (message != null)
        {
            this.getContext(request).put("statusMsg", message);           
View Full Code Here

TOP

Related Classes of javax.portlet.PortletPreferences

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.