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


Java ContentReader.getEncoding方法代码示例

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


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

示例1: saveContentInUtf8File

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
 * Populates a file with the content in the reader, but also converts the encoding to UTF-8.
 */
private void saveContentInUtf8File(ContentReader reader, File file)
{
    String encoding = reader.getEncoding();
    try
    {
        Reader in = new InputStreamReader(reader.getContentInputStream(), encoding);
        Writer out = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(file)), "UTF-8");

        FileCopyUtils.copy(in, out);  // both streams are closed
    }
    catch (IOException e)
    {
        throw new ContentIOException("Failed to copy content to file and convert "+encoding+" to UTF-8: \n" +
                "   file: " + file,
                e);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:21,代码来源:OOoContentTransformerHelper.java

示例2: transformInternal

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
public void transformInternal(ContentReader reader, ContentWriter writer,  TransformationOptions options)
        throws Exception
{
    // We can only work from a file
    File htmlFile = TempFileProvider.createTempFile("HtmlParserContentTransformer_", ".html");
    reader.getContent(htmlFile);
    
    // Fetch the encoding of the HTML, as set in the ContentReader
    // This will default to 'UTF-8' if not specifically set
    String encoding = reader.getEncoding();
    
    // Create the extractor
    EncodingAwareStringBean extractor = new EncodingAwareStringBean();
    extractor.setCollapse(false);
    extractor.setLinks(false);
    extractor.setReplaceNonBreakingSpaces(false);
    extractor.setURL(htmlFile, encoding);        
    // get the text
    String text = extractor.getStrings();
    // write it to the writer
    writer.putContent(text);
    
    // Tidy up
    htmlFile.delete();
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:26,代码来源:HtmlParserContentTransformer.java

示例3: saveContentInFile

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
 * Populates a file with the content in the reader.
 */
public void saveContentInFile(String sourceMimetype, ContentReader reader, File file) throws ContentIOException
{
    String encoding = reader.getEncoding();
    if (encodeAsUtf8(sourceMimetype, encoding))
    {
        saveContentInUtf8File(reader, file);
    }
    else
    {
        reader.getContent(file);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:16,代码来源:OOoContentTransformerHelper.java

示例4: getRepoResourceBundle

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
public ResourceBundle getRepoResourceBundle(
        final StoreRef storeRef,
        final String path,
        final Locale locale) throws IOException
{   
    // TODO - need to replace basic strategy with a more complete
    // search & instantiation strategy similar to ResourceBundle.getBundle()
    // Consider search query with basename* and then apply strategy ...
    
    // Avoid permission exceptions
    RunAsWork<ResourceBundle> getBundleWork = new RunAsWork<ResourceBundle>()
    {
        @Override
        public ResourceBundle doWork() throws Exception
        {
            NodeRef rootNode = nodeService.getRootNode(storeRef);

            // first attempt - with locale        
            NodeRef nodeRef = getNode(rootNode, path+"_"+locale+PROPERTIES_FILE_SUFFIX);
            
            if (nodeRef == null)
            {
                // second attempt - basename 
                nodeRef = getNode(rootNode, path+PROPERTIES_FILE_SUFFIX);
            }
            
            if (nodeRef == null)
            {
                logger.debug("Could not find message resource bundle " + storeRef + "/" + path);
                return null;
            }
            
            ContentReader cr = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
            ResourceBundle resBundle = new MessagePropertyResourceBundle(
                    new InputStreamReader(cr.getContentInputStream(), cr.getEncoding()));
            return resBundle;
        }
    };
    return AuthenticationUtil.runAs(getBundleWork, AuthenticationUtil.getSystemUserName());
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:41,代码来源:MessageServiceImpl.java

示例5: getReader

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
public Reader getReader()
{
    ContentReader reader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
    try
    {
        return new InputStreamReader(getInputStream(), reader.getEncoding());
    }
    catch (UnsupportedEncodingException e)
    {
        throw new AlfrescoRuntimeException("Unsupported Encoding", e);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:13,代码来源:RepoStore.java

示例6: BinaryProperty

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
 * This is the preferred constructor to use. Takes the properties from content reader that it needs.
 * @param reader ContentReader
 */
public BinaryProperty(ContentReader reader)
{
    super();
    this.mimeType = reader.getMimetype();
    this.encoding = reader.getEncoding();
    this.length = reader.getSize();
    this.locale = reader.getLocale();
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:13,代码来源:BinaryProperty.java


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