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