protected String deletePortletData( PortletDataContext portletDataContext, PortletPreferences portletPreferences) throws Exception { Group group = GroupLocalServiceUtil.getGroup(portletDataContext.getGroupId()); if (!group.isStagedPortlet(portletDataContext.getPortletId())) { if (_log.isDebugEnabled()) { _log.debug( "Do not delete portlet data for " + portletDataContext.getPortletId() + " because the portlet is not staged"); } return null; } Portlet portlet = PortletLocalServiceUtil.getPortletById( portletDataContext.getCompanyId(), portletDataContext.getPortletId()); if (portlet == null) { if (_log.isDebugEnabled()) { _log.debug( "Do not delete portlet data for " + portletDataContext.getPortletId() + " because the portlet does not exist"); } return null; } PortletDataHandler portletDataHandler = portlet.getPortletDataHandlerInstance(); if (portletDataHandler == null) { if (_log.isDebugEnabled()) { StringBundler sb = new StringBundler(4); sb.append("Do not delete portlet data for "); sb.append(portletDataContext.getPortletId()); sb.append(" because the portlet does not have a "); sb.append("PortletDataHandler"); _log.debug(sb.toString()); } return null; } if (_log.isDebugEnabled()) { _log.debug("Deleting data for " + portletDataContext.getPortletId()); } PortletPreferencesImpl portletPreferencesImpl = (PortletPreferencesImpl) PortletPreferencesFactoryUtil.fromDefaultXML(portletPreferences.getPreferences()); try { portletPreferencesImpl = (PortletPreferencesImpl) portletDataHandler.deleteData( portletDataContext, portletDataContext.getPortletId(), portletPreferencesImpl); } finally { portletDataContext.setGroupId(portletDataContext.getScopeGroupId()); } if (portletPreferencesImpl == null) { return null; } return PortletPreferencesFactoryUtil.toXML(portletPreferencesImpl); }