本文整理汇总了Java中org.alfresco.service.cmr.repository.ContentService.transform方法的典型用法代码示例。如果您正苦于以下问题:Java ContentService.transform方法的具体用法?Java ContentService.transform怎么用?Java ContentService.transform使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.alfresco.service.cmr.repository.ContentService
的用法示例。
在下文中一共展示了ContentService.transform方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transformDocument
import org.alfresco.service.cmr.repository.ContentService; //导入方法依赖的package包/类
private ScriptNode transformDocument(String mimetype, NodeRef destination)
{
ParameterCheck.mandatoryString("Mimetype", mimetype);
ParameterCheck.mandatory("Destination Node", destination);
final NodeRef sourceNodeRef = nodeRef;
// the delegate definition for transforming a document
Transformer transformer = new AbstractTransformer()
{
protected void doTransform(ContentService contentService,
ContentReader reader, ContentWriter writer)
{
TransformationOptions options = new TransformationOptions();
options.setSourceNodeRef(sourceNodeRef);
contentService.transform(reader, writer, options);
}
};
return transformNode(transformer, mimetype, destination);
}
示例2: getContentAsText
import org.alfresco.service.cmr.repository.ContentService; //导入方法依赖的package包/类
/**
* @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(getMimetype()))
{
result = getContentMaxLength(length);
}
else
{
// get the content reader
ContentService contentService = services.getContentService();
NodeRef nodeRef = getNodeRef();
ContentReader reader = contentService.getReader(nodeRef, property);
if (reader == null)
{
return ""; // Caller of this method returns "" if there is an IOException
}
// get the writer and set it up for text convert
ContentWriter writer = contentService.getTempWriter();
writer.setMimetype("text/plain");
writer.setEncoding(reader.getEncoding());
TransformationOptions options = new TransformationOptions();
options.setSourceNodeRef(nodeRef);
// try and transform the content
try
{
contentService.transform(reader, writer, options);
ContentReader resultReader = writer.getReader();
if (resultReader != null && reader.exists())
{
if (length != -1)
{
result = resultReader.getContentString(length);
}
else
{
result = resultReader.getContentString();
}
}
}
catch (NoTransformerException|UnsupportedTransformationException e)
{
// ignore
}
}
return result;
}