protected void importServicePortletPreferences(
      PortletDataContext portletDataContext, Element serviceElement) throws PortalException {

    long ownerId = GetterUtil.getLong(serviceElement.attributeValue("owner-id"));
    int ownerType = GetterUtil.getInteger(serviceElement.attributeValue("owner-type"));
    String serviceName = serviceElement.attributeValue("service-name");

    PortletPreferences portletPreferences =
        getPortletPreferences(
            portletDataContext.getCompanyId(),
            ownerId,
            ownerType,
            LayoutConstants.DEFAULT_PLID,
            serviceName);

    for (Attribute attribute : serviceElement.attributes()) {
      serviceElement.remove(attribute);
    }

    String xml = serviceElement.asXML();

    portletPreferences.setPreferences(xml);

    _portletPreferencesLocalService.updatePortletPreferences(portletPreferences);
  }
  public PortletPreferences updatePreferences(PortletPreferencesPK pk, PortletPreferencesImpl prefs)
      throws PortalException, SystemException {

    PortletPreferences portletPrefences = PortletPreferencesUtil.findByPrimaryKey(pk);

    String xml = PortletPreferencesSerializer.toXML(prefs);

    PortletPreferencesLocalUtil.getPreferencesPool(pk.userId).put(pk, prefs);

    portletPrefences.setPreferences(xml);

    PortletPreferencesUtil.update(portletPrefences);

    return portletPrefences;
  }
  public com.dotcms.repackage.portlet.javax.portlet.PortletPreferences getPreferences(
      String companyId, PortletPreferencesPK pk) throws PortalException, SystemException {

    //		String groupId = Layout.getGroupId(pk.layoutId);

    //		if (groupId != null) {
    //			if (!GetterUtil.getBoolean(
    //					PropsUtil.get(PropsUtil.GROUP_PAGES_PERSONALIZATION))) {
    //
    //				pk.userId = Layout.GROUP + groupId;
    //			}
    //		}

    Map prefsPool = PortletPreferencesLocalUtil.getPreferencesPool(pk.userId);

    PortletPreferencesImpl prefs = (PortletPreferencesImpl) prefsPool.get(pk);

    if (prefs == null) {
      PortletPreferences portletPreferences = null;

      Portlet portlet = null;
      //			if (groupId != null) {
      //				portlet = PortletManagerUtil.getPortletById(
      //					companyId, groupId, pk.portletId);
      //			}
      //			else {
      portlet = PortletManagerUtil.getPortletById(companyId, pk.portletId);
      //			}

      try {
        portletPreferences = PortletPreferencesUtil.findByPrimaryKey(pk);
      } catch (NoSuchPortletPreferencesException nsppe) {
        portletPreferences = PortletPreferencesUtil.create(pk);

        portletPreferences.setPreferences(portlet.getDefaultPreferences());

        PortletPreferencesUtil.update(portletPreferences);
      }

      prefs =
          PortletPreferencesSerializer.fromXML(companyId, pk, portletPreferences.getPreferences());

      prefsPool.put(pk, prefs);
    }

    return (PortletPreferencesImpl) prefs.clone();
  }
  /**
   * Converts the soap model instance into a normal model instance.
   *
   * @param soapModel the soap model instance to convert
   * @return the normal model instance
   */
  public static PortletPreferences toModel(PortletPreferencesSoap soapModel) {
    if (soapModel == null) {
      return null;
    }

    PortletPreferences model = new PortletPreferencesImpl();

    model.setMvccVersion(soapModel.getMvccVersion());
    model.setPortletPreferencesId(soapModel.getPortletPreferencesId());
    model.setOwnerId(soapModel.getOwnerId());
    model.setOwnerType(soapModel.getOwnerType());
    model.setPlid(soapModel.getPlid());
    model.setPortletId(soapModel.getPortletId());
    model.setPreferences(soapModel.getPreferences());

    return model;
  }