KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > communication > message > impl > MessageIndexerPluginImpl


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

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 /**
13  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
14  * @since Sep 13, 2004
15  * @version $Id: MessageIndexerPluginImpl.java,v 1.5 2004/11/01 15:07:50 tuan08 Exp $
16  */

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 JavaDoc {
30     String JavaDoc identifier = message.getId() ;
31     String JavaDoc title = message.getSubject() ;
32     if(title == null ) title = "-----------No Subject----------" ;
33     String JavaDoc textToIndex = message.getBody();
34     if(textToIndex == null) textToIndex = "" ;
35     String JavaDoc 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 JavaDoc getPluginIdentifier() { return IDENTIFIER ; }
48   
49   public Object JavaDoc getObject(String JavaDoc user,String JavaDoc objectId) throws Exception JavaDoc {
50     return mservice_.getMessage(objectId) ;
51   }
52   
53   public String JavaDoc getObjectAsText(String JavaDoc user,String JavaDoc objectId) throws Exception JavaDoc {
54     Message message = mservice_.getMessage(objectId) ;
55     if(message == null) return UNSYNCHRONIZED_DATABASE ;
56     return message.getBody() ;
57   }
58   
59   public String JavaDoc getObjectAsXHTML(String JavaDoc user,String JavaDoc objectId) throws Exception JavaDoc {
60     Message message = mservice_.getMessage(objectId) ;
61     if(message == null) return UNSYNCHRONIZED_DATABASE ;
62     return message.getBody() ;
63   }
64   
65   public String JavaDoc getObjectAsXML(String JavaDoc user, String JavaDoc objectId) throws Exception JavaDoc {
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 JavaDoc {
72     Term term = new Term(ACCOUNT_ID_FIELD, account.getId()) ;
73     iservice_.queueDeleteDocuments(term) ;
74   }
75   
76   void removeFolder(Folder folder) throws Exception JavaDoc {
77     Term term = new Term(FOLDER_ID_FIELD, folder.getId()) ;
78     iservice_.queueDeleteDocuments(term) ;
79   }
80   
81   void removeMessage(Message message) throws Exception JavaDoc {
82     Term term = new Term(IndexingService.IDENTIFIER_FIELD, message.getId()) ;
83     iservice_.queueDeleteDocuments(term) ;
84   }
85   
86   void moveMesasge(Account account, String JavaDoc oldFolderId, MessageImpl message) throws Exception JavaDoc {
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 JavaDoc {
93     iservice_.queueIndexDocument(createDocument(account, message)) ;
94   }
95 }
Popular Tags