@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; }
/** * For <a href="http://developer.atlassian.com/jira/browse/MARK-42">MARK-42</a> * * @return Returns a page ID so that suggested labels can be shown. */ @SuppressWarnings("unused") public long getPageId() { return null == page ? 0 : page.getId(); }
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); } }
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 void updatePageContent(Page pageToUpdate, InputContext inputContext) throws IOException, CloneNotSupportedException { String xhtml = getInputContentAsString(inputContext); ContentEntityObject previousVersionOfPage = (ContentEntityObject) pageToUpdate.clone(); User user = AuthenticatedUserThreadLocal.getUser(); pageToUpdate.setBodyAsString(xhtml); pageToUpdate.setLastModificationDate(new Date()); pageToUpdate.setLastModifierName(user.getName()); pageManager.saveContentEntity(pageToUpdate, previousVersionOfPage, null); }
Page newChildPage = new Page(); newChildPage.setTitle(generateUniquePageTitle(childPage.getSpaceKey(), childPage.getTitle())); newChildPage.setSpace(childPage.getSpace()); newChildPage.setBodyContent(childPage.getBodyContent()); newChildPage.setParentPage(parent); newChildPage.setCreatorName(user.getName()); for (Attachment attachment : childPage.getAttachments()) { newChildPage.addAttachment(newAttachment); parent.addChild(newChildPage); if (childPage.hasChildren()) { List<Page> childPageChildren = childPage.getChildren(); addChild(childPageChildren, newChildPage);
Page bookmarkPage = StringUtils.isBlank(getBookmarkPageId()) ? new Page() : pageManager.getPage(Long.parseLong(getBookmarkPageId())); String bookmarkTitle = validateTitle(StringUtils.defaultString(StringUtils.trim(getTitle()))); String bookmarkWikiContent = getBookmarkWikiContent(); if (!bookmarkPage.isPersistent()) bookmarkPage.setSpace(bookmarkSpace); bookmarkPage.setTitle(bookmarkTitle); setBookmarkPageContent(bookmarkPage, bookmarkWikiContent); bookmarkParent.addChild(bookmarkPage); LOG.debug(String.format("Create new bookmark page with ID %s", bookmarkPage.getIdAsString())); Page bookmarkPageOriginal = (Page) bookmarkPage.clone(); if (!(StringUtils.equals(bookmarkTitle, bookmarkPageOriginal.getTitle()) && (StringUtils.equals(bookmarkWikiContent, bookmarkPageOriginal.getBodyAsString())))) bookmarkPage.setTitle(bookmarkTitle); setBookmarkPageContent(bookmarkPage, bookmarkWikiContent); pageManager.saveContentEntity(bookmarkPage, bookmarkPageOriginal, null); LOG.debug(String.format("Updated bookmark page with ID %s", bookmarkPage.getIdAsString())); Space oldBookmarkSpace = bookmarkPage.getSpace(); if (!StringUtils.equals(oldBookmarkSpace.getKey(), bookmarkSpace.getKey())) pageManager.movePageAsChild(bookmarkPage, bookmarkParent);
private boolean isPageContentAttachment(Page aPage, String resourceName) { return StringUtils.equals(resourceName, aPage.getTitle() + PageContentResourceImpl.DISPLAY_NAME_SUFFIX); }
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); } }
/** * Render each of the nodes (Pages) in the supplied List to an HTML formatted String. * * @param nodes The list of nodes to be rendered to HTML * @param tocBuilder the class to be informed as nodes relevant to the table of contents are processed * @param bookmarksBuilder the class to be informed as nodes relevant to the bookmarks are processed * @param level the level in the ContentTree currently being processed. * @param fullContentTree the full content tree from which the nodes being rendered are taken. * @param progress a class interested in progress updates about the process * @return a list of the Strings where each String is an HTML version of the page content for each note. */ private List<String> renderContentTreeNodes(List<ContentNode> nodes, TocBuilder tocBuilder, BookmarksBuilder bookmarksBuilder, int level, ContentTree fullContentTree, PdfExportProgressMonitor progress) { List<String> renderedPagesContent = new ArrayList<>(); for (ContentNode node : nodes) { Page page = node.getPage(); String renderedHtml = renderToHtml(page, fullContentTree); renderedPagesContent.add(renderedHtml); progress.completedExportedHtmlConversionForPage(String.valueOf(page.getId()), page.getTitle()); tocBuilder.addEntry(level, page.getTitle()); bookmarksBuilder.beginEntry(page.getTitle()); List<ContentNode> children = node.getChildren(); if (children != null && !children.isEmpty()) { renderedPagesContent.addAll(renderContentTreeNodes(children, tocBuilder, bookmarksBuilder, level + 1, fullContentTree, progress)); } bookmarksBuilder.endEntry(); } return renderedPagesContent; }
if (permissionManager.hasCreatePermission(user, thisPage.getSpace(), Page.class)) { ResourceStates resourceStates = ((ConfluenceDavSession) getSession()).getResourceStates(); else if (StringUtils.equals(resourceName, thisPage.getTitle() + ".url")) { resourceStates.unhideContentUrl(thisPage); } else if (StringUtils.equals(resourceName, ".DS_Store")) {
public Page getBookmarkParent(Space space, boolean create) { Page parentPage = null; if (space != null) { parentPage = pageManager.getPage(space.getKey(), BOOKMARK_PARENT_PAGE); if (parentPage == null && create) { if (LOG.isDebugEnabled()) LOG.debug("bookmark parent page doesn't exist, creating in space: " + space.getKey()); parentPage = new Page(); parentPage.setSpace(space); parentPage.setTitle(BOOKMARK_PARENT_PAGE); parentPage.setBodyAsString(getBookmarkParentPageContent(space, parentPage)) ; pageManager.saveContentEntity(parentPage, null); if (LOG.isDebugEnabled()) LOG.debug("Create " + BOOKMARK_PARENT_PAGE + " for space " + space.getKey()); } } return parentPage; }
ResourceStates resourceStates = ((ConfluenceDavSession) getSession()).getResourceStates(); if (StringUtils.equals(resourceName, thisPage.getTitle() + PageContentResourceImpl.DISPLAY_NAME_SUFFIX)) { resourceStates.hideContentMarkup(thisPage); } else if (StringUtils.equals(resourceName, thisPage.getTitle() + PageUrlResourceImpl.DISPLAY_NAME_SUFFIX)) { resourceStates.hideContentUrl(thisPage); } else if (StringUtils.equals(resourceName, PageVersionsResourceImpl.DISPLAY_NAME)) { resourceStates.hideContentExports(thisPage); } else { List<Page> childPages = new ArrayList<Page>(thisPage.getChildren()); @SuppressWarnings("unchecked") List<Attachment> attachments = new ArrayList<Attachment>(thisPage.getLatestVersionsOfAttachments()); User user = AuthenticatedUserThreadLocal.getUser(); if (StringUtils.equals(resourceName, childPage.getTitle())) { if (permissionManager.hasPermission(user, Permission.REMOVE, childPage)) { pageManager.trashPage(childPage);
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 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 Document createDocument(Page page, LinkRenderingDetails linkDetails, DecorationPolicy decoration) { Document xhtml; ContentTree tree = new ContentTree(); tree.addRootNode(new ContentNode(page)); try { xhtml = intermediateHtmlBuilder.buildHtml(tree, page.getSpace(), linkDetails, decoration); } catch (ImportExportException e) { log.error("error build xml dom", e); throw new RuntimeException(e); } return xhtml; }
private File checkWriteToTempFile() throws IOException { Page thisPage = getPage(); File exportedContent = new File(GeneralUtil.getConfluenceTempDirectory(), "webdav-" + thisPage.getIdAsString() + getExportSuffix()); if (!exportedContent.exists() || exportedContent.lastModified() < thisPage.getLastModificationDate().getTime()) { InputStream in = null; OutputStream out = null; try { in = getContentInternal(); out = new BufferedOutputStream(new FileOutputStream(exportedContent)); IOUtils.copy(in, out); } finally { IOUtils.closeQuietly(out); IOUtils.closeQuietly(in); } } return exportedContent; }
setPage(new Page()); setSpaceKey(bookmarkPage.getSpaceKey()); setDescription(bookmark.getDescription());
if (getPage().getTitle().equals(displayName[displayName.length - 1])) { uniqueName = generateUniquePageTitle(getPage().getSpaceKey(), getPage().getTitle()); Page newPage = new Page(); newPage.setTitle(uniqueName); newPage.setSpace(targetSpace); newPage.setBodyContent(getPage().getBodyContent()); newPage.setParentPage(parentPage); newPage.setCreatorName(user.getName()); for (Attachment attachment : getPage().getAttachments()) { Attachment newAttachment = new Attachment(); newPage.addAttachment(newAttachment); parentPage.addChild(newPage); if (getPage().hasChildren()) { List<Page> childPages = getPage().getChildren(); addChild(childPages, newPage);
private boolean isAttachmentRepresentingTempVersionOfPageContent(String resourceName) { return StringUtils.equals( "._" + getPage().getTitle() + PageContentResourceImpl.DISPLAY_NAME_SUFFIX, resourceName ); }