1   /**
2    * Copyright (c) 2000-2010 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   *
12   * 
13   */
14  
15  package com.liferay.portlet.documentlibrary.util;
16  
17  import com.liferay.portal.kernel.portlet.LiferayPortletURL;
18  import com.liferay.portal.kernel.portlet.LiferayWindowState;
19  import com.liferay.portal.kernel.search.Document;
20  import com.liferay.portal.kernel.search.DocumentSummary;
21  import com.liferay.portal.kernel.search.Field;
22  import com.liferay.portal.kernel.search.SearchException;
23  import com.liferay.portal.kernel.util.StringUtil;
24  import com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil;
25  
26  import javax.portlet.PortletRequest;
27  import javax.portlet.PortletURL;
28  import javax.portlet.WindowStateException;
29  
30  /**
31   * <a href="Indexer.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Brian Wing Shun Chan
34   */
35  public class Indexer implements com.liferay.portal.kernel.search.Indexer {
36  
37      public DocumentSummary getDocumentSummary(
38          Document doc, PortletURL portletURL) {
39  
40          LiferayPortletURL liferayPortletURL = (LiferayPortletURL)portletURL;
41  
42          liferayPortletURL.setLifecycle(PortletRequest.ACTION_PHASE);
43  
44          try {
45              liferayPortletURL.setWindowState(LiferayWindowState.EXCLUSIVE);
46          }
47          catch (WindowStateException wse) {
48          }
49  
50          // Title
51  
52          String repositoryId = doc.get("repositoryId");
53          String fileName = doc.get("path");
54  
55          String title = fileName;
56  
57          // Content
58  
59          String content = doc.get(Field.CONTENT);
60  
61          content = StringUtil.shorten(content, 200);
62  
63          // Portlet URL
64  
65          portletURL.setParameter("struts_action", "/document_library/get_file");
66          portletURL.setParameter("folderId", repositoryId);
67          portletURL.setParameter("name", fileName);
68  
69          return new DocumentSummary(title, content, portletURL);
70      }
71  
72      public void reIndex(String[] ids) throws SearchException {
73          try {
74              DLFolderLocalServiceUtil.reIndex(ids);
75          }
76          catch (Exception e) {
77              throw new SearchException(e);
78          }
79      }
80  
81  }