### Eclipse Workspace Patch 1.0 #P wiki_dev Index: src-wiki/src/com/ecyrd/jspwiki/search/LuceneSearchProvider.java =================================================================== --- src-wiki/src/com/ecyrd/jspwiki/search/LuceneSearchProvider.java (revision 734659) +++ src-wiki/src/com/ecyrd/jspwiki/search/LuceneSearchProvider.java (working copy) @@ -46,6 +46,9 @@ import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; +import pl.com.pbpolsoft.wiki.util.attachment.ReadableAttachmentProvider; +import pl.com.pbpolsoft.wiki.util.attachment.ReadableAttachmentProviderFactory; + import com.ecyrd.jspwiki.*; import com.ecyrd.jspwiki.attachment.Attachment; import com.ecyrd.jspwiki.attachment.AttachmentManager; @@ -329,35 +332,57 @@ String filename = att.getFileName(); + if(filename.endsWith(".txt") || - filename.endsWith(".xml") || - filename.endsWith(".ini") || - filename.endsWith(".html")) - { - InputStream attStream; + filename.endsWith(".xml") || + filename.endsWith(".ini") || + filename.endsWith(".doc") || + filename.endsWith(".xls") || + filename.endsWith(".ppt") || + filename.endsWith(".pdf") || + filename.endsWith(".html")) + { + + + InputStream attStream; + + try + { + ReadableAttachmentProvider attProvider = ReadableAttachmentProviderFactory.getProvider(filename); + attStream = mgr.getAttachmentStream( att ); + + log.debug("Getting content of " + filename); - try - { - attStream = mgr.getAttachmentStream( att ); + if(attProvider != null) { + log.debug("Attachment provider: " + attProvider); + + attProvider.setContents(attStream); + + String readableAttachment = attProvider.getReadableContents(); + + attStream.close(); + return readableAttachment; + + } + + StringWriter sout = new StringWriter(); + FileUtil.copyContents( new InputStreamReader(attStream), sout ); - StringWriter sout = new StringWriter(); - FileUtil.copyContents( new InputStreamReader(attStream), sout ); + attStream.close(); + sout.close(); - attStream.close(); - sout.close(); - - return sout.toString(); - } - catch (ProviderException e) - { - log.error("Attachment cannot be loaded", e); - return null; - } - catch (IOException e) - { - log.error("Attachment cannot be loaded", e); - return null; - } + return sout.toString(); + } + catch (ProviderException e) + { + log.error("Attachment cannot be loaded", e); + return null; + } + catch (IOException e) + { + log.error("Attachment cannot be loaded", e); + return null; + } } return null;