KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > formview > test > FormViewTest


1 package net.sourceforge.formview.test;
2
3 import java.io.IOException JavaDoc;
4 import java.io.InputStream JavaDoc;
5 import org.xml.sax.SAXException JavaDoc;
6
7 import net.sourceforge.formview.FormView;
8 import net.sourceforge.formview.FormViewException;
9 import net.sourceforge.formview.FormViewResources;
10 import net.sourceforge.formview.displayer.DisplayersConfigResources;
11 import net.sourceforge.formview.permission.IPermissionsAdapter;
12 import net.sourceforge.formview.util.ApplicationFormViewUtil;
13 import net.sourceforge.formview.validator.ExtendedValidatorResources;
14
15 public class FormViewTest {
16
17     /**
18      * @param args
19      */

20     public static void main(String JavaDoc[] args)
21         throws FormViewException, IOException JavaDoc, SAXException JavaDoc {
22         InputStream JavaDoc inFomView = null;
23
24         
25         // Load Form view
26
FormViewResources resources = null;
27         try {
28             
29             // Create a new instance of a ValidatorResource, then get a stream
30
// handle on the XML file with the actions in it, and initialize the
31
// resources from it. This would normally be done by a servlet
32
// run during JSP initialization or some other application-startup
33
// routine.
34

35             inFomView = FormViewTest.class.getResourceAsStream("form-view-test.xml");
36             resources = new FormViewResources(inFomView);
37             
38         } finally {
39 // Make sure we close the input stream.
40
if (inFomView != null) {
41                 inFomView.close();
42             }
43
44         }
45
46         InputStream JavaDoc inDisplayerConfig = null;
47         // Merge with DisplayersConfigResources
48
DisplayersConfigResources displayersResources = null;
49         try {
50             
51             inDisplayerConfig = DisplayersConfigResources.class.getResourceAsStream("displayers-config.xml");
52             displayersResources = new DisplayersConfigResources(inDisplayerConfig);
53             
54         } finally {
55 // Make sure we close the input stream.
56
if (inDisplayerConfig != null) {
57                 inDisplayerConfig.close();
58             }
59         }
60         resources.mergeDisplayersWithDisplayerConfig(displayersResources);
61         
62         // Merge with validator
63
InputStream JavaDoc inValidator = null;
64         ExtendedValidatorResources validatorResources = null;
65         
66         try {
67         
68             // Create a new instance of a ValidatorResource, then get a stream
69
// handle on the XML file with the actions in it, and initialize the
70
// resources from it. This would normally be done by a servlet
71
// run during JSP initialization or some other application-startup
72
// routine.
73
inValidator = FormViewTest.class.getResourceAsStream("validation.xml");
74             validatorResources = new ExtendedValidatorResources(inValidator);
75             
76         } finally {
77             // Make sure we close the input stream.
78
if (inValidator != null) {
79                 inValidator.close();
80             }
81         }
82         
83         resources.mergeFormSetWithValidator(validatorResources);
84         
85         ///////// PUT Name of context of WEB Application
86
resources.addContextValue("contextPath", "myapplication");
87         
88         String JavaDoc formName = "/user/identite_collaborateur";
89         String JavaDoc state = "ERROR";
90          
91         ApplicationFormViewUtil.init(resources);
92         
93         FormView form = ApplicationFormViewUtil.getFormView(formName, state);
94         //defaultBehaviour = FormViewUtil.getDefaultBehaviour(defaultState);
95

96         // WEB => FormViewUtil.saveFormView(formName, state, request);
97

98         IPermissionsAdapter permissionsAdapter = new TestRolesPermissionAdapter();
99         
100         // Test role with buttonSave
101
String JavaDoc htmlContent = getHtmlContent();
102         String JavaDoc htmlContentProcess = ApplicationFormViewUtil.processHtmlContent(form, state, permissionsAdapter, htmlContent);
103         System.out.println(htmlContentProcess);
104         
105
106     }
107     
108     private static String JavaDoc getHtmlContent2() {
109         StringBuffer JavaDoc htmlContent = new StringBuffer JavaDoc("");
110         htmlContent.append("<html>\n");
111         htmlContent.append("<input name=\"buttonSave\" type=\"button\" >\n");
112         htmlContent.append("</html>\n");
113         return htmlContent.toString();
114     }
115     
116     private static String JavaDoc getHtmlContent() {
117         StringBuffer JavaDoc htmlContent = new StringBuffer JavaDoc("");
118         htmlContent.append("<html>\n");
119             htmlContent.append("<input name=\"buttonSave\" type=\"button\" >\n");
120             htmlContent.append("<div id=\"idDiv\" >");
121                 htmlContent.append(".................................");
122             htmlContent.append("</div>\n");
123             htmlContent.append("<label for=\"nom\" >");
124                 htmlContent.append("Nom Label");
125             htmlContent.append("</label>\n");
126             htmlContent.append("<input name=\"nom\" type=\"text\" >\n");
127             htmlContent.append("<input name=\"prenom\" type=\"text\" maxlength=\"200\" >\n");
128             htmlContent.append("<input name=\"dateNaissance\" type=\"text\" maxlength=\"8\" >\n");
129             htmlContent.append("<input name=\"lieuNaissance\" type=\"text\" >\n");
130             htmlContent.append("<input name=\"INPUT_NOT_IN_FORM\" type=\"text\" >\n");
131             htmlContent.append("<select name=\"selectList\" >\n");
132             htmlContent.append("<option value=\"ITEM0\" >Item0</option>");
133             htmlContent.append("<option value=\"ITEM1\" selected=\"selected\">Item1</option>");
134             htmlContent.append("</select>\n");
135             
136         htmlContent.append("</html>\n");
137         return htmlContent.toString();
138     }
139
140 }
141
Popular Tags