1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.documentlibrary.util;
21  
22  import com.liferay.portal.kernel.portlet.LiferayPortletURL;
23  import com.liferay.portal.kernel.portlet.LiferayWindowState;
24  import com.liferay.portal.kernel.search.Document;
25  import com.liferay.portal.kernel.search.DocumentSummary;
26  import com.liferay.portal.kernel.search.Field;
27  import com.liferay.portal.kernel.search.SearchException;
28  import com.liferay.portal.kernel.util.StringUtil;
29  import com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil;
30  
31  import javax.portlet.PortletRequest;
32  import javax.portlet.PortletURL;
33  import javax.portlet.WindowStateException;
34  
35  /**
36   * <a href="Indexer.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Brian Wing Shun Chan
39   *
40   */
41  public class Indexer implements com.liferay.portal.kernel.search.Indexer {
42  
43      public DocumentSummary getDocumentSummary(
44          Document doc, PortletURL portletURL) {
45  
46          LiferayPortletURL liferayPortletURL = (LiferayPortletURL)portletURL;
47  
48          liferayPortletURL.setLifecycle(PortletRequest.ACTION_PHASE);
49  
50          try {
51              liferayPortletURL.setWindowState(LiferayWindowState.EXCLUSIVE);
52          }
53          catch (WindowStateException wse) {
54          }
55  
56          // Title
57  
58          String repositoryId = doc.get("repositoryId");
59          String fileName = doc.get("path");
60  
61          String title = fileName;
62  
63          // Content
64  
65          String content = doc.get(Field.CONTENT);
66  
67          content = StringUtil.shorten(content, 200);
68  
69          // Portlet URL
70  
71          portletURL.setParameter("struts_action", "/document_library/get_file");
72          portletURL.setParameter("folderId", repositoryId);
73          portletURL.setParameter("name", fileName);
74  
75          return new DocumentSummary(title, content, portletURL);
76      }
77  
78      public void reIndex(String[] ids) throws SearchException {
79          try {
80              DLFolderLocalServiceUtil.reIndex(ids);
81          }
82          catch (Exception e) {
83              throw new SearchException(e);
84          }
85      }
86  
87  }