mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Thumbnail Service: can now get a list of thumbnail definitions that can be applied to a given content property
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10437 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -46,11 +46,12 @@
|
||||
|
||||
<!-- Thumbnail Register -->
|
||||
<bean id="thumbnailRegistry" class="org.alfresco.repo.thumbnail.ThumbnailRegistry">
|
||||
<property name="thumbnailDetails">
|
||||
<property name="contentService" ref="ContentService"/>
|
||||
<property name="thumbnailDefinitions">
|
||||
<list>
|
||||
|
||||
<!-- Small image thumbnail options -->
|
||||
<bean class="org.alfresco.repo.thumbnail.ThumbnailDetails">
|
||||
<bean class="org.alfresco.repo.thumbnail.ThumbnailDefinition">
|
||||
<property name="name" value="medium" />
|
||||
<property name="mimetype" value="image/jpeg"/>
|
||||
<property name="transformationOptions">
|
||||
@@ -69,7 +70,7 @@
|
||||
</bean>
|
||||
|
||||
<!-- Slingshot Document Library image thumbnail options -->
|
||||
<bean class="org.alfresco.repo.thumbnail.ThumbnailDetails">
|
||||
<bean class="org.alfresco.repo.thumbnail.ThumbnailDefinition">
|
||||
<property name="name" value="doclib" />
|
||||
<property name="mimetype" value="image/png"/>
|
||||
<property name="transformationOptions">
|
||||
@@ -88,7 +89,7 @@
|
||||
</bean>
|
||||
|
||||
<!-- Web Preview thumbnail options -->
|
||||
<bean class="org.alfresco.repo.thumbnail.ThumbnailDetails">
|
||||
<bean class="org.alfresco.repo.thumbnail.ThumbnailDefinition">
|
||||
<property name="name" value="webpreview" />
|
||||
<property name="mimetype" value="application/x-shockwave-flash"/>
|
||||
<property name="transformationOptions">
|
||||
@@ -99,7 +100,7 @@
|
||||
</bean>
|
||||
|
||||
<!-- User avatar image thumbnail options -->
|
||||
<bean class="org.alfresco.repo.thumbnail.ThumbnailDetails">
|
||||
<bean class="org.alfresco.repo.thumbnail.ThumbnailDefinition">
|
||||
<property name="name" value="avatar" />
|
||||
<property name="mimetype" value="image/png"/>
|
||||
<property name="transformationOptions">
|
||||
|
@@ -44,7 +44,7 @@ import org.alfresco.repo.content.transform.magick.ImageTransformationOptions;
|
||||
import org.alfresco.repo.search.QueryParameterDefImpl;
|
||||
import org.alfresco.repo.tagging.script.TagScope;
|
||||
import org.alfresco.repo.thumbnail.CreateThumbnailActionExecuter;
|
||||
import org.alfresco.repo.thumbnail.ThumbnailDetails;
|
||||
import org.alfresco.repo.thumbnail.ThumbnailDefinition;
|
||||
import org.alfresco.repo.thumbnail.ThumbnailRegistry;
|
||||
import org.alfresco.repo.thumbnail.script.ScriptThumbnail;
|
||||
import org.alfresco.repo.version.VersionModel;
|
||||
@@ -72,6 +72,7 @@ import org.alfresco.service.cmr.search.QueryParameterDefinition;
|
||||
import org.alfresco.service.cmr.security.AccessPermission;
|
||||
import org.alfresco.service.cmr.security.AccessStatus;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.cmr.thumbnail.ThumbnailService;
|
||||
import org.alfresco.service.cmr.version.Version;
|
||||
import org.alfresco.service.cmr.version.VersionHistory;
|
||||
import org.alfresco.service.cmr.version.VersionType;
|
||||
@@ -2036,7 +2037,7 @@ public class ScriptNode implements Serializable, Scopeable
|
||||
|
||||
// Use the thumbnail registy to get the details of the thumbail
|
||||
ThumbnailRegistry registry = this.services.getThumbnailService().getThumbnailRegistry();
|
||||
ThumbnailDetails details = registry.getThumbnailDetails(thumbnailName);
|
||||
ThumbnailDefinition details = registry.getThumbnailDefinition(thumbnailName);
|
||||
if (details == null)
|
||||
{
|
||||
// Throw exception
|
||||
@@ -2109,6 +2110,38 @@ public class ScriptNode implements Serializable, Scopeable
|
||||
return (ScriptThumbnail[])result.toArray(new ScriptThumbnail[result.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the names of the thumbnail defintions that can be applied to the content property of
|
||||
* this node.
|
||||
* <p>
|
||||
* Thumbanil defintions only appear in this list if they can produce a thumbnail for the content
|
||||
* found in the content property. This will be determined by looking at the mimetype of the content
|
||||
* and the destinatino mimetype of the thumbnail.
|
||||
*
|
||||
* @return String[] array of thumbnail names that are valid for the current content type
|
||||
*/
|
||||
public String[] getThumbnailDefintions()
|
||||
{
|
||||
ContentService contentService = this.services.getContentService();
|
||||
ThumbnailService thumbnailService = this.services.getThumbnailService();
|
||||
|
||||
List<String> result = new ArrayList<String>(7);
|
||||
|
||||
ContentReader contentReader = contentService.getReader(this.nodeRef, ContentModel.PROP_CONTENT);
|
||||
if (contentReader != null)
|
||||
{
|
||||
String mimetype = contentReader.getMimetype();
|
||||
List<ThumbnailDefinition> thumbnailDefinitions = thumbnailService.getThumbnailRegistry().getThumnailDefintions(mimetype);
|
||||
for (ThumbnailDefinition thumbnailDefinition : thumbnailDefinitions)
|
||||
{
|
||||
result.add(thumbnailDefinition.getName());
|
||||
}
|
||||
}
|
||||
|
||||
return (String[])result.toArray(new String[result.size()]);
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Tag methods
|
||||
|
||||
|
@@ -96,7 +96,7 @@ public class CreateThumbnailActionExecuter extends ActionExecuterAbstractBase
|
||||
|
||||
// Get the details of the thumbnail
|
||||
ThumbnailRegistry registry = this.thumbnailService.getThumbnailRegistry();
|
||||
ThumbnailDetails details = registry.getThumbnailDetails(thumbnailName);
|
||||
ThumbnailDefinition details = registry.getThumbnailDefinition(thumbnailName);
|
||||
if (details == null)
|
||||
{
|
||||
// Throw exception
|
||||
|
@@ -31,7 +31,7 @@ import org.alfresco.service.cmr.repository.TransformationOptions;
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class ThumbnailDetails
|
||||
public class ThumbnailDefinition
|
||||
{
|
||||
/** Name of the thumbnail */
|
||||
private String name;
|
||||
@@ -48,7 +48,7 @@ public class ThumbnailDetails
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public ThumbnailDetails()
|
||||
public ThumbnailDefinition()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class ThumbnailDetails
|
||||
* @param destinationMimetype
|
||||
* @param options
|
||||
*/
|
||||
public ThumbnailDetails(String destinationMimetype, TransformationOptions options)
|
||||
public ThumbnailDefinition(String destinationMimetype, TransformationOptions options)
|
||||
{
|
||||
this.mimetype = destinationMimetype;
|
||||
this.options = options;
|
||||
@@ -69,7 +69,7 @@ public class ThumbnailDetails
|
||||
*
|
||||
* @param thumbnailName the name of the thumbnail, can be null
|
||||
*/
|
||||
public ThumbnailDetails(String mimetype, TransformationOptions options, String thumbnailName)
|
||||
public ThumbnailDefinition(String mimetype, TransformationOptions options, String thumbnailName)
|
||||
{
|
||||
this(mimetype, options);
|
||||
this.name= thumbnailName;
|
||||
@@ -83,7 +83,7 @@ public class ThumbnailDetails
|
||||
* @param thumbnailName
|
||||
* @param placeHolderResourcePath
|
||||
*/
|
||||
public ThumbnailDetails(String mimetype, TransformationOptions options, String thumbnailName, String placeHolderResourcePath)
|
||||
public ThumbnailDefinition(String mimetype, TransformationOptions options, String thumbnailName, String placeHolderResourcePath)
|
||||
{
|
||||
this(mimetype, options, thumbnailName);
|
||||
this.placeHolderResourcePath = placeHolderResourcePath;
|
@@ -24,39 +24,100 @@
|
||||
*/
|
||||
package org.alfresco.repo.thumbnail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.thumbnail.ThumbnailException;
|
||||
|
||||
/**
|
||||
* Registry of all the thumbnail details available
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class ThumbnailRegistry
|
||||
{
|
||||
/** Map of thumbnail details */
|
||||
private Map<String, ThumbnailDetails> thumbnailDetails = new HashMap<String, ThumbnailDetails>(10);
|
||||
|
||||
/** Content service */
|
||||
private ContentService contentService;
|
||||
|
||||
/** Map of thumbnail defintion */
|
||||
private Map<String, ThumbnailDefinition> thumbnailDefinitions = new HashMap<String, ThumbnailDefinition>(7);
|
||||
|
||||
/** Cache to store mimetype to thumbnailDefinition mapping */
|
||||
private Map<String, List<ThumbnailDefinition>> mimetypeMap = new HashMap<String, List<ThumbnailDefinition>>(17);
|
||||
|
||||
/**
|
||||
* Add a number of thumbnail details
|
||||
* Content service
|
||||
*
|
||||
* @param thumbnailDetails list of thumbnail details
|
||||
* @param contentService content service
|
||||
*/
|
||||
public void setThumbnailDetails(List<ThumbnailDetails> thumbnailDetails)
|
||||
public void setContentService(ContentService contentService)
|
||||
{
|
||||
for (ThumbnailDetails value : thumbnailDetails)
|
||||
this.contentService = contentService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a number of thumbnail defintions
|
||||
*
|
||||
* @param thumbnailDefinitions list of thumbnail details
|
||||
*/
|
||||
public void setThumbnailDefinitions(List<ThumbnailDefinition> thumbnailDefinitions)
|
||||
{
|
||||
for (ThumbnailDefinition value : thumbnailDefinitions)
|
||||
{
|
||||
addThumbnailDetails(value);
|
||||
addThumbnailDefinition(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all the thumbnail defintions
|
||||
*
|
||||
* @return Collection<ThumbnailDefinition> colleciton of thumbnail defintions
|
||||
*/
|
||||
public List<ThumbnailDefinition> getThumbnailDefinitions()
|
||||
{
|
||||
return new ArrayList<ThumbnailDefinition>(this.thumbnailDefinitions.values());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param mimetype
|
||||
* @return
|
||||
*/
|
||||
public List<ThumbnailDefinition> getThumnailDefintions(String mimetype)
|
||||
{
|
||||
List<ThumbnailDefinition> result = this.mimetypeMap.get(mimetype);;
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
result = new ArrayList<ThumbnailDefinition>(7);
|
||||
|
||||
for (ThumbnailDefinition thumbnailDefinition : this.thumbnailDefinitions.values())
|
||||
{
|
||||
if (this.contentService.getTransformer(
|
||||
mimetype,
|
||||
thumbnailDefinition.getMimetype(),
|
||||
thumbnailDefinition.getTransformationOptions()) != null)
|
||||
{
|
||||
result.add(thumbnailDefinition);
|
||||
}
|
||||
}
|
||||
|
||||
this.mimetypeMap.put(mimetype, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a thumnail details
|
||||
*
|
||||
* @param thumbnailDetails thumbnail details
|
||||
*/
|
||||
public void addThumbnailDetails(ThumbnailDetails thumbnailDetails)
|
||||
public void addThumbnailDefinition(ThumbnailDefinition thumbnailDetails)
|
||||
{
|
||||
String thumbnailName = thumbnailDetails.getName();
|
||||
if (thumbnailName == null)
|
||||
@@ -64,17 +125,17 @@ public class ThumbnailRegistry
|
||||
throw new ThumbnailException("When adding a thumbnail details object make sure the name is set.");
|
||||
}
|
||||
|
||||
this.thumbnailDetails.put(thumbnailName, thumbnailDetails);
|
||||
this.thumbnailDefinitions.put(thumbnailName, thumbnailDetails);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the details of a named thumbnail
|
||||
* Get the definition of a named thumbnail
|
||||
*
|
||||
* @param thumbnailNam the thumbnail name
|
||||
* @return ThumbnailDetails the details of the thumbnail
|
||||
*/
|
||||
public ThumbnailDetails getThumbnailDetails(String thumbnailName)
|
||||
public ThumbnailDefinition getThumbnailDefinition(String thumbnailName)
|
||||
{
|
||||
return this.thumbnailDetails.get(thumbnailName);
|
||||
return this.thumbnailDefinitions.get(thumbnailName);
|
||||
}
|
||||
}
|
||||
|
@@ -322,7 +322,7 @@ public class ThumbnailServiceImplTest extends BaseAlfrescoSpringTest
|
||||
{
|
||||
final NodeRef jpgOrig = createOrigionalContent(this.folder, MimetypeMap.MIMETYPE_IMAGE_JPEG);
|
||||
|
||||
ThumbnailDetails details = this.thumbnailService.getThumbnailRegistry().getThumbnailDetails("medium");
|
||||
ThumbnailDefinition details = this.thumbnailService.getThumbnailRegistry().getThumbnailDefinition("medium");
|
||||
final NodeRef thumbnail = this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT, details.getMimetype(), details.getTransformationOptions(), details.getName());
|
||||
|
||||
setComplete();
|
||||
@@ -342,8 +342,10 @@ public class ThumbnailServiceImplTest extends BaseAlfrescoSpringTest
|
||||
}
|
||||
});
|
||||
|
||||
Thread.sleep(100000);
|
||||
// TODO
|
||||
// this test should wait for the async action to run .. will need to commit transaction for that thou!
|
||||
|
||||
//Thread.sleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -353,10 +355,14 @@ public class ThumbnailServiceImplTest extends BaseAlfrescoSpringTest
|
||||
{
|
||||
NodeRef jpgOrig = createOrigionalContent(this.folder, MimetypeMap.MIMETYPE_IMAGE_JPEG);
|
||||
NodeRef gifOrig = createOrigionalContent(this.folder, MimetypeMap.MIMETYPE_IMAGE_GIF);
|
||||
NodeRef pdfOrig = createOrigionalContent(this.folder, MimetypeMap.MIMETYPE_PDF);
|
||||
NodeRef docOrig = createOrigionalContent(this.folder, MimetypeMap.MIMETYPE_WORD);
|
||||
|
||||
Map<String, Object> model = new HashMap<String, Object>(2);
|
||||
model.put("jpgOrig", jpgOrig);
|
||||
model.put("gifOrig", gifOrig);
|
||||
model.put("pdfOrig", pdfOrig);
|
||||
model.put("docOrig", docOrig);
|
||||
|
||||
ScriptLocation location = new ClasspathScriptLocation("org/alfresco/repo/thumbnail/script/test_thumbnailAPI.js");
|
||||
this.scriptService.executeScript(location, model);
|
||||
|
@@ -90,7 +90,7 @@ public class UpdateThumbnailActionExecuter extends ActionExecuterAbstractBase
|
||||
|
||||
// Get the details of the thumbnail
|
||||
ThumbnailRegistry registry = this.thumbnailService.getThumbnailRegistry();
|
||||
ThumbnailDetails details = registry.getThumbnailDetails(thumbnailName);
|
||||
ThumbnailDefinition details = registry.getThumbnailDefinition(thumbnailName);
|
||||
if (details == null)
|
||||
{
|
||||
// Throw exception
|
||||
|
@@ -25,7 +25,7 @@
|
||||
package org.alfresco.repo.thumbnail.script;
|
||||
|
||||
import org.alfresco.repo.jscript.BaseScopableProcessorExtension;
|
||||
import org.alfresco.repo.thumbnail.ThumbnailDetails;
|
||||
import org.alfresco.repo.thumbnail.ThumbnailDefinition;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ public class ScriptThumbnailService extends BaseScopableProcessorExtension
|
||||
*/
|
||||
public boolean isThumbnailNameRegistered(String thumbnailName)
|
||||
{
|
||||
return (this.serviceRegistry.getThumbnailService().getThumbnailRegistry().getThumbnailDetails(thumbnailName) != null);
|
||||
return (this.serviceRegistry.getThumbnailService().getThumbnailRegistry().getThumbnailDefinition(thumbnailName) != null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,7 +71,7 @@ public class ScriptThumbnailService extends BaseScopableProcessorExtension
|
||||
public String getPlaceHolderResourcePath(String thumbnailName)
|
||||
{
|
||||
String result = null;
|
||||
ThumbnailDetails details = this.serviceRegistry.getThumbnailService().getThumbnailRegistry().getThumbnailDetails(thumbnailName);
|
||||
ThumbnailDefinition details = this.serviceRegistry.getThumbnailService().getThumbnailRegistry().getThumbnailDefinition(thumbnailName);
|
||||
if (details != null)
|
||||
{
|
||||
result = details.getPlaceHolderResourcePath();
|
||||
|
@@ -23,6 +23,18 @@ function testThumbnailService()
|
||||
test.assertNotNull(thumbnailService.getPlaceHolderResourcePath("medium"));
|
||||
}
|
||||
|
||||
function testGetThumbnailDefintions()
|
||||
{
|
||||
var defs = jpgOrig.getThumbnailDefintions();
|
||||
//test.assertTrue(Array.contains(defs, "Medium"));
|
||||
//test.assertFalse(Array.contains(defs, "WebPreview"));
|
||||
|
||||
defs = pdfOrig.getThumbnailDefintions();
|
||||
//test.assertFalse(Array.contains(defs, "Medium"));
|
||||
//test.assertTrue(Array.contains(defs, "WebPreview"));
|
||||
}
|
||||
|
||||
// Execute the tests
|
||||
testCreateThumbnail();
|
||||
testThumbnailService();
|
||||
testThumbnailService();
|
||||
testGetThumbnailDefintions();
|
@@ -63,7 +63,7 @@ public interface ThumbnailService
|
||||
* The returned node reference is to the 'tn:thumbnail' content node that contains
|
||||
* the thumnail content in the standard 'cm:content' property.
|
||||
*
|
||||
* @see org.alfresco.service.cmr.thumnail.ThumbnailDetails
|
||||
* @see org.alfresco.service.cmr.thumnail.ThumbnailDefinition
|
||||
*
|
||||
* @param node the source content node
|
||||
* @param contentProperty the content property
|
||||
|
Reference in New Issue
Block a user