001
014
015 package com.liferay.portlet.wiki.model.impl;
016
017 import com.liferay.documentlibrary.NoSuchDirectoryException;
018 import com.liferay.documentlibrary.service.DLServiceUtil;
019 import com.liferay.portal.kernel.exception.PortalException;
020 import com.liferay.portal.kernel.exception.SystemException;
021 import com.liferay.portal.kernel.log.Log;
022 import com.liferay.portal.kernel.log.LogFactoryUtil;
023 import com.liferay.portal.kernel.util.Validator;
024 import com.liferay.portal.model.CompanyConstants;
025 import com.liferay.portlet.wiki.model.WikiNode;
026 import com.liferay.portlet.wiki.model.WikiPage;
027 import com.liferay.portlet.wiki.service.WikiNodeLocalServiceUtil;
028 import com.liferay.portlet.wiki.service.WikiPageLocalServiceUtil;
029
030 import java.util.ArrayList;
031 import java.util.List;
032
033
037 public class WikiPageImpl extends WikiPageModelImpl implements WikiPage {
038
039 public WikiPageImpl() {
040 }
041
042 public String getAttachmentsDir() {
043 if (_attachmentDirs == null) {
044 _attachmentDirs = "wiki/" + getResourcePrimKey();
045 }
046
047 return _attachmentDirs;
048 }
049
050 public String[] getAttachmentsFiles()
051 throws PortalException, SystemException {
052
053 String[] fileNames = new String[0];
054
055 try {
056 fileNames = DLServiceUtil.getFileNames(
057 getCompanyId(), CompanyConstants.SYSTEM, getAttachmentsDir());
058 }
059 catch (NoSuchDirectoryException nsde) {
060 }
061
062 return fileNames;
063 }
064
065 public List<WikiPage> getChildPages() {
066 List<WikiPage> pages = null;
067
068 try {
069 pages = WikiPageLocalServiceUtil.getChildren(
070 getNodeId(), true, getTitle());
071 }
072 catch (Exception e) {
073 pages = new ArrayList<WikiPage>();
074
075 _log.error(e);
076 }
077
078 return pages;
079 }
080
081 public WikiNode getNode() {
082 WikiNode node = null;
083
084 try {
085 node = WikiNodeLocalServiceUtil.getNode(getNodeId());
086 }
087 catch (Exception e) {
088 node = new WikiNodeImpl();
089
090 _log.error(e);
091 }
092
093 return node;
094 }
095
096 public WikiPage getParentPage() {
097 if (Validator.isNull(getParentTitle())) {
098 return null;
099 }
100
101 WikiPage page = null;
102
103 try {
104 page = WikiPageLocalServiceUtil.getPage(
105 getNodeId(), getParentTitle());
106 }
107 catch (Exception e) {
108 _log.error(e);
109 }
110
111 return page;
112 }
113
114 public List<WikiPage> getParentPages() {
115 List<WikiPage> parentPages = new ArrayList<WikiPage>();
116
117 WikiPage parentPage = getParentPage();
118
119 if (parentPage != null) {
120 parentPages.addAll(parentPage.getParentPages());
121 parentPages.add(parentPage);
122 }
123
124 return parentPages;
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 void setAttachmentsDir(String attachmentsDir) {
146 _attachmentDirs = attachmentsDir;
147 }
148
149 private static Log _log = LogFactoryUtil.getLog(WikiPageImpl.class);
150
151 private String _attachmentDirs;
152
153 }