KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > converter > PluginConverterParser


1 /*******************************************************************************
2  * Copyright (c) 2000, 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 package org.eclipse.pde.internal.core.converter;
12
13 import java.io.InputStream JavaDoc;
14 import java.util.*;
15 import javax.xml.parsers.SAXParserFactory JavaDoc;
16
17 import org.eclipse.osgi.util.NLS;
18 import org.eclipse.pde.internal.core.PDECoreMessages;
19 import org.osgi.framework.BundleContext;
20 import org.osgi.framework.Version;
21 import org.osgi.util.tracker.ServiceTracker;
22 import org.xml.sax.*;
23 import org.xml.sax.helpers.DefaultHandler JavaDoc;
24
25 /**
26  * Internal class.
27  */

28 public class PluginConverterParser extends DefaultHandler JavaDoc implements IModel {
29     private static ServiceTracker xmlTracker = null;
30
31     private PluginInfo manifestInfo = new PluginInfo();
32     private BundleContext context;
33     private Version target; // The targeted platform for the given manifest
34
private static final Version TARGET21 = new Version(2, 1, 0);
35
36     public class PluginInfo {
37         private String JavaDoc schemaVersion;
38         private String JavaDoc pluginId;
39         private String JavaDoc version;
40         private String JavaDoc vendor;
41
42         // an ordered list of library path names.
43
private ArrayList libraryPaths;
44         // TODO Should get rid of the libraries map and just have a
45
// list of library export statements instead. Library paths must
46
// preserve order.
47
private Map libraries; //represent the libraries and their export statement
48
private ArrayList requires;
49         private boolean requiresExpanded = false; //indicates if the requires have been processed.
50
private boolean compatibilityFound = false; //set to true is the requirement list contain compatilibity
51
private String JavaDoc pluginClass;
52         private String JavaDoc masterPluginId;
53         private String JavaDoc masterVersion;
54         private String JavaDoc masterMatch;
55         private Set filters;
56         private String JavaDoc pluginName;
57         private boolean singleton;
58         private boolean fragment;
59         private final static String JavaDoc TARGET21_STRING = "2.1"; //$NON-NLS-1$
60
private boolean hasExtensionExtensionPoints = false;
61
62         public boolean isFragment() {
63             return fragment;
64         }
65
66         public String JavaDoc toString() {
67             return "plugin-id: " + pluginId + " version: " + version + " libraries: " + libraries + " class:" + pluginClass + " master: " + masterPluginId + " master-version: " + masterVersion + " requires: " + requires + " singleton: " + singleton; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
68
}
69
70         public Map getLibraries() {
71             if (libraries == null)
72                 return new HashMap(0);
73             return libraries;
74         }
75
76         public ArrayList getRequires() {
77             if (!TARGET21.equals(target) && schemaVersion == null && !requiresExpanded) {
78                 requiresExpanded = true;
79                 if (requires == null) {
80                     requires = new ArrayList(1);
81                     requires.add(new Prerequisite(PluginConverter.PI_RUNTIME, TARGET21_STRING, false, false, IModel.PLUGIN_REQUIRES_MATCH_GREATER_OR_EQUAL));
82                     requires.add(new Prerequisite(PluginConverter.PI_RUNTIME_COMPATIBILITY, null, false, false, null));
83                 } else {
84                     //Add elements on the requirement list of ui and help.
85
for (int i = 0; i < requires.size(); i++) {
86                         Prerequisite analyzed = (Prerequisite) requires.get(i);
87                         if ("org.eclipse.ui".equals(analyzed.getName())) { //$NON-NLS-1$
88
requires.add(i + 1, new Prerequisite("org.eclipse.ui.workbench.texteditor", null, true, analyzed.isExported(), null)); //$NON-NLS-1$
89
requires.add(i + 1, new Prerequisite("org.eclipse.jface.text", null, true, analyzed.isExported(), null)); //$NON-NLS-1$
90
requires.add(i + 1, new Prerequisite("org.eclipse.ui.editors", null, true, analyzed.isExported(), null)); //$NON-NLS-1$
91
requires.add(i + 1, new Prerequisite("org.eclipse.ui.views", null, true, analyzed.isExported(), null)); //$NON-NLS-1$
92
requires.add(i + 1, new Prerequisite("org.eclipse.ui.ide", null, true, analyzed.isExported(), null)); //$NON-NLS-1$
93
} else if ("org.eclipse.help".equals(analyzed.getName())) { //$NON-NLS-1$
94
requires.add(i + 1, new Prerequisite("org.eclipse.help.base", null, true, analyzed.isExported(), null)); //$NON-NLS-1$
95
} else if (PluginConverter.PI_RUNTIME.equals(analyzed.getName()) && !compatibilityFound) {
96                             requires.add(i + 1, new Prerequisite(PluginConverter.PI_RUNTIME_COMPATIBILITY, null, false, analyzed.isExported(), null));
97                         }
98                     }
99                     if (!requires.contains(new Prerequisite(PluginConverter.PI_RUNTIME_COMPATIBILITY, null, false, false, null))) {
100                         requires.add(new Prerequisite(PluginConverter.PI_RUNTIME_COMPATIBILITY, null, false, false, null));
101                     }
102                     //Remove any prereq on runtime and add a prereq on runtime 2.1
103
//This is used to recognize the version for which the given plugin was initially targeted.
104
Prerequisite runtimePrereq = new Prerequisite(PluginConverter.PI_RUNTIME, null, false, false, null);
105                     requires.remove(runtimePrereq);
106                     requires.add(new Prerequisite(PluginConverter.PI_RUNTIME, TARGET21_STRING, false, false, IModel.PLUGIN_REQUIRES_MATCH_GREATER_OR_EQUAL));
107                 }
108             }
109             if (requires == null)
110                 return requires = new ArrayList(0);
111
112             return requires;
113         }
114
115         public String JavaDoc getMasterId() {
116             return masterPluginId;
117         }
118
119         public String JavaDoc getMasterVersion() {
120             return masterVersion;
121         }
122
123         public String JavaDoc getMasterMatch() {
124             return masterMatch;
125         }
126
127         public String JavaDoc getPluginClass() {
128             return pluginClass;
129         }
130
131         public String JavaDoc getUniqueId() {
132             return pluginId;
133         }
134
135         public String JavaDoc getVersion() {
136             return version;
137         }
138
139         public Set getPackageFilters() {
140             return filters;
141         }
142
143         public String JavaDoc[] getLibrariesName() {
144             if (libraryPaths == null)
145                 return new String JavaDoc[0];
146             return (String JavaDoc[]) libraryPaths.toArray(new String JavaDoc[libraryPaths.size()]);
147         }
148
149         public String JavaDoc getPluginName() {
150             return pluginName;
151         }
152
153         public String JavaDoc getProviderName() {
154             return vendor;
155         }
156
157         public boolean isSingleton() {
158             return singleton;
159         }
160
161         public boolean hasExtensionExtensionPoints() {
162             return hasExtensionExtensionPoints;
163         }
164         
165         public String JavaDoc getRoot() {
166             return isFragment() ? FRAGMENT : PLUGIN;
167         }
168
169         /*
170          * Provides some basic form of validation. Since plugin/fragment is the only mandatory
171          * attribute, it is the only one we cara about here.
172          */

173         public String JavaDoc validateForm() {
174             if (this.pluginId == null) {
175                 return NLS.bind(PDECoreMessages.PluginParser_EclipseConverterMissingAttribute, new String JavaDoc[] {getRoot(), PLUGIN_ID, getRoot()});
176             }
177             if (this.pluginName == null) {
178                 return NLS.bind(PDECoreMessages.PluginParser_EclipseConverterMissingAttribute, new String JavaDoc[] {getRoot(), PLUGIN_NAME, getRoot()});
179             }
180             if (this.version == null) {
181                 return NLS.bind(PDECoreMessages.PluginParser_EclipseConverterMissingAttribute, new String JavaDoc[] {getRoot(), PLUGIN_VERSION, getRoot()});
182             }
183             if (isFragment() && this.masterPluginId == null) {
184                 return NLS.bind(PDECoreMessages.PluginParser_EclipseConverterMissingAttribute, new String JavaDoc[] {getRoot(), FRAGMENT_PLUGIN_ID, getRoot()});
185             }
186             if (isFragment() && this.masterVersion == null) {
187                 return NLS.bind(PDECoreMessages.PluginParser_EclipseConverterMissingAttribute, new String JavaDoc[] {getRoot(), FRAGMENT_PLUGIN_VERSION, getRoot()});
188             }
189             return null;
190         }
191     }
192
193     // Current State Information
194
Stack stateStack = new Stack();
195
196     // Current object stack (used to hold the current object we are populating in this plugin info
197
Stack objectStack = new Stack();
198     Locator locator = null;
199
200     // Valid States
201
private static final int IGNORED_ELEMENT_STATE = 0;
202     private static final int INITIAL_STATE = 1;
203     private static final int PLUGIN_STATE = 2;
204     private static final int PLUGIN_RUNTIME_STATE = 3;
205     private static final int PLUGIN_REQUIRES_STATE = 4;
206     private static final int PLUGIN_EXTENSION_POINT_STATE = 5;
207     private static final int PLUGIN_EXTENSION_STATE = 6;
208     private static final int RUNTIME_LIBRARY_STATE = 7;
209     private static final int LIBRARY_EXPORT_STATE = 8;
210     private static final int PLUGIN_REQUIRES_IMPORT_STATE = 9;
211     private static final int FRAGMENT_STATE = 11;
212
213     public PluginConverterParser(BundleContext context, Version target) {
214         super();
215         this.context = context;
216         this.target = target;
217     }
218
219     /**
220      * Receive a Locator object for document events.
221      *
222      * <p>
223      * By default, do nothing. Application writers may override this method in
224      * a subclass if they wish to store the locator for use with other document
225      * events.
226      * </p>
227      *
228      * @param locator A locator for all SAX document events.
229      * @see org.xml.sax.ContentHandler#setDocumentLocator(org.xml.sax.Locator)
230      * @see org.xml.sax.Locator
231      */

232     public void setDocumentLocator(Locator locator) {
233         this.locator = locator;
234     }
235
236     public void endDocument() {
237     }
238
239     public void endElement(String JavaDoc uri, String JavaDoc elementName, String JavaDoc qName) {
240         switch (((Integer JavaDoc) stateStack.peek()).intValue()) {
241             case IGNORED_ELEMENT_STATE :
242                 stateStack.pop();
243                 break;
244             case INITIAL_STATE :
245                 // shouldn't get here
246
// internalError(Policy.bind("parse.internalStack", elementName)); //$NON-NLS-1$
247
break;
248             case PLUGIN_STATE :
249             case FRAGMENT_STATE :
250                 break;
251             case PLUGIN_RUNTIME_STATE :
252                 if (elementName.equals(RUNTIME)) {
253                     stateStack.pop();
254                 }
255                 break;
256             case PLUGIN_REQUIRES_STATE :
257                 if (elementName.equals(PLUGIN_REQUIRES)) {
258                     stateStack.pop();
259                     objectStack.pop();
260                 }
261                 break;
262             case PLUGIN_EXTENSION_POINT_STATE :
263                 if (elementName.equals(EXTENSION_POINT)) {
264                     stateStack.pop();
265                 }
266                 break;
267             case PLUGIN_EXTENSION_STATE :
268                 if (elementName.equals(EXTENSION)) {
269                     stateStack.pop();
270                 }
271                 break;
272             case RUNTIME_LIBRARY_STATE :
273                 if (elementName.equals(LIBRARY)) {
274                     String JavaDoc curLibrary = (String JavaDoc) objectStack.pop();
275                     if (!curLibrary.trim().equals("")) { //$NON-NLS-1$
276
Vector exportsVector = (Vector) objectStack.pop();
277                         if (manifestInfo.libraries == null) {
278                             manifestInfo.libraries = new HashMap(3);
279                             manifestInfo.libraryPaths = new ArrayList(3);
280                         }
281                         manifestInfo.libraries.put(curLibrary, exportsVector);
282                         manifestInfo.libraryPaths.add(curLibrary.replace('\\', '/'));
283                     }
284                     stateStack.pop();
285                 }
286                 break;
287             case LIBRARY_EXPORT_STATE :
288                 if (elementName.equals(LIBRARY_EXPORT)) {
289                     stateStack.pop();
290                 }
291                 break;
292             case PLUGIN_REQUIRES_IMPORT_STATE :
293                 if (elementName.equals(PLUGIN_REQUIRES_IMPORT)) {
294                     stateStack.pop();
295                 }
296                 break;
297         }
298     }
299
300     public void handleExtensionPointState(String JavaDoc elementName, Attributes attributes) {
301         // nothing to do for extension-points' children
302
stateStack.push(new Integer JavaDoc(IGNORED_ELEMENT_STATE));
303         manifestInfo.hasExtensionExtensionPoints = true;
304     }
305
306     public void handleExtensionState(String JavaDoc elementName, Attributes attributes) {
307         // nothing to do for extensions' children
308
stateStack.push(new Integer JavaDoc(IGNORED_ELEMENT_STATE));
309         manifestInfo.hasExtensionExtensionPoints = true;
310     }
311
312     public void handleInitialState(String JavaDoc elementName, Attributes attributes) {
313         if (elementName.equals(PLUGIN)) {
314             stateStack.push(new Integer JavaDoc(PLUGIN_STATE));
315             parsePluginAttributes(attributes);
316         } else if (elementName.equals(FRAGMENT)) {
317             manifestInfo.fragment = true;
318             stateStack.push(new Integer JavaDoc(FRAGMENT_STATE));
319             parseFragmentAttributes(attributes);
320         } else {
321             stateStack.push(new Integer JavaDoc(IGNORED_ELEMENT_STATE));
322             internalError(elementName);
323         }
324     }
325
326     public void handleLibraryExportState(String JavaDoc elementName, Attributes attributes) {
327         // All elements ignored.
328
stateStack.push(new Integer JavaDoc(IGNORED_ELEMENT_STATE));
329     }
330
331     public void handleLibraryState(String JavaDoc elementName, Attributes attributes) {
332         if (elementName.equals(LIBRARY_EXPORT)) {
333             // Change State
334
stateStack.push(new Integer JavaDoc(LIBRARY_EXPORT_STATE));
335             // The top element on the stack much be a library element
336
String JavaDoc currentLib = (String JavaDoc) objectStack.peek();
337             if (attributes == null)
338                 return;
339             String JavaDoc maskValue = attributes.getValue("", LIBRARY_EXPORT_MASK); //$NON-NLS-1$
340
// pop off the library - already in currentLib
341
objectStack.pop();
342             Vector exportMask = (Vector) objectStack.peek();
343             // push library back on
344
objectStack.push(currentLib);
345             //Split the export upfront
346
if (maskValue != null) {
347                 StringTokenizer tok = new StringTokenizer(maskValue, ","); //$NON-NLS-1$
348
while (tok.hasMoreTokens()) {
349                     String JavaDoc value = tok.nextToken();
350                     if (!exportMask.contains(maskValue))
351                         exportMask.addElement(value.trim());
352                 }
353             }
354             return;
355         }
356         if (elementName.equals(LIBRARY_PACKAGES)) {
357             stateStack.push(new Integer JavaDoc(IGNORED_ELEMENT_STATE));
358             return;
359         }
360         stateStack.push(new Integer JavaDoc(IGNORED_ELEMENT_STATE));
361         internalError(elementName);
362         return;
363     }
364
365     public void handlePluginState(String JavaDoc elementName, Attributes attributes) {
366         if (elementName.equals(RUNTIME)) {
367             // We should only have one Runtime element in a plugin or fragment
368
Object JavaDoc whatIsIt = objectStack.peek();
369             if ((whatIsIt instanceof PluginInfo) && ((PluginInfo) objectStack.peek()).libraries != null) {
370                 // This is at least the 2nd Runtime element we have hit. Ignore it.
371
stateStack.push(new Integer JavaDoc(IGNORED_ELEMENT_STATE));
372                 return;
373             }
374             stateStack.push(new Integer JavaDoc(PLUGIN_RUNTIME_STATE));
375             // Push a new vector to hold all the library entries objectStack.push(new Vector());
376
return;
377         }
378         if (elementName.equals(PLUGIN_REQUIRES)) {
379             stateStack.push(new Integer JavaDoc(PLUGIN_REQUIRES_STATE));
380             // Push a new vector to hold all the prerequisites
381
objectStack.push(new Vector());
382             parseRequiresAttributes(attributes);
383             return;
384         }
385         if (elementName.equals(EXTENSION_POINT)) {
386             // mark the plugin as singleton and ignore all elements under extension (if there are any)
387
manifestInfo.singleton = true;
388             stateStack.push(new Integer JavaDoc(PLUGIN_EXTENSION_POINT_STATE));
389             return;
390         }
391         if (elementName.equals(EXTENSION)) {
392             // mark the plugin as singleton and ignore all elements under extension (if there are any)
393
manifestInfo.singleton = true;
394             stateStack.push(new Integer JavaDoc(PLUGIN_EXTENSION_STATE));
395             return;
396         }
397         // If we get to this point, the element name is one we don't currently accept.
398
// Set the state to indicate that this element will be ignored
399
stateStack.push(new Integer JavaDoc(IGNORED_ELEMENT_STATE));
400         internalError(elementName);
401     }
402
403     public void handleRequiresImportState(String JavaDoc elementName, Attributes attributes) {
404         // All elements ignored.
405
stateStack.push(new Integer JavaDoc(IGNORED_ELEMENT_STATE));
406     }
407
408     public void handleRequiresState(String JavaDoc elementName, Attributes attributes) {
409         if (elementName.equals(PLUGIN_REQUIRES_IMPORT)) {
410             parsePluginRequiresImport(attributes);
411             return;
412         }
413         // If we get to this point, the element name is one we don't currently accept.
414
// Set the state to indicate that this element will be ignored
415
stateStack.push(new Integer JavaDoc(IGNORED_ELEMENT_STATE));
416         internalError(elementName);
417     }
418
419     public void handleRuntimeState(String JavaDoc elementName, Attributes attributes) {
420         if (elementName.equals(LIBRARY)) {
421             // Change State
422
stateStack.push(new Integer JavaDoc(RUNTIME_LIBRARY_STATE));
423             // Process library attributes
424
parseLibraryAttributes(attributes);
425             return;
426         }
427         // If we get to this point, the element name is one we don't currently accept.
428
// Set the state to indicate that this element will be ignored
429
stateStack.push(new Integer JavaDoc(IGNORED_ELEMENT_STATE));
430         internalError(elementName);
431     }
432
433     synchronized public PluginInfo parsePlugin(InputStream JavaDoc in) throws Exception JavaDoc {
434         SAXParserFactory JavaDoc factory = acquireXMLParsing(context);
435         if (factory == null) {
436 // commented out to not fill up log
437
// PDECore.logErrorMessage("No SAX factory parser has been found.");
438
return null;
439         }
440
441         factory.setNamespaceAware(true);
442         factory.setNamespaceAware(true);
443         try {
444             factory.setFeature("http://xml.org/sax/features/string-interning", true); //$NON-NLS-1$
445
} catch (SAXException se) {
446             // ignore; we can still operate without string-interning
447
}
448         factory.setValidating(false);
449         factory.newSAXParser().parse(in, this);
450         return manifestInfo;
451     }
452
453     public static SAXParserFactory JavaDoc acquireXMLParsing(BundleContext context) {
454         if (xmlTracker == null) {
455             xmlTracker = new ServiceTracker(context, "javax.xml.parsers.SAXParserFactory", null); //$NON-NLS-1$
456
xmlTracker.open();
457         }
458         SAXParserFactory JavaDoc result = (SAXParserFactory JavaDoc) xmlTracker.getService();
459         if (result != null)
460             return result;
461         // backup to using jaxp to create a new instance
462
return SAXParserFactory.newInstance();
463     }
464
465     public static void releaseXMLParsing() {
466         if (xmlTracker != null)
467             xmlTracker.close();
468     }
469
470     public void parseFragmentAttributes(Attributes attributes) {
471         // process attributes
472
objectStack.push(manifestInfo);
473         int len = attributes.getLength();
474         for (int i = 0; i < len; i++) {
475             String JavaDoc attrName = attributes.getLocalName(i);
476             String JavaDoc attrValue = attributes.getValue(i).trim();
477             if (attrName.equals(FRAGMENT_ID))
478                 manifestInfo.pluginId = attrValue;
479             else if (attrName.equals(FRAGMENT_NAME))
480                 manifestInfo.pluginName = attrValue;
481             else if (attrName.equals(FRAGMENT_VERSION))
482                 manifestInfo.version = attrValue;
483             else if (attrName.equals(FRAGMENT_PROVIDER))
484                 manifestInfo.vendor = attrValue;
485             else if (attrName.equals(FRAGMENT_PLUGIN_ID))
486                 manifestInfo.masterPluginId = attrValue;
487             else if (attrName.equals(FRAGMENT_PLUGIN_VERSION))
488                 manifestInfo.masterVersion = attrValue;
489             else if (attrName.equals(FRAGMENT_PLUGIN_MATCH))
490                 manifestInfo.masterMatch = attrValue;
491         }
492     }
493
494     public void parseLibraryAttributes(Attributes attributes) {
495         // Push a vector to hold the export mask
496
objectStack.push(new Vector());
497         String JavaDoc current = attributes.getValue("", LIBRARY_NAME); //$NON-NLS-1$
498
objectStack.push(current);
499     }
500
501     public void parsePluginAttributes(Attributes attributes) {
502         // process attributes
503
objectStack.push(manifestInfo);
504         int len = attributes.getLength();
505         for (int i = 0; i < len; i++) {
506             String JavaDoc attrName = attributes.getLocalName(i);
507             String JavaDoc attrValue = attributes.getValue(i).trim();
508             if (attrName.equals(PLUGIN_ID))
509                 manifestInfo.pluginId = attrValue;
510             else if (attrName.equals(PLUGIN_NAME))
511                 manifestInfo.pluginName = attrValue;
512             else if (attrName.equals(PLUGIN_VERSION))
513                 manifestInfo.version = attrValue;
514             else if (attrName.equals(PLUGIN_VENDOR) || (attrName.equals(PLUGIN_PROVIDER)))
515                 manifestInfo.vendor = attrValue;
516             else if (attrName.equals(PLUGIN_CLASS))
517                 manifestInfo.pluginClass = attrValue;
518         }
519     }
520
521     public class Prerequisite {
522         String JavaDoc name;
523         String JavaDoc version;
524         boolean optional;
525         boolean export;
526         String JavaDoc match;
527
528         public boolean isExported() {
529             return export;
530         }
531
532         public String JavaDoc getMatch() {
533             return match;
534         }
535
536         public String JavaDoc getName() {
537             return name;
538         }
539
540         public boolean isOptional() {
541             return optional;
542         }
543
544         public String JavaDoc getVersion() {
545             return version;
546         }
547
548         public Prerequisite(String JavaDoc preqName, String JavaDoc prereqVersion, boolean isOtional, boolean isExported, String JavaDoc prereqMatch) {
549             name = preqName;
550             version = prereqVersion;
551             optional = isOtional;
552             export = isExported;
553             match = prereqMatch;
554         }
555
556         public String JavaDoc toString() {
557             return name;
558         }
559
560         public boolean equals(Object JavaDoc prereq) {
561             if (!(prereq instanceof Prerequisite))
562                 return false;
563             return name.equals(((Prerequisite) prereq).name);
564         }
565     }
566
567     public void parsePluginRequiresImport(Attributes attributes) {
568         if (manifestInfo.requires == null) {
569             manifestInfo.requires = new ArrayList();
570             // to avoid cycles
571
// if (!manifestInfo.pluginId.equals(PluginConverterImpl.PI_RUNTIME)) //$NON-NLS-1$
572
// manifestInfo.requires.add(new Prerequisite(PluginConverterImpl.PI_RUNTIME, null, false, false, null)); //$NON-NLS-1$
573
}
574         // process attributes
575
String JavaDoc plugin = attributes.getValue("", PLUGIN_REQUIRES_PLUGIN); //$NON-NLS-1$
576
if (plugin == null)
577             return;
578         if (plugin.equals(PluginConverter.PI_BOOT))
579             return;
580         if (plugin.equals(PluginConverter.PI_RUNTIME_COMPATIBILITY))
581             manifestInfo.compatibilityFound = true;
582         String JavaDoc version = attributes.getValue("", PLUGIN_REQUIRES_PLUGIN_VERSION); //$NON-NLS-1$
583
String JavaDoc optional = attributes.getValue("", PLUGIN_REQUIRES_OPTIONAL); //$NON-NLS-1$
584
String JavaDoc export = attributes.getValue("", PLUGIN_REQUIRES_EXPORT); //$NON-NLS-1$
585
String JavaDoc match = attributes.getValue("", PLUGIN_REQUIRES_MATCH); //$NON-NLS-1$
586
manifestInfo.requires.add(new Prerequisite(plugin, version, "true".equalsIgnoreCase(optional) ? true : false, "true".equalsIgnoreCase(export) ? true : false, match)); //$NON-NLS-1$ //$NON-NLS-2$
587
}
588
589     public void parseRequiresAttributes(Attributes attributes) {
590         //Nothing to do.
591
}
592
593     static String JavaDoc replace(String JavaDoc s, String JavaDoc from, String JavaDoc to) {
594         String JavaDoc str = s;
595         int fromLen = from.length();
596         int toLen = to.length();
597         int ix = str.indexOf(from);
598         while (ix != -1) {
599             str = str.substring(0, ix) + to + str.substring(ix + fromLen);
600             ix = str.indexOf(from, ix + toLen);
601         }
602         return str;
603     }
604
605     public void startDocument() {
606         stateStack.push(new Integer JavaDoc(INITIAL_STATE));
607     }
608
609     public void startElement(String JavaDoc uri, String JavaDoc elementName, String JavaDoc qName, Attributes attributes) {
610         switch (((Integer JavaDoc) stateStack.peek()).intValue()) {
611             case INITIAL_STATE :
612                 handleInitialState(elementName, attributes);
613                 break;
614             case FRAGMENT_STATE :
615             case PLUGIN_STATE :
616                 handlePluginState(elementName, attributes);
617                 break;
618             case PLUGIN_RUNTIME_STATE :
619                 handleRuntimeState(elementName, attributes);
620                 break;
621             case PLUGIN_REQUIRES_STATE :
622                 handleRequiresState(elementName, attributes);
623                 break;
624             case PLUGIN_EXTENSION_POINT_STATE :
625                 handleExtensionPointState(elementName, attributes);
626                 break;
627             case PLUGIN_EXTENSION_STATE :
628                 handleExtensionState(elementName, attributes);
629                 break;
630             case RUNTIME_LIBRARY_STATE :
631                 handleLibraryState(elementName, attributes);
632                 break;
633             case LIBRARY_EXPORT_STATE :
634                 handleLibraryExportState(elementName, attributes);
635                 break;
636             case PLUGIN_REQUIRES_IMPORT_STATE :
637                 handleRequiresImportState(elementName, attributes);
638                 break;
639             default :
640                 stateStack.push(new Integer JavaDoc(IGNORED_ELEMENT_STATE));
641         }
642     }
643
644     private void internalError(String JavaDoc elementName) {
645 // commented out to not fill up log
646
// String message = NLS.bind("Unknown element \"{0}\", found at the top level, ignored.", elementName);
647
// PDECore.logErrorMessage(message);
648
}
649
650     public void processingInstruction(String JavaDoc target, String JavaDoc data) throws SAXException {
651         // Since 3.0, a processing instruction of the form <?eclipse version="3.0"?> at
652
// the start of the manifest file is used to indicate the plug-in manifest
653
// schema version in effect. Pre-3.0 (i.e., 2.1) plug-in manifest files do not
654
// have one of these, and this is how we can distinguish the manifest of a
655
// pre-3.0 plug-in from a post-3.0 one (for compatibility tranformations).
656
if (target.equalsIgnoreCase("eclipse")) { //$NON-NLS-1$
657
// just the presence of this processing instruction indicates that this
658
// plug-in is at least 3.0
659
manifestInfo.schemaVersion = "3.0"; //$NON-NLS-1$
660
StringTokenizer tokenizer = new StringTokenizer(data, "=\""); //$NON-NLS-1$
661
while (tokenizer.hasMoreTokens()) {
662                 String JavaDoc token = tokenizer.nextToken();
663                 if (token.equalsIgnoreCase("version")) { //$NON-NLS-1$
664
if (!tokenizer.hasMoreTokens()) {
665                         break;
666                     }
667                     manifestInfo.schemaVersion = tokenizer.nextToken();
668                     break;
669                 }
670             }
671         }
672     }
673 }
674
Popular Tags