当前位置: 首页>>代码示例>>Java>>正文


Java ContentWriter.setEncoding方法代码示例

本文整理汇总了Java中org.alfresco.service.cmr.repository.ContentWriter.setEncoding方法的典型用法代码示例。如果您正苦于以下问题:Java ContentWriter.setEncoding方法的具体用法?Java ContentWriter.setEncoding怎么用?Java ContentWriter.setEncoding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.alfresco.service.cmr.repository.ContentWriter的用法示例。


在下文中一共展示了ContentWriter.setEncoding方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createFreeMarkerNode

import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
private NodeRef createFreeMarkerNode(NodeRef companyHome)
{
    NodeRef fmNode = createContentNode(companyHome, "testFreeMarkerNode");
    nodeService.setProperty(fmNode, ContentModel.PROP_CONTENT, new ContentData(null,
                MimetypeMap.MIMETYPE_TEXT_PLAIN, 0L, null));

    URL url = getClass().getResource(FM_TEMPLATE);
    assertNotNull("The url is null", url);
    File templateFile = new File(url.getFile());
    assertTrue("The template file does not exist", templateFile.exists());

    ContentWriter fmWriter = contentService.getWriter(fmNode, ContentModel.PROP_CONTENT, true);
    fmWriter.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
    fmWriter.setEncoding("UTF-8");
    fmWriter.putContent(templateFile);
    return fmNode;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:18,代码来源:RenditionServiceIntegrationTest.java

示例2: createPdfDocumentAsCurrentlyAuthenticatedUser

import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
private NodeRef createPdfDocumentAsCurrentlyAuthenticatedUser(final String nodeName)
{
    Map<QName, Serializable> props = new HashMap<QName, Serializable>();
    props.put(ContentModel.PROP_NAME, nodeName);
    NodeRef result = nodeService.createNode(testFolder, 
                                            ContentModel.ASSOC_CONTAINS, 
                                            QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, nodeName), 
                                            ContentModel.TYPE_CONTENT,
                                            props).getChildRef();
    
    File file = loadQuickPdfFile();

    // Set the content
    ContentWriter writer = contentService.getWriter(result, ContentModel.PROP_CONTENT, true);
    writer.setMimetype(MimetypeMap.MIMETYPE_PDF);
    writer.setEncoding("UTF-8");
    
    writer.putContent(file);
    
    return result;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:22,代码来源:MultiUserRenditionTest.java

示例3: createOriginalContent

import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
private NodeRef createOriginalContent(NodeRef parentFolder, String baseName, String mimetype) throws IOException
{
    String ext = this.mimetypeMap.getExtension(mimetype);
    File origFile = AbstractContentTransformerTest.loadQuickTestFile(ext);

    Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
    props.put(ContentModel.PROP_NAME, baseName + "." + ext);
    NodeRef node = this.secureNodeService.createNode(parentFolder, ContentModel.ASSOC_CONTAINS,
                QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "original." + ext),
                ContentModel.TYPE_CONTENT, props).getChildRef();

    ContentWriter writer = this.contentService.getWriter(node, ContentModel.PROP_CONTENT, true);
    writer.setMimetype(mimetype);
    writer.setEncoding("UTF-8");
    writer.putContent(origFile);

    return node;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:19,代码来源:ThumbnailServiceImplTest.java

示例4: writeContent

import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
/**
 * Write content to the node from InputStream.
 * 
 * @param nodeRef Target node.
 * @param content Content stream.
 * @param mimetype MIME content type.
 * @param encoding Encoding. Can be null for text based content, n which case the best guess.
 */
protected void writeContent(NodeRef nodeRef, InputStream content, String mimetype, String encoding)
{
    InputStream bis = new BufferedInputStream(content, 4092);

    // Only guess the encoding if it has not been supplied
    if (encoding == null)
    {
        if (mimetypeService.isText(mimetype))
        {
            ContentCharsetFinder charsetFinder = mimetypeService.getContentCharsetFinder();
            encoding = charsetFinder.getCharset(bis, mimetype).name();
        }
        else
        {
            encoding = "UTF-8";
        }
    }
    
    if (log.isDebugEnabled())
    {
        log.debug("Write content (MimeType=\"" + mimetype + "\", Encoding=\"" + encoding + "\"");
    }
    
    
    ContentService contentService = getContentService();
    ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
    writer.setMimetype(mimetype);
    writer.setEncoding(encoding);
    writer.putContent(bis);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:39,代码来源:AbstractEmailMessageHandler.java

示例5: makeCopy

import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
private void makeCopy(NodeRef nodeRef)
{
    InputStream resource = getClass().getClassLoader().getResourceAsStream(fileName);
    if (resource != null)
    {
        ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
        writer.setEncoding("UTF-8");
        writer.setMimetype(TEXT_CONTENT_MIMETYPE);
        writer.putContent(resource);
    }
    else throw new PatchException("Resource '"+fileName+"' not found");
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:13,代码来源:UpdateAuditTemplatePatch.java

示例6: updateContent

import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
private void updateContent(NodeRef nodeRef)
{
    // Make versionable
    nodeService.addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, null);
    
    // Update content
    InputStream is = this.getClass().getClassLoader().getResourceAsStream(source);
    if (is != null)
    {
        ContentWriter contentWriter = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
        contentWriter.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
        contentWriter.setEncoding("UTF-8");
        contentWriter.putContent(is);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:16,代码来源:FixTemplatePatch.java

示例7: testALF17549

import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
/**
 * https://issues.alfresco.com/jira/browse/ALF-17549
 */
public void testALF17549() throws Exception
{
    permissionService.setPermission(rootNodeRef, USER_1, PermissionService.COORDINATOR, true);

    AuthenticationUtil.setRunAsUser(USER_1);

    String sourceName = "sourceNode.txt";
    Map<QName, Serializable> props = new HashMap<QName, Serializable>();

    props.put(ContentModel.PROP_NAME, sourceName);

    NodeRef sourceNodeRef = nodeService.createNode(this.rootNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("{test}" + sourceName), ContentModel.TYPE_CONTENT, props)
            .getChildRef();

    ContentWriter writer = contentService.getWriter(sourceNodeRef, ContentModel.PROP_CONTENT, true);
    writer.setEncoding("UTF-8");
    writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
    writer.putContent("This is sample text content for unit test.");

    NodeRef targetNodeRef = nodeService.createNode(this.rootNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("{test}targetNode"), ContentModel.TYPE_FOLDER)
            .getChildRef();

    List<ChildAssociationRef> childAssoc = nodeService.getChildAssocs(targetNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("{test}sourceNode.html"));

    assertEquals(0, childAssoc.size());

    Action action = this.actionService.createAction(TransformActionExecuter.NAME);

    action.setParameterValue(TransformActionExecuter.PARAM_MIME_TYPE, MimetypeMap.MIMETYPE_HTML);
    action.setParameterValue(TransformActionExecuter.PARAM_DESTINATION_FOLDER, targetNodeRef);
    action.setParameterValue(TransformActionExecuter.PARAM_ASSOC_QNAME, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "copy"));
    action.setParameterValue(TransformActionExecuter.PARAM_ASSOC_TYPE_QNAME, ContentModel.ASSOC_CONTAINS);
    actionService.executeAction(action, sourceNodeRef);

    childAssoc = nodeService.getChildAssocs(targetNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("{test}sourceNode.html"));

    assertEquals(1, childAssoc.size());
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:42,代码来源:CopyServiceImplTest.java

示例8: createXmlFile

import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
private FileInfo createXmlFile(NodeRef folder, String content)
{
    String name = GUID.generate();
    FileInfo testXmlFile = fileFolderService.create(folder, name + ".xml", ContentModel.TYPE_CONTENT);
    ContentWriter writer = contentService.getWriter(testXmlFile.getNodeRef(), ContentModel.PROP_CONTENT, true);
    writer.setMimetype("text/xml");
    writer.setEncoding("UTF-8");
    writer.putContent(content);
    return testXmlFile;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:11,代码来源:XSLTProcessorTest.java

示例9: createTestContent

import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
private void createTestContent(NodeRef parentNode, int documentsAmount)
{
    for (int i = 0; i < documentsAmount; i++)
    {
        String testDocumentName = String.format(TEST_DOCUMENT_NAME_PATTERN, i, System.currentTimeMillis());
        FileInfo testDocument = fileFolderService.create(parentNode, testDocumentName, ContentModel.TYPE_CONTENT);
        ContentWriter writer = fileFolderService.getWriter(testDocument.getNodeRef());
        writer.putContent(String.format(TEXT_DOCUMENT_CONTENT_PATTERN, testDocumentName));
        writer.setMimetype(TEST_MIMETYPE);
        writer.setEncoding(TEST_ENCODING);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:13,代码来源:GetMethodRegressionTest.java

示例10: updateTextContent

import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
private void updateTextContent(NodeRef contentRef, String textData)
{
    ContentWriter writer = contentService.getWriter(contentRef, ContentModel.PROP_CONTENT, true);
    
    writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
    writer.setEncoding("UTF-8");
    
    writer.putContent(textData);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:10,代码来源:UserUsageTest.java

示例11: writeDestinationReport

import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
public NodeRef writeDestinationReport(String transferName,
        TransferTarget target,
        File tempFile)
{
   
    String title = transferName + "_destination";
    String description = "Transfer Destination Report - target: " + target.getName();
    String name = title + ".xml";
    
    logger.debug("writing destination transfer report " + title);
    logger.debug("parent node ref " + target.getNodeRef());
    
    Map<QName, Serializable> properties = new HashMap<QName, Serializable> ();
    properties.put(ContentModel.PROP_NAME, name);
    properties.put(ContentModel.PROP_TITLE, title);
    properties.put(ContentModel.PROP_DESCRIPTION, description);
    ChildAssociationRef ref = nodeService.createNode(target.getNodeRef(), 
            ContentModel.ASSOC_CONTAINS, 
            QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name), 
            TransferModel.TYPE_TRANSFER_REPORT_DEST, 
            properties);
    
    ContentWriter writer = contentService.getWriter(ref.getChildRef(), 
            ContentModel.PROP_CONTENT, true);
    writer.setLocale(Locale.getDefault());
    writer.setMimetype(MimetypeMap.MIMETYPE_XML);
    writer.setEncoding(DEFAULT_ENCODING);
    writer.putContent(tempFile);
    
    logger.debug("written " + name + ", " + ref.getChildRef());
    
    return ref.getChildRef();
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:34,代码来源:TransferReporterImpl.java

示例12: createTestContent

import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
private List<FileInfo> createTestContent(FileInfo parent, int count)
{
    List<FileInfo> result = new ArrayList<FileInfo>(count);
    for(int i = 0; i < count; i++)
    {
        FileInfo contentItem = fileFolderService.create(parent.getNodeRef(), "content_" + i, ContentModel.TYPE_CONTENT, ContentModel.ASSOC_CONTAINS);
        ContentWriter contentWriter = contentService.getWriter(contentItem.getNodeRef(), ContentModel.PROP_CONTENT, false);
        contentWriter.setEncoding("UTF-8");
        contentWriter.putContent("TEST" + i);
    }
    return result;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:13,代码来源:ImapServiceImplCacheTest.java

示例13: testMimetypAndEncodingAndLocale

import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
@Test
public void testMimetypAndEncodingAndLocale() throws Exception
{
    ContentWriter writer = getWriter();
    // set mimetype and encoding
    writer.setMimetype("text/plain");
    writer.setEncoding("UTF-16");
    writer.setLocale(Locale.CHINESE);
    
    // create a UTF-16 string
    String content = "A little bit o' this and a little bit o' that";
    byte[] bytesUtf16 = content.getBytes("UTF-16");
    // write the bytes directly to the writer
    OutputStream os = writer.getContentOutputStream();
    os.write(bytesUtf16);
    os.close();
    
    // now get a reader from the writer
    ContentReader reader = writer.getReader();
    assertEquals("Writer -> Reader content URL mismatch", writer.getContentUrl(), reader.getContentUrl());
    assertEquals("Writer -> Reader mimetype mismatch", writer.getMimetype(), reader.getMimetype());
    assertEquals("Writer -> Reader encoding mismatch", writer.getEncoding(), reader.getEncoding());
    assertEquals("Writer -> Reader locale mismatch", writer.getLocale(), reader.getLocale());
    
    // now get the string directly from the reader
    String contentCheck = reader.getContentString();     // internally it should have taken care of the encoding
    assertEquals("Encoding and decoding of strings failed", content, contentCheck);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:29,代码来源:AbstractWritableContentStoreTest.java

示例14: transformNode

import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
/**
 * Generic method to transform Node content from one mimetype to another.
 * 
 * @param transformer   The Transformer delegate supplying the transformation logic
 * @param mimetype      Mimetype of the destination content
 * @param destination   Destination folder location for the resulting document
 * 
 * @return Node representing the transformed content - or null if the transform failed
 */
private ScriptNode transformNode(Transformer transformer, String mimetype, NodeRef destination)
{
    ScriptNode transformedNode = null;
    
    // get the content reader
    ContentService contentService = this.services.getContentService();
    ContentReader reader = contentService.getReader(this.nodeRef, ContentModel.PROP_CONTENT);
    
    // only perform the transformation if some content is available
    if (reader != null)
    {
        // Copy the content node to a new node
        String copyName = TransformActionExecuter.transformName(this.services.getMimetypeService(), getName(),
                mimetype, true);
        NodeRef copyNodeRef = this.services.getCopyService().copy(this.nodeRef, destination,
                ContentModel.ASSOC_CONTAINS,
                QName.createQName(ContentModel.PROP_CONTENT.getNamespaceURI(), QName.createValidLocalName(copyName)),
                false);
        
        // modify the name of the copy to reflect the new mimetype
        this.nodeService.setProperty(copyNodeRef, ContentModel.PROP_NAME, copyName);
        
        // get the writer and set it up
        ContentWriter writer = contentService.getWriter(copyNodeRef, ContentModel.PROP_CONTENT, true);
        writer.setMimetype(mimetype); // new mimetype
        writer.setEncoding(reader.getEncoding()); // original encoding
        
        // Try and transform the content using the supplied delegate
        transformedNode = transformer.transform(contentService, copyNodeRef, reader, writer);
    }
    
    return transformedNode;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:43,代码来源:ScriptNode.java

示例15: createComment

import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
@Override
public NodeRef createComment(final NodeRef discussableNode, String title, String comment, boolean suppressRollups)
{
	if(comment == null)
	{
		throw new IllegalArgumentException("Must provide a non-null comment");
	}

    // There is no CommentService, so we have to create the node structure by hand.
    // This is what happens within e.g. comment.put.json.js when comments are submitted via the REST API.
    if (!nodeService.hasAspect(discussableNode, ForumModel.ASPECT_DISCUSSABLE))
    {
        nodeService.addAspect(discussableNode, ForumModel.ASPECT_DISCUSSABLE, null);
    }
    if (!nodeService.hasAspect(discussableNode, ForumModel.ASPECT_COMMENTS_ROLLUP) && !suppressRollups)
    {
        nodeService.addAspect(discussableNode, ForumModel.ASPECT_COMMENTS_ROLLUP, null);
    }
    // Forum node is created automatically by DiscussableAspect behaviour.
    NodeRef forumNode = nodeService.getChildAssocs(discussableNode, ForumModel.ASSOC_DISCUSSION, QName.createQName(NamespaceService.FORUMS_MODEL_1_0_URI, "discussion")).get(0).getChildRef();
    
    final List<ChildAssociationRef> existingTopics = nodeService.getChildAssocs(forumNode, ContentModel.ASSOC_CONTAINS, FORUM_TO_TOPIC_ASSOC_QNAME);
    NodeRef topicNode = null;
    if (existingTopics.isEmpty())
    {
        Map<QName, Serializable> props = new HashMap<QName, Serializable>(1, 1.0f);
        props.put(ContentModel.PROP_NAME, COMMENTS_TOPIC_NAME);
        topicNode = nodeService.createNode(forumNode, ContentModel.ASSOC_CONTAINS, FORUM_TO_TOPIC_ASSOC_QNAME, ForumModel.TYPE_TOPIC, props).getChildRef();
    }
    else
    {
        topicNode = existingTopics.get(0).getChildRef();
    }

    NodeRef postNode = nodeService.createNode(topicNode, ContentModel.ASSOC_CONTAINS, ContentModel.ASSOC_CONTAINS, ForumModel.TYPE_POST).getChildRef();
    nodeService.setProperty(postNode, ContentModel.PROP_CONTENT, new ContentData(null, MimetypeMap.MIMETYPE_TEXT_PLAIN, 0L, null));
    nodeService.setProperty(postNode, ContentModel.PROP_TITLE, title);
    ContentWriter writer = contentService.getWriter(postNode, ContentModel.PROP_CONTENT, true);
    writer.setMimetype(MimetypeMap.MIMETYPE_HTML);
    writer.setEncoding("UTF-8");
    writer.putContent(comment);

	// determine the siteId and activity data of the comment NodeRef
    String siteId = getSiteId(discussableNode);
    JSONObject activityData = getActivityData(siteId, discussableNode);

    postActivity(siteId, ActivityType.COMMENT_CREATED, activityData);

    return postNode;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:51,代码来源:CommentServiceImpl.java


注:本文中的org.alfresco.service.cmr.repository.ContentWriter.setEncoding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。