KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > form > FormComponentTag


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 package com.tonbeller.wcf.form;
14
15 import java.net.MalformedURLException JavaDoc;
16 import java.net.URL JavaDoc;
17 import java.util.Locale JavaDoc;
18 import java.util.MissingResourceException JavaDoc;
19
20 import javax.servlet.jsp.JspException JavaDoc;
21
22 import org.apache.log4j.Logger;
23 import org.w3c.dom.Document JavaDoc;
24
25 import com.tonbeller.wcf.component.Component;
26 import com.tonbeller.wcf.component.ComponentTag;
27 import com.tonbeller.wcf.controller.RequestContext;
28 import com.tonbeller.wcf.utils.ResourceLocator;
29 import com.tonbeller.wcf.utils.XmlUtils;
30 import com.tonbeller.wcf.wizard.WizardComponent;
31 import com.tonbeller.wcf.wizard.WizardComponentTag;
32
33 /**
34  * creates a FormComponent
35  *
36  * @author av
37  */

38 public class FormComponentTag extends ComponentTag {
39
40   String JavaDoc xmlUri;
41   String JavaDoc model;
42   boolean bookmarkable = false;
43   boolean finishButton = true;
44   String JavaDoc bundle;
45
46   private static Logger logger = Logger.getLogger(FormComponentTag.class);
47
48   /**
49    * loads a form from an xml file and registeres it with the controller.
50    */

51   public Component createComponent(RequestContext context) throws JspException JavaDoc {
52     try {
53
54       Document JavaDoc doc = parseDocument(context, getXmlUri());
55
56       // find the bean model
57
Object JavaDoc bean = null;
58       if (model != null)
59         bean = context.getModelReference(model);
60
61       // create the component
62
FormComponent fc = createFormComponent(context, id, doc, bean);
63       fc.setBookmarkable(bookmarkable);
64       fc.setFinishButton(finishButton);
65
66       registerWithWizard(fc);
67       return fc;
68
69     } catch (MalformedURLException JavaDoc e) {
70       logger.error(null, e);
71       throw new JspException JavaDoc(e);
72     }
73   }
74
75   /**
76    * if this is used inside a wizard tag, then its registered with the wizard.
77    */

78   private void registerWithWizard(FormComponent fc) {
79     WizardComponentTag wt = (WizardComponentTag) findAncestorWithClass(this,
80         WizardComponentTag.class);
81     if (wt == null)
82       return;
83     WizardComponent wc = (WizardComponent) wt.getComponent();
84     wc.addPage(fc);
85   }
86
87   protected FormComponent createFormComponent(RequestContext context, String JavaDoc id, Document JavaDoc doc,
88       Object JavaDoc bean) {
89     return new FormComponent(id, null, doc, bean);
90   }
91
92   protected Document JavaDoc parseDocument(RequestContext context, String JavaDoc xmlUri)
93       throws MalformedURLException JavaDoc, MissingResourceException JavaDoc {
94
95     Locale JavaDoc loc = context.getLocale(); // Default: browser setting
96
URL JavaDoc url = ResourceLocator.getResource(context.getServletContext(), loc, xmlUri);
97
98     Document JavaDoc document = XmlUtils.parse(url);
99     //In replaceI18n(...) wird geprüft, ob "bundle"-Attribut vorhanden
100
FormDocument.replaceI18n(context, document, getBundle());
101
102     return document;
103   }
104
105   public String JavaDoc getXmlUri() {
106     return xmlUri;
107   }
108
109   public void setXmlUri(String JavaDoc xmlUri) {
110     this.xmlUri = xmlUri;
111   }
112
113   public String JavaDoc getModel() {
114     return model;
115   }
116
117   public void setModel(String JavaDoc model) {
118     this.model = model;
119   }
120
121   public void setBookmarkable(boolean b) {
122     bookmarkable = b;
123   }
124
125   public void setBundle(String JavaDoc bundle) {
126     this.bundle = bundle;
127   }
128
129   public boolean isFinishButton() {
130     return finishButton;
131   }
132
133   public void setFinishButton(boolean finishButton) {
134     this.finishButton = finishButton;
135   }
136
137   public String JavaDoc getBundle() {
138     return bundle;
139   }
140
141 }
142
Popular Tags