コード例 #1
0
  @Override
  public LayoutTypePortlet create(Layout layout) {
    LayoutTypeController layoutTypeController =
        LayoutTypeControllerTracker.getLayoutTypeController(layout.getType());

    return new LayoutTypePortletImpl(layout, layoutTypeController);
  }
コード例 #2
0
  @Override
  protected void doImportStagedModel(PortletDataContext portletDataContext, Layout layout)
      throws Exception {

    long groupId = portletDataContext.getGroupId();
    long userId = portletDataContext.getUserId(layout.getUserUuid());

    Element layoutElement = portletDataContext.getImportDataStagedModelElement(layout);

    String layoutUuid = GetterUtil.getString(layoutElement.attributeValue("layout-uuid"));

    long layoutId = GetterUtil.getInteger(layoutElement.attributeValue("layout-id"));

    long oldLayoutId = layoutId;

    boolean privateLayout = portletDataContext.isPrivateLayout();

    String action = layoutElement.attributeValue(Constants.ACTION);

    if (action.equals(Constants.DELETE)) {
      Layout deletingLayout =
          _layoutLocalService.fetchLayoutByUuidAndGroupId(layoutUuid, groupId, privateLayout);

      _layoutLocalService.deleteLayout(
          deletingLayout, false, ServiceContextThreadLocal.getServiceContext());

      return;
    }

    Map<Long, Layout> layouts =
        (Map<Long, Layout>) portletDataContext.getNewPrimaryKeysMap(Layout.class + ".layout");

    Layout existingLayout = null;
    Layout importedLayout = null;

    String friendlyURL = layout.getFriendlyURL();

    String layoutsImportMode =
        MapUtil.getString(
            portletDataContext.getParameterMap(),
            PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE,
            PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_MERGE_BY_LAYOUT_UUID);

    if (layoutsImportMode.equals(PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_ADD_AS_NEW)) {

      layoutId = _layoutLocalService.getNextLayoutId(groupId, privateLayout);
      friendlyURL = StringPool.SLASH + layoutId;
    } else if (layoutsImportMode.equals(
        PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_MERGE_BY_LAYOUT_NAME)) {

      Locale locale = LocaleUtil.getSiteDefault();

      String localizedName = layout.getName(locale);

      List<Layout> previousLayouts = _layoutLocalService.getLayouts(groupId, privateLayout);

      for (Layout curLayout : previousLayouts) {
        if (localizedName.equals(curLayout.getName(locale))
            || friendlyURL.equals(curLayout.getFriendlyURL())) {

          existingLayout = curLayout;

          break;
        }
      }

      if (existingLayout == null) {
        layoutId = _layoutLocalService.getNextLayoutId(groupId, privateLayout);

        friendlyURL = getFriendlyURL(friendlyURL, layoutId);
      }
    } else if (layoutsImportMode.equals(
        PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_CREATED_FROM_PROTOTYPE)) {

      existingLayout =
          _layoutLocalService.fetchLayoutByUuidAndGroupId(layout.getUuid(), groupId, privateLayout);

      if (SitesUtil.isLayoutModifiedSinceLastMerge(existingLayout)) {
        layouts.put(oldLayoutId, existingLayout);

        return;
      }

      LayoutFriendlyURL layoutFriendlyURL =
          _layoutFriendlyURLLocalService.fetchFirstLayoutFriendlyURL(
              groupId, privateLayout, friendlyURL);

      if ((layoutFriendlyURL != null) && (existingLayout == null)) {
        Layout mergeFailFriendlyURLLayout =
            _layoutLocalService.getLayout(layoutFriendlyURL.getPlid());

        SitesUtil.addMergeFailFriendlyURLLayout(mergeFailFriendlyURLLayout);

        if (!_log.isWarnEnabled()) {
          return;
        }

        StringBundler sb = new StringBundler(6);

        sb.append("Layout with layout ID ");
        sb.append(layout.getLayoutId());
        sb.append(" cannot be propagated because the friendly URL ");
        sb.append("conflicts with the friendly URL of layout with ");
        sb.append("layout ID ");
        sb.append(mergeFailFriendlyURLLayout.getLayoutId());

        _log.warn(sb.toString());

        return;
      }
    } else {

      // The default behavior of import mode is
      // PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_MERGE_BY_LAYOUT_UUID

      existingLayout =
          _layoutLocalService.fetchLayoutByUuidAndGroupId(layout.getUuid(), groupId, privateLayout);

      if (existingLayout == null) {
        existingLayout =
            _layoutLocalService.fetchLayoutByFriendlyURL(groupId, privateLayout, friendlyURL);
      }

      if (existingLayout == null) {
        layoutId = _layoutLocalService.getNextLayoutId(groupId, privateLayout);

        friendlyURL = getFriendlyURL(friendlyURL, layoutId);
      }
    }

    if (_log.isDebugEnabled()) {
      StringBundler sb = new StringBundler(7);

      sb.append("Layout with {groupId=");
      sb.append(groupId);
      sb.append(",privateLayout=");
      sb.append(privateLayout);
      sb.append(",layoutId=");
      sb.append(layoutId);

      if (existingLayout == null) {
        sb.append("} does not exist");

        _log.debug(sb.toString());
      } else {
        sb.append("} exists");

        _log.debug(sb.toString());
      }
    }

    if (existingLayout == null) {
      long plid = _counterLocalService.increment();

      importedLayout = _layoutLocalService.createLayout(plid);

      if (layoutsImportMode.equals(
          PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_CREATED_FROM_PROTOTYPE)) {

        importedLayout.setSourcePrototypeLayoutUuid(layout.getUuid());

        layoutId = _layoutLocalService.getNextLayoutId(groupId, privateLayout);

        friendlyURL = getFriendlyURL(friendlyURL, layoutId);
      } else {
        importedLayout.setCreateDate(layout.getCreateDate());
        importedLayout.setModifiedDate(layout.getModifiedDate());
        importedLayout.setLayoutPrototypeUuid(layout.getLayoutPrototypeUuid());
        importedLayout.setLayoutPrototypeLinkEnabled(layout.isLayoutPrototypeLinkEnabled());
        importedLayout.setSourcePrototypeLayoutUuid(layout.getSourcePrototypeLayoutUuid());
      }

      importedLayout.setUuid(layout.getUuid());
      importedLayout.setGroupId(groupId);
      importedLayout.setUserId(userId);
      importedLayout.setPrivateLayout(privateLayout);
      importedLayout.setLayoutId(layoutId);

      initNewLayoutPermissions(
          portletDataContext.getCompanyId(),
          groupId,
          userId,
          layout,
          importedLayout,
          privateLayout);

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

      importedLayout.setLayoutSet(layoutSet);
    } else {
      importedLayout = existingLayout;
    }

    portletDataContext.setPlid(importedLayout.getPlid());
    portletDataContext.setOldPlid(layout.getPlid());

    long parentLayoutId = layout.getParentLayoutId();

    String parentLayoutUuid =
        GetterUtil.getString(layoutElement.attributeValue("parent-layout-uuid"));

    Element parentLayoutElement =
        portletDataContext.getReferenceDataElement(
            layout, Layout.class, layout.getGroupId(), parentLayoutUuid);

    if ((parentLayoutId != LayoutConstants.DEFAULT_PARENT_LAYOUT_ID)
        && (parentLayoutElement != null)) {

      StagedModelDataHandlerUtil.importStagedModel(portletDataContext, parentLayoutElement);

      Layout importedParentLayout = layouts.get(parentLayoutId);

      parentLayoutId = importedParentLayout.getLayoutId();
    }

    if (_log.isDebugEnabled()) {
      StringBundler sb = new StringBundler(4);

      sb.append("Importing layout with layout id ");
      sb.append(layoutId);
      sb.append(" and parent layout id ");
      sb.append(parentLayoutId);

      _log.debug(sb.toString());
    }

    importedLayout.setCompanyId(portletDataContext.getCompanyId());

    if (layout.getLayoutPrototypeUuid() != null) {
      importedLayout.setModifiedDate(new Date());
    }

    importedLayout.setParentLayoutId(parentLayoutId);
    importedLayout.setName(layout.getName());
    importedLayout.setTitle(layout.getTitle());
    importedLayout.setDescription(layout.getDescription());
    importedLayout.setKeywords(layout.getKeywords());
    importedLayout.setRobots(layout.getRobots());
    importedLayout.setType(layout.getType());

    String portletsMergeMode =
        MapUtil.getString(
            portletDataContext.getParameterMap(),
            PortletDataHandlerKeys.PORTLETS_MERGE_MODE,
            PortletDataHandlerKeys.PORTLETS_MERGE_MODE_REPLACE);

    if (layout.isTypePortlet()
        && Validator.isNotNull(layout.getTypeSettings())
        && !portletsMergeMode.equals(PortletDataHandlerKeys.PORTLETS_MERGE_MODE_REPLACE)) {

      mergePortlets(importedLayout, layout.getTypeSettings(), portletsMergeMode);
    } else if (layout.isTypeLinkToLayout()) {
      importLinkedLayout(portletDataContext, layout, importedLayout, layoutElement, layouts);
    } else {
      updateTypeSettings(importedLayout, layout);
    }

    importedLayout.setHidden(layout.isHidden());
    importedLayout.setFriendlyURL(
        getUniqueFriendlyURL(portletDataContext, importedLayout, friendlyURL));

    if (layout.getIconImageId() > 0) {
      importLayoutIconImage(portletDataContext, importedLayout, layoutElement);
    } else if (importedLayout.getIconImageId() > 0) {
      _imageLocalService.deleteImage(importedLayout.getIconImageId());
    }

    if (existingLayout == null) {
      int priority =
          _layoutLocalServiceHelper.getNextPriority(
              groupId, privateLayout, parentLayoutId, null, -1);

      importedLayout.setPriority(priority);
    }

    importedLayout.setLayoutPrototypeUuid(layout.getLayoutPrototypeUuid());
    importedLayout.setLayoutPrototypeLinkEnabled(layout.isLayoutPrototypeLinkEnabled());

    ServiceContext serviceContext = portletDataContext.createServiceContext(layout);

    importedLayout.setExpandoBridgeAttributes(serviceContext);

    StagingUtil.updateLastImportSettings(layoutElement, importedLayout, portletDataContext);

    fixImportTypeSettings(importedLayout);

    importTheme(portletDataContext, layout, importedLayout);

    _layoutLocalService.updateLayout(importedLayout);

    _layoutSetLocalService.updatePageCount(groupId, privateLayout);

    Map<Long, Long> layoutPlids =
        (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Layout.class);

    layoutPlids.put(layout.getPlid(), importedLayout.getPlid());

    layouts.put(oldLayoutId, importedLayout);

    importAssets(portletDataContext, layout, importedLayout);

    importLayoutFriendlyURLs(portletDataContext, layout, importedLayout);

    portletDataContext.importClassedModel(layout, importedLayout);
  }
コード例 #3
0
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    Layout newLayout = _persistence.create(pk);

    newLayout.setMvccVersion(RandomTestUtil.nextLong());

    newLayout.setUuid(RandomTestUtil.randomString());

    newLayout.setGroupId(RandomTestUtil.nextLong());

    newLayout.setCompanyId(RandomTestUtil.nextLong());

    newLayout.setUserId(RandomTestUtil.nextLong());

    newLayout.setUserName(RandomTestUtil.randomString());

    newLayout.setCreateDate(RandomTestUtil.nextDate());

    newLayout.setModifiedDate(RandomTestUtil.nextDate());

    newLayout.setPrivateLayout(RandomTestUtil.randomBoolean());

    newLayout.setLayoutId(RandomTestUtil.nextLong());

    newLayout.setParentLayoutId(RandomTestUtil.nextLong());

    newLayout.setName(RandomTestUtil.randomString());

    newLayout.setTitle(RandomTestUtil.randomString());

    newLayout.setDescription(RandomTestUtil.randomString());

    newLayout.setKeywords(RandomTestUtil.randomString());

    newLayout.setRobots(RandomTestUtil.randomString());

    newLayout.setType(RandomTestUtil.randomString());

    newLayout.setTypeSettings(RandomTestUtil.randomString());

    newLayout.setHidden(RandomTestUtil.randomBoolean());

    newLayout.setFriendlyURL(RandomTestUtil.randomString());

    newLayout.setIconImageId(RandomTestUtil.nextLong());

    newLayout.setThemeId(RandomTestUtil.randomString());

    newLayout.setColorSchemeId(RandomTestUtil.randomString());

    newLayout.setWapThemeId(RandomTestUtil.randomString());

    newLayout.setWapColorSchemeId(RandomTestUtil.randomString());

    newLayout.setCss(RandomTestUtil.randomString());

    newLayout.setPriority(RandomTestUtil.nextInt());

    newLayout.setLayoutPrototypeUuid(RandomTestUtil.randomString());

    newLayout.setLayoutPrototypeLinkEnabled(RandomTestUtil.randomBoolean());

    newLayout.setSourcePrototypeLayoutUuid(RandomTestUtil.randomString());

    _layouts.add(_persistence.update(newLayout));

    Layout existingLayout = _persistence.findByPrimaryKey(newLayout.getPrimaryKey());

    Assert.assertEquals(existingLayout.getMvccVersion(), newLayout.getMvccVersion());
    Assert.assertEquals(existingLayout.getUuid(), newLayout.getUuid());
    Assert.assertEquals(existingLayout.getPlid(), newLayout.getPlid());
    Assert.assertEquals(existingLayout.getGroupId(), newLayout.getGroupId());
    Assert.assertEquals(existingLayout.getCompanyId(), newLayout.getCompanyId());
    Assert.assertEquals(existingLayout.getUserId(), newLayout.getUserId());
    Assert.assertEquals(existingLayout.getUserName(), newLayout.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingLayout.getCreateDate()),
        Time.getShortTimestamp(newLayout.getCreateDate()));
    Assert.assertEquals(
        Time.getShortTimestamp(existingLayout.getModifiedDate()),
        Time.getShortTimestamp(newLayout.getModifiedDate()));
    Assert.assertEquals(existingLayout.getPrivateLayout(), newLayout.getPrivateLayout());
    Assert.assertEquals(existingLayout.getLayoutId(), newLayout.getLayoutId());
    Assert.assertEquals(existingLayout.getParentLayoutId(), newLayout.getParentLayoutId());
    Assert.assertEquals(existingLayout.getName(), newLayout.getName());
    Assert.assertEquals(existingLayout.getTitle(), newLayout.getTitle());
    Assert.assertEquals(existingLayout.getDescription(), newLayout.getDescription());
    Assert.assertEquals(existingLayout.getKeywords(), newLayout.getKeywords());
    Assert.assertEquals(existingLayout.getRobots(), newLayout.getRobots());
    Assert.assertEquals(existingLayout.getType(), newLayout.getType());
    Assert.assertEquals(existingLayout.getTypeSettings(), newLayout.getTypeSettings());
    Assert.assertEquals(existingLayout.getHidden(), newLayout.getHidden());
    Assert.assertEquals(existingLayout.getFriendlyURL(), newLayout.getFriendlyURL());
    Assert.assertEquals(existingLayout.getIconImageId(), newLayout.getIconImageId());
    Assert.assertEquals(existingLayout.getThemeId(), newLayout.getThemeId());
    Assert.assertEquals(existingLayout.getColorSchemeId(), newLayout.getColorSchemeId());
    Assert.assertEquals(existingLayout.getWapThemeId(), newLayout.getWapThemeId());
    Assert.assertEquals(existingLayout.getWapColorSchemeId(), newLayout.getWapColorSchemeId());
    Assert.assertEquals(existingLayout.getCss(), newLayout.getCss());
    Assert.assertEquals(existingLayout.getPriority(), newLayout.getPriority());
    Assert.assertEquals(
        existingLayout.getLayoutPrototypeUuid(), newLayout.getLayoutPrototypeUuid());
    Assert.assertEquals(
        existingLayout.getLayoutPrototypeLinkEnabled(), newLayout.getLayoutPrototypeLinkEnabled());
    Assert.assertEquals(
        existingLayout.getSourcePrototypeLayoutUuid(), newLayout.getSourcePrototypeLayoutUuid());
  }
コード例 #4
0
  protected void importLayout(
      PortletDataContext portletDataContext,
      User user,
      LayoutCache layoutCache,
      List<Layout> previousLayouts,
      List<Layout> newLayouts,
      Map<Long, Layout> newLayoutsMap,
      Set<Long> newLayoutIds,
      String portletsMergeMode,
      String themeId,
      String colorSchemeId,
      String layoutsImportMode,
      boolean privateLayout,
      boolean importPermissions,
      boolean importPublicLayoutPermissions,
      boolean importUserPermissions,
      boolean importThemeSettings,
      Element rootElement,
      Element layoutElement)
      throws Exception {

    long groupId = portletDataContext.getGroupId();

    String layoutUuid = GetterUtil.getString(layoutElement.attributeValue("layout-uuid"));

    long layoutId = GetterUtil.getInteger(layoutElement.attributeValue("layout-id"));

    long oldLayoutId = layoutId;

    boolean deleteLayout = GetterUtil.getBoolean(layoutElement.attributeValue("delete"));

    if (deleteLayout) {
      Layout layout = LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(layoutUuid, groupId);

      if (layout != null) {
        newLayoutsMap.put(oldLayoutId, layout);

        ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();

        LayoutLocalServiceUtil.deleteLayout(layout, false, serviceContext);
      }

      return;
    }

    String path = layoutElement.attributeValue("path");

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

    Layout layout = (Layout) portletDataContext.getZipEntryAsObject(path);

    Layout existingLayout = null;
    Layout importedLayout = null;

    String friendlyURL = layout.getFriendlyURL();

    if (layoutsImportMode.equals(PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_ADD_AS_NEW)) {

      layoutId = LayoutLocalServiceUtil.getNextLayoutId(groupId, privateLayout);
      friendlyURL = StringPool.SLASH + layoutId;
    } else if (layoutsImportMode.equals(
        PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_MERGE_BY_LAYOUT_NAME)) {

      Locale locale = LocaleUtil.getDefault();

      String localizedName = layout.getName(locale);

      for (Layout curLayout : previousLayouts) {
        if (localizedName.equals(curLayout.getName(locale))
            || friendlyURL.equals(curLayout.getFriendlyURL())) {

          existingLayout = curLayout;

          break;
        }
      }

      if (existingLayout == null) {
        layoutId = LayoutLocalServiceUtil.getNextLayoutId(groupId, privateLayout);
      }
    } else if (layoutsImportMode.equals(
        PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_CREATED_FROM_PROTOTYPE)) {

      existingLayout = LayoutUtil.fetchByG_P_SPLU(groupId, privateLayout, layout.getUuid());

      if (SitesUtil.isLayoutModifiedSinceLastMerge(existingLayout)) {
        newLayoutsMap.put(oldLayoutId, existingLayout);

        return;
      }
    } else {

      // The default behaviour of import mode is
      // PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_MERGE_BY_LAYOUT_UUID

      existingLayout = LayoutUtil.fetchByUUID_G(layout.getUuid(), groupId);

      if (existingLayout == null) {
        existingLayout = LayoutUtil.fetchByG_P_F(groupId, privateLayout, friendlyURL);
      }

      if (existingLayout == null) {
        layoutId = LayoutLocalServiceUtil.getNextLayoutId(groupId, privateLayout);
      }
    }

    if (_log.isDebugEnabled()) {
      if (existingLayout == null) {
        _log.debug(
            "Layout with {groupId="
                + groupId
                + ",privateLayout="
                + privateLayout
                + ",layoutId="
                + layoutId
                + "} does not exist");
      } else {
        _log.debug(
            "Layout with {groupId="
                + groupId
                + ",privateLayout="
                + privateLayout
                + ",layoutId="
                + layoutId
                + "} exists");
      }
    }

    if (existingLayout == null) {
      long plid = CounterLocalServiceUtil.increment();

      importedLayout = LayoutUtil.create(plid);

      if (layoutsImportMode.equals(
          PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_CREATED_FROM_PROTOTYPE)) {

        importedLayout.setSourcePrototypeLayoutUuid(layout.getUuid());

        layoutId = LayoutLocalServiceUtil.getNextLayoutId(groupId, privateLayout);
      } else {
        importedLayout.setUuid(layout.getUuid());
        importedLayout.setCreateDate(layout.getCreateDate());
        importedLayout.setModifiedDate(layout.getModifiedDate());
        importedLayout.setLayoutPrototypeUuid(layout.getLayoutPrototypeUuid());
        importedLayout.setLayoutPrototypeLinkEnabled(layout.isLayoutPrototypeLinkEnabled());
        importedLayout.setSourcePrototypeLayoutUuid(layout.getSourcePrototypeLayoutUuid());
      }

      importedLayout.setGroupId(groupId);
      importedLayout.setPrivateLayout(privateLayout);
      importedLayout.setLayoutId(layoutId);

      // Resources

      boolean addGroupPermissions = true;

      Group group = importedLayout.getGroup();

      if (privateLayout && group.isUser()) {
        addGroupPermissions = false;
      }

      boolean addGuestPermissions = false;

      if (!privateLayout || layout.isTypeControlPanel()) {
        addGuestPermissions = true;
      }

      ResourceLocalServiceUtil.addResources(
          user.getCompanyId(),
          groupId,
          user.getUserId(),
          Layout.class.getName(),
          importedLayout.getPlid(),
          false,
          addGroupPermissions,
          addGuestPermissions);

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

      importedLayout.setLayoutSet(layoutSet);
    } else {
      importedLayout = existingLayout;
    }

    newLayoutsMap.put(oldLayoutId, importedLayout);

    long parentLayoutId = layout.getParentLayoutId();

    Node parentLayoutNode =
        rootElement.selectSingleNode("./layouts/layout[@layout-id='" + parentLayoutId + "']");

    String parentLayoutUuid =
        GetterUtil.getString(layoutElement.attributeValue("parent-layout-uuid"));

    if ((parentLayoutId != LayoutConstants.DEFAULT_PARENT_LAYOUT_ID)
        && (parentLayoutNode != null)) {

      importLayout(
          portletDataContext,
          user,
          layoutCache,
          previousLayouts,
          newLayouts,
          newLayoutsMap,
          newLayoutIds,
          portletsMergeMode,
          themeId,
          colorSchemeId,
          layoutsImportMode,
          privateLayout,
          importPermissions,
          importPublicLayoutPermissions,
          importUserPermissions,
          importThemeSettings,
          rootElement,
          (Element) parentLayoutNode);

      Layout parentLayout = newLayoutsMap.get(parentLayoutId);

      parentLayoutId = parentLayout.getLayoutId();
    } else if (Validator.isNotNull(parentLayoutUuid)) {
      Layout parentLayout =
          LayoutLocalServiceUtil.getLayoutByUuidAndGroupId(parentLayoutUuid, groupId);

      parentLayoutId = parentLayout.getLayoutId();
    }

    if (_log.isDebugEnabled()) {
      _log.debug(
          "Importing layout with layout id "
              + layoutId
              + " and parent layout id "
              + parentLayoutId);
    }

    importedLayout.setCompanyId(user.getCompanyId());
    importedLayout.setParentLayoutId(parentLayoutId);
    importedLayout.setName(layout.getName());
    importedLayout.setTitle(layout.getTitle());
    importedLayout.setDescription(layout.getDescription());
    importedLayout.setKeywords(layout.getKeywords());
    importedLayout.setRobots(layout.getRobots());
    importedLayout.setType(layout.getType());

    if (layout.isTypeArticle()) {
      importJournalArticle(portletDataContext, layout, layoutElement);

      importedLayout.setTypeSettings(layout.getTypeSettings());
    } else if (layout.isTypePortlet()
        && Validator.isNotNull(layout.getTypeSettings())
        && !portletsMergeMode.equals(PortletDataHandlerKeys.PORTLETS_MERGE_MODE_REPLACE)) {

      mergePortlets(importedLayout, layout.getTypeSettings(), portletsMergeMode);
    } else if (layout.isTypeLinkToLayout()) {
      UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties();

      long linkToLayoutId =
          GetterUtil.getLong(
              typeSettingsProperties.getProperty("linkToLayoutId", StringPool.BLANK));

      if (linkToLayoutId > 0) {
        Node linkedLayoutNode =
            rootElement.selectSingleNode("./layouts/layout[@layout-id='" + linkToLayoutId + "']");

        if (linkedLayoutNode != null) {
          importLayout(
              portletDataContext,
              user,
              layoutCache,
              previousLayouts,
              newLayouts,
              newLayoutsMap,
              newLayoutIds,
              portletsMergeMode,
              themeId,
              colorSchemeId,
              layoutsImportMode,
              privateLayout,
              importPermissions,
              importPublicLayoutPermissions,
              importUserPermissions,
              importThemeSettings,
              rootElement,
              (Element) linkedLayoutNode);

          Layout linkedLayout = newLayoutsMap.get(linkToLayoutId);

          typeSettingsProperties.setProperty(
              "privateLayout", String.valueOf(linkedLayout.getPrivateLayout()));
          typeSettingsProperties.setProperty(
              "linkToLayoutId", String.valueOf(linkedLayout.getLayoutId()));
        } else {
          if (_log.isWarnEnabled()) {
            StringBundler sb = new StringBundler();

            sb.append("Unable to link layout with friendly URL ");
            sb.append(layout.getFriendlyURL());
            sb.append(" and layout id ");
            sb.append(layout.getLayoutId());
            sb.append(" to layout with layout id ");
            sb.append(linkToLayoutId);

            _log.warn(sb.toString());
          }
        }
      }

      importedLayout.setTypeSettings(layout.getTypeSettings());
    } else {
      importedLayout.setTypeSettings(layout.getTypeSettings());
    }

    importedLayout.setHidden(layout.isHidden());
    importedLayout.setFriendlyURL(friendlyURL);

    if (importThemeSettings) {
      importedLayout.setThemeId(layout.getThemeId());
      importedLayout.setColorSchemeId(layout.getColorSchemeId());
    } else {
      importedLayout.setThemeId(StringPool.BLANK);
      importedLayout.setColorSchemeId(StringPool.BLANK);
    }

    importedLayout.setWapThemeId(layout.getWapThemeId());
    importedLayout.setWapColorSchemeId(layout.getWapColorSchemeId());
    importedLayout.setCss(layout.getCss());
    importedLayout.setPriority(layout.getPriority());
    importedLayout.setLayoutPrototypeUuid(layout.getLayoutPrototypeUuid());
    importedLayout.setLayoutPrototypeLinkEnabled(layout.isLayoutPrototypeLinkEnabled());

    StagingUtil.updateLastImportSettings(layoutElement, importedLayout, portletDataContext);

    fixTypeSettings(importedLayout);

    importedLayout.setIconImage(false);

    if (layout.isIconImage()) {
      String iconImagePath = layoutElement.elementText("icon-image-path");

      byte[] iconBytes = portletDataContext.getZipEntryAsByteArray(iconImagePath);

      if ((iconBytes != null) && (iconBytes.length > 0)) {
        importedLayout.setIconImage(true);

        if (importedLayout.getIconImageId() == 0) {
          long iconImageId = CounterLocalServiceUtil.increment();

          importedLayout.setIconImageId(iconImageId);
        }

        ImageLocalServiceUtil.updateImage(importedLayout.getIconImageId(), iconBytes);
      }
    } else {
      ImageLocalServiceUtil.deleteImage(importedLayout.getIconImageId());
    }

    ServiceContext serviceContext =
        portletDataContext.createServiceContext(layoutElement, importedLayout, null);

    importedLayout.setExpandoBridgeAttributes(serviceContext);

    LayoutUtil.update(importedLayout, false);

    portletDataContext.setPlid(importedLayout.getPlid());
    portletDataContext.setOldPlid(layout.getPlid());

    newLayoutIds.add(importedLayout.getLayoutId());

    newLayouts.add(importedLayout);

    // Layout permissions

    if (importPermissions) {
      _permissionImporter.importLayoutPermissions(
          layoutCache,
          portletDataContext.getCompanyId(),
          groupId,
          user.getUserId(),
          importedLayout,
          layoutElement,
          rootElement,
          importUserPermissions);
    }

    if (importPublicLayoutPermissions) {
      String resourceName = Layout.class.getName();
      String resourcePrimKey = String.valueOf(importedLayout.getPlid());

      Role guestRole =
          RoleLocalServiceUtil.getRole(importedLayout.getCompanyId(), RoleConstants.GUEST);

      if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 5) {
        Resource resource =
            layoutCache.getResource(
                importedLayout.getCompanyId(),
                groupId,
                resourceName,
                ResourceConstants.SCOPE_INDIVIDUAL,
                resourcePrimKey,
                false);

        PermissionLocalServiceUtil.setRolePermissions(
            guestRole.getRoleId(), new String[] {ActionKeys.VIEW}, resource.getResourceId());
      } else if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) {
        ResourcePermissionLocalServiceUtil.setResourcePermissions(
            importedLayout.getCompanyId(),
            resourceName,
            ResourceConstants.SCOPE_INDIVIDUAL,
            resourcePrimKey,
            guestRole.getRoleId(),
            new String[] {ActionKeys.VIEW});
      } else {
        Resource resource =
            layoutCache.getResource(
                importedLayout.getCompanyId(),
                groupId,
                resourceName,
                ResourceConstants.SCOPE_INDIVIDUAL,
                resourcePrimKey,
                false);

        PermissionLocalServiceUtil.setGroupPermissions(
            groupId, new String[] {ActionKeys.VIEW}, resource.getResourceId());
      }
    }

    _portletImporter.importPortletData(
        portletDataContext, PortletKeys.LAYOUT_CONFIGURATION, null, layoutElement);
  }
コード例 #5
0
  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();
  }
コード例 #6
0
  protected File doExportPortletInfoAsFile(
      long plid,
      long groupId,
      String portletId,
      Map<String, String[]> parameterMap,
      Date startDate,
      Date endDate)
      throws Exception {

    boolean exportCategories = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.CATEGORIES);
    boolean exportPermissions =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PERMISSIONS);
    boolean exportPortletArchivedSetups =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PORTLET_ARCHIVED_SETUPS);

    boolean exportPortletData = false;

    if (parameterMap.containsKey(
        PortletDataHandlerKeys.PORTLET_DATA + "_" + PortletConstants.getRootPortletId(portletId))) {

      exportPortletData =
          MapUtil.getBoolean(
              parameterMap,
              PortletDataHandlerKeys.PORTLET_DATA
                  + "_"
                  + PortletConstants.getRootPortletId(portletId));
    } else {
      exportPortletData = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PORTLET_DATA);
    }

    boolean exportPortletDataAll =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PORTLET_DATA_ALL);
    boolean exportPortletSetup =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PORTLET_SETUP);
    boolean exportPortletUserPreferences =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PORTLET_USER_PREFERENCES);
    boolean exportUserPermissions =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.USER_PERMISSIONS);

    if (_log.isDebugEnabled()) {
      _log.debug("Export categories " + exportCategories);
      _log.debug("Export permissions " + exportPermissions);
      _log.debug("Export portlet archived setups " + exportPortletArchivedSetups);
      _log.debug("Export portlet data " + exportPortletData);
      _log.debug("Export all portlet data " + exportPortletDataAll);
      _log.debug("Export portlet setup " + exportPortletSetup);
      _log.debug("Export portlet user preferences " + exportPortletUserPreferences);
      _log.debug("Export user permissions " + exportUserPermissions);
    }

    if (exportPortletDataAll) {
      exportPortletData = true;
    }

    StopWatch stopWatch = null;

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

      stopWatch.start();
    }

    LayoutCache layoutCache = new LayoutCache();

    Layout layout = LayoutLocalServiceUtil.getLayout(plid);

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

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

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

    ZipWriter zipWriter = ZipWriterFactoryUtil.getZipWriter();

    long scopeGroupId = groupId;

    javax.portlet.PortletPreferences jxPreferences =
        PortletPreferencesFactoryUtil.getLayoutPortletSetup(layout, portletId);

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

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

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

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

    PortletDataContext portletDataContext =
        new PortletDataContextImpl(
            layout.getCompanyId(),
            scopeGroupId,
            parameterMap,
            new HashSet<String>(),
            startDate,
            endDate,
            zipWriter);

    portletDataContext.setPortetDataContextListener(
        new PortletDataContextListenerImpl(portletDataContext));

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

    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("type", "portlet");
    headerElement.addAttribute("group-id", String.valueOf(scopeGroupId));
    headerElement.addAttribute("private-layout", String.valueOf(layout.isPrivateLayout()));
    headerElement.addAttribute("root-portlet-id", PortletConstants.getRootPortletId(portletId));

    exportPortlet(
        portletDataContext,
        layoutCache,
        portletId,
        layout,
        rootElement,
        defaultUserId,
        exportPermissions,
        exportPortletArchivedSetups,
        exportPortletData,
        exportPortletSetup,
        exportPortletUserPreferences,
        exportUserPermissions);

    if (exportCategories) {
      exportAssetCategories(portletDataContext);
    }

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

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

    exportRatingsEntries(portletDataContext, rootElement);

    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);
    }

    return zipWriter.getFile();
  }
コード例 #7
0
  public static String getLayoutsJSON(
      HttpServletRequest request,
      long groupId,
      boolean privateLayout,
      long parentLayoutId,
      long[] expandedLayoutIds)
      throws Exception {

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

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    List<Layout> layoutAncestors = null;

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

    if (selPlid != 0) {
      Layout selLayout = LayoutLocalServiceUtil.getLayout(selPlid);

      layoutAncestors = selLayout.getAncestors();
    }

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

    for (Layout layout : layouts) {
      JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

      if ((layoutAncestors != null) && layoutAncestors.contains(layout)
          || ArrayUtil.contains(expandedLayoutIds, layout.getLayoutId())) {

        String childrenJSON = StringPool.BLANK;

        if (layout instanceof VirtualLayout) {
          VirtualLayout virtualLayout = (VirtualLayout) layout;

          childrenJSON =
              getLayoutsJSON(
                  request,
                  virtualLayout.getSourceGroupId(),
                  virtualLayout.getPrivateLayout(),
                  virtualLayout.getLayoutId(),
                  expandedLayoutIds);

        } else {
          childrenJSON =
              getLayoutsJSON(
                  request,
                  groupId,
                  layout.getPrivateLayout(),
                  layout.getLayoutId(),
                  expandedLayoutIds);
        }

        jsonObject.put("children", JSONFactoryUtil.createJSONArray(childrenJSON));
      }

      jsonObject.put("contentDisplayPage", layout.isContentDisplayPage());
      jsonObject.put("friendlyURL", layout.getFriendlyURL());

      if (layout instanceof VirtualLayout) {
        VirtualLayout virtualLayout = (VirtualLayout) layout;

        jsonObject.put("groupId", virtualLayout.getSourceGroupId());
      } else {
        jsonObject.put("groupId", layout.getGroupId());
      }

      jsonObject.put("hasChildren", layout.hasChildren());
      jsonObject.put("layoutId", layout.getLayoutId());
      jsonObject.put("name", layout.getName(themeDisplay.getLocale()));
      jsonObject.put("parentLayoutId", layout.getParentLayoutId());
      jsonObject.put("plid", layout.getPlid());
      jsonObject.put("priority", layout.getPriority());
      jsonObject.put("privateLayout", layout.isPrivateLayout());
      jsonObject.put("type", layout.getType());
      jsonObject.put("updateable", SitesUtil.isLayoutUpdateable(layout));
      jsonObject.put("uuid", layout.getUuid());

      LayoutRevision layoutRevision = LayoutStagingUtil.getLayoutRevision(layout);

      if (layoutRevision != null) {
        User user = themeDisplay.getUser();

        long recentLayoutSetBranchId =
            StagingUtil.getRecentLayoutSetBranchId(user, layout.getLayoutSet().getLayoutSetId());

        if (StagingUtil.isIncomplete(layout, recentLayoutSetBranchId)) {
          jsonObject.put("incomplete", true);
        }

        long layoutSetBranchId = layoutRevision.getLayoutSetBranchId();

        LayoutSetBranch layoutSetBranch =
            LayoutSetBranchLocalServiceUtil.getLayoutSetBranch(layoutSetBranchId);

        LayoutBranch layoutBranch = layoutRevision.getLayoutBranch();

        if (!layoutBranch.isMaster()) {
          jsonObject.put("layoutBranchId", layoutBranch.getLayoutBranchId());
          jsonObject.put("layoutBranchName", layoutBranch.getName());
        }

        jsonObject.put("layoutRevisionId", layoutRevision.getLayoutRevisionId());
        jsonObject.put("layoutSetBranchId", layoutSetBranchId);
        jsonObject.put("layoutSetBranchName", layoutSetBranch.getName());
      }

      jsonArray.put(jsonObject);
    }

    return jsonArray.toString();
  }