1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.documentlibrary.util;
24  
25  import com.liferay.documentlibrary.service.jms.IndexProducer;
26  import com.liferay.portal.kernel.search.Document;
27  import com.liferay.portal.kernel.search.DocumentSummary;
28  import com.liferay.portal.kernel.search.SearchException;
29  import com.liferay.portal.kernel.util.LongWrapper;
30  import com.liferay.portal.kernel.util.MethodWrapper;
31  
32  import java.io.IOException;
33  
34  import javax.portlet.PortletURL;
35  
36  import org.apache.commons.logging.Log;
37  import org.apache.commons.logging.LogFactory;
38  
39  /**
40   * <a href="Indexer.java.html"><b><i>View Source</i></b></a>
41   *
42   * @author Brian Wing Shun Chan
43   *
44   */
45  public class Indexer implements com.liferay.portal.kernel.search.Indexer {
46  
47      public static void addFile(
48              long companyId, String portletId, long groupId, long repositoryId,
49              String fileName)
50          throws IOException {
51  
52          try {
53              MethodWrapper methodWrapper = new MethodWrapper(
54                  IndexerImpl.class.getName(), "addFile",
55                  new Object[] {
56                      new LongWrapper(companyId), portletId,
57                      new LongWrapper(groupId), new LongWrapper(repositoryId),
58                      fileName
59                  });
60  
61              IndexProducer.produce(methodWrapper);
62          }
63          catch (Exception e) {
64              if (e instanceof IOException) {
65                  throw (IOException)e;
66              }
67              else {
68                  _log.error(e);
69              }
70          }
71      }
72  
73      public static void addFile(
74              long companyId, String portletId, long groupId, long repositoryId,
75              String fileName, String properties)
76          throws IOException {
77  
78          try {
79              MethodWrapper methodWrapper = new MethodWrapper(
80                  IndexerImpl.class.getName(), "addFile",
81                  new Object[] {
82                      new LongWrapper(companyId), portletId,
83                      new LongWrapper(groupId), new LongWrapper(repositoryId),
84                      fileName, properties
85                  });
86  
87              IndexProducer.produce(methodWrapper);
88          }
89          catch (Exception e) {
90              if (e instanceof IOException) {
91                  throw (IOException)e;
92              }
93              else {
94                  _log.error(e);
95              }
96          }
97      }
98  
99      public static void deleteFile(
100             long companyId, String portletId, long repositoryId,
101             String fileName)
102         throws IOException {
103 
104         try {
105             MethodWrapper methodWrapper = new MethodWrapper(
106                 IndexerImpl.class.getName(), "deleteFile",
107                 new Object[] {
108                     new LongWrapper(companyId), portletId,
109                     new LongWrapper(repositoryId), fileName
110                 });
111 
112             IndexProducer.produce(methodWrapper);
113         }
114         catch (Exception e) {
115             if (e instanceof IOException) {
116                 throw (IOException)e;
117             }
118             else {
119                 _log.error(e);
120             }
121         }
122     }
123 
124     public static void updateFile(
125             long companyId, String portletId, long groupId, long repositoryId,
126             String fileName, String properties)
127         throws IOException {
128 
129         try {
130             MethodWrapper methodWrapper = new MethodWrapper(
131                 IndexerImpl.class.getName(), "updateFile",
132                 new Object[] {
133                     new LongWrapper(companyId), portletId,
134                     new LongWrapper(groupId), new LongWrapper(repositoryId),
135                     fileName, properties
136                 });
137 
138             IndexProducer.produce(methodWrapper);
139         }
140         catch (Exception e) {
141             if (e instanceof IOException) {
142                 throw (IOException)e;
143             }
144             else {
145                 _log.error(e);
146             }
147         }
148     }
149 
150     public DocumentSummary getDocumentSummary(
151         Document doc, PortletURL portletURL) {
152 
153         return null;
154     }
155 
156     public void reIndex(String[] ids) throws SearchException {
157         IndexerImpl.reIndex(ids);
158     }
159 
160     private static Log _log = LogFactory.getLog(Indexer.class);
161 
162 }