protected void exportAssetTags(PortletDataContext portletDataContext) throws Exception {

    Document document = SAXReaderUtil.createDocument();

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

    Map<String, String[]> assetTagNamesMap = portletDataContext.getAssetTagNamesMap();

    for (Map.Entry<String, String[]> entry : assetTagNamesMap.entrySet()) {
      String[] assetTagNameParts = StringUtil.split(entry.getKey(), CharPool.POUND);

      String className = assetTagNameParts[0];
      String classPK = assetTagNameParts[1];

      Element assetElement = rootElement.addElement("asset");

      assetElement.addAttribute("class-name", className);
      assetElement.addAttribute("class-pk", classPK);
      assetElement.addAttribute("tags", StringUtil.merge(entry.getValue()));
    }

    List<AssetTag> assetTags =
        AssetTagServiceUtil.getGroupTags(portletDataContext.getScopeGroupId());

    for (AssetTag assetTag : assetTags) {
      exportAssetTag(portletDataContext, assetTag, rootElement);
    }

    portletDataContext.addZipEntry(
        portletDataContext.getRootPath() + "/tags.xml", document.formattedString());
  }
  protected void exportAssetTag(
      PortletDataContext portletDataContext, AssetTag assetTag, Element assetTagsElement)
      throws SystemException, PortalException {

    String path = getAssetTagPath(portletDataContext, assetTag.getTagId());

    if (!portletDataContext.isPathNotProcessed(path)) {
      return;
    }

    Element assetTagElement = assetTagsElement.addElement("tag");

    assetTagElement.addAttribute("path", path);

    assetTag.setUserUuid(assetTag.getUserUuid());

    portletDataContext.addZipEntry(path, assetTag);

    List<AssetTagProperty> assetTagProperties =
        AssetTagPropertyLocalServiceUtil.getTagProperties(assetTag.getTagId());

    for (AssetTagProperty assetTagProperty : assetTagProperties) {
      Element propertyElement = assetTagElement.addElement("property");

      propertyElement.addAttribute("key", assetTagProperty.getKey());
      propertyElement.addAttribute("value", assetTagProperty.getValue());
    }

    portletDataContext.addPermissions(AssetTag.class, assetTag.getTagId());
  }
  protected void exportLocks(PortletDataContext portletDataContext) throws Exception {

    Document document = SAXReaderUtil.createDocument();

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

    Map<String, Lock> locksMap = portletDataContext.getLocks();

    for (Map.Entry<String, Lock> entry : locksMap.entrySet()) {
      Lock lock = entry.getValue();

      String entryKey = entry.getKey();

      int pos = entryKey.indexOf(CharPool.POUND);

      String className = entryKey.substring(0, pos);
      String key = entryKey.substring(pos + 1);

      String path = getLockPath(portletDataContext, className, key, lock);

      Element assetElement = rootElement.addElement("asset");

      assetElement.addAttribute("path", path);
      assetElement.addAttribute("class-name", className);
      assetElement.addAttribute("key", key);

      portletDataContext.addZipEntry(path, lock);
    }

    portletDataContext.addZipEntry(
        ExportImportPathUtil.getRootPath(portletDataContext) + "/locks.xml",
        document.formattedString());
  }
  @Override
  protected void doExportStagedModel(
      PortletDataContext portletDataContext, DLFileEntryType fileEntryType) throws Exception {

    Element fileEntryTypeElement = portletDataContext.getExportDataElement(fileEntryType);

    List<DDMStructure> ddmStructures = fileEntryType.getDDMStructures();

    for (DDMStructure ddmStructure : ddmStructures) {
      com.liferay.dynamic.data.mapping.model.DDMStructure structure =
          _ddmStructureLocalService.getStructure(ddmStructure.getStructureId());

      Element referenceElement =
          StagedModelDataHandlerUtil.exportReferenceStagedModel(
              portletDataContext,
              fileEntryType,
              structure,
              PortletDataContext.REFERENCE_TYPE_STRONG);

      referenceElement.addAttribute(
          "structure-id", StringUtil.valueOf(ddmStructure.getStructureId()));
    }

    long defaultUserId = UserLocalServiceUtil.getDefaultUserId(fileEntryType.getCompanyId());

    if (defaultUserId == fileEntryType.getUserId()) {
      fileEntryTypeElement.addAttribute("preloaded", "true");
    }

    portletDataContext.addClassedModel(
        fileEntryTypeElement, ExportImportPathUtil.getModelPath(fileEntryType), fileEntryType);
  }
  protected void exportAssetLinks(PortletDataContext portletDataContext) throws Exception {

    Document document = SAXReaderUtil.createDocument();

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

    Map<String, String[]> assetLinkUuidsMap = portletDataContext.getAssetLinkUuidsMap();

    for (Map.Entry<String, String[]> entry : assetLinkUuidsMap.entrySet()) {
      String[] assetLinkNameParts = StringUtil.split(entry.getKey(), CharPool.POUND);
      String[] targetAssetEntryUuids = entry.getValue();

      String sourceAssetEntryUuid = assetLinkNameParts[0];
      String assetLinkType = assetLinkNameParts[1];

      Element assetElement = rootElement.addElement("asset-link");

      assetElement.addAttribute("source-uuid", sourceAssetEntryUuid);
      assetElement.addAttribute("target-uuids", StringUtil.merge(targetAssetEntryUuids));
      assetElement.addAttribute("type", assetLinkType);
    }

    portletDataContext.addZipEntry(
        portletDataContext.getRootPath() + "/links.xml", document.formattedString());
  }
  public void addElement(Element rootEl) {
    Element el = rootEl.addElement("Role");

    el.addAttribute("Name", _name);
    el.addAttribute("Description", _description);
    el.addAttribute("Type", _type);
  }
  @Override
  protected void doExportStagedModel(PortletDataContext portletDataContext, Layout layout)
      throws Exception {

    if (layout.isTypeSharedPortlet()) {
      return;
    }

    Element layoutElement = portletDataContext.getExportDataElement(layout);

    populateElementLayoutMetadata(layoutElement, layout);

    layoutElement.addAttribute(Constants.ACTION, Constants.ADD);

    portletDataContext.setPlid(layout.getPlid());

    long parentLayoutId = layout.getParentLayoutId();

    if (parentLayoutId != LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) {
      Layout parentLayout =
          _layoutLocalService.fetchLayout(
              layout.getGroupId(), layout.isPrivateLayout(), parentLayoutId);

      if (parentLayout != null) {
        StagedModelDataHandlerUtil.exportReferenceStagedModel(
            portletDataContext, layout, parentLayout, PortletDataContext.REFERENCE_TYPE_PARENT);

        layoutElement.addAttribute("parent-layout-uuid", parentLayout.getUuid());
      }
    }

    List<LayoutFriendlyURL> layoutFriendlyURLs =
        _layoutFriendlyURLLocalService.getLayoutFriendlyURLs(layout.getPlid());

    for (LayoutFriendlyURL layoutFriendlyURL : layoutFriendlyURLs) {
      StagedModelDataHandlerUtil.exportReferenceStagedModel(
          portletDataContext,
          layout,
          layoutFriendlyURL,
          PortletDataContext.REFERENCE_TYPE_DEPENDENCY);
    }

    if (layout.isIconImage()) {
      exportLayoutIconImage(portletDataContext, layout, layoutElement);
    }

    if (layout.isTypeLinkToLayout()) {
      exportLinkedLayout(portletDataContext, layout, layoutElement);
    }

    fixExportTypeSettings(layout);

    exportTheme(portletDataContext, layout);

    portletDataContext.addClassedModel(
        layoutElement, ExportImportPathUtil.getModelPath(layout), layout);
  }
  protected Element addOptionDynamicElement(String optionValue, Element dynamicElement) {

    Element optionElement = dynamicElement.addElement("dynamic-element");

    optionElement.addAttribute("name", "option_" + StringUtil.randomId());
    optionElement.addAttribute("type", "option");
    optionElement.addAttribute("value", optionValue);

    return optionElement;
  }
  protected Document createEmptyDocument() {
    Document document = SAXReaderUtil.createDocument();

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

    rootElement.addAttribute("available-locales", "en_US");
    rootElement.addAttribute("default-locale", "en_US");

    return document;
  }
  @Override
  protected void doExportStagedModel(PortletDataContext portletDataContext, MBMessage message)
      throws Exception {

    if ((message.getStatus() != WorkflowConstants.STATUS_APPROVED)
        || (message.getCategoryId() == MBCategoryConstants.DISCUSSION_CATEGORY_ID)) {

      return;
    }

    StagedModelDataHandlerUtil.exportStagedModel(portletDataContext, message.getCategory());

    Element messageElement = portletDataContext.getExportDataStagedModelElement(message);

    message.setPriority(message.getPriority());

    MBThread thread = message.getThread();

    messageElement.addAttribute("question", String.valueOf(thread.isQuestion()));

    boolean hasAttachmentsFileEntries = message.getAttachmentsFileEntriesCount() > 0;

    messageElement.addAttribute(
        "hasAttachmentsFileEntries", String.valueOf(hasAttachmentsFileEntries));

    if (portletDataContext.getBooleanParameter(MBPortletDataHandler.NAMESPACE, "attachments")
        && hasAttachmentsFileEntries) {

      for (FileEntry fileEntry : message.getAttachmentsFileEntries()) {
        String name = fileEntry.getTitle();
        String binPath = ExportImportPathUtil.getModelPath(message, name);

        Element attachmentElement = messageElement.addElement("attachment");

        attachmentElement.addAttribute("name", name);
        attachmentElement.addAttribute("bin-path", binPath);

        portletDataContext.addZipEntry(binPath, fileEntry.getContentStream());
      }

      long folderId = message.getAttachmentsFolderId();

      if (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
        message.setAttachmentsFolderId(folderId);
      }
    }

    portletDataContext.addClassedModel(
        messageElement,
        ExportImportPathUtil.getModelPath(message),
        message,
        MBPortletDataHandler.NAMESPACE);
  }
  @Override
  public String serialize(DDMForm ddmForm) {
    Document document = SAXReaderUtil.createDocument();

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

    rootElement.addAttribute("available-locales", getAvailableLanguagesIds(ddmForm));
    rootElement.addAttribute("default-locale", LocaleUtil.toLanguageId(ddmForm.getDefaultLocale()));

    addDynamicElementElements(ddmForm.getDDMFormFields(), rootElement);

    return document.asXML();
  }
  protected void exportMetaData(
      PortletDataContext portletDataContext, Element fileEntryElement, FileEntry fileEntry)
      throws Exception {

    LiferayFileEntry liferayFileEntry = (LiferayFileEntry) fileEntry;

    DLFileEntry dlFileEntry = liferayFileEntry.getDLFileEntry();

    long fileEntryTypeId = dlFileEntry.getFileEntryTypeId();

    DLFileEntryType dlFileEntryType =
        DLFileEntryTypeLocalServiceUtil.fetchFileEntryType(fileEntryTypeId);

    if ((dlFileEntryType == null) || !dlFileEntryType.isExportable()) {
      return;
    }

    StagedModelDataHandlerUtil.exportReferenceStagedModel(
        portletDataContext, fileEntry, dlFileEntryType, PortletDataContext.REFERENCE_TYPE_STRONG);

    List<DDMStructure> ddmStructures = dlFileEntryType.getDDMStructures();

    for (DDMStructure ddmStructure : ddmStructures) {
      FileVersion fileVersion = fileEntry.getFileVersion();

      DLFileEntryMetadata dlFileEntryMetadata =
          DLFileEntryMetadataLocalServiceUtil.fetchFileEntryMetadata(
              ddmStructure.getStructureId(), fileVersion.getFileVersionId());

      if (dlFileEntryMetadata == null) {
        continue;
      }

      Element structureFields = fileEntryElement.addElement("structure-fields");

      String path =
          ExportImportPathUtil.getModelPath(
              ddmStructure, String.valueOf(dlFileEntryMetadata.getDDMStorageId()));

      structureFields.addAttribute("path", path);

      structureFields.addAttribute("structureUuid", ddmStructure.getUuid());

      DDMFormValues ddmFormValues =
          StorageEngineUtil.getDDMFormValues(dlFileEntryMetadata.getDDMStorageId());

      portletDataContext.addZipEntry(path, ddmFormValues);
    }
  }
Esempio n. 13
0
  protected void exportThumbnail(
      PortletDataContext portletDataContext,
      FileEntry fileEntry,
      Element fileEntryElement,
      String binPathName,
      int index)
      throws PortalException, SystemException {

    FileVersion fileVersion = fileEntry.getFileVersion();

    if (!hasThumbnail(fileVersion, index)) {
      return;
    }

    InputStream is = null;

    try {
      is = doGetThumbnailAsStream(fileVersion, index);

      String binPath = getBinPath(portletDataContext, fileEntry, index);

      fileEntryElement.addAttribute(binPathName, binPath);

      exportBinary(portletDataContext, fileEntryElement, fileVersion, is, binPath, binPathName);
    } finally {
      StreamUtil.cleanUp(is);
    }
  }
  @Override
  protected void doExportStagedModel(PortletDataContext portletDataContext, MBThreadFlag threadFlag)
      throws Exception {

    MBThread thread = MBThreadLocalServiceUtil.getThread(threadFlag.getThreadId());

    MBMessage rootMessage = MBMessageLocalServiceUtil.getMessage(thread.getRootMessageId());

    if ((rootMessage.getStatus() != WorkflowConstants.STATUS_APPROVED)
        || (rootMessage.getCategoryId() == MBCategoryConstants.DISCUSSION_CATEGORY_ID)) {

      return;
    }

    StagedModelDataHandlerUtil.exportStagedModel(portletDataContext, rootMessage);

    Element threadFlagElement = portletDataContext.getExportDataElement(threadFlag);

    threadFlagElement.addAttribute("root-message-id", String.valueOf(rootMessage.getMessageId()));

    portletDataContext.addClassedModel(
        threadFlagElement,
        ExportImportPathUtil.getModelPath(threadFlag),
        threadFlag,
        MBPortletDataHandler.NAMESPACE);
  }
  @Override
  protected void validateExport(
      PortletDataContext portletDataContext,
      StagedModel stagedModel,
      Map<String, List<StagedModel>> dependentStagedModelsMap)
      throws Exception {

    ManifestSummary manifestSummary = portletDataContext.getManifestSummary();

    Map<String, LongWrapper> modelAdditionCounters = manifestSummary.getModelAdditionCounters();

    Assert.assertEquals(4, modelAdditionCounters.size());
    Assert.assertEquals(
        1, manifestSummary.getModelAdditionCount(DDMStructure.class, JournalArticle.class));
    Assert.assertEquals(
        1, manifestSummary.getModelAdditionCount(DDMTemplate.class, DDMStructure.class));
    Assert.assertEquals(1, manifestSummary.getModelAdditionCount(JournalArticle.class));
    Assert.assertEquals(1, manifestSummary.getModelAdditionCount(JournalFolder.class));

    Document document = SAXReaderUtil.createDocument();

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

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

    _exportDate = new Date();

    headerElement.addAttribute("export-date", Time.getRFC822(_exportDate));

    ExportImportHelperUtil.writeManifestSummary(document, manifestSummary);

    zipWriter.addEntry("/manifest.xml", document.asXML());
  }
  @Override
  protected void doExportStagedModel(PortletDataContext portletDataContext, WikiPage page)
      throws Exception {

    Element pageElement = portletDataContext.getExportDataElement(page);

    StagedModelDataHandlerUtil.exportReferenceStagedModel(
        portletDataContext, page, page.getNode(), PortletDataContext.REFERENCE_TYPE_PARENT);

    String content =
        _wikiPageExportImportContentProcessor.replaceExportContentReferences(
            portletDataContext,
            page,
            page.getContent(),
            portletDataContext.getBooleanParameter("wiki", "referenced-content"),
            true);

    page.setContent(content);

    if (page.isHead()) {
      for (FileEntry fileEntry : page.getAttachmentsFileEntries()) {
        StagedModelDataHandlerUtil.exportReferenceStagedModel(
            portletDataContext, page, fileEntry, PortletDataContext.REFERENCE_TYPE_WEAK);
      }
    }

    WikiPageResource pageResource =
        _wikiPageResourceLocalService.getPageResource(page.getResourcePrimKey());

    pageElement.addAttribute("page-resource-uuid", pageResource.getUuid());

    portletDataContext.addClassedModel(pageElement, ExportImportPathUtil.getModelPath(page), page);
  }
  @Override
  protected void doExportStagedModel(
      PortletDataContext portletDataContext, MDRRuleGroupInstance ruleGroupInstance)
      throws Exception {

    MDRRuleGroup ruleGroup =
        _mdrRuleGroupLocalService.getRuleGroup(ruleGroupInstance.getRuleGroupId());

    StagedModelDataHandlerUtil.exportReferenceStagedModel(
        portletDataContext, ruleGroupInstance, ruleGroup, PortletDataContext.REFERENCE_TYPE_PARENT);

    Element ruleGroupInstanceElement = portletDataContext.getExportDataElement(ruleGroupInstance);

    String className = ruleGroupInstance.getClassName();

    if (className.equals(Layout.class.getName())) {
      Layout layout = _layoutLocalService.getLayout(ruleGroupInstance.getClassPK());

      ruleGroupInstanceElement.addAttribute("layout-uuid", layout.getUuid());
    }

    portletDataContext.addClassedModel(
        ruleGroupInstanceElement,
        ExportImportPathUtil.getModelPath(ruleGroupInstance),
        ruleGroupInstance);
  }
  public void addExpando(Element element, String path, ClassedModel classedModel)
      throws PortalException, SystemException {

    Class<?> clazz = classedModel.getModelClass();

    String className = clazz.getName();

    if (!_expandoColumnsMap.containsKey(className)) {
      List<ExpandoColumn> expandoColumns =
          ExpandoColumnLocalServiceUtil.getDefaultTableColumns(_companyId, className);

      for (ExpandoColumn expandoColumn : expandoColumns) {
        addPermissions(ExpandoColumn.class, expandoColumn.getColumnId());
      }

      _expandoColumnsMap.put(className, expandoColumns);
    }

    ExpandoBridge expandoBridge = classedModel.getExpandoBridge();

    Map<String, Serializable> expandoBridgeAttributes = expandoBridge.getAttributes();

    if (!expandoBridgeAttributes.isEmpty()) {
      String expandoPath = getExpandoPath(path);

      element.addAttribute("expando-path", expandoPath);

      addZipEntry(expandoPath, expandoBridgeAttributes);
    }
  }
  @Override
  protected void doExportStagedModel(PortletDataContext portletDataContext, Repository repository)
      throws Exception {

    Element repositoryElement = portletDataContext.getExportDataElement(repository);

    Folder folder = DLAppLocalServiceUtil.getFolder(repository.getDlFolderId());

    if (folder.getModel() instanceof DLFolder) {
      DLFolder dlFolder = (DLFolder) folder.getModel();

      repositoryElement.addAttribute("hidden", String.valueOf(dlFolder.isHidden()));
    }

    portletDataContext.addClassedModel(
        repositoryElement, ExportImportPathUtil.getModelPath(repository), repository);

    List<RepositoryEntry> repositoryEntries =
        RepositoryEntryLocalServiceUtil.getRepositoryEntries(repository.getRepositoryId());

    for (RepositoryEntry repositoryEntry : repositoryEntries) {
      StagedModelDataHandlerUtil.exportReferenceStagedModel(
          portletDataContext, repository, repositoryEntry, PortletDataContext.REFERENCE_TYPE_CHILD);
    }
  }
  @Override
  protected void doExportStagedModel(
      PortletDataContext portletDataContext, DLFileEntryType fileEntryType) throws Exception {

    Element fileEntryTypeElement = portletDataContext.getExportDataElement(fileEntryType);

    List<DDMStructure> ddmStructures = fileEntryType.getDDMStructures();

    for (DDMStructure ddmStructure : ddmStructures) {
      StagedModelDataHandlerUtil.exportStagedModel(portletDataContext, ddmStructure);

      Element referenceElement =
          portletDataContext.addReferenceElement(
              fileEntryType,
              fileEntryTypeElement,
              ddmStructure,
              PortletDataContext.REFERENCE_TYPE_STRONG,
              false);

      referenceElement.addAttribute(
          "structure-id", StringUtil.valueOf(ddmStructure.getStructureId()));
    }

    portletDataContext.addClassedModel(
        fileEntryTypeElement,
        ExportImportPathUtil.getModelPath(fileEntryType),
        fileEntryType,
        DLPortletDataHandler.NAMESPACE);
  }
  @Override
  protected void doExportStagedModel(
      PortletDataContext portletDataContext,
      Element[] elements,
      MDRRuleGroupInstance ruleGroupInstance)
      throws Exception {

    Element ruleGroupsElement = elements[0];

    MDRRuleGroup ruleGroup =
        MDRRuleGroupLocalServiceUtil.getRuleGroup(ruleGroupInstance.getRuleGroupId());

    StagedModelDataHandlerUtil.exportStagedModel(portletDataContext, ruleGroupsElement, ruleGroup);

    Element ruleGroupInstancesElement = elements[1];

    Element ruleGroupInstanceElement = ruleGroupInstancesElement.addElement("rule-group-instance");

    String className = ruleGroupInstance.getClassName();

    if (className.equals(Layout.class.getName())) {
      Layout layout = LayoutLocalServiceUtil.getLayout(ruleGroupInstance.getClassPK());

      ruleGroupInstanceElement.addAttribute("layout-uuid", layout.getUuid());
    }

    portletDataContext.addClassedModel(
        ruleGroupInstanceElement,
        StagedModelPathUtil.getPath(ruleGroupInstance),
        ruleGroupInstance,
        MDRPortletDataHandler.NAMESPACE);
  }
  @Override
  protected void doExportStagedModel(PortletDataContext portletDataContext, DDLRecord record)
      throws Exception {

    StagedModelDataHandlerUtil.exportReferenceStagedModel(
        portletDataContext,
        record,
        record.getRecordSet(),
        PortletDataContext.REFERENCE_TYPE_STRONG);

    DDLRecordVersion recordVersion = record.getRecordVersion();

    Fields fields = StorageEngineUtil.getFields(recordVersion.getDDMStorageId());

    String fieldsPath = ExportImportPathUtil.getModelPath(record, "fields.xml");

    portletDataContext.addZipEntry(fieldsPath, fields);

    Element recordElement = portletDataContext.getExportDataElement(record);

    recordElement.addAttribute("fields-path", fieldsPath);

    portletDataContext.addClassedModel(
        recordElement, ExportImportPathUtil.getModelPath(record), record);
  }
  @Override
  protected String doExportData(
      PortletDataContext portletDataContext,
      String portletId,
      PortletPreferences portletPreferences)
      throws Exception {

    Element rootElement = addExportDataRootElement(portletDataContext);

    rootElement.addAttribute("group-id", String.valueOf(portletDataContext.getScopeGroupId()));

    if (portletDataContext.getBooleanParameter(NAMESPACE, "categories")) {
      ActionableDynamicQuery categoryActionableDynamicQuery =
          getCategoryActionableDynamicQuery(portletDataContext);

      categoryActionableDynamicQuery.performActions();
    }

    if (portletDataContext.getBooleanParameter(NAMESPACE, "vocabularies")) {
      ActionableDynamicQuery vocabularyActionableDynamicQuery =
          getVocabularyActionableDynamicQuery(portletDataContext);

      vocabularyActionableDynamicQuery.performActions();
    }

    return getExportDataRootElementString(rootElement);
  }
  protected void exportAssetCategory(
      PortletDataContext portletDataContext,
      Element assetVocabulariesElement,
      Element assetCategoriesElement,
      AssetCategory assetCategory)
      throws Exception {

    exportAssetVocabulary(
        portletDataContext, assetVocabulariesElement, assetCategory.getVocabularyId());

    if (assetCategory.getParentCategoryId() != AssetCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) {

      exportAssetCategory(
          portletDataContext,
          assetVocabulariesElement,
          assetCategoriesElement,
          assetCategory.getParentCategoryId());
    }

    String path = getAssetCategoryPath(portletDataContext, assetCategory.getCategoryId());

    if (!portletDataContext.isPathNotProcessed(path)) {
      return;
    }

    Element assetCategoryElement = assetCategoriesElement.addElement("category");

    assetCategoryElement.addAttribute("path", path);

    assetCategory.setUserUuid(assetCategory.getUserUuid());

    portletDataContext.addZipEntry(path, assetCategory);

    List<AssetCategoryProperty> assetCategoryProperties =
        AssetCategoryPropertyLocalServiceUtil.getCategoryProperties(assetCategory.getCategoryId());

    for (AssetCategoryProperty assetCategoryProperty : assetCategoryProperties) {

      Element propertyElement = assetCategoryElement.addElement("property");

      propertyElement.addAttribute("userUuid", assetCategoryProperty.getUserUuid());
      propertyElement.addAttribute("key", assetCategoryProperty.getKey());
      propertyElement.addAttribute("value", assetCategoryProperty.getValue());
    }

    portletDataContext.addPermissions(AssetCategory.class, assetCategory.getCategoryId());
  }
  protected void exportJournalArticle(
      PortletDataContext portletDataContext, Layout layout, Element layoutElement)
      throws Exception {

    UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties();

    String articleId = typeSettingsProperties.getProperty("article-id", StringPool.BLANK);

    long articleGroupId = layout.getGroupId();

    if (Validator.isNull(articleId)) {
      if (_log.isWarnEnabled()) {
        _log.warn("No article id found in typeSettings of layout " + layout.getPlid());
      }
    }

    JournalArticle article = null;

    try {
      article =
          JournalArticleLocalServiceUtil.getLatestArticle(
              articleGroupId, articleId, WorkflowConstants.STATUS_APPROVED);
    } catch (NoSuchArticleException nsae) {
      if (_log.isWarnEnabled()) {
        _log.warn(
            "No approved article found with group id "
                + articleGroupId
                + " and article id "
                + articleId);
      }
    }

    if (article == null) {
      return;
    }

    String path = JournalPortletDataHandlerImpl.getArticlePath(portletDataContext, article);

    Element articleElement = layoutElement.addElement("article");

    articleElement.addAttribute("path", path);

    Element dlFileEntryTypesElement = layoutElement.addElement("dl-file-entry-types");
    Element dlFoldersElement = layoutElement.addElement("dl-folders");
    Element dlFilesElement = layoutElement.addElement("dl-file-entries");
    Element dlFileRanksElement = layoutElement.addElement("dl-file-ranks");

    JournalPortletDataHandlerImpl.exportArticle(
        portletDataContext,
        layoutElement,
        layoutElement,
        layoutElement,
        dlFileEntryTypesElement,
        dlFoldersElement,
        dlFilesElement,
        dlFileRanksElement,
        article,
        false);
  }
Esempio n. 26
0
  @Override
  protected String doExportData(
      final PortletDataContext portletDataContext,
      String portletId,
      PortletPreferences portletPreferences)
      throws Exception {

    portletDataContext.addPermissions(
        "com.liferay.portlet.dynamicdatamapping", portletDataContext.getScopeGroupId());

    Element rootElement = addExportDataRootElement(portletDataContext);

    rootElement.addAttribute("group-id", String.valueOf(portletDataContext.getScopeGroupId()));

    ActionableDynamicQuery structureActionableDynamicQuery =
        new DDMStructureActionableDynamicQuery() {

          @Override
          protected void addCriteria(DynamicQuery dynamicQuery) {
            portletDataContext.addDateRangeCriteria(dynamicQuery, "modifiedDate");
          }

          @Override
          protected void performAction(Object object) throws PortalException {

            DDMStructure structure = (DDMStructure) object;

            StagedModelDataHandlerUtil.exportStagedModel(portletDataContext, structure);
          }
        };

    structureActionableDynamicQuery.setGroupId(portletDataContext.getScopeGroupId());

    structureActionableDynamicQuery.performActions();

    ActionableDynamicQuery templateActionableDynamicQuery =
        new DDMTemplateActionableDynamicQuery() {

          @Override
          protected void addCriteria(DynamicQuery dynamicQuery) {
            portletDataContext.addDateRangeCriteria(dynamicQuery, "modifiedDate");
          }

          @Override
          protected void performAction(Object object) throws PortalException {

            DDMTemplate template = (DDMTemplate) object;

            StagedModelDataHandlerUtil.exportStagedModel(portletDataContext, template);
          }
        };

    templateActionableDynamicQuery.setGroupId(portletDataContext.getScopeGroupId());

    templateActionableDynamicQuery.performActions();

    return getExportDataRootElementString(rootElement);
  }
  protected String doExport(Definition definition) {
    try {
      Document document = SAXReaderUtil.createDocument();

      Element workflowDefinitionElement = document.addElement("workflow-definition");

      workflowDefinitionElement.addAttribute(
          "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
      workflowDefinitionElement.addAttribute(
          "xsi:schemaLocation",
          "urn:liferay.com:liferay-workflow_"
              + _version
              + " http://www.liferay.com/dtd/liferay-workflow-definition_"
              + _schemaVersion
              + ".xsd");
      workflowDefinitionElement.addNamespace("", "urn:liferay.com:liferay-workflow_" + _version);

      Element nameElement = workflowDefinitionElement.addElement("name", _namespace);

      nameElement.addText(definition.getName());

      if (Validator.isNotNull(definition.getDescription())) {
        Element descriptionElement =
            workflowDefinitionElement.addElement("description", _namespace);

        descriptionElement.addText(definition.getDescription());
      }

      Element versionElement = workflowDefinitionElement.addElement("version", _namespace);

      versionElement.addText(String.valueOf(definition.getVersion()));

      Collection<Node> nodes = definition.getNodes();

      for (Node node : nodes) {
        NodeExporter nodeExporter = NodeExporterRegistry.getNodeExporter(node.getNodeType());

        nodeExporter.exportNode(node, workflowDefinitionElement, _namespace);
      }

      return document.formattedString();
    } catch (IOException ioe) {
      throw new SystemException("Unable to export definition", ioe);
    }
  }
  protected void addMetadataEntry(Map<String, String> entryMap, Element metadataElement) {

    for (Map.Entry<String, String> entry : entryMap.entrySet()) {
      Element entryElement = metadataElement.addElement("entry");

      entryElement.addAttribute("name", entry.getKey());

      entryElement.addText(entry.getValue());
    }
  }
Esempio n. 29
0
  protected void appendField(Element element, Field field) {
    Element dynamicElementElement = element.addElement("dynamic-element");

    dynamicElementElement.addAttribute(
        "default-language-id", LocaleUtil.toLanguageId(field.getDefaultLocale()));
    dynamicElementElement.addAttribute("name", field.getName());

    for (Locale locale : field.getAvailableLocales()) {
      List<Serializable> values = field.getValues(locale);

      for (Serializable value : values) {
        Element dynamicContentElement = dynamicElementElement.addElement("dynamic-content");

        dynamicContentElement.addAttribute("language-id", LocaleUtil.toLanguageId(locale));

        updateField(dynamicContentElement, value);
      }
    }
  }
  @Override
  protected void doExportStagedModel(PortletDataContext portletDataContext, AssetCategory category)
      throws Exception {

    if (category.getParentCategoryId() != AssetCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) {

      AssetCategory parentCategory =
          AssetCategoryLocalServiceUtil.fetchAssetCategory(category.getParentCategoryId());

      StagedModelDataHandlerUtil.exportReferenceStagedModel(
          portletDataContext, category, parentCategory, PortletDataContext.REFERENCE_TYPE_PARENT);
    } else {
      AssetVocabulary vocabulary =
          AssetVocabularyLocalServiceUtil.fetchAssetVocabulary(category.getVocabularyId());

      StagedModelDataHandlerUtil.exportReferenceStagedModel(
          portletDataContext, category, vocabulary, PortletDataContext.REFERENCE_TYPE_PARENT);
    }

    Element categoryElement = portletDataContext.getExportDataElement(category);

    category.setUserUuid(category.getUserUuid());

    List<AssetCategoryProperty> categoryProperties =
        AssetCategoryPropertyLocalServiceUtil.getCategoryProperties(category.getCategoryId());

    for (AssetCategoryProperty categoryProperty : categoryProperties) {
      Element propertyElement = categoryElement.addElement("property");

      propertyElement.addAttribute("userUuid", categoryProperty.getUserUuid());
      propertyElement.addAttribute("key", categoryProperty.getKey());
      propertyElement.addAttribute("value", categoryProperty.getValue());
    }

    String categoryPath = ExportImportPathUtil.getModelPath(category);

    categoryElement.addAttribute("path", categoryPath);

    portletDataContext.addPermissions(AssetCategory.class, category.getCategoryId());

    portletDataContext.addZipEntry(categoryPath, category);
  }