KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.Serializable JavaDoc;
21 import java.util.HashMap JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import javax.faces.context.FacesContext;
25
26 import org.alfresco.model.ContentModel;
27 import org.alfresco.model.ForumModel;
28 import org.alfresco.service.cmr.model.FileInfo;
29 import org.alfresco.service.cmr.repository.ContentService;
30 import org.alfresco.service.cmr.repository.ContentWriter;
31 import org.alfresco.service.cmr.repository.NodeRef;
32 import org.alfresco.service.namespace.QName;
33 import org.alfresco.web.app.AlfrescoNavigationHandler;
34 import org.alfresco.web.bean.ForumsBean;
35 import org.alfresco.web.bean.repository.Repository;
36 import org.alfresco.web.ui.common.Utils;
37 import org.apache.commons.logging.Log;
38 import org.apache.commons.logging.LogFactory;
39
40 /**
41  * Wizard bean used for creating and editing topic spaces
42  *
43  * @author gavinc
44  */

45 public class NewTopicWizard extends NewSpaceWizard
46 {
47    private static final Log logger = LogFactory.getLog(NewTopicWizard.class);
48    
49    protected String JavaDoc message;
50    
51    protected ContentService contentService;
52
53    /**
54     * Returns the message entered by the user for the first post
55     *
56     * @return The message for the first post
57     */

58    public String JavaDoc getMessage()
59    {
60       return this.message;
61    }
62
63    /**
64     * Sets the message
65     *
66     * @param message The message
67     */

68    public void setMessage(String JavaDoc message)
69    {
70       this.message = message;
71    }
72    
73    /**
74     * @param contentService The contentService to set.
75     */

76    public void setContentService(ContentService contentService)
77    {
78       this.contentService = contentService;
79    }
80    
81    /**
82     * @see org.alfresco.web.bean.wizard.AbstractWizardBean#init()
83     */

84    public void init()
85    {
86       super.init();
87
88       this.spaceType = ForumModel.TYPE_TOPIC.toString();
89       this.message = null;
90    }
91
92    /**
93     * @see org.alfresco.web.bean.wizard.NewSpaceWizard#performCustomProcessing(javax.faces.context.FacesContext)
94     */

95    @Override JavaDoc
96    protected void performCustomProcessing(FacesContext context) throws Exception JavaDoc
97    {
98       if (this.editMode == false)
99       {
100          // get the node ref of the node that will contain the content
101
NodeRef containerNodeRef = this.createdNode;
102          
103          // create a unique file name for the message content
104
String JavaDoc fileName = ForumsBean.createPostFileName();
105          
106          FileInfo fileInfo = this.fileFolderService.create(containerNodeRef,
107                fileName, ForumModel.TYPE_POST);
108          NodeRef postNodeRef = fileInfo.getNodeRef();
109          
110          if (logger.isDebugEnabled())
111             logger.debug("Created post node with filename: " + fileName);
112          
113          // apply the titled aspect - title and description
114
Map JavaDoc<QName, Serializable JavaDoc> titledProps = new HashMap JavaDoc<QName, Serializable JavaDoc>(3, 1.0f);
115          titledProps.put(ContentModel.PROP_TITLE, fileName);
116          this.nodeService.addAspect(postNodeRef, ContentModel.ASPECT_TITLED, titledProps);
117          
118          if (logger.isDebugEnabled())
119             logger.debug("Added titled aspect with properties: " + titledProps);
120          
121          Map JavaDoc<QName, Serializable JavaDoc> editProps = new HashMap JavaDoc<QName, Serializable JavaDoc>(1, 1.0f);
122          editProps.put(ContentModel.PROP_EDITINLINE, true);
123          this.nodeService.addAspect(postNodeRef, ContentModel.ASPECT_INLINEEDITABLE, editProps);
124          
125          if (logger.isDebugEnabled())
126             logger.debug("Added inlineeditable aspect with properties: " + editProps);
127          
128          // get a writer for the content and put the file
129
ContentWriter writer = contentService.getWriter(postNodeRef, ContentModel.PROP_CONTENT, true);
130          // set the mimetype and encoding
131
writer.setMimetype(Repository.getMimeTypeForFileName(context, fileName));
132          writer.setEncoding("UTF-8");
133          writer.putContent(Utils.replaceLineBreaks(this.message));
134       }
135    }
136    
137    /**
138     * @see org.alfresco.web.bean.wizard.AbstractWizardBean#finish()
139     */

140    @Override JavaDoc
141    public String JavaDoc finish()
142    {
143       String JavaDoc outcome = super.finish();
144       
145       // if we had a successful outcome work out the outcome to return
146
if (outcome != null)
147       {
148          outcome = AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
149          
150          if (this.editMode == false)
151          {
152             // if we are successful in creating the topic we need to setup
153
// the browse context for the new topic and pass an override
154
// outcome of 'showTopic'
155
this.browseBean.clickSpace(this.createdNode);
156             
157             outcome = outcome + AlfrescoNavigationHandler.DIALOG_SEPARATOR + "showTopic";
158          }
159       }
160       
161       return outcome;
162    }
163
164    /**
165     * @see org.alfresco.web.bean.wizard.AbstractWizardBean#cancel()
166     */

167    @Override JavaDoc
168    public String JavaDoc cancel()
169    {
170       super.cancel();
171       
172       return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
173    }
174 }
175
Popular Tags