Java Code Examples for javax.portlet.ActionResponse#getRenderParameters()

The following examples show how to use javax.portlet.ActionResponse#getRenderParameters() . 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: HeaderPortletTests_SPEC14_PortletRequest_ApiHeader1.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
@Override
public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException {
   MutableRenderParameters renderParams = actionResponse.getRenderParameters();
   renderParams.setValue("trB3", "true");
   renderParams.setValue("trB1", "true");
   renderParams.setValue("trA1", "true");
   renderParams.setValue("trPara1", "true");
   renderParams.setValue("trPara2", "true");
   renderParams.setValues("trPara4", "true", "false");
   renderParams.setValue("trPara6", "true");
   renderParams.setValues("trPara7", "true", "false");
   renderParams.setValues("trPara8", "true", "false");
   renderParams.setValue("trPara9", "true");
   renderParams.setValue("trPara10a", "true");
   renderParams.setValue("trPara10b", "true");
   renderParams.setValue("trPrivate1", "true");
   renderParams.setValue("trPrivate2", "true");
   renderParams.setValue("trPublic1", "true");
   renderParams.setValue("trPublic2", "true");
}
 
Example 2
Source File: UrlRPTestPortlet.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
public void processAction(ActionRequest req, ActionResponse resp)
      throws PortletException, IOException {
   
   ActionParameters ap = req.getActionParameters();
   MutableRenderParameters mrp = resp.getRenderParameters();
   Set<? extends String> rpNames = mrp.getNames();

   if (isDebug) {
      StringBuffer sb = new StringBuffer();
      sb.append("Action parameters:");
      for (String k : ap.getNames()) {
         sb.append("\nName: ").append(k);
         sb.append(", Values: ").append(Arrays.toString(ap.getValues(k)));
      }
      logger.debug(sb.toString());
   }

   // Handle the control parameters
   
   String setType = ap.getValue(PARAM_SETTYPE);
   setType = (setType == null) ? PARAM_SETTYPE_VARRAY : setType;
   mrp.setValue(PARAM_SETTYPE, setType);
   
   String remType = ap.getValue(PARAM_REMTYPE);
   remType = (remType == null) ? PARAM_REMTYPE_SET : remType;
   mrp.setValue(PARAM_REMTYPE, remType);
   
   String aurlCopy = ap.getValue(PARAM_AURLCOPY);
   aurlCopy = (aurlCopy == null) ? PARAM_AURLCOPY_ALL : aurlCopy;
   mrp.setValue(PARAM_AURLCOPY, aurlCopy);
   
   // Get the parameter name & values. Parse values string into individual values.
   // if string is 'null', change it into null.
   
   // string escape here to avoid xss vulnerability & problem with portlet hub json
   String pn = StringEscapeUtils.escapeHtml4(ap.getValue(PARAM_NAME));
   String pv = StringEscapeUtils.escapeHtml4(ap.getValue(PARAM_VALUES));

   String[] parsedVals = null;
   StringBuilder txt = new StringBuilder("Setting values to ");
   if (pn != null && pn.length() > 0 && pv != null) {
      parsedVals = pv.split(",", -1);
      if (pv.length() == 0) {
         txt.append("array containing single empty string");
         parsedVals = new String[] {""};
      } else if (parsedVals.length == 1) {
         if (parsedVals[0].equals("null")) {
            txt.append("null");
            parsedVals = null;
         } else if (parsedVals[0].equals("empty")) {
            txt.append("an empty array.");
            parsedVals = new String[0];
         } else {
            txt.append("an array containing the single item");
         }
      } else {
         txt.append("an array of values");
         for (int ii = 0; ii < parsedVals.length; ii++) {
            if (parsedVals[ii].equals("null")) {
               parsedVals[ii] = null;
            }
         }
      }
      try {
         if (remType.equals(PARAM_REMTYPE_REM)) {
            txt.append(". Removing parameter");
            mrp.removeParameter(pn);
         } else {
            if (setType.equals(PARAM_SETTYPE_VARRAY)) {
               txt.append(" using values array");
               mrp.setValues(pn, parsedVals);
            } else {
               txt.append(" using first value in array");
               String tval = (parsedVals == null) ? null : parsedVals[0];
               mrp.setValue(pn, tval);
            }
         }
      } catch(Exception e) {
         StringBuilder err = new StringBuilder("Exception setting parameter: ");
         err.append(e.toString());
         mrp.setValue("Error:", "<span style='color: red;'>" + err.toString() + "</span>");
      }
   } else if (rpNames.isEmpty()) {
      txt.append("the error message");
      mrp.setValue("Error:", "<span style='color: red;'>No parameters available!</span>");
   }
   
   if (isDebug) {
      logger.debug(txt.toString());
      txt = new StringBuilder("Parsed Action Parameters: ");
      txt.append(", Name: ").append(pn);
      txt.append(", Value string: >>").append(pv).append("<<");
      txt.append(", Parsed Values: ").append(Arrays.toString(parsedVals));
      logger.debug(txt.toString());
   }

}
 
Example 3
Source File: ParamTestPortlet.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
public void processAction(ActionRequest req, ActionResponse resp)
      throws PortletException, IOException {
   
   ActionParameters ap = req.getActionParameters();
   MutableRenderParameters mrp = resp.getRenderParameters();
   Set<? extends String> rpNames = mrp.getNames();

   if (isDebug) {
      StringBuffer sb = new StringBuffer();
      sb.append("Action parameters:");
      for (String k : ap.getNames()) {
         sb.append("\nName: ").append(k);
         sb.append(", Values: ").append(Arrays.toString(ap.getValues(k)));
      }
      logger.debug(sb.toString());
   }

   // decide how the set / remove is to be done
   
   String setType = ap.getValue(PARAM_SETTYPE);
   setType = (setType == null) ? PARAM_SETTYPE_VARRAY : setType;
   mrp.setValue(PARAM_SETTYPE, setType);
   
   String remType = ap.getValue(PARAM_REMTYPE);
   remType = (remType == null) ? PARAM_REMTYPE_SET : remType;
   mrp.setValue(PARAM_REMTYPE, remType);
   
   // Get the parameter name & values. Parse values string into individual values.
   // if string is 'null', change it into null.
   
   // string escape here to avoid xss vulnerability & problem with portlet hub json
   String pn = StringEscapeUtils.escapeHtml4(ap.getValue(PARAM_NAME));
   String pv = StringEscapeUtils.escapeHtml4(ap.getValue(PARAM_VALUES));

   String[] parsedVals = null;
   StringBuilder txt = new StringBuilder("Setting values to ");
   if (pn != null && pn.length() > 0 && pv != null) {
      if (pn.equals("null")) {
         pn = null;
      }
      parsedVals = pv.split(",", -1);
      if (pv.length() == 0) {
         txt.append("array containing single empty string");
         parsedVals = new String[] {""};
      } else if (parsedVals.length == 1) {
         if (parsedVals[0].equals("null")) {
            txt.append("null");
            parsedVals = null;
         } else if (parsedVals[0].equals("empty")) {
            txt.append("an empty array.");
            parsedVals = new String[0];
         } else {
            txt.append("an array containing the single item");
         }
      } else {
         txt.append("an array of values");
         for (int ii = 0; ii < parsedVals.length; ii++) {
            if (parsedVals[ii].equals("null")) {
               parsedVals[ii] = null;
            }
         }
      }
      try {
         if (remType.equals(PARAM_REMTYPE_REM)) {
            txt.append(". Removing parameter");
            mrp.removeParameter(pn);
         } else {
            if (setType.equals(PARAM_SETTYPE_VARRAY)) {
               txt.append(" using values array");
               mrp.setValues(pn, parsedVals);
            } else {
               txt.append(" using first value in array");
               String tval = (parsedVals == null) ? null : parsedVals[0];
               mrp.setValue(pn, tval);
            }
         }
      } catch(Exception e) {
         StringBuilder err = new StringBuilder("Exception setting parameter: ");
         err.append(e.toString());
         mrp.setValue("Error:", "<span style='color: red;'>" + err.toString() + "</span>");
      }
   } else if (rpNames.isEmpty()) {
      txt.append("the error message");
      mrp.setValue("Error:", "<span style='color: red;'>No parameters available!</span>");
   }
   
   if (isDebug) {
      logger.debug(txt.toString());
      txt = new StringBuilder("Parsed Action Parameters: ");
      txt.append(", Name: ").append(pn);
      txt.append(", Value string: >>").append(pv).append("<<");
      txt.append(", Parsed Values: ").append(Arrays.toString(parsedVals));
      logger.debug(txt.toString());
   }

}
 
Example 4
Source File: PortletHubTests_SPEC_23_JSPA.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
@Override
public void processAction(ActionRequest portletReq, ActionResponse portletResp) throws PortletException, IOException {
   
   MutableRenderParameters mrp = portletResp.getRenderParameters();
   String testcase = mrp.getValue("testcase");
   ActionParameters ap = portletReq.getActionParameters();
   String status = "OK";
  
   if (testcase == null || testcase.isEmpty()) {
      mrp.setValue("status", "Failed. No test case parameter present.");

   /* TestCase: V3PortletHubTests_SPEC_23_JSPA_startPartialAction1               */
   /* Details: "The portlet hub startPartialAction function can be called with   */
   /* no arguments"                                                              */
   } else if (testcase.equals(V3PORTLETHUBTESTS_SPEC_23_JSPA_STARTPARTIALACTION1)) {
      if (!ap.isEmpty()) {
         status = "Failed. Action parameters are set: " + Arrays.asList(ap.getNames()).toString();
      }

   /* TestCase: V3PortletHubTests_SPEC_23_JSPA_startPartialAction2               */
   /* Details: "The portlet hub startPartialAction function can be called with   */
   /* an action parameters argument"                                             */
   } else if (testcase.equals(V3PORTLETHUBTESTS_SPEC_23_JSPA_STARTPARTIALACTION2)) {
      String param = ap.getValue("param1");
      if (param == null || !param.equals("val1")) {
         status = "Failed. Action parameter had incorrect value: " + param;
      }

   /* TestCase: V3PortletHubTests_SPEC_23_JSPA_startPartialAction3               */
   /* Details: "The portlet hub startPartialAction function returns a            */
   /* PartialActionInit object"                                                  */
   } else if (testcase.equals(V3PORTLETHUBTESTS_SPEC_23_JSPA_STARTPARTIALACTION3)) {

   /* TestCase: V3PortletHubTests_SPEC_23_JSPA_startPartialAction4               */
   /* Details: "The PartialActionInit object has a url property of type string"  */
   } else if (testcase.equals(V3PORTLETHUBTESTS_SPEC_23_JSPA_STARTPARTIALACTION4)) {

   /* TestCase: V3PortletHubTests_SPEC_23_JSPA_startPartialAction5               */
   /* Details: "The PartialActionInit object has a setPageState property of type */
   /* function"                                                                  */
   } else if (testcase.equals(V3PORTLETHUBTESTS_SPEC_23_JSPA_STARTPARTIALACTION5)) {

   /* TestCase: V3PortletHubTests_SPEC_23_JSPA_startPartialAction6               */
   /* Details: "The PartialActionInit object url property used in an XHR causes  */
   /* a token to be returned that completes the partial action when passed to    */
   /* the setPageState function"                                                 */
   } else if (testcase.equals(V3PORTLETHUBTESTS_SPEC_23_JSPA_STARTPARTIALACTION6)) {

   /* TestCase: V3PortletHubTests_SPEC_23_JSPA_startPartialAction7               */
   /* Details: "The onStateChange event resulting from a partial action contains */
   /* render data produced by the portlet resource method"                       */
   } else if (testcase.equals(V3PORTLETHUBTESTS_SPEC_23_JSPA_STARTPARTIALACTION7)) {
      
   } else {
      status = "Failed. unknown test case: " + testcase;
   }
   
   mrp.setValue("status", status);

}