1 5 package org.exoplatform.services.communication.message.impl; 6 7 import org.apache.lucene.document.*; 8 import org.apache.lucene.index.Term; 9 import org.exoplatform.services.communication.message.*; 10 import org.exoplatform.services.indexing.BaseIndexerPlugin; 11 import org.exoplatform.services.indexing.IndexingService; 12 17 public class MessageIndexerPluginImpl 18 extends BaseIndexerPlugin implements MessageIndexerPlugin { 19 20 private MessageService mservice_ ; 21 22 public MessageIndexerPluginImpl(IndexingService iservice, 23 MessageServiceImpl mservice) { 24 super(iservice) ; 25 mservice_ = mservice ; 26 mservice.setIndexer(this) ; 27 } 28 29 public Document createDocument(Account account, MessageImpl message) throws Exception { 30 String identifier = message.getId() ; 31 String title = message.getSubject() ; 32 if(title == null ) title = "-----------No Subject----------" ; 33 String textToIndex = message.getBody(); 34 if(textToIndex == null) textToIndex = "" ; 35 String desc = getContentDescription(textToIndex, 200); 36 Document doc = createBaseDocument(identifier, message.getFrom(), title, desc , 37 textToIndex, account.getAccessRole()) ; 38 doc.add(Field.Text(FOLDER_ID_FIELD, message.getFolderId())) ; 39 doc.add(Field.Text(ACCOUNT_ID_FIELD, account.getId())) ; 40 doc.add(Field.Text(TO_FIELD, message.getTo())) ; 41 doc.add(Field.Text(FROM_FIELD, message.getFrom())) ; 42 doc.add(Field.Text(FLAG_FIELD, message.getFlags())) ; 43 doc.add(Field.Text(RECEIVED_DATE_FIELD, DateField.dateToString(message.getReceivedDate()))) ; 44 return doc ; 45 } 46 47 public String getPluginIdentifier() { return IDENTIFIER ; } 48 49 public Object getObject(String user,String objectId) throws Exception { 50 return mservice_.getMessage(objectId) ; 51 } 52 53 public String getObjectAsText(String user,String objectId) throws Exception { 54 Message message = mservice_.getMessage(objectId) ; 55 if(message == null) return UNSYNCHRONIZED_DATABASE ; 56 return message.getBody() ; 57 } 58 59 public String getObjectAsXHTML(String user,String objectId) throws Exception { 60 Message message = mservice_.getMessage(objectId) ; 61 if(message == null) return UNSYNCHRONIZED_DATABASE ; 62 return message.getBody() ; 63 } 64 65 public String getObjectAsXML(String user, String objectId) throws Exception { 66 Message message = mservice_.getMessage(objectId) ; 67 if(message == null) return UNSYNCHRONIZED_DATABASE ; 68 return message.getBody() ; 69 } 70 71 void removeAccount(Account account) throws Exception { 72 Term term = new Term(ACCOUNT_ID_FIELD, account.getId()) ; 73 iservice_.queueDeleteDocuments(term) ; 74 } 75 76 void removeFolder(Folder folder) throws Exception { 77 Term term = new Term(FOLDER_ID_FIELD, folder.getId()) ; 78 iservice_.queueDeleteDocuments(term) ; 79 } 80 81 void removeMessage(Message message) throws Exception { 82 Term term = new Term(IndexingService.IDENTIFIER_FIELD, message.getId()) ; 83 iservice_.queueDeleteDocuments(term) ; 84 } 85 86 void moveMesasge(Account account, String oldFolderId, MessageImpl message) throws Exception { 87 Term term = new Term(FOLDER_ID_FIELD, oldFolderId) ; 88 iservice_.queueDeleteDocuments(term) ; 89 iservice_.queueIndexDocument(createDocument(account, message)) ; 90 } 91 92 void createMesasge(Account account, MessageImpl message) throws Exception { 93 iservice_.queueIndexDocument(createDocument(account, message)) ; 94 } 95 } | Popular Tags |