Source Code Cross Referenced for JsfJspDataObject.java in  » IDE-Netbeans » visualweb.api.designer » org » netbeans » modules » visualweb » project » jsfloader » 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.jsfloader 
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.jsfloader;
043:
044:        import java.beans.PropertyVetoException;
045:        import java.io.IOException;
046:        import java.io.OutputStream;
047:        import java.io.PrintStream;
048:        import java.lang.reflect.Method;
049:        import java.util.HashMap;
050:        import java.util.Map;
051:        import java.nio.charset.Charset;
052:        import java.nio.charset.IllegalCharsetNameException;
053:        import java.nio.charset.UnsupportedCharsetException;
054:        import java.util.logging.Level;
055:        import java.util.logging.Logger;
056:
057:        import javax.xml.parsers.DocumentBuilder;
058:        import javax.xml.parsers.DocumentBuilderFactory;
059:        import javax.xml.parsers.ParserConfigurationException;
060:
061:        import org.netbeans.api.project.FileOwnerQuery;
062:        import org.netbeans.api.project.Project;
063:        import org.netbeans.modules.web.core.jsploader.api.TagLibParseCookie;
064:        import org.netbeans.modules.web.core.jsploader.api.TagLibParseFactory;
065:
066:        import org.openide.ErrorManager;
067:        import org.openide.awt.HtmlBrowser;
068:        import org.openide.cookies.EditCookie;
069:        import org.openide.cookies.OpenCookie;
070:        import org.openide.cookies.SaveCookie;
071:        import org.openide.filesystems.*;
072:        import org.openide.loaders.*;
073:        import org.openide.nodes.*;
074:        import org.openide.util.*;
075:        import org.openide.xml.XMLUtil;
076:        import org.openide.cookies.ViewCookie;
077:        import org.w3c.dom.Document;
078:        import org.w3c.dom.NamedNodeMap;
079:        import org.w3c.dom.NodeList;
080:        import org.xml.sax.SAXException;
081:
082:        import org.netbeans.modules.visualweb.api.insync.InSyncService;
083:        import org.netbeans.modules.visualweb.api.insync.JsfJspDataObjectMarker;
084:        import org.netbeans.modules.visualweb.project.jsf.api.JsfDataObjectException;
085:        import org.netbeans.modules.visualweb.project.jsf.api.JsfProjectUtils;
086:        import org.openide.util.lookup.Lookups;
087:        import org.openide.util.lookup.ProxyLookup;
088:
089:        /** Object that represents one JSP file which has corresponding java file.
090:         *
091:         * @author  Peter Zavadsky
092:         * @author  Tor Norbye (the strange designer stuff)
093:         * @author  Mark Dey (the strange start page stuff)
094:         */
095:        public class JsfJspDataObject extends MultiDataObject implements 
096:                CookieSet.Factory, JsfJspDataObjectMarker {
097:
098:            static final long serialVersionUID = 8354927561693097159L;
099:
100:            static final String JSF_ATTRIBUTE = "jsfjsp"; // NOI18N
101:            private static final String JSP_ICON_BASE = "org/netbeans/modules/visualweb/project/jsfloader/resources/jsfJspObject.png"; // NOI18N
102:            static final String PROP_ENCODING = "encoding"; // NOI18N
103:            private static final String PROP_CUSTOM_TEMPLATE = "custom-template"; // NOI18N
104:            private static final String DEFAULT_ENCODING = "UTF-8"; // NOI18N
105:
106:            private transient OpenEdit openEdit;
107:            private transient Lookup currentLookup;
108:
109:            /** New instance.
110:             * @param pf primary file object for this data object
111:             * @param loader the data loader creating it
112:             * @exception DataObjectExistsException if there was already a data object for it
113:             */
114:            public JsfJspDataObject(FileObject primaryFile, UniFileLoader loader)
115:                    throws DataObjectExistsException {
116:                super (primaryFile, loader);
117:                CookieSet set = getCookieSet();
118:
119:                set.add(OpenCookie.class, this );
120:                set.add(EditCookie.class, this );
121:                set.add(JsfJspEditorSupport.class, this );
122:                set.add(ViewSupport.class, this );
123:                set.add(TagLibParseCookie.class, this );
124:
125:                createLookup();
126:            }
127:
128:            private void createLookup() {
129:                Lookup noEncodingLookup = super .getLookup();
130:
131:                org.netbeans.spi.queries.FileEncodingQueryImplementation feq = new org.netbeans.spi.queries.FileEncodingQueryImplementation() {
132:
133:                    public Charset getEncoding(FileObject file) {
134:                        assert file != null;
135:                        assert file.equals(getPrimaryFile());
136:
137:                        String charsetName = getFileEncoding();
138:                        try {
139:                            return Charset.forName(charsetName);
140:                        } catch (IllegalCharsetNameException ichse) {
141:                            //the jsp templates contains the ${encoding} property 
142:                            //so the ICHNE is always thrown for them, just ignore
143:                            Boolean template = (Boolean) file
144:                                    .getAttribute("template");//NOI18N
145:                            if (template == null || !template.booleanValue()) {
146:                                Logger.getLogger("global").log(
147:                                        Level.INFO,
148:                                        "Detected illegal charset name in file "
149:                                                + file.getNameExt() + " ("
150:                                                + ichse.getMessage() + ")");
151:                            }
152:                        } catch (UnsupportedCharsetException uchse) {
153:                            Logger.getLogger("global").log(
154:                                    Level.INFO,
155:                                    "Detected unsupported charset name in file "
156:                                            + file.getNameExt() + " ("
157:                                            + uchse.getMessage() + ")");
158:                        }
159:
160:                        return null;
161:                    }
162:                };
163:
164:                currentLookup = new ProxyLookup(noEncodingLookup, Lookups
165:                        .singleton(feq));
166:            }
167:
168:            @Override
169:            protected Node createNodeDelegate() {
170:                DataNode n = new JsfJspDataNode(this , Children.LEAF);
171:                n.setIconBaseWithExtension(JSP_ICON_BASE);
172:                return n;
173:            }
174:
175:            @Override
176:            public HelpCtx getHelpCtx() {
177:                return new HelpCtx(
178:                        "org.netbeans.modules.visualweb.project.jsfloader.JsfJspDataLoader"
179:                                + ".Obj"); // NOI18N
180:            }
181:
182:            /** Creates new Cookie */
183:            public <T extends Node.Cookie> T createCookie(Class<T> klass) {
184:                if (OpenCookie.class.equals(klass)
185:                        || EditCookie.class.equals(klass)) {
186:                    if (openEdit == null) {
187:                        openEdit = new OpenEdit();
188:                    }
189:                    return klass.cast(openEdit);
190:                } else if (JsfJspEditorSupport.class.isAssignableFrom(klass)) {
191:                    return klass.cast(getJsfJspEditorSupport());
192:                } else if (ViewSupport.class.isAssignableFrom(klass)) {
193:                    return klass.cast(new ViewSupport(getPrimaryEntry()));
194:                } else if (TagLibParseCookie.class.isAssignableFrom(klass)) {
195:                    return klass.cast(TagLibParseFactory
196:                            .createTagLibParseCookie(getPrimaryFile()));
197:                } else {
198:                    return null;
199:                }
200:            }
201:
202:            // Package accessibility for JsfJspEditorSupport:
203:            CookieSet getCookieSet0() {
204:                return getCookieSet();
205:            }
206:
207:            @Override
208:            public Lookup getLookup() {
209:                return currentLookup;
210:            }
211:
212:            /** Gets the superclass cookie, without hacking save cookie. */
213:            <T extends Node.Cookie> T getPureCookie(Class<T> clazz) {
214:                return super .getCookie(clazz);
215:            }
216:
217:            /** Overrides behaviour to provide compound save cookie. */
218:            @Override
219:            public <T extends Node.Cookie> T getCookie(Class<T> clazz) {
220:                if (clazz == SaveCookie.class) {
221:                    FileObject primaryJavaFileObject = Utils
222:                            .findJavaForJsp(getPrimaryFile());
223:                    if (primaryJavaFileObject != null
224:                            && primaryJavaFileObject.isValid()) {
225:                        SaveCookie jspSaveCookie = (SaveCookie) super 
226:                                .getCookie(clazz);
227:                        JsfJavaDataObject jsfJavaDataObject = Utils
228:                                .findCorrespondingJsfJavaDataObject(
229:                                        getPrimaryFile(), false);
230:                        SaveCookie javaSaveCookie;
231:                        if (jsfJavaDataObject == null) {
232:                            javaSaveCookie = null;
233:                        } else {
234:                            javaSaveCookie = (SaveCookie) jsfJavaDataObject
235:                                    .getPureCookie(clazz);
236:                        }
237:
238:                        if (jspSaveCookie == null && javaSaveCookie == null) {
239:                            return null;
240:                        } else {
241:                            return clazz.cast(new CompoundSaveCookie(
242:                                    jspSaveCookie, javaSaveCookie));
243:                        }
244:                    }
245:                } else {
246:                    // XXX NB #80853 Fix the cookie creation when referred by impl classes.
247:                    if (TagLibParseCookie.class.isAssignableFrom(clazz)) {
248:                        return clazz.cast(super 
249:                                .getCookie(TagLibParseCookie.class));
250:                    }
251:                }
252:
253:                return super .getCookie(clazz);
254:            }
255:
256:            private transient JsfJspEditorSupport jsfJspEditorSupport;
257:
258:            private static final Object LOCK_JSF_JSP_EDITOR = new Object();
259:
260:            private JsfJspEditorSupport getJsfJspEditorSupport() {
261:                synchronized (LOCK_JSF_JSP_EDITOR) {
262:                    if (jsfJspEditorSupport == null) {
263:                        jsfJspEditorSupport = new JsfJspEditorSupport(this );
264:                    }
265:
266:                    return jsfJspEditorSupport;
267:                }
268:            }
269:
270:            private class OpenEdit implements  OpenCookie, EditCookie {
271:                public void open() {
272:                    String attr = getAttribute();
273:                    if ((attr != null && attr
274:                            .equals(JsfJavaEditorSupport.MV_ID_DESIGNER))
275:                            || attr == null) {
276:                        getJsfJspEditorSupport().openDesigner();
277:                    } else {
278:                        getJsfJspEditorSupport().editJsp();
279:                    }
280:                }
281:
282:                public void edit() {
283:                    String attr = getAttribute();
284:                    if (attr != null
285:                            && attr.equals(JsfJavaEditorSupport.MV_ID_DESIGNER)) {
286:                        getJsfJspEditorSupport().openDesigner();
287:                    } else {
288:                        getJsfJspEditorSupport().editJsp();
289:                    }
290:                }
291:
292:                private String getAttribute() {
293:                    try {
294:                        String attr = (String) getPrimaryFile().getAttribute(
295:                                OpenEditOverride.MULTIVIEW_ATTRIBUTE);
296:                        getPrimaryFile().setAttribute(
297:                                OpenEditOverride.MULTIVIEW_ATTRIBUTE, null);
298:                        return attr;
299:                    } catch (IOException ex) {
300:                    }
301:                    return null;
302:                }
303:
304:            }
305:
306:            private static final class ViewSupport implements  ViewCookie {
307:                /** entry */
308:                private MultiDataObject.Entry primary;
309:
310:                /** Constructs new ViewSupport */
311:                public ViewSupport(MultiDataObject.Entry primary) {
312:                    this .primary = primary;
313:                }
314:
315:                public void view() {
316:                    try {
317:                        HtmlBrowser.URLDisplayer.getDefault().showURL(
318:                                primary.getFile().getURL());
319:                    } catch (FileStateInvalidException fsie) {
320:                        ErrorManager.getDefault().notify(
321:                                ErrorManager.INFORMATIONAL, fsie);
322:                    }
323:                }
324:            }
325:
326:            // this is just a flag for obtaining encoding at first time.
327:            private boolean isEncodingRetrieved = false;
328:
329:            public String getFileEncoding() {
330:                if (!isEncodingRetrieved) {
331:                    updateFileEncoding(false);
332:                    isEncodingRetrieved = true;
333:                }
334:                String retrievedEncoding = (String) getPrimaryFile()
335:                        .getAttribute(PROP_ENCODING);
336:                retrievedEncoding = retrievedEncoding != null ? retrievedEncoding
337:                        : DEFAULT_ENCODING;
338:
339:                return retrievedEncoding;
340:            }
341:
342:            void updateFileEncoding(boolean fromEditor) {
343:                // VW templates are not valid JSP files, so skip the encoding step
344:                if (isTemplate()) {
345:                    return;
346:                }
347:
348:                TagLibParseCookie tlps = getCookie(TagLibParseCookie.class);
349:                if (tlps != null) {
350:                    String encoding = tlps.getOpenInfo(true, fromEditor)
351:                            .getEncoding();
352:                    try {
353:                        getPrimaryFile().setAttribute(PROP_ENCODING, encoding);
354:                    } catch (IOException e) {
355:                        ErrorManager.getDefault().notify(ErrorManager.WARNING,
356:                                e);
357:                    }
358:                }
359:            }
360:
361:            private static final ThreadLocal<Boolean> pureCopy = new ThreadLocal<Boolean>();
362:
363:            /** Copies only this object without touching the corresponding jsf jsp one.
364:             * Used when copying originated form corresponding file. */
365:            void pureCopy(DataFolder folder) throws IOException {
366:                try {
367:                    pureCopy.set(Boolean.TRUE);
368:                    copy(folder);
369:                } finally {
370:                    pureCopy.set(Boolean.FALSE);
371:                }
372:            }
373:
374:            private class MarkupVisitor {
375:                private String oldName;
376:                private String newName;
377:
378:                MarkupVisitor(String oldName, String newName) {
379:                    this .oldName = oldName;
380:                    this .newName = newName;
381:                }
382:
383:                public void apply(org.w3c.dom.Node node) {
384:                    visit(node);
385:                    NamedNodeMap atts = node.getAttributes();
386:                    if (atts != null) {
387:                        int attc = atts.getLength();
388:                        for (int i = 0; i < attc; i++)
389:                            apply(atts.item(i));
390:                    }
391:                    NodeList kids = node.getChildNodes();
392:                    int kidc = kids.getLength();
393:                    for (int i = 0; i < kidc; i++)
394:                        apply(kids.item(i));
395:                }
396:
397:                private void visit(org.w3c.dom.Node node) {
398:                    if (node.getNodeType() == org.w3c.dom.Node.ATTRIBUTE_NODE) {
399:                        String attrValue = node.getNodeValue();
400:                        String newval = update(attrValue);
401:                        if (newval != null)
402:                            node.setNodeValue(newval);
403:                    }
404:                }
405:
406:                private String update(String attrValue) {
407:                    if (attrValue.startsWith("#{") && attrValue.endsWith("}")) {
408:                        return "${pound}" + updateName(attrValue.substring(1));
409:                    } else {
410:                        return null;
411:                    }
412:                }
413:
414:                private String updateName(String attrValue) {
415:                    if (attrValue.startsWith("{" + oldName + ".")
416:                            && attrValue.endsWith("}")) { //NOI18N
417:                        int dotAt = attrValue.indexOf(".");
418:                        if (dotAt != -1) {
419:                            String tail = attrValue.substring(dotAt, attrValue
420:                                    .length() - 1); // everything to the right
421:                            StringBuffer buf = new StringBuffer();
422:                            buf.append("{");
423:                            buf.append(newName);
424:                            buf.append(tail);
425:                            buf.append("}"); //NOI18N
426:                            return buf.toString();
427:                        }
428:                    }
429:                    return attrValue;
430:                }
431:            }
432:
433:            /** Handles copy. Handles also copy of corresponding jsf jsp file. */
434:            @Override
435:            protected DataObject handleCopy(DataFolder folder)
436:                    throws IOException {
437:                if (pureCopy.get() == Boolean.TRUE) {
438:                    return super .handleCopy(folder);
439:                } else {
440:                    FileObject javaFile = Utils
441:                            .findJavaForJsp(getPrimaryFile());
442:                    if (javaFile == null) {
443:                        throw new JsfDataObjectException(
444:                                "Can't find java file for " + this );
445:                    }
446:
447:                    DataObject dataObject = super .handleCopy(folder);
448:                    boolean doNormalEventNotify = false;
449:
450:                    // fix the name of the PageBean to __NAME__ if the destination is a Template folder.
451:                    if (folder.getPrimaryFile().getFileSystem().isDefault()) {
452:                        FileObject primaryFileObject = dataObject
453:                                .getPrimaryFile();
454:                        try {
455:                            DocumentBuilderFactory factory = DocumentBuilderFactory
456:                                    .newInstance();
457:                            factory.setNamespaceAware(true);
458:                            DocumentBuilder documentBuilder = factory
459:                                    .newDocumentBuilder();
460:                            Document document = documentBuilder
461:                                    .parse(primaryFileObject.getInputStream());
462:                            String beanName = Utils
463:                                    .getBeanNameForJsp(getPrimaryFile());
464:                            if (beanName == null) {
465:                                throw new JsfDataObjectException(
466:                                        "Got null bean name for "
467:                                                + getPrimaryFile());
468:                            }
469:                            MarkupVisitor markupVisitor = new MarkupVisitor(
470:                                    beanName, "${folder}${name}"); // NOI18N
471:                            markupVisitor.apply(document);
472:                            FileLock lock = primaryFileObject.lock();
473:                            try {
474:                                OutputStream os = primaryFileObject
475:                                        .getOutputStream(lock);
476:                                PrintStream ps = new PrintStream(os);
477:                                ps.println("<#assign pound = '#'>"); // NOI18N
478:                                XMLUtil.write(document, os, getFileEncoding()); // NOI18N
479:                            } finally {
480:                                lock.releaseLock();
481:                            }
482:
483:                            // set required attributes
484:                            primaryFileObject.setAttribute(PROP_ENCODING,
485:                                    getFileEncoding());
486:                            primaryFileObject.setAttribute(
487:                                    DataObject.PROP_TEMPLATE, Boolean.TRUE);
488:                            primaryFileObject.setAttribute(
489:                                    "javax.script.ScriptEngine", "freemarker"); // NOI18N
490:
491:                            // set attribute for JsfJspTemplateEncodingQueryImplementation for custom templates
492:                            primaryFileObject.setAttribute(
493:                                    PROP_CUSTOM_TEMPLATE, Boolean.TRUE);
494:
495:                            try {
496:                                Class iteratorClass = Thread
497:                                        .currentThread()
498:                                        .getContextClassLoader()
499:                                        .loadClass(
500:                                                "org.netbeans.modules.visualweb.project.jsf.ui.PageIterator"); //NOI18N
501:                                Method m = iteratorClass
502:                                        .getMethod("createWebFormIterator"); // NOI18N
503:                                Object templateIterator = m.invoke(null);
504:                                primaryFileObject.setAttribute(
505:                                        "templateWizardIterator",
506:                                        templateIterator); // NOI18N
507:                            } catch (Exception ex) {
508:                                ex.printStackTrace();
509:                            }
510:                        } catch (ParserConfigurationException e) {
511:                            throw new JsfDataObjectException(
512:                                    "Parser Configuration Exception : "
513:                                            + e.getMessage()
514:                                            + " while processing "
515:                                            + primaryFileObject);
516:                        } catch (SAXException e) {
517:                            throw new JsfDataObjectException(
518:                                    "Parsing Exception : " + e.getMessage()
519:                                            + " while processing "
520:                                            + primaryFileObject);
521:                        }
522:                    } else {
523:                        // do the normal event notification
524:                        doNormalEventNotify = true;
525:                    }
526:
527:                    try {
528:                        DataObject javaDataObject = DataObject.find(javaFile);
529:                        if (javaDataObject instanceof  JsfJavaDataObject) {
530:                            FileObject javaFolder = Utils
531:                                    .findJavaFolderForJsp(dataObject
532:                                            .getPrimaryFile());
533:                            DataFolder javaDataFolder = DataFolder
534:                                    .findFolder(javaFolder);
535:                            ((JsfJavaDataObject) javaDataObject)
536:                                    .pureCopy(javaDataFolder);
537:                        }
538:                    } catch (DataObjectNotFoundException dnfe) {
539:                        ErrorManager.getDefault().notify(
540:                                ErrorManager.INFORMATIONAL, dnfe);
541:                    }
542:
543:                    if (doNormalEventNotify) {
544:                        // invalidate the JspDataObject (created because the backing java had not been created)
545:                        // and pick up the new JsfJspDataObject
546:                        try {
547:                            FileObject fo = dataObject.getPrimaryFile();
548:                            dataObject.setValid(false);
549:                            dataObject = DataObject.find(fo);
550:                        } catch (PropertyVetoException ex) {
551:                            ErrorManager.getDefault().notify(
552:                                    ErrorManager.INFORMATIONAL, ex);
553:                            return dataObject;
554:                        }
555:                        InSyncService.getProvider().copied(
556:                                (JsfJspDataObjectMarker) this ,
557:                                (JsfJspDataObjectMarker) dataObject);
558:                    }
559:                    return dataObject;
560:                }
561:            }
562:
563:            @Override
564:            protected void handleDelete() throws IOException {
565:                boolean isTemplate = this .isTemplate();
566:                FileObject fo = getPrimaryFile();
567:                super .handleDelete();
568:
569:                // delete corresponding template .java
570:                if (isTemplate) {
571:                    FileObject javaFO = Utils.findJavaForJsp(fo);
572:                    DataObject javaTemplate = DataObject.find(javaFO);
573:                    if (javaTemplate != null) {
574:                        try {
575:                            javaTemplate.delete();
576:                        } catch (IOException ex) {
577:                            ErrorManager.getDefault().log(
578:                                    ErrorManager.ERROR,
579:                                    "Could not delete java template: "
580:                                            + javaFO.getNameExt()); // NOI18N
581:                        }
582:                    }
583:                }
584:            }
585:
586:            /** Handles create from template. Also handles creating from template of corresponding java file. */
587:            @Override
588:            protected DataObject handleCreateFromTemplate(DataFolder df,
589:                    String name) throws IOException {
590:                DataObject result = null;
591:                try {
592:                    JsfJspDataLoader.jspTemplateCreation.set(Boolean.TRUE);
593:
594:                    // freemarker-based template encoding handling
595:                    if (Boolean.TRUE.equals(this .getPrimaryFile().getAttribute(
596:                            PROP_CUSTOM_TEMPLATE))) {
597:                        JsfJspTemplateEncodingQueryImplementation.TEMPLATE_FILEOBJECT
598:                                .set(this .getPrimaryFile());
599:                    }
600:
601:                    result = super .handleCreateFromTemplate(df, name);
602:                } finally {
603:                    JsfJspDataLoader.jspTemplateCreation.set(Boolean.FALSE);
604:
605:                    if (Boolean.TRUE.equals(this .getPrimaryFile().getAttribute(
606:                            PROP_CUSTOM_TEMPLATE))) {
607:                        JsfJspTemplateEncodingQueryImplementation.TEMPLATE_FILEOBJECT
608:                                .remove();
609:                    }
610:                }
611:
612:                result.getPrimaryFile().setAttribute(JSF_ATTRIBUTE,
613:                        Boolean.TRUE);
614:                FileObject backingTargetFileObjectFolder = Utils
615:                        .findJavaFolderForJsp(result.getPrimaryFile());
616:                if (backingTargetFileObjectFolder == null) {
617:                    throw new JsfDataObjectException(
618:                            "Can't find corresponding java folder for "
619:                                    + result); // NOI18N
620:                }
621:                DataFolder backingTargetFolder = (DataFolder) DataObject
622:                        .find(backingTargetFileObjectFolder);
623:                // Find the backing file template
624:                FileObject javaTemplateFile = Utils
625:                        .findJavaForJsp(getPrimaryFile());
626:                if (javaTemplateFile == null) {
627:                    throw new JsfDataObjectException(
628:                            "Can't find java file template for jsp template "
629:                                    + this ); // NOI18N
630:                }
631:                DataObject backingTemplate = DataObject.find(javaTemplateFile);
632:                if (backingTargetFileObjectFolder.getFileObject(result
633:                        .getName(), backingTemplate.getPrimaryFile().getExt()) != null) {
634:                    ErrorManager
635:                            .getDefault()
636:                            .log(
637:                                    ErrorManager.ERROR,
638:                                    "\ndesigner:JsfJspDataObject#handleCreateFromTemplate: The java file " // NOI18N
639:                                            + result.getName()
640:                                            + "."
641:                                            + backingTemplate.getPrimaryFile()
642:                                                    .getExt()
643:                                            + " was created by somebody else. It is not necessary now, fix it!"); // NOI18N
644:                } else {
645:                    DataObject newBackingJava = null;
646:                    try {
647:                        FileObject resultFileObject = result.getPrimaryFile();
648:                        Project project = FileOwnerQuery
649:                                .getOwner(resultFileObject);
650:                        if (project == null) {
651:                            newBackingJava = backingTemplate
652:                                    .createFromTemplate(backingTargetFolder,
653:                                            result.getName());
654:                        } else {
655:                            Map<String, String> templateParameters = new HashMap<String, String>();
656:                            Object newProject = project.getProjectDirectory()
657:                                    .getAttribute("NewProject"); //NOI18N
658:                            if (newProject instanceof  Boolean
659:                                    && (Boolean) newProject) {
660:                                templateParameters.put("creatingProject",
661:                                        "true"); //NOI18N
662:                            }
663:                            templateParameters.put("j2eePlatformVersion",
664:                                    JsfProjectUtils
665:                                            .getJ2eePlatformVersion(project)); //NOI18N
666:                            templateParameters.put("sourceLevel",
667:                                    JsfProjectUtils.getSourceLevel(project)); //NOI18N
668:                            newBackingJava = backingTemplate
669:                                    .createFromTemplate(backingTargetFolder,
670:                                            result.getName(),
671:                                            templateParameters);
672:                        }
673:                    } catch (Exception ex) {
674:                        // XXX NB issue #113284
675:                        ex.printStackTrace();
676:                    }
677:
678:                    try {
679:
680:                        // XXX NB issue #81746.
681:                        if (newBackingJava != null) {
682:                            newBackingJava.getPrimaryFile().setAttribute(
683:                                    "NBIssue81746Workaround", Boolean.TRUE); // NOI18N
684:                            newBackingJava.getPrimaryFile().setAttribute(
685:                                    JsfJavaDataObject.JSF_ATTRIBUTE,
686:                                    Boolean.TRUE);
687:                        }
688:                    } catch (IOException ex) {
689:                        ex.printStackTrace();
690:                    }
691:
692:                    // Invalidate the JspDataObject if it had been created earlier and replace
693:                    // with the correct DataObject type (since the backing java file now exists)
694:                    if (!(result instanceof  JsfJspDataObject)) {
695:                        try {
696:                            FileObject jspFile = result.getPrimaryFile();
697:                            result.setValid(false);
698:                            result = DataObject.find(jspFile);
699:
700:                            if (!(result instanceof  JsfJspDataObject)) {
701:                                ErrorManager
702:                                        .getDefault()
703:                                        .log(
704:                                                ErrorManager.ERROR,
705:                                                "JsfJspDataObject#handleCreateFromTemplate: DataObject.find() did not return the correct value for "
706:                                                        + jspFile);
707:                            }
708:
709:                        } catch (PropertyVetoException ex) {
710:                            ErrorManager
711:                                    .getDefault()
712:                                    .log(
713:                                            ErrorManager.ERROR,
714:                                            "\nJsfJspDataObject#handleCreateFromTemplate: Unable to change to JsfJspDataLoader for FileObject: " // NOI18N
715:                                                    + result.getPrimaryFile());
716:                        }
717:                    }
718:                }
719:
720:                try {
721:                    // XXX NB issue #81746.
722:                    result.getPrimaryFile().setAttribute(
723:                            "NBIssue81746Workaround", Boolean.TRUE); // NOI18N
724:                } catch (IOException ex) {
725:                    ex.printStackTrace();
726:                }
727:
728:                return result;
729:            }
730:
731:            /** Renames the file. Handles also rename of corresponding jsf jsp file. */
732:            @Override
733:            protected FileObject handleRename(String name) throws IOException {
734:                FileObject fo = super .handleRename(name);
735:                return fo;
736:            }
737:
738:            // </rave>
739:
740:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.