use of org.xwiki.rendering.listener.reference.AttachmentResourceReference in project xwiki-platform by xwiki.
the class XWikiWikiModelTest method getImageURLWhenBothStyleAndDimensionParametersAreSpecified.
/**
* Tests that the proper image URL is generated when both the style and the dimension parameters are specified.
*
* @throws Exception if an exception occurs while running the test
*/
@Test
public void getImageURLWhenBothStyleAndDimensionParametersAreSpecified() throws Exception {
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("height", "46");
parameters.put("width", "101px");
parameters.put("style", "width: 20%; height:75px");
// Note that the style parameter take precedence over the dimension parameters and the width is actually 20% but
// we can't use it for resizing the image on the server side so it's omitted from the query string.
testImageURL(new AttachmentResourceReference("attachmentReference"), parameters, true, "height=75");
}
use of org.xwiki.rendering.listener.reference.AttachmentResourceReference in project xwiki-platform by xwiki.
the class XWikiWikiModelTest method getImageURLWhenIncludingImageDimensionsIsForbidden.
/**
* Tests that the proper image URL is generated when both the width and the height image parameters are specified
* but including them in the image URL is forbidden from the rendering configuration.
*
* @throws Exception if an exception occurs while running the test
*/
@Test
public void getImageURLWhenIncludingImageDimensionsIsForbidden() throws Exception {
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("width", "101px");
parameters.put("height", "55px");
testImageURL(new AttachmentResourceReference("attachmentReference"), parameters, false, null);
}
use of org.xwiki.rendering.listener.reference.AttachmentResourceReference in project xwiki-platform by xwiki.
the class XWikiWikiModelTest method getImageURLWhenOnlyWidthAttributeIsSpecified.
/**
* Tests that the proper image URL is generated when only the width image parameter is specified.
*
* @throws Exception if an exception occurs while running the test
*/
@Test
public void getImageURLWhenOnlyWidthAttributeIsSpecified() throws Exception {
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("width", "150");
parameters.put("height", "30%");
testImageURL(new AttachmentResourceReference("attachmentReference"), parameters, true, "width=150");
}
use of org.xwiki.rendering.listener.reference.AttachmentResourceReference 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