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.wiki.model.impl;
16  
17  import com.liferay.documentlibrary.NoSuchDirectoryException;
18  import com.liferay.documentlibrary.service.DLServiceUtil;
19  import com.liferay.portal.PortalException;
20  import com.liferay.portal.SystemException;
21  import com.liferay.portal.kernel.log.Log;
22  import com.liferay.portal.kernel.log.LogFactoryUtil;
23  import com.liferay.portal.kernel.util.PropsKeys;
24  import com.liferay.portal.kernel.util.Validator;
25  import com.liferay.portal.model.CompanyConstants;
26  import com.liferay.portal.util.PropsUtil;
27  import com.liferay.portlet.wiki.model.WikiNode;
28  import com.liferay.portlet.wiki.model.WikiPage;
29  import com.liferay.portlet.wiki.service.WikiNodeLocalServiceUtil;
30  import com.liferay.portlet.wiki.service.WikiPageLocalServiceUtil;
31  
32  import java.util.ArrayList;
33  import java.util.List;
34  
35  /**
36   * <a href="WikiPageImpl.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Brian Wing Shun Chan
39   * @author Jorge Ferrer
40   */
41  public class WikiPageImpl extends WikiPageModelImpl implements WikiPage {
42  
43      public static final String DEFAULT_FORMAT =
44          PropsUtil.get(PropsKeys.WIKI_FORMATS_DEFAULT);
45  
46      public static final double DEFAULT_VERSION = 1.0;
47  
48      public static final String[] FORMATS =
49          PropsUtil.getArray(PropsKeys.WIKI_FORMATS);
50  
51      public static final String FRONT_PAGE =
52          PropsUtil.get(PropsKeys.WIKI_FRONT_PAGE_NAME);
53  
54      public static final String MOVED = "Moved";
55  
56      public static final String NEW = "New";
57  
58      public static final String REVERTED = "Reverted";
59  
60      public WikiPageImpl() {
61      }
62  
63      public String getAttachmentsDir() {
64          if (_attachmentDirs == null) {
65              _attachmentDirs = "wiki/" + getResourcePrimKey();
66          }
67  
68          return _attachmentDirs;
69      }
70  
71      public String[] getAttachmentsFiles()
72          throws PortalException, SystemException {
73  
74          String[] fileNames = new String[0];
75  
76          try {
77              fileNames = DLServiceUtil.getFileNames(
78                  getCompanyId(), CompanyConstants.SYSTEM, getAttachmentsDir());
79          }
80          catch (NoSuchDirectoryException nsde) {
81          }
82  
83          return fileNames;
84      }
85  
86      public List<WikiPage> getChildPages() {
87          List<WikiPage> pages = null;
88  
89          try {
90              pages = WikiPageLocalServiceUtil.getChildren(
91                  getNodeId(), true, getTitle());
92          }
93          catch (Exception e) {
94              pages = new ArrayList<WikiPage>();
95  
96              _log.error(e);
97          }
98  
99          return pages;
100     }
101 
102     public WikiNode getNode() {
103         WikiNode node = null;
104 
105         try {
106             node = WikiNodeLocalServiceUtil.getNode(getNodeId());
107         }
108         catch (Exception e) {
109             node = new WikiNodeImpl();
110 
111             _log.error(e);
112         }
113 
114         return node;
115     }
116 
117     public WikiPage getParentPage() {
118         if (Validator.isNull(getParentTitle())) {
119             return null;
120         }
121 
122         WikiPage page = null;
123 
124         try {
125             page = WikiPageLocalServiceUtil.getPage(
126                 getNodeId(), getParentTitle());
127         }
128         catch (Exception e) {
129             _log.error(e);
130         }
131 
132         return page;
133     }
134 
135     public List<WikiPage> getParentPages() {
136         List<WikiPage> parentPages = new ArrayList<WikiPage>();
137 
138         WikiPage parentPage = getParentPage();
139 
140         if (parentPage != null) {
141             parentPages.addAll(parentPage.getParentPages());
142             parentPages.add(parentPage);
143         }
144 
145         return parentPages;
146     }
147 
148     public WikiPage getRedirectPage() {
149         if (Validator.isNull(getRedirectTitle())) {
150             return null;
151         }
152 
153         WikiPage page = null;
154 
155         try {
156             page = WikiPageLocalServiceUtil.getPage(
157                 getNodeId(), getRedirectTitle());
158         }
159         catch (Exception e) {
160             _log.error(e);
161         }
162 
163         return page;
164     }
165 
166     public void setAttachmentsDir(String attachmentsDir) {
167         _attachmentDirs = attachmentsDir;
168     }
169 
170     private static Log _log = LogFactoryUtil.getLog(WikiPageImpl.class);
171 
172     private String _attachmentDirs;
173 
174 }