/** * Creates an {@link AttachmentReference} from a file name and a reference to the document holding that file. * * @param documentReference a reference to the document the file is attached to * @param fileName the name of a file attached to a document * @return a reference to the specified attachment * @since 2.5M2 */ public AttachmentReference createAttachmentReference(DocumentReference documentReference, String fileName) { return new AttachmentReference(fileName, documentReference); }
/** * Creates an {@link AttachmentReference} from a file name and a reference to the document holding that file. * * @param documentReference a reference to the document the file is attached to * @param fileName the name of a file attached to a document * @return a reference to the specified attachment * @since 2.5M2 */ public AttachmentReference createAttachmentReference(DocumentReference documentReference, String fileName) { return new AttachmentReference(fileName, documentReference); }
@Override public AttachmentReference replaceParent(EntityReference oldParent, EntityReference newParent) { if (newParent == oldParent) { return this; } return new AttachmentReference(this, oldParent, newParent); }
@Override public AttachmentReference replaceParent(EntityReference newParent) { if (newParent == getParent()) { return this; } return new AttachmentReference(this, newParent); } }
@Override public EntityReference next() { Object[] item = this.data.next(); return new AttachmentReference(String.valueOf(item[1]), HibernateDeletedAttachmentsReader.this.resolver.resolve(String.valueOf(item[0]))); }
/** * {@inheritDoc} * @see org.xwiki.model.reference.AttachmentReferenceResolver#resolve */ public AttachmentReference resolve(String attachmentReferenceRepresentation, Object... parameters) { return new AttachmentReference(this.entityReferenceResolver.resolve( attachmentReferenceRepresentation, EntityType.ATTACHMENT, parameters)); } }
/** * {@inheritDoc} * * @see org.xwiki.model.reference.AttachmentReferenceResolver#resolve */ public AttachmentReference resolve(String attachmentReferenceRepresentation, Object... parameters) { return new AttachmentReference(this.entityReferenceResolver.resolve( attachmentReferenceRepresentation, EntityType.ATTACHMENT, parameters)); } }
@Override public AttachmentReference resolve(EntityReference attachmentReferenceRepresentation, Object... parameters) { if (attachmentReferenceRepresentation instanceof AttachmentReference) { return (AttachmentReference) attachmentReferenceRepresentation; } return new AttachmentReference(this.entityReferenceResolver.resolve(attachmentReferenceRepresentation, EntityType.ATTACHMENT, parameters)); } }
@Override public AttachmentReference resolve(String attachmentReferenceRepresentation, Object... parameters) { return new AttachmentReference(this.entityReferenceResolver.resolve( attachmentReferenceRepresentation, EntityType.ATTACHMENT, parameters)); } }
@Override public AttachmentReference resolve(String attachmentReferenceRepresentation, Object... parameters) { return new AttachmentReference(this.entityReferenceResolver.resolve( attachmentReferenceRepresentation, EntityType.ATTACHMENT, parameters)); } }
@Override public EntityReference next() { Object[] item = this.data.next(); return new AttachmentReference(String.valueOf(item[1]), HibernateDeletedAttachmentsReader.this.resolver.resolve(String.valueOf(item[0]))); }
@Override public EntityReference next() { Object[] item = this.data.next(); return new AttachmentReference(String.valueOf(item[1]), HibernateAttachmentsReader.this.resolver.resolve(String.valueOf(item[0]))); }
/** * {@inheritDoc} * @see org.xwiki.model.reference.AttachmentReferenceResolver#resolve */ public AttachmentReference resolve(String attachmentReferenceRepresentation, Object... parameters) { return new AttachmentReference(this.entityReferenceResolver.resolve( attachmentReferenceRepresentation, EntityType.ATTACHMENT, parameters)); } }
@Override public EntityReference next() { Object[] item = this.data.next(); return new AttachmentReference(String.valueOf(item[1]), HibernateAttachmentsReader.this.resolver.resolve(String.valueOf(item[0]))); }
@Override public List filterResults(List results) { // We need at least 2 columns in the select: the document full name and the attachment file name. if (results.size() > 0 && results.get(0).getClass().isArray()) { List<AttachmentReference> attachmentReferences = new ArrayList<>(); for (Object result : results) { Object[] actualResult = (Object[]) result; String documentFullName = String.valueOf(actualResult[0]); String attachmentFileName = String.valueOf(actualResult[1]); DocumentReference documentReference = this.documentReferenceResolver.resolve(documentFullName); attachmentReferences.add(new AttachmentReference(attachmentFileName, documentReference)); } return attachmentReferences; } return results; } }
private void migrateAttachments(File documentContentDirectory, DocumentReference documentReference) throws IOException { File attachmentsDirectory = new File(documentContentDirectory, FilesystemStoreTools.ATTACHMENTS_DIR_NAME); if (attachmentsDirectory.isDirectory()) { for (File oldAttachmentDirectory : attachmentsDirectory.listFiles()) { if (oldAttachmentDirectory.isDirectory()) { AttachmentReference attachmentReference = new AttachmentReference( FileSystemStoreUtils.decode(oldAttachmentDirectory.getName()), documentReference); File newAttachmentDirectory = this.fstools.getAttachmentDir(attachmentReference); this.logger.info("Moving attachment folder [{}] to new location [{}]", oldAttachmentDirectory, newAttachmentDirectory); FileUtils.moveDirectory(oldAttachmentDirectory, newAttachmentDirectory); migrateAttachmentFiles(newAttachmentDirectory, attachmentReference.getName()); } } } }
/** * {@inheritDoc} * * @see DocumentAccessBridge#getAttachmentReferences(org.xwiki.model.reference.DocumentReference) */ public List<AttachmentReference> getAttachmentReferences(DocumentReference documentReference) throws Exception { List<AttachmentReference> attachmentReferences = new ArrayList<AttachmentReference>(); XWikiContext xcontext = getContext(); DocumentReference resolvedReference = documentReference; List<XWikiAttachment> attachments = xcontext.getWiki().getDocument(resolvedReference, xcontext).getAttachmentList(); for (XWikiAttachment attachment : attachments) { attachmentReferences.add(new AttachmentReference(attachment.getFilename(), resolvedReference)); } return attachmentReferences; }
/** * @since 7.2M2 */ public void attachFile(List<String> spaces, String page, String name, InputStream is, boolean failIfExists) throws Exception { AttachmentReference reference = new AttachmentReference(name, new DocumentReference(getCurrentWiki(), spaces, page)); attachFile(reference, is, failIfExists); }
/** * {@inheritDoc} * * @see DocumentAccessBridge#getAttachmentURL(org.xwiki.bridge.AttachmentName, boolean) */ @Deprecated public String getAttachmentURL(org.xwiki.bridge.AttachmentName attachmentName, boolean isFullURL) { return getAttachmentURL(new AttachmentReference(attachmentName.getFileName(), new DocumentReference( attachmentName.getDocumentName().getWiki(), attachmentName.getDocumentName().getWiki(), attachmentName.getDocumentName().getPage())), isFullURL); }
/** * {@inheritDoc} * * @see DocumentAccessBridge#getAttachmentContent(org.xwiki.bridge.AttachmentName) */ @Deprecated public InputStream getAttachmentContent(org.xwiki.bridge.AttachmentName attachmentName) throws Exception { return getAttachmentContent(new AttachmentReference(attachmentName.getFileName(), new DocumentReference( attachmentName.getDocumentName().getWiki(), attachmentName.getDocumentName().getSpace(), attachmentName.getDocumentName().getPage()))); }