View Javadoc

1   package pl.caltha.forms.internal;
2   
3   import org.objectledge.templating.MergingException;
4   import org.objectledge.templating.Template;
5   import org.objectledge.templating.TemplateNotFoundException;
6   import org.objectledge.templating.Templating;
7   import org.objectledge.templating.TemplatingContext;
8   import org.objectledge.web.mvc.tools.LinkTool;
9   
10  import pl.caltha.forms.FormTool;
11  import pl.caltha.forms.Instance;
12  import pl.caltha.forms.internal.model.InstanceImpl;
13  import pl.caltha.forms.internal.ui.UIConstants;
14  
15  /*** This a form tool context tool implementation.
16   *
17   * @author <a href="mailto:zwierzem@ngo.pl">Damian Gajda</a>
18   * @version $Id: FormToolImpl.java,v 1.7 2005/03/23 13:42:23 zwierzem Exp $
19   */
20  public class FormToolImpl 
21  implements FormTool
22  {
23      private Templating templating;
24      
25      private TemplatingContext templatingContext;
26      
27      public FormToolImpl(Templating templating, TemplatingContext templatingContext)
28      {
29          this.templating = templating;
30          this.templatingContext = templatingContext;
31      }
32      
33      
34      public String generateUI(Instance instance, LinkTool formLink, String skinName)
35      throws MergingException, TemplateNotFoundException
36      {
37          // 1. get UI from Instance, get rootNode
38          // 2. put root node into the context
39          // 3. put instance into the context
40          templatingContext.put("formtool-instance", instance);
41          templatingContext.put("formtool-form", ((InstanceImpl)instance).getForm().getUI().getUIRoot());
42          templatingContext.put("formtool-link", formLink);
43          templatingContext.put("formtoolConst", UIConstants.getInstance());
44  
45          // 4. get the skin == template
46          Template template = templating.getTemplate("forms/"+skinName);
47          
48          // 5. merge template
49          return template.merge(templatingContext);
50      }
51  
52  
53      public String generateUI(Instance instance, LinkTool formLink)
54      throws MergingException, TemplateNotFoundException
55      {
56          return generateUI(instance, formLink, "Default");
57      }
58  }