Search in sources :

Example 11 with ResourceReference

use of org.xwiki.resource.ResourceReference in project xwiki-platform by xwiki.

the class DefaultResourceReferenceSerializer method serialize.

@Override
public ExtendedURL serialize(ResourceReference resource) throws SerializeResourceReferenceException, UnsupportedResourceReferenceException {
    ResourceReferenceSerializer<ResourceReference, ExtendedURL> serializer;
    ParameterizedType type = new DefaultParameterizedType(null, ResourceReferenceSerializer.class, ResourceReference.class, ExtendedURL.class);
    try {
        serializer = this.componentManager.getInstance(type, this.urlContextManager.getURLFormatId());
    } catch (ComponentLookupException e) {
        throw new UnsupportedResourceReferenceException(String.format("Invalid URL format id [%s]. Cannot serialize Resource Reference [%s].", this.urlContextManager.getURLFormatId(), resource), e);
    }
    return serializer.serialize(resource);
}
Also used : DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) ResourceReference(org.xwiki.resource.ResourceReference) UnsupportedResourceReferenceException(org.xwiki.resource.UnsupportedResourceReferenceException) ExtendedURL(org.xwiki.url.ExtendedURL) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType)

Example 12 with ResourceReference

use of org.xwiki.resource.ResourceReference in project xwiki-platform by xwiki.

the class DownloadActionTest method setRequestExpectations.

private void setRequestExpectations(String uri, String id, String forceDownload, String range, long modifiedSince, String attachmentName) {
    ResourceReference rr = new EntityResourceReference(new AttachmentReference(attachmentName, this.documentReference), EntityResourceAction.VIEW);
    when(this.request.getRequestURI()).thenReturn(uri);
    when(this.request.getParameter("id")).thenReturn(id);
    when(this.request.getDateHeader("If-Modified-Since")).thenReturn(modifiedSince);
    when(this.request.getParameter("force-download")).thenReturn(forceDownload);
    when(this.request.getHeader("Range")).thenReturn(range);
    when(this.resourceReferenceManager.getResourceReference()).thenReturn(rr);
}
Also used : AttachmentReference(org.xwiki.model.reference.AttachmentReference) EntityResourceReference(org.xwiki.resource.entity.EntityResourceReference) ResourceReference(org.xwiki.resource.ResourceReference) EntityResourceReference(org.xwiki.resource.entity.EntityResourceReference)

Example 13 with ResourceReference

use of org.xwiki.resource.ResourceReference in project xwiki-platform by xwiki.

the class DefaultResourceReferenceManager method getResourceReference.

@Override
public ResourceReference getResourceReference() {
    ResourceReference result = null;
    ExecutionContext ec = this.execution.getContext();
    if (ec != null) {
        result = (ResourceReference) ec.getProperty(ResourceReferenceManager.RESOURCE_CONTEXT_PROPERTY);
    }
    return result;
}
Also used : ExecutionContext(org.xwiki.context.ExecutionContext) ResourceReference(org.xwiki.resource.ResourceReference)

Example 14 with ResourceReference

use of org.xwiki.resource.ResourceReference in project xwiki-platform by xwiki.

the class MainResourceReferenceHandlerManagerTest method handleWithOrder.

@Test
public void handleWithOrder() throws Exception {
    // First Handler component will lower priority
    ResourceReferenceHandler testHandler = mock(ResourceReferenceHandler.class, "handler1");
    when(testHandler.getSupportedResourceReferences()).thenReturn(Arrays.asList(new ResourceType("test")));
    // Second Handler component will higher priority so that it's executed first
    ResourceReferenceHandler beforeTestHandler = mock(ResourceReferenceHandler.class, "handler2");
    when(beforeTestHandler.getSupportedResourceReferences()).thenReturn(Arrays.asList(new ResourceType("test")));
    // We return 1 to mean that the second Handler has a higher priority than the first Handler
    when(beforeTestHandler.compareTo(testHandler)).thenReturn(-1);
    ComponentManager contextComponentManager = this.componentManager.getInstance(ComponentManager.class, "context");
    when(contextComponentManager.<ResourceReferenceHandler>getInstanceList(new DefaultParameterizedType(null, ResourceReferenceHandler.class, ResourceType.class))).thenReturn(Arrays.asList(testHandler, beforeTestHandler));
    ResourceReference reference = mock(ResourceReference.class);
    when(reference.getType()).thenReturn(new ResourceType("test"));
    this.componentManager.getComponentUnderTest().handle(reference);
    // Verify that the second Action is called (since it has a higher priority).
    verify(beforeTestHandler).handle(same(reference), any(ResourceReferenceHandlerChain.class));
}
Also used : ResourceReferenceHandler(org.xwiki.resource.ResourceReferenceHandler) ComponentManager(org.xwiki.component.manager.ComponentManager) ResourceType(org.xwiki.resource.ResourceType) ResourceReference(org.xwiki.resource.ResourceReference) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) ResourceReferenceHandlerChain(org.xwiki.resource.ResourceReferenceHandlerChain) Test(org.junit.Test)

Aggregations

ResourceReference (org.xwiki.resource.ResourceReference)14 EntityResourceReference (org.xwiki.resource.entity.EntityResourceReference)11 ResourceReferenceManager (org.xwiki.resource.ResourceReferenceManager)6 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)4 ResourceType (org.xwiki.resource.ResourceType)4 XWikiException (com.xpn.xwiki.XWikiException)3 IOException (java.io.IOException)3 Test (org.junit.Test)3 EntityReference (org.xwiki.model.reference.EntityReference)3 ExtendedURL (org.xwiki.url.ExtendedURL)3 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)2 URL (java.net.URL)2 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)2 ExecutionContext (org.xwiki.context.ExecutionContext)2 DocumentReference (org.xwiki.model.reference.DocumentReference)2 XWiki (com.xpn.xwiki.XWiki)1 MonitorPlugin (com.xpn.xwiki.monitor.api.MonitorPlugin)1 BaseObject (com.xpn.xwiki.objects.BaseObject)1 FileUploadPlugin (com.xpn.xwiki.plugin.fileupload.FileUploadPlugin)1 FileNotFoundException (java.io.FileNotFoundException)1