private boolean isPageContentAttachment(Page aPage, String resourceName) { return StringUtils.equals(resourceName, aPage.getTitle() + PageContentResourceImpl.DISPLAY_NAME_SUFFIX); }
private boolean isAttachmentRepresentingTempVersionOfPageContent(String resourceName) { return StringUtils.equals( "._" + getPage().getTitle() + PageContentResourceImpl.DISPLAY_NAME_SUFFIX, resourceName ); }
public String getDisplayName() { return getPage().getTitle() + DISPLAY_NAME_SUFFIX; } }
public String getDisplayName() { return getPage().getTitle() + DISPLAY_NAME_SUFFIX; } }
public String getDisplayName() { return getPage().getTitle() + DISPLAY_NAME_SUFFIX; } }
public String getDisplayName() { return getPage().getTitle() + DISPLAY_NAME_SUFFIX; }
public AlphabeticPageListing(List<Page> pages) { pageMap = new HashMap<>(); for (Page page : pages) { char c = Character.toUpperCase(page.getTitle().charAt(0)); if (Character.isDigit(c)) addToMap("0-9", page); else if (c >= 'A' && c <= 'Z') addToMap(Character.toString(c), page); else addToMap("@", page); } }
private boolean isPagePathSameAsBreadcrumbs(String[] pathTokensAfterSpace, Page page) { if (!webdavSettingsManager.isStrictPageResourcePathCheckingDisabled()) { @SuppressWarnings("unchecked") List<Page> pageAncestors = page.getAncestors(); Collection<Page> uniqueAncestors = getUniqueAncestors(pageAncestors); LOGGER.debug("Page ancestors: " + pageAncestors); LOGGER.debug("Unique ancestors: " + uniqueAncestors); LOGGER.debug("Expected ancestor path: " + StringUtils.join(pathTokensAfterSpace, "/")); if (pathTokensAfterSpace.length == uniqueAncestors.size()) { for (int i = 0; i < pathTokensAfterSpace.length; ++i) if (!StringUtils.equals(pathTokensAfterSpace[i], pageAncestors.get(i).getTitle())) return false; return true; } return false; } else { LOGGER.debug("Strict page checking disabled. So I'll just assume the paths are ok."); return true; } }
private boolean isPathPointingToPageContent(String[] resourcePathTokens) { if (resourcePathTokens.length >= 5 && (StringUtils.equals(GlobalSpacesResourceImpl.DISPLAY_NAME, resourcePathTokens[1]) || StringUtils.equals(PersonalSpacesResourceImpl.DISPLAY_NAME, resourcePathTokens[1]))) { String spaceKey = resourcePathTokens[2]; Space space = spaceManager.getSpace(spaceKey); Page page = pageManager.getPage(spaceKey, resourcePathTokens[resourcePathTokens.length - 2]); return null != space && !hasAliasInTokens(resourcePathTokens, 3) && null != page && StringUtils.equals(page.getTitle() + PageContentResourceImpl.DISPLAY_NAME_SUFFIX, resourcePathTokens[resourcePathTokens.length - 1]); } return false; }
private boolean isPathPointingToPageUrl(String[] resourcePathTokens) { if (resourcePathTokens.length >= 5 && (StringUtils.equals(GlobalSpacesResourceImpl.DISPLAY_NAME, resourcePathTokens[1]) || StringUtils.equals(PersonalSpacesResourceImpl.DISPLAY_NAME, resourcePathTokens[1]))) { String spaceKey = resourcePathTokens[2]; Space space = spaceManager.getSpace(spaceKey); Page page = pageManager.getPage(spaceKey, resourcePathTokens[resourcePathTokens.length - 2]); return null != space && !hasAliasInTokens(resourcePathTokens, 3) && null != page && StringUtils.equals(page.getTitle() + PageUrlResourceImpl.DISPLAY_NAME_SUFFIX, resourcePathTokens[resourcePathTokens.length - 1]); } return false; }
private void populateLinkFixer(LinkFixer linkFixer, ContentTree contentTree, Collection<Page> additionalInternalPages) { List<ContentNode> contentNodes = contentTree.getAllContentNodes(); for (ContentNode node : contentNodes) { Page p = node.getPage(); linkFixer.addPage(p.getIdAsString(), p.getTitle()); } additionalInternalPages.forEach(p -> linkFixer.addPage(p.getIdAsString(), p.getTitle())); }
private StringBuilder getContentEntityWikiLink( ContentEntityObject content, PageContext ctx ) { StringBuilder buff = new StringBuilder(); if ( content instanceof SpaceContentEntityObject ) { SpaceContentEntityObject spaceContent = (SpaceContentEntityObject) content; if ( !StringUtils.equals( spaceContent.getSpaceKey(), ctx.getSpaceKey() ) ) buff.append( spaceContent.getSpaceKey() ).append( ":" ); if ( content instanceof Page ) { Page page = (Page) content; buff.append( page.getTitle() ); } else if ( content instanceof BlogPost ) { BlogPost blogPost = (BlogPost) content; buff.append( blogPost.getDatePath() ).append( "/" ).append( blogPost.getTitle() ); } else { buff.append( "$" ).append( content.getIdAsString() ); } } else if ( content instanceof PersonalInformation ) { buff.append( "~" ).append( ( (PersonalInformation) content ).getUsername() ); } else { buff.append( "$" ).append( content.getIdAsString() ); } return buff; } }
private DavResourceLocator[] getChildPageResourceLocators() { DavResourceLocator locator = getLocator(); Page page = getPage(); List<Page> childrenPages = permissionManager.getPermittedEntities(AuthenticatedUserThreadLocal.getUser(), Permission.VIEW, page.getChildren()); StringBuffer contentPathBuffer = new StringBuffer(); List<DavResourceLocator> pageResourceLocators = new ArrayList<DavResourceLocator>(); String parentResourcePath = getParentResourcePath(); LOGGER.debug("Found " + (null == childrenPages ? 0 : childrenPages.size()) + " child pages of " + page + "."); for (Page childPage : childrenPages) { DavResourceLocator pageResourceLocator; contentPathBuffer.setLength(0); contentPathBuffer.append(parentResourcePath) .append('/').append(page.getTitle()) .append('/').append(childPage.getTitle()); LOGGER.debug("Found child page of \"" + page + "\", \"" + childPage + "\""); pageResourceLocator = locator.getFactory().createResourceLocator( locator.getPrefix(), locator.getWorkspacePath(), contentPathBuffer.toString(), false ); LOGGER.debug("Created a " + pageResourceLocator.getClass() + " with the following details:\"\n" + "\nPrefix: " + locator.getPrefix() + "\nWorkspace path: " + locator.getWorkspacePath() + "\nResource path: " + contentPathBuffer.toString()); pageResourceLocators.add(pageResourceLocator); } return pageResourceLocators.toArray(new DavResourceLocator[pageResourceLocators.size()]); }
private DavResourceLocator[] getPageResourceLocators() { DavResourceLocator locator = getLocator(); Space space = getSpace(); @SuppressWarnings("unchecked") List<Page> topLevelPages = permissionManager.getPermittedEntities(AuthenticatedUserThreadLocal.getUser(), Permission.VIEW, pageManager.getTopLevelPages(space)); StringBuffer contentPathBuffer = new StringBuffer(); List<DavResourceLocator> pageResourceLocators = new ArrayList<DavResourceLocator>(); String parentResourcePath = getParentResourcePath(); for (Page topLevelPage : topLevelPages) { DavResourceLocator pageResourceLocator; contentPathBuffer.setLength(0); contentPathBuffer.append(parentResourcePath) .append('/').append(spaceKey) .append('/').append(topLevelPage.getTitle()); pageResourceLocator = locator.getFactory().createResourceLocator( locator.getPrefix(), locator.getWorkspacePath(), contentPathBuffer.toString(), false ); pageResourceLocators.add(pageResourceLocator); } return pageResourceLocators.toArray(new DavResourceLocator[pageResourceLocators.size()]); }
private PdfNode createPdfTreeNode(ContentNode contentNode, String contextPath, PdfExportProgressMonitor progress, Collection<Page> internalPages, SpaceExportMetrics spaceExportMetrics, PageExportMetrics pageExportMetrics) throws ImportExportException { spaceExportMetrics.getPageExportMetrics().add(pageExportMetrics); final Page page = contentNode.getPage(); progress.performingHtmlToPdfConversionForPage(page.getTitle()); final RenderedPdfFile file = createPdf(page, contextPath, new LinkRenderingDetails(internalPages, NORMALISE), page.getTitle(), pageExportMetrics, headerAndFooter()); PdfNode node = new PdfNode(page.getTitle(), file); for (ContentNode child : contentNode.getChildren()) { final PageExportMetrics childInfo = new PageExportMetrics(); node.addChild(createPdfTreeNode(child, contextPath, progress, internalPages, spaceExportMetrics, childInfo)); } return node; }
@Override public Map<String, ?> getPage(String authenticationToken, String pageId) { Page page = pageManager.getPage(Long.parseLong(pageId)); Map<String, Object> pageStruct = null; if (null != page && permissionManager.hasPermission(AuthenticatedUserThreadLocal.getUser(), Permission.VIEW, page)) { pageStruct = new Hashtable<String, Object>(); pageStruct.put("id", page.getIdAsString()); pageStruct.put("spaceKey", page.getSpaceKey()); Page parentPage = page.getParent(); if (null != parentPage) pageStruct.put("parentId", page.getParent().getIdAsString()); pageStruct.put("title", page.getTitle()); pageStruct.put("version", page.getVersion()); pageStruct.put("content", page.getBodyAsString()); if (StringUtils.isNotBlank(page.getCreatorName())) pageStruct.put("creator", page.getCreatorName()); pageStruct.put("created", page.getCreationDate()); if (StringUtils.isNotBlank(page.getLastModifierName())) pageStruct.put("lastModifier", page.getLastModifierName()); pageStruct.put("lastModified", page.getLastModificationDate()); } return pageStruct; }
public void move(DavResource davResource) throws DavException { Page thisPage = getPage(); String[] destinationResourcePathComponents = StringUtils.split(davResource.getResourcePath(), '/'); User user = AuthenticatedUserThreadLocal.getUser(); if (!isDestinationPathValid(destinationResourcePathComponents)) throw new DavException( HttpServletResponse.SC_FORBIDDEN, "Cannot move " + getResourcePath() + " to " + StringUtils.join(destinationResourcePathComponents, '/')); String destinationSpaceKey = destinationResourcePathComponents[2]; String destinationPageTitle = destinationResourcePathComponents[destinationResourcePathComponents.length - 1]; if (!permissionManager.hasPermission(user, Permission.EDIT, thisPage)) throw new DavException(HttpServletResponse.SC_FORBIDDEN, "Permission denied to move " + thisPage); if (!StringUtils.equals(thisPage.getTitle(), destinationPageTitle)) { /* Page rename */ if (null != pageManager.getPage(destinationSpaceKey, destinationPageTitle)) throw new DavException(HttpServletResponse.SC_FORBIDDEN, StringUtils.join(destinationResourcePathComponents, '/') + " points to an existing page."); pageManager.renamePage(thisPage, destinationPageTitle); } else { /* Page move */ String destinationPageParentTitle = destinationResourcePathComponents.length > 4 ? destinationResourcePathComponents[destinationResourcePathComponents.length - 2] : null; Page destinationPageParent = null == destinationPageParentTitle ? null : pageManager.getPage(destinationSpaceKey, destinationPageParentTitle); Space destinationSpace = spaceManager.getSpace(destinationSpaceKey); pageManager.movePageAsChild(thisPage, destinationPageParent); } }
private void createPage(String newPageTitle) throws DavException { Space thisSpace = getSpace(); Page newPage = new Page(); newPage.setSpace(thisSpace); /* Check for invalid page title */ if (PageResourceImpl.isPageTitleValid(newPageTitle)) { /* Check for (A Document Being Saved By Text Edit) created by TextEdit and stop the page creation */ ConfluenceDavSession confluenceDavSession = (ConfluenceDavSession) getSession(); if (isTextEditCreatingTempFolder(newPageTitle, confluenceDavSession)) throw new DavException(HttpServletResponse.SC_FORBIDDEN, "This plugin does not allow creation of page with the title \"" + TEXTEDIT_TEMP_FOLDER_NAME + "\". See http://developer.atlassian.com/jira/browse/WBDV-143 for more information."); newPage.setTitle(newPageTitle); /* Check for duplicate page creation. */ if (null == pageManager.getPage(newPage.getSpaceKey(), newPage.getTitle())) { newPage.setCreatorName(AuthenticatedUserThreadLocal.getUser().getName()); pageManager.saveContentEntity(newPage, null); } else { throw new DavException(HttpServletResponse.SC_BAD_REQUEST, "Page creation denied. Page " + newPageTitle + " is not unique in space " + newPage.getSpaceKey()); } } else { throw new DavException(HttpServletResponse.SC_FORBIDDEN, "Page creation denied. New page name has invalid characters in the title: " + newPageTitle); } }
newChildPage.setTitle(generateUniquePageTitle(childPage.getSpaceKey(), childPage.getTitle())); newChildPage.setSpace(childPage.getSpace()); newChildPage.setBodyContent(childPage.getBodyContent());
private void createPage(String newPageTitle) throws DavException { Page thisPage = getPage(); Page newPage = new Page(); newPage.setSpace(thisPage.getSpace()); /* Check for invalid page title */ if (isPageTitleValid(newPageTitle)) { /* Check for (A Document Being Saved By Text Edit) created by TextEdit and stop the page creation */ ConfluenceDavSession confluenceDavSession = (ConfluenceDavSession) getSession(); if (isTextEditCreatingTempFolder(newPageTitle, confluenceDavSession)) throw new DavException(HttpServletResponse.SC_FORBIDDEN, "This plugin does not allow creation of page with the title \"" + TEXTEDIT_TEMP_FOLDER_NAME + "\". See http://developer.atlassian.com/jira/browse/WBDV-143 for more information."); newPage.setTitle(newPageTitle); /* Check for duplicate page creation. */ if (null == pageManager.getPage(newPage.getSpaceKey(), newPage.getTitle())) { newPage.setParentPage(thisPage); newPage.setCreatorName(AuthenticatedUserThreadLocal.getUser().getName()); thisPage.addChild(newPage); pageManager.saveContentEntity(newPage, null); } else { throw new DavException(HttpServletResponse.SC_FORBIDDEN, "Page creation denied. Page " + newPageTitle + " is not unique in space " + newPage.getSpaceKey()); } } else { throw new DavException(HttpServletResponse.SC_FORBIDDEN, "Page creation denied. New page name has invalid characters in the title: " + newPageTitle); } }