Document Reader Service

Create your own DocumentReader class

Your Document Reader must extend BaseComponentPlugin and implement interface DocumentReader (like BaseDocumentReader). Your class must be a plugin so that an extension of BaseComponentPlugin is necessary.

public interface DocumentReader {

  /**
   * @return all appropriate mime types
   */
  String[] getMimeTypes();

  /**
   * @param is
   * @return document content
   * @throws Exception
   */
  String getContentAsText(InputStream is) throws Exception;

  /**
   * @param is data input stream
   * @param encoding char set for input stream
   * @return document content
   * @throws Exception
   */
  String getContentAsText(InputStream is, String encoding) throws Exception;

  /**
   * @param mimeType
   * @return metainfo properties reduced to some supported metadata set (Dublin
   *         Core or other)
   */
  Properties getProperties(InputStream is) throws Exception;

}

Where:

  • getMimeTypes() - must return an array of supported mimetypes (for ex. "text/plain");
  • getContentAsText(InputStream is) - returns a String containing the text that is read from the InputStream "is".
  • getContentAsText(InputStream is, String encoding) - returns a String containing the text that is read from the InputStream "is" according to the provided encoding.
  • getProperties(InputStream is) - returns the properties of the document or null. See Dublin Core Metadata for supported properties.

Add your DocumentReader to DocumentReaderService component

<configuration>
  <component>
    <key>org.exoplatform.services.document.DocumentReaderService</key>
    <type>org.exoplatform.services.document.impl.DocumentReaderServiceImpl</type>
    <component-plugins>

      <component-plugin>
        <name>my.own.reader</name>
        <set-method>addDocumentReader</set-method>
        <type>org.mycompany.MyDocumentReader</type>
        <description>to read some document inputstream</description>
      </component-plugin>
      
      ... other document readers
       
    </component-plugins>
  </component>
</configuration>

  • "component-plugin" used to register your org.mycompany.MyDocumentReader type in DocumentReaderService;
  • "addDocumentReader" corresponds to DocumentReaderServiceImpl.addDocumentReader(ComponentPlugin plugin);
Tags:
Created by Sergey Karpenko on 12/04/2008
Last modified by Sören Schmidt on 05/08/2009

Products

generated on Thu Sep 02 15:41:39 UTC 2010

eXo Optional Modules

eXo Core Foundations


Copyright (c) 2000-2010. All Rights Reserved - eXo platform SAS
2.4.30451