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);
}
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);
}
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;
}
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));
}
Aggregations