mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Merged from BRANCHES/DEV/KEVINR:
. NodeInfo panel and Ajax client library - Rewrite of Node Info panel - Alfresco common DOM methods refactored into namespaced object (YUI/Dojo style) Alfresco.Dom - Addition of useful DOM and 'smart' alignment method to common.js - OpenSearch now uses additional namespace for it's global method handlers: Alfresco.OpenSearchEngine - Temporary icons added for pop-up node info panel . Additional FreeMarker model API method "cropContent(contentprop, length)" to return the first N bytes of a content stream - auto converted to plain/text from all supported transformation mimetypes . DownloadContentServlet now handles ContentIOException more gracefully . AbstractContentReader fixed to handle empty file data when requesting N characters from a content stream . Yahoo scripts move to PageTag rendering as appropriate . Refactoring of existing ajax components that output Yahoo scripts git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5253 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -36,6 +36,8 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.action.executer.TransformActionExecuter;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
||||
import org.alfresco.repo.template.LuceneSearchResultsMap;
|
||||
import org.alfresco.repo.template.NamePathResultsMap;
|
||||
@@ -793,6 +795,64 @@ public class TemplateNode implements Serializable
|
||||
return (reader != null && reader.exists()) ? reader.getContentString() : "";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the content stream to the specified maximum length in characters
|
||||
*/
|
||||
public String getContent(int length)
|
||||
{
|
||||
ContentService contentService = services.getContentService();
|
||||
ContentReader reader = contentService.getReader(nodeRef, property);
|
||||
|
||||
return (reader != null && reader.exists()) ? reader.getContentString(length) : "";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param length Length of the character stream to return, or -1 for all
|
||||
*
|
||||
* @return the binary content stream converted to text using any available transformer
|
||||
* if fails to convert then null will be returned
|
||||
*/
|
||||
public String getContentAsText(int length)
|
||||
{
|
||||
String result = null;
|
||||
|
||||
if (MimetypeMap.MIMETYPE_TEXT_PLAIN.equals(mimetype))
|
||||
{
|
||||
result = getContent(length);
|
||||
}
|
||||
else
|
||||
{
|
||||
// get the content reader
|
||||
ContentService contentService = services.getContentService();
|
||||
ContentReader reader = contentService.getReader(nodeRef, property);
|
||||
|
||||
// get the writer and set it up for text convert
|
||||
ContentWriter writer = contentService.getWriter(null, ContentModel.PROP_CONTENT, true);
|
||||
writer.setMimetype("text/plain");
|
||||
writer.setEncoding(reader.getEncoding());
|
||||
|
||||
// try and transform the content
|
||||
if (contentService.isTransformable(reader, writer))
|
||||
{
|
||||
contentService.transform(reader, writer);
|
||||
|
||||
ContentReader resultReader = writer.getReader();
|
||||
if (resultReader != null && reader.exists())
|
||||
{
|
||||
if (length != -1)
|
||||
{
|
||||
result = resultReader.getContentString(length);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = resultReader.getContentString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
|
Reference in New Issue
Block a user