PageRenderTime 68ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/GayanM/carbon-registry
Java | 35 lines | 27 code | 8 blank | 0 comment | 0 complexity | 5138cd4ff61a5f2b6a5d0d29d8522108 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.hssf.extractor.ExcelExtractor;
  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 MSExcelIndexer implements Indexer {
  13. public static final Log log = LogFactory.getLog(MSExcelIndexer.class);
  14. public IndexDocument getIndexedDocument(File2Index fileData)
  15. throws SolrException {
  16. try {
  17. POIFSFileSystem fs = new POIFSFileSystem(new ByteArrayInputStream(fileData.data));
  18. ExcelExtractor extractor = new ExcelExtractor(fs);
  19. String excelText = extractor.getText();
  20. return new IndexDocument(fileData.path, excelText, 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. }