@Override
  public String toXML(PortletPreferences portletPreferences) {
    PortletPreferencesImpl portletPreferencesImpl = null;

    if (portletPreferences instanceof PortletPreferencesWrapper) {
      PortletPreferencesWrapper portletPreferencesWrapper =
          (PortletPreferencesWrapper) portletPreferences;

      portletPreferencesImpl = portletPreferencesWrapper.getPortletPreferencesImpl();
    } else {
      portletPreferencesImpl = (PortletPreferencesImpl) portletPreferences;
    }

    return portletPreferencesImpl.toXML();
  }
  @Override
  public PortletPreferences getPreferences(HttpServletRequest request) {
    PortletRequest portletRequest =
        (PortletRequest) request.getAttribute(JavaConstants.JAVAX_PORTLET_REQUEST);

    PortletPreferences portletPreferences = null;

    if (portletRequest != null) {
      PortletPreferencesWrapper portletPreferencesWrapper =
          (PortletPreferencesWrapper) portletRequest.getPreferences();

      portletPreferences = portletPreferencesWrapper.getPortletPreferencesImpl();
    }

    return portletPreferences;
  }