KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > builders > NativeCodeAttributeValues


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.pde.internal.core.builders;
13
14 import java.io.IOException JavaDoc;
15 import java.io.InputStream JavaDoc;
16 import java.util.ArrayList JavaDoc;
17 import java.util.Iterator JavaDoc;
18 import java.util.List JavaDoc;
19 import java.util.Map JavaDoc;
20 import java.util.Properties JavaDoc;
21 import java.util.SortedSet JavaDoc;
22 import java.util.StringTokenizer JavaDoc;
23 import java.util.TreeSet JavaDoc;
24 import java.util.zip.ZipEntry JavaDoc;
25 import java.util.zip.ZipFile JavaDoc;
26
27 import org.eclipse.osgi.service.resolver.BundleDescription;
28 import org.eclipse.pde.core.plugin.IPluginModelBase;
29 import org.eclipse.pde.internal.core.PDECore;
30
31 public class NativeCodeAttributeValues {
32
33     // ISO 639 CODES ALPHABETIC BY LANGUAGE NAME
34
public final static int LANGUAGE_NAME= 0;
35     public final static int LANGUAGE_CODE= 1;
36     public final static String JavaDoc[][] LANGUAGES=
37         {
38             {"Abkhazian", "ab"}, //$NON-NLS-1$ //$NON-NLS-2$
39
{"Afan (Oromo)", "om"}, //$NON-NLS-1$ //$NON-NLS-2$
40
{"Afar", "aa"}, //$NON-NLS-1$ //$NON-NLS-2$
41
{"Afrikaans", "af"}, //$NON-NLS-1$ //$NON-NLS-2$
42
{"Albanian", "sq"}, //$NON-NLS-1$ //$NON-NLS-2$
43
{"Amharic", "am"}, //$NON-NLS-1$ //$NON-NLS-2$
44
{"Arabic", "ar"}, //$NON-NLS-1$ //$NON-NLS-2$
45
{"Armenian", "hy"}, //$NON-NLS-1$ //$NON-NLS-2$
46
{"Assamese", "as"}, //$NON-NLS-1$ //$NON-NLS-2$
47
{"Aymara", "ay"}, //$NON-NLS-1$ //$NON-NLS-2$
48
{"Azerbaijani", "az"}, //$NON-NLS-1$ //$NON-NLS-2$
49

50             {"Bashkir", "ba"}, //$NON-NLS-1$ //$NON-NLS-2$
51
{"Basque", "eu"}, //$NON-NLS-1$ //$NON-NLS-2$
52
{"Bengali;Bangla", "bn"}, //$NON-NLS-1$ //$NON-NLS-2$
53
{"Bhutani", "dz"}, //$NON-NLS-1$ //$NON-NLS-2$
54
{"Bihari", "bh"}, //$NON-NLS-1$ //$NON-NLS-2$
55
{"Bislama", "bi"}, //$NON-NLS-1$ //$NON-NLS-2$
56
{"Breton", "br"}, //$NON-NLS-1$ //$NON-NLS-2$
57
{"Bulgarian", "bg"}, //$NON-NLS-1$ //$NON-NLS-2$
58
{"Burmese", "my"}, //$NON-NLS-1$ //$NON-NLS-2$
59
{"Byelorussian", "be"}, //$NON-NLS-1$ //$NON-NLS-2$
60

61             {"Cambodian", "km"}, //$NON-NLS-1$ //$NON-NLS-2$
62
{"Catalan", "ca"}, //$NON-NLS-1$ //$NON-NLS-2$
63
{"Chinese", "zh"}, //$NON-NLS-1$ //$NON-NLS-2$
64
{"Corsican", "co"}, //$NON-NLS-1$ //$NON-NLS-2$
65
{"Croatian", "hr"}, //$NON-NLS-1$ //$NON-NLS-2$
66
{"Czech", "cs"}, //$NON-NLS-1$ //$NON-NLS-2$
67

68             {"Danish", "da"}, //$NON-NLS-1$ //$NON-NLS-2$
69
{"Dutch", "nl"}, //$NON-NLS-1$ //$NON-NLS-2$
70

71             {"English", "en"}, //$NON-NLS-1$ //$NON-NLS-2$
72
{"Esperanto", "eo"}, //$NON-NLS-1$ //$NON-NLS-2$
73
{"Estonian", "et"}, //$NON-NLS-1$ //$NON-NLS-2$
74

75             {"Faroese", "fo"}, //$NON-NLS-1$ //$NON-NLS-2$
76
{"Fiji", "fj"}, //$NON-NLS-1$ //$NON-NLS-2$
77
{"Finnish", "fi"}, //$NON-NLS-1$ //$NON-NLS-2$
78
{"French", "fr"}, //$NON-NLS-1$ //$NON-NLS-2$
79
{"Frisian", "fy"}, //$NON-NLS-1$ //$NON-NLS-2$
80

81             {"Galician", "gl"}, //$NON-NLS-1$ //$NON-NLS-2$
82
{"Georgian", "ka"}, //$NON-NLS-1$ //$NON-NLS-2$
83
{"German", "de"}, //$NON-NLS-1$ //$NON-NLS-2$
84
{"Greek", "el"}, //$NON-NLS-1$ //$NON-NLS-2$
85
{"Greenlandic", "kl"}, //$NON-NLS-1$ //$NON-NLS-2$
86
{"Guarani", "gn"}, //$NON-NLS-1$ //$NON-NLS-2$
87
{"Gujarati", "gu"}, //$NON-NLS-1$ //$NON-NLS-2$
88

89             {"Hausa", "ha"}, //$NON-NLS-1$ //$NON-NLS-2$
90
{"Hebrew", "he"}, //$NON-NLS-1$ //$NON-NLS-2$
91
{"Hindi", "hi"}, //$NON-NLS-1$ //$NON-NLS-2$
92
{"Hungarian", "hu"}, //$NON-NLS-1$ //$NON-NLS-2$
93

94             {"Icelandic", "is"}, //$NON-NLS-1$ //$NON-NLS-2$
95
{"Indonesian", "id"}, //$NON-NLS-1$ //$NON-NLS-2$
96
{"Interlingua", "ia"}, //$NON-NLS-1$ //$NON-NLS-2$
97
{"Interlingue", "ie"}, //$NON-NLS-1$ //$NON-NLS-2$
98
{"Inuktitut", "iu"}, //$NON-NLS-1$ //$NON-NLS-2$
99
{"Inupiak", "ik"}, //$NON-NLS-1$ //$NON-NLS-2$
100
{"Irish", "ga"}, //$NON-NLS-1$ //$NON-NLS-2$
101
{"Italian", "it"}, //$NON-NLS-1$ //$NON-NLS-2$
102

103             {"Japanese", "ja"}, //$NON-NLS-1$ //$NON-NLS-2$
104
{"Javanese", "jv"}, //$NON-NLS-1$ //$NON-NLS-2$
105

106             {"Kannada", "kn"}, //$NON-NLS-1$ //$NON-NLS-2$
107
{"Kashmiri", "ks"}, //$NON-NLS-1$ //$NON-NLS-2$
108
{"Kazakh", "kk"}, //$NON-NLS-1$ //$NON-NLS-2$
109
{"Kinyarwanda", "rw"}, //$NON-NLS-1$ //$NON-NLS-2$
110
{"Kirghiz", "ky"}, //$NON-NLS-1$ //$NON-NLS-2$
111
{"Kurundi", "rn"}, //$NON-NLS-1$ //$NON-NLS-2$
112
{"Korean", "ko"}, //$NON-NLS-1$ //$NON-NLS-2$
113
{"Kurdish", "ku"}, //$NON-NLS-1$ //$NON-NLS-2$
114

115             {"Laothian", "lo"}, //$NON-NLS-1$ //$NON-NLS-2$
116
{"Latin", "la"}, //$NON-NLS-1$ //$NON-NLS-2$
117
{"Latvian;Lettish", "lv"}, //$NON-NLS-1$ //$NON-NLS-2$
118
{"Lingala", "ln"}, //$NON-NLS-1$ //$NON-NLS-2$
119
{"Lithuanian", "lt"}, //$NON-NLS-1$ //$NON-NLS-2$
120

121             {"Macedonian", "mk"}, //$NON-NLS-1$ //$NON-NLS-2$
122
{"Malagasy", "mg"}, //$NON-NLS-1$ //$NON-NLS-2$
123
{"Malay", "ms"}, //$NON-NLS-1$ //$NON-NLS-2$
124
{"Malayalam", "ml"}, //$NON-NLS-1$ //$NON-NLS-2$
125
{"Maltese", "mt"}, //$NON-NLS-1$ //$NON-NLS-2$
126
{"Maori", "mi"}, //$NON-NLS-1$ //$NON-NLS-2$
127
{"Marathi", "mr"}, //$NON-NLS-1$ //$NON-NLS-2$
128
{"Moldavian", "mo"}, //$NON-NLS-1$ //$NON-NLS-2$
129
{"Mongolian", "mn"}, //$NON-NLS-1$ //$NON-NLS-2$
130

131             {"Nauru", "na"}, //$NON-NLS-1$ //$NON-NLS-2$
132
{"Nepali", "ne"}, //$NON-NLS-1$ //$NON-NLS-2$
133
{"Norwegian", "no"}, //$NON-NLS-1$ //$NON-NLS-2$
134

135             {"Occitan", "oc"}, //$NON-NLS-1$ //$NON-NLS-2$
136
{"Oriya", "or"}, //$NON-NLS-1$ //$NON-NLS-2$
137

138             {"Pashto;Pushto", "ps"}, //$NON-NLS-1$ //$NON-NLS-2$
139
{"Persian (Farsi)", "fa"}, //$NON-NLS-1$ //$NON-NLS-2$
140
{"Polish", "pl"}, //$NON-NLS-1$ //$NON-NLS-2$
141
{"Portuguese", "pt"}, //$NON-NLS-1$ //$NON-NLS-2$
142
{"Punjabi", "pa"}, //$NON-NLS-1$ //$NON-NLS-2$
143

144             {"Quechua", "qu"}, //$NON-NLS-1$ //$NON-NLS-2$
145

146             {"Rhaeto-Romance", "rm"}, //$NON-NLS-1$ //$NON-NLS-2$
147
{"Romanian", "ro"}, //$NON-NLS-1$ //$NON-NLS-2$
148
{"Russian", "ru"}, //$NON-NLS-1$ //$NON-NLS-2$
149

150             {"Samoan", "sm"}, //$NON-NLS-1$ //$NON-NLS-2$
151
{"Sangho", "sg"}, //$NON-NLS-1$ //$NON-NLS-2$
152
{"Sanskrit", "sa"}, //$NON-NLS-1$ //$NON-NLS-2$
153
{"Scots Gaelic", "gd"}, //$NON-NLS-1$ //$NON-NLS-2$
154
{"Serbian", "sr"}, //$NON-NLS-1$ //$NON-NLS-2$
155
{"Serbo-Croatian", "sh"}, //$NON-NLS-1$ //$NON-NLS-2$
156
{"Sesotho", "st"}, //$NON-NLS-1$ //$NON-NLS-2$
157
{"Setswana", "tn"}, //$NON-NLS-1$ //$NON-NLS-2$
158
{"Shona", "sn"}, //$NON-NLS-1$ //$NON-NLS-2$
159
{"Sindhi", "sd"}, //$NON-NLS-1$ //$NON-NLS-2$
160
{"Singhalese", "si"}, //$NON-NLS-1$ //$NON-NLS-2$
161
{"Siswati", "ss"}, //$NON-NLS-1$ //$NON-NLS-2$
162
{"Slovak", "sk"}, //$NON-NLS-1$ //$NON-NLS-2$
163
{"Slovenian", "sl"}, //$NON-NLS-1$ //$NON-NLS-2$
164
{"Somali", "so"}, //$NON-NLS-1$ //$NON-NLS-2$
165
{"Spanish", "es"}, //$NON-NLS-1$ //$NON-NLS-2$
166
{"Sundanese", "su"}, //$NON-NLS-1$ //$NON-NLS-2$
167
{"Swahili", "sw"}, //$NON-NLS-1$ //$NON-NLS-2$
168
{"Swedish", "sv"}, //$NON-NLS-1$ //$NON-NLS-2$
169

170             {"Tagalog", "tl"}, //$NON-NLS-1$ //$NON-NLS-2$
171
{"Tajik", "tg"}, //$NON-NLS-1$ //$NON-NLS-2$
172
{"Tamil", "ta"}, //$NON-NLS-1$ //$NON-NLS-2$
173
{"Tatar", "tt"}, //$NON-NLS-1$ //$NON-NLS-2$
174
{"Telugu", "te"}, //$NON-NLS-1$ //$NON-NLS-2$
175
{"Thai", "th"}, //$NON-NLS-1$ //$NON-NLS-2$
176
{"Tibetan", "bo"}, //$NON-NLS-1$ //$NON-NLS-2$
177
{"Tigrinya", "ti"}, //$NON-NLS-1$ //$NON-NLS-2$
178
{"Tonga", "to"}, //$NON-NLS-1$ //$NON-NLS-2$
179
{"Tsonga", "ts"}, //$NON-NLS-1$ //$NON-NLS-2$
180
{"Turkish", "tr"}, //$NON-NLS-1$ //$NON-NLS-2$
181
{"Turkmen", "tk"}, //$NON-NLS-1$ //$NON-NLS-2$
182
{"Twi", "tw"}, //$NON-NLS-1$ //$NON-NLS-2$
183

184             {"Uigur", "ug"}, //$NON-NLS-1$ //$NON-NLS-2$
185
{"Ukrainian", "uk"}, //$NON-NLS-1$ //$NON-NLS-2$
186
{"Urdu", "ur"}, //$NON-NLS-1$ //$NON-NLS-2$
187
{"Uzbek", "uz"}, //$NON-NLS-1$ //$NON-NLS-2$
188

189             {"Vietnamese", "vi"}, //$NON-NLS-1$ //$NON-NLS-2$
190
{"Volapuk", "vo"}, //$NON-NLS-1$ //$NON-NLS-2$
191

192             {"Welsh", "cy"}, //$NON-NLS-1$ //$NON-NLS-2$
193
{"Wolof", "wo"}, //$NON-NLS-1$ //$NON-NLS-2$
194

195             {"Xhosa", "xh"}, //$NON-NLS-1$ //$NON-NLS-2$
196

197             {"Yiddish", "yi"}, //$NON-NLS-1$ //$NON-NLS-2$
198
{"Yoruba", "yo"}, //$NON-NLS-1$ //$NON-NLS-2$
199

200             {"Zhuang", "za"}, //$NON-NLS-1$ //$NON-NLS-2$
201
{"Zulu", "zu"}, //$NON-NLS-1$ //$NON-NLS-2$
202
};
203     
204     public final static String JavaDoc[] EXCLUDE_FILES= new String JavaDoc[]
205         { ".classpath", //$NON-NLS-1$
206
".project", //$NON-NLS-1$
207
"plugin.xml", //$NON-NLS-1$
208
"fragment.xml", //$NON-NLS-1$
209
"build.properties", //$NON-NLS-1$
210
"META-INF/MANIFEST.MF" }; //$NON-NLS-1$
211

212     private static final String JavaDoc OSNAME_ALIASES_LOCATION= "org/eclipse/osgi/framework/internal/core/osname.aliases"; //$NON-NLS-1$
213
private static final String JavaDoc PROCESSOR_ALIASES_LOCATION= "org/eclipse/osgi/framework/internal/core/processor.aliases"; //$NON-NLS-1$
214

215     // Tokenizer constants.
216
private static final String JavaDoc SPACE= " "; //$NON-NLS-1$
217
private static final String JavaDoc QUOTE= "\""; //$NON-NLS-1$
218
private static final String JavaDoc COMMENT= "#"; //$NON-NLS-1$
219

220     // OS & Processor Types
221
public static String JavaDoc[] OS_TYPES= new String JavaDoc [0];
222     public static String JavaDoc[] ADDITIONAL_OS_ALIASES= new String JavaDoc [0];
223     public static String JavaDoc[] PROCESSOR_TYPES= new String JavaDoc [0];
224     public static String JavaDoc[] ADDITIONAL_PROCESSOR_ALIASES= new String JavaDoc [0];
225     static {
226         ZipFile JavaDoc smfJar= null;
227         try {
228             
229             IPluginModelBase model = PDECore.getDefault().getModelManager().findModel("org.eclipse.osgi"); //$NON-NLS-1$
230
if (model!=null)
231             {
232                 BundleDescription desc = model.getBundleDescription();
233                 if (desc != null)
234                 {
235                     //find path to org.eclipse.osgi plugin
236
String JavaDoc path = desc.getLocation();
237                     smfJar= new ZipFile JavaDoc(path+"\\core.jar"); //$NON-NLS-1$
238
if (smfJar!=null)
239                     {
240                         initializeOSTypes(smfJar);
241                         initializeProcessorTypes(smfJar);
242                     }
243                 }
244             }
245
246         } catch (IOException JavaDoc ex) {
247             
248         } finally {
249             try {
250                 if (smfJar != null)
251                     smfJar.close();
252             } catch (IOException JavaDoc ex) {
253             }
254         }
255     }
256     
257     static void initializeOSTypes(ZipFile JavaDoc smfJar) {
258         try {
259             ZipEntry JavaDoc aliasFile= smfJar.getEntry(OSNAME_ALIASES_LOCATION);
260             InputStream JavaDoc is= smfJar.getInputStream(aliasFile);
261             Properties JavaDoc properties= new Properties JavaDoc();
262             properties.load(is);
263             SortedSet JavaDoc osTypes= new TreeSet JavaDoc();
264             List JavaDoc additionalOSAliases= new ArrayList JavaDoc();
265             
266             Iterator JavaDoc it= properties.entrySet().iterator();
267             while (it.hasNext()) {
268                 Map.Entry JavaDoc entry= (Map.Entry JavaDoc) it.next();
269                 osTypes.add(entry.getKey());
270                 parseAliases((String JavaDoc) entry.getValue(), additionalOSAliases);
271             }
272             
273             OS_TYPES= new String JavaDoc[osTypes.size()];
274             osTypes.toArray(OS_TYPES);
275             
276             ADDITIONAL_OS_ALIASES= new String JavaDoc[additionalOSAliases.size()];
277             additionalOSAliases.toArray(ADDITIONAL_OS_ALIASES);
278             
279         } catch (IOException JavaDoc ex) {
280             PDECore.logException(ex);
281         }
282     }
283     
284     static void initializeProcessorTypes(ZipFile JavaDoc smfJar) {
285         try {
286             ZipEntry JavaDoc aliasFile= smfJar.getEntry(PROCESSOR_ALIASES_LOCATION);
287             InputStream JavaDoc is= smfJar.getInputStream(aliasFile);
288             Properties JavaDoc properties= new Properties JavaDoc();
289             properties.load(is);
290             SortedSet JavaDoc processorTypes= new TreeSet JavaDoc();
291             List JavaDoc additionalProcessorAliases= new ArrayList JavaDoc();
292             
293             Iterator JavaDoc it= properties.entrySet().iterator();
294             while (it.hasNext()) {
295                 Map.Entry JavaDoc entry= (Map.Entry JavaDoc) it.next();
296                 processorTypes.add(entry.getKey());
297                 parseAliases((String JavaDoc) entry.getValue(), additionalProcessorAliases);
298             }
299             
300             PROCESSOR_TYPES= new String JavaDoc[processorTypes.size()];
301             processorTypes.toArray(PROCESSOR_TYPES);
302             
303             ADDITIONAL_PROCESSOR_ALIASES= new String JavaDoc[additionalProcessorAliases.size()];
304             additionalProcessorAliases.toArray(ADDITIONAL_PROCESSOR_ALIASES);
305             
306         } catch (IOException JavaDoc ex) {
307             PDECore.logException(ex);
308         }
309     }
310     
311     static void parseAliases(String JavaDoc line, List JavaDoc aliases) {
312         boolean inQuote= false;
313         StringTokenizer JavaDoc outer= new StringTokenizer JavaDoc(line, QUOTE, true);
314         while (outer.hasMoreTokens()) {
315             String JavaDoc token= outer.nextToken();
316             if (token.equals(QUOTE)) {
317                 inQuote= !inQuote;
318             } else if (inQuote) {
319                 aliases.add(token);
320             } else {
321                 StringTokenizer JavaDoc inner= new StringTokenizer JavaDoc(token, SPACE, false);
322                 while (inner.hasMoreTokens()) {
323                     String JavaDoc next= inner.nextToken();
324                     // Stop processing the line when a comment is detected.
325
if (next.startsWith(COMMENT)) return;
326                     aliases.add(next);
327                 }
328             }
329         }
330     }
331     
332 }
333
Popular Tags