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