1
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.Validator;
32 import com.liferay.portal.model.CompanyConstants;
33 import com.liferay.portal.util.PropsKeys;
34 import com.liferay.portal.util.PropsUtil;
35 import com.liferay.portlet.expando.model.ExpandoBridge;
36 import com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl;
37 import com.liferay.portlet.wiki.model.WikiNode;
38 import com.liferay.portlet.wiki.model.WikiPage;
39 import com.liferay.portlet.wiki.service.WikiNodeLocalServiceUtil;
40 import com.liferay.portlet.wiki.service.WikiPageLocalServiceUtil;
41
42 import java.util.ArrayList;
43 import java.util.List;
44
45
52 public class WikiPageImpl extends WikiPageModelImpl implements WikiPage {
53
54 public static final String DEFAULT_FORMAT =
55 PropsUtil.get(PropsKeys.WIKI_FORMATS_DEFAULT);
56
57 public static final double DEFAULT_VERSION = 1.0;
58
59 public static final String[] FORMATS =
60 PropsUtil.getArray(PropsKeys.WIKI_FORMATS);
61
62 public static final String FRONT_PAGE =
63 PropsUtil.get(PropsKeys.WIKI_FRONT_PAGE_NAME);
64
65 public static final String MOVED = "Moved";
66
67 public static final String NEW = "New";
68
69 public static final String REVERTED = "Reverted";
70
71 public WikiPageImpl() {
72 }
73
74 public String getAttachmentsDir() {
75 if (_attachmentDirs == null) {
76 _attachmentDirs = "wiki/" + getResourcePrimKey();
77 }
78
79 return _attachmentDirs;
80 }
81
82 public String[] getAttachmentsFiles()
83 throws PortalException, SystemException {
84
85 String[] fileNames = new String[0];
86
87 try {
88 fileNames = DLServiceUtil.getFileNames(
89 getCompanyId(), CompanyConstants.SYSTEM, getAttachmentsDir());
90 }
91 catch (NoSuchDirectoryException nsde) {
92 }
93
94 return fileNames;
95 }
96
97 public List<WikiPage> getChildPages() {
98 List<WikiPage> pages = null;
99
100 try {
101 pages = WikiPageLocalServiceUtil.getChildren(
102 getNodeId(), true, getTitle());
103 }
104 catch (Exception e) {
105 pages = new ArrayList<WikiPage>();
106
107 _log.error(e);
108 }
109
110 return pages;
111 }
112
113 public ExpandoBridge getExpandoBridge() {
114 if (_expandoBridge == null) {
115 _expandoBridge = new ExpandoBridgeImpl(
116 WikiPage.class.getName(), getResourcePrimKey());
117 }
118
119 return _expandoBridge;
120 }
121
122 public WikiNode getNode() {
123 WikiNode node = null;
124
125 try {
126 node = WikiNodeLocalServiceUtil.getNode(getNodeId());
127 }
128 catch (Exception e) {
129 node = new WikiNodeImpl();
130
131 _log.error(e);
132 }
133
134 return node;
135 }
136
137 public WikiPage getParentPage() {
138 if (Validator.isNull(getParentTitle())) {
139 return null;
140 }
141
142 WikiPage page = null;
143
144 try {
145 page = WikiPageLocalServiceUtil.getPage(
146 getNodeId(), getParentTitle());
147 }
148 catch (Exception e) {
149 _log.error(e);
150 }
151
152 return page;
153 }
154
155 public List<WikiPage> getParentPages() {
156 List<WikiPage> parentPages = new ArrayList<WikiPage>();
157
158 WikiPage parentPage = getParentPage();
159
160 if (parentPage != null) {
161 parentPages.addAll(parentPage.getParentPages());
162 parentPages.add(parentPage);
163 }
164
165 return parentPages;
166 }
167
168 public WikiPage getRedirectPage() {
169 if (Validator.isNull(getRedirectTitle())) {
170 return null;
171 }
172
173 WikiPage page = null;
174
175 try {
176 page = WikiPageLocalServiceUtil.getPage(
177 getNodeId(), getRedirectTitle());
178 }
179 catch (Exception e) {
180 _log.error(e);
181 }
182
183 return page;
184 }
185
186 public void setAttachmentsDir(String attachmentsDir) {
187 _attachmentDirs = attachmentsDir;
188 }
189
190 private static Log _log = LogFactoryUtil.getLog(WikiPageImpl.class);
191
192 private String _attachmentDirs;
193 private ExpandoBridge _expandoBridge;
194
195 }