1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.tuigwaa.controller;
17
18 import java.util.ArrayList;
19 import java.util.List;
20 import java.util.Map;
21 import java.util.Properties;
22
23 import javax.servlet.http.HttpServletRequest;
24
25 import org.apache.commons.lang.StringUtils;
26 import org.apache.struts.action.ActionErrors;
27 import org.apache.struts.action.ActionMapping;
28 import org.apache.struts.action.ActionMessage;
29 import org.apache.struts.action.ActionMessages;
30 import org.apache.struts.validator.ValidatorForm;
31 import org.seasar.framework.container.factory.SingletonS2ContainerFactory;
32 import org.seasar.tuigwaa.cms.ContentsService;
33 import org.seasar.tuigwaa.cms.core.CmsConstants;
34 import org.seasar.tuigwaa.cms.core.Page;
35 import org.seasar.tuigwaa.cms.core.wiki.base.WikiHelper;
36 import org.seasar.tuigwaa.plugin.TgwPluginUtils;
37 import org.seasar.tuigwaa.util.ajax.AjaxEvent;
38 import org.seasar.tuigwaa.util.ajax.Ajaxlizable;
39 import org.seasar.tuigwaa.util.ajax.SharedObjects;
40
41
42 public class PageForm extends ValidatorForm implements Ajaxlizable {
43
44 private static final long serialVersionUID = 6577847530646108778L;
45
46 private boolean saved = false;
47
48 private String domain;
49
50 private String name;
51
52 private String content;
53
54 private String folder;
55
56 private String contentType;
57
58
59
60 private List folderList;
61
62 private List attachmentList;
63
64 private Map selectedEntityMap;
65
66 private ContentsService wikiService;
67
68 private List entityInfoList;
69
70 private Properties settings;
71
72 private String lastVersion;
73
74 private String conflictedText;
75
76 private String sectionId;
77
78 public PageForm(String domain, String folder) {
79 this.domain = domain;
80 this.folder = folder;
81 this.wikiService = (ContentsService) SingletonS2ContainerFactory
82 .getContainer().getComponent(ContentsService.class);
83 }
84
85 public int getHashCode() {
86 return hashCode();
87 }
88
89 public String getPreviewHTMLByAjax(String content, String pageName) {
90 String ret = null;
91 try {
92 TgwPluginUtils.bindEntityMapToCmsRequest(selectedEntityMap);
93 Page page = wikiService.convert(domain, "",
94 CmsConstants.CONTENTTYPE_XWIKI, content,
95 CmsConstants.OUTPUTTYPE_HTML);
96 ret = page.getContent().toString();
97 } catch (Exception e) {
98 e.printStackTrace();
99 throw new RuntimeException(e);
100 }
101 return ret;
102 }
103
104 public void setEntityInfoList(List entityInfoList) {
105 this.entityInfoList = entityInfoList;
106 }
107
108 public List getEntityInfoList() {
109 return entityInfoList;
110 }
111
112 public void setFolderList(List folderList) {
113 this.folderList = folderList;
114 }
115
116 public List getFolderList() {
117 return folderList;
118 }
119
120 public void setAttachmentList(List attachmentList) {
121 this.attachmentList = attachmentList;
122 }
123
124 public List getAttachmentList() {
125 return attachmentList;
126 }
127
128 public Map getSelectedEntityMap() {
129 return selectedEntityMap;
130 }
131
132 public void setSelectedEntityMap(Map selectedEntityMap) {
133 this.selectedEntityMap = selectedEntityMap;
134 }
135
136 public void setSaved(boolean saved) {
137 this.saved = saved;
138 }
139
140 public boolean isSaved() {
141 return saved;
142 }
143
144 public void setLastVersion(String lastVersion) {
145 this.lastVersion = lastVersion;
146 }
147
148 public String getLastVersion() {
149 return lastVersion;
150 }
151
152 public void setConflictedText(String conflictedText) {
153 this.conflictedText = conflictedText;
154 }
155
156 public String getConflictedText() {
157 return conflictedText;
158 }
159
160 public void reset(ActionMapping actionMapping, HttpServletRequest request) {
161 }
162
163
164
165 public String getName() {
166 return name;
167 }
168
169 public void setName(String name) {
170 this.name = StringUtils.trim(name);
171 }
172
173 public String getContent() {
174 return content;
175 }
176
177 public String[] getContentLines() {
178 if (content != null) {
179 List list = new ArrayList();
180 String[] lines = content.split("\n");
181 for(int i=0; i<lines.length; i++){
182 if(lines[i].length()>0){
183 list.add(lines[i]);
184 }
185 }
186 return (String[])list.toArray(new String[lines.length]);
187 }
188 return null;
189 }
190
191 public void setContent(String content) {
192 if(content!=null && content.indexOf("\r")>=0){
193 content = WikiHelper.removeCarriageReturn(content);
194 }
195 this.content = content;
196 }
197
198 public String getFolder() {
199 return folder;
200 }
201
202 public void setFolder(String folder) {
203 this.folder = folder;
204 }
205
206 public String getContentType() {
207 return contentType;
208 }
209
210 public void setContentType(String contentType) {
211 this.contentType = contentType;
212 }
213
214 public String getSectionId() {
215 return sectionId;
216 }
217
218 public void setSectionId(String sectionId) {
219 this.sectionId = sectionId;
220 }
221
222 public Properties getSettings() {
223 return settings;
224 }
225
226 public void setSettings(Properties settings) {
227 this.settings = settings;
228 }
229
230 public boolean isSharable() {
231 return false;
232 }
233
234 public void addEvent(AjaxEvent event) {
235 }
236
237 public String getSharedKey() {
238 return null;
239 }
240
241 public void setSharedObject(SharedObjects objs) {
242 }
243
244
245
246 public ActionErrors validate(ActionMapping mapping,
247 HttpServletRequest request) {
248
249 if (getName() == null || getName().indexOf("/") > 0) {
250 ActionMessages messages = new ActionMessages();
251 messages.add(ActionErrors.GLOBAL_MESSAGE, new ActionMessage(
252 "error.message.pagenamehasslash"));
253
254 ActionErrors errors = new ActionErrors();
255 errors.add(messages);
256 return errors;
257 }
258
259 return super.validate(mapping, request);
260 }
261 }