protected void updateLayoutSetPrototype(long groupId, boolean privateLayout)
      throws PortalException {

    // Layout

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

    LayoutSetPrototype layoutSetPrototype =
        LayoutSetPrototypeLocalServiceUtil.getLayoutSetPrototype(
            layoutSet.getLayoutSetPrototypeId());

    Group layoutSetPrototypeGroup = layoutSetPrototype.getGroup();

    List<Layout> layoutSetPrototypeLayouts =
        LayoutLocalServiceUtil.getLayouts(layoutSetPrototypeGroup.getGroupId(), true);

    String[] layoutSetPrototypeLayoutUuids = new String[layoutSetPrototypeLayouts.size()];

    for (int i = 0; i < layoutSetPrototypeLayouts.size(); i++) {
      Layout layout = layoutSetPrototypeLayouts.get(i);

      layoutSetPrototypeLayoutUuids[i] = layout.getUuid();
    }

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

    for (Layout layout : layouts) {
      if (ArrayUtil.contains(
          layoutSetPrototypeLayoutUuids, layout.getSourcePrototypeLayoutUuid())) {

        layout.setLayoutPrototypeUuid(StringPool.BLANK);
        layout.setLayoutPrototypeLinkEnabled(false);
        layout.setSourcePrototypeLayoutUuid(StringPool.BLANK);

        LayoutLocalServiceUtil.updateLayout(layout);
      }
    }

    // Layout set

    UnicodeProperties settingsProperties = layoutSet.getSettingsProperties();

    settingsProperties.remove("last-merge-time");

    layoutSet.setSettingsProperties(settingsProperties);

    layoutSet.setLayoutSetPrototypeUuid(StringPool.BLANK);
    layoutSet.setLayoutSetPrototypeLinkEnabled(false);

    LayoutSetLocalServiceUtil.updateLayoutSet(layoutSet);

    LayoutSetLocalServiceUtil.updateLookAndFeel(
        layoutSet.getGroupId(), null, null, StringPool.BLANK, false);
  }
Ejemplo n.º 2
0
  protected List<Layout> addUserGroupLayouts(
      Group group, LayoutSet layoutSet, List<Layout> layouts, long parentLayoutId)
      throws Exception {

    layouts = ListUtil.copy(layouts);

    List<UserGroup> userUserGroups =
        UserGroupLocalServiceUtil.getUserUserGroups(group.getClassPK());

    for (UserGroup userGroup : userUserGroups) {
      Group userGroupGroup = userGroup.getGroup();

      List<Layout> userGroupLayouts =
          LayoutLocalServiceUtil.getLayouts(
              userGroupGroup.getGroupId(), layoutSet.isPrivateLayout(), parentLayoutId);

      for (Layout userGroupLayout : userGroupLayouts) {
        Layout virtualLayout = new VirtualLayout(userGroupLayout, group);

        layouts.add(virtualLayout);
      }
    }

    return layouts;
  }
  protected List<Layout> getCandidateLayouts(long plid, boolean privateLayout, KBArticle kbArticle)
      throws Exception {

    List<Layout> candidateLayouts = new ArrayList<>();

    Group group = GroupLocalServiceUtil.getGroup(kbArticle.getGroupId());

    if (group.isLayout()) {
      Layout layout = LayoutLocalServiceUtil.getLayout(group.getClassPK());

      candidateLayouts.add(layout);

      group = layout.getGroup();
    }

    List<Layout> layouts =
        LayoutLocalServiceUtil.getLayouts(
            group.getGroupId(), privateLayout, LayoutConstants.TYPE_PORTLET);

    candidateLayouts.addAll(layouts);

    Layout layout = LayoutLocalServiceUtil.getLayout(plid);

    if ((layout.getGroupId() == kbArticle.getGroupId()) && layout.isTypePortlet()) {

      candidateLayouts.remove(layout);
      candidateLayouts.add(0, layout);
    }

    return candidateLayouts;
  }
Ejemplo n.º 4
0
  protected Layout getPortalPageLayout(long userId, long groupId, String portalPageName)
      throws Exception {
    Layout portalPageLayout = null;
    boolean privateLayout = true;
    List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(groupId, privateLayout);

    for (Layout layout : layouts) {

      if (layout.getName(Locale.US).equals(portalPageName)) {
        portalPageLayout = layout;
      }
    }

    if (portalPageLayout == null) {
      long parentLayoutId = LayoutConstants.DEFAULT_PARENT_LAYOUT_ID;
      String type = LayoutConstants.TYPE_PORTLET;
      boolean hidden = false;
      String friendlyURL = "/" + portalPageName.toLowerCase();
      portalPageLayout =
          ServiceUtil.addLayout(
              userId,
              groupId,
              privateLayout,
              parentLayoutId,
              portalPageName,
              portalPageName,
              portalPageName,
              type,
              hidden,
              friendlyURL);
    }

    return portalPageLayout;
  }
  protected void exportImportLayouts(boolean privateLayout) throws Exception {
    List<Layout> layouts =
        LayoutLocalServiceUtil.getLayouts(_stagingGroup.getGroupId(), privateLayout);

    User user = TestPropsValues.getUser();

    Map<String, Serializable> publishLayoutLocalSettingsMap =
        ExportImportConfigurationSettingsMapFactory.buildPublishLayoutLocalSettingsMap(
            user,
            _stagingGroup.getGroupId(),
            _liveGroup.getGroupId(),
            privateLayout,
            ExportImportHelperUtil.getLayoutIds(layouts),
            new HashMap<String, String[]>());

    ExportImportConfiguration exportImportConfiguration =
        ExportImportConfigurationLocalServiceUtil.addDraftExportImportConfiguration(
            user.getUserId(),
            ExportImportConfigurationConstants.TYPE_PUBLISH_LAYOUT_LOCAL,
            publishLayoutLocalSettingsMap);

    File larFile = ExportImportLocalServiceUtil.exportLayoutsAsFile(exportImportConfiguration);

    ExportImportLocalServiceUtil.importLayouts(exportImportConfiguration, larFile);
  }
  @Override
  protected StagedModel addStagedModel(
      Group group, Map<String, List<StagedModel>> dependentStagedModelsMap) throws Exception {

    _layoutSetPrototype = LayoutTestUtil.addLayoutSetPrototype(RandomTestUtil.randomString());

    List<Layout> layouts =
        LayoutLocalServiceUtil.getLayouts(
            _layoutSetPrototype.getGroupId(), true, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);

    Assert.assertEquals(1, layouts.size());

    Layout layout = layouts.get(0);

    addLayout(LayoutSetPrototype.class, layout);
    addLayoutFriendlyURLs(LayoutSetPrototype.class, layout.getPlid());

    LayoutPrototype layoutPrototype = addLayoutPrototype(dependentStagedModelsMap);

    Layout prototypedLayout =
        LayoutTestUtil.addLayout(_layoutSetPrototype.getGroupId(), true, layoutPrototype, true);

    addLayout(LayoutSetPrototype.class, prototypedLayout);
    addLayoutFriendlyURLs(LayoutSetPrototype.class, prototypedLayout.getPlid());

    return _layoutSetPrototype;
  }
Ejemplo n.º 7
0
  private LiferayPortletURL createLiferayPortletURL(
      PortletRequest request, String toPage, String portletId) {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    //		String portletId = (String) request.getAttribute(WebKeys.PORTLET_ID);
    LiferayPortletURL renderURL = null;
    String localHost = themeDisplay.getPortalURL();
    List<Layout> layouts = null;
    try {
      layouts = LayoutLocalServiceUtil.getLayouts(themeDisplay.getLayout().getGroupId(), false);

      for (Layout layout : layouts) {

        String nodeNameRemoved =
            PortalUtil.getLayoutFriendlyURL(layout, themeDisplay).replace(localHost, "");

        // Viene ricercato l'URL esatto per la pagina successiva
        if (nodeNameRemoved.indexOf(toPage) > 0) {

          renderURL =
              PortletURLFactoryUtil.create(
                  request, portletId, layout.getPlid(), PortletRequest.RENDER_PHASE);
          renderURL.setWindowState(WindowState.NORMAL);
          renderURL.setPortletMode(PortletMode.VIEW);

          break;
        }
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
    return renderURL;
  }
  private void _getFolders(CommandArgument commandArgument, Document document, Node rootNode)
      throws Exception {

    Element foldersElement = document.createElement("Folders");

    rootNode.appendChild(foldersElement);

    if (commandArgument.getCurrentFolder().equals(StringPool.SLASH)) {
      getRootFolders(commandArgument, document, foldersElement);
    } else {
      Group group = commandArgument.getCurrentGroup();

      List<Layout> layouts =
          LayoutLocalServiceUtil.getLayouts(
              group.getGroupId(), false, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);

      if (("/" + commandArgument.getCurrentGroupName() + "/")
          .equals(commandArgument.getCurrentFolder())) {

        for (Layout layout : layouts) {
          Element folderElement = document.createElement("Folder");

          foldersElement.appendChild(folderElement);

          folderElement.setAttribute("name", "~" + _getLayoutName(layout).replace('/', '>'));
        }
      } else {
        String layoutName = _getLayoutName(commandArgument.getCurrentFolder());

        Layout layout = null;

        for (int i = 0; i < layouts.size(); i++) {
          layout = _getLayout(layoutName, layouts.get(i));

          if (layout != null) {
            break;
          }
        }

        if (layout != null) {
          List<Layout> layoutChildren = layout.getChildren();

          for (int i = 0; i < layoutChildren.size(); i++) {
            layout = layoutChildren.get(i);

            Element folderElement = document.createElement("Folder");

            foldersElement.appendChild(folderElement);

            folderElement.setAttribute("name", "~" + _getLayoutName(layout).replace('/', '>'));
          }
        }
      }
    }
  }
  protected void addLayoutIds(
      List<Long> layoutIds, long groupId, boolean privateLayout, long layoutId) throws Exception {

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

    for (Layout layout : layouts) {
      layoutIds.add(layout.getLayoutId());

      addLayoutIds(layoutIds, layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId());
    }
  }
Ejemplo n.º 10
0
  public static List<Layout> getLayouts(
      HttpServletRequest request, long groupId, boolean privateLayout, long parentLayoutId)
      throws Exception {

    boolean incomplete = ParamUtil.getBoolean(request, "incomplete", true);
    int start = ParamUtil.getInteger(request, "start");
    int end = start + PropsValues.LAYOUT_MANAGE_PAGES_INITIAL_CHILDREN;

    return LayoutLocalServiceUtil.getLayouts(
        groupId, privateLayout, parentLayoutId, incomplete, start, end);
  }
  @Test
  public void testExportImportLayoutsPriorities() throws Exception {
    Layout layout1 = LayoutTestUtil.addLayout(group);
    Layout layout2 = LayoutTestUtil.addLayout(group);
    Layout layout3 = LayoutTestUtil.addLayout(group);

    int priority = layout1.getPriority();

    layout1.setPriority(layout3.getPriority());
    layout3.setPriority(priority);

    layout1 = LayoutLocalServiceUtil.updateLayout(layout1);
    layout3 = LayoutLocalServiceUtil.updateLayout(layout3);

    long[] layoutIds = new long[] {layout1.getLayoutId(), layout2.getLayoutId()};

    exportImportLayouts(layoutIds, getImportParameterMap());

    Layout importedLayout1 =
        LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(
            layout1.getUuid(), importedGroup.getGroupId(), false);

    Assert.assertNotEquals(layout1.getPriority(), importedLayout1.getPriority());

    Layout importedLayout2 =
        LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(
            layout2.getUuid(), importedGroup.getGroupId(), false);

    Assert.assertNotEquals(layout2.getPriority(), importedLayout2.getPriority());

    List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(group.getGroupId(), false);

    layoutIds = ExportImportHelperUtil.getLayoutIds(layouts);

    exportImportLayouts(layoutIds, getImportParameterMap());

    importedLayout1 =
        LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(
            layout1.getUuid(), importedGroup.getGroupId(), false);

    Assert.assertEquals(layout1.getPriority(), importedLayout1.getPriority());

    importedLayout2 =
        LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(
            layout2.getUuid(), importedGroup.getGroupId(), false);

    Assert.assertEquals(layout2.getPriority(), importedLayout2.getPriority());

    Layout importedLayout3 =
        LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(
            layout3.getUuid(), importedGroup.getGroupId(), false);

    Assert.assertEquals(layout3.getPriority(), importedLayout3.getPriority());
  }
  @Override
  public Layout getLayout() throws PortalException {
    Group group = getGroup();

    if (group.getPrivateLayoutsPageCount() > 0) {
      List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(group.getGroupId(), true);

      return layouts.get(0);
    }

    throw new NoSuchLayoutException("{groupId=" + group.getGroupId() + "}");
  }
  @Test
  public void testExportImportLayouts() throws Exception {
    LayoutTestUtil.addLayout(group);

    List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(group.getGroupId(), false);

    exportImportLayouts(ExportImportHelperUtil.getLayoutIds(layouts), getImportParameterMap());

    Assert.assertEquals(
        LayoutLocalServiceUtil.getLayoutsCount(group, false),
        LayoutLocalServiceUtil.getLayoutsCount(importedGroup, false));
  }
  @Test
  public void testDeleteMissingLayouts() throws Exception {
    Layout layout1 = LayoutTestUtil.addLayout(group);
    Layout layout2 = LayoutTestUtil.addLayout(group);

    List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(group.getGroupId(), false);

    long[] layoutIds = ExportImportHelperUtil.getLayoutIds(layouts);

    exportImportLayouts(layoutIds, getImportParameterMap());

    Assert.assertEquals(
        LayoutLocalServiceUtil.getLayoutsCount(group, false),
        LayoutLocalServiceUtil.getLayoutsCount(importedGroup, false));

    LayoutTestUtil.addLayout(importedGroup);

    Map<String, String[]> parameterMap = getImportParameterMap();

    parameterMap.put(
        PortletDataHandlerKeys.DELETE_MISSING_LAYOUTS, new String[] {Boolean.TRUE.toString()});

    layoutIds = new long[] {layout1.getLayoutId()};

    exportImportLayouts(layoutIds, getImportParameterMap());

    Assert.assertEquals(
        LayoutLocalServiceUtil.getLayoutsCount(group, false),
        LayoutLocalServiceUtil.getLayoutsCount(importedGroup, false));

    Layout importedLayout1 =
        LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(
            layout1.getUuid(), importedGroup.getGroupId(), false);

    Assert.assertNotNull(importedLayout1);

    Layout importedLayout2 =
        LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(
            layout2.getUuid(), importedGroup.getGroupId(), false);

    Assert.assertNotNull(importedLayout2);
  }
  protected static List<String> getLayoutIds(
      HttpServletRequest request,
      boolean privateLayout,
      long parentLayoutId,
      List<String> layoutIds)
      throws Exception {

    long groupId = ParamUtil.getLong(request, "groupId");

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

    for (Layout layout : layouts) {
      layoutIds.add(String.valueOf(layout.getLayoutId()));

      getLayoutIds(request, privateLayout, layout.getLayoutId(), layoutIds);
    }

    return layoutIds;
  }
  protected List<LayoutTypePortlet> getLayoutTypePortlets(long groupId, boolean privateLayout)
      throws Exception {

    List<LayoutTypePortlet> layoutTypePortlets = new ArrayList<LayoutTypePortlet>();

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

    for (Layout layout : layouts) {
      if (!layout.isTypePortlet()) {
        continue;
      }

      LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

      layoutTypePortlets.add(layoutTypePortlet);
    }

    return layoutTypePortlets;
  }
  protected void exportLayouts(
      PortletDataContext portletDataContext,
      LayoutPrototype layoutPrototype,
      Element layoutPrototypeElement)
      throws Exception {

    List<Layout> layouts =
        LayoutLocalServiceUtil.getLayouts(
            layoutPrototype.getGroupId(), true, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);

    for (Layout layout : layouts) {
      StagedModelDataHandlerUtil.exportStagedModel(portletDataContext, layout);

      portletDataContext.addReferenceElement(
          layoutPrototype,
          layoutPrototypeElement,
          layout,
          PortletDataContext.REFERENCE_TYPE_EMBEDDED,
          false);
    }
  }
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();
  }
  public static List<LayoutTypePortlet> getLayoutTypePortlets(Layout layout)
      throws PortletContainerException {

    if (_PORTLET_EVENT_DISTRIBUTION_LAYOUT_SET) {
      List<Layout> layouts = null;

      try {
        layouts =
            LayoutLocalServiceUtil.getLayouts(
                layout.getGroupId(), layout.isPrivateLayout(), LayoutConstants.TYPE_PORTLET);
      } catch (SystemException se) {
        throw new PortletContainerException(se);
      }

      List<LayoutTypePortlet> layoutTypePortlets = new ArrayList<LayoutTypePortlet>(layouts.size());

      for (Layout curLayout : layouts) {
        LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) curLayout.getLayoutType();

        layoutTypePortlets.add(layoutTypePortlet);
      }

      return layoutTypePortlets;
    }

    if (layout.isTypePortlet()) {
      List<LayoutTypePortlet> layoutTypePortlets = new ArrayList<LayoutTypePortlet>(1);

      LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

      layoutTypePortlets.add(layoutTypePortlet);

      return layoutTypePortlets;
    }

    return Collections.emptyList();
  }
Ejemplo n.º 20
0
  private String getAssetViewURL(
      PortletRequest request, PortletResponse response, AssetEntry assetEntry, String keywords) {

    try {
      ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
      PortletURL returnURL =
          PortletURLFactoryUtil.create(
              request,
              (String) request.getAttribute(WebKeys.PORTLET_ID),
              themeDisplay.getLayout().getPlid(),
              PortletRequest.RENDER_PHASE);
      returnURL.setWindowState(WindowState.NORMAL);
      returnURL.setPortletMode(PortletMode.VIEW);
      returnURL.setParameter("action", "ricercaLibera");
      returnURL.setParameter("cercaPerKeyword", keywords);

      PortletURL viewURL = null;

      String localHost = themeDisplay.getPortalURL();
      List<Layout> layouts = null;

      layouts = LayoutLocalServiceUtil.getLayouts(themeDisplay.getLayout().getGroupId(), false);
      for (Layout layout : layouts) {

        String nodeNameRemoved =
            PortalUtil.getLayoutFriendlyURL(layout, themeDisplay).replace(localHost, "");

        // Viene ricercato l'URL esatto per la pagina successiva
        if (nodeNameRemoved.indexOf(paginaDettaglioContenuto) > 0) {

          viewURL =
              PortletURLFactoryUtil.create(
                  request, assetPublisherPortletId, layout.getPlid(), PortletRequest.RENDER_PHASE);
          viewURL.setWindowState(WindowState.NORMAL);
          viewURL.setPortletMode(PortletMode.VIEW);
          viewURL.setParameter("action", "ricerca");
          viewURL.setParameter("struts_action", "/asset_publisher/view_content");

          // String currentURL = HttpUtil.addParameter(PortalUtil.getCurrentURL(request), "_" +
          // request.getAttribute(WebKeys.PORTLET_ID) + "_cercaPerKeyword", keywords);
          viewURL.setParameter("redirect", returnURL.toString());

          viewURL.setParameter("assetEntryId", String.valueOf(assetEntry.getEntryId()));

          AssetRendererFactory assetRendererFactory = assetEntry.getAssetRendererFactory();

          AssetRenderer assetRenderer = assetEntry.getAssetRenderer();

          viewURL.setParameter("type", assetRendererFactory.getType());

          if (Validator.isNotNull(assetRenderer.getUrlTitle())) {

            if (assetRenderer.getGroupId() != themeDisplay.getScopeGroupId()) {
              viewURL.setParameter("groupId", String.valueOf(assetRenderer.getGroupId()));
            }

            viewURL.setParameter("urlTitle", assetRenderer.getUrlTitle());
          }

          break;
        }
      }

      return viewURL.toString();

    } catch (Exception e) {
      e.printStackTrace();
    }

    return null;
  }
Ejemplo n.º 21
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);
      }
    }
  }
  @Override
  public void processAction(
      ActionMapping actionMapping,
      ActionForm actionForm,
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse)
      throws Exception {

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

    long groupId = ParamUtil.getLong(actionRequest, "groupId");
    boolean privateLayout = ParamUtil.getBoolean(actionRequest, "privateLayout");

    Layout layout = null;

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

    if (layouts.size() > 0) {
      layout = layouts.get(0);
    } else {
      long parentLayoutId = LayoutConstants.DEFAULT_PARENT_LAYOUT_ID;
      String name = "New Page";
      String title = StringPool.BLANK;
      String description = StringPool.BLANK;
      String type = LayoutConstants.TYPE_PORTLET;
      boolean hidden = false;
      String friendlyURL = StringPool.BLANK;

      ServiceContext serviceContext =
          ServiceContextFactory.getInstance(Layout.class.getName(), actionRequest);

      layout =
          LayoutServiceUtil.addLayout(
              groupId,
              privateLayout,
              parentLayoutId,
              name,
              title,
              description,
              type,
              hidden,
              friendlyURL,
              serviceContext);
    }

    if (layout == null) {
      return;
    }

    String tabs1 = "public-pages";

    if (privateLayout) {
      tabs1 = "private-pages";
    }

    HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);

    PortletURL portletURL =
        new PortletURLImpl(
            request, PortletKeys.LAYOUTS_ADMIN, layout.getPlid(), PortletRequest.RENDER_PHASE);

    portletURL.setParameter("struts_action", "/layouts_admin/edit_layouts");
    portletURL.setParameter("tabs1", tabs1);
    portletURL.setParameter("redirect", redirect);
    portletURL.setParameter("groupId", String.valueOf(groupId));
    portletURL.setPortletMode(PortletMode.VIEW);
    portletURL.setWindowState(WindowState.MAXIMIZED);

    actionResponse.sendRedirect(portletURL.toString());
  }
Ejemplo n.º 23
0
 @Override
 public List<Layout> getChildren() throws SystemException {
   return LayoutLocalServiceUtil.getLayouts(getGroupId(), isPrivateLayout(), getLayoutId());
 }
  protected boolean isViewableGroup(
      PermissionChecker permissionChecker,
      Layout layout,
      String controlPanelCategory,
      boolean checkResourcePermission)
      throws PortalException, SystemException {

    Group group = GroupLocalServiceUtil.getGroup(layout.getGroupId());

    // Inactive sites are not viewable

    if (!group.isActive()) {
      return false;
    } else if (group.isStagingGroup()) {
      Group liveGroup = group.getLiveGroup();

      if (!liveGroup.isActive()) {
        return false;
      }
    }

    // User private layouts are only viewable by the user and anyone who can
    // update the user. The user must also be active.

    if (group.isUser()) {
      long groupUserId = group.getClassPK();

      if (groupUserId == permissionChecker.getUserId()) {
        return true;
      }

      User groupUser = UserLocalServiceUtil.getUserById(groupUserId);

      if (!groupUser.isActive()) {
        return false;
      }

      if (layout.isPrivateLayout()) {
        if (GroupPermissionUtil.contains(
                permissionChecker, groupUser.getGroupId(), ActionKeys.MANAGE_LAYOUTS)
            || UserPermissionUtil.contains(
                permissionChecker,
                groupUserId,
                groupUser.getOrganizationIds(),
                ActionKeys.UPDATE)) {

          return true;
        }

        return false;
      }
    }

    // If the current group is staging, only users with editorial rights
    // can access it

    if (group.isStagingGroup()) {
      if (GroupPermissionUtil.contains(
          permissionChecker, group.getGroupId(), ActionKeys.VIEW_STAGING)) {

        return true;
      }

      return false;
    }

    // Control panel layouts are only viewable by authenticated users

    if (group.isControlPanel()) {
      if (!permissionChecker.isSignedIn()) {
        return false;
      }

      if (PortalPermissionUtil.contains(permissionChecker, ActionKeys.VIEW_CONTROL_PANEL)) {

        return true;
      }

      if (Validator.isNotNull(controlPanelCategory)) {
        return true;
      }

      return false;
    }

    // Site layouts are only viewable by users who are members of the site
    // or by users who can update the site

    if (group.isSite()) {
      if (GroupPermissionUtil.contains(
              permissionChecker, group.getGroupId(), ActionKeys.MANAGE_LAYOUTS)
          || GroupPermissionUtil.contains(
              permissionChecker, group.getGroupId(), ActionKeys.UPDATE)) {

        return true;
      }

      if (layout.isPrivateLayout() && !permissionChecker.isGroupMember(group.getGroupId())) {

        return false;
      }
    }

    // Organization site layouts are also viewable by users who belong to
    // the organization or by users who can update organization

    if (group.isCompany()) {
      return false;
    } else if (group.isLayoutPrototype()) {
      if (LayoutPrototypePermissionUtil.contains(
          permissionChecker, group.getClassPK(), ActionKeys.VIEW)) {

        return true;
      }

      return false;
    } else if (group.isLayoutSetPrototype()) {
      if (LayoutSetPrototypePermissionUtil.contains(
          permissionChecker, group.getClassPK(), ActionKeys.VIEW)) {

        return true;
      }

      return false;
    } else if (group.isOrganization()) {
      long organizationId = group.getOrganizationId();

      if (OrganizationLocalServiceUtil.hasUserOrganization(
          permissionChecker.getUserId(), organizationId, false, false)) {

        return true;
      } else if (OrganizationPermissionUtil.contains(
          permissionChecker, organizationId, ActionKeys.UPDATE)) {

        return true;
      }

      if (!PropsValues.ORGANIZATIONS_MEMBERSHIP_STRICT) {
        List<Organization> userOrgs =
            OrganizationLocalServiceUtil.getUserOrganizations(permissionChecker.getUserId());

        for (Organization organization : userOrgs) {
          for (Organization ancestorOrganization : organization.getAncestors()) {

            if (organizationId == ancestorOrganization.getOrganizationId()) {

              return true;
            }
          }
        }
      }
    } else if (group.isUserGroup()) {
      if (UserGroupPermissionUtil.contains(
          permissionChecker, group.getClassPK(), ActionKeys.UPDATE)) {

        return true;
      }
    }

    // Only check the actual Layout if all of the above failed

    if (containsWithoutViewableGroup(
        permissionChecker, layout, controlPanelCategory, ActionKeys.VIEW)) {

      return true;
    }

    // As a last resort, check if any top level pages are viewable by the
    // user

    List<Layout> layouts =
        LayoutLocalServiceUtil.getLayouts(
            layout.getGroupId(),
            layout.isPrivateLayout(),
            LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);

    for (Layout curLayout : layouts) {
      if (!curLayout.isHidden()
          && containsWithoutViewableGroup(
              permissionChecker, curLayout, controlPanelCategory, ActionKeys.VIEW)) {

        return true;
      }
    }

    return false;
  }
Ejemplo n.º 25
0
  public static List<Portlet> getPortletDataHandlerPortlets(long groupId, boolean privateLayout)
      throws Exception {

    return getPortletDataHandlerPortlets(LayoutLocalServiceUtil.getLayouts(groupId, privateLayout));
  }
Ejemplo n.º 26
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);
      }
    }
  }
  private void _getFiles(CommandArgument commandArgument, Document document, Node rootNode)
      throws Exception {

    if (commandArgument.getCurrentFolder().equals(StringPool.SLASH)) {
      return;
    }

    Element filesElement = document.createElement("Files");

    rootNode.appendChild(filesElement);

    Group group = commandArgument.getCurrentGroup();

    List<Layout> layouts =
        LayoutLocalServiceUtil.getLayouts(
            group.getGroupId(), false, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);

    if (("/" + commandArgument.getCurrentGroupName() + "/")
        .equals(commandArgument.getCurrentFolder())) {

      for (Layout layout : layouts) {
        Element fileElement = document.createElement("File");

        filesElement.appendChild(fileElement);

        fileElement.setAttribute("name", _getLayoutName(layout));
        fileElement.setAttribute("desc", _getLayoutName(layout));
        fileElement.setAttribute("size", StringPool.BLANK);
        fileElement.setAttribute(
            "url", PortalUtil.getLayoutURL(layout, commandArgument.getThemeDisplay(), false));
      }
    } else {
      String layoutName = _getLayoutName(commandArgument.getCurrentFolder());

      Layout layout = null;

      for (int i = 0; i < layouts.size(); i++) {
        layout = _getLayout(layoutName, layouts.get(i));

        if (layout != null) {
          break;
        }
      }

      if (layout == null) {
        return;
      }

      List<Layout> layoutChildren = layout.getChildren();

      for (int i = 0; i < layoutChildren.size(); i++) {
        layout = layoutChildren.get(i);

        Element fileElement = document.createElement("File");

        filesElement.appendChild(fileElement);

        fileElement.setAttribute("name", _getLayoutName(layout));
        fileElement.setAttribute("desc", _getLayoutName(layout));
        fileElement.setAttribute("size", getSize());
        fileElement.setAttribute(
            "url", PortalUtil.getLayoutURL(layout, commandArgument.getThemeDisplay(), false));
      }
    }
  }
 protected void propagateChanges(Group group) throws Exception {
   LayoutLocalServiceUtil.getLayouts(
       group.getGroupId(), false, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
 }