Search in sources :

Example 11 with AttachmentResourceReference

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");
}
Also used : HashMap(java.util.HashMap) AttachmentResourceReference(org.xwiki.rendering.listener.reference.AttachmentResourceReference) Test(org.junit.Test)

Example 12 with AttachmentResourceReference

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);
}
Also used : HashMap(java.util.HashMap) AttachmentResourceReference(org.xwiki.rendering.listener.reference.AttachmentResourceReference) Test(org.junit.Test)

Example 13 with AttachmentResourceReference

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");
}
Also used : HashMap(java.util.HashMap) AttachmentResourceReference(org.xwiki.rendering.listener.reference.AttachmentResourceReference) Test(org.junit.Test)

Example 14 with AttachmentResourceReference

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

AttachmentResourceReference (org.xwiki.rendering.listener.reference.AttachmentResourceReference)14 Test (org.junit.Test)11 HashMap (java.util.HashMap)9 ExtendedRenderingConfiguration (org.xwiki.rendering.configuration.ExtendedRenderingConfiguration)3 ResourceReference (org.xwiki.rendering.listener.reference.ResourceReference)3 AttachmentReference (org.xwiki.model.reference.AttachmentReference)2 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)1 BaseObject (com.xpn.xwiki.objects.BaseObject)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Type (java.lang.reflect.Type)1 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)1 DefaultVersionConstraint (org.xwiki.extension.version.internal.DefaultVersionConstraint)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 PresentationBuilder (org.xwiki.officeimporter.builder.PresentationBuilder)1 XDOMOfficeDocument (org.xwiki.officeimporter.document.XDOMOfficeDocument)1 ExpandedMacroBlock (org.xwiki.rendering.block.ExpandedMacroBlock)1 ImageBlock (org.xwiki.rendering.block.ImageBlock)1 MetaDataBlock (org.xwiki.rendering.block.MetaDataBlock)1 XDOM (org.xwiki.rendering.block.XDOM)1