KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > core > InternalFeatureParser


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.update.internal.core;
12
13
14 import java.io.IOException JavaDoc;
15 import java.io.InputStream JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.util.Stack JavaDoc;
18
19 import javax.xml.parsers.ParserConfigurationException JavaDoc;
20 import javax.xml.parsers.SAXParser JavaDoc;
21 import javax.xml.parsers.SAXParserFactory JavaDoc;
22
23 import org.eclipse.core.runtime.IStatus;
24 import org.eclipse.core.runtime.MultiStatus;
25 import org.eclipse.core.runtime.Platform;
26 import org.eclipse.core.runtime.Status;
27 import org.eclipse.osgi.util.NLS;
28 import org.eclipse.update.core.IURLEntry;
29 import org.eclipse.update.core.IUpdateConstants;
30 import org.eclipse.update.core.model.ContentEntryModel;
31 import org.eclipse.update.core.model.FeatureModel;
32 import org.eclipse.update.core.model.FeatureModelFactory;
33 import org.eclipse.update.core.model.ImportModel;
34 import org.eclipse.update.core.model.IncludedFeatureReferenceModel;
35 import org.eclipse.update.core.model.InstallHandlerEntryModel;
36 import org.eclipse.update.core.model.NonPluginEntryModel;
37 import org.eclipse.update.core.model.PluginEntryModel;
38 import org.eclipse.update.core.model.URLEntryModel;
39 import org.xml.sax.Attributes JavaDoc;
40 import org.xml.sax.InputSource JavaDoc;
41 import org.xml.sax.SAXException JavaDoc;
42 import org.xml.sax.SAXParseException JavaDoc;
43 import org.xml.sax.helpers.DefaultHandler JavaDoc;
44
45 /**
46  * Default feature parser.
47  * Parses the feature manifest file as defined by the platform. Defers
48  * to a model factory to create the actual concrete model objects. The
49  * update framework supplies two factory implementations:
50  * <ul>
51  * <p>
52  * <b>Note:</b> This class/interface is part of an interim API that is still under development and expected to
53  * change significantly before reaching stability. It is being made available at this early stage to solicit feedback
54  * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken
55  * (repeatedly) as the API evolves.
56  * </p>
57  * <li>@see org.eclipse.update.core.model.FeatureModelFactory
58  * <li>@see org.eclipse.update.core.BaseFeatureFactory
59  * </ul>
60  *
61  * @since 2.0
62  */

63 public class InternalFeatureParser extends DefaultHandler JavaDoc {
64
65     private SAXParser JavaDoc parser;
66     private FeatureModelFactory factory;
67     private MultiStatus status;
68
69     private boolean URL_ALREADY_SEEN = false;
70
71     private static final int STATE_IGNORED_ELEMENT = -1;
72     private static final int STATE_INITIAL = 0;
73     private static final int STATE_INCLUDES = 1;
74     private static final int STATE_FEATURE = 2;
75     private static final int STATE_HANDLER = 3;
76     private static final int STATE_DESCRIPTION = 4;
77     private static final int STATE_COPYRIGHT = 5;
78     private static final int STATE_LICENSE = 6;
79     private static final int STATE_URL = 7;
80     private static final int STATE_UPDATE = 8;
81     private static final int STATE_DISCOVERY = 9;
82     private static final int STATE_REQUIRES = 10;
83     private static final int STATE_IMPORT = 11;
84     private static final int STATE_PLUGIN = 12;
85     private static final int STATE_DATA = 13;
86     private static final String JavaDoc PLUGIN_ID = UpdateCore.getPlugin().getBundle().getSymbolicName();
87
88     private static final String JavaDoc FEATURE = "feature"; //$NON-NLS-1$
89
private static final String JavaDoc INCLUDES = "includes"; //$NON-NLS-1$
90
private static final String JavaDoc HANDLER = "install-handler"; //$NON-NLS-1$
91
private static final String JavaDoc DESCRIPTION = "description"; //$NON-NLS-1$
92
private static final String JavaDoc COPYRIGHT = "copyright"; //$NON-NLS-1$
93
private static final String JavaDoc LICENSE = "license"; //$NON-NLS-1$
94
private static final String JavaDoc URL = "url"; //$NON-NLS-1$
95
private static final String JavaDoc UPDATE = "update"; //$NON-NLS-1$
96
private static final String JavaDoc DISCOVERY = "discovery"; //$NON-NLS-1$
97
private static final String JavaDoc REQUIRES = "requires"; //$NON-NLS-1$
98
private static final String JavaDoc IMPORT = "import"; //$NON-NLS-1$
99
private static final String JavaDoc PLUGIN = "plugin"; //$NON-NLS-1$
100
private static final String JavaDoc DATA = "data"; //$NON-NLS-1$
101
// Current State Information
102
Stack JavaDoc stateStack = new Stack JavaDoc();
103
104     // Current object stack (used to hold the current object we are
105
// populating in this plugin descriptor
106
Stack JavaDoc objectStack = new Stack JavaDoc();
107
108     private int currentState;
109     private String JavaDoc location;
110     
111     private final static SAXParserFactory JavaDoc parserFactory =
112         SAXParserFactory.newInstance();
113
114     /**
115      * Constructs a feature parser.
116      *
117      * @since 2.0
118      */

119     public InternalFeatureParser() {
120         super();
121         try {
122             parserFactory.setNamespaceAware(true);
123             this.parser = parserFactory.newSAXParser();
124         } catch (ParserConfigurationException JavaDoc e) {
125             UpdateCore.log(e);
126         } catch (SAXException JavaDoc e) {
127             UpdateCore.log(e);
128         }
129     }
130
131     public void init(FeatureModelFactory factory) {
132         init(factory, null);
133     }
134     
135     /**
136      * @param factory
137      * @param location
138      * @since 3.1
139      */

140     public void init(FeatureModelFactory factory, String JavaDoc location) {
141         // PERF: separate instance creation from parsing
142
this.factory = factory;
143         stateStack = new Stack JavaDoc();
144         objectStack = new Stack JavaDoc();
145         status = null;
146         URL_ALREADY_SEEN = false;
147         this.location = location;
148         //parser.reset();
149
}
150     
151     public void internalInit(FeatureModelFactory factory, String JavaDoc location) {
152         init(factory, location);
153         stateStack.push(new Integer JavaDoc(STATE_INITIAL));
154         currentState = ((Integer JavaDoc) stateStack.peek()).intValue();
155     }
156     
157     public FeatureModel getFeatureModel() throws SAXException JavaDoc {
158         if (objectStack.isEmpty())
159             throw new SAXException JavaDoc(Messages.DefaultFeatureParser_NoFeatureTag);
160         else {
161             if (objectStack.peek() instanceof FeatureModel) {
162                 return (FeatureModel) objectStack.pop();
163             } else {
164                 String JavaDoc stack = ""; //$NON-NLS-1$
165
Iterator JavaDoc iter = objectStack.iterator();
166                 while (iter.hasNext()) {
167                     stack = "\r\n" + iter.next().toString() + stack; //$NON-NLS-1$
168
}
169                 throw new SAXException JavaDoc(NLS.bind(Messages.DefaultFeatureParser_WrongParsingStack, (new String JavaDoc[] { stack })));
170             }
171         }
172     }
173
174     /**
175      * Parses the specified input steam and constructs a feature model.
176      * The input stream is not closed as part of this operation.
177      *
178      * @param in input stream
179      * @return feature model
180      * @exception SAXException
181      * @exception IOException
182      * @since 2.0
183      */

184     public FeatureModel parse(InputStream JavaDoc in) throws SAXException JavaDoc, IOException JavaDoc {
185         stateStack.push(new Integer JavaDoc(STATE_INITIAL));
186         currentState = ((Integer JavaDoc) stateStack.peek()).intValue();
187         parser.parse(new InputSource JavaDoc(in), this);
188         return getFeatureModel();
189     }
190
191     /**
192      * Returns all status objects accumulated by the parser.
193      *
194      * @return multi-status containing accumulated status, or <code>null</code>.
195      * @since 2.0
196      */

197     public MultiStatus getStatus() {
198         return status;
199     }
200
201     /**
202      * Handle start of element tags
203      * @see DefaultHandler#startElement(String, String, String, Attributes)
204      * @since 2.0
205      */

206     public void startElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc qName, Attributes JavaDoc attributes) throws SAXException JavaDoc {
207
208         if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_PARSING)
209             debug("Start Element: uri:" + uri + " local Name:" + localName + " qName:" + qName); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
210

211         switch (currentState) {
212             case STATE_IGNORED_ELEMENT :
213                 internalErrorUnknownTag(NLS.bind(Messages.DefaultFeatureParser_UnknownElement, (new String JavaDoc[] { localName, getState(currentState) })));
214                 break;
215
216             case STATE_INITIAL :
217                 handleInitialState(localName, attributes);
218                 break;
219
220             case STATE_FEATURE :
221             case STATE_INCLUDES :
222             case STATE_HANDLER :
223             case STATE_DESCRIPTION :
224             case STATE_COPYRIGHT :
225             case STATE_LICENSE :
226                 handleFeatureState(localName, attributes);
227                 break;
228
229             case STATE_URL :
230                 if (URL_ALREADY_SEEN)
231                     internalError(Messages.DefaultFeatureParser_TooManyURLtag);
232                 handleURLState(localName, attributes);
233                 break;
234
235             case STATE_UPDATE :
236             case STATE_DISCOVERY :
237                 handleUpdateDiscoveryState(localName, attributes);
238                 break;
239
240             case STATE_REQUIRES :
241                 handleRequiresState(localName, attributes);
242                 break;
243
244             case STATE_IMPORT :
245                 handleImportState(localName,attributes);
246                 break;
247                 
248             case STATE_PLUGIN :
249             case STATE_DATA :
250                 handleFeatureState(localName, attributes);
251                 break;
252
253             default :
254                 internalErrorUnknownTag(NLS.bind(Messages.DefaultFeatureParser_UnknownStartState, (new String JavaDoc[] { Integer.toString(currentState) })));
255                 break;
256         }
257
258         int newState = ((Integer JavaDoc) stateStack.peek()).intValue();
259         if (newState != STATE_IGNORED_ELEMENT)
260             currentState = newState;
261
262     }
263
264     /**
265      * Handle end of element tags
266      * @see DefaultHandler#endElement(String, String, String)
267      * @since 2.0
268      */

269     public void endElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc qName) {
270
271         // variables used
272
URLEntryModel info = null;
273         FeatureModel featureModel = null;
274         String JavaDoc text = null;
275         int innerState = 0;
276
277         int state = ((Integer JavaDoc) stateStack.peek()).intValue();
278         switch (state) {
279             case STATE_IGNORED_ELEMENT :
280                 stateStack.pop();
281                 break;
282
283             case STATE_INITIAL :
284                 internalError(Messages.DefaultFeatureParser_ParsingStackBackToInitialState);
285                 break;
286
287             case STATE_FEATURE :
288                 stateStack.pop();
289                 if (objectStack.peek() instanceof String JavaDoc) {
290                     text = (String JavaDoc) objectStack.pop();
291                     FeatureModel feature = (FeatureModel) objectStack.peek();
292                     feature.getDescriptionModel().setAnnotation(text);
293                 }
294                 //do not pop
295
break;
296
297             case STATE_INCLUDES :
298                 stateStack.pop();
299                 if (objectStack.peek() instanceof IncludedFeatureReferenceModel) {
300                     IncludedFeatureReferenceModel includedFeatureRefModel = ((IncludedFeatureReferenceModel) objectStack.pop());
301                     if (objectStack.peek() instanceof FeatureModel) {
302                         featureModel = (FeatureModel) objectStack.peek();
303                         featureModel.addIncludedFeatureReferenceModel(includedFeatureRefModel);
304                     }
305                 }
306                 break;
307
308             case STATE_HANDLER :
309                 stateStack.pop();
310                 if (objectStack.peek() instanceof InstallHandlerEntryModel) {
311                     InstallHandlerEntryModel handlerModel = (InstallHandlerEntryModel) objectStack.pop();
312                     featureModel = (FeatureModel) objectStack.peek();
313                     if (featureModel.getInstallHandlerModel() != null)
314                         internalError(NLS.bind(Messages.DefaultFeatureParser_ElementAlreadySet, (new String JavaDoc[] { getState(state) })));
315                     else
316                         featureModel.setInstallHandlerModel(handlerModel);
317                 }
318                 break;
319
320             case STATE_DESCRIPTION :
321                 stateStack.pop();
322
323                 text = ""; //$NON-NLS-1$
324
while (objectStack.peek() instanceof String JavaDoc) {
325                     text = (String JavaDoc) objectStack.pop() + text;
326                 }
327                 if (objectStack.peek() instanceof URLEntryModel) {
328                     info = (URLEntryModel) objectStack.pop();
329                     text = cleanupText(text);
330                     if (text != null)
331                         info.setAnnotation(text);
332
333                     innerState = ((Integer JavaDoc) stateStack.peek()).intValue();
334                     switch (innerState) {
335                         case STATE_FEATURE :
336                             if (objectStack.peek() instanceof FeatureModel) {
337                                 featureModel = (FeatureModel) objectStack.peek();
338                                 if (featureModel.getDescriptionModel() != null)
339                                     internalError(NLS.bind(Messages.DefaultFeatureParser_ElementAlreadySet, (new String JavaDoc[] { getState(state) })));
340                                 else
341                                     featureModel.setDescriptionModel(info);
342                             }
343                             break;
344
345                         default :
346                             internalError(NLS.bind(Messages.DefaultFeatureParser_StateIncludeWrongElement, (new String JavaDoc[] { getState(innerState), getState(state) })));
347                             break;
348
349                     }
350                 }
351                 break;
352
353             case STATE_COPYRIGHT :
354                 stateStack.pop();
355                 text = ""; //$NON-NLS-1$
356
while (objectStack.peek() instanceof String JavaDoc) {
357                     text = (String JavaDoc) objectStack.pop() + text;
358                 }
359                 if (objectStack.peek() instanceof URLEntryModel) {
360                     info = (URLEntryModel) objectStack.pop();
361                     text = cleanupText(text);
362                     if (text != null) {
363                         info.setAnnotation(text);
364                     }
365
366                     innerState = ((Integer JavaDoc) stateStack.peek()).intValue();
367                     switch (innerState) {
368                         case STATE_FEATURE :
369                             if (objectStack.peek() instanceof FeatureModel) {
370                                 featureModel = (FeatureModel) objectStack.peek();
371                                 if (featureModel.getCopyrightModel() != null)
372                                     internalError(NLS.bind(Messages.DefaultFeatureParser_ElementAlreadySet, (new String JavaDoc[] { getState(state) })));
373                                 else
374                                     featureModel.setCopyrightModel(info);
375                             }
376                             break;
377
378                         default :
379                             internalError(NLS.bind(Messages.DefaultFeatureParser_StateIncludeWrongElement, (new String JavaDoc[] { getState(innerState), getState(state) })));
380                             break;
381
382                     }
383                 }
384                 break;
385
386             case STATE_LICENSE :
387                 stateStack.pop();
388
389                 text = ""; //$NON-NLS-1$
390
while (objectStack.peek() instanceof String JavaDoc) {
391                     text = (String JavaDoc) objectStack.pop() + text;
392                 }
393                 if (objectStack.peek() instanceof URLEntryModel) {
394                     info = (URLEntryModel) objectStack.pop();
395                     text = cleanupText(text);
396                     if (text != null) {
397                         info.setAnnotation(text);
398                     }
399
400                     innerState = ((Integer JavaDoc) stateStack.peek()).intValue();
401                     switch (innerState) {
402                         case STATE_FEATURE :
403                             if (objectStack.peek() instanceof FeatureModel) {
404                                 featureModel = (FeatureModel) objectStack.peek();
405                                 if (featureModel.getLicenseModel() != null)
406                                     internalError(NLS.bind(Messages.DefaultFeatureParser_ElementAlreadySet, (new String JavaDoc[] { getState(state) })));
407                                 else
408                                     featureModel.setLicenseModel(info);
409                             }
410                             break;
411
412                         default :
413                             internalError(NLS.bind(Messages.DefaultFeatureParser_StateIncludeWrongElement, (new String JavaDoc[] { getState(innerState), getState(state) })));
414                             break;
415
416                     }
417                 }
418                 break;
419
420             case STATE_URL :
421                 stateStack.pop();
422                 URL_ALREADY_SEEN = true;
423                 break;
424
425             case STATE_UPDATE :
426                 stateStack.pop();
427                 if (objectStack.peek() instanceof URLEntryModel) {
428                     info = (URLEntryModel) objectStack.pop();
429                     if (objectStack.peek() instanceof FeatureModel) {
430                         featureModel = (FeatureModel) objectStack.peek();
431                         if (featureModel.getUpdateSiteEntryModel() != null) {
432                             internalError(NLS.bind(Messages.DefaultFeatureParser_ElementAlreadySet, (new String JavaDoc[] { getState(state) })));
433                         } else {
434                             featureModel.setUpdateSiteEntryModel(info);
435                         }
436                     }
437                 }
438                 break;
439
440             case STATE_DISCOVERY :
441                 stateStack.pop();
442                 if (objectStack.peek() instanceof URLEntryModel) {
443                     info = (URLEntryModel) objectStack.pop();
444                     if (objectStack.peek() instanceof FeatureModel) {
445                         featureModel = (FeatureModel) objectStack.peek();
446                         featureModel.addDiscoverySiteEntryModel(info);
447                     }
448                 }
449                 break;
450
451             case STATE_REQUIRES :
452                 stateStack.pop();
453                 if (objectStack.peek() instanceof FeatureModel) {
454                     featureModel = (FeatureModel) objectStack.peek();
455                     ImportModel[] importModels = featureModel.getImportModels();
456                     if (importModels.length == 0) {
457                         internalError(Messages.DefaultFeatureParser_RequireStateWithoutImportElement);
458                     } else {
459                         boolean patchMode = false;
460                         for (int i = 0; i < importModels.length; i++) {
461                             ImportModel importModel = importModels[i];
462                             if (importModel.isPatch()) {
463                                 if (patchMode == false)
464                                     patchMode = true;
465                                 else {
466                                     internalError(Messages.DefaultFeatureParser_MultiplePatchImports);
467                                     break;
468                                 }
469                             }
470                         }
471                     }
472                 }
473                 break;
474
475             case STATE_IMPORT :
476                 stateStack.pop();
477                 if (objectStack.peek() instanceof ImportModel) {
478                     ImportModel importModel = (ImportModel) objectStack.pop();
479                     if (objectStack.peek() instanceof FeatureModel) {
480                         featureModel = (FeatureModel) objectStack.peek();
481                         featureModel.addImportModel(importModel);
482                     }
483                 }
484                 break;
485
486             case STATE_PLUGIN :
487                 stateStack.pop();
488                 if (objectStack.peek() instanceof PluginEntryModel) {
489                     PluginEntryModel pluginEntry = (PluginEntryModel) objectStack.pop();
490                     if (objectStack.peek() instanceof FeatureModel) {
491                         featureModel = (FeatureModel) objectStack.peek();
492                         featureModel.addPluginEntryModel(pluginEntry);
493                     }
494                 }
495                 break;
496
497             case STATE_DATA :
498                 stateStack.pop();
499                 if (objectStack.peek() instanceof NonPluginEntryModel) {
500                     NonPluginEntryModel nonPluginEntry = (NonPluginEntryModel) objectStack.pop();
501                     if (objectStack.peek() instanceof FeatureModel) {
502                         featureModel = (FeatureModel) objectStack.peek();
503                         featureModel.addNonPluginEntryModel(nonPluginEntry);
504                     }
505                 }
506                 break;
507
508             default :
509                 internalErrorUnknownTag(Messages.DefaultFeatureParser_UnknownEndState + state);
510                 break;
511         }
512
513         if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_PARSING)
514             debug("End Element:" + uri + ":" + localName + ":" + qName); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
515
}
516     
517     /*
518      * Method cleanupText.
519      * Removes pre white space and post white space
520      * return null if the text only contains whitespaces (\t \r\n and spaces)
521      *
522      * @param text or null
523      * @return String
524      */

525     private String JavaDoc cleanupText(String JavaDoc text) {
526         text = text.trim();
527         if ("".equals(text)) return null; //$NON-NLS-1$
528
return text;
529     }
530
531     /**
532      * Handle character text
533      * @see DefaultHandler#characters(char[], int, int)
534      * @since 2.0
535      */

536     public void characters(char[] ch, int start, int length) {
537         String JavaDoc text = ""; //$NON-NLS-1$
538
boolean valid = true;
539
540         if (valid) {
541             text = new String JavaDoc(ch, start, length);
542         }
543
544         //only push if not unknown state
545
int state = ((Integer JavaDoc) stateStack.peek()).intValue();
546         if (state == STATE_DESCRIPTION || state == STATE_COPYRIGHT || state == STATE_LICENSE)
547             objectStack.push(text);
548
549     }
550
551     /**
552      * Handle errors
553      * @see DefaultHandler#error(SAXParseException)
554      * @since 2.0
555      */

556     public void error(SAXParseException JavaDoc ex) {
557         logStatus(ex);
558     }
559
560     /**
561      * Handle fatal errors
562      * @see DefaultHandler#fatalError(SAXParseException)
563      * @exception SAXException
564      * @since 2.0
565      */

566     public void fatalError(SAXParseException JavaDoc ex) throws SAXException JavaDoc {
567         logStatus(ex);
568         throw ex;
569     }
570
571     private void handleInitialState(String JavaDoc elementName, Attributes JavaDoc attributes) throws SAXException JavaDoc {
572         if (elementName.equals(FEATURE)) {
573             stateStack.push(new Integer JavaDoc(STATE_FEATURE));
574             processFeature(attributes);
575         } else
576             internalErrorUnknownTag(NLS.bind(Messages.DefaultFeatureParser_UnknownElement, (new String JavaDoc[] { elementName, getState(currentState) })));
577     }
578
579     private void handleFeatureState(String JavaDoc elementName, Attributes JavaDoc attributes) throws SAXException JavaDoc {
580         if (elementName.equals(HANDLER)) {
581             stateStack.push(new Integer JavaDoc(STATE_HANDLER));
582             processHandler(attributes);
583         } else if (elementName.equals(DESCRIPTION)) {
584             stateStack.push(new Integer JavaDoc(STATE_DESCRIPTION));
585             processInfo(attributes);
586         } else if (elementName.equals(COPYRIGHT)) {
587             stateStack.push(new Integer JavaDoc(STATE_COPYRIGHT));
588             processInfo(attributes);
589         } else if (elementName.equals(LICENSE)) {
590             stateStack.push(new Integer JavaDoc(STATE_LICENSE));
591             processInfo(attributes);
592         } else if (elementName.equals(URL)) {
593             stateStack.push(new Integer JavaDoc(STATE_URL));
594             //No process as URL tag does not contain any element itself
595
} else if (elementName.equals(INCLUDES)) {
596             stateStack.push(new Integer JavaDoc(STATE_INCLUDES));
597             processIncludes(attributes);
598         } else if (elementName.equals(REQUIRES)) {
599             stateStack.push(new Integer JavaDoc(STATE_REQUIRES));
600             processRequire(attributes);
601         } else if (elementName.equals(PLUGIN)) {
602             stateStack.push(new Integer JavaDoc(STATE_PLUGIN));
603             processPlugin(attributes);
604         } else if (elementName.equals(DATA)) {
605             stateStack.push(new Integer JavaDoc(STATE_DATA));
606             processData(attributes);
607         } else
608             internalErrorUnknownTag(NLS.bind(Messages.DefaultFeatureParser_UnknownElement, (new String JavaDoc[] { elementName, getState(currentState) })));
609     }
610
611     private void handleURLState(String JavaDoc elementName, Attributes JavaDoc attributes) throws SAXException JavaDoc {
612         if (elementName.equals(UPDATE)) {
613             stateStack.push(new Integer JavaDoc(STATE_UPDATE));
614             processURLInfo(attributes);
615         } else if (elementName.equals(DISCOVERY)) {
616             stateStack.push(new Integer JavaDoc(STATE_DISCOVERY));
617             processURLInfo(attributes);
618         } else
619             internalErrorUnknownTag(NLS.bind(Messages.DefaultFeatureParser_UnknownElement, (new String JavaDoc[] { elementName, getState(currentState) })));
620     }
621
622     private void handleRequiresState(String JavaDoc elementName, Attributes JavaDoc attributes) throws SAXException JavaDoc {
623         if (elementName.equals(IMPORT)) {
624             stateStack.push(new Integer JavaDoc(STATE_IMPORT));
625             processImport(attributes);
626         } else
627             internalErrorUnknownTag(NLS.bind(Messages.DefaultFeatureParser_UnknownElement, (new String JavaDoc[] { elementName, getState(currentState) })));
628     }
629     private void handleUpdateDiscoveryState(String JavaDoc elementName, Attributes JavaDoc attributes) throws SAXException JavaDoc {
630         if (elementName.equals(HANDLER)) {
631             stateStack.push(new Integer JavaDoc(STATE_HANDLER));
632             processHandler(attributes);
633         } else if (elementName.equals(DESCRIPTION)) {
634             stateStack.push(new Integer JavaDoc(STATE_DESCRIPTION));
635             processInfo(attributes);
636         } else if (elementName.equals(COPYRIGHT)) {
637             stateStack.push(new Integer JavaDoc(STATE_COPYRIGHT));
638             processInfo(attributes);
639         } else if (elementName.equals(LICENSE)) {
640             stateStack.push(new Integer JavaDoc(STATE_LICENSE));
641             processInfo(attributes);
642         } else if (elementName.equals(URL)) {
643             stateStack.push(new Integer JavaDoc(STATE_URL));
644             //No process as URL tag does not contain any element itself
645
} else if (elementName.equals(INCLUDES)) {
646             stateStack.push(new Integer JavaDoc(STATE_INCLUDES));
647             processIncludes(attributes);
648         } else if (elementName.equals(REQUIRES)) {
649             stateStack.push(new Integer JavaDoc(STATE_REQUIRES));
650             processRequire(attributes);
651         } else if (elementName.equals(PLUGIN)) {
652             stateStack.push(new Integer JavaDoc(STATE_PLUGIN));
653             processPlugin(attributes);
654         } else if (elementName.equals(DATA)) {
655             stateStack.push(new Integer JavaDoc(STATE_DATA));
656             processData(attributes);
657         } else if (elementName.equals(UPDATE)) {
658             stateStack.push(new Integer JavaDoc(STATE_UPDATE));
659             processURLInfo(attributes);
660         } else if (elementName.equals(DISCOVERY)) {
661             stateStack.push(new Integer JavaDoc(STATE_DISCOVERY));
662             processURLInfo(attributes);
663         } else
664             internalErrorUnknownTag(NLS.bind(Messages.DefaultFeatureParser_UnknownElement, (new String JavaDoc[] { elementName, getState(currentState) })));
665         }
666
667
668
669     private void handleImportState(String JavaDoc elementName, Attributes JavaDoc attributes) throws SAXException JavaDoc {
670         if (elementName.equals(HANDLER)) {
671             stateStack.push(new Integer JavaDoc(STATE_HANDLER));
672             processHandler(attributes);
673         } else if (elementName.equals(DESCRIPTION)) {
674             stateStack.push(new Integer JavaDoc(STATE_DESCRIPTION));
675             processInfo(attributes);
676         } else if (elementName.equals(COPYRIGHT)) {
677             stateStack.push(new Integer JavaDoc(STATE_COPYRIGHT));
678             processInfo(attributes);
679         } else if (elementName.equals(LICENSE)) {
680             stateStack.push(new Integer JavaDoc(STATE_LICENSE));
681             processInfo(attributes);
682         } else if (elementName.equals(URL)) {
683             stateStack.push(new Integer JavaDoc(STATE_URL));
684             //No process as URL tag does not contain any element itself
685
} else if (elementName.equals(INCLUDES)) {
686             stateStack.push(new Integer JavaDoc(STATE_INCLUDES));
687             processIncludes(attributes);
688         } else if (elementName.equals(REQUIRES)) {
689             stateStack.push(new Integer JavaDoc(STATE_REQUIRES));
690             processRequire(attributes);
691         } else if (elementName.equals(PLUGIN)) {
692             stateStack.push(new Integer JavaDoc(STATE_PLUGIN));
693             processPlugin(attributes);
694         } else if (elementName.equals(DATA)) {
695             stateStack.push(new Integer JavaDoc(STATE_DATA));
696             processData(attributes);
697         } else if (elementName.equals(IMPORT)) {
698             stateStack.push(new Integer JavaDoc(STATE_IMPORT));
699             processImport(attributes);
700         } else
701             internalErrorUnknownTag(NLS.bind(Messages.DefaultFeatureParser_UnknownElement, (new String JavaDoc[] { elementName, getState(currentState) })));
702     }
703
704     /*
705      * Process feature information
706      */

707     private void processFeature(Attributes JavaDoc attributes) {
708
709         // identifier and version
710
String JavaDoc id = attributes.getValue("id"); //$NON-NLS-1$
711
String JavaDoc ver = attributes.getValue("version"); //$NON-NLS-1$
712

713         if (id == null || id.trim().equals("") //$NON-NLS-1$
714
|| ver == null || ver.trim().equals("")) { //$NON-NLS-1$
715
internalError(NLS.bind(Messages.DefaultFeatureParser_IdOrVersionInvalid, (new String JavaDoc[] { id, ver, getState(currentState)})));
716         } else {
717             // create feature model
718
FeatureModel feature = factory.createFeatureModel();
719
720             feature.setFeatureIdentifier(id);
721             feature.setFeatureVersion(ver);
722
723             // label
724
String JavaDoc label = attributes.getValue("label"); //$NON-NLS-1$
725
feature.setLabel(label);
726
727             // provider
728
String JavaDoc provider = attributes.getValue("provider-name"); //$NON-NLS-1$
729
feature.setProvider(provider);
730
731             //image
732
String JavaDoc imageURL = attributes.getValue("image"); //$NON-NLS-1$
733
feature.setImageURLString(imageURL);
734
735             // OS
736
String JavaDoc os = attributes.getValue("os"); //$NON-NLS-1$
737
feature.setOS(os);
738
739             // WS
740
String JavaDoc ws = attributes.getValue("ws"); //$NON-NLS-1$
741
feature.setWS(ws);
742
743             // NL
744
String JavaDoc nl = attributes.getValue("nl"); //$NON-NLS-1$
745
feature.setNL(nl);
746
747             // arch
748
String JavaDoc arch = attributes.getValue("arch"); //$NON-NLS-1$
749
feature.setArch(arch);
750
751             // primary
752
String JavaDoc primary = attributes.getValue("primary"); //$NON-NLS-1$
753
feature.setPrimary(primary != null && primary.trim().equalsIgnoreCase("true")); //$NON-NLS-1$
754

755             // exclusive
756
String JavaDoc exclusive = attributes.getValue("exclusive"); //$NON-NLS-1$
757
feature.setExclusive(exclusive != null && exclusive.trim().equalsIgnoreCase("true")); //$NON-NLS-1$
758

759             // application
760
String JavaDoc application = attributes.getValue("application"); //$NON-NLS-1$
761
feature.setApplication(application);
762
763             // affinity
764
String JavaDoc affinity = attributes.getValue("colocation-affinity"); //$NON-NLS-1$
765
feature.setAffinityFeature(affinity);
766
767             // primary plugin
768
String JavaDoc plugin = attributes.getValue("plugin"); //$NON-NLS-1$
769
feature.setPrimaryPluginID(plugin);
770
771             objectStack.push(feature);
772
773             if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_PARSING) {
774                 debug("End process DefaultFeature tag: id:" //$NON-NLS-1$
775
+id + " ver:" //$NON-NLS-1$
776
+ver + " label:" //$NON-NLS-1$
777
+label + " provider:" //$NON-NLS-1$
778
+provider);
779                 debug("End process DefaultFeature tag: image:" + imageURL); //$NON-NLS-1$
780
debug("End process DefaultFeature tag: ws:" //$NON-NLS-1$
781
+ws + " os:" //$NON-NLS-1$
782
+os + " nl:" //$NON-NLS-1$
783
+nl + " application:" //$NON-NLS-1$
784
+application);
785             }
786         }
787     }
788
789     /*
790      * process URL info with element text
791      */

792     private void processHandler(Attributes JavaDoc attributes) {
793         InstallHandlerEntryModel handler = factory.createInstallHandlerEntryModel();
794
795         String JavaDoc handlerURL = attributes.getValue("url"); //$NON-NLS-1$
796
handler.setURLString(handlerURL);
797
798         String JavaDoc library = attributes.getValue("library"); //$NON-NLS-1$
799
handler.setLibrary(library);
800
801         String JavaDoc clazz = attributes.getValue("handler"); //$NON-NLS-1$
802
handler.setHandlerName(clazz);
803
804         objectStack.push(handler);
805
806         if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_PARSING)
807             debug("Processed Handler: url:" //$NON-NLS-1$
808
+handlerURL + " library:" //$NON-NLS-1$
809
+library + " class:" //$NON-NLS-1$
810
+clazz);
811     }
812
813     /*
814      * process URL info with element text
815      */

816     private void processInfo(Attributes JavaDoc attributes) {
817         URLEntryModel inf = factory.createURLEntryModel();
818         String JavaDoc infoURL = attributes.getValue("url"); //$NON-NLS-1$
819
inf.setURLString(infoURL);
820
821         objectStack.push(inf);
822
823         if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_PARSING)
824             debug("Processed Info: url:" + infoURL); //$NON-NLS-1$
825
}
826
827     /*
828      * Process includes information
829      */

830     private void processIncludes(Attributes JavaDoc attributes) {
831
832         // identifier and version
833
String JavaDoc id = attributes.getValue("id"); //$NON-NLS-1$
834
String JavaDoc ver = attributes.getValue("version"); //$NON-NLS-1$
835

836         if (id == null || id.trim().equals("") //$NON-NLS-1$
837
|| ver == null || ver.trim().equals("")) { //$NON-NLS-1$
838
internalError(NLS.bind(Messages.DefaultFeatureParser_IdOrVersionInvalid, (new String JavaDoc[] { id, ver, getState(currentState)})));
839         }
840
841         IncludedFeatureReferenceModel includedFeature = factory.createIncludedFeatureReferenceModel();
842         includedFeature.setFeatureIdentifier(id);
843         includedFeature.setFeatureVersion(ver);
844
845         // name
846
String JavaDoc name = attributes.getValue("name");//$NON-NLS-1$
847
includedFeature.setLabel(name);
848
849         // optional
850
String JavaDoc optional = attributes.getValue("optional");//$NON-NLS-1$
851
boolean isOptional = "true".equalsIgnoreCase(optional);//$NON-NLS-1$
852
includedFeature.isOptional(isOptional);
853
854         // search location
855
String JavaDoc locationName = attributes.getValue("search-location");//$NON-NLS-1$
856
// bug 27030
857
if (locationName == null)
858             locationName = attributes.getValue("search_location");//$NON-NLS-1$
859
int searchLocation = IUpdateConstants.SEARCH_ROOT;
860         if ("both".equalsIgnoreCase(locationName))//$NON-NLS-1$
861
searchLocation = IUpdateConstants.SEARCH_ROOT & IUpdateConstants.SEARCH_SELF;
862         if ("self".equalsIgnoreCase(locationName))//$NON-NLS-1$
863
searchLocation = IUpdateConstants.SEARCH_SELF;
864         includedFeature.setSearchLocation(searchLocation);
865
866         // os arch ws nl
867
String JavaDoc os = attributes.getValue("os");//$NON-NLS-1$
868
includedFeature.setOS(os);
869
870         String JavaDoc ws = attributes.getValue("ws");//$NON-NLS-1$
871
includedFeature.setWS(ws);
872
873         String JavaDoc arch = attributes.getValue("arch");//$NON-NLS-1$
874
includedFeature.setArch(arch);
875         
876         // NL
877
String JavaDoc nl = attributes.getValue("nl"); //$NON-NLS-1$
878
includedFeature.setNL(nl);
879
880         objectStack.push(includedFeature);
881
882         if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_PARSING) {
883             debug("End process Includes tag: id:" //$NON-NLS-1$
884
+id + " ver:" + ver); //$NON-NLS-1$
885
debug("name =" + name + " optional=" + optional + " search-location=" + locationName); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
886
debug("os=" + os + " ws=" + ws + " arch=" + arch); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
887
}
888     }
889
890     /*
891      * process URL info with label attribute
892      */

893     private void processURLInfo(Attributes JavaDoc attributes) {
894         URLEntryModel inf = factory.createURLEntryModel();
895         String JavaDoc infoURL = attributes.getValue("url"); //$NON-NLS-1$
896
String JavaDoc label = attributes.getValue("label"); //$NON-NLS-1$
897
String JavaDoc type = attributes.getValue("type"); //$NON-NLS-1$
898
inf.setURLString(infoURL);
899         inf.setAnnotation(label);
900         
901         if ("web".equalsIgnoreCase(type)) //$NON-NLS-1$
902
inf.setType(IURLEntry.WEB_SITE);
903         else
904             inf.setType(IURLEntry.UPDATE_SITE);
905
906         if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_PARSING)
907             debug("Processed URLInfo: url:" + infoURL + " label:" + label+" type:"+type);//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
908

909         objectStack.push(inf);
910     }
911
912     /*
913      * process import info
914      */

915     private void processImport(Attributes JavaDoc attributes) {
916         String JavaDoc pluginID = attributes.getValue("plugin"); //$NON-NLS-1$
917
String JavaDoc featureID = attributes.getValue("feature"); //$NON-NLS-1$
918
String JavaDoc idMatch = attributes.getValue("id-match"); //$NON-NLS-1$
919

920         if (!(pluginID == null ^ featureID == null)) {
921             internalError(Messages.DefaultFeatureParser_PluginAndFeatureId);
922             return;
923         }
924
925         // since 2.0.2 , manage feature and plugin import
926
String JavaDoc id = null;
927         if (pluginID == null) {
928             id = featureID;
929         } else {
930             id = pluginID;
931         }
932
933         if (id == null || id.trim().equals("")) //$NON-NLS-1$
934
internalError(NLS.bind(Messages.DefaultFeatureParser_MissingId, (new String JavaDoc[] { getState(currentState) })));
935         else {
936             ImportModel imp = factory.createImportModel();
937             String JavaDoc ver = attributes.getValue("version"); //$NON-NLS-1$
938
String JavaDoc match = attributes.getValue("match"); //$NON-NLS-1$
939
String JavaDoc patch = attributes.getValue("patch"); //$NON-NLS-1$
940

941             imp.setPatch(patch != null && patch.equalsIgnoreCase("true")); //$NON-NLS-1$
942

943             if (ver == null) {
944                 if (imp.isPatch()) {
945                     internalError(Messages.DefaultFeatureParser_MissingPatchVersion);
946                 }
947                 ver = "0.0.0"; //$NON-NLS-1$
948
match = "greaterOrEqual"; //$NON-NLS-1$
949
} else if (match == null) {
950                 if (imp.isPatch())
951                     match = "perfect"; //$NON-NLS-1$
952
else
953                     match = "compatible"; //$NON-NLS-1$
954
}
955
956             imp.setIdentifier(id);
957             imp.setVersion(ver);
958             imp.setFeatureImport(featureID != null);
959             imp.setMatchingRuleName(match);
960             imp.setMatchingIdRuleName(idMatch);
961
962             if (imp.isPatch()) {
963                 // patch reference must be perfect.
964
if (match != null && !match.equalsIgnoreCase("perfect")) { //$NON-NLS-1$
965
internalError(Messages.DefaultFeatureParser_wrongMatchForPatch);
966                 }
967                 if (imp.isFeatureImport() == false) {
968                     imp.setPatch(false);
969                     internalError(Messages.DefaultFeatureParser_patchWithPlugin);
970                 }
971             }
972
973             // os arch ws
974
String JavaDoc os = attributes.getValue("os"); //$NON-NLS-1$
975
imp.setOS(os);
976
977             String JavaDoc ws = attributes.getValue("ws"); //$NON-NLS-1$
978
imp.setWS(ws);
979
980             String JavaDoc arch = attributes.getValue("arch"); //$NON-NLS-1$
981
imp.setOSArch(arch);
982
983             objectStack.push(imp);
984
985             if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_PARSING) {
986                 debug("Processed import: id:" + id + " ver:" + ver);//$NON-NLS-1$ //$NON-NLS-2$
987
debug("Processed import: match:" + match); //$NON-NLS-1$
988
}
989
990         }
991     }
992
993     /*
994      * process import info
995      */

996     private void processRequire(Attributes JavaDoc attributes) {
997     }
998
999     /*
1000     * process plugin entry info
1001     */

1002    private void processPlugin(Attributes JavaDoc attributes) {
1003        String JavaDoc id = attributes.getValue("id"); //$NON-NLS-1$
1004
String JavaDoc ver = attributes.getValue("version"); //$NON-NLS-1$
1005
if (id == null || id.trim().equals("") //$NON-NLS-1$
1006
|| ver == null || ver.trim().equals("")) { //$NON-NLS-1$
1007
internalError(NLS.bind(Messages.DefaultFeatureParser_IdOrVersionInvalid, (new String JavaDoc[] { id, ver, getState(currentState)})));
1008        } else {
1009            PluginEntryModel pluginEntry = factory.createPluginEntryModel();
1010            pluginEntry.setPluginIdentifier(id);
1011            pluginEntry.setPluginVersion(ver);
1012
1013            String JavaDoc fragment = attributes.getValue("fragment"); //$NON-NLS-1$
1014
pluginEntry.isFragment(fragment != null && fragment.trim().equalsIgnoreCase("true"));//$NON-NLS-1$
1015

1016            //setOS
1017
String JavaDoc os = attributes.getValue("os"); //$NON-NLS-1$
1018
pluginEntry.setOS(os);
1019
1020            //setWS
1021
String JavaDoc ws = attributes.getValue("ws"); //$NON-NLS-1$
1022
pluginEntry.setWS(ws);
1023
1024            //setNL
1025
String JavaDoc nl = attributes.getValue("nl"); //$NON-NLS-1$
1026
pluginEntry.setNL(nl);
1027
1028            // setArch
1029
String JavaDoc arch = attributes.getValue("arch"); //$NON-NLS-1$
1030
pluginEntry.setArch(arch);
1031
1032            // setUnpack
1033
String JavaDoc unpack = attributes.getValue("unpack"); //$NON-NLS-1$
1034
pluginEntry.setUnpack(!"false".equalsIgnoreCase(unpack)); //$NON-NLS-1$
1035

1036            // download size
1037
long download_size = ContentEntryModel.UNKNOWN_SIZE;
1038            String JavaDoc download = attributes.getValue("download-size"); //$NON-NLS-1$
1039
if (download != null && !download.trim().equals("")) { //$NON-NLS-1$
1040
try {
1041                    download_size = Long.valueOf(download).longValue();
1042                } catch (NumberFormatException JavaDoc e) {
1043                    // use UNKNOWN_SIZE
1044
}
1045            }
1046            pluginEntry.setDownloadSize(download_size);
1047
1048            // install size
1049
long install_size = ContentEntryModel.UNKNOWN_SIZE;
1050            String JavaDoc install = attributes.getValue("install-size"); //$NON-NLS-1$
1051
if (install != null && !install.trim().equals("")) { //$NON-NLS-1$
1052
try {
1053                    install_size = Long.valueOf(install).longValue();
1054                } catch (NumberFormatException JavaDoc e) {
1055                    // use UNKNOWN_SIZE
1056
}
1057            }
1058            pluginEntry.setInstallSize(install_size);
1059
1060            objectStack.push(pluginEntry);
1061
1062            if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_PARSING) {
1063                debug("Processed Plugin: id:" + id + " ver:" + ver + " fragment:" + fragment); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1064
debug("Processed Plugin: os:" + os + " ws:" + ws + " nl:" + nl); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1065
debug("Processed Plugin: download size:" //$NON-NLS-1$
1066
+download_size + " install size:" //$NON-NLS-1$
1067
+install_size);
1068            }
1069
1070        }
1071    }
1072
1073    /*
1074     * process non-plug-in entry info
1075     */

1076    private void processData(Attributes JavaDoc attributes) {
1077        String JavaDoc id = attributes.getValue("id"); //$NON-NLS-1$
1078
if (id == null || id.trim().equals("")) { //$NON-NLS-1$
1079
internalError(NLS.bind(Messages.DefaultFeatureParser_MissingId, (new String JavaDoc[] { getState(currentState) })));
1080        } else {
1081            NonPluginEntryModel dataEntry = factory.createNonPluginEntryModel();
1082            dataEntry.setIdentifier(id);
1083
1084            //setOS
1085
String JavaDoc os = attributes.getValue("os"); //$NON-NLS-1$
1086
dataEntry.setOS(os);
1087
1088            //setWS
1089
String JavaDoc ws = attributes.getValue("ws"); //$NON-NLS-1$
1090
dataEntry.setWS(ws);
1091
1092            //setNL
1093
String JavaDoc nl = attributes.getValue("nl"); //$NON-NLS-1$
1094
dataEntry.setNL(nl);
1095
1096            // setArch
1097
String JavaDoc arch = attributes.getValue("arch"); //$NON-NLS-1$
1098
dataEntry.setArch(arch);
1099
1100            // download size
1101
long download_size = ContentEntryModel.UNKNOWN_SIZE;
1102            String JavaDoc download = attributes.getValue("download-size"); //$NON-NLS-1$
1103
if (download != null && !download.trim().equals("")) { //$NON-NLS-1$
1104
try {
1105                    download_size = Long.valueOf(download).longValue();
1106                } catch (NumberFormatException JavaDoc e) {
1107                    // use UNKNOWN_SIZE
1108
}
1109            }
1110            dataEntry.setDownloadSize(download_size);
1111
1112            // install size
1113
long install_size = ContentEntryModel.UNKNOWN_SIZE;
1114            String JavaDoc install = attributes.getValue("install-size"); //$NON-NLS-1$
1115
if (install != null && !install.trim().equals("")) { //$NON-NLS-1$
1116
try {
1117                    install_size = Long.valueOf(install).longValue();
1118                } catch (NumberFormatException JavaDoc e) {
1119                    // use UNKNOWN_SIZE
1120
}
1121            }
1122            dataEntry.setInstallSize(install_size);
1123
1124            objectStack.push(dataEntry);
1125
1126            if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_PARSING) {
1127                debug("Processed Data: id:" + id); //$NON-NLS-1$
1128
debug("Processed Data: download size:" //$NON-NLS-1$
1129
+download_size + " install size:" //$NON-NLS-1$
1130
+install_size);
1131            }
1132
1133        }
1134    }
1135
1136    private void debug(String JavaDoc s) {
1137        UpdateCore.debug("InternalFeatureParser: " + s); //$NON-NLS-1$
1138
}
1139
1140    private void logStatus(SAXParseException JavaDoc ex) {
1141        String JavaDoc name = ex.getSystemId();
1142        if (name == null)
1143            name = ""; //$NON-NLS-1$
1144
else
1145            name = name.substring(1 + name.lastIndexOf("/")); //$NON-NLS-1$
1146

1147        String JavaDoc msg;
1148        if (name.equals("")) { //$NON-NLS-1$
1149
msg = NLS.bind(Messages.DefaultFeatureParser_ErrorParsing, (new String JavaDoc[] { ex.getMessage() }));
1150        } else {
1151            String JavaDoc[] values = new String JavaDoc[] { name, Integer.toString(ex.getLineNumber()), Integer.toString(ex.getColumnNumber()), ex.getMessage()};
1152            msg = NLS.bind(Messages.DefaultFeatureParser_ErrorlineColumnMessage, values);
1153        }
1154        error(new Status(IStatus.ERROR, PLUGIN_ID, Platform.PARSE_PROBLEM, msg, ex));
1155    }
1156
1157    /*
1158     * Handles an error state specified by the status. The collection of all logged status
1159     * objects can be accessed using <code>getStatus()</code>.
1160     *
1161     * @param error a status detailing the error condition
1162     */

1163    private void error(IStatus error) {
1164
1165        if (status == null) {
1166            status = new MultiStatus(PLUGIN_ID, Platform.PARSE_PROBLEM, Messages.DefaultFeatureParser_ErrorParsingFeature, null);
1167        }
1168
1169        status.add(error);
1170        if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_PARSING)
1171            UpdateCore.log(error);
1172    }
1173
1174    private void internalErrorUnknownTag(String JavaDoc msg) {
1175        stateStack.push(new Integer JavaDoc(STATE_IGNORED_ELEMENT));
1176        internalError(msg);
1177    }
1178
1179    private void internalError(String JavaDoc message) {
1180        if (location != null)
1181            message += " " + NLS.bind(Messages.DefaultFeatureParser_location, (new String JavaDoc[] { location })); //$NON-NLS-1$
1182
error(new Status(IStatus.ERROR, PLUGIN_ID, Platform.PARSE_PROBLEM, message, null));
1183    }
1184
1185    /*
1186     * return the state as String
1187     */

1188    private String JavaDoc getState(int state) {
1189
1190        switch (state) {
1191            case STATE_IGNORED_ELEMENT :
1192                return "Ignored"; //$NON-NLS-1$
1193

1194            case STATE_INITIAL :
1195                return "Initial"; //$NON-NLS-1$
1196

1197            case STATE_FEATURE :
1198                return "Feature"; //$NON-NLS-1$
1199

1200            case STATE_HANDLER :
1201                return "Install Handler"; //$NON-NLS-1$
1202

1203            case STATE_DESCRIPTION :
1204                return "description"; //$NON-NLS-1$
1205

1206            case STATE_INCLUDES :
1207                return "includes"; //$NON-NLS-1$
1208

1209            case STATE_COPYRIGHT :
1210                return "Copyright"; //$NON-NLS-1$
1211

1212            case STATE_LICENSE :
1213                return "License"; //$NON-NLS-1$
1214

1215            case STATE_URL :
1216                return "URL"; //$NON-NLS-1$
1217

1218            case STATE_UPDATE :
1219                return "Update URL"; //$NON-NLS-1$
1220

1221            case STATE_DISCOVERY :
1222                return "Discovery URL"; //$NON-NLS-1$
1223

1224            case STATE_REQUIRES :
1225                return "Require"; //$NON-NLS-1$
1226

1227            case STATE_IMPORT :
1228                return "Import"; //$NON-NLS-1$
1229

1230            case STATE_PLUGIN :
1231                return "Plugin"; //$NON-NLS-1$
1232

1233            case STATE_DATA :
1234                return "Data"; //$NON-NLS-1$
1235

1236            default :
1237                return NLS.bind(Messages.DefaultFeatureParser_UnknownState, (new String JavaDoc[] { Integer.toString(state) }));
1238        }
1239
1240    }
1241
1242    /**
1243     * @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)
1244     */

1245    public void ignorableWhitespace(char[] arg0, int arg1, int arg2) throws SAXException JavaDoc {
1246        super.ignorableWhitespace(arg0, arg1, arg2);
1247    }
1248}
1249
Popular Tags