1 19 20 package org.netbeans.modules.j2ee.ddloaders.web.multiview; 21 22 import org.netbeans.modules.xml.multiview.Error; 23 import org.netbeans.modules.j2ee.dd.api.web.*; 24 import org.openide.util.NbBundle; 25 26 31 public class SectionValidator { 32 33 static Error validateServlets(WebApp webApp) { 34 Servlet[] servlets = webApp.getServlet(); 35 Error error=null; 36 for (int i=0;i<servlets.length;i++) { 37 String name = servlets[i].getServletName(); 39 if (name==null || name.length()==0) { 40 Error.ErrorLocation loc = new Error.ErrorLocation (servlets[i],"ServletName"); error = new Error (Error.MISSING_VALUE_MESSAGE, "Servlet Name", loc); 42 break; 43 } 44 name = servlets[i].getServletClass(); 46 if (name==null) name = servlets[i].getJspFile(); 47 if (name==null || name.length()==0) { 48 Error.ErrorLocation loc = new Error.ErrorLocation (servlets[i],"ServletClass"); error = new Error (Error.MISSING_VALUE_MESSAGE, "Servlet Class", loc); 50 break; 51 } 52 String [] urlPatterns = DDUtils.getUrlPatterns(webApp,servlets[i]); 54 for (int j=0;j<urlPatterns.length;j++) { 55 String errMessage = DDUtils.checkServletMappig(urlPatterns[j]); 56 if (errMessage!=null) { 57 Error.ErrorLocation loc = new Error.ErrorLocation (servlets[i],"ServletMapping"); error = new Error (Error.ERROR_MESSAGE, errMessage , loc); 59 break; 60 } 61 if (DDUtils.isServletMapping(webApp, servlets[i], urlPatterns[j])) { 62 Error.ErrorLocation loc = new Error.ErrorLocation (servlets[i],"ServletMapping"); error = new Error (Error.DUPLICATE_VALUE_MESSAGE, urlPatterns[j] , loc); 64 break; 65 } 66 } 67 } 68 return error; 69 } 70 71 static Error validateFilters(WebApp webApp) { 72 Filter[] filters = webApp.getFilter(); 73 Error error=null; 74 for (int i=0;i<filters.length;i++) { 75 String name = filters[i].getFilterName(); 77 if (name==null || name.length()==0) { 78 Error.ErrorLocation loc = new Error.ErrorLocation (filters[i],"FilterName"); error = new Error (Error.MISSING_VALUE_MESSAGE, "Filter Name", loc); 80 break; 81 } 82 name = filters[i].getFilterClass(); 84 if (name==null || name.length()==0) { 85 Error.ErrorLocation loc = new Error.ErrorLocation (filters[i],"FilterClass"); error = new Error (Error.MISSING_VALUE_MESSAGE, "Filter Class", loc); 87 break; 88 } 89 } 90 return error; 91 } 92 93 static Error validatePages(WebApp webApp) { 94 Error error=null; 95 JspConfig jspConfig=null; 96 JspPropertyGroup[] groups=null; 97 try { 98 jspConfig = webApp.getSingleJspConfig(); 99 } catch (org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException ex) { 100 return null; 101 } 102 if (jspConfig==null) { 103 return null; 104 } else groups = jspConfig.getJspPropertyGroup(); 105 if (groups==null) return null; 106 107 for (int i=0;i<groups.length;i++) { 109 if (groups[i].sizeUrlPattern()==0) { 110 Error.ErrorLocation loc = new Error.ErrorLocation (groups[i],"url_patterns"); error = new Error (Error.MISSING_VALUE_MESSAGE, "URL Pattern", loc); 112 break; 113 } 114 } 115 return error; 116 } 117 118 static String validateNewServlet(WebApp webApp, String servletName, String servletClass, String jspFile, String urlPatterns) { 119 if (servletName.length()==0) { 120 return NbBundle.getMessage(SectionValidator.class,"TXT_EmptyServletName"); 121 } else { 122 Servlet[] servlets = webApp.getServlet(); 123 boolean exists=false; 124 for (int i=0;i<servlets.length;i++) { 125 if (servletName.equals(servlets[i].getServletName())) { 126 exists=true; 127 break; 128 } 129 } 130 if (exists) { 131 return NbBundle.getMessage(SectionValidator.class,"TXT_ServletNameExists",servletName); 132 } 133 } 134 if (servletClass.length()==0 && jspFile.length()==0) { 135 return NbBundle.getMessage(SectionValidator.class,"TXT_Servlet_BothMissing"); 136 } 137 if (servletClass.length()>0 && jspFile.length()>0) { 138 return NbBundle.getMessage(SectionValidator.class,"TXT_Servlet_BothSpecified"); 139 } 140 String [] patterns = DDUtils.getStringArray(urlPatterns); 141 if (patterns.length>0) { 142 for (int i=0;i<patterns.length;i++) { 143 String errMessage = DDUtils.checkServletMappig(patterns[i]); 144 if (errMessage!=null) return errMessage; 145 if (DDUtils.isServletMapping(webApp,patterns[i])) { 146 return NbBundle.getMessage(SectionValidator.class,"TXT_UrlPatternExists",patterns[i]); 147 } 148 } 149 } 150 return null; 151 } 152 153 static String validateNewFilter(WebApp webApp, String filterName, String filterClass) { 154 if (filterName.length()==0) { 155 return NbBundle.getMessage(SectionValidator.class,"TXT_EmptyFilterName"); 156 } else { 157 Filter[] filters = webApp.getFilter(); 158 boolean exists=false; 159 for (int i=0;i<filters.length;i++) { 160 if (filterName.equals(filters[i].getFilterName())) { 161 exists=true; 162 break; 163 } 164 } 165 if (exists) { 166 return NbBundle.getMessage(SectionValidator.class,"TXT_FilterNameExists",filterName); 167 } 168 } 169 if (filterClass.length()==0) { 170 return NbBundle.getMessage(SectionValidator.class,"TXT_EmptyFilterClass"); 171 } 172 return null; 173 } 174 175 static String validateNewJspPropertyGroup(String urlPatterns) { 176 String [] patterns = DDUtils.getStringArray(urlPatterns); 177 if (patterns.length==0) { 178 return NbBundle.getMessage(SectionValidator.class,"TXT_EmptyUrls"); 179 } 180 return null; 181 } 182 } 183 | Popular Tags |