public String getUserUuid() {
    try {
      User user = UserLocalServiceUtil.getDefaultUser(getCompanyId());

      return user.getUserUuid();
    } catch (Exception e) {
      return StringPool.BLANK;
    }
  }
Ejemplo n.º 2
0
  public String getUserUuid() {
    User user = getUser(_document.getCreatedBy());

    try {
      return user.getUserUuid();
    } catch (Exception e) {
    }

    return StringPool.BLANK;
  }
  protected void exportPortletPreference(
      PortletDataContext portletDataContext,
      long ownerId,
      int ownerType,
      boolean defaultUser,
      PortletPreferences portletPreferences,
      String portletId,
      long plid,
      Element parentElement)
      throws Exception {

    String preferencesXML = portletPreferences.getPreferences();

    if (Validator.isNull(preferencesXML)) {
      preferencesXML = PortletConstants.DEFAULT_PREFERENCES;
    }

    javax.portlet.PortletPreferences jxPortletPreferences =
        PortletPreferencesFactoryUtil.fromDefaultXML(preferencesXML);

    Portlet portlet =
        _portletLocalService.getPortletById(portletDataContext.getCompanyId(), portletId);

    Element portletPreferencesElement = parentElement.addElement("portlet-preferences");

    if ((portlet != null) && (portlet.getPortletDataHandlerInstance() != null)) {

      Element exportDataRootElement = portletDataContext.getExportDataRootElement();

      try {
        portletDataContext.clearScopedPrimaryKeys();

        Element preferenceDataElement = portletPreferencesElement.addElement("preference-data");

        portletDataContext.setExportDataRootElement(preferenceDataElement);

        ExportImportPortletPreferencesProcessor exportImportPortletPreferencesProcessor =
            ExportImportPortletPreferencesProcessorRegistryUtil
                .getExportImportPortletPreferencesProcessor(portlet.getRootPortletId());

        if (exportImportPortletPreferencesProcessor != null) {
          List<Capability> exportCapabilities =
              exportImportPortletPreferencesProcessor.getExportCapabilities();

          if (ListUtil.isNotEmpty(exportCapabilities)) {
            for (Capability exportCapability : exportCapabilities) {
              exportCapability.process(portletDataContext, jxPortletPreferences);
            }
          }

          exportImportPortletPreferencesProcessor.processExportPortletPreferences(
              portletDataContext, jxPortletPreferences);
        } else {
          PortletDataHandler portletDataHandler = portlet.getPortletDataHandlerInstance();

          jxPortletPreferences =
              portletDataHandler.processExportPortletPreferences(
                  portletDataContext, portletId, jxPortletPreferences);
        }
      } finally {
        portletDataContext.setExportDataRootElement(exportDataRootElement);
      }
    }

    Document document =
        SAXReaderUtil.read(PortletPreferencesFactoryUtil.toXML(jxPortletPreferences));

    Element rootElement = document.getRootElement();

    rootElement.addAttribute("owner-id", String.valueOf(ownerId));
    rootElement.addAttribute("owner-type", String.valueOf(ownerType));
    rootElement.addAttribute("default-user", String.valueOf(defaultUser));
    rootElement.addAttribute("plid", String.valueOf(plid));
    rootElement.addAttribute("portlet-id", portletId);

    if (ownerType == PortletKeys.PREFS_OWNER_TYPE_ARCHIVED) {
      PortletItem portletItem = _portletItemLocalService.getPortletItem(ownerId);

      rootElement.addAttribute("archive-user-uuid", portletItem.getUserUuid());
      rootElement.addAttribute("archive-name", portletItem.getName());
    } else if (ownerType == PortletKeys.PREFS_OWNER_TYPE_USER) {
      User user = _userLocalService.fetchUserById(ownerId);

      if (user == null) {
        return;
      }

      rootElement.addAttribute("user-uuid", user.getUserUuid());
    }

    List<Node> nodes =
        document.selectNodes(
            "/portlet-preferences/preference[name/text() = " + "'last-publish-date']");

    for (Node node : nodes) {
      document.remove(node);
    }

    String path =
        ExportImportPathUtil.getPortletPreferencesPath(
            portletDataContext, portletId, ownerId, ownerType, plid);

    portletPreferencesElement.addAttribute("path", path);

    portletDataContext.addZipEntry(path, document.formattedString(StringPool.TAB, false, false));
  }
  protected void exportServicePortletPreference(
      PortletDataContext portletDataContext,
      long ownerId,
      int ownerType,
      PortletPreferences portletPreferences,
      String serviceName,
      Element parentElement)
      throws Exception {

    String path =
        ExportImportPathUtil.getServicePortletPreferencesPath(
            portletDataContext, serviceName, ownerId, ownerType);

    if (portletDataContext.isPathProcessed(path)) {
      return;
    }

    String preferencesXML = portletPreferences.getPreferences();

    if (Validator.isNull(preferencesXML)) {
      preferencesXML = PortletConstants.DEFAULT_PREFERENCES;
    }

    javax.portlet.PortletPreferences jxPortletPreferences =
        PortletPreferencesFactoryUtil.fromDefaultXML(preferencesXML);

    Element serviceElement = parentElement.addElement("service");

    serviceElement.addAttribute("service-name", serviceName);

    Document document =
        SAXReaderUtil.read(PortletPreferencesFactoryUtil.toXML(jxPortletPreferences));

    Element rootElement = document.getRootElement();

    rootElement.addAttribute("owner-id", String.valueOf(ownerId));
    rootElement.addAttribute("owner-type", String.valueOf(ownerType));
    rootElement.addAttribute("default-user", String.valueOf(false));
    rootElement.addAttribute("service-name", serviceName);

    if (ownerType == PortletKeys.PREFS_OWNER_TYPE_ARCHIVED) {
      PortletItem portletItem = _portletItemLocalService.getPortletItem(ownerId);

      rootElement.addAttribute("archive-user-uuid", portletItem.getUserUuid());
      rootElement.addAttribute("archive-name", portletItem.getName());
    } else if (ownerType == PortletKeys.PREFS_OWNER_TYPE_USER) {
      User user = _userLocalService.fetchUserById(ownerId);

      if (user == null) {
        return;
      }

      rootElement.addAttribute("user-uuid", user.getUserUuid());
    }

    List<Node> nodes =
        document.selectNodes(
            "/portlet-preferences/preference[name/text() = " + "'last-publish-date']");

    for (Node node : nodes) {
      document.remove(node);
    }

    serviceElement.addAttribute("path", path);

    portletDataContext.addZipEntry(path, document.formattedString());
  }
Ejemplo n.º 5
0
  protected void exportPortletPreference(
      PortletDataContext portletDataContext,
      long ownerId,
      int ownerType,
      boolean defaultUser,
      PortletPreferences portletPreferences,
      String portletId,
      long plid,
      Element parentElement)
      throws Exception {

    String preferencesXML = portletPreferences.getPreferences();

    if (Validator.isNull(preferencesXML)) {
      preferencesXML = PortletConstants.DEFAULT_PREFERENCES;
    }

    Document document = SAXReaderUtil.read(preferencesXML);

    Element rootElement = document.getRootElement();

    rootElement.addAttribute("owner-id", String.valueOf(ownerId));
    rootElement.addAttribute("owner-type", String.valueOf(ownerType));
    rootElement.addAttribute("default-user", String.valueOf(defaultUser));
    rootElement.addAttribute("plid", String.valueOf(plid));
    rootElement.addAttribute("portlet-id", portletId);

    if (ownerType == PortletKeys.PREFS_OWNER_TYPE_ARCHIVED) {
      PortletItem portletItem = PortletItemLocalServiceUtil.getPortletItem(ownerId);

      rootElement.addAttribute("archive-user-uuid", portletItem.getUserUuid());
      rootElement.addAttribute("archive-name", portletItem.getName());
    } else if (ownerType == PortletKeys.PREFS_OWNER_TYPE_USER) {
      User user = UserLocalServiceUtil.fetchUserById(ownerId);

      if (user == null) {
        return;
      }

      rootElement.addAttribute("user-uuid", user.getUserUuid());
    }

    List<Node> nodes =
        document.selectNodes(
            "/portlet-preferences/preference[name/text() = " + "'last-publish-date']");

    for (Node node : nodes) {
      document.remove(node);
    }

    String path =
        getPortletPreferencesPath(portletDataContext, portletId, ownerId, ownerType, plid);

    Element portletPreferencesElement = parentElement.addElement("portlet-preferences");

    portletPreferencesElement.addAttribute("path", path);

    if (portletDataContext.isPathNotProcessed(path)) {
      portletDataContext.addZipEntry(path, document.formattedString(StringPool.TAB, false, false));
    }
  }