use of org.xwiki.rendering.listener.reference.ResourceReference in project xwiki-platform by xwiki.
the class DefaultResourceReferenceEntityReferenceResolverTest method resolveTypeDocument.
@Test
public void resolveTypeDocument() throws ComponentLookupException {
assertEquals(new DocumentReference(WIKI, SPACE, PAGE), this.mocker.getComponentUnderTest().resolve(documentResource(WIKI + ':' + SPACE + '.' + PAGE, true), null));
assertEquals(new DocumentReference(CURRENT_WIKI, SPACE, PAGE), this.mocker.getComponentUnderTest().resolve(documentResource(SPACE + '.' + PAGE, true), null));
assertEquals(new DocumentReference(CURRENT_WIKI, CURRENT_SPACE, PAGE), this.mocker.getComponentUnderTest().resolve(documentResource(PAGE, true), null));
assertEquals(new DocumentReference(CURRENT_WIKI, CURRENT_SPACE, CURRENT_PAGE), this.mocker.getComponentUnderTest().resolve(documentResource("", true), null));
when(this.currentEntityReferenceResolver.resolve(eq(WIKI + ':' + SPACE + '.' + PAGE), eq(EntityType.DOCUMENT), any())).thenReturn(new DocumentReference(WIKI, SPACE, PAGE));
ResourceReference withBaseReference = documentResource("", true);
withBaseReference.addBaseReference(WIKI + ':' + SPACE + '.' + PAGE);
assertEquals(new DocumentReference(WIKI, SPACE, PAGE), this.mocker.getComponentUnderTest().resolve(withBaseReference, null));
assertEquals(new DocumentReference(WIKI, SPACE, PAGE), this.mocker.getComponentUnderTest().resolve(documentResource("", true), null, new DocumentReference(WIKI, SPACE, PAGE)));
}
use of org.xwiki.rendering.listener.reference.ResourceReference in project xwiki-platform by xwiki.
the class XWikiWikiModelTest method getImageURLWhenIcon.
@Test
public void getImageURLWhenIcon() throws Exception {
ResourceReference reference = new ResourceReference("iconname", ResourceType.ICON);
SkinAccessBridge skinAccessBridge = this.mocker.getInstance((Type) SkinAccessBridge.class);
when(skinAccessBridge.getIconURL("iconname")).thenReturn("/path/to/icon");
assertEquals("/path/to/icon", this.mocker.getComponentUnderTest().getImageURL(reference, Collections.<String, String>emptyMap()));
}
use of org.xwiki.rendering.listener.reference.ResourceReference in project xwiki-platform by xwiki.
the class XWikiWikiModelTest method getDocumentViewURLWhenBaseReferenceSpecified.
@Test
public void getDocumentViewURLWhenBaseReferenceSpecified() throws Exception {
ResourceReference reference = new ResourceReference("reference", ResourceType.DOCUMENT);
reference.addBaseReference("base");
DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
when(this.referenceResolver.resolve(reference, EntityType.DOCUMENT)).thenReturn(documentReference);
when(this.documentAccessBridge.getDocumentURL(documentReference, "view", null, null)).thenReturn("viewurl");
assertEquals("viewurl", this.mocker.getComponentUnderTest().getDocumentViewURL(reference));
}
use of org.xwiki.rendering.listener.reference.ResourceReference 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.rendering.listener.reference.ResourceReference in project xwiki-platform by xwiki.
the class RepositoryManager method getDownloadReference.
/**
* @since 9.5RC1
*/
public ResourceReference getDownloadReference(XWikiDocument document, String extensionVersion) throws ResolveException {
String downloadURL = null;
// this
BaseObject extensionVersionObject = getExtensionVersionObject(document, extensionVersion, false);
// important
if (extensionVersionObject != null) {
downloadURL = getValue(extensionVersionObject, XWikiRepositoryModel.PROP_VERSION_DOWNLOAD);
} else if (isVersionProxyingEnabled(document)) {
downloadURL = resolveExtensionDownloadURL(document, extensionVersion);
}
ResourceReference resourceReference = null;
if (StringUtils.isNotEmpty(downloadURL)) {
resourceReference = this.resourceReferenceParser.parse(downloadURL);
} else {
BaseObject extensionObject = document.getXObject(XWikiRepositoryModel.EXTENSION_CLASSREFERENCE);
String extensionId = getValue(extensionObject, XWikiRepositoryModel.PROP_EXTENSION_ID);
String fileName = extensionId + '-' + extensionVersion + '.' + getValue(extensionObject, XWikiRepositoryModel.PROP_EXTENSION_TYPE);
XWikiAttachment attachment = document.getAttachment(fileName);
if (attachment == null) {
// Try without the prefix
int index = fileName.indexOf(':');
if (index != -1 && index < extensionId.length()) {
fileName = fileName.substring(index + 1);
attachment = document.getAttachment(fileName);
}
}
if (attachment != null) {
resourceReference = new AttachmentResourceReference(this.entityReferenceSerializer.serialize(attachment.getReference()));
}
}
return resourceReference;
}
Aggregations