Source Code Cross Referenced for Jsp2JavaTagHandler.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » internal » ui » examples » jspeditor » 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 Eclipse » jdt » org.eclipse.jdt.internal.ui.examples.jspeditor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2004 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.jdt.internal.ui.examples.jspeditor;
011:
012:        import java.io.IOException;
013:
014:        import org.eclipse.core.runtime.Assert;
015:
016:        import org.eclipse.jface.text.source.translation.ITagHandler;
017:        import org.eclipse.jface.text.source.translation.ITranslatorResultCollector;
018:
019:        /**
020:         * 
021:         * @since 3.0
022:         */
023:        public class Jsp2JavaTagHandler implements  ITagHandler {
024:
025:            private boolean fInUseBean;
026:            private boolean fInTagLib;
027:            private String fTagLibValue;
028:            private String fClass;
029:            private String fId;
030:            private String fSource;
031:            private boolean fInDeclaration;
032:            private boolean fInJavaSection;
033:
034:            /*
035:             * @see org.eclipse.jface.text.source.ITagHandler#canHandleTag(java.lang.String)
036:             */
037:            public boolean canHandleTag(String tag) {
038:                return true;
039:            }
040:
041:            /*
042:             * @see org.eclipse.jface.text.source.ITagHandler#canHandleText(java.lang.String)
043:             */
044:            public boolean canHandleText(String text) {
045:                return true;
046:            }
047:
048:            public void reset(String startTag) {
049:                fInUseBean = "jsp:useBean".equals(startTag); //$NON-NLS-1$
050:                fInTagLib = "c:out".equals(startTag); //$NON-NLS-1$
051:                fInJavaSection = "<%".equals(startTag); //$NON-NLS-1$
052:                fInDeclaration = "<%!".equals(startTag); //$NON-NLS-1$
053:            }
054:
055:            /*
056:             * @see org.eclipse.jface.text.source.ITagHandler#addAttribute(java.lang.String, java.lang.String)
057:             */
058:            public void addAttribute(String name, String value,
059:                    int sourceLineNumber) {
060:                if (fInUseBean) {
061:                    if ("id".equals(name)) //$NON-NLS-1$
062:                        fId = value;
063:                    else if ("class".equals(name)) //$NON-NLS-1$
064:                        fClass = value;
065:                }
066:                if (fInTagLib) {
067:                    fTagLibValue = value;
068:                }
069:                if ("source".equals(name)) //$NON-NLS-1$
070:                    fSource = value;
071:            }
072:
073:            /*
074:             * @see org.eclipse.jface.text.source.ITagHandler#backTranslateOffsetInLine(java.lang.String, int)
075:             */
076:            public int backTranslateOffsetInLine(String originalLine,
077:                    String translatedLine, int offsetInTranslatedLine) {
078:                int javaPartitionStart = 0;
079:                if (originalLine.indexOf("<%") != -1) //$NON-NLS-1$
080:                    javaPartitionStart = handleJavaSection(originalLine,
081:                            offsetInTranslatedLine);
082:                else if (originalLine.indexOf("<jsp:useBean id=\"") != -1) { //$NON-NLS-1$
083:                    javaPartitionStart = handleUseBeanTag(originalLine,
084:                            offsetInTranslatedLine);
085:                } else if (originalLine.indexOf("<c:out value=\"${") != -1) { //$NON-NLS-1$
086:                    javaPartitionStart = handleTagLib(originalLine,
087:                            offsetInTranslatedLine);
088:                }
089:                return javaPartitionStart;
090:            }
091:
092:            private int handleJavaSection(String jspLineStr,
093:                    int relativeLineOffsetInJava) {
094:                return jspLineStr.indexOf("<%") + 3; //$NON-NLS-1$
095:            }
096:
097:            private int handleTagLib(String jspLineStr,
098:                    int relativeLineOffsetInJava) {
099:                int javaFileOffset = "System.out.println(".length(); //$NON-NLS-1$
100:                return jspLineStr.indexOf("<c:out value=\"${") + 16 - javaFileOffset; //$NON-NLS-1$
101:            }
102:
103:            /*
104:             * This is a good example where the relative line offset in the Java
105:             * document cannot be directly mapped back to Jsp document.
106:             */
107:            private int handleUseBeanTag(String jspLineStr,
108:                    int relativeLineOffsetInJava) {
109:
110:                int javaPartitionStart;
111:
112:                int variableNameStart = jspLineStr
113:                        .indexOf("<jsp:useBean id=\"") + 17; //$NON-NLS-1$
114:                int variableNameLength = Math.max(0, jspLineStr.indexOf('"',
115:                        variableNameStart)
116:                        - variableNameStart);
117:
118:                int typeStart = jspLineStr.indexOf("class=\"") + 7; //$NON-NLS-1$
119:                int typeLength = Math.max(0, jspLineStr.indexOf('"', typeStart)
120:                        - typeStart);
121:
122:                if (relativeLineOffsetInJava < typeLength) {
123:                    javaPartitionStart = typeStart;
124:                } else if (relativeLineOffsetInJava < typeLength
125:                        + variableNameLength)
126:                    javaPartitionStart = variableNameStart;
127:                else
128:                    javaPartitionStart = typeStart;
129:
130:                // start relative to Jsp line start
131:                return javaPartitionStart - relativeLineOffsetInJava;
132:            }
133:
134:            /*
135:             * @see org.eclipse.jface.text.source.ITagHandler#processEndTag(ITranslatorResultCollector, int)
136:             */
137:            public void processEndTag(
138:                    ITranslatorResultCollector resultCollector,
139:                    int sourceLineNumber) throws IOException {
140:                Assert
141:                        .isTrue(resultCollector instanceof  JspTranslatorResultCollector);
142:
143:                JspTranslatorResultCollector jspResultCollector = (JspTranslatorResultCollector) resultCollector;
144:
145:                if (fInUseBean) {
146:                    if (fId != null && fClass != null) {
147:                        jspResultCollector
148:                                .appendLocalDeclaration(
149:                                        fClass
150:                                                + " " + fId + "= new " + fClass + "();\n", sourceLineNumber); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
151:                        fId = fClass = null;
152:                    }
153:                    fInUseBean = false;
154:                }
155:                if (fInTagLib && fTagLibValue != null) {
156:                    jspResultCollector
157:                            .appendContent(
158:                                    "System.out.println(" + fTagLibValue.substring(2, fTagLibValue.length() - 1) + ");\n", sourceLineNumber); //$NON-NLS-1$ //$NON-NLS-2$
159:                    fTagLibValue = null;
160:                    fInTagLib = false;
161:                }
162:                if (fInJavaSection) {
163:                    int i = 0;
164:                    StringBuffer out = new StringBuffer();
165:                    while (i < fSource.length()) {
166:                        char c = fSource.charAt(i++);
167:                        if (c == '\n') {
168:                            jspResultCollector.appendContent(out.toString()
169:                                    + "\n", sourceLineNumber++); //$NON-NLS-1$
170:                            out.setLength(0);
171:                        } else {
172:                            out.append(c);
173:                        }
174:                    }
175:                    if (out.length() > 0) {
176:                        jspResultCollector.appendContent(
177:                                out.toString() + "\n", sourceLineNumber); //$NON-NLS-1$
178:                    }
179:                }
180:                if (fInDeclaration) {
181:                    int i = 0;
182:                    StringBuffer out = new StringBuffer();
183:                    while (i < fSource.length()) {
184:                        char c = fSource.charAt(i++);
185:                        if (c == '\n') {
186:                            jspResultCollector.appendDeclaration(out.toString()
187:                                    + "\n", sourceLineNumber++); //$NON-NLS-1$
188:                            out.setLength(0);
189:                        } else {
190:                            out.append(c);
191:                        }
192:                    }
193:                    if (out.length() > 0) {
194:                        jspResultCollector.appendDeclaration(out.toString()
195:                                + "\n", sourceLineNumber); //$NON-NLS-1$
196:                    }
197:                }
198:            }
199:        }
w_ww___._ja___v___a___2__s_.co___m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.