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