1 package net.sourceforge.formview.test; 2 3 import java.io.IOException ; 4 import java.io.InputStream ; 5 6 import org.xml.sax.SAXException ; 7 8 import net.sourceforge.formview.FormView; 9 import net.sourceforge.formview.FormViewException; 10 import net.sourceforge.formview.FormViewResources; 11 import net.sourceforge.formview.displayer.DisplayersConfigResources; 12 import net.sourceforge.formview.permission.IPermissionsAdapter; 13 import net.sourceforge.formview.util.ApplicationFormViewUtil; 14 import net.sourceforge.formview.validator.ExtendedValidatorResources; 15 16 public class FormViewTestWithSeveralValidator { 17 18 21 public static void main(String [] args) 22 throws FormViewException, IOException , SAXException { 23 InputStream inFomView = null; 24 25 26 FormViewResources resources = null; 28 try { 29 30 36 inFomView = FormViewTest.class.getResourceAsStream("form-view-test.xml"); 37 resources = new FormViewResources(inFomView); 38 39 } finally { 40 if (inFomView != null) { 42 inFomView.close(); 43 } 44 45 } 46 47 InputStream inDisplayerConfig = null; 48 DisplayersConfigResources displayersResources = null; 50 try { 51 52 inDisplayerConfig = DisplayersConfigResources.class.getResourceAsStream("displayers-config.xml"); 53 displayersResources = new DisplayersConfigResources(inDisplayerConfig); 54 55 } finally { 56 if (inDisplayerConfig != null) { 58 inDisplayerConfig.close(); 59 } 60 } 61 resources.mergeDisplayersWithDisplayerConfig(displayersResources); 62 63 InputStream [] inSeveralValidator = new InputStream [2]; 65 ExtendedValidatorResources validatorResources = null; 66 67 try { 68 69 inSeveralValidator[0] = FormViewTest.class.getResourceAsStream("validation1.xml"); 75 inSeveralValidator[1] = FormViewTest.class.getResourceAsStream("validation2.xml"); 76 validatorResources = new ExtendedValidatorResources(inSeveralValidator); 77 78 } finally { 79 if (inSeveralValidator != null) { 81 for (int streamIndex = 0;streamIndex < inSeveralValidator.length;streamIndex++) { 82 InputStream inValidator = (InputStream ) inSeveralValidator[streamIndex]; 83 inValidator.close(); 84 } 85 } 86 } 87 88 resources.mergeFormSetWithValidator(validatorResources); 89 90 resources.addContextValue("contextPath", "myapplication"); 92 93 String formName = "/user/identite_collaborateur_ONE"; 95 String state = "READ"; 96 97 String [] roles = null; 98 ApplicationFormViewUtil.init(resources); 99 100 FormView form = ApplicationFormViewUtil.getFormView(formName, state); 101 103 105 IPermissionsAdapter permissionsAdapter = new TestRolesPermissionAdapter(); 106 107 108 109 String htmlContent = getHtmlContent(); 111 String htmlContentProcess = ApplicationFormViewUtil.processHtmlContent(form, state, permissionsAdapter, htmlContent); 112 System.out.println(htmlContentProcess); 113 114 formName = "/user/identite_collaborateur_TWO"; 116 form = ApplicationFormViewUtil.getFormView(formName, state); 117 htmlContent = getHtmlContent(); 118 htmlContentProcess = ApplicationFormViewUtil.processHtmlContent(form, state, permissionsAdapter, htmlContent); 119 System.out.println(htmlContentProcess); 120 121 122 123 } 124 125 private static String getHtmlContent2() { 126 StringBuffer htmlContent = new StringBuffer (""); 127 htmlContent.append("<html>\n"); 128 htmlContent.append("<input name=\"buttonSave\" type=\"button\" >\n"); 129 htmlContent.append("</html>\n"); 130 return htmlContent.toString(); 131 } 132 133 private static String getHtmlContent() { 134 StringBuffer htmlContent = new StringBuffer (""); 135 htmlContent.append("<html>\n"); 136 htmlContent.append("<input name=\"buttonSave\" type=\"button\" >\n"); 137 htmlContent.append("<input name=\"nom\" type=\"text\" >\n"); 138 htmlContent.append("<input name=\"prenom\" type=\"text\" maxlength=\"200\" >\n"); 139 htmlContent.append("<input name=\"dateNaissance\" type=\"text\" maxlength=\"8\" >\n"); 140 htmlContent.append("<input name=\"lieuNaissance\" type=\"text\" >\n"); 141 htmlContent.append("<input name=\"INPUT_NOT_IN_FORM\" type=\"text\" >\n"); 142 htmlContent.append("<select name=\"selectList\" >\n"); 143 htmlContent.append("<option value=\"ITEM0\" >Item0</option>"); 144 htmlContent.append("<option value=\"ITEM1\" selected=\"selected\">Item1</option>"); 145 htmlContent.append("</select>\n"); 146 147 htmlContent.append("</html>\n"); 148 return htmlContent.toString(); 149 } 150 151 } 152 | Popular Tags |