public Attachment getAttachment() { if (null == attachment) attachment = attachmentManager.getAttachment(getContentEntityObject(), attachmentName); return attachment; }
private boolean isSameImage(Attachment anAttachment, byte[] chartImageBytes) throws IOException { InputStream attachmentInput = attachmentManager.getAttachmentData(anAttachment); try { return IOUtils.contentEquals(attachmentInput, new ByteArrayInputStream(chartImageBytes)); } finally { IOUtils.closeQuietly(attachmentInput); } }
@SuppressWarnings({"unchecked"}) private void addContentAttachmentsToList(ContentEntityObject content, List<Attachment> attachments) { if (content != null) attachments.addAll(attachmentManager.getLatestVersionsOfAttachments(content)); }
public void execute() throws Exception { Page page = pageManager.getPage(getContainingPageId()); if (null != page) { Attachment attachment = attachmentManager.getAttachment(page, getFileName()); if (null != attachment) attachmentManager.removeAttachmentFromServer(attachment); } }
public static void addOrUpdateAttachment(AttachmentManager attachmentManager, ContentEntityObject ceo, String fileName, InputContext inputContext) throws IOException, CloneNotSupportedException { Attachment attachment = attachmentManager.getAttachment(ceo, fileName); Attachment previousVersionOfAttachment = null; File inputContentFile = null; attachmentManager.saveAttachment(attachment, previousVersionOfAttachment, inputContentStream);
InputStream attachmentInput = null; try { attachmentInput = getAttachmentManager().getAttachmentData(attachment); davResource.getCollection().addMember( davResource, } finally { IOUtils.closeQuietly(attachmentInput); getAttachmentManager().removeAttachmentFromServer(attachment); getAttachmentManager().moveAttachment(attachment, destinationAttachmentName, destinationPage); } else { throw new DavException(HttpServletResponse.SC_FORBIDDEN,
attachmentInput = getAttachmentManager().getAttachmentData(attachment); getAttachmentManager().saveAttachment(attachmentCopy, null, attachmentInput); } catch (IOException e) { LOGGER.error("Error copying " + attachment + " to " + StringUtils.join(destinationResourcePathComponents, '/'));
private Attachment saveChartImageAsAttachment(ContentEntityObject attachmentContent, String attachmentMimeType, String attachmentFileName, byte[] chartImageBytes, String comment, Attachment currentVersionOfAttachment) throws IOException { Attachment previousVersionOfAttachment = null != currentVersionOfAttachment && currentVersionOfAttachment.isPersistent() ? (Attachment) currentVersionOfAttachment.clone() : null; Attachment chartImageAttachment = null == previousVersionOfAttachment ? new Attachment() : currentVersionOfAttachment; chartImageAttachment.setContainer(attachmentContent); chartImageAttachment.setMediaType(attachmentMimeType); chartImageAttachment.setVersionComment(comment); chartImageAttachment.setFileName(attachmentFileName); chartImageAttachment.setFileSize(chartImageBytes.length); if(null == previousVersionOfAttachment) attachmentContent.addAttachment(chartImageAttachment); attachmentManager.saveAttachment(chartImageAttachment, previousVersionOfAttachment, new ByteArrayInputStream(chartImageBytes)); return chartImageAttachment; }
attachmentManager.removeAttachmentFromServer(theAttachment); theAttachment = null;
public void removeMember(DavResource davResource) throws DavException { String[] pathComponents = StringUtils.split(davResource.getResourcePath(), '/'); String resourceName = pathComponents[pathComponents.length - 1]; Space thisSpace = getSpace(); User user = AuthenticatedUserThreadLocal.getUser(); if (isResourceSpaceDescription(thisSpace, resourceName)) { if (permissionManager.hasPermission(user, Permission.EDIT, thisSpace)) ((ConfluenceDavSession) getSession()).getResourceStates().hideSpaceDescription(thisSpace); else throw new DavException(HttpServletResponse.SC_FORBIDDEN, "No permission to edit " + thisSpace); } else { Page pageToRemove = pageManager.getPage(thisSpace.getKey(), resourceName); if (null == pageToRemove) { ContentEntityObject spaceDesc = getSpace().getDescription(); Attachment attachmentToRemove = attachmentManager.getAttachment(spaceDesc, resourceName); if (null != attachmentToRemove) { attachmentManager.removeAttachmentFromServer(attachmentToRemove); } } else { if (permissionManager.hasPermission( AuthenticatedUserThreadLocal.getUser(), Permission.REMOVE, pageToRemove)) { pageManager.trashPage(pageToRemove); } else { throw new DavException(HttpServletResponse.SC_FORBIDDEN, "Forbidden to delete " + pageToRemove); } } } }
InputStream in = attachmentManager.getAttachmentData(attachment); attachmentManager.saveAttachment(newAttachment, null, in); in.close(); } catch (IOException e) {
attachmentManager.saveAttachment(newAttachment, null, in); in.close(); } catch (IOException e) {
private boolean isPathPointingToPageAttachment(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 && null != attachmentManager.getAttachment(page, resourcePathTokens[resourcePathTokens.length - 1]); } return false; }
private DavResourceLocator[] getPageAttachmentResourceLocators() { DavResourceLocator locator = getLocator(); List<Attachment> attachments = attachmentManager.getLatestVersionsOfAttachments(getPage()); StringBuffer contentPathBuffer = new StringBuffer(); List<DavResourceLocator> pageAttachmentResourceLocators = new ArrayList<DavResourceLocator>(); String parentResourcePath = getParentResourcePath(); for (Attachment attachment : attachments) { DavResourceLocator pageAttachmentResourceLocator; contentPathBuffer.setLength(0); contentPathBuffer.append(parentResourcePath) .append('/').append(pageTitle) .append('/').append(attachment.getFileName()); pageAttachmentResourceLocator = locator.getFactory().createResourceLocator( locator.getPrefix(), locator.getWorkspacePath(), contentPathBuffer.toString(), false ); pageAttachmentResourceLocators.add(pageAttachmentResourceLocator); } return pageAttachmentResourceLocators.toArray(new DavResourceLocator[pageAttachmentResourceLocators.size()]); }
public InputStream getContent() { return attachmentManager.getAttachmentData(getAttachment()); }
private boolean isPathPointingSpaceAttachment(String[] resourcePathTokens) { if (resourcePathTokens.length == 4 && !StringUtils.equals(resourcePathTokens[resourcePathTokens.length - 1], BlogPostsResourceImpl.DISPLAY_NAME)) { Space space = spaceManager.getSpace(resourcePathTokens[2]); return null != space && null == pageManager.getPage(space.getKey(), resourcePathTokens[3]) && null != attachmentManager.getAttachment(space.getDescription(), resourcePathTokens[3]); } return false; } }
ContentEntityObject spaceDesc = thisSpace.getDescription(); @SuppressWarnings("unchecked") List<Attachment> attachments = attachmentManager.getLatestVersionsOfAttachments(spaceDesc); StringBuffer contentPathBuffer = new StringBuffer(); List<DavResourceLocator> resourceLocators = new ArrayList<DavResourceLocator>();
ConfluenceEntityObject page = findEntityForWikiLink( spaceKey, pageTitle, addPart( processed, LinkPart.ATTACHMENT_NAME ) ); if ( page instanceof ContentEntityObject ) { content = attachmentManager.getAttachment( (ContentEntityObject) page, attachmentName );
private DataHandler createAvatarDataHandler(User user) throws MessagingException, IOException { PropertySet propertySet = userAccessor.getPropertySet(user); if (propertySet == null) return createWebResourceDataHandler(ProfilePictureInfo.DEFAULT_PROFILE_PATH); String profilePicture = propertySet.getString(UserPreferencesKeys.PROPERTY_USER_PROFILE_PICTURE); if (profilePicture == null) { return createWebResourceDataHandler(ProfilePictureInfo.DEFAULT_PROFILE_PATH); } if (profilePicture.startsWith(UserAccessor.PROFILE_PICTURE_BUILTIN_PATH)) { return createWebResourceDataHandler(profilePicture); } PersonalInformation personalInformation = personalInformationManager.getPersonalInformation(user); if (personalInformation == null) return createWebResourceDataHandler(ProfilePictureInfo.DEFAULT_PROFILE_PATH); Attachment a = attachmentManager.getAttachment(personalInformation, profilePicture); if (a != null) { return new DataHandler(new ProfileImageDataSource(new ByteArrayDataSource(a.getContentsAsStream(), a.getContentType()))); } return null; }
resourceStates.unhideAttachment(attachmentManager.getAttachment(thisPage, resourceName)); } else { throw new DavException(HttpServletResponse.SC_FORBIDDEN, "Attachment creation denied. File name contains invalid characters ['&', '+', '?', '|', '=']: " + resourceName);