@@ -0,0 +1,3503 @@
+/**%0A * Copyright %5B2016%5D Gaurav Gupta%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22); you may not%0A * use this file except in compliance with the License. You may obtain a copy of%0A * the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS, WITHOUT%0A * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the%0A * License for the specific language governing permissions and limitations under%0A * the License.%0A */%0Apackage org.netbeans.jcode.servlet;%0A%0Aimport java.io.IOException;%0Aimport org.netbeans.api.project.Project;%0Aimport org.netbeans.modules.j2ee.common.dd.DDHelper;%0Aimport org.netbeans.modules.j2ee.dd.api.web.DDProvider;%0Aimport org.netbeans.modules.j2ee.dd.api.web.WebApp;%0Aimport org.netbeans.modules.j2ee.dd.api.web.WelcomeFileList;%0Aimport org.netbeans.modules.web.api.webmodule.WebModule;%0Aimport org.openide.filesystems.FileObject;%0Aimport org.openide.filesystems.FileUtil;%0A%0A/**%0A *%0A * @author Gaurav Gupta%0A */%0Apublic class ServletUtil %7B%0A    public static void setWelcomeFiles(Project project, String text) throws IOException %7B%0A        FileObject webXml = null;%0A        // Create web.xml%0A        WebModule wm1 = WebModule.getWebModule(project.getProjectDirectory());%0A        if (wm1 != null && wm1.getDocumentBase() != null) %7B%0A            FileObject webInf = wm1.getWebInf();%0A            if (webInf == null) %7B%0A                webInf = FileUtil.createFolder(wm1.getDocumentBase(), %22WEB-INF%22);    //NOI18N%0A            %7D%0A            webXml = DDHelper.createWebXml(wm1.getJ2eeProfile(), webInf);%0A        %7D%0A%0A        WebApp webApp = null;%0A        if (webXml != null) %7B%0A            webApp = DDProvider.getDefault().getDDRoot(webXml);%0A%0A            if (text.length() == 0) %7B%0A                webApp.setWelcomeFileList(null);%0A            %7D else %7B%0A                java.util.List wfList = new java.util.ArrayList();%0A                java.util.StringTokenizer tok = new java.util.StringTokenizer(text, %22,%22);%0A                while (tok.hasMoreTokens()) %7B%0A                    String wf = tok.nextToken().trim();%0A                    if (wf.length() %3E 0 && !wfList.contains(wf)) %7B%0A                        wfList.add(wf);%0A                    %7D%0A                %7D%0A                if (wfList.size() == 0) %7B%0A                    try %7B%0A                        WelcomeFileList welcomeFileList = (WelcomeFileList) webApp.createBean(%22WelcomeFileList%22); //NOI18N%0A                        webApp.setWelcomeFileList(welcomeFileList);%0A                    %7D catch (ClassNotFoundException ex) %7B%0A                    %7D%0A                %7D else %7B%0A                    String%5B%5D welcomeFiles = new String%5BwfList.size()%5D;%0A                    wfList.toArray(welcomeFiles);%0A                    WelcomeFileList welcomeFileList = webApp.getSingleWelcomeFileList();%0A                    if (welcomeFileList == null) %7B%0A                        try %7B%0A                            welcomeFileList = (WelcomeFileList) webApp.createBean(%22WelcomeFileList%22); //NOI18N%0A                            welcomeFileList.setWelcomeFile(welcomeFiles);%0A                            webApp.setWelcomeFileList(welcomeFileList);%0A                        %7D catch (ClassNotFoundException ex) %7B%0A                        %7D%0A                    %7D else %7B%0A                        welcomeFileList.setWelcomeFile(welcomeFiles);%0A                    %7D%0A                %7D%0A            %7D%0A        %7D%0A    %7D%0A%0A%7D%0A

Add welcome file