Source Code Cross Referenced for JSFFrameworkProvider.java in  » IDE-Netbeans » visualweb.api.designer » org » netbeans » modules » visualweb » project » jsf » framework » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » visualweb.api.designer » org.netbeans.modules.visualweb.project.jsf.framework 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.visualweb.project.jsf.framework;
043:
044:        import org.netbeans.modules.visualweb.project.jsf.api.JsfProjectConstants;
045:        import org.netbeans.modules.visualweb.project.jsf.api.ProjectTemplate;
046:        import org.netbeans.modules.visualweb.project.jsf.api.JsfProjectUtils;
047:
048:        import java.io.File;
049:        import java.io.FileNotFoundException;
050:        import java.io.IOException;
051:        import java.math.BigInteger;
052:        import java.util.HashSet;
053:        import java.util.Set;
054:        import java.util.HashMap;
055:        import java.util.ArrayList;
056:        import java.beans.PropertyChangeListener;
057:        import java.beans.PropertyChangeEvent;
058:        import java.util.logging.Level;
059:        import java.util.logging.Logger;
060:        import org.netbeans.api.java.classpath.ClassPath;
061:        import org.netbeans.modules.j2ee.dd.api.common.InitParam;
062:        import org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException;
063:        import org.netbeans.modules.j2ee.dd.api.web.*;
064:        import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
065:        import org.netbeans.modules.web.api.webmodule.ExtenderController;
066:        import org.netbeans.modules.web.spi.webmodule.WebModuleExtender;
067:        import org.openide.filesystems.FileObject;
068:        import org.openide.filesystems.FileSystem;
069:        import org.openide.filesystems.FileUtil;
070:        import org.netbeans.api.project.FileOwnerQuery;
071:        import org.netbeans.api.project.Project;
072:        import org.netbeans.api.project.ProjectManager;
073:        import org.netbeans.api.project.libraries.Library;
074:        import org.netbeans.api.project.libraries.LibraryManager;
075:        import org.netbeans.modules.web.spi.webmodule.WebFrameworkProvider;
076:        import org.netbeans.modules.web.api.webmodule.WebModule;
077:        import org.netbeans.modules.web.jsf.api.ConfigurationUtils;
078:        import org.netbeans.modules.web.jsf.api.facesmodel.JSFConfigModel;
079:        import org.netbeans.modules.web.jsf.api.facesmodel.JSFConfigComponentFactory;
080:        import org.netbeans.modules.web.jsf.api.facesmodel.Application;
081:        import org.netbeans.modules.web.jsf.api.facesmodel.LocaleConfig;
082:        import org.netbeans.modules.web.jsf.api.facesmodel.DefaultLocale;
083:        import org.netbeans.modules.web.jsf.api.facesmodel.SupportedLocale;
084:        import org.openide.util.NbBundle;
085:        import org.openide.loaders.DataObject;
086:        import org.openide.cookies.OpenCookie;
087:        import java.util.Locale;
088:
089:        /**
090:         *
091:         * @author Po-Ting Wu
092:         */
093:        public class JSFFrameworkProvider extends WebFrameworkProvider {
094:
095:            private static final Logger LOGGER = Logger
096:                    .getLogger(JSFFrameworkProvider.class.getName());
097:
098:            private static final String RESOURCE_FOLDER = "org/netbeans/modules/web/jsf/resources/"; //NOI18N
099:
100:            private static final String FACES_STATE_SAVING_METHOD = "javax.faces.STATE_SAVING_METHOD"; // NOI18N
101:            private static final String FACES_VALIDATE_XML = "com.sun.faces.validateXml"; // NOI18N
102:            private static final String FACES_VERIFY_OBJECTS = "com.sun.faces.verifyObjects"; // NOI18N
103:
104:            private static final String DEFAULT_LOCALE = Locale.getDefault()
105:                    .toString(); // NOI18N
106:            private static final String[] SUPPORTED_LOCALES = { "en", // NOI18N
107:                    "ja", // NOI18N
108:                    "zh_CN", // NOI18N
109:                    "pt_BR", // NOI18N
110:            };
111:
112:            private JSFConfigurationPanel panel;
113:
114:            /** Creates a new instance of JSFFrameworkProvider */
115:            public JSFFrameworkProvider() {
116:                super (NbBundle.getMessage(JSFFrameworkProvider.class,
117:                        "JSF_Name"), // NOI18N
118:                        NbBundle.getMessage(JSFFrameworkProvider.class,
119:                                "JSF_Description")); //NOI18N
120:            }
121:
122:            // not named extend() so as to avoid implementing WebFrameworkProvider.extend()
123:            // better to move this to JSFConfigurationPanel
124:            Set extendImpl(WebModule webModule) {
125:                final FileObject fileObject = webModule.getDocumentBase();
126:                final Project project = FileOwnerQuery.getOwner(fileObject);
127:                final ProjectTemplate template = new JsfProjectTemplate();
128:                Set result = new HashSet();
129:
130:                // Set Bean Package and Start Page
131:                String presetPackage = JsfProjectUtils.getProjectProperty(
132:                        project, JsfProjectConstants.PROP_JSF_PAGEBEAN_PACKAGE);
133:                if (presetPackage == null || presetPackage.length() == 0) {
134:                    presetPackage = panel.getBeanPackage();
135:                    JsfProjectUtils.createProjectProperty(project,
136:                            JsfProjectConstants.PROP_JSF_PAGEBEAN_PACKAGE,
137:                            presetPackage);
138:                }
139:                template.setBeanPackage(presetPackage);
140:
141:                String presetName = JsfProjectUtils.getProjectProperty(project,
142:                        JsfProjectConstants.PROP_START_PAGE);
143:                if (presetName == null || presetName.length() == 0) {
144:                    presetName = "Page1.jsp"; // NOI18N
145:                } else if (JsfProjectConstants.NO_START_PAGE.equals(presetName)) {
146:                    presetName = ""; // NOI18N
147:                }
148:                final String pageName = presetName;
149:                JsfProjectUtils.createProjectProperty(project,
150:                        JsfProjectConstants.PROP_START_PAGE, pageName);
151:                JsfProjectUtils.setProjectVersion(project, "4.0"); // NOI18N
152:
153:                fireChange(project);
154:
155:                // Create Visual Web files
156:                ProjectManager.mutex().postReadRequest(new Runnable() {
157:                    public void run() {
158:                        try {
159:                            project.getProjectDirectory().setAttribute(
160:                                    "NewProject", Boolean.TRUE); // NOI18N
161:                            template.create(project, pageName);
162:                        } catch (IOException ioe) {
163:                            LOGGER
164:                                    .log(
165:                                            Level.WARNING,
166:                                            "Exception during extending an web project",
167:                                            ioe); //NOI18N
168:                        }
169:                    }
170:                });
171:
172:                // <RAVE> Add the VWP libraries to the project
173:                try {
174:                    ClassPath cp = ClassPath.getClassPath(fileObject,
175:                            ClassPath.COMPILE);
176:                    boolean isMyFaces = cp
177:                            .findResource("org/apache/myfaces/webapp/StartupServletContextListener.class") != null; //NOI18N
178:                    if (!isMyFaces
179:                            && (cp
180:                                    .findResource("javax/faces/FacesException.class") == null)) { //NOI18N
181:                        try {
182:                            Library jsfLib = LibraryManager
183:                                    .getDefault()
184:                                    .getLibrary(
185:                                            JsfProjectUtils
186:                                                    .isJavaEE5Project(project) ? "jsf12"
187:                                                    : "jsf1102"); // NOI18N
188:                            if (jsfLib != null) {
189:                                JsfProjectUtils.addLibraryReferences(project,
190:                                        new Library[] {
191:                                                jsfLib,
192:                                                LibraryManager.getDefault()
193:                                                        .getLibrary("jstl11"), // NOI18N
194:                                        });
195:                            }
196:                        } catch (IOException ioExceptoin) {
197:                            LOGGER
198:                                    .log(
199:                                            Level.WARNING,
200:                                            "Exception during extending an web project",
201:                                            ioExceptoin); //NOI18N
202:                        }
203:                    }
204:
205:                    String srcLevel = JsfProjectUtils.getSourceLevel(project);
206:                    if ("1.3".equals(srcLevel) || "1.4".equals(srcLevel)) { // NOI18N
207:                        if (cp
208:                                .findResource("javax/sql/rowset/BaseRowSet.class") == null) { //NOI18N
209:                            // IDE doesn't have the Rowset RI support
210:                            Library libRowset = LibraryManager.getDefault()
211:                                    .getLibrary("rowset-ri"); // NOI18N
212:                            if (libRowset != null) {
213:                                try {
214:                                    JsfProjectUtils.addLibraryReferences(
215:                                            project,
216:                                            new Library[] { libRowset });
217:                                } catch (IOException ioExceptoin) {
218:                                    LOGGER
219:                                            .log(
220:                                                    Level.WARNING,
221:                                                    "Exception during extending an web project",
222:                                                    ioExceptoin); //NOI18N
223:                                }
224:                            }
225:                        }
226:                    }
227:
228:                    template.addLibrary(project);
229:
230:                    FileSystem fileSystem = webModule.getWebInf()
231:                            .getFileSystem();
232:                    fileSystem.runAtomicAction(new CreateFacesConfig(webModule,
233:                            isMyFaces, pageName));
234:
235:                    FileObject pagejsp = fileObject.getFileObject(pageName);
236:                    if (pagejsp != null) {
237:                        result.add(pagejsp);
238:                    } else {
239:                        // Page is not created yet, open later.
240:                        ProjectManager.mutex().postReadRequest(new Runnable() {
241:                            public void run() {
242:                                try {
243:                                    FileObject pagejsp = fileObject
244:                                            .getFileObject(pageName);
245:                                    if (pagejsp != null) {
246:                                        DataObject obj = DataObject
247:                                                .find(pagejsp);
248:                                        OpenCookie open = (OpenCookie) obj
249:                                                .getCookie(OpenCookie.class);
250:                                        if (open != null) {
251:                                            open.open();
252:                                        }
253:                                    }
254:                                } catch (IOException ioe) {
255:                                    LOGGER
256:                                            .log(
257:                                                    Level.WARNING,
258:                                                    "Exception during extending an web project",
259:                                                    ioe); //NOI18N
260:                                }
261:                            }
262:                        });
263:                    }
264:                } catch (FileNotFoundException exception) {
265:                    LOGGER.log(Level.WARNING,
266:                            "Exception during extending an web project",
267:                            exception); //NOI18N 
268:                } catch (IOException exception) {
269:                    LOGGER.log(Level.WARNING,
270:                            "Exception during extending an web project",
271:                            exception); //NOI18N
272:                }
273:                return result;
274:            }
275:
276:            public java.io.File[] getConfigurationFiles(
277:                    org.netbeans.modules.web.api.webmodule.WebModule wm) {
278:                // The JavaEE 5 introduce web modules without deployment descriptor. In such wm can not be jsf used.
279:                FileObject dd = wm.getDeploymentDescriptor();
280:                if (dd != null) {
281:                    FileObject[] filesFO = ConfigurationUtils
282:                            .getFacesConfigFiles(wm);
283:                    File[] files = new File[filesFO.length];
284:                    for (int i = 0; i < filesFO.length; i++)
285:                        files[i] = FileUtil.toFile(filesFO[i]);
286:                    if (files.length > 0)
287:                        return files;
288:                }
289:                return null;
290:            }
291:
292:            public WebModuleExtender createWebModuleExtender(
293:                    WebModule webModule, ExtenderController controller) {
294:                boolean defaultValue = (webModule == null || !isInWebModule(webModule));
295:                Project project = (webModule == null) ? null : FileOwnerQuery
296:                        .getOwner(webModule.getDeploymentDescriptor());
297:                panel = new JSFConfigurationPanel(this , project, controller,
298:                        !defaultValue);
299:
300:                // Default Bean Package
301:                if (project != null) {
302:                    panel.setBeanPackage(project.getProjectDirectory()
303:                            .getName());
304:                }
305:
306:                if (!defaultValue) {
307:                    // get configuration panel with values from the wm
308:                    Servlet servlet = ConfigurationUtils
309:                            .getFacesServlet(webModule);
310:                    panel.setServletName(servlet == null ? "Faces Servlet"
311:                            : servlet.getServletName()); // NOI18N
312:                    panel.setURLPattern(ConfigurationUtils
313:                            .getFacesServletMapping(webModule));
314:                    panel.setValidateXML(JSFConfigUtilities
315:                            .validateXML(webModule.getDeploymentDescriptor()));
316:                    panel
317:                            .setVerifyObjects(JSFConfigUtilities
318:                                    .verifyObjects(webModule
319:                                            .getDeploymentDescriptor()));
320:                }
321:
322:                return panel;
323:            }
324:
325:            public boolean isInWebModule(
326:                    org.netbeans.modules.web.api.webmodule.WebModule webModule) {
327:                FileObject documentBase = webModule.getDocumentBase();
328:                Project project = FileOwnerQuery.getOwner(documentBase);
329:                return JsfProjectUtils.isJsfProject(project);
330:            }
331:
332:            private class CreateFacesConfig implements  FileSystem.AtomicAction {
333:                WebModule webModule;
334:                boolean isMyFaces;
335:                String pageName;
336:
337:                public CreateFacesConfig(WebModule webModule,
338:                        boolean isMyFaces, String pageName) {
339:                    this .webModule = webModule;
340:                    this .isMyFaces = isMyFaces;
341:                    this .pageName = pageName;
342:                }
343:
344:                public void run() throws IOException {
345:                    // Enter servlet into the deployment descriptor
346:                    FileObject dd = webModule.getDeploymentDescriptor();
347:                    WebApp ddRoot = DDProvider.getDefault().getDDRoot(dd);
348:                    String j2eeLevel = webModule.getJ2eePlatformVersion();
349:                    if (ddRoot != null) {
350:                        try {
351:                            // Set the context parameter
352:                            InitParam facesSaving = null;
353:                            InitParam facesValidate = null;
354:                            InitParam facesVerify = null;
355:                            InitParam[] params = ddRoot.getContextParam();
356:                            for (int i = 0; i < params.length; i++) {
357:                                InitParam ip = params[i];
358:                                String name = ip.getParamName();
359:                                if (FACES_STATE_SAVING_METHOD.equals(name)) {
360:                                    facesSaving = ip;
361:                                } else if (FACES_VALIDATE_XML.equals(name)) {
362:                                    facesValidate = ip;
363:                                } else if (FACES_VERIFY_OBJECTS.equals(name)) {
364:                                    facesVerify = ip;
365:                                }
366:                            }
367:
368:                            if (facesSaving == null) {
369:                                facesSaving = (InitParam) ddRoot
370:                                        .createBean("InitParam"); // NOI18N
371:                                facesSaving
372:                                        .setParamName(FACES_STATE_SAVING_METHOD);
373:                                facesSaving.setParamValue("client"); // NOI18N
374:                                ddRoot.addContextParam(facesSaving);
375:                            }
376:
377:                            String value = (panel == null || panel
378:                                    .validateXML()) ? "true" : "false"; // NOI18N
379:                            if (facesValidate == null) {
380:                                facesValidate = (InitParam) ddRoot
381:                                        .createBean("InitParam"); //NOI18N
382:                                facesValidate.setParamName(FACES_VALIDATE_XML);
383:                                facesValidate.setParamValue(value);
384:                                ddRoot.addContextParam(facesValidate);
385:                            } else {
386:                                facesValidate.setParamValue(value);
387:                            }
388:
389:                            value = (panel == null || panel.verifyObjects()) ? "true"
390:                                    : "false"; // NOI18N
391:                            if (facesVerify == null) {
392:                                facesVerify = (InitParam) ddRoot
393:                                        .createBean("InitParam"); //NOI18N
394:                                facesVerify.setParamName(FACES_VERIFY_OBJECTS);
395:                                facesVerify.setParamValue(value);
396:                                ddRoot.addContextParam(facesVerify);
397:                            } else {
398:                                facesVerify.setParamValue(value);
399:                            }
400:
401:                            String facesServletName = panel == null ? "Faces Servlet"
402:                                    : panel.getServletName(); // NOI18N
403:                            String facesMapping = panel == null ? "faces/*"
404:                                    : panel.getURLPattern(); // NOI18N
405:
406:                            // The UpLoad Filter
407:                            Filter filter;
408:                            InitParam contextParam;
409:                            boolean hasUploadFilter = false;
410:                            Filter[] filters = ddRoot.getFilter();
411:                            for (int i = 0; i < filters.length; i++) {
412:                                filter = filters[i];
413:                                if ("UploadFilter".equals(filter
414:                                        .getFilterName())) {
415:                                    hasUploadFilter = true;
416:                                    break;
417:                                }
418:                            }
419:
420:                            if (!hasUploadFilter) {
421:                                filter = (Filter) ddRoot.createBean("Filter"); // NOI18N
422:                                filter.setFilterName("UploadFilter"); // NOI18N
423:                                if (J2eeModule.JAVA_EE_5.equals(j2eeLevel))
424:                                    filter
425:                                            .setFilterClass("com.sun.webui.jsf.util.UploadFilter"); // NOI18N
426:                                else
427:                                    filter
428:                                            .setFilterClass("com.sun.rave.web.ui.util.UploadFilter"); // NOI18N
429:
430:                                contextParam = (InitParam) filter
431:                                        .createBean("InitParam"); // NOI18N
432:                                contextParam
433:                                        .setDescription("The maximum allowed upload size in bytes.  If this is set "
434:                                                + "to a negative value, there is no maximum.  The default "
435:                                                + "value is 1000000."); // NOI18N
436:                                contextParam.setParamName("maxSize"); // NOI18N
437:                                contextParam.setParamValue("1000000"); // NOI18N
438:                                filter.addInitParam(contextParam);
439:
440:                                contextParam = (InitParam) filter
441:                                        .createBean("InitParam"); // NOI18N
442:                                contextParam
443:                                        .setDescription("The size (in bytes) of an uploaded file which, if it is "
444:                                                + "exceeded, will cause the file to be written directly to "
445:                                                + "disk instead of stored in memory.  Files smaller than or "
446:                                                + "equal to this size will be stored in memory.  The default "
447:                                                + "value is 4096."); // NOI18N
448:                                contextParam.setParamName("sizeThreshold"); // NOI18N
449:                                contextParam.setParamValue("4096"); // NOI18N
450:                                filter.addInitParam(contextParam);
451:                                ddRoot.addFilter(filter);
452:
453:                                FilterMapping filterMapping = (FilterMapping) ddRoot
454:                                        .createBean("FilterMapping"); // NOI18N
455:                                filterMapping.setFilterName("UploadFilter"); // NOI18N
456:                                filterMapping.setServletName(facesServletName);
457:                                ddRoot.addFilterMapping(filterMapping);
458:                            }
459:
460:                            // The Servlets
461:                            Servlet servlet;
462:                            boolean hasFacesServlet = false;
463:                            boolean hasExceptionServlet = false;
464:                            boolean hasThemeServlet = false;
465:                            Servlet[] servlets = ddRoot.getServlet();
466:                            for (int i = 0; i < servlets.length; i++) {
467:                                servlet = servlets[i];
468:                                String name = servlet.getServletName();
469:                                if (facesServletName.equals(name)) {
470:                                    hasFacesServlet = true;
471:                                } else if ("ExceptionHandlerServlet"
472:                                        .equals(name)) {
473:                                    hasExceptionServlet = true;
474:                                } else if ("ThemeServlet".equals(name)) {
475:                                    hasThemeServlet = true;
476:                                }
477:                            }
478:
479:                            if (!hasFacesServlet) {
480:                                servlet = (Servlet) ddRoot
481:                                        .createBean("Servlet"); // NOI18N
482:                                servlet.setServletName(facesServletName);
483:                                servlet
484:                                        .setServletClass("javax.faces.webapp.FacesServlet"); // NOI18N    
485:                                if (J2eeModule.JAVA_EE_5.equals(j2eeLevel)) {
486:                                    contextParam = (InitParam) servlet
487:                                            .createBean("InitParam"); // NOI18N
488:                                    contextParam
489:                                            .setParamName("javax.faces.LIFECYCLE_ID"); // NOI18N
490:                                    contextParam
491:                                            .setParamValue("com.sun.faces.lifecycle.PARTIAL"); // NOI18N
492:                                    servlet.addInitParam(contextParam);
493:                                }
494:                                servlet.setLoadOnStartup(new BigInteger("1"));// NOI18N
495:                                ddRoot.addServlet(servlet);
496:                            }
497:
498:                            if (!hasExceptionServlet) {
499:                                servlet = (Servlet) ddRoot
500:                                        .createBean("Servlet"); // NOI18N
501:                                servlet
502:                                        .setServletName("ExceptionHandlerServlet");
503:                                servlet
504:                                        .setServletClass("com.sun.errorhandler.ExceptionHandler"); // NOI18N    
505:
506:                                contextParam = (InitParam) servlet
507:                                        .createBean("InitParam"); // NOI18N
508:                                contextParam.setParamName("errorHost"); // NOI18N
509:                                contextParam.setParamValue("localhost"); // NOI18N
510:                                servlet.addInitParam(contextParam);
511:
512:                                contextParam = (InitParam) servlet
513:                                        .createBean("InitParam"); // NOI18N
514:                                contextParam.setParamName("errorPort"); // NOI18N
515:                                contextParam.setParamValue("24444"); // NOI18N
516:                                servlet.addInitParam(contextParam);
517:
518:                                ddRoot.addServlet(servlet);
519:                            }
520:
521:                            if (!hasThemeServlet) {
522:                                servlet = (Servlet) ddRoot
523:                                        .createBean("Servlet"); // NOI18N
524:                                servlet.setServletName("ThemeServlet"); // NOI18N
525:
526:                                if (J2eeModule.JAVA_EE_5.equals(j2eeLevel))
527:                                    servlet
528:                                            .setServletClass("com.sun.webui.theme.ThemeServlet"); // NOI18N
529:                                else
530:                                    servlet
531:                                            .setServletClass("com.sun.rave.web.ui.theme.ThemeServlet"); // NOI18N
532:
533:                                ddRoot.addServlet(servlet);
534:                            }
535:
536:                            // The Servlet Mappings
537:                            ServletMapping mapping;
538:                            boolean hasFacesPattern = false;
539:                            ServletMapping[] maps = ddRoot.getServletMapping();
540:                            for (int i = 0; i < maps.length; i++) {
541:                                mapping = maps[i];
542:                                if (facesServletName.equals(mapping
543:                                        .getServletName())
544:                                        && facesMapping.equals(mapping
545:                                                .getUrlPattern())) {
546:                                    hasFacesPattern = true;
547:                                }
548:                            }
549:
550:                            if (!hasFacesPattern) {
551:                                mapping = (ServletMapping) ddRoot
552:                                        .createBean("ServletMapping"); // NOI18N
553:                                mapping.setServletName(facesServletName);
554:                                mapping.setUrlPattern(facesMapping);
555:                                ddRoot.addServletMapping(mapping);
556:                            }
557:
558:                            mapping = (ServletMapping) ddRoot
559:                                    .createBean("ServletMapping"); // NOI18N
560:                            mapping.setServletName("ExceptionHandlerServlet");
561:                            mapping.setUrlPattern("/error/ExceptionHandler");
562:                            ddRoot.addServletMapping(mapping);
563:
564:                            mapping = (ServletMapping) ddRoot
565:                                    .createBean("ServletMapping"); // NOI18N
566:                            mapping.setServletName("ThemeServlet"); // NOI18N
567:                            mapping.setUrlPattern("/theme/*"); // NOI18N
568:                            ddRoot.addServletMapping(mapping);
569:
570:                            // add welcome file
571:                            JsfProjectUtils.setWelcomeFile(webModule, ddRoot,
572:                                    facesMapping, pageName);
573:
574:                            // Catch ServletException
575:                            ErrorPage errorPage = (ErrorPage) ddRoot
576:                                    .createBean("ErrorPage");
577:                            errorPage
578:                                    .setExceptionType("javax.servlet.ServletException");
579:                            errorPage.setLocation("/error/ExceptionHandler");
580:                            ddRoot.addErrorPage(errorPage);
581:
582:                            // Catch IOException
583:                            errorPage = (ErrorPage) ddRoot
584:                                    .createBean("ErrorPage");
585:                            errorPage.setExceptionType("java.io.IOException");
586:                            errorPage.setLocation("/error/ExceptionHandler");
587:                            ddRoot.addErrorPage(errorPage);
588:
589:                            // Catch FacesException
590:                            errorPage = (ErrorPage) ddRoot
591:                                    .createBean("ErrorPage");
592:                            errorPage
593:                                    .setExceptionType("javax.faces.FacesException");
594:                            errorPage.setLocation("/error/ExceptionHandler");
595:                            ddRoot.addErrorPage(errorPage);
596:
597:                            // Catch ApplicationException
598:                            errorPage = (ErrorPage) ddRoot
599:                                    .createBean("ErrorPage");
600:                            errorPage
601:                                    .setExceptionType("com.sun.rave.web.ui.appbase.ApplicationException");
602:                            errorPage.setLocation("/error/ExceptionHandler");
603:                            ddRoot.addErrorPage(errorPage);
604:
605:                            // The JSP Configuration
606:                            if (!J2eeModule.J2EE_13.equals(j2eeLevel)) {
607:                                try {
608:                                    JspConfig jspConfig = ddRoot
609:                                            .getSingleJspConfig();
610:                                    if (jspConfig == null) {
611:                                        jspConfig = (JspConfig) ddRoot
612:                                                .createBean("JspConfig"); // NOI18N
613:                                        ddRoot.addJspConfig(jspConfig);
614:                                    }
615:
616:                                    JspPropertyGroup jspGroup = (JspPropertyGroup) jspConfig
617:                                            .createBean("JspPropertyGroup"); // NOI18N
618:                                    jspGroup.addUrlPattern("*.jspf");
619:                                    jspGroup.setIsXml(true);
620:                                    jspConfig.addJspPropertyGroup(jspGroup);
621:                                } catch (VersionNotSupportedException e) {
622:                                    // already exclude J2EE 1.3 project here
623:                                }
624:                            }
625:
626:                            if (isMyFaces) {
627:                                Listener facesListener = (Listener) ddRoot
628:                                        .createBean("Listener"); // NOI18N
629:                                facesListener
630:                                        .setListenerClass("org.apache.myfaces.webapp.StartupServletContextListener"); // NOI18N
631:                                ddRoot.addListener(facesListener);
632:                            }
633:                            ddRoot.write(dd);
634:
635:                        } catch (ClassNotFoundException cnfe) {
636:                            LOGGER.log(Level.WARNING,
637:                                    "Exception in JSFMoveClassPlugin", cnfe); //NOI18N
638:                        }
639:                    }
640:
641:                    // copy faces-config.xml
642:                    File fileConfig = new File(FileUtil.toFile(webModule
643:                            .getWebInf()), "faces-config.xml"); // NOI18N
644:                    if (!fileConfig.exists()) {
645:                        String facesConfigTemplate = "faces-config.xml"; //NOI18N
646:                        if (ddRoot != null) {
647:                            if (WebApp.VERSION_2_5.equals(ddRoot.getVersion())) {
648:                                facesConfigTemplate = "faces-config_1_2.xml"; //NOI18N
649:                            }
650:                        }
651:                        String content = JsfProjectUtils.readResource(Thread
652:                                .currentThread().getContextClassLoader()
653:                                .getResourceAsStream(
654:                                        RESOURCE_FOLDER + facesConfigTemplate),
655:                                "UTF-8"); //NOI18N
656:                        FileObject target = FileUtil.createData(webModule
657:                                .getWebInf(), "faces-config.xml");//NOI18N
658:                        JsfProjectUtils.createFile(target, content, "UTF-8"); //NOI18N
659:                    }
660:
661:                    // set locale in faces-config.xml
662:                    /* Not ready yet, comment out for issue#118937, Tutorial: Currency converter fails
663:                    final FileObject facesConfig = FileUtil.toFileObject(fileConfig);
664:                    if (facesConfig != null) {
665:                        ProjectManager.mutex().postReadRequest(new Runnable() {
666:                            public void run() {
667:                                JSFConfigModel facesModel = ConfigurationUtils.getConfigModel(facesConfig, true);
668:                                if (facesModel != null) {
669:                                    facesModel.startTransaction();
670:                                    JSFConfigComponentFactory facesFactory = facesModel.getFactory();
671:                                    LocaleConfig newLocale = facesFactory.createLocaleConfig();
672:                    
673:                                    DefaultLocale defaultLC = facesFactory.createDefatultLocale();
674:                                    defaultLC.setLocale(DEFAULT_LOCALE);
675:                                    newLocale.setDefaultLocale(defaultLC);
676:                    
677:                                    for (String locale : SUPPORTED_LOCALES) {
678:                                        SupportedLocale supportedLC = facesFactory.createSupportedLocale();
679:                                        supportedLC.setLocale(locale);
680:                                        newLocale.addSupportedLocales(supportedLC);
681:                                    }
682:                    
683:                                    Application newApplication = facesFactory.createApplication();
684:                                    facesModel.getRootComponent().addApplication(newApplication);
685:                                    newApplication.addLocaleConfig(newLocale);
686:                                    facesModel.endTransaction();
687:
688:                                    try {
689:                                        facesModel.sync();
690:                                    } catch (IOException ioe) {
691:                                        LOGGER.log(Level.WARNING, "Exception during setting locale in faces-config.xml", ioe); //NOI18N
692:                                    }
693:                                }
694:                            }
695:                        }); 
696:                    }
697:                     */
698:                }
699:            }
700:
701:            private HashMap propertyListeners = new HashMap();
702:
703:            private void fireChange(Project project) {
704:                PropertyChangeEvent event = new PropertyChangeEvent(project,
705:                        null, null, null);
706:
707:                PropertyChangeListener[] listeners;
708:                synchronized (propertyListeners) {
709:                    ArrayList projectListeners = (ArrayList) propertyListeners
710:                            .get(project);
711:                    if (projectListeners == null) {
712:                        return;
713:                    }
714:                    listeners = (PropertyChangeListener[]) projectListeners
715:                            .toArray(new PropertyChangeListener[propertyListeners
716:                                    .size()]);
717:                }
718:                for (int i = 0; i < listeners.length; i++) {
719:                    PropertyChangeListener listener = listeners[i];
720:                    if (listener != null) {
721:                        listener.propertyChange(event);
722:                    }
723:                }
724:            }
725:
726:            public void addPropertyChangeListener(Project project,
727:                    PropertyChangeListener listener) {
728:                synchronized (propertyListeners) {
729:                    ArrayList projectListeners = (ArrayList) propertyListeners
730:                            .get(project);
731:                    if (projectListeners == null) {
732:                        projectListeners = new ArrayList();
733:                        propertyListeners.put(project, projectListeners);
734:                    }
735:                    projectListeners.add(listener);
736:                }
737:            }
738:
739:            public void removePropertyChangeListener(Project project,
740:                    PropertyChangeListener listener) {
741:                synchronized (propertyListeners) {
742:                    ArrayList projectListeners = (ArrayList) propertyListeners
743:                            .get(project);
744:                    if (projectListeners != null) {
745:                        projectListeners.remove(listener);
746:                    }
747:                }
748:            }
749:        }
w___w__w_.j_av_a___2_s._com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.