PageRenderTime 74ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/components/registry/org.wso2.carbon.registry.indexing/src/main/java/org/wso2/carbon/registry/indexing/indexer/MSPowerpointIndexer.java

https://github.com/GayanM/carbon-registry
Java | 35 lines | 27 code | 8 blank | 0 comment | 0 complexity | c677a1755ab2065291c064ac6ee9c092 MD5 | raw file
  1. package org.wso2.carbon.registry.indexing.indexer;
  2. import java.io.ByteArrayInputStream;
  3. import java.io.IOException;
  4. import org.apache.commons.logging.Log;
  5. import org.apache.commons.logging.LogFactory;
  6. import org.apache.poi.hslf.extractor.PowerPointExtractor;
  7. import org.apache.poi.poifs.filesystem.POIFSFileSystem;
  8. import org.apache.solr.common.SolrException;
  9. import org.apache.solr.common.SolrException.ErrorCode;
  10. import org.wso2.carbon.registry.indexing.AsyncIndexer.File2Index;
  11. import org.wso2.carbon.registry.indexing.solr.IndexDocument;
  12. public class MSPowerpointIndexer implements Indexer {
  13. public static final Log log = LogFactory.getLog(MSPowerpointIndexer.class);
  14. public IndexDocument getIndexedDocument(File2Index fileData)
  15. throws SolrException {
  16. try {
  17. POIFSFileSystem fs = new POIFSFileSystem(new ByteArrayInputStream(fileData.data));
  18. PowerPointExtractor extractor = new PowerPointExtractor(fs);
  19. String ppText = extractor.getText();
  20. return new IndexDocument(fileData.path, ppText, null);
  21. } catch (IOException e) {
  22. String msg = "Failed to write to the index";
  23. log.error(msg, e);
  24. throw new SolrException(ErrorCode.SERVER_ERROR, msg);
  25. }
  26. }
  27. }