public static String getStringFromAttribute(int type, Serializable attribute) {

    if (attribute == null) {
      return StringPool.BLANK;
    }

    if ((type == ExpandoColumnConstants.BOOLEAN)
        || (type == ExpandoColumnConstants.DOUBLE)
        || (type == ExpandoColumnConstants.FLOAT)
        || (type == ExpandoColumnConstants.INTEGER)
        || (type == ExpandoColumnConstants.LONG)
        || (type == ExpandoColumnConstants.SHORT)) {

      return String.valueOf(attribute);
    } else if ((type == ExpandoColumnConstants.BOOLEAN_ARRAY)
        || (type == ExpandoColumnConstants.DOUBLE_ARRAY)
        || (type == ExpandoColumnConstants.FLOAT_ARRAY)
        || (type == ExpandoColumnConstants.INTEGER_ARRAY)
        || (type == ExpandoColumnConstants.LONG_ARRAY)
        || (type == ExpandoColumnConstants.SHORT_ARRAY)
        || (type == ExpandoColumnConstants.STRING_ARRAY)) {

      return StringUtil.merge(ArrayUtil.toStringArray((Object[]) attribute));
    } else if (type == ExpandoColumnConstants.DATE) {
      DateFormat dateFormat = _getDateFormat();

      return dateFormat.format((Date) attribute);
    } else if (type == ExpandoColumnConstants.DATE_ARRAY) {
      return StringUtil.merge(ArrayUtil.toStringArray((Date[]) attribute, _getDateFormat()));
    } else {
      return attribute.toString();
    }
  }
Esempio n. 2
0
  protected static String exportLinksToLayout(PortletDataContext portletDataContext, String content)
      throws Exception {

    List<String> oldLinksToLayout = new ArrayList<String>();
    List<String> newLinksToLayout = new ArrayList<String>();

    Matcher matcher = _exportLinksToLayoutPattern.matcher(content);

    while (matcher.find()) {
      long layoutId = GetterUtil.getLong(matcher.group(1));

      String type = matcher.group(2);

      boolean privateLayout = type.startsWith("private");

      try {
        Layout layout =
            LayoutLocalServiceUtil.getLayout(
                portletDataContext.getScopeGroupId(), privateLayout, layoutId);

        String oldLinkToLayout = matcher.group(0);

        StringBundler sb = new StringBundler(5);

        sb.append(type);
        sb.append(StringPool.AT);
        sb.append(layout.getUuid());
        sb.append(StringPool.AT);
        sb.append(layout.getFriendlyURL());

        String newLinkToLayout = StringUtil.replace(oldLinkToLayout, type, sb.toString());

        oldLinksToLayout.add(oldLinkToLayout);
        newLinksToLayout.add(newLinkToLayout);
      } catch (Exception e) {
        if (_log.isDebugEnabled() || _log.isWarnEnabled()) {
          String message =
              "Unable to get layout with ID "
                  + layoutId
                  + " in group "
                  + portletDataContext.getScopeGroupId();

          if (_log.isWarnEnabled()) {
            _log.warn(message);
          } else {
            _log.debug(message, e);
          }
        }
      }
    }

    content =
        StringUtil.replace(
            content,
            ArrayUtil.toStringArray(oldLinksToLayout.toArray()),
            ArrayUtil.toStringArray(newLinksToLayout.toArray()));

    return content;
  }
  public void processAction(
      PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    if (!cmd.equals(Constants.UPDATE)) {
      return;
    }

    boolean allAssetVocabularies = ParamUtil.getBoolean(actionRequest, "allAssetVocabularies");
    long[] assetVocabularyIds =
        StringUtil.split(ParamUtil.getString(actionRequest, "assetVocabularyIds"), 0L);

    String portletResource = ParamUtil.getString(actionRequest, "portletResource");

    PortletPreferences preferences =
        PortletPreferencesFactoryUtil.getPortletSetup(actionRequest, portletResource);

    preferences.setValue("all-asset-vocabularies", String.valueOf(allAssetVocabularies));
    preferences.setValues("asset-vocabulary-ids", ArrayUtil.toStringArray(assetVocabularyIds));

    preferences.store();

    SessionMessages.add(actionRequest, portletConfig.getPortletName() + ".doConfigure");
  }
Esempio n. 4
0
  @Override
  public void addKeyword(String name, Short[] values) {
    if (values == null) {
      return;
    }

    addKeyword(name, ArrayUtil.toStringArray(values));
  }
  @Override
  protected String[] getFileEntryMimeTypes() {
    Set<String> videoMimeTypes = VideoProcessorUtil.getVideoMimeTypes();

    if (videoMimeTypes == null) {
      return null;
    }

    return ArrayUtil.toStringArray(videoMimeTypes.toArray());
  }
Esempio n. 6
0
  protected <T extends Number & Comparable<? super T>> void createNumberField(
      String name, boolean typify, T... values) {

    if (values == null) {
      return;
    }

    createSortableNumericField(name, typify, values);

    createField(name, ArrayUtil.toStringArray(values));
  }
Esempio n. 7
0
  @Override
  public void addTrashSessionMessages(
      ActionRequest actionRequest, List<TrashedModel> trashedModels, String cmd) {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    List<String> classNames = new ArrayList<String>();
    List<Long> restoreTrashEntryIds = new ArrayList<Long>();
    List<String> titles = new ArrayList<String>();

    for (int i = 0; i < trashedModels.size(); i++) {
      try {
        TrashedModel trashedModel = trashedModels.get(i);

        TrashEntry trashEntry = trashedModel.getTrashEntry();

        TrashHandler trashHandler = trashedModel.getTrashHandler();

        TrashRenderer trashRenderer =
            trashHandler.getTrashRenderer(trashedModel.getTrashEntryClassPK());

        classNames.add(trashRenderer.getClassName());
        restoreTrashEntryIds.add(trashEntry.getEntryId());
        titles.add(trashRenderer.getTitle(themeDisplay.getLocale()));
      } catch (Exception e) {
      }
    }

    Map<String, String[]> data = new HashMap<String, String[]>();

    data.put(Constants.CMD, new String[] {cmd});

    data.put("deleteEntryClassName", ArrayUtil.toStringArray(classNames.toArray()));
    data.put("deleteEntryTitle", ArrayUtil.toStringArray(titles.toArray()));
    data.put("restoreTrashEntryIds", ArrayUtil.toStringArray(restoreTrashEntryIds.toArray()));

    SessionMessages.add(
        actionRequest,
        PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_DELETE_SUCCESS_DATA,
        data);
  }
Esempio n. 8
0
  @Override
  public void addKeywordSortable(String name, Boolean[] values) {
    if (values == null) {
      return;
    }

    String[] valuesString = ArrayUtil.toStringArray(values);

    createField(name, valuesString);

    createSortableTextField(name, valuesString);
  }
  public static String[] getCategories(List<App> apps, List<Bundle> bundles) {
    List<String> categories = new ArrayList<>();

    categories.addAll(getAppCategories(apps));
    categories.addAll(getBundleCategories(bundles));

    ListUtil.distinct(categories);
    ListUtil.sort(categories);

    categories.add(0, "all-categories");

    return ArrayUtil.toStringArray(categories);
  }
  protected void deleteFolders(
      LiferayPortletConfig liferayPortletConfig, ActionRequest actionRequest, boolean moveToTrash)
      throws Exception {

    long[] deleteFolderIds = null;

    long folderId = ParamUtil.getLong(actionRequest, "folderId");

    if (folderId > 0) {
      deleteFolderIds = new long[] {folderId};
    } else {
      deleteFolderIds = StringUtil.split(ParamUtil.getString(actionRequest, "folderIds"), 0L);
    }

    for (long deleteFolderId : deleteFolderIds) {
      if (moveToTrash) {
        JournalFolderServiceUtil.moveFolderToTrash(deleteFolderId);
      } else {
        JournalFolderServiceUtil.deleteFolder(deleteFolderId);
      }

      AssetPublisherUtil.removeRecentFolderId(
          actionRequest, JournalArticle.class.getName(), deleteFolderId);
    }

    if (moveToTrash && (deleteFolderIds.length > 0)) {
      Map<String, String[]> data = new HashMap<String, String[]>();

      data.put("restoreFolderIds", ArrayUtil.toStringArray(deleteFolderIds));

      SessionMessages.add(
          actionRequest,
          liferayPortletConfig.getPortletId() + SessionMessages.KEY_SUFFIX_DELETE_SUCCESS_DATA,
          data);

      SessionMessages.add(
          actionRequest,
          liferayPortletConfig.getPortletId()
              + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_SUCCESS_MESSAGE);
    }
  }
  protected void updateDisplaySettings(ActionRequest actionRequest, PortletPreferences preferences)
      throws Exception {

    String displayStyle = ParamUtil.getString(actionRequest, "displayStyle");
    boolean anyAssetType = ParamUtil.getBoolean(actionRequest, "anyAssetType");
    long[] classNameIds = StringUtil.split(ParamUtil.getString(actionRequest, "classNameIds"), 0L);
    boolean showAssetTitle = ParamUtil.getBoolean(actionRequest, "showAssetTitle");
    boolean showContextLink = ParamUtil.getBoolean(actionRequest, "showContextLink");
    int abstractLength = ParamUtil.getInteger(actionRequest, "abstractLength");
    String assetLinkBehaviour = ParamUtil.getString(actionRequest, "assetLinkBehaviour");
    boolean showAvailableLocales = ParamUtil.getBoolean(actionRequest, "showAvailableLocales");
    String[] extensions = actionRequest.getParameterValues("extensions");
    boolean enablePrint = ParamUtil.getBoolean(actionRequest, "enablePrint");
    boolean enableFlags = ParamUtil.getBoolean(actionRequest, "enableFlags");
    boolean enableRatings = ParamUtil.getBoolean(actionRequest, "enableRatings");
    boolean enableComments = ParamUtil.getBoolean(actionRequest, "enableComments");
    boolean enableCommentRatings = ParamUtil.getBoolean(actionRequest, "enableCommentRatings");
    boolean enableTagBasedNavigation =
        ParamUtil.getBoolean(actionRequest, "enableTagBasedNavigation");
    String medatadaFields = ParamUtil.getString(actionRequest, "metadataFields");

    preferences.setValue("selection-style", "manual");
    preferences.setValue("display-style", displayStyle);
    preferences.setValue("any-asset-type", String.valueOf(anyAssetType));
    preferences.setValues("class-name-ids", ArrayUtil.toStringArray(classNameIds));
    preferences.setValue("show-asset-title", String.valueOf(showAssetTitle));
    preferences.setValue("show-context-link", String.valueOf(showContextLink));
    preferences.setValue("abstract-length", String.valueOf(abstractLength));
    preferences.setValue("asset-link-behaviour", assetLinkBehaviour);
    preferences.setValue("show-available-locales", String.valueOf(showAvailableLocales));
    preferences.setValues("extensions", extensions);
    preferences.setValue("enable-print", String.valueOf(enablePrint));
    preferences.setValue("enable-flags", String.valueOf(enableFlags));
    preferences.setValue("enable-ratings", String.valueOf(enableRatings));
    preferences.setValue("enable-comments", String.valueOf(enableComments));
    preferences.setValue("enable-comment-ratings", String.valueOf(enableCommentRatings));
    preferences.setValue("enable-tag-based-navigation", String.valueOf(enableTagBasedNavigation));
    preferences.setValue("metadata-fields", medatadaFields);
  }
Esempio n. 12
0
  @Override
  public Serializable getIndexedFieldValue(Serializable fieldValue, String type) throws Exception {

    if (fieldValue instanceof Date) {
      Date valueDate = (Date) fieldValue;

      DateFormat dateFormat = DateFormatFactoryUtil.getSimpleDateFormat("yyyyMMddHHmmss");

      fieldValue = dateFormat.format(valueDate);
    } else if (type.equals(DDMImpl.TYPE_RADIO) || type.equals(DDMImpl.TYPE_SELECT)) {

      String valueString = (String) fieldValue;

      JSONArray jsonArray = JSONFactoryUtil.createJSONArray(valueString);

      String[] stringArray = ArrayUtil.toStringArray(jsonArray);

      fieldValue = stringArray[0];
    }

    return fieldValue;
  }
  protected void updateDynamicSettings(ActionRequest actionRequest, PortletPreferences preferences)
      throws Exception {

    updateDisplaySettings(actionRequest, preferences);
    updateQueryLogic(actionRequest, preferences);
    updateRssSettings(actionRequest, preferences);

    boolean mergeUrlTags = ParamUtil.getBoolean(actionRequest, "mergeUrlTags");
    boolean defaultScope = ParamUtil.getBoolean(actionRequest, "defaultScope");
    String[] scopeIds = StringUtil.split(ParamUtil.getString(actionRequest, "scopeIds"));
    long assetVocabularyId = ParamUtil.getLong(actionRequest, "assetVocabularyId");
    String orderByColumn1 = ParamUtil.getString(actionRequest, "orderByColumn1");
    String orderByColumn2 = ParamUtil.getString(actionRequest, "orderByColumn2");
    String orderByType1 = ParamUtil.getString(actionRequest, "orderByType1");
    String orderByType2 = ParamUtil.getString(actionRequest, "orderByType2");
    boolean excludeZeroViewCount = ParamUtil.getBoolean(actionRequest, "excludeZeroViewCount");
    boolean showQueryLogic = ParamUtil.getBoolean(actionRequest, "showQueryLogic");
    int delta = ParamUtil.getInteger(actionRequest, "delta");
    String paginationType = ParamUtil.getString(actionRequest, "paginationType");
    String[] extensions = actionRequest.getParameterValues("extensions");

    preferences.setValue("selection-style", "dynamic");
    preferences.setValue("merge-url-tags", String.valueOf(mergeUrlTags));
    preferences.setValue("default-scope", String.valueOf(defaultScope));
    preferences.setValues("scope-ids", ArrayUtil.toStringArray(scopeIds));
    preferences.setValue("asset-vocabulary-id", String.valueOf(assetVocabularyId));
    preferences.setValue("order-by-column-1", orderByColumn1);
    preferences.setValue("order-by-column-2", orderByColumn2);
    preferences.setValue("order-by-type-1", orderByType1);
    preferences.setValue("order-by-type-2", orderByType2);
    preferences.setValue("exclude-zero-view-count", String.valueOf(excludeZeroViewCount));
    preferences.setValue("show-query-logic", String.valueOf(showQueryLogic));
    preferences.setValue("delta", String.valueOf(delta));
    preferences.setValue("pagination-type", paginationType);
    preferences.setValues("extensions", extensions);
  }
  protected void addAttribute(
      Document document, ExpandoColumn expandoColumn, List<ExpandoValue> expandoValues)
      throws PortalException {

    UnicodeProperties unicodeProperties = expandoColumn.getTypeSettingsProperties();

    int indexType =
        GetterUtil.getInteger(unicodeProperties.getProperty(ExpandoColumnConstants.INDEX_TYPE));

    String fieldName = encodeFieldName(expandoColumn.getName(), indexType);

    ExpandoValue expandoValue = new ExpandoValueImpl();

    expandoValue.setColumnId(expandoColumn.getColumnId());
    expandoValue.setData(expandoColumn.getDefaultData());

    boolean defaultValue = true;

    for (ExpandoValue curExpandoValue : expandoValues) {
      if (curExpandoValue.getColumnId() == expandoColumn.getColumnId()) {
        expandoValue = curExpandoValue;

        defaultValue = false;

        break;
      }
    }

    int type = expandoColumn.getType();

    if (type == ExpandoColumnConstants.BOOLEAN) {
      document.addKeyword(fieldName, expandoValue.getBoolean());
    } else if (type == ExpandoColumnConstants.BOOLEAN_ARRAY) {
      if (!defaultValue) {
        document.addKeyword(fieldName, expandoValue.getBooleanArray());
      } else {
        document.addKeyword(fieldName, new boolean[0]);
      }
    } else if (type == ExpandoColumnConstants.DATE) {
      document.addDate(fieldName, expandoValue.getDate());
    } else if (type == ExpandoColumnConstants.DOUBLE) {
      document.addKeyword(fieldName, expandoValue.getDouble());
    } else if (type == ExpandoColumnConstants.DOUBLE_ARRAY) {
      if (!defaultValue) {
        document.addKeyword(fieldName, expandoValue.getDoubleArray());
      } else {
        document.addKeyword(fieldName, new double[0]);
      }
    } else if (type == ExpandoColumnConstants.FLOAT) {
      document.addKeyword(fieldName, expandoValue.getFloat());
    } else if (type == ExpandoColumnConstants.FLOAT_ARRAY) {
      if (!defaultValue) {
        document.addKeyword(fieldName, expandoValue.getFloatArray());
      } else {
        document.addKeyword(fieldName, new float[0]);
      }
    } else if (type == ExpandoColumnConstants.INTEGER) {
      document.addKeyword(fieldName, expandoValue.getInteger());
    } else if (type == ExpandoColumnConstants.INTEGER_ARRAY) {
      if (!defaultValue) {
        document.addKeyword(fieldName, expandoValue.getIntegerArray());
      } else {
        document.addKeyword(fieldName, new int[0]);
      }
    } else if (type == ExpandoColumnConstants.LONG) {
      document.addKeyword(fieldName, expandoValue.getLong());
    } else if (type == ExpandoColumnConstants.LONG_ARRAY) {
      if (!defaultValue) {
        document.addKeyword(fieldName, expandoValue.getLongArray());
      } else {
        document.addKeyword(fieldName, new long[0]);
      }
    } else if (type == ExpandoColumnConstants.NUMBER) {
      document.addKeyword(fieldName, expandoValue.getNumber().toString());
    } else if (type == ExpandoColumnConstants.NUMBER_ARRAY) {
      if (!defaultValue) {
        document.addKeyword(fieldName, ArrayUtil.toStringArray(expandoValue.getNumberArray()));
      } else {
        document.addKeyword(fieldName, new long[0]);
      }
    } else if (type == ExpandoColumnConstants.SHORT) {
      document.addKeyword(fieldName, expandoValue.getShort());
    } else if (type == ExpandoColumnConstants.SHORT_ARRAY) {
      if (!defaultValue) {
        document.addKeyword(fieldName, expandoValue.getShortArray());
      } else {
        document.addKeyword(fieldName, new short[0]);
      }
    } else if (type == ExpandoColumnConstants.STRING) {
      if (indexType == ExpandoColumnConstants.INDEX_TYPE_KEYWORD) {
        document.addKeyword(fieldName, expandoValue.getString());
      } else {
        document.addText(fieldName, expandoValue.getString());
      }
    } else if (type == ExpandoColumnConstants.STRING_ARRAY) {
      if (!defaultValue) {
        if (indexType == ExpandoColumnConstants.INDEX_TYPE_KEYWORD) {
          document.addKeyword(fieldName, expandoValue.getStringArray());
        } else {
          document.addText(
              fieldName, StringUtil.merge(expandoValue.getStringArray(), StringPool.SPACE));
        }
      } else {
        if (indexType == ExpandoColumnConstants.INDEX_TYPE_KEYWORD) {
          document.addKeyword(fieldName, StringPool.BLANK);
        } else {
          document.addText(fieldName, StringPool.BLANK);
        }
      }
    } else if (type == ExpandoColumnConstants.STRING_LOCALIZED) {
      if (!defaultValue) {
        if (indexType == ExpandoColumnConstants.INDEX_TYPE_KEYWORD) {
          document.addLocalizedKeyword(fieldName, expandoValue.getStringMap());
        } else {
          document.addLocalizedText(fieldName, expandoValue.getStringMap());
        }
      }
    }
  }
  protected File doExport(PortletDataContext portletDataContext, long[] layoutIds)
      throws Exception {

    Map<String, String[]> parameterMap = portletDataContext.getParameterMap();

    boolean ignoreLastPublishDate =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.IGNORE_LAST_PUBLISH_DATE);
    boolean layoutSetPrototypeSettings =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.LAYOUT_SET_PROTOTYPE_SETTINGS);
    boolean layoutSetSettings =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.LAYOUT_SET_SETTINGS);
    boolean logo = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.LOGO);
    boolean permissions = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PERMISSIONS);

    if (_log.isDebugEnabled()) {
      _log.debug("Export permissions " + permissions);
    }

    LayoutSet layoutSet =
        _layoutSetLocalService.getLayoutSet(
            portletDataContext.getGroupId(), portletDataContext.isPrivateLayout());

    long companyId = layoutSet.getCompanyId();
    long defaultUserId = _userLocalService.getDefaultUserId(companyId);

    ServiceContext serviceContext = ServiceContextThreadLocal.popServiceContext();

    if (serviceContext == null) {
      serviceContext = new ServiceContext();
    }

    serviceContext.setCompanyId(companyId);
    serviceContext.setSignedIn(false);
    serviceContext.setUserId(defaultUserId);

    serviceContext.setAttribute("exporting", Boolean.TRUE);

    long layoutSetBranchId = MapUtil.getLong(parameterMap, "layoutSetBranchId");

    serviceContext.setAttribute("layoutSetBranchId", layoutSetBranchId);

    ServiceContextThreadLocal.pushServiceContext(serviceContext);

    if (ignoreLastPublishDate) {
      portletDataContext.setEndDate(null);
      portletDataContext.setStartDate(null);
    }

    StopWatch stopWatch = new StopWatch();

    stopWatch.start();

    Document document = SAXReaderUtil.createDocument();

    Element rootElement = document.addElement("root");

    portletDataContext.setExportDataRootElement(rootElement);

    Element headerElement = rootElement.addElement("header");

    headerElement.addAttribute(
        "available-locales",
        StringUtil.merge(LanguageUtil.getAvailableLocales(portletDataContext.getScopeGroupId())));
    headerElement.addAttribute("build-number", String.valueOf(ReleaseInfo.getBuildNumber()));
    headerElement.addAttribute("export-date", Time.getRFC822());

    if (portletDataContext.hasDateRange()) {
      headerElement.addAttribute("start-date", String.valueOf(portletDataContext.getStartDate()));
      headerElement.addAttribute("end-date", String.valueOf(portletDataContext.getEndDate()));
    }

    headerElement.addAttribute("company-id", String.valueOf(portletDataContext.getCompanyId()));
    headerElement.addAttribute(
        "company-group-id", String.valueOf(portletDataContext.getCompanyGroupId()));
    headerElement.addAttribute("group-id", String.valueOf(portletDataContext.getGroupId()));
    headerElement.addAttribute(
        "user-personal-site-group-id",
        String.valueOf(portletDataContext.getUserPersonalSiteGroupId()));
    headerElement.addAttribute(
        "private-layout", String.valueOf(portletDataContext.isPrivateLayout()));

    Group group = layoutSet.getGroup();

    String type = "layout-set";

    if (group.isLayoutPrototype()) {
      type = "layout-prototype";

      LayoutPrototype layoutPrototype =
          _layoutPrototypeLocalService.getLayoutPrototype(group.getClassPK());

      headerElement.addAttribute("type-uuid", layoutPrototype.getUuid());

      layoutIds =
          ExportImportHelperUtil.getAllLayoutIds(
              portletDataContext.getGroupId(), portletDataContext.isPrivateLayout());
    } else if (group.isLayoutSetPrototype()) {
      type = "layout-set-prototype";

      LayoutSetPrototype layoutSetPrototype =
          _layoutSetPrototypeLocalService.getLayoutSetPrototype(group.getClassPK());

      headerElement.addAttribute("type-uuid", layoutSetPrototype.getUuid());
    }

    headerElement.addAttribute("type", type);

    LayoutSetBranch layoutSetBranch =
        _layoutSetBranchLocalService.fetchLayoutSetBranch(layoutSetBranchId);

    if (logo) {
      Image image = null;

      if (layoutSetBranch != null) {
        image = _imageLocalService.getImage(layoutSetBranch.getLogoId());
      } else {
        image = _imageLocalService.getImage(layoutSet.getLogoId());
      }

      if ((image != null) && (image.getTextObj() != null)) {
        String logoPath = ExportImportPathUtil.getRootPath(portletDataContext);

        logoPath += "/logo";

        headerElement.addAttribute("logo-path", logoPath);

        portletDataContext.addZipEntry(logoPath, image.getTextObj());
      }
    }

    String layoutSetPrototypeUuid = layoutSet.getLayoutSetPrototypeUuid();

    if (layoutSetPrototypeSettings && Validator.isNotNull(layoutSetPrototypeUuid)) {

      LayoutSetPrototype layoutSetPrototype =
          _layoutSetPrototypeLocalService.getLayoutSetPrototypeByUuidAndCompanyId(
              layoutSetPrototypeUuid, companyId);

      headerElement.addAttribute("layout-set-prototype-uuid", layoutSetPrototypeUuid);
      headerElement.addAttribute(
          "layout-set-prototype-name", layoutSetPrototype.getName(LocaleUtil.getDefault()));
    }

    Element missingReferencesElement = rootElement.addElement("missing-references");

    portletDataContext.setMissingReferencesElement(missingReferencesElement);

    if (layoutSetBranch != null) {
      _themeExporter.exportTheme(portletDataContext, layoutSetBranch);
    } else {
      _themeExporter.exportTheme(portletDataContext, layoutSet);
    }

    if (layoutSetSettings) {
      Element settingsElement = headerElement.addElement("settings");

      if (layoutSetBranch != null) {
        settingsElement.addCDATA(layoutSetBranch.getSettings());
      } else {
        settingsElement.addCDATA(layoutSet.getSettings());
      }
    }

    Map<String, Object[]> portletIds = new LinkedHashMap<>();

    List<Layout> layouts =
        _layoutLocalService.getLayouts(
            portletDataContext.getGroupId(), portletDataContext.isPrivateLayout());

    if (group.isStagingGroup()) {
      group = group.getLiveGroup();
    }

    // Collect data portlets

    for (Portlet portlet : ExportImportHelperUtil.getDataSiteLevelPortlets(companyId)) {

      String portletId = portlet.getRootPortletId();

      if (ExportImportThreadLocal.isStagingInProcess() && !group.isStagedPortlet(portletId)) {

        continue;
      }

      // Calculate the amount of exported data

      if (BackgroundTaskThreadLocal.hasBackgroundTask()) {
        PortletDataHandler portletDataHandler = portlet.getPortletDataHandlerInstance();

        portletDataHandler.prepareManifestSummary(portletDataContext);
      }

      // Add portlet ID to exportable portlets list

      portletIds.put(
          PortletPermissionUtil.getPrimaryKey(0, portletId),
          new Object[] {
            portletId,
            LayoutConstants.DEFAULT_PLID,
            portletDataContext.getGroupId(),
            StringPool.BLANK,
            StringPool.BLANK
          });

      if (!portlet.isScopeable()) {
        continue;
      }

      // Scoped data

      for (Layout layout : layouts) {
        if (!ArrayUtil.contains(layoutIds, layout.getLayoutId())
            || !layout.isTypePortlet()
            || !layout.hasScopeGroup()) {

          continue;
        }

        Group scopeGroup = layout.getScopeGroup();

        portletIds.put(
            PortletPermissionUtil.getPrimaryKey(layout.getPlid(), portlet.getPortletId()),
            new Object[] {
              portlet.getPortletId(),
              layout.getPlid(),
              scopeGroup.getGroupId(),
              StringPool.BLANK,
              layout.getUuid()
            });
      }
    }

    // Collect layout portlets

    for (Layout layout : layouts) {
      getLayoutPortlets(portletDataContext, layoutIds, portletIds, layout);
    }

    if (BackgroundTaskThreadLocal.hasBackgroundTask()) {
      ManifestSummary manifestSummary = portletDataContext.getManifestSummary();

      PortletDataHandlerStatusMessageSenderUtil.sendStatusMessage(
          "layout", ArrayUtil.toStringArray(portletIds.keySet()), manifestSummary);

      manifestSummary.resetCounters();
    }

    // Export actual data

    portletDataContext.addDeletionSystemEventStagedModelTypes(new StagedModelType(Layout.class));

    // Force to always have a layout group element

    portletDataContext.getExportDataGroupElement(Layout.class);

    for (Layout layout : layouts) {
      exportLayout(portletDataContext, layoutIds, layout);
    }

    Element portletsElement = rootElement.addElement("portlets");

    Element servicesElement = rootElement.addElement("services");

    long previousScopeGroupId = portletDataContext.getScopeGroupId();

    for (Map.Entry<String, Object[]> portletIdsEntry : portletIds.entrySet()) {

      Object[] portletObjects = portletIdsEntry.getValue();

      String portletId = null;
      long plid = LayoutConstants.DEFAULT_PLID;
      long scopeGroupId = 0;
      String scopeType = StringPool.BLANK;
      String scopeLayoutUuid = null;

      if (portletObjects.length == 4) {
        portletId = (String) portletIdsEntry.getValue()[0];
        plid = (Long) portletIdsEntry.getValue()[1];
        scopeGroupId = (Long) portletIdsEntry.getValue()[2];
        scopeLayoutUuid = (String) portletIdsEntry.getValue()[3];
      } else {
        portletId = (String) portletIdsEntry.getValue()[0];
        plid = (Long) portletIdsEntry.getValue()[1];
        scopeGroupId = (Long) portletIdsEntry.getValue()[2];
        scopeType = (String) portletIdsEntry.getValue()[3];
        scopeLayoutUuid = (String) portletIdsEntry.getValue()[4];
      }

      Layout layout = _layoutLocalService.fetchLayout(plid);

      if (layout == null) {
        layout = new LayoutImpl();

        layout.setCompanyId(companyId);
        layout.setGroupId(portletDataContext.getGroupId());
      }

      portletDataContext.setPlid(plid);
      portletDataContext.setOldPlid(plid);
      portletDataContext.setPortletId(portletId);
      portletDataContext.setScopeGroupId(scopeGroupId);
      portletDataContext.setScopeType(scopeType);
      portletDataContext.setScopeLayoutUuid(scopeLayoutUuid);

      Map<String, Boolean> exportPortletControlsMap =
          ExportImportHelperUtil.getExportPortletControlsMap(
              companyId, portletId, parameterMap, type);

      try {
        _exportImportLifecycleManager.fireExportImportLifecycleEvent(
            EVENT_PORTLET_EXPORT_STARTED,
            getProcessFlag(),
            PortletDataContextFactoryUtil.clonePortletDataContext(portletDataContext));

        _portletExportController.exportPortlet(
            portletDataContext,
            layout,
            portletsElement,
            permissions,
            exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_ARCHIVED_SETUPS),
            exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_DATA),
            exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_SETUP),
            exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_USER_PREFERENCES));
        _portletExportController.exportService(
            portletDataContext,
            servicesElement,
            exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_SETUP));

        _exportImportLifecycleManager.fireExportImportLifecycleEvent(
            EVENT_PORTLET_EXPORT_SUCCEEDED,
            getProcessFlag(),
            PortletDataContextFactoryUtil.clonePortletDataContext(portletDataContext));
      } catch (Throwable t) {
        _exportImportLifecycleManager.fireExportImportLifecycleEvent(
            EVENT_PORTLET_EXPORT_FAILED,
            getProcessFlag(),
            PortletDataContextFactoryUtil.clonePortletDataContext(portletDataContext),
            t);

        throw t;
      }
    }

    portletDataContext.setScopeGroupId(previousScopeGroupId);

    _portletExportController.exportAssetLinks(portletDataContext);
    _portletExportController.exportExpandoTables(portletDataContext);
    _portletExportController.exportLocks(portletDataContext);

    _deletionSystemEventExporter.exportDeletionSystemEvents(portletDataContext);

    if (permissions) {
      _permissionExporter.exportPortletDataPermissions(portletDataContext);
    }

    ExportImportHelperUtil.writeManifestSummary(document, portletDataContext.getManifestSummary());

    if (_log.isInfoEnabled()) {
      _log.info("Exporting layouts takes " + stopWatch.getTime() + " ms");
    }

    boolean updateLastPublishDate =
        MapUtil.getBoolean(
            portletDataContext.getParameterMap(), PortletDataHandlerKeys.UPDATE_LAST_PUBLISH_DATE);

    if (ExportImportThreadLocal.isStagingInProcess() && updateLastPublishDate) {

      ExportImportProcessCallbackRegistryUtil.registerCallback(
          new UpdateLayoutSetLastPublishDateCallable(
              portletDataContext.getDateRange(),
              portletDataContext.getGroupId(),
              portletDataContext.isPrivateLayout()));
    }

    portletDataContext.addZipEntry("/manifest.xml", document.formattedString());

    ZipWriter zipWriter = portletDataContext.getZipWriter();

    return zipWriter.getFile();
  }
Esempio n. 16
0
  @Override
  public Serializable getDisplayFieldValue(
      ThemeDisplay themeDisplay, Serializable fieldValue, String type) throws Exception {

    if (fieldValue instanceof Date) {
      Date valueDate = (Date) fieldValue;

      DateFormat dateFormat = DateFormatFactoryUtil.getDate(themeDisplay.getLocale());

      fieldValue = dateFormat.format(valueDate);
    } else if (type.equals(DDMImpl.TYPE_CHECKBOX)) {
      Boolean valueBoolean = (Boolean) fieldValue;

      if (valueBoolean) {
        fieldValue = LanguageUtil.get(themeDisplay.getLocale(), "yes");
      } else {
        fieldValue = LanguageUtil.get(themeDisplay.getLocale(), "no");
      }
    } else if (type.equals(DDMImpl.TYPE_DDM_DOCUMENTLIBRARY)) {
      if (Validator.isNull(fieldValue)) {
        return StringPool.BLANK;
      }

      String valueString = String.valueOf(fieldValue);

      JSONObject jsonObject = JSONFactoryUtil.createJSONObject(valueString);

      String uuid = jsonObject.getString("uuid");
      long groupId = jsonObject.getLong("groupId");

      FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId);

      fieldValue =
          DLUtil.getPreviewURL(
              fileEntry, fileEntry.getFileVersion(), null, StringPool.BLANK, false, true);
    } else if (type.equals(DDMImpl.TYPE_DDM_LINK_TO_PAGE)) {
      if (Validator.isNull(fieldValue)) {
        return StringPool.BLANK;
      }

      String valueString = String.valueOf(fieldValue);

      JSONObject jsonObject = JSONFactoryUtil.createJSONObject(valueString);

      long groupId = jsonObject.getLong("groupId");
      boolean privateLayout = jsonObject.getBoolean("privateLayout");
      long layoutId = jsonObject.getLong("layoutId");

      Layout layout = LayoutLocalServiceUtil.getLayout(groupId, privateLayout, layoutId);

      fieldValue = PortalUtil.getLayoutFriendlyURL(layout, themeDisplay);
    } else if (type.equals(DDMImpl.TYPE_RADIO) || type.equals(DDMImpl.TYPE_SELECT)) {

      String valueString = String.valueOf(fieldValue);

      JSONArray jsonArray = JSONFactoryUtil.createJSONArray(valueString);

      String[] stringArray = ArrayUtil.toStringArray(jsonArray);

      fieldValue = stringArray[0];
    }

    return fieldValue;
  }
  public void addAttributes(Document document, DDMStructure ddmStructure, Fields fields) {

    Iterator<Field> itr = fields.iterator();

    while (itr.hasNext()) {
      Field field = itr.next();

      try {
        String indexType = ddmStructure.getFieldProperty(field.getName(), "indexType");

        if (Validator.isNull(indexType)) {
          continue;
        }

        for (Locale locale : LanguageUtil.getAvailableLocales()) {
          String name = encodeName(ddmStructure.getStructureId(), field.getName(), locale);

          Serializable value = field.getValue(locale);

          if (value instanceof Boolean) {
            document.addKeyword(name, (Boolean) value);
          } else if (value instanceof Boolean[]) {
            document.addKeyword(name, (Boolean[]) value);
          } else if (value instanceof Date) {
            document.addDate(name, (Date) value);
          } else if (value instanceof Date[]) {
            document.addDate(name, (Date[]) value);
          } else if (value instanceof Double) {
            document.addKeyword(name, (Double) value);
          } else if (value instanceof Double[]) {
            document.addKeyword(name, (Double[]) value);
          } else if (value instanceof Integer) {
            document.addKeyword(name, (Integer) value);
          } else if (value instanceof Integer[]) {
            document.addKeyword(name, (Integer[]) value);
          } else if (value instanceof Object[]) {
            String[] valuesString = ArrayUtil.toStringArray((Object[]) value);

            if (indexType.equals("keyword")) {
              document.addKeyword(name, valuesString);
            } else {
              document.addText(name, valuesString);
            }
          } else {
            String valueString = String.valueOf(value);

            String type = field.getType();

            if (type.equals(DDMImpl.TYPE_RADIO) || type.equals(DDMImpl.TYPE_SELECT)) {

              JSONArray jsonArray = JSONFactoryUtil.createJSONArray(valueString);

              String[] stringArray = ArrayUtil.toStringArray(jsonArray);

              if (indexType.equals("keyword")) {
                document.addKeyword(name, stringArray);
              } else {
                document.addText(name, stringArray);
              }
            } else {
              if (indexType.equals("keyword")) {
                document.addKeyword(name, valueString);
              } else {
                document.addText(name, valueString);
              }
            }
          }
        }
      } catch (Exception e) {
        if (_log.isWarnEnabled()) {
          _log.warn(e, e);
        }
      }
    }
  }