KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > web > bean > wizard > NewPostWizard


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the GNU Lesser General Public License as
5  * published by the Free Software Foundation; either version
6  * 2.1 of the License, or (at your option) any later version.
7  * You may obtain a copy of the License at
8  *
9  * http://www.gnu.org/licenses/lgpl.txt
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an
13  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14  * either express or implied. See the License for the specific
15  * language governing permissions and limitations under the
16  * License.
17  */

18 package org.alfresco.web.bean.wizard;
19
20 import javax.faces.context.FacesContext;
21 import javax.faces.event.ActionEvent;
22
23 import org.alfresco.model.ContentModel;
24 import org.alfresco.model.ForumModel;
25 import org.alfresco.service.cmr.repository.ContentReader;
26 import org.alfresco.service.cmr.repository.ContentWriter;
27 import org.alfresco.web.app.AlfrescoNavigationHandler;
28 import org.alfresco.web.bean.ForumsBean;
29 import org.alfresco.web.bean.repository.Node;
30 import org.alfresco.web.bean.repository.Repository;
31 import org.alfresco.web.ui.common.Utils;
32 import org.springframework.util.StringUtils;
33
34 /**
35  * Backing bean for posting forum articles.
36  *
37  * @author gavinc
38  */

39 public class NewPostWizard extends CreateContentWizard
40 {
41    /**
42     * @see org.alfresco.web.bean.wizard.AbstractWizardBean#init()
43     */

44    @Override JavaDoc
45    public void init()
46    {
47       super.init();
48       
49       // set up for creating a post
50
this.objectType = ForumModel.TYPE_POST.toString();
51    }
52
53    /**
54     * @see org.alfresco.web.bean.wizard.AbstractWizardBean#startWizardForEdit(javax.faces.event.ActionEvent)
55     */

56    @Override JavaDoc
57    public void startWizardForEdit(ActionEvent event)
58    {
59       // TODO: Allow action link to have multiple action listeners
60
// then we wouldn't need to have this coupling back
61
// to the browse bean in here
62

63       // we need to setup the content in the browse bean first
64
this.browseBean.setupContentAction(event);
65       
66       super.startWizardForEdit(event);
67    }
68
69    /**
70     * @see org.alfresco.web.bean.wizard.AbstractWizardBean#populate()
71     */

72    @Override JavaDoc
73    public void populate()
74    {
75       super.populate();
76       
77       // we need to remove the <br> tags and replace with carriage returns
78
// and then setup the content member variable
79
Node currentDocument = this.browseBean.getDocument();
80       ContentReader reader = this.contentService.getReader(currentDocument.getNodeRef(),
81             ContentModel.PROP_CONTENT);
82       
83       if (reader != null)
84       {
85          String JavaDoc htmlContent = reader.getContentString();
86          if (htmlContent != null)
87          {
88             this.content = StringUtils.replace(htmlContent, "<br/>", "\r\n");
89          }
90       }
91    }
92
93    /**
94     * @see org.alfresco.web.bean.wizard.AbstractWizardBean#finish()
95     */

96    @Override JavaDoc
97    public String JavaDoc finish()
98    {
99       if (this.editMode)
100       {
101          // remove the line breaks before the save
102
this.content = Utils.replaceLineBreaks(this.content);
103       }
104       else
105       {
106          // create appropriate values for filename and content type
107
this.fileName = ForumsBean.createPostFileName();
108          this.contentType = Repository.getMimeTypeForFileName(
109                      FacesContext.getCurrentInstance(), this.fileName);
110          
111          // remove link breaks and replace with <br/>
112
this.content = Utils.replaceLineBreaks(this.content);
113       }
114       
115       String JavaDoc outcome = super.finish();
116       
117       // if we had a successful outcome from the creation close the dialog
118
if (outcome != null);
119       {
120          outcome = AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
121       }
122       
123       return outcome;
124    }
125
126    /**
127     * @see org.alfresco.web.bean.wizard.BaseContentWizard#performCustomProcessing()
128     */

129    @Override JavaDoc
130    protected void performCustomProcessing()
131    {
132       if (this.editMode)
133       {
134          // update the content
135
Node currentDocument = this.browseBean.getDocument();
136          
137          ContentWriter writer = this.contentService.getWriter(currentDocument.getNodeRef(),
138                ContentModel.PROP_CONTENT, true);
139          if (writer != null)
140          {
141             writer.putContent(this.content);
142          }
143       }
144    }
145
146    /**
147     * @see org.alfresco.web.bean.wizard.AbstractWizardBean#cancel()
148     */

149    @Override JavaDoc
150    public String JavaDoc cancel()
151    {
152       super.cancel();
153       
154       return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
155    }
156 }
157
Popular Tags