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