@Test
  public void testChangePageNodeWithRedirectPage() throws Exception {
    WikiNode destinationNode = WikiTestUtil.addNode(_group.getGroupId());

    WikiTestUtil.addPage(
        TestPropsValues.getUserId(),
        _group.getGroupId(),
        _node.getNodeId(),
        "InitialTitlePage",
        true);

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    WikiPageLocalServiceUtil.renamePage(
        TestPropsValues.getUserId(),
        _node.getNodeId(),
        "InitialTitlePage",
        "RenamedPage",
        serviceContext);

    WikiPageLocalServiceUtil.changeNode(
        TestPropsValues.getUserId(),
        _node.getNodeId(),
        "RenamedPage",
        destinationNode.getNodeId(),
        serviceContext);

    WikiPage page = WikiPageLocalServiceUtil.getPage(destinationNode.getNodeId(), "RenamedPage");
    WikiPage redirectPage =
        WikiPageLocalServiceUtil.getPage(destinationNode.getNodeId(), "InitialTitlePage");

    Assert.assertEquals(destinationNode.getNodeId(), page.getNodeId());
    Assert.assertEquals(destinationNode.getNodeId(), redirectPage.getNodeId());
    Assert.assertEquals("RenamedPage", redirectPage.getRedirectTitle());
  }
  @Test
  public void testChangeChildPageNode() throws Exception {
    WikiNode destinationNode = WikiTestUtil.addNode(_group.getGroupId());

    WikiTestUtil.addPage(
        TestPropsValues.getUserId(), _group.getGroupId(), _node.getNodeId(), "ParentPage", true);

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    WikiTestUtil.addPage(
        TestPropsValues.getUserId(),
        _node.getNodeId(),
        "ChildPage",
        RandomTestUtil.randomString(),
        "ParentPage",
        true,
        serviceContext);

    WikiPageLocalServiceUtil.changeNode(
        TestPropsValues.getUserId(),
        _node.getNodeId(),
        "ChildPage",
        destinationNode.getNodeId(),
        serviceContext);

    WikiPage parentPage = WikiPageLocalServiceUtil.getPage(_node.getNodeId(), "ParentPage");
    WikiPage childPage = WikiPageLocalServiceUtil.getPage(destinationNode.getNodeId(), "ChildPage");

    Assert.assertEquals(_node.getNodeId(), parentPage.getNodeId());
    Assert.assertEquals(destinationNode.getNodeId(), childPage.getNodeId());
    Assert.assertTrue(Validator.isNull(childPage.getParentTitle()));
  }
  @Override
  protected void moveBaseModelToTrash(long primaryKey) throws Exception {
    WikiPage page = WikiPageLocalServiceUtil.getPageByPageId(primaryKey);

    WikiPageLocalServiceUtil.movePageToTrash(
        TestPropsValues.getUserId(), page.getNodeId(), page.getTitle());
  }
  @Test
  public void testChangePageNodeWithChildHierarchy() throws Exception {
    WikiNode destinationNode = WikiTestUtil.addNode(_group.getGroupId());

    WikiTestUtil.addPage(
        TestPropsValues.getUserId(), _group.getGroupId(), _node.getNodeId(), "ParentPage", true);

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    List<WikiPage> childPages = createPageHierarchy("ParentPage", 10, serviceContext);

    WikiPageLocalServiceUtil.changeNode(
        TestPropsValues.getUserId(),
        _node.getNodeId(),
        "ParentPage",
        destinationNode.getNodeId(),
        serviceContext);

    WikiPage page = WikiPageLocalServiceUtil.getPage(destinationNode.getNodeId(), "ParentPage");

    Assert.assertEquals(destinationNode.getNodeId(), page.getNodeId());

    for (WikiPage childPage : childPages) {
      childPage = WikiPageLocalServiceUtil.getPage(childPage.getResourcePrimKey());

      Assert.assertEquals(destinationNode.getNodeId(), childPage.getNodeId());
    }
  }
  protected void checkPopulatedServiceContext(
      ServiceContext serviceContext, WikiPage page, boolean hasExpandoValues) throws Exception {

    long[] assetCategoryIds =
        AssetCategoryLocalServiceUtil.getCategoryIds(
            WikiPage.class.getName(), page.getResourcePrimKey());

    Assert.assertArrayEquals(serviceContext.getAssetCategoryIds(), assetCategoryIds);

    AssetEntry assetEntry =
        AssetEntryLocalServiceUtil.getEntry(WikiPage.class.getName(), page.getResourcePrimKey());

    List<AssetLink> assetLinks = AssetLinkLocalServiceUtil.getLinks(assetEntry.getEntryId());

    long[] assetLinkEntryIds = ListUtil.toLongArray(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR);

    Assert.assertArrayEquals(serviceContext.getAssetLinkEntryIds(), assetLinkEntryIds);

    String[] assetTagNames =
        AssetTagLocalServiceUtil.getTagNames(WikiPage.class.getName(), page.getResourcePrimKey());

    Assert.assertArrayEquals(serviceContext.getAssetTagNames(), assetTagNames);

    if (hasExpandoValues) {
      ExpandoBridge expandoBridge = page.getExpandoBridge();

      AssertUtils.assertEquals(
          expandoBridge.getAttributes(), serviceContext.getExpandoBridgeAttributes());
    }
  }
  @Override
  public String getRestoreLink(PortletRequest portletRequest, long classPK)
      throws PortalException, SystemException {

    String portletId = PortletKeys.WIKI;

    WikiPage page = WikiPageLocalServiceUtil.getPage(classPK);

    long plid = PortalUtil.getPlidFromPortletId(page.getGroupId(), PortletKeys.WIKI);

    if (plid == LayoutConstants.DEFAULT_PLID) {
      plid = PortalUtil.getControlPanelPlid(portletRequest);

      portletId = PortletKeys.WIKI_ADMIN;
    }

    PortletURL portletURL =
        PortletURLFactoryUtil.create(portletRequest, portletId, plid, PortletRequest.RENDER_PHASE);

    WikiNode node = page.getNode();

    portletURL.setParameter("struts_action", "/wiki/view");
    portletURL.setParameter("nodeName", node.getName());
    portletURL.setParameter("title", HtmlUtil.unescape(page.getTitle()));

    return portletURL.toString();
  }
  @Test
  public void testGetPage() throws Exception {
    WikiPage page = WikiTestUtil.addPage(_group.getGroupId(), _node.getNodeId(), true);

    WikiPage retrievedPage = WikiPageLocalServiceUtil.getPage(page.getResourcePrimKey());

    Assert.assertEquals(retrievedPage.getPageId(), page.getPageId());
  }
  @Override
  public ContainerModel getParentContainerModel(long classPK)
      throws PortalException, SystemException {

    WikiPage page = WikiPageLocalServiceUtil.getPage(classPK);

    return page.getNode();
  }
  @Override
  protected String getUniqueTitle(BaseModel<?> baseModel) {
    WikiPage page = (WikiPage) baseModel;

    String title = page.getTitle();

    return TrashUtil.getOriginalTitle(title);
  }
  @Override
  public String getRestoreMessage(PortletRequest portletRequest, long classPK)
      throws PortalException, SystemException {

    WikiPage page = WikiPageLocalServiceUtil.getPage(classPK);

    return page.getTitle();
  }
  @Test(expected = NoSuchPageResourceException.class)
  public void testDeletePage() throws Exception {
    WikiPage page =
        WikiTestUtil.addPage(
            TestPropsValues.getUserId(), _group.getGroupId(), _node.getNodeId(), "TestPage", true);

    WikiPageLocalServiceUtil.deletePage(page);

    WikiPageLocalServiceUtil.getPage(page.getResourcePrimKey());
  }
  public boolean isInTrash(long classPK) throws PortalException, SystemException {

    WikiPage page = WikiPageLocalServiceUtil.getPage(classPK);

    if (page.isInTrash() || page.isInTrashFolder()) {
      return true;
    }

    return false;
  }
  protected void addExpandoValueToPage(WikiPage page) throws Exception {
    ExpandoValue value =
        ExpandoTestUtil.addValue(
            PortalUtil.getClassNameId(WikiPage.class),
            page.getPrimaryKey(),
            RandomTestUtil.randomString());

    ExpandoBridge expandoBridge = page.getExpandoBridge();

    ExpandoColumn column = value.getColumn();

    expandoBridge.addAttribute(column.getName(), ExpandoColumnConstants.STRING, value.getString());
  }
  public void deleteTrashEntries(long[] classPKs, boolean checkPermission)
      throws PortalException, SystemException {

    for (long classPK : classPKs) {
      WikiPage page = WikiPageLocalServiceUtil.getPage(classPK);

      if (checkPermission) {
        WikiPageServiceUtil.deletePage(page.getNodeId(), page.getTitle());
      } else {
        WikiPageLocalServiceUtil.deletePage(page.getNodeId(), page.getTitle());
      }
    }
  }
  @Test(expected = DuplicatePageException.class)
  public void testRenamePageSameName() throws Exception {
    WikiPage page = WikiTestUtil.addPage(_group.getGroupId(), _node.getNodeId(), true);

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    WikiPageLocalServiceUtil.renamePage(
        TestPropsValues.getUserId(),
        _node.getNodeId(),
        page.getTitle(),
        page.getTitle(),
        true,
        serviceContext);
  }
  protected void testRevertPage(boolean hasExpandoValues) throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    String originalContent = RandomTestUtil.randomString();

    WikiPage originalPage =
        WikiTestUtil.addPage(
            TestPropsValues.getUserId(),
            _node.getNodeId(),
            RandomTestUtil.randomString(),
            originalContent,
            true,
            serviceContext);

    if (hasExpandoValues) {
      addExpandoValueToPage(originalPage);
    }

    WikiPage updatedPage1 =
        WikiTestUtil.updatePage(
            originalPage,
            TestPropsValues.getUserId(),
            originalContent + "\nAdded second line.",
            serviceContext);

    Assert.assertNotEquals(originalContent, updatedPage1.getContent());

    WikiPage updatedPage2 =
        WikiTestUtil.updatePage(
            updatedPage1,
            TestPropsValues.getUserId(),
            updatedPage1.getContent() + "\nAdded third line.",
            serviceContext);

    Assert.assertNotEquals(originalContent, updatedPage2.getContent());

    WikiPage revertedPage =
        WikiPageLocalServiceUtil.revertPage(
            TestPropsValues.getUserId(),
            _node.getNodeId(),
            updatedPage2.getTitle(),
            originalPage.getVersion(),
            serviceContext);

    Assert.assertEquals(revertedPage.getContent(), originalContent);

    checkPopulatedServiceContext(serviceContext, revertedPage, hasExpandoValues);
  }
  @Test
  public void testMoveParentPageWithRedirectPageToTrash() throws Exception {
    WikiPage[] pages =
        WikiTestUtil.addRenamedTrashedParentPage(
            group.getGroupId(), _node.getNodeId(), false, false);

    WikiPage parentPage = pages[0];
    WikiPage childPage = pages[1];
    WikiPage redirectPage = pages[2];

    Assert.assertTrue(parentPage.isInTrashExplicitly());
    Assert.assertTrue(childPage.isInTrashImplicitly());
    Assert.assertEquals(childPage.getParentTitle(), parentPage.getTitle());
    Assert.assertTrue(redirectPage.isInTrashImplicitly());
    Assert.assertEquals(redirectPage.getRedirectTitle(), parentPage.getTitle());
  }
  @Override
  public void updateTitle(long classPK, String name) throws PortalException, SystemException {

    WikiPage page = WikiPageLocalServiceUtil.getPage(classPK);

    page.setTitle(name);

    WikiPageLocalServiceUtil.updateWikiPage(page);

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

    pageResource.setTitle(name);

    WikiPageResourceLocalServiceUtil.updateWikiPageResource(pageResource);
  }
  private static boolean _hasPermission(
      PermissionChecker permissionChecker, WikiPage page, String actionId) {

    if (permissionChecker.hasOwnerPermission(
            page.getCompanyId(),
            WikiPage.class.getName(),
            page.getResourcePrimKey(),
            page.getUserId(),
            actionId)
        || permissionChecker.hasPermission(
            page.getGroupId(), WikiPage.class.getName(), page.getResourcePrimKey(), actionId)) {

      return true;
    }

    return false;
  }
  @Test
  public void testChangePageNode() throws Exception {
    WikiNode destinationNode = WikiTestUtil.addNode(_group.getGroupId());

    WikiPage page = WikiTestUtil.addPage(_group.getGroupId(), _node.getNodeId(), true);

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    WikiPageLocalServiceUtil.changeNode(
        TestPropsValues.getUserId(),
        _node.getNodeId(),
        page.getTitle(),
        destinationNode.getNodeId(),
        serviceContext);

    WikiPageLocalServiceUtil.getPage(destinationNode.getNodeId(), page.getTitle());
  }
  public void spamWikiPages(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    checkWikiPagePermission(themeDisplay.getScopeGroupId());

    long[] wikiPageIds = ParamUtil.getLongValues(actionRequest, "spamWikiPageIds");

    for (long wikiPageId : wikiPageIds) {
      WikiPage wikiPage = WikiPageLocalServiceUtil.getPageByPageId(wikiPageId);

      wikiPage.setSummary(AkismetConstants.WIKI_PAGE_MARKED_AS_SPAM);

      WikiPageLocalServiceUtil.updateWikiPage(wikiPage);
    }
  }
示例#22
0
  private Map<String, Boolean> _getLinks(WikiPage page) throws PageContentException {

    try {
      return _getEngine(page.getFormat()).getOutgoingLinks(page);
    } catch (WikiFormatException wfe) {
      return Collections.emptyMap();
    }
  }
示例#23
0
  private String _convert(
      WikiPage page, PortletURL viewPageURL, PortletURL editPageURL, String attachmentURLPrefix)
      throws PageContentException, WikiFormatException {

    LiferayPortletURL liferayViewPageURL = (LiferayPortletURL) viewPageURL;
    LiferayPortletURL liferayEditPageURL = (LiferayPortletURL) editPageURL;

    WikiEngine engine = _getEngine(page.getFormat());

    String content = engine.convert(page, viewPageURL, editPageURL, attachmentURLPrefix);

    String editPageURLString = StringPool.BLANK;

    if (editPageURL != null) {
      liferayEditPageURL.setParameter("title", "__REPLACEMENT__", false);

      editPageURLString = editPageURL.toString();

      editPageURLString = StringUtil.replace(editPageURLString, "__REPLACEMENT__", "$1");
    }

    Matcher matcher = _editPageURLPattern.matcher(content);

    content = _convertURLs(editPageURLString, matcher);

    String viewPageURLString = StringPool.BLANK;

    if (viewPageURL != null) {
      liferayViewPageURL.setParameter("title", "__REPLACEMENT__", false);

      viewPageURLString = viewPageURL.toString();

      viewPageURLString = StringUtil.replace(viewPageURLString, "__REPLACEMENT__", "$1");
    }

    matcher = _viewPageURLPattern.matcher(content);

    content = _convertURLs(viewPageURLString, matcher);

    content = _replaceAttachments(content, page.getTitle(), attachmentURLPrefix);

    return content;
  }
  @Test(expected = NoSuchPageResourceException.class)
  public void testDeleteTrashedParentPageWithImplicitTrashedChildPage() throws Exception {

    WikiPage[] pages =
        WikiTestUtil.addTrashedPageWithChildPage(_group.getGroupId(), _node.getNodeId(), false);

    WikiPage parentPage = pages[0];
    WikiPage childPage = pages[1];

    WikiPageLocalServiceUtil.deletePage(parentPage);

    try {
      WikiPageLocalServiceUtil.getPage(parentPage.getResourcePrimKey());

      Assert.fail();
    } catch (NoSuchPageResourceException nspre) {
      WikiPageLocalServiceUtil.getPage(childPage.getResourcePrimKey());
    }
  }
  protected String getPageDiff(long companyId, WikiPage latestPage, WikiPage page, Locale locale)
      throws SystemException {

    try {
      String templateId = "com/liferay/portlet/wiki/dependencies/rss.vm";

      String templateContent = ContentUtil.get(templateId);

      Template template =
          TemplateManagerUtil.getTemplate(
              TemplateManager.VELOCITY,
              new StringTemplateResource(templateId, templateContent),
              TemplateContextType.STANDARD);

      template.put("companyId", companyId);
      template.put("contextLine", Diff.CONTEXT_LINE);
      template.put("diffUtil", new DiffUtil());
      template.put("languageUtil", LanguageUtil.getLanguage());
      template.put("locale", locale);

      String sourceContent = WikiUtil.processContent(latestPage.getContent());
      String targetContent = WikiUtil.processContent(page.getContent());

      sourceContent = HtmlUtil.escape(sourceContent);
      targetContent = HtmlUtil.escape(targetContent);

      List<DiffResult>[] diffResults =
          DiffUtil.diff(
              new UnsyncStringReader(sourceContent), new UnsyncStringReader(targetContent));

      template.put("sourceResults", diffResults[0]);
      template.put("targetResults", diffResults[1]);

      UnsyncStringWriter unsyncStringWriter = new UnsyncStringWriter();

      template.processTemplate(unsyncStringWriter);

      return unsyncStringWriter.toString();
    } catch (Exception e) {
      throw new SystemException(e);
    }
  }
示例#26
0
  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }

    if (!(obj instanceof WikiPage)) {
      return false;
    }

    WikiPage wikiPage = (WikiPage) obj;

    long primaryKey = wikiPage.getPrimaryKey();

    if (getPrimaryKey() == primaryKey) {
      return true;
    } else {
      return false;
    }
  }
  @Test
  public void testDeleteTrashedParentPageWithExplicitTrashedChildPage() throws Exception {

    WikiPage[] pages =
        WikiTestUtil.addTrashedPageWithChildPage(_group.getGroupId(), _node.getNodeId(), true);

    WikiPage parentPage = pages[0];
    WikiPage childPage = pages[1];

    WikiPageLocalServiceUtil.deletePage(parentPage);

    try {
      WikiPageLocalServiceUtil.getPage(parentPage.getResourcePrimKey());

      Assert.fail();
    } catch (NoSuchPageResourceException nspre) {
      childPage = WikiPageLocalServiceUtil.getPageByPageId(childPage.getPageId());

      Assert.assertNull(childPage.fetchParentPage());
    }
  }
  protected void testRestorePageFromTrash(boolean hasExpandoValues) throws Exception {

    WikiPage page = WikiTestUtil.addPage(_group.getGroupId(), _node.getNodeId(), true);

    if (hasExpandoValues) {
      addExpandoValueToPage(page);
    }

    page =
        WikiPageLocalServiceUtil.movePageToTrash(
            TestPropsValues.getUserId(), _node.getNodeId(), page.getTitle());

    WikiPageLocalServiceUtil.restorePageFromTrash(TestPropsValues.getUserId(), page);

    WikiPage restoredPage = WikiPageLocalServiceUtil.getPage(page.getResourcePrimKey());

    Assert.assertNotNull(restoredPage);

    if (hasExpandoValues) {
      ExpandoBridge expandoBridge = page.getExpandoBridge();

      ExpandoBridge restoredExpandoBridge = restoredPage.getExpandoBridge();

      AssertUtils.assertEquals(
          restoredExpandoBridge.getAttributes(), expandoBridge.getAttributes());
    }
  }
  @Override
  public void checkDuplicateTrashEntry(TrashEntry trashEntry, long containerModelId, String newName)
      throws PortalException, SystemException {

    WikiPage page = WikiPageLocalServiceUtil.getPage(trashEntry.getClassPK());

    if (containerModelId == TrashEntryConstants.DEFAULT_CONTAINER_ID) {
      containerModelId = page.getNodeId();
    }

    String restoredTitle = page.getTitle();

    if (Validator.isNotNull(newName)) {
      restoredTitle = newName;
    }

    String originalTitle = TrashUtil.stripTrashNamespace(restoredTitle);

    WikiPageResource pageResource =
        WikiPageResourceLocalServiceUtil.fetchPageResource(containerModelId, originalTitle);

    if (pageResource != null) {
      DuplicateEntryException dee = new DuplicateEntryException();

      WikiPage duplicatePage = WikiPageLocalServiceUtil.getPage(pageResource.getResourcePrimKey());

      dee.setDuplicateEntryId(duplicatePage.getPageId());
      dee.setOldName(duplicatePage.getTitle());
      dee.setTrashEntryId(trashEntry.getEntryId());

      throw dee;
    }
  }
  @Override
  public boolean equals(Object obj) {
    if (obj == null) {
      return false;
    }

    WikiPage wikiPage = null;

    try {
      wikiPage = (WikiPage) obj;
    } catch (ClassCastException cce) {
      return false;
    }

    long primaryKey = wikiPage.getPrimaryKey();

    if (getPrimaryKey() == primaryKey) {
      return true;
    } else {
      return false;
    }
  }