use of org.xwiki.rendering.listener.reference.AttachmentResourceReference in project xwiki-platform by xwiki.
the class DefaultOfficeResourceViewerTest method testViewPresentation.
@Test
public void testViewPresentation() throws Exception {
AttachmentResourceReference attachResourceRef = new AttachmentResourceReference("xwiki:Some.Page@presentation.odp");
DocumentReference documentReference = new DocumentReference("wiki", "Some", "Page");
AttachmentReference attachmentReference = new AttachmentReference("presentation.odp", documentReference);
AttachmentReferenceResolver<String> attachmentReferenceResolver = mocker.getInstance(AttachmentReferenceResolver.TYPE_STRING, "current");
when(attachmentReferenceResolver.resolve(attachResourceRef.getReference())).thenReturn(attachmentReference);
when(documentAccessBridge.getAttachmentReferences(attachmentReference.getDocumentReference())).thenReturn(Arrays.asList(attachmentReference));
when(documentAccessBridge.getAttachmentVersion(attachmentReference)).thenReturn("3.2");
ByteArrayInputStream attachmentContent = new ByteArrayInputStream(new byte[256]);
when(documentAccessBridge.getAttachmentContent(attachmentReference)).thenReturn(attachmentContent);
ResourceReference imageReference = new ResourceReference("slide0.png", ResourceType.URL);
ExpandedMacroBlock galleryMacro = new ExpandedMacroBlock("gallery", Collections.singletonMap("width", "300px"), null, false);
galleryMacro.addChild(new ImageBlock(imageReference, true));
XDOM xdom = new XDOM(Collections.<Block>singletonList(galleryMacro));
Map<String, byte[]> artifacts = Collections.singletonMap("slide0.png", new byte[8]);
XDOMOfficeDocument xdomOfficeDocument = new XDOMOfficeDocument(xdom, artifacts, mocker);
PresentationBuilder presentationBuilder = mocker.getInstance(PresentationBuilder.class);
when(presentationBuilder.build(attachmentContent, attachmentReference.getName(), documentReference)).thenReturn(xdomOfficeDocument);
Map<String, ?> viewParameters = Collections.singletonMap("ownerDocument", documentReference);
TemporaryResourceReference temporaryResourceReference = new TemporaryResourceReference("officeviewer", Arrays.asList(String.valueOf(viewParameters.hashCode()), "slide0.png"), documentReference);
Type type = new DefaultParameterizedType(null, ResourceReferenceSerializer.class, TemporaryResourceReference.class, ExtendedURL.class);
ResourceReferenceSerializer<TemporaryResourceReference, ExtendedURL> urlTemporaryResourceReferenceSerializer = mocker.getInstance(type, "standard/tmp");
ExtendedURL extendedURL = new ExtendedURL(Arrays.asList("url", "to", "slide0.png"));
when(urlTemporaryResourceReferenceSerializer.serialize(temporaryResourceReference)).thenReturn(extendedURL);
XDOM output = this.mocker.getComponentUnderTest().createView(attachResourceRef, viewParameters);
ImageBlock imageBlock = (ImageBlock) output.getBlocks(new ClassBlockMatcher(ImageBlock.class), Block.Axes.DESCENDANT).get(0);
assertEquals("/url/to/slide0.png", imageBlock.getReference().getReference());
galleryMacro = (ExpandedMacroBlock) output.getBlocks(new ClassBlockMatcher(ExpandedMacroBlock.class), Block.Axes.DESCENDANT).get(0);
assertFalse(galleryMacro.getParent() instanceof XDOM);
assertEquals(Syntax.XWIKI_2_1, ((MetaDataBlock) galleryMacro.getParent()).getMetaData().getMetaData(MetaData.SYNTAX));
TemporaryResourceStore store = mocker.getInstance(TemporaryResourceStore.class);
verify(store).createTemporaryFile(eq(temporaryResourceReference), any(InputStream.class));
}
use of org.xwiki.rendering.listener.reference.AttachmentResourceReference in project xwiki-platform by xwiki.
the class OfficeMacro method getResourceReference.
private ResourceReference getResourceReference(MacroBlock block, OfficeMacroParameters parameters) throws MacroExecutionException {
ResourceReference resourceReference = parameters.getReference();
// Make sure to provide full reference for attachment
if (resourceReference == null || resourceReference.getType().equals(ResourceType.ATTACHMENT) || !resourceReference.isTyped()) {
AttachmentReference attachmentReference;
if (resourceReference == null) {
// Support former way of indicating the file to view
String reference = parameters.getAttachment();
if (StringUtils.isEmpty(reference)) {
throw new MacroExecutionException("You must specify the 'reference' parameter pointing to the office file to display.");
}
attachmentReference = this.macroAttachmentReferenceResolver.resolve(reference, block);
} else {
attachmentReference = this.macroAttachmentReferenceResolver.resolve(resourceReference.getReference(), block);
}
resourceReference = new AttachmentResourceReference(this.serializer.serialize(attachmentReference));
}
return resourceReference;
}
use of org.xwiki.rendering.listener.reference.AttachmentResourceReference in project xwiki-platform by xwiki.
the class XWikiWikiModelTest method getImageURLWhenBothWidthAndHeightAreUnspecifiedAndImageSizeIsNotLimited.
/**
* Tests that the proper image URL is generated when both the width and the height are unspecified and the image
* size is not limited in the configuration.
*
* @throws Exception if an exception occurs while running the test
*/
@Test
public void getImageURLWhenBothWidthAndHeightAreUnspecifiedAndImageSizeIsNotLimited() throws Exception {
final ExtendedRenderingConfiguration configuration = this.mocker.getInstance(ExtendedRenderingConfiguration.class);
when(configuration.getImageWidthLimit()).thenReturn(-1);
when(configuration.getImageHeightLimit()).thenReturn(-1);
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("style", "bad CSS declaration");
testImageURL(new AttachmentResourceReference("attachmentReference"), parameters, true, null);
}
use of org.xwiki.rendering.listener.reference.AttachmentResourceReference in project xwiki-platform by xwiki.
the class XWikiWikiModelTest method getImageURLWhenBothWidthAndHeightCSSPropertiesAreSpecified.
/**
* Tests that the proper image URL is generated when both the width and the height CSS properties are specified.
*
* @throws Exception if an exception occurs while running the test
*/
@Test
public void getImageURLWhenBothWidthAndHeightCSSPropertiesAreSpecified() throws Exception {
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("style", "border: 1px; height: 30px; margin-top: 2em; width: 70px");
testImageURL(new AttachmentResourceReference("attachmentReference"), parameters, true, "width=70&height=30");
}
use of org.xwiki.rendering.listener.reference.AttachmentResourceReference in project xwiki-platform by xwiki.
the class XWikiWikiModelTest method getImageURLWhenBothWidthAndHeightAreUnspecifiedAndOnlyImageWidthIsLimited.
/**
* Tests that the proper image URL is generated when both the width and the height are unspecified and only the
* image width is limited in the configuration.
*
* @throws Exception if an exception occurs while running the test
*/
@Test
public void getImageURLWhenBothWidthAndHeightAreUnspecifiedAndOnlyImageWidthIsLimited() throws Exception {
final ExtendedRenderingConfiguration configuration = this.mocker.getInstance(ExtendedRenderingConfiguration.class);
when(configuration.getImageWidthLimit()).thenReturn(25);
when(configuration.getImageHeightLimit()).thenReturn(-1);
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("width", "45%");
parameters.put("style", "height:10em");
testImageURL(new AttachmentResourceReference("attachmentReference"), parameters, true, "width=25");
}
Aggregations