001
014
015 package com.liferay.portlet.wiki.model.impl;
016
017 import com.liferay.portal.kernel.dao.orm.QueryUtil;
018 import com.liferay.portal.kernel.exception.PortalException;
019 import com.liferay.portal.kernel.exception.SystemException;
020 import com.liferay.portal.kernel.log.Log;
021 import com.liferay.portal.kernel.log.LogFactoryUtil;
022 import com.liferay.portal.kernel.repository.model.FileEntry;
023 import com.liferay.portal.kernel.util.Validator;
024 import com.liferay.portal.kernel.workflow.WorkflowConstants;
025 import com.liferay.portal.portletfilerepository.PortletFileRepositoryUtil;
026 import com.liferay.portlet.wiki.model.WikiNode;
027 import com.liferay.portlet.wiki.model.WikiPage;
028 import com.liferay.portlet.wiki.service.WikiNodeLocalServiceUtil;
029 import com.liferay.portlet.wiki.service.WikiPageLocalServiceUtil;
030 import com.liferay.portlet.wiki.service.WikiPageServiceUtil;
031 import com.liferay.portlet.wiki.util.WikiPageAttachmentsUtil;
032
033 import java.util.ArrayList;
034 import java.util.Collections;
035 import java.util.List;
036
037
041 public class WikiPageImpl extends WikiPageBaseImpl {
042
043 public WikiPageImpl() {
044 }
045
046 public List<FileEntry> getAttachmentsFileEntries()
047 throws PortalException, SystemException {
048
049 return getAttachmentsFileEntries(QueryUtil.ALL_POS, QueryUtil.ALL_POS);
050 }
051
052 public List<FileEntry> getAttachmentsFileEntries(int start, int end)
053 throws PortalException, SystemException {
054
055 return PortletFileRepositoryUtil.getPortletFileEntries(
056 getGroupId(), getAttachmentsFolderId(),
057 WorkflowConstants.STATUS_APPROVED, start, end, null);
058 }
059
060 public int getAttachmentsFileEntriesCount()
061 throws PortalException, SystemException {
062
063 return PortletFileRepositoryUtil.getPortletFileEntriesCount(
064 getGroupId(), getAttachmentsFolderId(),
065 WorkflowConstants.STATUS_APPROVED);
066 }
067
068 public long getAttachmentsFolderId()
069 throws PortalException, SystemException {
070
071 if (_attachmentsFolderId > 0) {
072 return _attachmentsFolderId;
073 }
074
075 _attachmentsFolderId = WikiPageAttachmentsUtil.getFolderId(
076 getGroupId(), getUserId(), getNodeId(), getResourcePrimKey());
077
078 return _attachmentsFolderId;
079 }
080
081 public List<WikiPage> getChildPages() {
082 try {
083 return WikiPageLocalServiceUtil.getChildren(
084 getNodeId(), true, getTitle());
085 }
086 catch (Exception e) {
087 _log.error(e, e);
088
089 return Collections.emptyList();
090 }
091 }
092
093 public List<FileEntry> getDeletedAttachmentsFileEntries()
094 throws PortalException, SystemException {
095
096 return getDeletedAttachmentsFileEntries(
097 QueryUtil.ALL_POS, QueryUtil.ALL_POS);
098 }
099
100 public List<FileEntry> getDeletedAttachmentsFileEntries(int start, int end)
101 throws PortalException, SystemException {
102
103 return PortletFileRepositoryUtil.getPortletFileEntries(
104 getGroupId(), getAttachmentsFolderId(),
105 WorkflowConstants.STATUS_IN_TRASH, start, end, null);
106 }
107
108 public int getDeletedAttachmentsFileEntriesCount()
109 throws PortalException, SystemException {
110
111 return PortletFileRepositoryUtil.getPortletFileEntriesCount(
112 getGroupId(), getAttachmentsFolderId(),
113 WorkflowConstants.STATUS_IN_TRASH);
114 }
115
116 public WikiNode getNode() {
117 try {
118 return WikiNodeLocalServiceUtil.getNode(getNodeId());
119 }
120 catch (Exception e) {
121 _log.error(e, e);
122
123 return new WikiNodeImpl();
124 }
125 }
126
127 public WikiPage getParentPage() {
128 if (Validator.isNull(getParentTitle())) {
129 return null;
130 }
131
132 try {
133 return WikiPageLocalServiceUtil.getPage(
134 getNodeId(), getParentTitle());
135 }
136 catch (Exception e) {
137 _log.error(e, e);
138
139 return null;
140 }
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 try {
162 return WikiPageLocalServiceUtil.getPage(
163 getNodeId(), getRedirectTitle());
164 }
165 catch (Exception e) {
166 _log.error(e, e);
167
168 return null;
169 }
170 }
171
172 public List<WikiPage> getViewableChildPages() {
173 try {
174 return WikiPageServiceUtil.getChildren(
175 getGroupId(), getNodeId(), true, getTitle());
176 }
177 catch (Exception e) {
178 _log.error(e, e);
179
180 return Collections.emptyList();
181 }
182 }
183
184 public WikiPage getViewableParentPage() {
185 if (Validator.isNull(getParentTitle())) {
186 return null;
187 }
188
189 try {
190 return WikiPageServiceUtil.getPage(
191 getGroupId(), getNodeId(), getParentTitle());
192 }
193 catch (Exception e) {
194 _log.error(e, e);
195
196 return null;
197 }
198 }
199
200 public List<WikiPage> getViewableParentPages() {
201 List<WikiPage> pages = new ArrayList<WikiPage>();
202
203 WikiPage page = getViewableParentPage();
204
205 if (page != null) {
206 pages.addAll(page.getViewableParentPages());
207 pages.add(page);
208 }
209
210 return pages;
211 }
212
213 public boolean isInTrashContainer() {
214 WikiNode node = getNode();
215
216 if (node != null) {
217 return node.isInTrash();
218 }
219
220 return false;
221 }
222
223 @Override
224 public boolean isResourceMain() {
225 return isHead();
226 }
227
228 public void setAttachmentsFolderId(long attachmentsFolderId) {
229 _attachmentsFolderId = attachmentsFolderId;
230 }
231
232 private static Log _log = LogFactoryUtil.getLog(WikiPageImpl.class);
233
234 private long _attachmentsFolderId;
235
236 }