Source Code Cross Referenced for CodeClipHandler.java in  » IDE-Netbeans » visualweb.api.designer » org » netbeans » modules » visualweb » palette » codeclips » 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.palette.codeclips 
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:         * CodeClipHandler.java
043:         *
044:         * Created on July 27, 2006, 10:16 AM
045:         *
046:         * Handler/SAX parser that grabs the data from the file
047:         *
048:         * @author Joelle Lam <joelle.lam@sun.com>
049:         * @version %I%, %G%
050:         * @see layer.xml
051:         */
052:
053:        package org.netbeans.modules.visualweb.palette.codeclips;
054:
055:        import java.util.LinkedList;
056:        import org.openide.util.NbBundle;
057:        import org.xml.sax.Attributes;
058:        import org.xml.sax.SAXException;
059:        import org.xml.sax.helpers.DefaultHandler;
060:
061:        public final class CodeClipHandler extends DefaultHandler {
062:
063:            public static final String XML_ROOT = "codeclip_palette_item"; // NOI18N
064:            public static final String ATTR_VERSION = "version"; // NOI18N
065:            public static final String LATEST_VERSION = "1.0"; // NOI18N
066:            public static final String TAG_BODY = "body"; // NOI18N
067:            public static final String ATTR_CLASSNAME = "name"; // NOI18N
068:            public static final String ATTR_CUSTNAME = "name"; // NOI18N
069:            public static final String TAG_ICON16 = "icon16"; // NOI18N
070:            public static final String ATTR_URL = "urlvalue"; // NOI18N
071:            public static final String TAG_ICON32 = "icon32"; // NOI18N
072:            public static final String TAG_DESCRIPTION = "description"; // NOI18N
073:            public static final String ATTR_BUNDLE = "localizing-bundle"; // NOI18N
074:            public static final String ATTR_DISPLAY_NAME_KEY = "display-name-key"; // NOI18N
075:            public static final String ATTR_TOOLTIP_KEY = "tooltip-key"; // NOI18N
076:
077:            private LinkedList<String> bodyLines;
078:            private boolean insideBody = false;
079:
080:            //raw data read from the file
081:            //    private HashMap attributeMap;
082:            private String body;
083:            private String icon16URL;
084:            private String icon32URL;
085:            private String bundleName;
086:            private String displayNameKey;
087:            private String tooltipKey;
088:
089:            public String getBody() {
090:                return body;
091:            }
092:
093:            public String getIcon16URL() {
094:                return icon16URL;
095:            }
096:
097:            public String getIcon32URL() {
098:                return icon32URL;
099:            }
100:
101:            public String getBundleName() {
102:                return bundleName;
103:            }
104:
105:            public String getDisplayNameKey() {
106:                return displayNameKey;
107:            }
108:
109:            public String getTooltipKey() {
110:                return tooltipKey;
111:            }
112:
113:            @Override
114:            public void startElement(String uri, String localName,
115:                    String qName, Attributes attributes) throws SAXException {
116:                if (XML_ROOT.equals(qName)) {
117:                    String version = attributes.getValue(ATTR_VERSION);
118:                    if (version == null) {
119:                        String message = NbBundle.getBundle(
120:                                CodeClipHandler.class).getString(
121:                                "MSG_UnknownEditorPaletteItemVersion"); // NOI18N
122:                        throw new SAXException(message);
123:                    } else if (!version.equals(LATEST_VERSION)) { // NOI18N
124:                        String message = NbBundle.getBundle(
125:                                CodeClipHandler.class).getString(
126:                                "MSG_UnsupportedEditorPaletteItemVersion"); // NOI18N
127:                        throw new SAXException(message);
128:                    }
129:                } else if (TAG_BODY.equals(qName)) {
130:                    bodyLines = new LinkedList<String>();
131:                    insideBody = true;
132:                    //We could ultimately parse the body here?  Then we don't need to figure out the bundle.property file.
133:                } else if (TAG_ICON16.equals(qName)) {
134:                    icon16URL = attributes.getValue(ATTR_URL);
135:                    // TODO support also class resource name for icons
136:                } else if (TAG_ICON32.equals(qName)) {
137:                    icon32URL = attributes.getValue(ATTR_URL);
138:                    // TODO support also class resource name for icons
139:                } else if (TAG_DESCRIPTION.equals(qName)) {
140:                    bundleName = attributes.getValue(ATTR_BUNDLE);
141:                    displayNameKey = attributes.getValue(ATTR_DISPLAY_NAME_KEY);
142:                    tooltipKey = attributes.getValue(ATTR_TOOLTIP_KEY);
143:                }
144:            }
145:
146:            public void endElement(String uri, String localName, String qName)
147:                    throws SAXException {
148:
149:                if (TAG_BODY.equals(qName)) {
150:                    insideBody = false;
151:                    body = trimSurroundingLines(bodyLines);
152:                }
153:            }
154:
155:            public void characters(char buf[], int offset, int len)
156:                    throws SAXException {
157:                if (insideBody) {
158:                    String chars = new String(buf, offset, len).trim();
159:                    bodyLines.add(chars + "\n");
160:                }
161:            }
162:
163:            /**
164:             * Trims empty lines from the beginning and the end of the line list
165:             */
166:            private String trimSurroundingLines(LinkedList/*<String>*/lines) {
167:
168:                int nlines = lines.size();
169:
170:                int firstNonEmpty = nlines;
171:
172:                //going from the beginning and skipping empty lines until the first nonempty line occurs
173:                for (int i = 0; i < firstNonEmpty; i++) {
174:                    String line = (String) lines.get(i);
175:                    if (line.trim().length() != 0)
176:                        firstNonEmpty = i;
177:                }
178:
179:                int lastNonEmpty = -1;
180:
181:                //going from the end and skipping empty lines until the first nonempty line occurs
182:                for (int i = nlines - 1; i > lastNonEmpty; i--) {
183:                    String line = (String) lines.get(i);
184:                    if (line.trim().length() != 0)
185:                        lastNonEmpty = i;
186:                }
187:
188:                StringBuffer sb = new StringBuffer();
189:                for (int i = firstNonEmpty; i <= lastNonEmpty; i++)
190:                    sb.append((String) lines.get(i));
191:
192:                String body = sb.toString();
193:                if (body.length() > 0 && body.charAt(body.length() - 1) == '\n') // cut trailing new-line
194:                    body = body.substring(0, body.length() - 1);
195:
196:                return body;
197:            }
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.