Search in sources :

Example 41 with ResourceReference

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)));
}
Also used : AttachmentResourceReference(org.xwiki.rendering.listener.reference.AttachmentResourceReference) ResourceReference(org.xwiki.rendering.listener.reference.ResourceReference) DocumentResourceReference(org.xwiki.rendering.listener.reference.DocumentResourceReference) SpaceResourceReference(org.xwiki.rendering.listener.reference.SpaceResourceReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 42 with ResourceReference

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()));
}
Also used : SkinAccessBridge(org.xwiki.bridge.SkinAccessBridge) AttachmentResourceReference(org.xwiki.rendering.listener.reference.AttachmentResourceReference) ResourceReference(org.xwiki.rendering.listener.reference.ResourceReference) DocumentResourceReference(org.xwiki.rendering.listener.reference.DocumentResourceReference) Test(org.junit.Test)

Example 43 with ResourceReference

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));
}
Also used : AttachmentResourceReference(org.xwiki.rendering.listener.reference.AttachmentResourceReference) ResourceReference(org.xwiki.rendering.listener.reference.ResourceReference) DocumentResourceReference(org.xwiki.rendering.listener.reference.DocumentResourceReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 44 with ResourceReference

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;
}
Also used : ResolveException(org.xwiki.extension.ResolveException) AttachmentReference(org.xwiki.model.reference.AttachmentReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) AttachmentResourceReference(org.xwiki.rendering.listener.reference.AttachmentResourceReference) ResourceReference(org.xwiki.rendering.listener.reference.ResourceReference) ExtensionResourceReference(org.xwiki.repository.internal.reference.ExtensionResourceReference) XWikiException(com.xpn.xwiki.XWikiException)

Example 45 with ResourceReference

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;
}
Also used : AttachmentResourceReference(org.xwiki.rendering.listener.reference.AttachmentResourceReference) AttachmentResourceReference(org.xwiki.rendering.listener.reference.AttachmentResourceReference) ResourceReference(org.xwiki.rendering.listener.reference.ResourceReference) ExtensionResourceReference(org.xwiki.repository.internal.reference.ExtensionResourceReference) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment) DefaultVersionConstraint(org.xwiki.extension.version.internal.DefaultVersionConstraint) BaseObject(com.xpn.xwiki.objects.BaseObject)

Aggregations

ResourceReference (org.xwiki.rendering.listener.reference.ResourceReference)51 DocumentReference (org.xwiki.model.reference.DocumentReference)27 Test (org.junit.Test)26 LinkBlock (org.xwiki.rendering.block.LinkBlock)20 XDOM (org.xwiki.rendering.block.XDOM)16 DocumentResourceReference (org.xwiki.rendering.listener.reference.DocumentResourceReference)15 AttachmentResourceReference (org.xwiki.rendering.listener.reference.AttachmentResourceReference)13 Block (org.xwiki.rendering.block.Block)12 SpaceReference (org.xwiki.model.reference.SpaceReference)11 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)9 AttachmentReference (org.xwiki.model.reference.AttachmentReference)9 ImageBlock (org.xwiki.rendering.block.ImageBlock)8 MacroBlock (org.xwiki.rendering.block.MacroBlock)8 ResourceType (org.xwiki.rendering.listener.reference.ResourceType)8 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)7 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)7 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)7 EntityReference (org.xwiki.model.reference.EntityReference)6 EntityReferenceResolver (org.xwiki.model.reference.EntityReferenceResolver)6 GroupBlock (org.xwiki.rendering.block.GroupBlock)5