Exemplo n.º 1
0
  protected void mergePublicRenderParameters(
      DynamicServletRequest dynamicRequest, PortletPreferences preferences, long plid) {

    Enumeration<PublicRenderParameter> publicRenderParameters =
        Collections.enumeration(_portlet.getPublicRenderParameters());

    while (publicRenderParameters.hasMoreElements()) {
      PublicRenderParameter publicRenderParameter = publicRenderParameters.nextElement();

      String ignoreKey = PublicRenderParameterConfiguration.getIgnoreKey(publicRenderParameter);

      boolean ignoreValue = GetterUtil.getBoolean(preferences.getValue(ignoreKey, null));

      if (ignoreValue) {
        continue;
      }

      String mappingKey = PublicRenderParameterConfiguration.getMappingKey(publicRenderParameter);

      String mappingValue = GetterUtil.getString(preferences.getValue(mappingKey, null));

      HttpServletRequest request = (HttpServletRequest) dynamicRequest.getRequest();

      String[] newValues = request.getParameterValues(mappingValue);

      if ((newValues != null) && (newValues.length != 0)) {
        newValues = ArrayUtil.remove(newValues, StringPool.NULL);
      }

      String name = publicRenderParameter.getIdentifier();

      if ((newValues == null) || (newValues.length == 0)) {
        QName qName = publicRenderParameter.getQName();

        String[] values =
            _publicRenderParameters.get(PortletQNameUtil.getPublicRenderParameterName(qName));

        if ((values) == null || (values.length == 0) || (Validator.isNull(values[0]))) {

          continue;
        }

        if (dynamicRequest.getParameter(name) == null) {
          dynamicRequest.setParameterValues(name, values);
        }
      } else {
        dynamicRequest.setParameterValues(name, newValues);
      }
    }
  }
  public void editPublicRenderParameters(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    Portlet portlet = ActionUtil.getPortlet(actionRequest);

    PortletPreferences portletPreferences =
        ActionUtil.getLayoutPortletSetup(actionRequest, portlet);

    actionRequest = ActionUtil.getWrappedActionRequest(actionRequest, portletPreferences);

    Enumeration<String> enu = portletPreferences.getNames();

    while (enu.hasMoreElements()) {
      String name = enu.nextElement();

      if (name.startsWith(PublicRenderParameterConfiguration.IGNORE_PREFIX)
          || name.startsWith(PublicRenderParameterConfiguration.MAPPING_PREFIX)) {

        portletPreferences.reset(name);
      }
    }

    for (PublicRenderParameter publicRenderParameter : portlet.getPublicRenderParameters()) {

      String ignoreKey = PublicRenderParameterConfiguration.getIgnoreKey(publicRenderParameter);

      boolean ignoreValue = ParamUtil.getBoolean(actionRequest, ignoreKey);

      if (ignoreValue) {
        portletPreferences.setValue(ignoreKey, String.valueOf(Boolean.TRUE));
      } else {
        String mappingKey = PublicRenderParameterConfiguration.getMappingKey(publicRenderParameter);

        String mappingValue = ParamUtil.getString(actionRequest, mappingKey);

        if (Validator.isNotNull(mappingValue)) {
          portletPreferences.setValue(mappingKey, mappingValue);
        }
      }
    }

    if (SessionErrors.isEmpty(actionRequest)) {
      portletPreferences.store();
    }
  }