本文整理汇总了Java中org.alfresco.repo.thumbnail.ThumbnailDefinition类的典型用法代码示例。如果您正苦于以下问题:Java ThumbnailDefinition类的具体用法?Java ThumbnailDefinition怎么用?Java ThumbnailDefinition使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ThumbnailDefinition类属于org.alfresco.repo.thumbnail包,在下文中一共展示了ThumbnailDefinition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: update
import org.alfresco.repo.thumbnail.ThumbnailDefinition; //导入依赖的package包/类
/**
* Updates the thumbnails content
*/
public void update()
{
List<ChildAssociationRef> parentRefs = services.getNodeService().getParentAssocs(nodeRef, RenditionModel.ASSOC_RENDITION, RegexQNamePattern.MATCH_ALL);
// There should in fact only ever be one parent association of type rendition on any rendition node.
if (parentRefs.size() != 1)
{
StringBuilder msg = new StringBuilder();
msg.append("Node ")
.append(nodeRef)
.append(" has ")
.append(parentRefs.size())
.append(" rendition parents. Unable to update.");
if (logger.isWarnEnabled())
{
logger.warn(msg.toString());
}
throw new AlfrescoRuntimeException(msg.toString());
}
String name = parentRefs.get(0).getQName().getLocalName();
ThumbnailDefinition def = services.getThumbnailService().getThumbnailRegistry().getThumbnailDefinition(name);
services.getThumbnailService().updateThumbnail(this.nodeRef, def.getTransformationOptions());
}
示例2: getThumbnailDefinitions
import org.alfresco.repo.thumbnail.ThumbnailDefinition; //导入依赖的package包/类
/**
* 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[] getThumbnailDefinitions()
{
ThumbnailService thumbnailService = this.services.getThumbnailService();
List<String> result = new ArrayList<String>(7);
Serializable value = this.nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);
ContentData contentData = DefaultTypeConverter.INSTANCE.convert(ContentData.class, value);
if (ContentData.hasContent(contentData))
{
String mimetype = contentData.getMimetype();
List<ThumbnailDefinition> thumbnailDefinitions = thumbnailService.getThumbnailRegistry().getThumbnailDefinitions(mimetype, contentData.getSize());
for (ThumbnailDefinition thumbnailDefinition : thumbnailDefinitions)
{
result.add(thumbnailDefinition.getName());
}
}
return (String[])result.toArray(new String[result.size()]);
}
示例3: requestRenditions
import org.alfresco.repo.thumbnail.ThumbnailDefinition; //导入依赖的package包/类
private void requestRenditions(List<ThumbnailDefinition> thumbnailDefs, Node fileNode)
{
if (thumbnailDefs != null)
{
ThumbnailRegistry registry = thumbnailService.getThumbnailRegistry();
for (ThumbnailDefinition thumbnailDef : thumbnailDefs)
{
NodeRef sourceNodeRef = fileNode.getNodeRef();
String mimeType = fileNode.getContent().getMimeType();
long size = fileNode.getContent().getSizeInBytes();
// Check if anything is currently available to generate thumbnails for the specified mimeType
if (! registry.isThumbnailDefinitionAvailable(null, mimeType, size, sourceNodeRef, thumbnailDef))
{
throw new InvalidArgumentException("Unable to create thumbnail '" + thumbnailDef.getName() + "' for " +
mimeType + " as no transformer is currently available.");
}
Action action = ThumbnailHelper.createCreateThumbnailAction(thumbnailDef, sr);
// Queue async creation of thumbnail
actionService.executeAction(action, sourceNodeRef, true, true);
}
}
}
示例4: getPlaceHolderResourcePath
import org.alfresco.repo.thumbnail.ThumbnailDefinition; //导入依赖的package包/类
/**
* Gets the resource path for the place holder thumbnail for the given named thumbnail.
*
* Returns null if none set.
*
* @param thumbnailName the thumbnail name
* @return String the place holder thumbnail resource path, null if none set
*/
public String getPlaceHolderResourcePath(String thumbnailName)
{
String result = null;
ThumbnailDefinition details = this.serviceRegistry.getThumbnailService().getThumbnailRegistry().getThumbnailDefinition(thumbnailName);
if (details != null)
{
result = details.getPlaceHolderResourcePath();
}
return result;
}
示例5: thumbnailTransformationsUsingJodConverter
import org.alfresco.repo.thumbnail.ThumbnailDefinition; //导入依赖的package包/类
/**
* This test method tests the built-in thumbnail transformations - all for a Word source document.
* This will include transformations doc-pdf-png and doc-pdf-swf. ALF-2070
*/
@Test
public void thumbnailTransformationsUsingJodConverter()
{
// If OpenOffice is not available then we will ignore this test (by passing it).
// This is because not all the build servers have OOo installed.
if (!isOpenOfficeAvailable())
{
System.out.println("Did not run " + this.getClass().getSimpleName() + ".thumbnailTransformationsUsingJodConverter" +
" because OOo is not available.");
return;
}
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
ThumbnailRegistry thumbnailRegistry = thumbnailService.getThumbnailRegistry();
for (ThumbnailDefinition thumbDef : thumbnailRegistry.getThumbnailDefinitions())
{
if (log.isDebugEnabled())
{
log.debug("Testing thumbnail definition " + thumbDef.getName());
}
NodeRef thumbnail = thumbnailService.createThumbnail(contentNodeRef, ContentModel.PROP_CONTENT,
thumbDef.getMimetype(), thumbDef.getTransformationOptions(), thumbDef.getName());
assertNotNull("Thumbnail was unexpectedly null.", thumbnail);
}
return null;
}
});
}
示例6: getThumbnailDefs
import org.alfresco.repo.thumbnail.ThumbnailDefinition; //导入依赖的package包/类
private List<ThumbnailDefinition> getThumbnailDefs(Set<String> renditionNames)
{
List<ThumbnailDefinition> thumbnailDefs = null;
if (renditionNames != null)
{
// If thumbnail generation has been configured off, then don't bother.
if (!thumbnailService.getThumbnailsEnabled())
{
throw new DisabledServiceException("Thumbnail generation has been disabled.");
}
thumbnailDefs = new ArrayList<>(renditionNames.size());
ThumbnailRegistry registry = thumbnailService.getThumbnailRegistry();
for (String renditionName : renditionNames)
{
// Use the thumbnail registry to get the details of the thumbnail
ThumbnailDefinition thumbnailDef = registry.getThumbnailDefinition(renditionName);
if (thumbnailDef == null)
{
throw new NotFoundException(renditionName + " is not registered.");
}
thumbnailDefs.add(thumbnailDef);
}
}
return thumbnailDefs;
}
示例7: createRendition
import org.alfresco.repo.thumbnail.ThumbnailDefinition; //导入依赖的package包/类
@Override
public void createRendition(String nodeId, Rendition rendition, boolean executeAsync, Parameters parameters)
{
// If thumbnail generation has been configured off, then don't bother.
if (!thumbnailService.getThumbnailsEnabled())
{
throw new DisabledServiceException("Thumbnail generation has been disabled.");
}
final NodeRef sourceNodeRef = validateSourceNode(nodeId);
final NodeRef renditionNodeRef = getRenditionByName(sourceNodeRef, rendition.getId(), parameters);
if (renditionNodeRef != null)
{
throw new ConstraintViolatedException(rendition.getId() + " rendition already exists.");
}
// Use the thumbnail registry to get the details of the thumbnail
ThumbnailRegistry registry = thumbnailService.getThumbnailRegistry();
ThumbnailDefinition thumbnailDefinition = registry.getThumbnailDefinition(rendition.getId());
if (thumbnailDefinition == null)
{
throw new NotFoundException(rendition.getId() + " is not registered.");
}
ContentData contentData = getContentData(sourceNodeRef, true);
// Check if anything is currently available to generate thumbnails for the specified mimeType
if (!registry.isThumbnailDefinitionAvailable(contentData.getContentUrl(), contentData.getMimetype(), contentData.getSize(), sourceNodeRef,
thumbnailDefinition))
{
throw new InvalidArgumentException("Unable to create thumbnail '" + thumbnailDefinition.getName() + "' for " +
contentData.getMimetype() + " as no transformer is currently available.");
}
Action action = ThumbnailHelper.createCreateThumbnailAction(thumbnailDefinition, serviceRegistry);
// Create thumbnail - or else queue for async creation
actionService.executeAction(action, sourceNodeRef, true, executeAsync);
}
示例8: toApiRendition
import org.alfresco.repo.thumbnail.ThumbnailDefinition; //导入依赖的package包/类
protected Rendition toApiRendition(ThumbnailDefinition thumbnailDefinition)
{
ContentInfo contentInfo = new ContentInfo(thumbnailDefinition.getMimetype(),
getMimeTypeDisplayName(thumbnailDefinition.getMimetype()), null, null);
Rendition apiRendition = new Rendition();
apiRendition.setId(thumbnailDefinition.getName());
apiRendition.setContent(contentInfo);
apiRendition.setStatus(RenditionStatus.NOT_CREATED);
return apiRendition;
}
示例9: getRendition
import org.alfresco.repo.thumbnail.ThumbnailDefinition; //导入依赖的package包/类
@Override
public Rendition getRendition(String nodeId, String renditionId, Parameters parameters)
{
final NodeRef nodeRef = validateSourceNode(nodeId);
NodeRef renditionNodeRef = getRenditionByName(nodeRef, renditionId, parameters);
// if there is no rendition, then try to find the available/registered rendition (yet to be created).
if (renditionNodeRef == null)
{
ThumbnailDefinition thumbnailDefinition = thumbnailService.getThumbnailRegistry().getThumbnailDefinition(renditionId);
if (thumbnailDefinition == null)
{
throw new NotFoundException(renditionId + " is not registered.");
}
else
{
String contentMimeType = getMimeType(nodeRef);
// List all available thumbnail definitions for the source node
List<ThumbnailDefinition> thumbnailDefinitions = thumbnailService.getThumbnailRegistry().getThumbnailDefinitions(contentMimeType, -1);
boolean found = false;
for (ThumbnailDefinition td : thumbnailDefinitions)
{
// Check the registered renditionId is applicable for the node's mimeType
if (renditionId.equals(td.getName()))
{
found = true;
break;
}
}
if (!found)
{
throw new NotFoundException(renditionId + " is not applicable for the node's mimeType " + contentMimeType);
}
}
return toApiRendition(thumbnailDefinition);
}
return toApiRendition(renditionNodeRef);
}
示例10: createRendition
import org.alfresco.repo.thumbnail.ThumbnailDefinition; //导入依赖的package包/类
@Override
public void createRendition(String nodeId, Rendition rendition, Parameters parameters)
{
// If thumbnail generation has been configured off, then don't bother.
if (!thumbnailService.getThumbnailsEnabled())
{
throw new DisabledServiceException("Thumbnail generation has been disabled.");
}
final NodeRef sourceNodeRef = validateSourceNode(nodeId);
final NodeRef renditionNodeRef = getRenditionByName(sourceNodeRef, rendition.getId(), parameters);
if (renditionNodeRef != null)
{
throw new ConstraintViolatedException(rendition.getId() + " rendition already exists.");
}
// Use the thumbnail registry to get the details of the thumbnail
ThumbnailRegistry registry = thumbnailService.getThumbnailRegistry();
ThumbnailDefinition thumbnailDefinition = registry.getThumbnailDefinition(rendition.getId());
if (thumbnailDefinition == null)
{
throw new NotFoundException(rendition.getId() + " is not registered.");
}
ContentData contentData = getContentData(sourceNodeRef, true);
// Check if anything is currently available to generate thumbnails for the specified mimeType
if (!registry.isThumbnailDefinitionAvailable(contentData.getContentUrl(), contentData.getMimetype(), contentData.getSize(), sourceNodeRef,
thumbnailDefinition))
{
throw new InvalidArgumentException("Unable to create thumbnail '" + thumbnailDefinition.getName() + "' for " +
contentData.getMimetype() + " as no transformer is currently available.");
}
Action action = ThumbnailHelper.createCreateThumbnailAction(thumbnailDefinition, serviceRegistry);
// Queue async creation of thumbnail
actionService.executeAction(action, sourceNodeRef, true, true);
}
示例11: getMimeAwarePlaceHolderResourcePath
import org.alfresco.repo.thumbnail.ThumbnailDefinition; //导入依赖的package包/类
/**
* Gets the resource path for the place holder thumbnail for the given named thumbnail and the given mime type.
* If there is no icon available for the specified MIME type, a generic icon will be used instead.
* The generic icon is that returned by {@link #getPlaceHolderResourcePath(String)}
* If neither a MIME-specific icon nor a generic icon is available, <code>null</code> is returned.
*
* @param thumbnailName the thumbnail name
* @param mimetype the mimetype of the piece of content.
* @return String the place holder thumbnail resource path
* @see #getPlaceHolderResourcePath(String)
*/
public String getMimeAwarePlaceHolderResourcePath(String thumbnailName, String mimetype)
{
String result = null;
// Sanity check
if (mimetype == null || mimetype.trim().length() == 0)
{
return getPlaceHolderResourcePath(thumbnailName);
}
Map<String, String> extensionsByMimetype = serviceRegistry.getMimetypeService().getExtensionsByMimetype();
// We get the extension for the mime type directly from the Map as we need
// to know if a mimetype is not recognised by the system. (The MimetypeService gives us ".bin"
// for unrecognised mimetypes.)
// The mime fragment is the part of the resource path that refers to the mime type
// e.g. "_pdf" in alfresco/thumbnail/thumbnail_placeholder_doclib_pdf.png
String extension = extensionsByMimetype.get(mimetype);
if (extension != null)
{
StringBuilder sb = new StringBuilder();
sb.append("_").append(String.valueOf(extension));
String mimeFragment = sb.toString();
ThumbnailDefinition details = serviceRegistry.getThumbnailService().getThumbnailRegistry().getThumbnailDefinition(thumbnailName);
if (details != null)
{
String resourcePath = details.getMimeAwarePlaceHolderResourcePath();
if (resourcePath != null)
{
// It's possible that the mimetype service recognises mime types for which we have no icon.
String formattedResourcePath = MessageFormat.format(resourcePath, mimeFragment);
boolean iconResourceExists = classpathResourceExists("/" + formattedResourcePath);
if (iconResourceExists)
{
result = formattedResourcePath;
}
}
}
}
return result == null ? getPlaceHolderResourcePath(thumbnailName) : result;
}
示例12: userWithReadOnlyAccessToNodeShouldNotCauseFailedThumbnailProblems
import org.alfresco.repo.thumbnail.ThumbnailDefinition; //导入依赖的package包/类
/** This test case relates to ALF-17797. */
@Test public void userWithReadOnlyAccessToNodeShouldNotCauseFailedThumbnailProblems() throws Exception
{
final String siteConsumer = testSiteInfo.siteConsumer;
// Let's trigger the creation of a doclib thumbnail for the broken JPG node.
// We know this cannot succeed. We also know the user triggering it does not have write permissions for the node.
AuthenticationUtil.setFullyAuthenticatedUser(siteConsumer);
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
// This is what ScriptNode.createThumbnail does
ThumbnailDefinition details = thumbnailRegistry.getThumbnailDefinition("doclib");
Action action = ThumbnailHelper.createCreateThumbnailAction(details, services);
// Queue async creation of thumbnail
services.getActionService().executeAction(action, brokenJpg, true, true);
return null;
}
});
// FIXME Yuck. Sleeping to wait for the completion of the above async action.
Thread.sleep(2000);
// The node in question should have no thumbnail/rendition. But it should be marked as having had a failed rendition.
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
assertTrue("Expected an empty list of renditions for brokenJpg.",
renditionService.getRenditions(brokenJpg).isEmpty());
assertTrue("Expected brokenJpg to have FailedThumbnailSource aspect.",
nodeService.hasAspect(brokenJpg, ContentModel.ASPECT_FAILED_THUMBNAIL_SOURCE));
List<ChildAssociationRef> failedThumbnailChildren = nodeService.getChildAssocs(brokenJpg, ContentModel.ASSOC_FAILED_THUMBNAIL, RegexQNamePattern.MATCH_ALL);
assertEquals("Wrong number of failed thumbnail child nodes.", 1, failedThumbnailChildren.size());
NodeRef failedThumbnailChildNode = failedThumbnailChildren.get(0).getChildRef();
assertEquals(1, nodeService.getProperty(failedThumbnailChildNode, ContentModel.PROP_FAILURE_COUNT));
return null;
}
});
}
示例13: getRenditions
import org.alfresco.repo.thumbnail.ThumbnailDefinition; //导入依赖的package包/类
@Override
public CollectionWithPagingInfo<Rendition> getRenditions(String nodeId, Parameters parameters)
{
final NodeRef nodeRef = validateSourceNode(nodeId);
String contentMimeType = getMimeType(nodeRef);
Query query = parameters.getQuery();
boolean includeCreated = true;
boolean includeNotCreated = true;
String status = getStatus(parameters);
if (status != null)
{
includeCreated = RenditionStatus.CREATED.equals(RenditionStatus.valueOf(status));
includeNotCreated = !includeCreated;
}
Map<String, Rendition> apiRenditions = new TreeMap<>();
if (includeNotCreated)
{
// List all available thumbnail definitions
List<ThumbnailDefinition> thumbnailDefinitions = thumbnailService.getThumbnailRegistry().getThumbnailDefinitions(contentMimeType, -1);
for (ThumbnailDefinition thumbnailDefinition : thumbnailDefinitions)
{
apiRenditions.put(thumbnailDefinition.getName(), toApiRendition(thumbnailDefinition));
}
}
List<ChildAssociationRef> nodeRefRenditions = renditionService.getRenditions(nodeRef);
if (!nodeRefRenditions.isEmpty())
{
for (ChildAssociationRef childAssociationRef : nodeRefRenditions)
{
NodeRef renditionNodeRef = childAssociationRef.getChildRef();
Rendition apiRendition = toApiRendition(renditionNodeRef);
if (includeCreated)
{
// Replace/append any thumbnail definitions with created rendition info
apiRenditions.put(apiRendition.getId(), apiRendition);
}
else
{
// Remove any thumbnail definitions that has been created from the list,
// as the filter requires only the Not_Created renditions
apiRenditions.remove(apiRendition.getId());
}
}
}
// Wrap paging info, as the core service doesn't support paging
Paging paging = parameters.getPaging();
PagingResults<Rendition> results = Util.wrapPagingResults(paging, apiRenditions.values());
return CollectionWithPagingInfo.asPaged(paging, results.getPage(), results.hasMoreItems(), results.getTotalResultCount().getFirst());
}
示例14: getRendition
import org.alfresco.repo.thumbnail.ThumbnailDefinition; //导入依赖的package包/类
@Override
public Rendition getRendition(String nodeId, String renditionId, Parameters parameters)
{
final NodeRef nodeRef = validateSourceNode(nodeId);
NodeRef renditionNodeRef = getRenditionByName(nodeRef, renditionId, parameters);
boolean includeNotCreated = true;
String status = getStatus(parameters);
if (status != null)
{
includeNotCreated = !RenditionStatus.CREATED.equals(RenditionStatus.valueOf(status));
}
// if there is no rendition, then try to find the available/registered rendition (yet to be created).
if (renditionNodeRef == null && includeNotCreated)
{
ThumbnailDefinition thumbnailDefinition = thumbnailService.getThumbnailRegistry().getThumbnailDefinition(renditionId);
if (thumbnailDefinition == null)
{
throw new NotFoundException(renditionId + " is not registered.");
}
else
{
String contentMimeType = getMimeType(nodeRef);
// List all available thumbnail definitions for the source node
List<ThumbnailDefinition> thumbnailDefinitions = thumbnailService.getThumbnailRegistry().getThumbnailDefinitions(contentMimeType, -1);
boolean found = false;
for (ThumbnailDefinition td : thumbnailDefinitions)
{
// Check the registered renditionId is applicable for the node's mimeType
if (renditionId.equals(td.getName()))
{
found = true;
break;
}
}
if (!found)
{
throw new NotFoundException(renditionId + " is not applicable for the node's mimeType " + contentMimeType);
}
}
return toApiRendition(thumbnailDefinition);
}
if (renditionNodeRef == null)
{
throw new NotFoundException("The rendition with id: " + renditionId + " was not found.");
}
return toApiRendition(renditionNodeRef);
}
示例15: getRenditions
import org.alfresco.repo.thumbnail.ThumbnailDefinition; //导入依赖的package包/类
@Override
public CollectionWithPagingInfo<Rendition> getRenditions(String nodeId, Parameters parameters)
{
final NodeRef nodeRef = validateSourceNode(nodeId);
String contentMimeType = getMimeType(nodeRef);
Query query = parameters.getQuery();
boolean includeCreated = true;
boolean includeNotCreated = true;
if (query != null)
{
// Filtering via "where" clause
MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(RENDITION_STATUS_COLLECTION_EQUALS_QUERY_PROPERTIES, null);
QueryHelper.walk(query, propertyWalker);
String withStatus = propertyWalker.getProperty(PARAM_STATUS, WhereClauseParser.EQUALS);
if (withStatus != null)
{
try
{
includeCreated = RenditionStatus.CREATED.equals(RenditionStatus.valueOf(withStatus));
}
catch (IllegalArgumentException ex)
{
throw new InvalidArgumentException("Invalid status value: " + withStatus);
}
includeNotCreated = !includeCreated;
}
}
Map<String, Rendition> apiRenditions = new TreeMap<>();
if (includeNotCreated)
{
// List all available thumbnail definitions
List<ThumbnailDefinition> thumbnailDefinitions = thumbnailService.getThumbnailRegistry().getThumbnailDefinitions(contentMimeType, -1);
for (ThumbnailDefinition thumbnailDefinition : thumbnailDefinitions)
{
apiRenditions.put(thumbnailDefinition.getName(), toApiRendition(thumbnailDefinition));
}
}
List<ChildAssociationRef> nodeRefRenditions = renditionService.getRenditions(nodeRef);
if (!nodeRefRenditions.isEmpty())
{
for (ChildAssociationRef childAssociationRef : nodeRefRenditions)
{
NodeRef renditionNodeRef = childAssociationRef.getChildRef();
Rendition apiRendition = toApiRendition(renditionNodeRef);
if (includeCreated)
{
// Replace/append any thumbnail definitions with created rendition info
apiRenditions.put(apiRendition.getId(), apiRendition);
}
else
{
// Remove any thumbnail definitions that has been created from the list,
// as the filter requires only the Not_Created renditions
apiRenditions.remove(apiRendition.getId());
}
}
}
// Wrap paging info, as the core service doesn't support paging
Paging paging = parameters.getPaging();
PagingResults<Rendition> results = Util.wrapPagingResults(paging, apiRenditions.values());
return CollectionWithPagingInfo.asPaged(paging, results.getPage(), results.hasMoreItems(), results.getTotalResultCount().getFirst());
}