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.portal.kernel.util.Validator;
25  import com.liferay.portlet.documentlibrary.model.DLFileEntry;
26  import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil;
27  import com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil;
28  
29  import javax.portlet.PortletRequest;
30  import javax.portlet.PortletURL;
31  import javax.portlet.WindowStateException;
32  
33  /**
34   * <a href="Indexer.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Brian Wing Shun Chan
37   * @author Raymond Augé
38   */
39  public class Indexer implements com.liferay.portal.kernel.search.Indexer {
40  
41      public String[] getClassNames() {
42          return _CLASS_NAMES;
43      }
44  
45      public DocumentSummary getDocumentSummary(
46          Document doc, String snippet, PortletURL portletURL) {
47  
48          LiferayPortletURL liferayPortletURL = (LiferayPortletURL)portletURL;
49  
50          liferayPortletURL.setLifecycle(PortletRequest.ACTION_PHASE);
51  
52          try {
53              liferayPortletURL.setWindowState(LiferayWindowState.EXCLUSIVE);
54          }
55          catch (WindowStateException wse) {
56          }
57  
58          // Title
59  
60          String repositoryId = doc.get("repositoryId");
61          String fileName = doc.get("path");
62  
63          String title = fileName;
64  
65          // Content
66  
67          String content = snippet;
68  
69          if (Validator.isNull(snippet)) {
70              content = StringUtil.shorten(doc.get(Field.CONTENT), 200);
71          }
72  
73          // Portlet URL
74  
75          portletURL.setParameter("struts_action", "/document_library/get_file");
76          portletURL.setParameter("folderId", repositoryId);
77          portletURL.setParameter("name", fileName);
78  
79          return new DocumentSummary(title, content, portletURL);
80      }
81  
82      public void reIndex(String className, long classPK) throws SearchException {
83          try {
84              DLFileEntryLocalServiceUtil.reIndex(classPK);
85          }
86          catch (Exception e) {
87              throw new SearchException(e);
88          }
89      }
90  
91      public void reIndex(String[] ids) throws SearchException {
92          try {
93              DLFolderLocalServiceUtil.reIndex(ids);
94          }
95          catch (Exception e) {
96              throw new SearchException(e);
97          }
98      }
99  
100     private static final String[] _CLASS_NAMES = new String[] {
101         DLFileEntry.class.getName()
102     };
103 
104 }