Source Code Cross Referenced for XMLUtil.java in  » IDE-Eclipse » Eclipse-plug-in-development » org » eclipse » pde » internal » ui » editor » text » 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 » Eclipse plug in development » org.eclipse.pde.internal.ui.editor.text 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2005, 2007 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.pde.internal.ui.editor.text;
011:
012:        import java.util.Hashtable;
013:        import java.util.Locale;
014:
015:        import org.eclipse.core.resources.IProject;
016:        import org.eclipse.core.runtime.IStatus;
017:        import org.eclipse.jdt.core.JavaConventions;
018:        import org.eclipse.pde.core.plugin.IPluginElement;
019:        import org.eclipse.pde.core.plugin.IPluginExtension;
020:        import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
021:        import org.eclipse.pde.core.plugin.IPluginObject;
022:        import org.eclipse.pde.internal.core.PDECore;
023:        import org.eclipse.pde.internal.core.ischema.ISchema;
024:        import org.eclipse.pde.internal.core.ischema.ISchemaAttribute;
025:        import org.eclipse.pde.internal.core.ischema.ISchemaElement;
026:        import org.eclipse.pde.internal.core.text.IDocumentAttributeNode;
027:        import org.eclipse.pde.internal.core.text.IDocumentElementNode;
028:        import org.eclipse.pde.internal.core.text.IDocumentRange;
029:        import org.eclipse.pde.internal.core.text.IDocumentTextNode;
030:        import org.eclipse.pde.internal.core.util.PDEJavaHelper;
031:        import org.eclipse.pde.internal.ui.PDEPlugin;
032:
033:        public abstract class XMLUtil {
034:
035:            /**
036:             * Scans up the node's parents till it reaches
037:             * a IPluginExtension or IPluginExtensionPoint (or null)
038:             * and returns the result.
039:             * 
040:             * @param node
041:             * @return the IPluginExtension or IPluginExtensionPoint that contains <code>node</code>
042:             */
043:            public static IPluginObject getTopLevelParent(IDocumentRange range) {
044:                IDocumentElementNode node = null;
045:                if (range instanceof  IDocumentAttributeNode)
046:                    node = ((IDocumentAttributeNode) range)
047:                            .getEnclosingElement();
048:                else if (range instanceof  IDocumentTextNode)
049:                    node = ((IDocumentTextNode) range).getEnclosingElement();
050:                else if (range instanceof  IPluginElement)
051:                    node = (IDocumentElementNode) range;
052:                else if (range instanceof  IPluginObject)
053:                    // not an attribute/text node/element -> return direct node
054:                    return (IPluginObject) range;
055:
056:                while (node != null && !(node instanceof  IPluginExtension)
057:                        && !(node instanceof  IPluginExtensionPoint))
058:                    node = node.getParentNode();
059:
060:                return node != null ? (IPluginObject) node : null;
061:            }
062:
063:            private static boolean withinRange(int start, int len, int offset) {
064:                return start <= offset && offset <= start + len;
065:            }
066:
067:            public static boolean withinRange(IDocumentRange range, int offset) {
068:                if (range instanceof  IDocumentAttributeNode)
069:                    return withinRange(((IDocumentAttributeNode) range)
070:                            .getValueOffset(), ((IDocumentAttributeNode) range)
071:                            .getValueLength(), offset);
072:                if (range instanceof  IDocumentElementNode)
073:                    return withinRange(((IDocumentElementNode) range)
074:                            .getOffset(), ((IDocumentElementNode) range)
075:                            .getLength(), offset);
076:                if (range instanceof  IDocumentTextNode)
077:                    return withinRange(((IDocumentTextNode) range).getOffset(),
078:                            ((IDocumentTextNode) range).getLength(), offset);
079:                return false;
080:            }
081:
082:            /**
083:             * Get the ISchemaElement corresponding to this IDocumentElementNode
084:             * @param node
085:             * @param extensionPoint the extension point of the schema, if <code>null</code> it will be deduced
086:             * @return the ISchemaElement for <code>node</code>
087:             */
088:            public static ISchemaElement getSchemaElement(
089:                    IDocumentElementNode node, String extensionPoint) {
090:                if (extensionPoint == null) {
091:                    IPluginObject obj = getTopLevelParent(node);
092:                    if (!(obj instanceof  IPluginExtension))
093:                        return null;
094:                    extensionPoint = ((IPluginExtension) obj).getPoint();
095:                }
096:                ISchema schema = PDECore.getDefault().getSchemaRegistry()
097:                        .getSchema(extensionPoint);
098:                if (schema == null)
099:                    return null;
100:
101:                ISchemaElement sElement = schema.findElement(node
102:                        .getXMLTagName());
103:                return sElement;
104:            }
105:
106:            /**
107:             * Get the ISchemaAttribute corresponding to this IDocumentAttributeNode
108:             * @param attr
109:             * @param extensionPoint the extension point of the schema, if <code>null</code> it will be deduced
110:             * @return the ISchemaAttribute for <code>attr</code>
111:             */
112:            public static ISchemaAttribute getSchemaAttribute(
113:                    IDocumentAttributeNode attr, String extensionPoint) {
114:                ISchemaElement ele = getSchemaElement(attr
115:                        .getEnclosingElement(), extensionPoint);
116:                if (ele == null)
117:                    return null;
118:
119:                return ele.getAttribute(attr.getAttributeName());
120:            }
121:
122:            /**
123:             * @param project
124:             * @param attInfo
125:             * @param counter
126:             * @return
127:             */
128:            public static String createDefaultClassName(IProject project,
129:                    ISchemaAttribute attInfo, int counter) {
130:                String tag = attInfo.getParent().getName();
131:                String expectedType = attInfo.getBasedOn();
132:                String className = ""; //$NON-NLS-1$
133:                if (expectedType == null) {
134:                    StringBuffer buf = new StringBuffer(tag);
135:                    buf.setCharAt(0, Character.toUpperCase(tag.charAt(0)));
136:                    className = buf.toString();
137:                } else {
138:                    // package will be the same as the plugin ID
139:                    // class name will be generated based on the required interface
140:                    className = expectedType;
141:                    int dotLoc = className.lastIndexOf('.');
142:                    if (dotLoc != -1)
143:                        className = className.substring(dotLoc + 1);
144:                    if (className.length() > 2 && className.charAt(0) == 'I'
145:                            && Character.isUpperCase(className.charAt(1)))
146:                        className = className.substring(1);
147:                }
148:                String packageName = createDefaultPackageName(project,
149:                        className);
150:                className += counter;
151:                return packageName + "." + className; //$NON-NLS-1$
152:            }
153:
154:            /**
155:             * @param id
156:             * @param className
157:             * @return
158:             */
159:            public static String createDefaultPackageName(IProject project,
160:                    String className) {
161:                String id = project.getName();
162:                StringBuffer buffer = new StringBuffer();
163:                IStatus status;
164:                for (int i = 0; i < id.length(); i++) {
165:                    char ch = id.charAt(i);
166:                    if (buffer.length() == 0) {
167:                        if (Character.isJavaIdentifierStart(ch))
168:                            buffer.append(Character.toLowerCase(ch));
169:                    } else {
170:                        if (Character.isJavaIdentifierPart(ch))
171:                            buffer.append(ch);
172:                        else if (ch == '.') {
173:                            status = JavaConventions.validatePackageName(buffer
174:                                    .toString(), PDEJavaHelper
175:                                    .getJavaSourceLevel(project), PDEJavaHelper
176:                                    .getJavaComplianceLevel(project));
177:                            if (status.getSeverity() == IStatus.ERROR)
178:                                buffer.append(className
179:                                        .toLowerCase(Locale.ENGLISH));
180:                            buffer.append(ch);
181:                        }
182:                    }
183:                }
184:
185:                status = JavaConventions.validatePackageName(buffer.toString(),
186:                        PDEJavaHelper.getJavaSourceLevel(project),
187:                        PDEJavaHelper.getJavaComplianceLevel(project));
188:                if (status.getSeverity() == IStatus.ERROR)
189:                    buffer.append(className.toLowerCase(Locale.ENGLISH));
190:
191:                return buffer.toString();
192:            }
193:
194:            /**
195:             * @param project
196:             * @param attInfo
197:             * @param counter
198:             * @return
199:             */
200:            public static String createDefaultName(IProject project,
201:                    ISchemaAttribute attInfo, int counter) {
202:                if (attInfo.getType().getName().equals("boolean")) //$NON-NLS-1$
203:                    return "true"; //$NON-NLS-1$
204:
205:                String tag = attInfo.getParent().getName();
206:                return project.getName() + "." + tag + counter; //$NON-NLS-1$
207:            }
208:
209:            /**
210:             * @param elementInfo
211:             * @return
212:             */
213:            public static int getCounterValue(ISchemaElement elementInfo) {
214:                Hashtable counters = PDEPlugin.getDefault()
215:                        .getDefaultNameCounters();
216:                String counterKey = getCounterKey(elementInfo);
217:                Integer counter = (Integer) counters.get(counterKey);
218:                if (counter == null) {
219:                    counter = new Integer(1);
220:                } else
221:                    counter = new Integer(counter.intValue() + 1);
222:                counters.put(counterKey, counter);
223:                return counter.intValue();
224:            }
225:
226:            public static String getCounterKey(ISchemaElement elementInfo) {
227:                return elementInfo.getSchema().getQualifiedPointId()
228:                        + "." + elementInfo.getName(); //$NON-NLS-1$
229:            }
230:
231:        }
w___w_w.___j__a___v___a2s_.c_o__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.