KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.web.bean.wizard;
18
19 import java.util.ResourceBundle JavaDoc;
20
21 import javax.faces.context.FacesContext;
22 import javax.faces.event.ValueChangeEvent;
23
24 import org.alfresco.web.app.Application;
25 import org.alfresco.web.bean.repository.Repository;
26
27 /**
28  * Handler class used by the Create In-line Content Wizard
29  *
30  * @author Kevin Roast
31  */

32 public class CreateContentWizard extends BaseContentWizard
33 {
34    protected static final String JavaDoc CONTENT_TEXT = "txt";
35    protected static final String JavaDoc CONTENT_HTML = "html";
36
37    // TODO: retrieve these from the config service
38
private static final String JavaDoc WIZARD_TITLE_ID = "create_content_title";
39    private static final String JavaDoc WIZARD_DESC_ID = "create_content_desc";
40    private static final String JavaDoc STEP1_TITLE_ID = "create_content_step1_title";
41    private static final String JavaDoc STEP1_DESCRIPTION_ID = "create_content_step1_desc";
42    private static final String JavaDoc STEP2_TITLE_ID = "create_content_step2_title";
43    private static final String JavaDoc STEP2_DESCRIPTION_ID = "create_content_step2_desc";
44    private static final String JavaDoc STEP3_TITLE_ID = "create_content_step3_title";
45    private static final String JavaDoc STEP3_DESCRIPTION_ID = "create_content_step3_desc";
46    
47    // create content wizard specific properties
48
protected String JavaDoc content;
49    protected String JavaDoc createType = CONTENT_HTML;
50    
51    
52    /**
53     * Deals with the finish button being pressed
54     *
55     * @return outcome
56     */

57    public String JavaDoc finish()
58    {
59       return saveContent(null, this.content);
60    }
61    
62    /**
63     * @see org.alfresco.web.bean.wizard.AbstractWizardBean#getWizardDescription()
64     */

65    public String JavaDoc getWizardDescription()
66    {
67       return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_DESC_ID);
68    }
69
70    /**
71     * @see org.alfresco.web.bean.wizard.AbstractWizardBean#getWizardTitle()
72     */

73    public String JavaDoc getWizardTitle()
74    {
75       return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_TITLE_ID);
76    }
77    
78    /**
79     * @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepDescription()
80     */

81    public String JavaDoc getStepDescription()
82    {
83       String JavaDoc stepDesc = null;
84       
85       switch (this.currentStep)
86       {
87          case 1:
88          {
89             stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), STEP1_DESCRIPTION_ID);
90             break;
91          }
92          case 2:
93          {
94             stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), STEP2_DESCRIPTION_ID);
95             break;
96          }
97          case 3:
98          {
99             stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), STEP3_DESCRIPTION_ID);
100             break;
101          }
102          case 4:
103          {
104             stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), SUMMARY_DESCRIPTION_ID);
105             break;
106          }
107          default:
108          {
109             stepDesc = "";
110          }
111       }
112       
113       return stepDesc;
114    }
115
116    /**
117     * @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepInstructions()
118     */

119    public String JavaDoc getStepInstructions()
120    {
121       String JavaDoc stepInstruction = null;
122       
123       switch (this.currentStep)
124       {
125          case 4:
126          {
127             stepInstruction = Application.getMessage(FacesContext.getCurrentInstance(), FINISH_INSTRUCTION_ID);
128             break;
129          }
130          default:
131          {
132             stepInstruction = Application.getMessage(FacesContext.getCurrentInstance(), DEFAULT_INSTRUCTION_ID);
133          }
134       }
135       
136       return stepInstruction;
137    }
138    
139    /**
140     * @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepTitle()
141     */

142    public String JavaDoc getStepTitle()
143    {
144       String JavaDoc stepTitle = null;
145       
146       switch (this.currentStep)
147       {
148          case 1:
149          {
150             stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP1_TITLE_ID);
151             break;
152          }
153          case 2:
154          {
155             stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP2_TITLE_ID);
156             break;
157          }
158          case 3:
159          {
160             stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP3_TITLE_ID);
161             break;
162          }
163          case 4:
164          {
165             stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), SUMMARY_TITLE_ID);
166             break;
167          }
168          default:
169          {
170             stepTitle = "";
171          }
172       }
173       
174       return stepTitle;
175    }
176    
177    /**
178     * @return Returns the content from the edited form.
179     */

180    public String JavaDoc getContent()
181    {
182       return this.content;
183    }
184    
185    /**
186     * @param content The content to edit (should be clear initially)
187     */

188    public void setContent(String JavaDoc content)
189    {
190       this.content = content;
191    }
192    
193    /**
194     * Initialises the wizard
195     */

196    public void init()
197    {
198       super.init();
199       
200       this.content = null;
201       
202       // created content is inline editable by default
203
this.inlineEdit = true;
204    }
205    
206    /**
207     * @return Returns the summary data for the wizard.
208     */

209    public String JavaDoc getSummary()
210    {
211       ResourceBundle JavaDoc bundle = Application.getBundle(FacesContext.getCurrentInstance());
212       
213       // TODO: show first few lines of content here?
214
return buildSummary(
215             new String JavaDoc[] {bundle.getString("file_name"), bundle.getString("type"),
216                           bundle.getString("content_type"), bundle.getString("title"),
217                           bundle.getString("description"), bundle.getString("author")},
218             new String JavaDoc[] {this.fileName, getSummaryObjectType(), getSummaryContentType(),
219                           this.title, this.description, this.author});
220    }
221    
222    /**
223     * @see org.alfresco.web.bean.wizard.AbstractWizardBean#determineOutcomeForStep(int)
224     */

225    protected String JavaDoc determineOutcomeForStep(int step)
226    {
227       String JavaDoc outcome = null;
228       
229       switch(step)
230       {
231          case 1:
232          {
233             outcome = "select";
234             break;
235          }
236          case 2:
237          {
238             if (getCreateType().equals(CONTENT_HTML))
239             {
240                outcome = "create-html";
241             }
242             else if (getCreateType().equals(CONTENT_TEXT))
243             {
244                outcome = "create-text";
245             }
246             break;
247          }
248          case 3:
249          {
250             this.fileName = "newfile." + getCreateType();
251             this.contentType = Repository.getMimeTypeForFileName(
252                   FacesContext.getCurrentInstance(), this.fileName);
253             this.title = this.fileName;
254             
255             outcome = "properties";
256             break;
257          }
258          case 4:
259          {
260             outcome = "summary";
261             break;
262          }
263          default:
264          {
265             outcome = CANCEL_OUTCOME;
266          }
267       }
268       
269       return outcome;
270    }
271    
272    /**
273     * Create content type value changed by the user
274     */

275    public void createContentChanged(ValueChangeEvent event)
276    {
277       // clear the content as HTML is not compatible with the plain text box etc.
278
this.content = null;
279    }
280
281    /**
282     * @return Returns the createType.
283     */

284    public String JavaDoc getCreateType()
285    {
286       return this.createType;
287    }
288
289    /**
290     * @param createType The createType to set.
291     */

292    public void setCreateType(String JavaDoc createType)
293    {
294       this.createType = createType;
295    }
296 }
297
Popular Tags