use of org.xwiki.model.reference.AttachmentReference in project xwiki-platform by xwiki.
the class XWikiWikiModelTest method testImageURL.
private void testImageURL(final ResourceReference imageReference, Map<String, String> parameters, final boolean expectedIsImageDimensionsIncludedInImageURL, final String expectedQueryString) throws Exception {
AttachmentReference attachmentReference = new AttachmentReference("image", new DocumentReference("wiki", "space", "page"));
ExtendedRenderingConfiguration configuration = this.mocker.getInstance(ExtendedRenderingConfiguration.class);
when(configuration.isImageDimensionsIncludedInImageURL()).thenReturn(expectedIsImageDimensionsIncludedInImageURL);
when(this.referenceResolver.resolve(imageReference, EntityType.ATTACHMENT)).thenReturn(attachmentReference);
when(this.documentAccessBridge.getAttachmentURL(attachmentReference, expectedQueryString, false)).thenReturn("?" + expectedQueryString);
assertEquals("?" + expectedQueryString, this.mocker.getComponentUnderTest().getImageURL(imageReference, parameters));
}
use of org.xwiki.model.reference.AttachmentReference in project xwiki-platform by xwiki.
the class RepositoryManager method isVersionValid.
private boolean isVersionValid(XWikiDocument document, BaseObject extensionVersionObject, XWikiContext context) {
// Has a version
String extensionVersion = getValue(extensionVersionObject, XWikiRepositoryModel.PROP_VERSION_VERSION);
if (StringUtils.isBlank(extensionVersion)) {
this.logger.debug("No actual version provided for object [{}({})]", XWikiRepositoryModel.EXTENSIONVERSION_CLASSREFERENCE, extensionVersionObject.getNumber());
return false;
}
boolean valid;
ResourceReference resourceReference = null;
try {
resourceReference = getDownloadReference(document, extensionVersion);
} catch (ResolveException e) {
logger.debug("Cannot obtain download source reference for object [{}({})]", XWikiRepositoryModel.EXTENSIONVERSION_CLASSREFERENCE, extensionVersionObject.getNumber());
return false;
}
if (resourceReference != null) {
if (ResourceType.ATTACHMENT.equals(resourceReference.getType())) {
AttachmentReference attachmentReference = this.attachmentResolver.resolve(resourceReference.getReference(), document.getDocumentReference());
XWikiDocument attachmentDocument;
try {
attachmentDocument = context.getWiki().getDocument(attachmentReference.getDocumentReference(), context);
valid = attachmentDocument.getAttachment(attachmentReference.getName()) != null;
} catch (XWikiException e) {
this.logger.error("Failed to get document [{}]", attachmentReference.getDocumentReference(), e);
valid = false;
}
if (!valid) {
this.logger.debug("Attachment [{}] does not exists", attachmentReference);
}
} else if (ResourceType.URL.equals(resourceReference.getType()) || ExtensionResourceReference.TYPE.equals(resourceReference.getType())) {
valid = true;
} else {
valid = false;
this.logger.debug("Unknown resource type [{}]", resourceReference.getType());
}
} else {
valid = false;
this.logger.debug("No actual download provided for object [{}({})]", XWikiRepositoryModel.EXTENSIONVERSION_CLASSREFERENCE, extensionVersionObject.getNumber());
}
return valid;
}
use of org.xwiki.model.reference.AttachmentReference in project xwiki-platform by xwiki.
the class AttachVfsResourceReferenceSerializerTest method serialize.
@Test
public void serialize() throws Exception {
VfsResourceReference reference = new VfsResourceReference(URI.create("attach:attachment"), "path1/path2/test.txt");
ExtendedURL extendedURL = new ExtendedURL(Arrays.asList("vfs", "attach:wiki:space.page@attachment", "path1", "path2", "test.txt"));
URLNormalizer<ExtendedURL> normalizer = this.mocker.getInstance(new DefaultParameterizedType(null, URLNormalizer.class, ExtendedURL.class), "contextpath");
when(normalizer.normalize(extendedURL)).thenReturn(extendedURL);
AttachmentReferenceResolver<String> attachmentResolver = this.mocker.getInstance(AttachmentReferenceResolver.TYPE_STRING, "current");
AttachmentReference attachmentReference = new AttachmentReference("attachment", new DocumentReference("wiki", Arrays.asList("space"), "page"));
when(attachmentResolver.resolve("attachment")).thenReturn(attachmentReference);
EntityReferenceSerializer<String> entitySerializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING);
when(entitySerializer.serialize(attachmentReference)).thenReturn("wiki:space.page@attachment");
assertEquals("/vfs/attach%3Awiki%3Aspace.page%40attachment/path1/path2/test.txt", this.mocker.getComponentUnderTest().serialize(reference).toString());
}
use of org.xwiki.model.reference.AttachmentReference in project xwiki-platform by xwiki.
the class CascadingVfsPermissionCheckerTest method checkPermissionWithAttachSchemeChecker.
@Test
public void checkPermissionWithAttachSchemeChecker() throws Exception {
VfsResourceReference reference = new VfsResourceReference(URI.create("attach:whatever"), "whatever");
AttachmentReferenceResolver<String> resolver = this.mocker.registerMockComponent(AttachmentReferenceResolver.TYPE_STRING);
DocumentReference attachmentDocumentReference = new DocumentReference("wiki", "space", "page");
AttachmentReference attachmentReference = new AttachmentReference("file", attachmentDocumentReference);
when(resolver.resolve("whatever")).thenReturn(attachmentReference);
ContextualAuthorizationManager authorizationManager = this.mocker.registerMockComponent(ContextualAuthorizationManager.class);
when(authorizationManager.hasAccess(Right.VIEW, attachmentReference)).thenReturn(true);
this.mocker.getComponentUnderTest().checkPermission(reference);
}
use of org.xwiki.model.reference.AttachmentReference in project xwiki-platform by xwiki.
the class AttachURIVfsResourceReferenceSerializer method serialize.
@Override
public URI serialize(VfsResourceReference reference) throws SerializeResourceReferenceException, UnsupportedResourceReferenceException {
AttachmentReference attachmentReference = this.attachmentResolver.resolve(reference.getURI().getSchemeSpecificPart());
String scheme = reference.getURI().getScheme();
String documentRefefenceString = this.documentSerializer.serialize(attachmentReference.getDocumentReference());
return URI.create(String.format("%s://%s/%s/%s", scheme, documentRefefenceString, attachmentReference.getName(), reference.getPath()));
}
Aggregations