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


001:        /*******************************************************************************
002:         * Copyright (c) 2004, 2006 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.ui.ide;
011:
012:        import java.nio.charset.Charset;
013:        import java.nio.charset.IllegalCharsetNameException;
014:        import java.util.ArrayList;
015:        import java.util.Collection;
016:        import java.util.Collections;
017:        import java.util.Iterator;
018:        import java.util.List;
019:
020:        import org.eclipse.core.resources.ResourcesPlugin;
021:        import org.eclipse.core.runtime.content.IContentDescription;
022:        import org.eclipse.osgi.util.NLS;
023:        import org.eclipse.ui.WorkbenchEncoding;
024:        import org.eclipse.ui.internal.WorkbenchPlugin;
025:        import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
026:        import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
027:
028:        /**
029:         * IDEEncoding is a utility class for managing encoding information that
030:         * includes user preferences from the IDE and core resources.
031:         * <p>
032:         * This class provides all its functionality via static methods.
033:         * It is not intended to be instantiated or subclassed.
034:         * </p>
035:         * 
036:         * @see org.eclipse.ui.WorkbenchEncoding
037:         * @see org.eclipse.core.resources.ResourcesPlugin
038:         * @since 3.1
039:         */
040:        public final class IDEEncoding {
041:
042:            private IDEEncoding() {
043:                // prevent instantiation
044:            }
045:
046:            //The preference for the user entered encodings.
047:            private static String IDE_ENCODINGS_PREFERENCE = "IDE_ENCODINGS_PREFERENCE"; //$NON-NLS-1$
048:
049:            private static String PREFERENCE_SEPARATOR = "'"; //$NON-NLS-1$
050:
051:            /**
052:             * Display constant for the UTF 8 byte order marker for resources.
053:             */
054:            public static String BOM_UTF_8 = "UTF-8 (BOM)";//$NON-NLS-1$
055:
056:            /**
057:             * Display constant for the UTF 16 big endian byte order marker for
058:             * resources.
059:             */
060:            public static String BOM_UTF_16BE = "UTF-16 Big-Endian (BOM)";//$NON-NLS-1$
061:
062:            /**
063:             * Display constant for the UTF 16 little endian byte order marker for
064:             * resources.
065:             */
066:            public static String BOM_UTF_16LE = "UTF-16 Little-Endian (BOM)";//$NON-NLS-1$
067:
068:            /**
069:             * Get all of the available encodings including any that were saved as a
070:             * preference in the IDE or in core resources.
071:             * 
072:             * @return List of String
073:             */
074:            public static List getIDEEncodings() {
075:                List encodings = getIDEEncodingsPreference();
076:                encodings.addAll(WorkbenchEncoding.getDefinedEncodings());
077:
078:                String enc = getResourceEncoding();
079:
080:                if (!(enc == null || encodings.contains(enc))) {
081:                    encodings.add(enc);
082:                }
083:
084:                Collections.sort(encodings);
085:                return encodings;
086:            }
087:
088:            /**
089:             * Get the current value of the encoding preference. If the value is not set
090:             * return <code>null</code>.
091:             * 
092:             * @return String
093:             */
094:            public static String getResourceEncoding() {
095:                String preference = ResourcesPlugin.getPlugin()
096:                        .getPluginPreferences().getString(
097:                                ResourcesPlugin.PREF_ENCODING);
098:                if (preference == null || preference.length() == 0) {
099:                    return null;
100:                }
101:                return preference;
102:            }
103:
104:            /**
105:             * Add value to the list of workbench encodings.
106:             * 
107:             * @param value
108:             */
109:            public static void addIDEEncoding(String value) {
110:
111:                if (WorkbenchEncoding.getDefinedEncodings().contains(value)) {
112:                    return;
113:                }
114:
115:                writeEncodingsPreference(value, getIDEEncodingsPreference());
116:
117:            }
118:
119:            /**
120:             * Write the encodings preference. If value is not null
121:             * and not already in the list of currentEncodings add
122:             * it to the list.
123:             * @param value String or <code>null</code>
124:             * @param encodings The list of encodings to write
125:             */
126:            private static void writeEncodingsPreference(String value,
127:                    Collection encodings) {
128:                boolean addValue = (value != null);
129:
130:                StringBuffer result = new StringBuffer();
131:
132:                Iterator currentEncodings = encodings.iterator();
133:
134:                while (currentEncodings.hasNext()) {
135:                    String string = (String) currentEncodings.next();
136:                    result.append(string);
137:                    result.append(PREFERENCE_SEPARATOR);
138:                    if (addValue && string.equals(value)) {
139:                        addValue = false;
140:                    }
141:                }
142:
143:                if (addValue) {
144:                    result.append(value);
145:                }
146:
147:                IDEWorkbenchPlugin.getDefault().getPreferenceStore().setValue(
148:                        IDE_ENCODINGS_PREFERENCE, result.toString());
149:            }
150:
151:            /**
152:             * Get the value of the encodings preference.
153:             * 
154:             * @return List
155:             */
156:            private static List getIDEEncodingsPreference() {
157:
158:                boolean updateRequired = false;
159:
160:                String encodings = IDEWorkbenchPlugin.getDefault()
161:                        .getPreferenceStore().getString(
162:                                IDE_ENCODINGS_PREFERENCE);
163:
164:                if (encodings == null || encodings.length() == 0) {
165:                    return new ArrayList();
166:                }
167:
168:                String[] preferenceEncodings = encodings
169:                        .split(PREFERENCE_SEPARATOR);
170:                ArrayList result = new ArrayList();
171:
172:                //Drop any encodings that are not valid
173:                for (int i = 0; i < preferenceEncodings.length; i++) {
174:                    String string = preferenceEncodings[i];
175:                    boolean isSupported;
176:                    try {
177:                        isSupported = Charset.isSupported(string);
178:                    } catch (IllegalCharsetNameException e) {
179:                        isSupported = false;
180:                    }
181:                    if (isSupported) {
182:                        result.add(string);
183:                    } else {
184:                        WorkbenchPlugin
185:                                .log(NLS
186:                                        .bind(
187:                                                IDEWorkbenchMessages.WorkbenchEncoding_invalidCharset,
188:                                                string));
189:                        updateRequired = true;
190:                    }
191:
192:                }
193:
194:                if (updateRequired) {
195:                    writeEncodingsPreference(null, result);
196:                }
197:                return result;
198:
199:            }
200:
201:            /**
202:             * Clear the IDE encodings preference.
203:             */
204:            public static void clearUserEncodings() {
205:                IDEWorkbenchPlugin.getDefault().getPreferenceStore()
206:                        .setToDefault(IDE_ENCODINGS_PREFERENCE);
207:            }
208:
209:            /**
210:             * Get the displayable string for the byte order marking from the supplied
211:             * file description.
212:             * 
213:             * @param description
214:             *            The description to query. May be <code>null</code>.
215:             * @return String or <code>null</code> if the byte order mark cannot be
216:             *         found or the description is <code>null</code>.
217:             * @see IContentDescription#getProperty(org.eclipse.core.runtime.QualifiedName)
218:             */
219:            public static String getByteOrderMarkLabel(
220:                    IContentDescription description) {
221:
222:                if (description == null) {
223:                    return null;
224:                }
225:
226:                byte[] bom = (byte[]) description
227:                        .getProperty(IContentDescription.BYTE_ORDER_MARK);
228:                if (bom == null) {
229:                    return null;
230:                }
231:                if (bom == IContentDescription.BOM_UTF_8) {
232:                    return IDEEncoding.BOM_UTF_8;
233:                }
234:                if (bom == IContentDescription.BOM_UTF_16BE) {
235:                    return IDEEncoding.BOM_UTF_16BE;
236:                }
237:                if (bom == IContentDescription.BOM_UTF_16LE) {
238:                    return IDEEncoding.BOM_UTF_16LE;
239:                }
240:
241:                return null;
242:            }
243:
244:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.