Source Code Cross Referenced for InSyncServiceProvider.java in  » IDE-Netbeans » visualweb.api.designer » org » netbeans » modules » visualweb » insync » 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.insync 
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:        package org.netbeans.modules.visualweb.insync;
042:
043:        import java.net.URL;
044:        import java.util.List;
045:
046:        import javax.faces.component.UIComponent;
047:        import org.netbeans.api.project.Project;
048:        import org.netbeans.modules.visualweb.api.insync.InSyncService;
049:        import org.netbeans.modules.visualweb.api.insync.JsfJspDataObjectMarker;
050:        import org.netbeans.modules.visualweb.insync.beans.BeansUnit;
051:        import org.netbeans.modules.visualweb.insync.faces.ElAttrUpdater;
052:        import org.netbeans.modules.visualweb.insync.faces.Entities;
053:        import org.netbeans.modules.visualweb.insync.faces.FacesPageUnit;
054:        import org.netbeans.modules.visualweb.insync.live.LiveUnit;
055:        import org.netbeans.modules.visualweb.insync.markup.MarkupUnit;
056:        import org.netbeans.modules.visualweb.insync.markup.MarkupVisitor;
057:        import org.netbeans.modules.visualweb.insync.models.FacesModel;
058:        import org.netbeans.modules.visualweb.insync.models.FacesModelSet;
059:        import org.openide.ErrorManager;
060:        import org.openide.filesystems.FileObject;
061:        import org.openide.loaders.DataObject;
062:        import org.openide.nodes.Node;
063:        import org.w3c.dom.Document;
064:        import org.w3c.dom.DocumentFragment;
065:        import org.w3c.dom.Element;
066:
067:        import com.sun.rave.designtime.DesignBean;
068:        import com.sun.rave.designtime.DesignContext;
069:        import com.sun.rave.designtime.DesignEvent;
070:        import com.sun.rave.designtime.DesignProject;
071:        import com.sun.rave.designtime.DesignProperty;
072:        import com.sun.rave.designtime.markup.MarkupDesignBean;
073:        import com.sun.rave.designtime.markup.MarkupMouseRegion;
074:        import org.netbeans.modules.visualweb.jsfsupport.container.FacesContainer;
075:
076:        /**
077:         * This class provides a concrete implementation of InSyncService.
078:         * As well, it provides some functionality to handle the mapping of Java <-> JSP files.
079:         * This code should really exist in a Faces module to InSync, but these services will
080:         * be needed once I start removing any knowledge of this mapping from all other modules.
081:         *
082:         * The key would be to creating a Faces InSync module, and have a FacesInSyncService
083:         * that modules would then depend on.  Otherwise we cannot break out the Faces specific
084:         * functionality out of InSync's core.
085:         *
086:         * TODO
087:         * @author eric
088:         *
089:         */
090:        public class InSyncServiceProvider extends InSyncService {
091:
092:            protected static InSyncServiceProvider singleton;
093:
094:            public static InSyncServiceProvider get() {
095:                if (singleton == null) {
096:                    InSyncService iService = InSyncService.getProvider();
097:                    if (iService instanceof  InSyncServiceProvider)
098:                        singleton = (InSyncServiceProvider) iService;
099:                    else
100:                        singleton = new InSyncServiceProvider();
101:                }
102:                return singleton;
103:            }
104:
105:            public InSyncServiceProvider() {
106:                super ();
107:            }
108:
109:            /**
110:             * This is a hack until we get things done correctly with integration of Retouche.
111:             * Should only be called from JsfJspDataObject to notify us that toDataObject was created by copying fromDataObject.
112:             * Go through and rename the EL expression references to the original page name to the new page name.
113:             *
114:             * This is NOT the way to fix the problem of copy, however there are too many other issues that get in the way
115:             * that prevent us from creating a simple fix that will yield the same results.  Since ALL of this code will change
116:             * when we properly integrate insync into platform, this is throw away code.
117:             * 
118:             *  TODO: Remove
119:             *  
120:             * @param fromDataObject
121:             * @param toDataObject
122:             */
123:            public void copied(JsfJspDataObjectMarker fromDataObject,
124:                    JsfJspDataObjectMarker toDataObject) {
125:                InSyncServiceProviderQuery query = new InSyncServiceProviderQuery(
126:                        fromDataObject.getPrimaryFile(),
127:                        (DataObject) fromDataObject);
128:                String oldName = query.getBeanNameViaJsp();
129:                query = new InSyncServiceProviderQuery(toDataObject
130:                        .getPrimaryFile(), (DataObject) toDataObject);
131:                String newName = query.getBeanNameViaJsp();
132:                if (oldName == null || newName == null)
133:                    return;
134:                MarkupUnit markupUnit = new MarkupUnit(toDataObject
135:                        .getPrimaryFile(), MarkupUnit.ALLOW_XML, true,
136:                        new UndoManager());
137:                markupUnit.sync();
138:                if (markupUnit.isBusted())
139:                    return;
140:                MarkupVisitor v = new ElAttrUpdater(oldName, newName);
141:                v.apply(markupUnit.getSourceDom());
142:                markupUnit.flush();
143:            }
144:
145:            public void doOutsideOfRefactoringSession(Runnable runnable) {
146:                //NB6.0 MdrInSyncSynchronizer.get().doOutsideOfRefactoringSession(runnable);
147:            }
148:
149:            public String getBeanNameForJsp(FileObject fileObject) {
150:                String result = FacesModel.getBeanNameForJsp(fileObject);
151:                return result;
152:            }
153:
154:            public DataObject getJavaDataObjectEquivalent(
155:                    DataObject dataObject, String originalName,
156:                    boolean forceCreate) {
157:                InSyncServiceProviderQuery query = newQuery(null, dataObject);
158:                return query.getJavaDataObjectEquivalent(originalName,
159:                        forceCreate);
160:            }
161:
162:            public DataObject getJavaDataObjectEquivalent(
163:                    FileObject fileObject, String originalName,
164:                    boolean forceCreate) {
165:                InSyncServiceProviderQuery query = newQuery(fileObject, null);
166:                return query.getJavaDataObjectEquivalent(originalName,
167:                        forceCreate);
168:            }
169:
170:            public DataObject getJavaDataObjectEquivalent(Node node,
171:                    String originalName, boolean forceCreate) {
172:                DataObject dataObject = (DataObject) node
173:                        .getCookie(DataObject.class);
174:                return getJavaDataObjectEquivalent(dataObject, originalName,
175:                        forceCreate);
176:            }
177:
178:            public FileObject getJavaFileObjectEquivalent(
179:                    FileObject fileObject, String originalName,
180:                    boolean forceCreate) {
181:                InSyncServiceProviderQuery query = newQuery(fileObject, null);
182:                return query.getJavaFileObjectEquivalent(originalName,
183:                        forceCreate);
184:            }
185:
186:            /**
187:             * Gets corresponding java file object for specified jsp file object if exists.
188:             * 
189:             * @return corresponding java file object or <code>null</code>
190:             */
191:            public FileObject getJavaForJsp(FileObject jspFileObject) {
192:                InSyncServiceProviderQuery query = newQuery(jspFileObject, null);
193:                return query.getJavaForJsp();
194:            }
195:
196:            public FileObject getJavaFolderForJsp(FileObject fileObject) {
197:                InSyncServiceProviderQuery query = newQuery(fileObject, null);
198:                return query.getJavaFolderForJsp();
199:            }
200:
201:            protected InSyncServiceProviderQuery newQuery(
202:                    FileObject fileObject, DataObject dataObject) {
203:                return new InSyncServiceProviderQuery(fileObject, dataObject);
204:            }
205:
206:            // XXX The three methods dealing with triggering of parsing of jsp.
207:            public void jspDataObjectTopComponentActivated(DataObject dobj) {
208:                // XXX No longer needed as SourceMonitor has been removed.
209:            }
210:
211:            public void jspDataObjectTopComponentHidden(DataObject dobj) {
212:                // XXX No longer needed as SourceMonitor has been removed.
213:            }
214:
215:            public void jspDataObjectTopComponentShown(DataObject dobj) {
216:                // XXX No longer needed as SourceMonitor has been removed.
217:            }
218:
219:            // <missing_designtime_api>
220:
221:            // <markup_separation> XXX See the InSyncService
222:            public void appendParsedString(Document doc, org.w3c.dom.Node node,
223:                    String xhtml, MarkupDesignBean bean) {
224:                MarkupUnit unit = MarkupUnit.getMarkupUnitForDocument(doc);
225:                if (unit == null) {
226:                    return;
227:                }
228:                unit.appendParsedString(node, xhtml, bean);
229:            }
230:
231:            public FileObject getFileObject(Document doc) {
232:                return Util.getFileObject(doc);
233:            }
234:
235:            public int computeLine(Document doc, Element element) {
236:                //        MarkupUnit unit = MarkupUnit.getMarkupUnitForDocument(doc);
237:                //        if (unit == null) {
238:                //            return 0;
239:                //        }
240:                //        return unit.computeLine(element);
241:                return Util.computeLine(doc, element);
242:            }
243:
244:            public URL getDocumentUrl(Document doc) {
245:                ////        if (!(doc instanceof RaveDocument)) {
246:                ////            return null;
247:                ////        }
248:                //        if (doc == null) {
249:                //            return null;
250:                //        }
251:                //        
252:                ////        RaveDocument rDoc = (RaveDocument)doc;
253:                //// <removing set/getRoot from RaveDocument>
254:                ////        DesignProject designProject = rDoc.getRoot().getDesignBean().getDesignContext().getProject();
255:                //        MarkupUnit unit = MarkupUnit.getMarkupUnitForDocument(doc);
256:                //        DesignProject designProject;
257:                //        if (unit != null) {
258:                //            FacesModel facesModel = FacesModel.getInstance(unit.getFileObject());
259:                //            designProject = ((DesignContext)facesModel.getLiveUnit()).getProject();
260:                //        } else {
261:                //            designProject = null;
262:                //        }
263:                //// <removing set/getRoot from RaveDocument>
264:                //        if(designProject instanceof FacesModelSet) {
265:                //            FacesModelSet fModelSet = (FacesModelSet)designProject;
266:                //            FileObject documentRoot = JsfProjectUtils.getDocumentRoot(fModelSet.getProject());
267:                //            try {
268:                //                return documentRoot.getURL();
269:                //            } catch(FileStateInvalidException fsie) {
270:                //                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, fsie);
271:                //            }
272:                //        }
273:                //        
274:                //        return null;
275:                return Util.getDocumentUrl(doc);
276:            }
277:
278:            // </markup_separation>
279:
280:            public void setUrl(Document doc, URL url) {
281:                MarkupUnit.setUrlForDocument(doc, url);
282:            }
283:
284:            public URL getUrl(Document doc) {
285:                return MarkupUnit.getUrlForDocument(doc);
286:            }
287:
288:            // JSF rendering.
289:            public DocumentFragment renderHtml(FileObject markupFile,
290:                    MarkupDesignBean bean) {
291:                FacesModel facesModel = FacesModel.getInstance(markupFile);
292:
293:                if (facesModel == null) {
294:                    return null;
295:                } else {
296:                    return FacesPageUnit.renderHtml(facesModel, bean);
297:                }
298:            }
299:
300:            public Exception getRenderFailure(FileObject markupFile) {
301:                FacesModel facesModel = FacesModel.getInstance(markupFile);
302:                if (facesModel == null) {
303:                    return null;
304:                } else {
305:                    FacesPageUnit facesPageUnit = facesModel.getFacesUnit();
306:                    return facesPageUnit.getRenderFailure();
307:                }
308:            }
309:
310:            public DesignBean getRenderFailureComponent(FileObject markupFile) {
311:                FacesModel facesModel = FacesModel.getInstance(markupFile);
312:                if (facesModel == null) {
313:                    return null;
314:                } else {
315:                    FacesPageUnit facesPageUnit = facesModel.getFacesUnit();
316:                    return facesPageUnit.getRenderFailureComponent();
317:                }
318:            }
319:
320:            // </missing_designtime_api>
321:
322:            // <separation of models>
323:            public Document getJspDomForMarkupFile(FileObject markupFile) {
324:                FacesModel facesModel = FacesModel.getInstance(markupFile);
325:                if (facesModel == null) {
326:                    return null;
327:                } else {
328:                    return facesModel.getJspDom();
329:                }
330:            }
331:
332:            public Document getHtmlDomForMarkupFile(FileObject markupFile) {
333:                FacesModel facesModel = FacesModel.getInstance(markupFile);
334:                if (facesModel == null) {
335:                    return null;
336:                } else {
337:                    return facesModel.getHtmlDom();
338:                }
339:            }
340:
341:            //    public DocumentFragment getHtmlDomFragmentForMarkupFile(FileObject markupFile) {
342:            //        FacesModel facesModel = FacesModel.getInstance(markupFile);
343:            //        if (facesModel == null) {
344:            //            return null;
345:            //        } else {
346:            //            return facesModel.getHtmlDomFragment();
347:            //        }
348:            //    }
349:
350:            public DocumentFragment getHtmlDomFragmentForDocument(
351:                    Document document) {
352:                //        FileObject markupFile = getFileObject(document);
353:                //        if (markupFile == null) {
354:                //            return null;
355:                //        }
356:                //        
357:                //        FacesModel facesModel = FacesModel.getInstance(markupFile);
358:                //        if (facesModel == null) {
359:                //            return null;
360:                //        } else {
361:                //            return facesModel.getHtmlDomFragment();
362:                //        }
363:                return Util.getHtmlDomFragmentForDocument(document);
364:            }
365:
366:            public Element getHtmlBodyForMarkupFile(FileObject markupFile) {
367:                //        FacesModel facesModel = FacesModel.getInstance(markupFile);
368:                //        if (facesModel == null) {
369:                //            return null;
370:                //        } else {
371:                //            return facesModel.getHtmlBody();
372:                //        }
373:                return Util.getHtmlBodyForMarkupFile(markupFile);
374:            }
375:
376:            // XXX Refresh antipatern.
377:            public void clearHtmlForMarkupFile(FileObject markupFile) {
378:                FacesModel facesModel = FacesModel.getInstance(markupFile);
379:                if (facesModel != null) {
380:                    facesModel.clearHtml();
381:                }
382:            }
383:
384:            public boolean isBraveheartPage(Document dom) {
385:                return Util.isBraveheartPage(dom);
386:            }
387:
388:            public boolean isWoodstockPage(Document dom) {
389:                return Util.isWoodstockPage(dom);
390:            }
391:
392:            // </separation of models>
393:
394:            // <service_methods>
395:            public String fromURL(String url) {
396:                //        if (url.startsWith("file:")) { // NOI18N
397:                //            int n = url.length();
398:                //            StringBuffer sb = new StringBuffer(n);
399:                //            for (int i = 5; i < n; i++) {
400:                //                char c = url.charAt(i);
401:                //                // TODO -- any File.separatorChar manipulation perhaps?
402:                //                if (c == '%' && i < n-3) {
403:                //                    char d1 = url.charAt(i+1);
404:                //                    char d2 = url.charAt(i+2);
405:                //                    if (Character.isDigit(d1) && Character.isDigit(d2)) {
406:                //                        String numString = ""+d1+d2;
407:                //                        try {
408:                //                            int num = Integer.parseInt(numString, 16);
409:                //                            if (num >= 0 && num <= 255) {
410:                //                                sb.append((char)num);
411:                //                                i += 2;
412:                //                                continue;
413:                //                            }
414:                //                        } catch (NumberFormatException nex) {
415:                //                            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, nex);
416:                //                        }
417:                //                    }
418:                //                    sb.append(c);
419:                //                } else {
420:                //                    sb.append(c);
421:                //                }
422:                //            }
423:                //            return sb.toString();
424:                //        }
425:                //        return url;
426:                return Util.fromURL(url);
427:            }
428:
429:            //    // XXX From org.netbeans.modules.visualweb.insync.Util.
430:            //    /**
431:            //     * Given an element which may be in a rendered DocumentFragment, return the corresponding JSF
432:            //     * element in the source.
433:            //     */
434:            //    public Element getCorrespondingSourceElement(Element elem) {
435:            //        if (!(elem instanceof RaveElement)) {
436:            //            return elem;
437:            //        }
438:            //        
439:            //        RaveElement element = (RaveElement)elem;
440:            //        
441:            //        if (!element.isRendered()) {
442:            //            return element;
443:            //        }
444:            //        
445:            //        org.w3c.dom.Node node = element;
446:            //        while (node != null) {
447:            //            if (node instanceof RaveElement) {
448:            //                RaveElement xel = (RaveElement)node;
449:            //                if (xel.isRendered()) {
450:            //                    RaveElement src = xel.getSource();
451:            //                    if (src != null) {
452:            //                        return src;
453:            //                    }
454:            //                }
455:            //            }
456:            //            node = node.getParentNode();
457:            //        }
458:            //        
459:            ////        return element.getSourceElement();
460:            //        return element.getSource();
461:            //    }
462:
463:            public String computeFileName(Object location) {
464:                //        if (location instanceof String) {
465:                //            return (String)location;
466:                //        } else if (location instanceof URL) {
467:                //            // <markup_separation>
468:                ////            return MarkupUnit.fromURL(((URL)location).toExternalForm());
469:                //            // ====
470:                //            return InSyncServiceProvider.get().fromURL(((URL)location).toExternalForm());
471:                //            // </markup_separation>
472:                //        } else if (location instanceof Element) {
473:                //            // Locate the filename for a given element
474:                //            Element element = (Element)location;
475:                //            element = MarkupService.getCorrespondingSourceElement(element);
476:                //
477:                //            // <markup_separation>
478:                ////            // XXX I should derive this from the engine instead, after all
479:                ////            // the engine can know the unit! (Since engines cannot be used
480:                ////            // with multiple DOMs anyway)
481:                ////            FileObject fo = unit.getFileObject();
482:                //            // ====
483:                //            FileObject fo = getFileObject(element.getOwnerDocument());
484:                //            // </markup_separation>
485:                //            File f = FileUtil.toFile(fo);
486:                //
487:                //            return f.toString();
488:                //        } else if (location != null) {
489:                //            return location.toString();
490:                //        }
491:                //
492:                //        return "";
493:                return Util.computeFileName(location);
494:            }
495:
496:            public int computeLineNumber(Object location, int lineno) {
497:                //        if (location instanceof Element) {
498:                //            /*
499:                //            // The location is an XhtmlElement -- so the line number
500:                //            // needs to be relative to it.... compute the line number
501:                //            // of the element
502:                //            if (lineno == -1)
503:                //                lineno = 0;
504:                //            Element element = (Element)location;
505:                //            RaveDocument doc = (RaveDocument)element.getOwnerDocument();
506:                //            lineno += doc.getLineNumber(element);
507:                //             */
508:                //            if (lineno == -1) {
509:                //                lineno = 0;
510:                //            }
511:                //
512:                //            Element element = (Element)location;
513:                //            element = MarkupService.getCorrespondingSourceElement(element);
514:                //            // <markup_separation>
515:                ////            lineno += unit.computeLine(element);
516:                //            // ====
517:                //            lineno += InSyncServiceProvider.get().computeLine(element.getOwnerDocument(), element);
518:                //            // </markup_separation>
519:                //        }
520:                //
521:                //        return lineno;
522:                return Util.computeLineNumber(location, lineno);
523:            }
524:
525:            // </service_methods>
526:
527:            // <error_handling> Moved from RaveDocument.
528:            private final RaveErrorHandler raveErrorHandler = new RaveErrorHandlerImpl();
529:
530:            public InSyncService.RaveErrorHandler getRaveErrorHandler() {
531:                return raveErrorHandler;
532:            }
533:
534:            /** Class implementing the Rave IDE specific error handling. */
535:            private static class RaveErrorHandlerImpl implements 
536:                    InSyncService.RaveErrorHandler {
537:                //        private boolean clearErrors = false;
538:
539:                public void clearErrors(boolean delayed) {
540:                    //            if (delayed) {
541:                    //                clearErrors = true;
542:                    //            } else {
543:                    //                OutputWriter out = getOutputWriter();
544:                    //                try {
545:                    //                    out.reset();
546:                    //                }
547:                    //                catch (IOException ioe) {
548:                    //                    // This is lame - our own output window shouldn't
549:                    //                    // throw IO exceptions!
550:                    //                    ErrorManager.getDefault().notify(ioe);
551:                    //                }
552:                    //            }
553:                    Util.clearErrors(delayed);
554:                }
555:
556:                public void selectErrors() {
557:                    //            InputOutput io = getInputOutput();
558:                    //            io.select();
559:                    Util.selectErrors();
560:                }
561:
562:                public void displayError(String message) {
563:                    displayErrorForFileObject(message, null, -1, -1);
564:                }
565:
566:                public void displayErrorForLocation(String message,
567:                        Object location, int line, int column) {
568:                    //            String fileName = InSyncServiceProvider.get().computeFileName(location);
569:                    //            line = InSyncServiceProvider.get().computeLineNumber(location, line);
570:                    //
571:                    //            File file = new File(fileName);
572:                    //            FileObject fo = FileUtil.toFileObject(file);
573:                    //
574:                    //            displayErrorForFileObject(message, fo, line >= 1 ? line : 1, column);
575:                    Util.displayErrorForLocation(message, location, line,
576:                            column);
577:                }
578:
579:                public void displayErrorForFileObject(String message,
580:                        final FileObject fileObject, final int line,
581:                        final int column) {
582:                    //    //        final XhtmlElement e = Util.getSource(element);
583:                    //            OutputListener listener;
584:                    //            if (fileObject == null) {
585:                    //                listener = null;
586:                    //            } else {
587:                    //                listener = new OutputListener() {
588:                    //                    public void outputLineSelected(OutputEvent ev) {
589:                    //                    }
590:                    //                    public void outputLineAction(OutputEvent ev) {
591:                    //    //                    Util.show(null, unit.getFileObject(), unit.getLine(e),
592:                    //    //                              0, true);
593:                    //                        // <markup_separation>
594:                    //    //                    Util.show(null, fileObject, lineNumber, 0, true);
595:                    //                        // ====
596:                    //                        showLineAt(fileObject, line, column);
597:                    //                        // </markup_separation>
598:                    //                    }
599:                    //                    public void outputLineCleared (OutputEvent ev) {
600:                    //                    }
601:                    //                };
602:                    //            }
603:                    //
604:                    //            displayError(message, listener);
605:                    Util.displayErrorForFileObject(message, fileObject, line,
606:                            column);
607:                }
608:
609:                //        /** 
610:                //         * Display the given error message to the user. The optional listener argument
611:                //         * (pass in null if not applicable) will make the line hyperlinked and the
612:                //         * listener is invoked to process any user clicks.
613:                //         * @param message The string to be displayed to the user
614:                //         * @param listener null, or a listener to be notified when the user clicks
615:                //         *   the linked message
616:                //         */
617:                //        private void displayError(String message, OutputListener listener) {
618:                //            OutputWriter out = getOutputWriter();
619:                //            try {
620:                //                if (clearErrors) {
621:                //                    out.reset();
622:                //                    clearErrors = false;
623:                //                }
624:                //                // Write the error message to the output tab:
625:                //                out.println(message, listener);
626:                //            }
627:                //            catch (IOException ioe) {
628:                //                // This is lame - our own output window shouldn't throw IO exceptions!
629:                //                ErrorManager.getDefault().notify(ioe);
630:                //            }
631:                //        }
632:                //        
633:                //        private  static void showLineAt(FileObject fo, int lineno, int column) {
634:                //            DataObject dobj;
635:                //            try {
636:                //                dobj = DataObject.find(fo);
637:                //            }
638:                //            catch (DataObjectNotFoundException ex) {
639:                //                ErrorManager.getDefault().notify(ex);
640:                //                return;
641:                //            }
642:                //
643:                //            // Try to open doc before showing the line. This SHOULD not be
644:                //            // necessary, except without this the IDE hangs in its attempt
645:                //            // to open the file when the file in question is a CSS file.
646:                //            // Probably a bug in the xml/css module's editorsupport code.
647:                //            // This has the negative effect of first flashing the top
648:                //            // of the file before showing the destination line, so
649:                //            // this operation is made conditional so only clients who
650:                //            // actually need it need to use it.
651:                //            EditorCookie ec = (EditorCookie)dobj.getCookie(EditorCookie.class);
652:                //            if (ec != null) {
653:                //                try {
654:                //                    ec.openDocument(); // ensure that it has been opened - REDUNDANT?
655:                //                    //ec.open();
656:                //                }
657:                //                catch (IOException ex) {
658:                //                    ErrorManager.getDefault().notify(ex);
659:                //                }
660:                //            }
661:                //
662:                //            LineCookie lc = (LineCookie)dobj.getCookie(LineCookie.class);
663:                //            if (lc != null) {
664:                //                Line.Set ls = lc.getLineSet();
665:                //                if (ls != null) {
666:                //                    // -1: convert line numbers to be zero-based
667:                //                    Line line = ls.getCurrent(lineno-1);
668:                //                    // TODO - pass in a column too?
669:                //                    line.show(Line.SHOW_GOTO, column);
670:                //                }
671:                //            }
672:                //        }
673:                //    
674:                //        private static InputOutput getInputOutput() {
675:                //            return IOProvider.getDefault().getIO(NbBundle.getMessage(InSyncServiceProvider.class, "LBL_Output"), false);
676:                //        }
677:                //        private static OutputWriter getOutputWriter() {
678:                //            InputOutput io = getInputOutput();
679:                //            return io.getOut();
680:                //        }
681:            } // End of RaveErrorHandlerImpl.
682:            // </error_handling>
683:
684:            public void copyMarkupMouseRegionForElement(Element fromElement,
685:                    Element toElement) {
686:                MarkupMouseRegion region = FacesPageUnit
687:                        .getMarkupMouseRegionForElement(fromElement);
688:                FacesPageUnit.setMarkupMouseRegionForElement(toElement, region);
689:            }
690:
691:            public MarkupMouseRegion getMarkupMouseRegionForElement(
692:                    Element element) {
693:                return FacesPageUnit.getMarkupMouseRegionForElement(element);
694:            }
695:
696:            public void copyMarkupDesignBeanForElement(Element fromElement,
697:                    Element toElement) {
698:                MarkupDesignBean bean = MarkupUnit
699:                        .getMarkupDesignBeanForElement(fromElement);
700:                MarkupUnit.setMarkupDesignBeanForElement(toElement, bean);
701:            }
702:
703:            public MarkupDesignBean getMarkupDesignBeanForElement(
704:                    Element element) {
705:                return MarkupUnit.getMarkupDesignBeanForElement(element);
706:            }
707:
708:            public void setMarkupDesignBeanForElement(Element element,
709:                    MarkupDesignBean markupDesignBean) {
710:                MarkupUnit.setMarkupDesignBeanForElement(element,
711:                        markupDesignBean);
712:            }
713:
714:            /**
715:             * Generate the html string from the given node. This will return
716:             * an empty string unless the Node is an Element or a DocumentFragment
717:             * or a Document.
718:             */
719:            public String getHtmlStream(org.w3c.dom.Node node) {
720:                return Util.getHtmlStream(node);
721:            }
722:
723:            /** Generate the html string from the given element */
724:            public String getHtmlStream(Element element) {
725:                return Util.getHtmlStream(element);
726:            }
727:
728:            /** Generate the html string from the given element. Does formatting. */
729:            public String getHtmlStream(org.w3c.dom.Document document) {
730:                return Util.getHtmlStream(document);
731:            }
732:
733:            /** Generate the html string from the given document fragment */
734:            public String getHtmlStream(DocumentFragment df) {
735:                return Util.getHtmlStream(df);
736:            }
737:
738:            public boolean isWebPage(FileObject fo) {
739:                return Util.isWebPage(fo);
740:            }
741:
742:            public String[] getMimeTypes() {
743:                return Util.getMimeTypes();
744:            }
745:
746:            public List getWebPages(Project project, boolean includePages,
747:                    boolean includeFragments) {
748:                return Util
749:                        .getWebPages(project, includePages, includeFragments);
750:            }
751:
752:            public URL resolveUrl(URL base, Document document, String src) {
753:                return Util.resolveUrl(base, document, src);
754:            }
755:
756:            public WriteLock writeLockContext(DesignContext designContext,
757:                    String message) {
758:                // XXX Blind casting, just matching the original code.
759:                return (WriteLock) ((LiveUnit) designContext).getModel()
760:                        .writeLock(message);
761:            }
762:
763:            public void writeUnlockContext(DesignContext designContext,
764:                    WriteLock lock) {
765:                // XXX Blind casting, just matching the original code.
766:                ((LiveUnit) designContext).getModel().writeUnlock(
767:                        (UndoEvent) lock);
768:            }
769:
770:            public void addLocalStyleValueForElement(Element element,
771:                    int style, String value) {
772:                Util.addLocalStyleValueForElement(element, style, value);
773:            }
774:
775:            public void removeLocalStyleValueForElement(Element element,
776:                    int style) {
777:                Util.removeLocalStyleValueForElement(element, style);
778:            }
779:
780:            public Project getProjectForDesignProject(
781:                    DesignProject designProject) {
782:                FacesModelSet set = (FacesModelSet) designProject;
783:                return set.getProject();
784:            }
785:
786:            public FileObject getMarkupFileObjectForDesignContext(
787:                    DesignContext designContext) {
788:                LiveUnit lu = (LiveUnit) designContext;
789:                FacesPageUnit fu = (FacesPageUnit) lu.getBeansUnit();
790:                MarkupUnit mu = fu.getPageUnit();
791:                return mu.getFileObject();
792:            }
793:
794:            public void initModelsForWebformFile(Project project,
795:                    FileObject webformFile) {
796:                FacesModelSet modelset = FacesModelSet.getInstance(project);
797:                FacesModel model = modelset.getFacesModel(webformFile);
798:                if (model == null) {
799:                    ErrorManager.getDefault().notify(
800:                            ErrorManager.INFORMATIONAL,
801:                            new IllegalStateException(webformFile
802:                                    + " has no insync Model!")); // NOI18N
803:                }
804:            }
805:
806:            public String expandHtmlEntities(String html, boolean warn,
807:                    org.w3c.dom.Node node) {
808:                return Entities.expandHtmlEntities(html, warn, node);
809:            }
810:
811:            public int getExpandedOffset(String unexpanded, int unexpandedOffset) {
812:                return Entities.getExpandedOffset(unexpanded, unexpandedOffset);
813:            }
814:
815:            public int getUnexpandedOffset(String unexpanded, int expandedOffset) {
816:                return Entities.getUnexpandedOffset(unexpanded, expandedOffset);
817:            }
818:
819:            public static boolean isComponentRendersChildren(
820:                    DesignBean designBean) {
821:                DesignContext designContext = designBean.getDesignContext();
822:                if (designContext == null) {
823:                    return false;
824:                }
825:                BeansUnit beansUnit = ((LiveUnit) designContext).getBeansUnit();
826:                if (beansUnit == null) {
827:                    return false;
828:                }
829:                FacesModel facesModel = (FacesModel) beansUnit.getModel();
830:                if (facesModel != null) {
831:                    FacesContainer container = facesModel.getFacesModelSet()
832:                            .getFacesContainer();
833:                    return container
834:                            .isComponentRendersChildren((UIComponent) designBean
835:                                    .getInstance());
836:                }
837:                return false;
838:            }
839:
840:            //  Thread.currentThread().getContextClassLoader() stuff
841:            public ClassLoader getContextClassLoader(DesignContext designContext) {
842:                if (designContext == null) {
843:                    return null;
844:                }
845:                BeansUnit beansUnit = ((LiveUnit) designContext).getBeansUnit();
846:                if (beansUnit == null) {
847:                    return null;
848:                }
849:                return beansUnit.getClassLoader();
850:            }
851:
852:            public ClassLoader getContextClassLoader(DesignBean designBean) {
853:                if (designBean == null) {
854:                    return null;
855:                }
856:                return getContextClassLoader(designBean.getDesignContext());
857:            }
858:
859:            public ClassLoader getContextClassLoader(
860:                    DesignProperty designProperty) {
861:                if (designProperty == null) {
862:                    return null;
863:                }
864:
865:                return getContextClassLoader(designProperty.getDesignBean());
866:            }
867:
868:            public ClassLoader getContextClassLoader(DesignEvent designEvent) {
869:                if (designEvent == null) {
870:                    return null;
871:                }
872:                return getContextClassLoader(designEvent.getDesignBean());
873:            }
874:
875:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.