1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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.portlet.wiki.model.impl;
24  
25  import com.liferay.documentlibrary.NoSuchDirectoryException;
26  import com.liferay.documentlibrary.service.DLServiceUtil;
27  import com.liferay.portal.PortalException;
28  import com.liferay.portal.SystemException;
29  import com.liferay.portal.kernel.log.Log;
30  import com.liferay.portal.kernel.log.LogFactoryUtil;
31  import com.liferay.portal.kernel.util.PropsKeys;
32  import com.liferay.portal.kernel.util.Validator;
33  import com.liferay.portal.model.CompanyConstants;
34  import com.liferay.portal.util.PropsUtil;
35  import com.liferay.portlet.wiki.model.WikiNode;
36  import com.liferay.portlet.wiki.model.WikiPage;
37  import com.liferay.portlet.wiki.service.WikiNodeLocalServiceUtil;
38  import com.liferay.portlet.wiki.service.WikiPageLocalServiceUtil;
39  
40  import java.util.ArrayList;
41  import java.util.List;
42  
43  /**
44   * <a href="WikiPageImpl.java.html"><b><i>View Source</i></b></a>
45   *
46   * @author Brian Wing Shun Chan
47   * @author Jorge Ferrer
48   */
49  public class WikiPageImpl extends WikiPageModelImpl implements WikiPage {
50  
51      public static final String DEFAULT_FORMAT =
52          PropsUtil.get(PropsKeys.WIKI_FORMATS_DEFAULT);
53  
54      public static final double DEFAULT_VERSION = 1.0;
55  
56      public static final String[] FORMATS =
57          PropsUtil.getArray(PropsKeys.WIKI_FORMATS);
58  
59      public static final String FRONT_PAGE =
60          PropsUtil.get(PropsKeys.WIKI_FRONT_PAGE_NAME);
61  
62      public static final String MOVED = "Moved";
63  
64      public static final String NEW = "New";
65  
66      public static final String REVERTED = "Reverted";
67  
68      public WikiPageImpl() {
69      }
70  
71      public String getAttachmentsDir() {
72          if (_attachmentDirs == null) {
73              _attachmentDirs = "wiki/" + getResourcePrimKey();
74          }
75  
76          return _attachmentDirs;
77      }
78  
79      public String[] getAttachmentsFiles()
80          throws PortalException, SystemException {
81  
82          String[] fileNames = new String[0];
83  
84          try {
85              fileNames = DLServiceUtil.getFileNames(
86                  getCompanyId(), CompanyConstants.SYSTEM, getAttachmentsDir());
87          }
88          catch (NoSuchDirectoryException nsde) {
89          }
90  
91          return fileNames;
92      }
93  
94      public List<WikiPage> getChildPages() {
95          List<WikiPage> pages = null;
96  
97          try {
98              pages = WikiPageLocalServiceUtil.getChildren(
99                  getNodeId(), true, getTitle());
100         }
101         catch (Exception e) {
102             pages = new ArrayList<WikiPage>();
103 
104             _log.error(e);
105         }
106 
107         return pages;
108     }
109 
110     public WikiNode getNode() {
111         WikiNode node = null;
112 
113         try {
114             node = WikiNodeLocalServiceUtil.getNode(getNodeId());
115         }
116         catch (Exception e) {
117             node = new WikiNodeImpl();
118 
119             _log.error(e);
120         }
121 
122         return node;
123     }
124 
125     public WikiPage getParentPage() {
126         if (Validator.isNull(getParentTitle())) {
127             return null;
128         }
129 
130         WikiPage page = null;
131 
132         try {
133             page = WikiPageLocalServiceUtil.getPage(
134                 getNodeId(), getParentTitle());
135         }
136         catch (Exception e) {
137             _log.error(e);
138         }
139 
140         return page;
141     }
142 
143     public List<WikiPage> getParentPages() {
144         List<WikiPage> parentPages = new ArrayList<WikiPage>();
145 
146         WikiPage parentPage = getParentPage();
147 
148         if (parentPage != null) {
149             parentPages.addAll(parentPage.getParentPages());
150             parentPages.add(parentPage);
151         }
152 
153         return parentPages;
154     }
155 
156     public WikiPage getRedirectPage() {
157         if (Validator.isNull(getRedirectTitle())) {
158             return null;
159         }
160 
161         WikiPage page = null;
162 
163         try {
164             page = WikiPageLocalServiceUtil.getPage(
165                 getNodeId(), getRedirectTitle());
166         }
167         catch (Exception e) {
168             _log.error(e);
169         }
170 
171         return page;
172     }
173 
174     public void setAttachmentsDir(String attachmentsDir) {
175         _attachmentDirs = attachmentsDir;
176     }
177 
178     private static Log _log = LogFactoryUtil.getLog(WikiPageImpl.class);
179 
180     private String _attachmentDirs;
181 
182 }