Ejemplo n.º 1
0
  protected void exportAssetCategories(PortletDataContext portletDataContext) throws Exception {

    Document document = SAXReaderUtil.createDocument();

    Element rootElement = document.addElement("categories-hierarchy");

    Element assetVocabulariesElement = rootElement.addElement("vocabularies");

    List<AssetVocabulary> assetVocabularies =
        AssetVocabularyLocalServiceUtil.getGroupVocabularies(portletDataContext.getGroupId());

    for (AssetVocabulary assetVocabulary : assetVocabularies) {
      _portletExporter.exportAssetVocabulary(
          portletDataContext, assetVocabulariesElement, assetVocabulary);
    }

    Element categoriesElement = rootElement.addElement("categories");

    List<AssetCategory> assetCategories =
        AssetCategoryUtil.findByGroupId(portletDataContext.getGroupId());

    for (AssetCategory assetCategory : assetCategories) {
      _portletExporter.exportAssetCategory(
          portletDataContext, assetVocabulariesElement, categoriesElement, assetCategory);
    }

    _portletExporter.exportAssetCategories(portletDataContext, rootElement);

    portletDataContext.addZipEntry(
        portletDataContext.getRootPath() + "/categories-hierarchy.xml", document.formattedString());
  }
  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());
  }
Ejemplo n.º 3
0
  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());
  }
Ejemplo n.º 4
0
  @Override
  public String getXML(Document document, Fields fields) {
    Element rootElement = null;

    try {
      if (document != null) {
        rootElement = document.getRootElement();
      } else {
        document = SAXReaderUtil.createDocument();

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

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

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

        List<Node> nodes = getElementsByName(document, field.getName());

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

        appendField(rootElement, field);
      }

      return document.formattedString();
    } catch (IOException ioe) {
      throw new SystemException(ioe);
    }
  }
  private String _getAssetEntryXml(String assetEntryType, String assetEntryUuid) {

    String xml = null;

    try {
      Document document = SAXReaderUtil.createDocument(StringPool.UTF8);

      Element assetEntryElement = document.addElement("asset-entry");

      Element assetEntryTypeElement = assetEntryElement.addElement("asset-entry-type");

      assetEntryTypeElement.addText(assetEntryType);

      Element assetEntryUuidElement = assetEntryElement.addElement("asset-entry-uuid");

      assetEntryUuidElement.addText(assetEntryUuid);

      xml = document.formattedString(StringPool.BLANK);
    } catch (IOException ioe) {
      if (_log.isWarnEnabled()) {
        _log.warn(ioe);
      }
    }

    return xml;
  }
Ejemplo n.º 6
0
  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());
  }
  protected void exportAssetLinks(PortletDataContext portletDataContext) throws Exception {

    Document document = SAXReaderUtil.createDocument();

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

    Element exportDataRootElement = portletDataContext.getExportDataRootElement();

    try {
      portletDataContext.setExportDataRootElement(rootElement);

      ActionableDynamicQuery linkActionableDynamicQuery =
          _assetLinkLocalService.getExportActionbleDynamicQuery(portletDataContext);

      linkActionableDynamicQuery.performActions();

      for (long linkId : portletDataContext.getAssetLinkIds()) {
        AssetLink assetLink = _assetLinkLocalService.getAssetLink(linkId);

        StagedAssetLink stagedAssetLink =
            ModelAdapterUtil.adapt(assetLink, AssetLink.class, StagedAssetLink.class);

        portletDataContext.addClassedModel(
            portletDataContext.getExportDataElement(stagedAssetLink),
            ExportImportPathUtil.getModelPath(stagedAssetLink),
            stagedAssetLink);
      }
    } finally {
      portletDataContext.setExportDataRootElement(exportDataRootElement);
    }

    portletDataContext.addZipEntry(
        ExportImportPathUtil.getRootPath(portletDataContext) + "/links.xml",
        document.formattedString());
  }
  @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
 public void setEvaluationModel(Course course, JSONObject model)
     throws PortalException, SystemException, DocumentException, IOException {
   Document document = SAXReaderUtil.createDocument();
   Element rootElement = document.addElement("eval");
   rootElement.addElement("courseEval").setText(PonderatedCourseEval.class.getName());
   course.setCourseExtraData(document.formattedString());
 }
  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;
  }
Ejemplo n.º 11
0
  protected void exportAssetCategories(PortletDataContext portletDataContext) throws Exception {

    Document document = SAXReaderUtil.createDocument();

    Element rootElement = document.addElement("categories-hierarchy");

    exportAssetCategories(portletDataContext, rootElement);

    portletDataContext.addZipEntry(
        portletDataContext.getRootPath() + "/categories-hierarchy.xml", document.formattedString());
  }
  @Override
  protected String doExportData(
      PortletDataContext portletDataContext,
      String portletId,
      PortletPreferences portletPreferences)
      throws Exception {

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

    long rootFolderId = GetterUtil.getLong(portletPreferences.getValue("rootFolderId", null));

    Document document = SAXReaderUtil.createDocument();

    Element rootElement = document.addElement("documentlibrary-display-data");

    Element fileEntryTypesElement = rootElement.addElement("file-entry-types");
    Element foldersElement = rootElement.addElement("folders");
    Element fileEntriesElement = rootElement.addElement("file-entries");
    Element fileShortcutsElement = rootElement.addElement("file-shortcuts");
    Element fileRanksElement = rootElement.addElement("file-ranks");

    if (rootFolderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
      List<Folder> folders = FolderUtil.findByRepositoryId(portletDataContext.getScopeGroupId());

      for (Folder folder : folders) {
        DLPortletDataHandlerImpl.exportFolder(
            portletDataContext,
            fileEntryTypesElement,
            foldersElement,
            fileEntriesElement,
            fileShortcutsElement,
            fileRanksElement,
            folder,
            false);
      }
    } else {
      Folder folder = FolderUtil.findByPrimaryKey(rootFolderId);

      rootElement.addAttribute("root-folder-id", String.valueOf(folder.getFolderId()));

      DLPortletDataHandlerImpl.exportFolder(
          portletDataContext,
          fileEntryTypesElement,
          foldersElement,
          fileEntriesElement,
          fileShortcutsElement,
          fileRanksElement,
          folder,
          true);
    }

    return document.formattedString();
  }
  public String getXml(List list) {
    Document doc = SAXReaderUtil.createDocument();

    Element root = doc.addElement("result");

    for (Object obj : list) {
      BeanToXMLUtil.addBean(obj, root);
    }

    return doc.asXML();
  }
  @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();
  }
  @Override
  protected String doExportData(
      PortletDataContext portletDataContext,
      String portletId,
      PortletPreferences portletPreferences)
      throws Exception {

    long questionId =
        GetterUtil.getLong(portletPreferences.getValue("questionId", StringPool.BLANK));

    if (questionId <= 0) {
      if (_log.isWarnEnabled()) {
        _log.warn("No question id found in preferences of portlet " + portletId);
      }

      return StringPool.BLANK;
    }

    PollsQuestion question = null;

    try {
      question = PollsQuestionUtil.findByPrimaryKey(questionId);
    } catch (NoSuchQuestionException nsqe) {
      if (_log.isWarnEnabled()) {
        _log.warn(nsqe, nsqe);
      }

      return StringPool.BLANK;
    }

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

    Document document = SAXReaderUtil.createDocument();

    Element rootElement = document.addElement("polls-display-data");

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

    Element questionsElement = rootElement.addElement("questions");
    Element choicesElement = rootElement.addElement("choices");
    Element votesElement = rootElement.addElement("votes");

    PollsPortletDataHandlerImpl.exportQuestion(
        portletDataContext, questionsElement, choicesElement, votesElement, question);

    return document.formattedString();
  }
  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);
    }
  }
Ejemplo n.º 17
0
  protected void exportAssetCategories(
      PortletDataContext portletDataContext,
      boolean exportPortletDataAll,
      boolean exportCategories,
      boolean companyGroup)
      throws Exception {

    Document document = SAXReaderUtil.createDocument();

    Element rootElement = document.addElement("categories-hierarchy");

    if (exportPortletDataAll || exportCategories || companyGroup) {
      if (_log.isDebugEnabled()) {
        _log.debug("Export categories");
      }

      Element assetVocabulariesElement = rootElement.addElement("vocabularies");

      List<AssetVocabulary> assetVocabularies =
          AssetVocabularyLocalServiceUtil.getGroupVocabularies(portletDataContext.getGroupId());

      for (AssetVocabulary assetVocabulary : assetVocabularies) {
        _portletExporter.exportAssetVocabulary(
            portletDataContext, assetVocabulariesElement, assetVocabulary);
      }

      Element categoriesElement = rootElement.addElement("categories");

      List<AssetCategory> assetCategories =
          AssetCategoryUtil.findByGroupId(portletDataContext.getGroupId());

      for (AssetCategory assetCategory : assetCategories) {
        _portletExporter.exportAssetCategory(
            portletDataContext, assetVocabulariesElement,
            categoriesElement, assetCategory);
      }
    }

    _portletExporter.exportAssetCategories(portletDataContext, rootElement);

    portletDataContext.addZipEntry(
        ExportImportPathUtil.getRootPath(portletDataContext) + "/categories-hierarchy.xml",
        document.formattedString());
  }
Ejemplo n.º 18
0
  @Override
  public String getSitemap(long groupId, boolean privateLayout, ThemeDisplay themeDisplay)
      throws PortalException, SystemException {

    Document document = SAXReaderUtil.createDocument();

    document.setXMLEncoding(StringPool.UTF8);

    Element rootElement =
        document.addElement("urlset", "http://www.google.com/schemas/sitemap/0.9");

    rootElement.addAttribute("xmlns:xhtml", "http://www.w3.org/1999/xhtml");

    List<Layout> layouts =
        LayoutLocalServiceUtil.getLayouts(
            groupId, privateLayout, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);

    visitLayouts(rootElement, layouts, themeDisplay);

    return document.asXML();
  }
  @Override
  protected String doExportData(
      PortletDataContext portletDataContext,
      String portletId,
      PortletPreferences portletPreferences)
      throws Exception {

    Document document = SAXReaderUtil.createDocument();

    Element rootElement = document.addElement("wsrp-data");

    if (portletDataContext.getBooleanParameter(_NAMESPACE, "wsrp-producers")) {

      Element wsrpProducersElement = rootElement.addElement("wsrp-producers");

      List<WSRPProducer> wsrpProducers =
          WSRPProducerLocalServiceUtil.getWSRPProducers(
              portletDataContext.getCompanyId(), QueryUtil.ALL_POS, QueryUtil.ALL_POS);

      for (WSRPProducer wsrpProducer : wsrpProducers) {
        exportWSRPProducer(portletDataContext, wsrpProducersElement, wsrpProducer);
      }
    }

    if (portletDataContext.getBooleanParameter(_NAMESPACE, "wsrp-consumers")) {

      Element wsrpConsumersElement = rootElement.addElement("wsrp-consumers");

      List<WSRPConsumer> wsrpConsumers =
          WSRPConsumerLocalServiceUtil.getWSRPConsumers(
              portletDataContext.getCompanyId(), QueryUtil.ALL_POS, QueryUtil.ALL_POS);

      for (WSRPConsumer wsrpConsumer : wsrpConsumers) {
        exportWSRPConsumer(portletDataContext, wsrpConsumersElement, wsrpConsumer);
      }
    }

    return document.formattedString();
  }
  protected void exportExpandoTables(PortletDataContext portletDataContext) throws Exception {

    Document document = SAXReaderUtil.createDocument();

    Element rootElement = document.addElement("expando-tables");

    Map<String, List<ExpandoColumn>> expandoColumnsMap = portletDataContext.getExpandoColumns();

    for (Map.Entry<String, List<ExpandoColumn>> entry : expandoColumnsMap.entrySet()) {

      String className = entry.getKey();

      Element expandoTableElement = rootElement.addElement("expando-table");

      expandoTableElement.addAttribute("class-name", className);

      List<ExpandoColumn> expandoColumns = entry.getValue();

      for (ExpandoColumn expandoColumn : expandoColumns) {
        Element expandoColumnElement = expandoTableElement.addElement("expando-column");

        expandoColumnElement.addAttribute("column-id", String.valueOf(expandoColumn.getColumnId()));
        expandoColumnElement.addAttribute("name", expandoColumn.getName());
        expandoColumnElement.addAttribute("type", String.valueOf(expandoColumn.getType()));

        DocUtil.add(expandoColumnElement, "default-data", expandoColumn.getDefaultData());

        Element typeSettingsElement = expandoColumnElement.addElement("type-settings");

        UnicodeProperties typeSettingsProperties = expandoColumn.getTypeSettingsProperties();

        typeSettingsElement.addCDATA(typeSettingsProperties.toString());
      }
    }

    portletDataContext.addZipEntry(
        ExportImportPathUtil.getRootPath(portletDataContext) + "/expando-tables.xml",
        document.formattedString());
  }
Ejemplo n.º 21
0
  protected void exportRatingsEntries(PortletDataContext portletDataContext, Element parentElement)
      throws Exception {

    Document document = SAXReaderUtil.createDocument();

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

    Map<String, List<RatingsEntry>> ratingsEntriesMap = portletDataContext.getRatingsEntries();

    for (Map.Entry<String, List<RatingsEntry>> entry : ratingsEntriesMap.entrySet()) {

      String[] ratingsEntryParts = StringUtil.split(entry.getKey(), CharPool.POUND);

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

      String ratingsEntriesPath = getRatingsEntriesPath(portletDataContext, className, classPK);

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

      assetElement.addAttribute("path", ratingsEntriesPath);
      assetElement.addAttribute("class-name", className);
      assetElement.addAttribute("class-pk", classPK);

      List<RatingsEntry> ratingsEntries = entry.getValue();

      for (RatingsEntry ratingsEntry : ratingsEntries) {
        String ratingsEntryPath =
            getRatingsEntryPath(portletDataContext, className, classPK, ratingsEntry);

        portletDataContext.addZipEntry(ratingsEntryPath, ratingsEntry);
      }
    }

    portletDataContext.addZipEntry(
        portletDataContext.getRootPath() + "/ratings.xml", document.formattedString());
  }
Ejemplo n.º 22
0
  protected void exportComments(PortletDataContext portletDataContext) throws Exception {

    Document document = SAXReaderUtil.createDocument();

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

    Map<String, List<MBMessage>> commentsMap = portletDataContext.getComments();

    for (Map.Entry<String, List<MBMessage>> entry : commentsMap.entrySet()) {

      String[] commentParts = StringUtil.split(entry.getKey(), CharPool.POUND);

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

      String commentsPath = getCommentsPath(portletDataContext, className, classPK);

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

      assetElement.addAttribute("path", commentsPath);
      assetElement.addAttribute("class-name", className);
      assetElement.addAttribute("class-pk", classPK);

      List<MBMessage> mbMessages = entry.getValue();

      for (MBMessage mbMessage : mbMessages) {
        String commentPath = getCommentPath(portletDataContext, className, classPK, mbMessage);

        if (portletDataContext.isPathNotProcessed(commentPath)) {
          portletDataContext.addZipEntry(commentPath, mbMessage);
        }
      }
    }

    portletDataContext.addZipEntry(
        portletDataContext.getRootPath() + "/comments.xml", document.formattedString());
  }
  @Override
  protected String doExportData(
      PortletDataContext portletDataContext,
      String portletId,
      PortletPreferences portletPreferences)
      throws Exception {

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

    Document document = SAXReaderUtil.createDocument();

    Element rootElement = document.addElement("calendar-data");

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

    List<CalEvent> events = CalEventUtil.findByGroupId(portletDataContext.getScopeGroupId());

    for (CalEvent event : events) {
      exportEvent(portletDataContext, rootElement, event);
    }

    return document.formattedString();
  }
Ejemplo n.º 24
0
  protected File doExportLayoutsAsFile(
      long groupId,
      boolean privateLayout,
      long[] layoutIds,
      Map<String, String[]> parameterMap,
      Date startDate,
      Date endDate)
      throws Exception {

    boolean exportCategories = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.CATEGORIES);
    boolean exportIgnoreLastPublishDate =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.IGNORE_LAST_PUBLISH_DATE);
    boolean exportPermissions =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PERMISSIONS);
    boolean exportPortletDataAll =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PORTLET_DATA_ALL);
    boolean exportTheme = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.THEME);
    boolean exportThemeSettings =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.THEME_REFERENCE);
    boolean exportLogo = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.LOGO);
    boolean exportLayoutSetSettings =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.LAYOUT_SET_SETTINGS);
    boolean updateLastPublishDate =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.UPDATE_LAST_PUBLISH_DATE);

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

    LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(groupId, privateLayout);

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

    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();

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

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

      ServiceContextThreadLocal.pushServiceContext(serviceContext);
    }

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

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

    serviceContext.setAttribute("layoutSetBranchId", layoutSetBranchId);

    long lastPublishDate = System.currentTimeMillis();

    if (endDate != null) {
      lastPublishDate = endDate.getTime();
    }

    if (exportIgnoreLastPublishDate) {
      endDate = null;
      startDate = null;
    }

    StopWatch stopWatch = null;

    if (_log.isInfoEnabled()) {
      stopWatch = new StopWatch();

      stopWatch.start();
    }

    LayoutCache layoutCache = new LayoutCache();

    ZipWriter zipWriter = ZipWriterFactoryUtil.getZipWriter();

    PortletDataContext portletDataContext =
        PortletDataContextFactoryUtil.createExportPortletDataContext(
            companyId, groupId, parameterMap, startDate, endDate, zipWriter);

    portletDataContext.setPortetDataContextListener(
        new PortletDataContextListenerImpl(portletDataContext));

    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(groupId));
    headerElement.addAttribute(
        "user-personal-site-group-id",
        String.valueOf(portletDataContext.getUserPersonalSiteGroupId()));
    headerElement.addAttribute("private-layout", String.valueOf(privateLayout));

    Group group = layoutSet.getGroup();

    String type = "layout-set";

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

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

      headerElement.addAttribute("type-uuid", layoutPrototype.getUuid());
    } else if (group.isLayoutSetPrototype()) {
      type = "layout-set-prototype";

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

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

    headerElement.addAttribute("type", type);

    if (exportTheme || exportThemeSettings) {
      headerElement.addAttribute("theme-id", layoutSet.getThemeId());
      headerElement.addAttribute("color-scheme-id", layoutSet.getColorSchemeId());
    }

    if (exportLogo) {
      Image image = ImageLocalServiceUtil.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());
      }
    }

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

      settingsElement.addCDATA(layoutSet.getSettings());
    }

    Element cssElement = headerElement.addElement("css");

    cssElement.addCDATA(layoutSet.getCss());

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

    List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(groupId, privateLayout);

    List<Portlet> portlets = getDataSiteLevelPortlets(companyId);

    long plid = LayoutConstants.DEFAULT_PLID;

    if (!layouts.isEmpty()) {
      Layout firstLayout = layouts.get(0);

      plid = firstLayout.getPlid();
    }

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

    for (Portlet portlet : portlets) {
      String portletId = portlet.getRootPortletId();

      if (!group.isStagedPortlet(portletId)) {
        continue;
      }

      String key = PortletPermissionUtil.getPrimaryKey(0, portletId);

      if (portletIds.get(key) == null) {
        portletIds.put(
            key, new Object[] {portletId, plid, groupId, StringPool.BLANK, StringPool.BLANK});
      }
    }

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

    portletDataContext.setMissingReferencesElement(missingReferencesElement);

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

    Element layoutsElement = portletDataContext.getExportDataGroupElement(Layout.class);

    String layoutSetPrototypeUuid = layoutSet.getLayoutSetPrototypeUuid();

    if (Validator.isNotNull(layoutSetPrototypeUuid)) {
      LayoutSetPrototype layoutSetPrototype =
          LayoutSetPrototypeLocalServiceUtil.getLayoutSetPrototypeByUuidAndCompanyId(
              layoutSetPrototypeUuid, companyId);

      layoutsElement.addAttribute("layout-set-prototype-uuid", layoutSetPrototypeUuid);

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

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

    long previousScopeGroupId = portletDataContext.getScopeGroupId();

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

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

      Object[] portletObjects = portletIdsEntry.getValue();

      String portletId = null;
      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 = LayoutLocalServiceUtil.fetchLayout(plid);

      if (layout == null) {
        if (!group.isCompany() && (plid <= LayoutConstants.DEFAULT_PLID)) {

          continue;
        }

        if (_log.isWarnEnabled()) {
          _log.warn("Assuming global scope because no layout was found");
        }

        layout = new LayoutImpl();

        layout.setGroupId(groupId);
        layout.setCompanyId(companyId);
      }

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

      boolean[] exportPortletControls =
          getExportPortletControls(companyId, portletId, parameterMap, type);

      _portletExporter.exportPortlet(
          portletDataContext,
          layoutCache,
          portletId,
          layout,
          portletsElement,
          defaultUserId,
          exportPermissions,
          exportPortletControls[0],
          exportPortletControls[1],
          exportPortletControls[2],
          exportPortletControls[3]);
    }

    portletDataContext.setScopeGroupId(previousScopeGroupId);

    exportAssetCategories(
        portletDataContext, exportPortletDataAll, exportCategories, group.isCompany());

    _portletExporter.exportAssetLinks(portletDataContext);
    _portletExporter.exportAssetTags(portletDataContext);
    _portletExporter.exportComments(portletDataContext);
    _portletExporter.exportExpandoTables(portletDataContext);
    _portletExporter.exportLocks(portletDataContext);

    _deletionSystemEventExporter.exportDeletionSystemEvents(portletDataContext);

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

    _portletExporter.exportRatingsEntries(portletDataContext, rootElement);

    if (exportTheme && !portletDataContext.isPerformDirectBinaryImport()) {
      exportTheme(layoutSet, zipWriter);
    }

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

    if (_log.isInfoEnabled()) {
      if (stopWatch != null) {
        _log.info("Exporting layouts takes " + stopWatch.getTime() + " ms");
      } else {
        _log.info("Exporting layouts is finished");
      }
    }

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

    try {
      return zipWriter.getFile();
    } finally {
      if (updateLastPublishDate) {
        updateLastPublishDate(layoutSet, lastPublishDate);
      }
    }
  }
  protected String getResults(HttpServletRequest request) throws Exception {

    String xml = StringUtil.read(request.getInputStream());

    String documentName = null;

    int beginPos = xml.lastIndexOf("<document>");
    int endPos = xml.lastIndexOf("</document>");

    if (beginPos != -1) {
      documentName = xml.substring(beginPos + 10, endPos);

      documentName = HttpUtil.decodeURL(documentName);
    }

    String path = documentName;

    int pos = documentName.lastIndexOf("sharepoint/");

    if (pos != -1) {
      path = path.substring(pos + 11);
    }

    Group group = GroupServiceUtil.getGroup(SharepointUtil.getGroupId(path));

    boolean minimal = false;

    beginPos = xml.lastIndexOf("<minimal>");
    endPos = xml.lastIndexOf("</minimal>");

    if (beginPos != -1) {
      minimal = GetterUtil.getBoolean(xml.substring(beginPos + 9, endPos));
    }

    Document doc = SAXReaderUtil.createDocument();

    Element root = doc.addElement("Results");

    String url = "http://" + request.getLocalAddr() + ":" + request.getServerPort() + "/sharepoint";

    root.addElement("SubscribeUrl").setText(url);
    root.addElement("MtgInstance");
    root.addElement("SettingUrl").setText(url);
    root.addElement("PermsUrl").setText(url);
    root.addElement("UserInfoUrl").setText(url);

    Element rolesEl = root.addElement("Roles");

    List<Role> roles = RoleLocalServiceUtil.getRoles(PortalUtil.getCompanyId(request));

    for (Role role : roles) {
      ResponseElement responseElement = new RoleResponseElement(role);

      responseElement.addElement(rolesEl);
    }

    if (!minimal) {
      Element schemaEl = root.addElement("Schema");

      schemaEl.addAttribute("Name", "Documents");
      schemaEl.addAttribute("Url", group.getName());

      Element fieldEl = schemaEl.addElement("Field");

      fieldEl.addAttribute("Name", "FileLeafRef");
      fieldEl.addAttribute("Required", "true");
      fieldEl.addAttribute("Type", "Invalid");

      fieldEl.addElement("Choices");

      fieldEl = schemaEl.addElement("Field");

      fieldEl.addAttribute("Name", "_SourceUrl");
      fieldEl.addAttribute("Required", "false");
      fieldEl.addAttribute("Type", "Text");

      fieldEl.addElement("Choices");

      fieldEl = schemaEl.addElement("Field");

      fieldEl.addAttribute("Name", "_SharedFileIndex");
      fieldEl.addAttribute("Required", "false");
      fieldEl.addAttribute("Type", "Text");

      fieldEl.addElement("Choices");

      fieldEl = schemaEl.addElement("Field");

      fieldEl.addAttribute("Name", "Order");
      fieldEl.addAttribute("Required", "false");
      fieldEl.addAttribute("Type", "Number");

      fieldEl.addElement("Choices");

      fieldEl = schemaEl.addElement("Field");

      fieldEl.addAttribute("Name", "Title");
      fieldEl.addAttribute("Required", "false");
      fieldEl.addAttribute("Type", "Text");

      fieldEl.addElement("Choices");

      Element listInfoEl = root.addElement("ListInfo");

      listInfoEl.addAttribute("Name", "Links");

      listInfoEl.addElement("Moderated").setText(String.valueOf(false));

      Element listPermissionsEl = listInfoEl.addElement("ListPermissions");

      listPermissionsEl.addElement("DeleteListItems");
      listPermissionsEl.addElement("EditListItems");
      listPermissionsEl.addElement("InsertListItems");
      listPermissionsEl.addElement("ManageRoles");
      listPermissionsEl.addElement("ManageWeb");
    }

    Element permissionsEl = root.addElement("Permissions");

    if (!minimal) {
      permissionsEl.addElement("DeleteListItems");
      permissionsEl.addElement("EditListItems");
      permissionsEl.addElement("InsertListItems");
      permissionsEl.addElement("ManageRoles");
      permissionsEl.addElement("ManageWeb");
    }

    root.addElement("HasUniquePerm").setText(String.valueOf(true));
    root.addElement("WorkspaceType").setText("DWS");
    root.addElement("IsADMode").setText(String.valueOf(false));
    root.addElement("DocUrl").setText(documentName);
    root.addElement("Minimal").setText(String.valueOf(true));

    Element resultsEl = root.addElement("Results");

    resultsEl.addElement("Title").setText(group.getName());
    resultsEl.addElement("LastUpdate");

    User user = (User) request.getSession().getAttribute(WebKeys.USER);

    ResponseElement responseElement = new MemberResponseElement(user, false);

    responseElement.addElement(resultsEl);

    Element membersEl = resultsEl.addElement("Members");

    List<User> users = UserLocalServiceUtil.getGroupUsers(group.getGroupId());

    for (User member : users) {
      responseElement = new MemberResponseElement(member, true);

      responseElement.addElement(membersEl);
    }

    if (!minimal) {
      Element assigneesEl = resultsEl.addElement("Assignees");

      for (User member : users) {
        responseElement = new MemberResponseElement(member, true);

        responseElement.addElement(assigneesEl);
      }

      Element listEl = resultsEl.addElement("List");

      listEl.addAttribute("Name", "Documents");

      listEl.addElement("ID");

      String parentFolderPath = path;

      pos = parentFolderPath.lastIndexOf("/");

      if (pos != -1) {
        parentFolderPath = parentFolderPath.substring(0, pos);
      }

      SharepointStorage storage = SharepointUtil.getStorage(parentFolderPath);

      SharepointRequest sharepointRequest = new SharepointRequest(parentFolderPath);

      storage.addDocumentElements(sharepointRequest, listEl);
    }

    return doc.asXML();
  }
Ejemplo n.º 26
0
  protected void exportPortlet(
      PortletDataContext portletDataContext,
      LayoutCache layoutCache,
      String portletId,
      Layout layout,
      Element parentElement,
      long defaultUserId,
      boolean exportPermissions,
      boolean exportPortletArchivedSetups,
      boolean exportPortletData,
      boolean exportPortletSetup,
      boolean exportPortletUserPreferences,
      boolean exportUserPermissions)
      throws Exception {

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

    if (portlet == null) {
      if (_log.isDebugEnabled()) {
        _log.debug("Do not export portlet " + portletId + " because the portlet does not exist");
      }

      return;
    }

    if ((!portlet.isInstanceable())
        && (!portlet.isPreferencesUniquePerLayout())
        && (portletDataContext.hasNotUniquePerLayout(portletId))) {

      return;
    }

    Document document = SAXReaderUtil.createDocument();

    Element portletElement = document.addElement("portlet");

    portletElement.addAttribute("portlet-id", portletId);
    portletElement.addAttribute("root-portlet-id", PortletConstants.getRootPortletId(portletId));
    portletElement.addAttribute("old-plid", String.valueOf(layout.getPlid()));
    portletElement.addAttribute("scope-layout-type", portletDataContext.getScopeType());
    portletElement.addAttribute("scope-layout-uuid", portletDataContext.getScopeLayoutUuid());

    // Data

    if (exportPortletData) {
      javax.portlet.PortletPreferences jxPreferences =
          PortletPreferencesFactoryUtil.getPortletSetup(layout, portletId, StringPool.BLANK);

      if (!portlet.isPreferencesUniquePerLayout()) {
        StringBundler sb = new StringBundler(5);

        sb.append(portletId);
        sb.append(StringPool.AT);
        sb.append(portletDataContext.getScopeType());
        sb.append(StringPool.AT);
        sb.append(portletDataContext.getScopeLayoutUuid());

        String dataKey = sb.toString();

        if (!portletDataContext.hasNotUniquePerLayout(dataKey)) {
          portletDataContext.putNotUniquePerLayout(dataKey);

          exportPortletData(portletDataContext, portlet, layout, jxPreferences, portletElement);
        }
      } else {
        exportPortletData(portletDataContext, portlet, layout, jxPreferences, portletElement);
      }
    }

    // Portlet preferences

    long plid = PortletKeys.PREFS_OWNER_ID_DEFAULT;

    if (layout != null) {
      plid = layout.getPlid();
    }

    if (exportPortletSetup) {
      exportPortletPreferences(
          portletDataContext,
          PortletKeys.PREFS_OWNER_ID_DEFAULT,
          PortletKeys.PREFS_OWNER_TYPE_LAYOUT,
          false,
          layout,
          plid,
          portletId,
          portletElement);

      exportPortletPreferences(
          portletDataContext,
          portletDataContext.getScopeGroupId(),
          PortletKeys.PREFS_OWNER_TYPE_GROUP,
          false,
          layout,
          plid,
          portletId,
          portletElement);

      exportPortletPreferences(
          portletDataContext,
          portletDataContext.getCompanyId(),
          PortletKeys.PREFS_OWNER_TYPE_COMPANY,
          false,
          layout,
          plid,
          portletId,
          portletElement);
    }

    // Portlet preferences

    if (exportPortletUserPreferences) {
      List<PortletPreferences> portletPreferencesList =
          PortletPreferencesLocalServiceUtil.getPortletPreferences(
              PortletKeys.PREFS_OWNER_TYPE_USER, plid, portletId);

      for (PortletPreferences portletPreferences : portletPreferencesList) {

        boolean defaultUser = false;

        if (portletPreferences.getOwnerId() == PortletKeys.PREFS_OWNER_ID_DEFAULT) {

          defaultUser = true;
        }

        exportPortletPreferences(
            portletDataContext,
            portletPreferences.getOwnerId(),
            PortletKeys.PREFS_OWNER_TYPE_USER,
            defaultUser,
            layout,
            plid,
            portletId,
            portletElement);
      }

      try {
        PortletPreferences groupPortletPreferences =
            PortletPreferencesLocalServiceUtil.getPortletPreferences(
                portletDataContext.getScopeGroupId(),
                PortletKeys.PREFS_OWNER_TYPE_GROUP,
                PortletKeys.PREFS_PLID_SHARED,
                portletId);

        exportPortletPreference(
            portletDataContext,
            portletDataContext.getScopeGroupId(),
            PortletKeys.PREFS_OWNER_TYPE_GROUP,
            false,
            groupPortletPreferences,
            portletId,
            PortletKeys.PREFS_PLID_SHARED,
            portletElement);
      } catch (NoSuchPortletPreferencesException nsppe) {
      }
    }

    // Archived setups

    if (exportPortletArchivedSetups) {
      String rootPortletId = PortletConstants.getRootPortletId(portletId);

      List<PortletItem> portletItems =
          PortletItemLocalServiceUtil.getPortletItems(
              portletDataContext.getGroupId(), rootPortletId, PortletPreferences.class.getName());

      for (PortletItem portletItem : portletItems) {
        exportPortletPreferences(
            portletDataContext,
            portletItem.getPortletItemId(),
            PortletKeys.PREFS_OWNER_TYPE_ARCHIVED,
            false,
            null,
            plid,
            portletItem.getPortletId(),
            portletElement);
      }
    }

    // Permissions

    if (exportPermissions) {
      _permissionExporter.exportPortletPermissions(
          portletDataContext, layoutCache, portletId, layout, portletElement);
    }

    // Zip

    StringBundler sb = new StringBundler(4);

    sb.append(portletDataContext.getPortletPath(portletId));
    sb.append(StringPool.SLASH);
    sb.append(layout.getPlid());
    sb.append("/portlet.xml");

    String path = sb.toString();

    Element element = parentElement.addElement("portlet");

    element.addAttribute("portlet-id", portletId);
    element.addAttribute("layout-id", String.valueOf(layout.getLayoutId()));
    element.addAttribute("path", path);

    if (portletDataContext.isPathNotProcessed(path)) {
      try {
        portletDataContext.addZipEntry(path, document.formattedString());
      } catch (IOException ioe) {
        if (_log.isWarnEnabled()) {
          _log.warn(ioe.getMessage());
        }
      }

      portletDataContext.addPrimaryKey(String.class, path);
    }
  }
Ejemplo n.º 27
0
  protected File doExportLayoutsAsFile(
      long groupId,
      boolean privateLayout,
      long[] layoutIds,
      Map<String, String[]> parameterMap,
      Date startDate,
      Date endDate)
      throws Exception {

    boolean exportCategories = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.CATEGORIES);
    boolean exportIgnoreLastPublishDate =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.IGNORE_LAST_PUBLISH_DATE);
    boolean exportPermissions =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PERMISSIONS);
    boolean exportUserPermissions =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.USER_PERMISSIONS);
    boolean exportPortletArchivedSetups =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PORTLET_ARCHIVED_SETUPS);
    boolean exportPortletUserPreferences =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PORTLET_USER_PREFERENCES);
    boolean exportTheme = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.THEME);
    boolean exportThemeSettings =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.THEME_REFERENCE);
    boolean exportLogo = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.LOGO);
    boolean exportLayoutSetSettings =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.LAYOUT_SET_SETTINGS);
    boolean publishToRemote =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PUBLISH_TO_REMOTE);
    boolean updateLastPublishDate =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.UPDATE_LAST_PUBLISH_DATE);

    if (_log.isDebugEnabled()) {
      _log.debug("Export categories " + exportCategories);
      _log.debug("Export permissions " + exportPermissions);
      _log.debug("Export user permissions " + exportUserPermissions);
      _log.debug("Export portlet archived setups " + exportPortletArchivedSetups);
      _log.debug("Export portlet user preferences " + exportPortletUserPreferences);
      _log.debug("Export theme " + exportTheme);
    }

    LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(groupId, privateLayout);

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

    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();

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

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

      ServiceContextThreadLocal.pushServiceContext(serviceContext);
    }

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

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

    serviceContext.setAttribute("layoutSetBranchId", layoutSetBranchId);

    long lastPublishDate = System.currentTimeMillis();

    if (endDate != null) {
      lastPublishDate = endDate.getTime();
    }

    if (exportIgnoreLastPublishDate) {
      endDate = null;
      startDate = null;
    }

    StopWatch stopWatch = null;

    if (_log.isInfoEnabled()) {
      stopWatch = new StopWatch();

      stopWatch.start();
    }

    LayoutCache layoutCache = new LayoutCache();

    ZipWriter zipWriter = ZipWriterFactoryUtil.getZipWriter();

    PortletDataContext portletDataContext =
        new PortletDataContextImpl(
            companyId, groupId, parameterMap, new HashSet<String>(), startDate, endDate, zipWriter);

    portletDataContext.setPortetDataContextListener(
        new PortletDataContextListenerImpl(portletDataContext));

    Document document = SAXReaderUtil.createDocument();

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

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

    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("group-id", String.valueOf(groupId));
    headerElement.addAttribute("private-layout", String.valueOf(privateLayout));

    Group group = layoutSet.getGroup();

    String type = "layout-set";

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

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

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

    headerElement.addAttribute("type", type);

    if (exportTheme || exportThemeSettings) {
      headerElement.addAttribute("theme-id", layoutSet.getThemeId());
      headerElement.addAttribute("color-scheme-id", layoutSet.getColorSchemeId());
    }

    if (exportLogo) {
      Image image = ImageLocalServiceUtil.getImage(layoutSet.getLogoId());

      if (image != null) {
        String logoPath = getLayoutSetLogoPath(portletDataContext);

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

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

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

      settingsElement.addCDATA(layoutSet.getSettings());
    }

    Element cssElement = headerElement.addElement("css");

    cssElement.addCDATA(layoutSet.getCss());

    Portlet layoutConfigurationPortlet =
        PortletLocalServiceUtil.getPortletById(
            portletDataContext.getCompanyId(), PortletKeys.LAYOUT_CONFIGURATION);

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

    List<Layout> layouts = null;

    if ((layoutIds == null) || (layoutIds.length == 0)) {
      layouts = LayoutLocalServiceUtil.getLayouts(groupId, privateLayout);
    } else {
      layouts = LayoutLocalServiceUtil.getLayouts(groupId, privateLayout, layoutIds);
    }

    List<Portlet> portlets = getAlwaysExportablePortlets(companyId);

    if (!layouts.isEmpty()) {
      Layout firstLayout = layouts.get(0);

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

      for (Portlet portlet : portlets) {
        String portletId = portlet.getRootPortletId();

        if (!group.isStagedPortlet(portletId)) {
          continue;
        }

        String key = PortletPermissionUtil.getPrimaryKey(0, portletId);

        if (portletIds.get(key) == null) {
          portletIds.put(
              key,
              new Object[] {
                portletId, firstLayout.getPlid(), groupId, StringPool.BLANK, StringPool.BLANK
              });
        }
      }
    }

    Element layoutsElement = rootElement.addElement("layouts");

    String layoutSetPrototypeUuid = layoutSet.getLayoutSetPrototypeUuid();

    if (Validator.isNotNull(layoutSetPrototypeUuid)) {
      LayoutSetPrototype layoutSetPrototype =
          LayoutSetPrototypeLocalServiceUtil.getLayoutSetPrototypeByUuid(layoutSetPrototypeUuid);

      layoutsElement.addAttribute("layout-set-prototype-uuid", layoutSetPrototypeUuid);

      if (publishToRemote) {
        String path = getLayoutSetPrototype(portletDataContext, layoutSetPrototypeUuid);

        File layoutSetPrototypeFile = null;

        InputStream inputStream = null;

        try {
          layoutSetPrototypeFile =
              SitesUtil.exportLayoutSetPrototype(layoutSetPrototype, serviceContext);

          inputStream = new FileInputStream(layoutSetPrototypeFile);

          portletDataContext.addZipEntry(path.concat(".lar"), inputStream);
          portletDataContext.addZipEntry(path.concat(".xml"), layoutSetPrototype);
        } finally {
          StreamUtil.cleanUp(inputStream);

          FileUtil.delete(layoutSetPrototypeFile);
        }
      }
    }

    for (Layout layout : layouts) {
      exportLayout(
          portletDataContext,
          layoutConfigurationPortlet,
          layoutCache,
          portlets,
          portletIds,
          exportPermissions,
          exportUserPermissions,
          layout,
          layoutsElement);
    }

    if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM < 5) {
      Element rolesElement = rootElement.addElement("roles");

      if (exportPermissions) {
        _permissionExporter.exportLayoutRoles(layoutCache, companyId, groupId, rolesElement);
      }
    }

    long previousScopeGroupId = portletDataContext.getScopeGroupId();

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

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

      Object[] portletObjects = portletIdsEntry.getValue();

      String portletId = null;
      long plid = 0;
      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 = LayoutLocalServiceUtil.getLayout(plid);

      portletDataContext.setPlid(layout.getPlid());
      portletDataContext.setOldPlid(layout.getPlid());
      portletDataContext.setScopeGroupId(scopeGroupId);
      portletDataContext.setScopeType(scopeType);
      portletDataContext.setScopeLayoutUuid(scopeLayoutUuid);

      boolean[] exportPortletControls =
          getExportPortletControls(companyId, portletId, portletDataContext, parameterMap);

      _portletExporter.exportPortlet(
          portletDataContext,
          layoutCache,
          portletId,
          layout,
          portletsElement,
          defaultUserId,
          exportPermissions,
          exportPortletArchivedSetups,
          exportPortletControls[0],
          exportPortletControls[1],
          exportPortletUserPreferences,
          exportUserPermissions);
    }

    portletDataContext.setScopeGroupId(previousScopeGroupId);

    if (exportCategories) {
      exportAssetCategories(portletDataContext);
    }

    _portletExporter.exportAssetLinks(portletDataContext);
    _portletExporter.exportAssetTags(portletDataContext);
    _portletExporter.exportComments(portletDataContext);
    _portletExporter.exportExpandoTables(portletDataContext);
    _portletExporter.exportLocks(portletDataContext);

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

    _portletExporter.exportRatingsEntries(portletDataContext, rootElement);

    if (exportTheme && !portletDataContext.isPerformDirectBinaryImport()) {
      exportTheme(layoutSet, zipWriter);
    }

    if (_log.isInfoEnabled()) {
      if (stopWatch != null) {
        _log.info("Exporting layouts takes " + stopWatch.getTime() + " ms");
      } else {
        _log.info("Exporting layouts is finished");
      }
    }

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

    try {
      return zipWriter.getFile();
    } finally {
      if (updateLastPublishDate) {
        updateLastPublishDate(layoutSet, lastPublishDate);
      }
    }
  }
  protected void exportPortlet(
      PortletDataContext portletDataContext,
      Layout layout,
      Element parentElement,
      boolean exportPermissions,
      boolean exportPortletArchivedSetups,
      boolean exportPortletData,
      boolean exportPortletSetup,
      boolean exportPortletUserPreferences)
      throws Exception {

    long plid = PortletKeys.PREFS_OWNER_ID_DEFAULT;
    long layoutId = LayoutConstants.DEFAULT_PARENT_LAYOUT_ID;

    if (layout != null) {
      plid = layout.getPlid();
      layoutId = layout.getLayoutId();
    }

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

    if ((portlet == null) || portlet.isUndeployedPortlet()) {
      if (_log.isDebugEnabled()) {
        _log.debug(
            "Do not export portlet "
                + portletDataContext.getPortletId()
                + " because the portlet is not deployed");
      }

      return;
    }

    if (!portlet.isInstanceable()
        && !portlet.isPreferencesUniquePerLayout()
        && portletDataContext.hasNotUniquePerLayout(portletDataContext.getPortletId())) {

      return;
    }

    if (BackgroundTaskThreadLocal.hasBackgroundTask()) {
      PortletDataContext clonedPortletDataContext =
          PortletDataContextFactoryUtil.clonePortletDataContext(portletDataContext);

      ManifestSummary manifestSummary = clonedPortletDataContext.getManifestSummary();

      manifestSummary.resetCounters();

      PortletDataHandler portletDataHandler = portlet.getPortletDataHandlerInstance();

      portletDataHandler.prepareManifestSummary(clonedPortletDataContext);

      PortletDataHandlerStatusMessageSenderUtil.sendStatusMessage(
          "portlet", portletDataContext.getPortletId(), manifestSummary);
    }

    Document document = SAXReaderUtil.createDocument();

    Element portletElement = document.addElement("portlet");

    portletElement.addAttribute("portlet-id", portletDataContext.getPortletId());
    portletElement.addAttribute("root-portlet-id", portletDataContext.getRootPortletId());
    portletElement.addAttribute("old-plid", String.valueOf(plid));
    portletElement.addAttribute(
        "scope-group-id", String.valueOf(portletDataContext.getScopeGroupId()));
    portletElement.addAttribute("scope-layout-type", portletDataContext.getScopeType());
    portletElement.addAttribute("scope-layout-uuid", portletDataContext.getScopeLayoutUuid());
    portletElement.addAttribute("private-layout", String.valueOf(layout.isPrivateLayout()));

    // Data

    if (exportPortletData) {
      javax.portlet.PortletPreferences jxPortletPreferences = null;

      if (ExportImportThreadLocal.isInitialLayoutStagingInProcess()) {
        Group liveGroup = layout.getGroup();

        Group stagingGroup = liveGroup.getStagingGroup();

        layout.setGroupId(stagingGroup.getGroupId());

        jxPortletPreferences =
            PortletPreferencesFactoryUtil.getStrictPortletSetup(
                layout, portletDataContext.getPortletId());

        layout.setGroupId(liveGroup.getGroupId());
      } else {
        jxPortletPreferences =
            PortletPreferencesFactoryUtil.getStrictPortletSetup(
                layout, portletDataContext.getPortletId());
      }

      if (!portlet.isPreferencesUniquePerLayout()) {
        StringBundler sb = new StringBundler(5);

        sb.append(portletDataContext.getPortletId());
        sb.append(StringPool.AT);
        sb.append(portletDataContext.getScopeType());
        sb.append(StringPool.AT);
        sb.append(portletDataContext.getScopeLayoutUuid());

        String dataKey = sb.toString();

        if (!portletDataContext.hasNotUniquePerLayout(dataKey)) {
          portletDataContext.putNotUniquePerLayout(dataKey);

          exportPortletData(
              portletDataContext, portlet, layout, jxPortletPreferences, portletElement);
        }
      } else {
        exportPortletData(
            portletDataContext, portlet, layout, jxPortletPreferences, portletElement);
      }
    }

    // Portlet preferences

    if (exportPortletSetup) {

      // Company

      exportPortletPreferences(
          portletDataContext,
          portletDataContext.getCompanyId(),
          PortletKeys.PREFS_OWNER_TYPE_COMPANY,
          false,
          layout,
          plid,
          portlet.getRootPortletId(),
          portletElement);

      // Group

      exportPortletPreferences(
          portletDataContext,
          portletDataContext.getScopeGroupId(),
          PortletKeys.PREFS_OWNER_TYPE_GROUP,
          false,
          layout,
          PortletKeys.PREFS_PLID_SHARED,
          portlet.getRootPortletId(),
          portletElement);

      // Layout

      exportPortletPreferences(
          portletDataContext,
          PortletKeys.PREFS_OWNER_ID_DEFAULT,
          PortletKeys.PREFS_OWNER_TYPE_LAYOUT,
          false,
          layout,
          plid,
          portletDataContext.getPortletId(),
          portletElement);
    }

    // Portlet user preferences

    if (exportPortletUserPreferences) {
      List<PortletPreferences> portletPreferencesList =
          _portletPreferencesLocalService.getPortletPreferences(
              PortletKeys.PREFS_OWNER_TYPE_USER, plid, portletDataContext.getPortletId());

      for (PortletPreferences portletPreferences : portletPreferencesList) {

        boolean defaultUser = false;

        if (portletPreferences.getOwnerId() == PortletKeys.PREFS_OWNER_ID_DEFAULT) {

          defaultUser = true;
        }

        exportPortletPreferences(
            portletDataContext,
            portletPreferences.getOwnerId(),
            PortletKeys.PREFS_OWNER_TYPE_USER,
            defaultUser,
            layout,
            plid,
            portletDataContext.getPortletId(),
            portletElement);
      }

      try {
        PortletPreferences groupPortletPreferences =
            _portletPreferencesLocalService.getPortletPreferences(
                portletDataContext.getScopeGroupId(),
                PortletKeys.PREFS_OWNER_TYPE_GROUP,
                PortletKeys.PREFS_PLID_SHARED,
                portlet.getRootPortletId());

        exportPortletPreference(
            portletDataContext,
            portletDataContext.getScopeGroupId(),
            PortletKeys.PREFS_OWNER_TYPE_GROUP,
            false,
            groupPortletPreferences,
            portlet.getRootPortletId(),
            PortletKeys.PREFS_PLID_SHARED,
            portletElement);
      } catch (NoSuchPortletPreferencesException nsppe) {
      }
    }

    // Archived setups

    if (exportPortletArchivedSetups) {
      List<PortletItem> portletItems =
          _portletItemLocalService.getPortletItems(
              portletDataContext.getGroupId(),
              portletDataContext.getRootPortletId(),
              PortletPreferences.class.getName());

      for (PortletItem portletItem : portletItems) {
        exportPortletPreferences(
            portletDataContext,
            portletItem.getPortletItemId(),
            PortletKeys.PREFS_OWNER_TYPE_ARCHIVED,
            false,
            null,
            plid,
            portletItem.getPortletId(),
            portletElement);
      }
    }

    // Permissions

    if (exportPermissions) {
      _permissionExporter.exportPortletPermissions(
          portletDataContext, portletDataContext.getPortletId(), layout, portletElement);
    }

    // Zip

    StringBundler pathSB = new StringBundler(4);

    pathSB.append(ExportImportPathUtil.getPortletPath(portletDataContext));
    pathSB.append(StringPool.SLASH);
    pathSB.append(plid);
    pathSB.append("/portlet.xml");

    String path = pathSB.toString();

    Element element = parentElement.addElement("portlet");

    element.addAttribute("portlet-id", portletDataContext.getPortletId());
    element.addAttribute("layout-id", String.valueOf(layoutId));
    element.addAttribute("path", path);
    element.addAttribute("portlet-data", String.valueOf(exportPortletData));

    PortletDataHandler portletDataHandler = portlet.getPortletDataHandlerInstance();

    element.addAttribute("schema-version", portletDataHandler.getSchemaVersion());

    StringBundler configurationOptionsSB = new StringBundler(6);

    if (exportPortletSetup) {
      configurationOptionsSB.append("setup");
      configurationOptionsSB.append(StringPool.COMMA);
    }

    if (exportPortletArchivedSetups) {
      configurationOptionsSB.append("archived-setups");
      configurationOptionsSB.append(StringPool.COMMA);
    }

    if (exportPortletUserPreferences) {
      configurationOptionsSB.append("user-preferences");
      configurationOptionsSB.append(StringPool.COMMA);
    }

    if (configurationOptionsSB.index() > 0) {
      configurationOptionsSB.setIndex(configurationOptionsSB.index() - 1);
    }

    element.addAttribute("portlet-configuration", configurationOptionsSB.toString());

    try {
      portletDataContext.addZipEntry(path, document.formattedString());
    } catch (IOException ioe) {
      if (_log.isWarnEnabled()) {
        _log.warn(ioe.getMessage());
      }
    }
  }
  protected String doExportData(
      PortletDataContext context, String portletId, PortletPreferences preferences)
      throws Exception {

    context.addPermissions("com.liferay.portlet.journal", context.getScopeGroupId());

    String articleId = preferences.getValue("article-id", null);

    if (articleId == null) {
      if (_log.isWarnEnabled()) {
        _log.warn("No article id found in preferences of portlet " + portletId);
      }

      return StringPool.BLANK;
    }

    long articleGroupId = GetterUtil.getLong(preferences.getValue("group-id", StringPool.BLANK));

    if (articleGroupId <= 0) {
      if (_log.isWarnEnabled()) {
        _log.warn("No group id found in preferences of portlet " + portletId);
      }

      return StringPool.BLANK;
    }

    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 StringPool.BLANK;
    }

    Document document = SAXReaderUtil.createDocument();

    Element rootElement = document.addElement("journal-content-data");

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

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

    articleElement.addAttribute("path", path);

    Element dlFoldersElement = rootElement.addElement("dl-folders");
    Element dlFilesElement = rootElement.addElement("dl-file-entries");
    Element dlFileRanksElement = rootElement.addElement("dl-file-ranks");
    Element igFoldersElement = rootElement.addElement("ig-folders");
    Element igImagesElement = rootElement.addElement("ig-images");

    JournalPortletDataHandlerImpl.exportArticle(
        context,
        rootElement,
        dlFoldersElement,
        dlFilesElement,
        dlFileRanksElement,
        igFoldersElement,
        igImagesElement,
        article,
        false);

    String structureId = article.getStructureId();

    if (Validator.isNotNull(structureId)) {
      JournalStructure structure =
          JournalStructureUtil.findByG_S(article.getGroupId(), structureId);

      JournalPortletDataHandlerImpl.exportStructure(context, rootElement, structure);
    }

    String templateId = article.getTemplateId();

    if (Validator.isNotNull(templateId)) {
      JournalTemplate template = JournalTemplateUtil.findByG_T(article.getGroupId(), templateId);

      JournalPortletDataHandlerImpl.exportTemplate(
          context,
          rootElement,
          dlFoldersElement,
          dlFilesElement,
          dlFileRanksElement,
          igFoldersElement,
          igImagesElement,
          template);
    }

    return document.formattedString();
  }
  protected File doExport(PortletDataContext portletDataContext) throws Exception {

    boolean exportPermissions =
        MapUtil.getBoolean(
            portletDataContext.getParameterMap(), PortletDataHandlerKeys.PERMISSIONS);

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

    StopWatch stopWatch = new StopWatch();

    stopWatch.start();

    Layout layout = _layoutLocalService.getLayout(portletDataContext.getPlid());

    if (!layout.isTypeControlPanel() && !layout.isTypePanel() && !layout.isTypePortlet()) {

      throw new LayoutImportException("Layout type " + layout.getType() + " is not valid");
    }

    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();

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

      serviceContext.setCompanyId(layout.getCompanyId());
      serviceContext.setSignedIn(false);

      long defaultUserId = _userLocalService.getDefaultUserId(layout.getCompanyId());

      serviceContext.setUserId(defaultUserId);

      ServiceContextThreadLocal.pushServiceContext(serviceContext);
    }

    long layoutSetBranchId =
        MapUtil.getLong(portletDataContext.getParameterMap(), "layoutSetBranchId");

    serviceContext.setAttribute("layoutSetBranchId", layoutSetBranchId);

    long scopeGroupId = portletDataContext.getGroupId();

    javax.portlet.PortletPreferences jxPortletPreferences =
        PortletPreferencesFactoryUtil.getLayoutPortletSetup(
            layout, portletDataContext.getPortletId());

    String scopeType = GetterUtil.getString(jxPortletPreferences.getValue("lfrScopeType", null));
    String scopeLayoutUuid =
        GetterUtil.getString(jxPortletPreferences.getValue("lfrScopeLayoutUuid", null));

    if (Validator.isNotNull(scopeType)) {
      Group scopeGroup = null;

      if (scopeType.equals("company")) {
        scopeGroup = _groupLocalService.getCompanyGroup(layout.getCompanyId());
      } else if (Validator.isNotNull(scopeLayoutUuid)) {
        scopeGroup = layout.getScopeGroup();
      }

      if (scopeGroup != null) {
        scopeGroupId = scopeGroup.getGroupId();
      }
    }

    portletDataContext.setScopeType(scopeType);
    portletDataContext.setScopeLayoutUuid(scopeLayoutUuid);

    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(
                PortalUtil.getSiteGroupId(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("type", "portlet");
    headerElement.addAttribute("company-id", String.valueOf(portletDataContext.getCompanyId()));
    headerElement.addAttribute(
        "company-group-id", String.valueOf(portletDataContext.getCompanyGroupId()));
    headerElement.addAttribute("group-id", String.valueOf(scopeGroupId));
    headerElement.addAttribute(
        "user-personal-site-group-id",
        String.valueOf(portletDataContext.getUserPersonalSiteGroupId()));
    headerElement.addAttribute("private-layout", String.valueOf(layout.isPrivateLayout()));
    headerElement.addAttribute("root-portlet-id", portletDataContext.getRootPortletId());

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

    portletDataContext.setMissingReferencesElement(missingReferencesElement);

    Map<String, Boolean> exportPortletControlsMap =
        ExportImportHelperUtil.getExportPortletControlsMap(
            layout.getCompanyId(),
            portletDataContext.getPortletId(),
            portletDataContext.getParameterMap());

    exportPortlet(
        portletDataContext,
        layout,
        rootElement,
        exportPermissions,
        exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_ARCHIVED_SETUPS),
        exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_DATA),
        exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_SETUP),
        exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_USER_PREFERENCES));
    exportService(
        portletDataContext,
        rootElement,
        exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_SETUP));

    exportAssetLinks(portletDataContext);
    exportExpandoTables(portletDataContext);
    exportLocks(portletDataContext);

    _deletionSystemEventExporter.exportDeletionSystemEvents(portletDataContext);

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

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

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

    try {
      portletDataContext.addZipEntry("/manifest.xml", document.formattedString());
    } catch (IOException ioe) {
      throw new SystemException(ioe);
    }

    ZipWriter zipWriter = portletDataContext.getZipWriter();

    return zipWriter.getFile();
  }