Fix Issue#109570, Extension mapping pattern does not work correctly.
1.1 --- a/visualweb.project.jsf/src/org/netbeans/modules/visualweb/project/jsf/framework/JSFFrameworkProvider.java Fri Jul 20 21:58:51 2007 +0000
1.2 +++ b/visualweb.project.jsf/src/org/netbeans/modules/visualweb/project/jsf/framework/JSFFrameworkProvider.java Fri Jul 20 22:33:31 2007 +0000
1.3 @@ -39,6 +39,8 @@
1.4 import java.util.ArrayList;
1.5 import java.beans.PropertyChangeListener;
1.6 import java.beans.PropertyChangeEvent;
1.7 +import java.util.logging.Level;
1.8 +import java.util.logging.Logger;
1.9 import org.netbeans.api.java.classpath.ClassPath;
1.10 import org.netbeans.modules.j2ee.dd.api.common.InitParam;
1.11 import org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException;
1.12 @@ -49,7 +51,6 @@
1.13 import org.openide.filesystems.FileSystem;
1.14 import org.openide.filesystems.FileUtil;
1.15 import org.openide.filesystems.FileLock;
1.16 -import org.openide.filesystems.Repository;
1.17 import org.netbeans.api.project.FileOwnerQuery;
1.18 import org.netbeans.api.project.Project;
1.19 import org.netbeans.api.project.ProjectManager;
1.20 @@ -70,6 +71,12 @@
1.21 * @author Po-Ting Wu
1.22 */
1.23 public class JSFFrameworkProvider extends WebFrameworkProvider {
1.24 +
1.25 + private static final Logger LOGGER = Logger.getLogger(JSFFrameworkProvider.class.getName());
1.26 +
1.27 + private static String FORWARD_JSF = "forwardToJSF.jsp"; //NOI18N
1.28 + private static String RESOURCE_FOLDER = "org/netbeans/modules/web/jsf/resources/"; //NOI18N
1.29 +
1.30 private static final String FACES_STATE_SAVING_METHOD = "javax.faces.STATE_SAVING_METHOD"; // NOI18N
1.31 private static final String FACES_VALIDATE_XML = "com.sun.faces.validateXml"; // NOI18N
1.32 private static final String FACES_VERIFY_OBJECTS = "com.sun.faces.verifyObjects"; // NOI18N
1.33 @@ -113,7 +120,7 @@
1.34 project.getProjectDirectory().setAttribute("NewProject", Boolean.TRUE); // NOI18N
1.35 template.create(project, webModule.getJ2eePlatformVersion(), pageName);
1.36 } catch (IOException ioe){
1.37 - Exceptions.printStackTrace(ioe);
1.38 + LOGGER.log(Level.WARNING, "Exception during extending an web project", ioe); //NOI18N
1.39 }
1.40 }
1.41 });
1.42 @@ -138,8 +145,8 @@
1.43 try {
1.44 JSFUtils.createJSFUserLibrary(installFolder, libraryVersion);
1.45 jsfLib = JSFUtils.getJSFLibrary(libraryVersion);
1.46 - } catch (IOException ioe) {
1.47 - Exceptions.printStackTrace(ioe);
1.48 + } catch (IOException ioExceptoin) {
1.49 + LOGGER.log(Level.WARNING, "Exception during extending an web project", ioExceptoin); //NOI18N
1.50 }
1.51 }
1.52 }
1.53 @@ -152,8 +159,8 @@
1.54 jsfLib,
1.55 LibraryManager.getDefault().getLibrary("jstl11"),
1.56 });
1.57 - } catch (IOException ioe) {
1.58 - // Exceptions.printStackTrace(ioe);
1.59 + } catch (IOException ioExceptoin) {
1.60 + LOGGER.log(Level.WARNING, "Exception during extending an web project", ioExceptoin); //NOI18N
1.61 }
1.62 }
1.63 }
1.64 @@ -179,15 +186,15 @@
1.65 }
1.66 }
1.67 } catch (IOException ioe){
1.68 - Exceptions.printStackTrace(ioe);
1.69 + LOGGER.log(Level.WARNING, "Exception during extending an web project", ioe); //NOI18N
1.70 }
1.71 }
1.72 });
1.73 }
1.74 - } catch (FileNotFoundException exc) {
1.75 - Exceptions.printStackTrace(exc);
1.76 - } catch (IOException exc) {
1.77 - Exceptions.printStackTrace(exc);
1.78 + } catch (FileNotFoundException exception) {
1.79 + LOGGER.log(Level.WARNING, "Exception during extending an web project", exception); //NOI18N
1.80 + } catch (IOException exception) {
1.81 + LOGGER.log(Level.WARNING, "Exception during extending an web project", exception); //NOI18N
1.82 }
1.83 return result;
1.84 }
1.85 @@ -324,7 +331,7 @@
1.86 }
1.87
1.88 String facesServletName = panel == null ? "Faces Servlet" : panel.getServletName(); // NOI18N
1.89 - String urlPattern = panel == null ? "/faces/*" : panel.getURLPattern(); // NOI18N
1.90 + String facesMapping = panel == null ? "faces/*" : panel.getURLPattern(); // NOI18N
1.91
1.92 // The UpLoad Filter
1.93 Filter filter;
1.94 @@ -441,7 +448,7 @@
1.95 for (int i = 0; i < maps.length; i++) {
1.96 mapping = maps[i];
1.97 if (facesServletName.equals(mapping.getServletName()) &&
1.98 - urlPattern.equals(mapping.getUrlPattern())) {
1.99 + facesMapping.equals(mapping.getUrlPattern())) {
1.100 hasFacesPattern = true;
1.101 }
1.102 }
1.103 @@ -449,7 +456,7 @@
1.104 if (!hasFacesPattern) {
1.105 mapping = (ServletMapping)ddRoot.createBean("ServletMapping"); // NOI18N
1.106 mapping.setServletName(facesServletName);
1.107 - mapping.setUrlPattern(urlPattern);
1.108 + mapping.setUrlPattern(facesMapping);
1.109 ddRoot.addServletMapping(mapping);
1.110 }
1.111
1.112 @@ -463,14 +470,31 @@
1.113 mapping.setUrlPattern("/theme/*"); // NOI18N
1.114 ddRoot.addServletMapping(mapping);
1.115
1.116 - // Adjust the path to the startpage based on JSF parameters
1.117 - String welcomeFile = JsfProjectUtils.getWelcomeFile(urlPattern, pageName);
1.118 - WelcomeFileList wfl = ddRoot.getSingleWelcomeFileList();
1.119 - if (wfl == null) {
1.120 - wfl = (WelcomeFileList) ddRoot.createBean("WelcomeFileList");
1.121 - ddRoot.setWelcomeFileList(wfl);
1.122 + // add welcome file
1.123 + WelcomeFileList welcomeFiles = ddRoot.getSingleWelcomeFileList();
1.124 + if (welcomeFiles == null) {
1.125 + welcomeFiles = (WelcomeFileList) ddRoot.createBean("WelcomeFileList"); //NOI18N
1.126 + ddRoot.setWelcomeFileList(welcomeFiles);
1.127 }
1.128 - wfl.setWelcomeFile(new String[] { welcomeFile });
1.129 + // add the welcome file only if there not any
1.130 + if (welcomeFiles.sizeWelcomeFile() == 0) {
1.131 + if (facesMapping.charAt(0) == '/') {
1.132 + // if the mapping start with '/' (like /faces/*), then the welcame file can be the mapping
1.133 + welcomeFiles.addWelcomeFile(ConfigurationUtils.translateURI(facesMapping, pageName));
1.134 + }
1.135 + else {
1.136 + // if the mapping doesn't strat '/' (like *.jsf), then the welcome file has to be
1.137 + // a helper file, which will foward the request to the right url
1.138 + welcomeFiles.addWelcomeFile(FORWARD_JSF);
1.139 + //copy forwardToJSF.jsp
1.140 + if (facesMapping.charAt(0) != '/') {
1.141 + String content = readResource(Thread.currentThread().getContextClassLoader().getResourceAsStream(RESOURCE_FOLDER + FORWARD_JSF), "UTF-8"); //NOI18N
1.142 + content = content.replace("__FORWARD__", ConfigurationUtils.translateURI(facesMapping, pageName));
1.143 + FileObject target = FileUtil.createData(webModule.getDocumentBase(), FORWARD_JSF);//NOI18N
1.144 + createFile(target, content, "UTF-8"); //NOI18N
1.145 + }
1.146 + }
1.147 + }
1.148
1.149 // Catch ServletException
1.150 ErrorPage errorPage = (ErrorPage)ddRoot.createBean("ErrorPage");
1.151 @@ -515,15 +539,15 @@
1.152 }
1.153
1.154 if (isMyFaces) {
1.155 - Listener facesListener = (Listener) ddRoot.createBean("Listener");
1.156 - facesListener.setListenerClass("org.apache.myfaces.webapp.StartupServletContextListener");
1.157 + Listener facesListener = (Listener) ddRoot.createBean("Listener"); // NOI18N
1.158 + facesListener.setListenerClass("org.apache.myfaces.webapp.StartupServletContextListener"); // NOI18N
1.159 ddRoot.addListener(facesListener);
1.160 }
1.161 ddRoot.write(dd);
1.162
1.163
1.164 } catch (ClassNotFoundException cnfe){
1.165 - Exceptions.printStackTrace(cnfe);
1.166 + LOGGER.log(Level.WARNING, "Exception in JSFMoveClassPlugin", cnfe); //NOI18N
1.167 }
1.168 }
1.169
1.170 @@ -536,42 +560,10 @@
1.171 facesConfigTemplate = "faces-config_1_2.xml"; //NOI18N
1.172 }
1.173 }
1.174 - String content = readResource(Repository.getDefault().getDefaultFileSystem().findResource("org-netbeans-modules-web-jsf/" + facesConfigTemplate).getInputStream(), "UTF-8"); //NOI18N
1.175 + String content = readResource(Thread.currentThread().getContextClassLoader().getResourceAsStream(RESOURCE_FOLDER + facesConfigTemplate), "UTF-8"); //NOI18N
1.176 FileObject target = FileUtil.createData(webModule.getWebInf(), "faces-config.xml");//NOI18N
1.177 createFile(target, content, "UTF-8"); //NOI18N
1.178 }
1.179 -
1.180 - // update welcome page
1.181 - FileObject documentBase = webModule.getDocumentBase();
1.182 - FileObject indexjsp = documentBase.getFileObject("index.jsp"); //NOI18N
1.183 - if (indexjsp != null){
1.184 - changeIndexJSP(indexjsp, pageName);
1.185 - }
1.186 - }
1.187 -
1.188 - /** Changes the index.jsp file. Only when there is <h1>JSP Page</h1> string.
1.189 - */
1.190 - private void changeIndexJSP(FileObject indexjsp, String pageName) throws IOException {
1.191 -
1.192 - String content = readResource(indexjsp.getInputStream(), "UTF-8"); //NO18N
1.193 -
1.194 - // what find
1.195 - String find = "<h1>JSP Page</h1>"; // NOI18N
1.196 - String endLine = System.getProperty("line.separator"); //NOI18N
1.197 - if ( content.indexOf(find) > 0){
1.198 - StringBuffer replace = new StringBuffer();
1.199 - replace.append(find);
1.200 - replace.append(endLine);
1.201 - replace.append(" <br/>"); //NOI18N
1.202 - replace.append(endLine);
1.203 - replace.append(" <a href=\"."); //NOI18N
1.204 - replace.append(ConfigurationUtils.translateURI(panel == null ? "/faces/*" : panel.getURLPattern(),"/"+pageName)); //NOI18N
1.205 - replace.append("\">"); //NOI18N
1.206 - replace.append(NbBundle.getMessage(JSFFrameworkProvider.class,"LBL_JSF_WELCOME_PAGE"));
1.207 - replace.append("</a>"); //NOI18N
1.208 - content = content.replaceFirst(find, new String(replace.toString().getBytes("UTF8"), "UTF-8")); //NOI18N
1.209 - createFile(indexjsp, content, "UTF-8"); //NOI18N
1.210 - }
1.211 }
1.212 }
1.213