KickJava   Java API By Example, From Geeks To Geeks.

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


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 FormViewSeveralFormViewConfig {
16
17     /**
18      * @param args
19      */

20     public static void main(String JavaDoc[] args)
21         throws FormViewException, IOException JavaDoc, SAXException JavaDoc {
22         InputStream JavaDoc[] inSeveralFomView = new InputStream JavaDoc[2];
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             inSeveralFomView[0] = FormViewSeveralFormViewConfig.class.getResourceAsStream("form-view-test1.xml");
36             inSeveralFomView[1] = FormViewSeveralFormViewConfig.class.getResourceAsStream("form-view-test2.xml");
37             resources = new FormViewResources(inSeveralFomView);
38             
39         } finally {
40 // // Make sure we close the input stream.
41
if (inSeveralFomView != null) {
42                 for (int streamIndex = 0;streamIndex < inSeveralFomView.length;streamIndex++) {
43                     InputStream JavaDoc inFormView = (InputStream JavaDoc) inSeveralFomView[streamIndex];
44                     inFormView.close();
45                 }
46             }
47         }
48
49         InputStream JavaDoc inDisplayerConfig = null;
50         // Merge with DisplayersConfigResources
51
DisplayersConfigResources displayersResources = null;
52         try {
53             
54             inDisplayerConfig = DisplayersConfigResources.class.getResourceAsStream("displayers-config.xml");
55             displayersResources = new DisplayersConfigResources(inDisplayerConfig);
56             
57         } finally {
58 // Make sure we close the input stream.
59
if (inDisplayerConfig != null) {
60                 inDisplayerConfig.close();
61             }
62         }
63         resources.mergeDisplayersWithDisplayerConfig(displayersResources);
64         
65         // Merge with validator
66
InputStream JavaDoc inValidator = null;
67         ExtendedValidatorResources validatorResources = null;
68         
69         try {
70         
71             // Create a new instance of a ValidatorResource, then get a stream
72
// handle on the XML file with the actions in it, and initialize the
73
// resources from it. This would normally be done by a servlet
74
// run during JSP initialization or some other application-startup
75
// routine.
76
inValidator = FormViewSeveralFormViewConfig.class.getResourceAsStream("validation.xml");
77             validatorResources = new ExtendedValidatorResources(inValidator);
78             
79         } finally {
80             // Make sure we close the input stream.
81
if (inValidator != null) {
82                 inValidator.close();
83             }
84         }
85         
86         resources.mergeFormSetWithValidator(validatorResources);
87         
88         ///////// PUT Name of context of WEB Application
89
resources.addContextValue("contextPath", "myapplication");
90         
91         String JavaDoc formName = "/user/identite_collaborateur";
92         String JavaDoc state = "CREATE";
93          
94         ApplicationFormViewUtil.init(resources);
95         
96         FormView form = ApplicationFormViewUtil.getFormView(formName, state);
97         //defaultBehaviour = FormViewUtil.getDefaultBehaviour(defaultState);
98

99         // WEB => FormViewUtil.saveFormView(formName, state, request);
100

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