1 11 package org.eclipse.update.internal.core; 12 13 14 import java.io.IOException ; 15 import java.io.InputStream ; 16 import java.util.Iterator ; 17 import java.util.Stack ; 18 19 import javax.xml.parsers.ParserConfigurationException ; 20 import javax.xml.parsers.SAXParser ; 21 import javax.xml.parsers.SAXParserFactory ; 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 ; 40 import org.xml.sax.InputSource ; 41 import org.xml.sax.SAXException ; 42 import org.xml.sax.SAXParseException ; 43 import org.xml.sax.helpers.DefaultHandler ; 44 45 63 public class InternalFeatureParser extends DefaultHandler { 64 65 private SAXParser 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 PLUGIN_ID = UpdateCore.getPlugin().getBundle().getSymbolicName(); 87 88 private static final String FEATURE = "feature"; private static final String INCLUDES = "includes"; private static final String HANDLER = "install-handler"; private static final String DESCRIPTION = "description"; private static final String COPYRIGHT = "copyright"; private static final String LICENSE = "license"; private static final String URL = "url"; private static final String UPDATE = "update"; private static final String DISCOVERY = "discovery"; private static final String REQUIRES = "requires"; private static final String IMPORT = "import"; private static final String PLUGIN = "plugin"; private static final String DATA = "data"; Stack stateStack = new Stack (); 103 104 Stack objectStack = new Stack (); 107 108 private int currentState; 109 private String location; 110 111 private final static SAXParserFactory parserFactory = 112 SAXParserFactory.newInstance(); 113 114 119 public InternalFeatureParser() { 120 super(); 121 try { 122 parserFactory.setNamespaceAware(true); 123 this.parser = parserFactory.newSAXParser(); 124 } catch (ParserConfigurationException e) { 125 UpdateCore.log(e); 126 } catch (SAXException e) { 127 UpdateCore.log(e); 128 } 129 } 130 131 public void init(FeatureModelFactory factory) { 132 init(factory, null); 133 } 134 135 140 public void init(FeatureModelFactory factory, String location) { 141 this.factory = factory; 143 stateStack = new Stack (); 144 objectStack = new Stack (); 145 status = null; 146 URL_ALREADY_SEEN = false; 147 this.location = location; 148 } 150 151 public void internalInit(FeatureModelFactory factory, String location) { 152 init(factory, location); 153 stateStack.push(new Integer (STATE_INITIAL)); 154 currentState = ((Integer ) stateStack.peek()).intValue(); 155 } 156 157 public FeatureModel getFeatureModel() throws SAXException { 158 if (objectStack.isEmpty()) 159 throw new SAXException (Messages.DefaultFeatureParser_NoFeatureTag); 160 else { 161 if (objectStack.peek() instanceof FeatureModel) { 162 return (FeatureModel) objectStack.pop(); 163 } else { 164 String stack = ""; Iterator iter = objectStack.iterator(); 166 while (iter.hasNext()) { 167 stack = "\r\n" + iter.next().toString() + stack; } 169 throw new SAXException (NLS.bind(Messages.DefaultFeatureParser_WrongParsingStack, (new String [] { stack }))); 170 } 171 } 172 } 173 174 184 public FeatureModel parse(InputStream in) throws SAXException , IOException { 185 stateStack.push(new Integer (STATE_INITIAL)); 186 currentState = ((Integer ) stateStack.peek()).intValue(); 187 parser.parse(new InputSource (in), this); 188 return getFeatureModel(); 189 } 190 191 197 public MultiStatus getStatus() { 198 return status; 199 } 200 201 206 public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { 207 208 if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_PARSING) 209 debug("Start Element: uri:" + uri + " local Name:" + localName + " qName:" + qName); 211 switch (currentState) { 212 case STATE_IGNORED_ELEMENT : 213 internalErrorUnknownTag(NLS.bind(Messages.DefaultFeatureParser_UnknownElement, (new String [] { 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 [] { Integer.toString(currentState) }))); 255 break; 256 } 257 258 int newState = ((Integer ) stateStack.peek()).intValue(); 259 if (newState != STATE_IGNORED_ELEMENT) 260 currentState = newState; 261 262 } 263 264 269 public void endElement(String uri, String localName, String qName) { 270 271 URLEntryModel info = null; 273 FeatureModel featureModel = null; 274 String text = null; 275 int innerState = 0; 276 277 int state = ((Integer ) 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 ) { 290 text = (String ) objectStack.pop(); 291 FeatureModel feature = (FeatureModel) objectStack.peek(); 292 feature.getDescriptionModel().setAnnotation(text); 293 } 294 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 [] { getState(state) }))); 315 else 316 featureModel.setInstallHandlerModel(handlerModel); 317 } 318 break; 319 320 case STATE_DESCRIPTION : 321 stateStack.pop(); 322 323 text = ""; while (objectStack.peek() instanceof String ) { 325 text = (String ) 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 ) 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 [] { getState(state) }))); 340 else 341 featureModel.setDescriptionModel(info); 342 } 343 break; 344 345 default : 346 internalError(NLS.bind(Messages.DefaultFeatureParser_StateIncludeWrongElement, (new String [] { getState(innerState), getState(state) }))); 347 break; 348 349 } 350 } 351 break; 352 353 case STATE_COPYRIGHT : 354 stateStack.pop(); 355 text = ""; while (objectStack.peek() instanceof String ) { 357 text = (String ) 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 ) 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 [] { getState(state) }))); 373 else 374 featureModel.setCopyrightModel(info); 375 } 376 break; 377 378 default : 379 internalError(NLS.bind(Messages.DefaultFeatureParser_StateIncludeWrongElement, (new String [] { getState(innerState), getState(state) }))); 380 break; 381 382 } 383 } 384 break; 385 386 case STATE_LICENSE : 387 stateStack.pop(); 388 389 text = ""; while (objectStack.peek() instanceof String ) { 391 text = (String ) 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 ) 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 [] { getState(state) }))); 407 else 408 featureModel.setLicenseModel(info); 409 } 410 break; 411 412 default : 413 internalError(NLS.bind(Messages.DefaultFeatureParser_StateIncludeWrongElement, (new String [] { 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 [] { 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); } 516 517 525 private String cleanupText(String text) { 526 text = text.trim(); 527 if ("".equals(text)) return null; return text; 529 } 530 531 536 public void characters(char[] ch, int start, int length) { 537 String text = ""; boolean valid = true; 539 540 if (valid) { 541 text = new String (ch, start, length); 542 } 543 544 int state = ((Integer ) stateStack.peek()).intValue(); 546 if (state == STATE_DESCRIPTION || state == STATE_COPYRIGHT || state == STATE_LICENSE) 547 objectStack.push(text); 548 549 } 550 551 556 public void error(SAXParseException ex) { 557 logStatus(ex); 558 } 559 560 566 public void fatalError(SAXParseException ex) throws SAXException { 567 logStatus(ex); 568 throw ex; 569 } 570 571 private void handleInitialState(String elementName, Attributes attributes) throws SAXException { 572 if (elementName.equals(FEATURE)) { 573 stateStack.push(new Integer (STATE_FEATURE)); 574 processFeature(attributes); 575 } else 576 internalErrorUnknownTag(NLS.bind(Messages.DefaultFeatureParser_UnknownElement, (new String [] { elementName, getState(currentState) }))); 577 } 578 579 private void handleFeatureState(String elementName, Attributes attributes) throws SAXException { 580 if (elementName.equals(HANDLER)) { 581 stateStack.push(new Integer (STATE_HANDLER)); 582 processHandler(attributes); 583 } else if (elementName.equals(DESCRIPTION)) { 584 stateStack.push(new Integer (STATE_DESCRIPTION)); 585 processInfo(attributes); 586 } else if (elementName.equals(COPYRIGHT)) { 587 stateStack.push(new Integer (STATE_COPYRIGHT)); 588 processInfo(attributes); 589 } else if (elementName.equals(LICENSE)) { 590 stateStack.push(new Integer (STATE_LICENSE)); 591 processInfo(attributes); 592 } else if (elementName.equals(URL)) { 593 stateStack.push(new Integer (STATE_URL)); 594 } else if (elementName.equals(INCLUDES)) { 596 stateStack.push(new Integer (STATE_INCLUDES)); 597 processIncludes(attributes); 598 } else if (elementName.equals(REQUIRES)) { 599 stateStack.push(new Integer (STATE_REQUIRES)); 600 processRequire(attributes); 601 } else if (elementName.equals(PLUGIN)) { 602 stateStack.push(new Integer (STATE_PLUGIN)); 603 processPlugin(attributes); 604 } else if (elementName.equals(DATA)) { 605 stateStack.push(new Integer (STATE_DATA)); 606 processData(attributes); 607 } else 608 internalErrorUnknownTag(NLS.bind(Messages.DefaultFeatureParser_UnknownElement, (new String [] { elementName, getState(currentState) }))); 609 } 610 611 private void handleURLState(String elementName, Attributes attributes) throws SAXException { 612 if (elementName.equals(UPDATE)) { 613 stateStack.push(new Integer (STATE_UPDATE)); 614 processURLInfo(attributes); 615 } else if (elementName.equals(DISCOVERY)) { 616 stateStack.push(new Integer (STATE_DISCOVERY)); 617 processURLInfo(attributes); 618 } else 619 internalErrorUnknownTag(NLS.bind(Messages.DefaultFeatureParser_UnknownElement, (new String [] { elementName, getState(currentState) }))); 620 } 621 622 private void handleRequiresState(String elementName, Attributes attributes) throws SAXException { 623 if (elementName.equals(IMPORT)) { 624 stateStack.push(new Integer (STATE_IMPORT)); 625 processImport(attributes); 626 } else 627 internalErrorUnknownTag(NLS.bind(Messages.DefaultFeatureParser_UnknownElement, (new String [] { elementName, getState(currentState) }))); 628 } 629 private void handleUpdateDiscoveryState(String elementName, Attributes attributes) throws SAXException { 630 if (elementName.equals(HANDLER)) { 631 stateStack.push(new Integer (STATE_HANDLER)); 632 processHandler(attributes); 633 } else if (elementName.equals(DESCRIPTION)) { 634 stateStack.push(new Integer (STATE_DESCRIPTION)); 635 processInfo(attributes); 636 } else if (elementName.equals(COPYRIGHT)) { 637 stateStack.push(new Integer (STATE_COPYRIGHT)); 638 processInfo(attributes); 639 } else if (elementName.equals(LICENSE)) { 640 stateStack.push(new Integer (STATE_LICENSE)); 641 processInfo(attributes); 642 } else if (elementName.equals(URL)) { 643 stateStack.push(new Integer (STATE_URL)); 644 } else if (elementName.equals(INCLUDES)) { 646 stateStack.push(new Integer (STATE_INCLUDES)); 647 processIncludes(attributes); 648 } else if (elementName.equals(REQUIRES)) { 649 stateStack.push(new Integer (STATE_REQUIRES)); 650 processRequire(attributes); 651 } else if (elementName.equals(PLUGIN)) { 652 stateStack.push(new Integer (STATE_PLUGIN)); 653 processPlugin(attributes); 654 } else if (elementName.equals(DATA)) { 655 stateStack.push(new Integer (STATE_DATA)); 656 processData(attributes); 657 } else if (elementName.equals(UPDATE)) { 658 stateStack.push(new Integer (STATE_UPDATE)); 659 processURLInfo(attributes); 660 } else if (elementName.equals(DISCOVERY)) { 661 stateStack.push(new Integer (STATE_DISCOVERY)); 662 processURLInfo(attributes); 663 } else 664 internalErrorUnknownTag(NLS.bind(Messages.DefaultFeatureParser_UnknownElement, (new String [] { elementName, getState(currentState) }))); 665 } 666 667 668 669 private void handleImportState(String elementName, Attributes attributes) throws SAXException { 670 if (elementName.equals(HANDLER)) { 671 stateStack.push(new Integer (STATE_HANDLER)); 672 processHandler(attributes); 673 } else if (elementName.equals(DESCRIPTION)) { 674 stateStack.push(new Integer (STATE_DESCRIPTION)); 675 processInfo(attributes); 676 } else if (elementName.equals(COPYRIGHT)) { 677 stateStack.push(new Integer (STATE_COPYRIGHT)); 678 processInfo(attributes); 679 } else if (elementName.equals(LICENSE)) { 680 stateStack.push(new Integer (STATE_LICENSE)); 681 processInfo(attributes); 682 } else if (elementName.equals(URL)) { 683 stateStack.push(new Integer (STATE_URL)); 684 } else if (elementName.equals(INCLUDES)) { 686 stateStack.push(new Integer (STATE_INCLUDES)); 687 processIncludes(attributes); 688 } else if (elementName.equals(REQUIRES)) { 689 stateStack.push(new Integer (STATE_REQUIRES)); 690 processRequire(attributes); 691 } else if (elementName.equals(PLUGIN)) { 692 stateStack.push(new Integer (STATE_PLUGIN)); 693 processPlugin(attributes); 694 } else if (elementName.equals(DATA)) { 695 stateStack.push(new Integer (STATE_DATA)); 696 processData(attributes); 697 } else if (elementName.equals(IMPORT)) { 698 stateStack.push(new Integer (STATE_IMPORT)); 699 processImport(attributes); 700 } else 701 internalErrorUnknownTag(NLS.bind(Messages.DefaultFeatureParser_UnknownElement, (new String [] { elementName, getState(currentState) }))); 702 } 703 704 707 private void processFeature(Attributes attributes) { 708 709 String id = attributes.getValue("id"); String ver = attributes.getValue("version"); 713 if (id == null || id.trim().equals("") || ver == null || ver.trim().equals("")) { internalError(NLS.bind(Messages.DefaultFeatureParser_IdOrVersionInvalid, (new String [] { id, ver, getState(currentState)}))); 716 } else { 717 FeatureModel feature = factory.createFeatureModel(); 719 720 feature.setFeatureIdentifier(id); 721 feature.setFeatureVersion(ver); 722 723 String label = attributes.getValue("label"); feature.setLabel(label); 726 727 String provider = attributes.getValue("provider-name"); feature.setProvider(provider); 730 731 String imageURL = attributes.getValue("image"); feature.setImageURLString(imageURL); 734 735 String os = attributes.getValue("os"); feature.setOS(os); 738 739 String ws = attributes.getValue("ws"); feature.setWS(ws); 742 743 String nl = attributes.getValue("nl"); feature.setNL(nl); 746 747 String arch = attributes.getValue("arch"); feature.setArch(arch); 750 751 String primary = attributes.getValue("primary"); feature.setPrimary(primary != null && primary.trim().equalsIgnoreCase("true")); 755 String exclusive = attributes.getValue("exclusive"); feature.setExclusive(exclusive != null && exclusive.trim().equalsIgnoreCase("true")); 759 String application = attributes.getValue("application"); feature.setApplication(application); 762 763 String affinity = attributes.getValue("colocation-affinity"); feature.setAffinityFeature(affinity); 766 767 String plugin = attributes.getValue("plugin"); feature.setPrimaryPluginID(plugin); 770 771 objectStack.push(feature); 772 773 if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_PARSING) { 774 debug("End process DefaultFeature tag: id:" +id + " ver:" +ver + " label:" +label + " provider:" +provider); 779 debug("End process DefaultFeature tag: image:" + imageURL); debug("End process DefaultFeature tag: ws:" +ws + " os:" +os + " nl:" +nl + " application:" +application); 785 } 786 } 787 } 788 789 792 private void processHandler(Attributes attributes) { 793 InstallHandlerEntryModel handler = factory.createInstallHandlerEntryModel(); 794 795 String handlerURL = attributes.getValue("url"); handler.setURLString(handlerURL); 797 798 String library = attributes.getValue("library"); handler.setLibrary(library); 800 801 String clazz = attributes.getValue("handler"); handler.setHandlerName(clazz); 803 804 objectStack.push(handler); 805 806 if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_PARSING) 807 debug("Processed Handler: url:" +handlerURL + " library:" +library + " class:" +clazz); 811 } 812 813 816 private void processInfo(Attributes attributes) { 817 URLEntryModel inf = factory.createURLEntryModel(); 818 String infoURL = attributes.getValue("url"); inf.setURLString(infoURL); 820 821 objectStack.push(inf); 822 823 if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_PARSING) 824 debug("Processed Info: url:" + infoURL); } 826 827 830 private void processIncludes(Attributes attributes) { 831 832 String id = attributes.getValue("id"); String ver = attributes.getValue("version"); 836 if (id == null || id.trim().equals("") || ver == null || ver.trim().equals("")) { internalError(NLS.bind(Messages.DefaultFeatureParser_IdOrVersionInvalid, (new String [] { id, ver, getState(currentState)}))); 839 } 840 841 IncludedFeatureReferenceModel includedFeature = factory.createIncludedFeatureReferenceModel(); 842 includedFeature.setFeatureIdentifier(id); 843 includedFeature.setFeatureVersion(ver); 844 845 String name = attributes.getValue("name"); includedFeature.setLabel(name); 848 849 String optional = attributes.getValue("optional"); boolean isOptional = "true".equalsIgnoreCase(optional); includedFeature.isOptional(isOptional); 853 854 String locationName = attributes.getValue("search-location"); if (locationName == null) 858 locationName = attributes.getValue("search_location"); int searchLocation = IUpdateConstants.SEARCH_ROOT; 860 if ("both".equalsIgnoreCase(locationName)) searchLocation = IUpdateConstants.SEARCH_ROOT & IUpdateConstants.SEARCH_SELF; 862 if ("self".equalsIgnoreCase(locationName)) searchLocation = IUpdateConstants.SEARCH_SELF; 864 includedFeature.setSearchLocation(searchLocation); 865 866 String os = attributes.getValue("os"); includedFeature.setOS(os); 869 870 String ws = attributes.getValue("ws"); includedFeature.setWS(ws); 872 873 String arch = attributes.getValue("arch"); includedFeature.setArch(arch); 875 876 String nl = attributes.getValue("nl"); includedFeature.setNL(nl); 879 880 objectStack.push(includedFeature); 881 882 if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_PARSING) { 883 debug("End process Includes tag: id:" +id + " ver:" + ver); debug("name =" + name + " optional=" + optional + " search-location=" + locationName); debug("os=" + os + " ws=" + ws + " arch=" + arch); } 888 } 889 890 893 private void processURLInfo(Attributes attributes) { 894 URLEntryModel inf = factory.createURLEntryModel(); 895 String infoURL = attributes.getValue("url"); String label = attributes.getValue("label"); String type = attributes.getValue("type"); inf.setURLString(infoURL); 899 inf.setAnnotation(label); 900 901 if ("web".equalsIgnoreCase(type)) 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); 909 objectStack.push(inf); 910 } 911 912 915 private void processImport(Attributes attributes) { 916 String pluginID = attributes.getValue("plugin"); String featureID = attributes.getValue("feature"); String idMatch = attributes.getValue("id-match"); 920 if (!(pluginID == null ^ featureID == null)) { 921 internalError(Messages.DefaultFeatureParser_PluginAndFeatureId); 922 return; 923 } 924 925 String id = null; 927 if (pluginID == null) { 928 id = featureID; 929 } else { 930 id = pluginID; 931 } 932 933 if (id == null || id.trim().equals("")) internalError(NLS.bind(Messages.DefaultFeatureParser_MissingId, (new String [] { getState(currentState) }))); 935 else { 936 ImportModel imp = factory.createImportModel(); 937 String ver = attributes.getValue("version"); String match = attributes.getValue("match"); String patch = attributes.getValue("patch"); 941 imp.setPatch(patch != null && patch.equalsIgnoreCase("true")); 943 if (ver == null) { 944 if (imp.isPatch()) { 945 internalError(Messages.DefaultFeatureParser_MissingPatchVersion); 946 } 947 ver = "0.0.0"; match = "greaterOrEqual"; } else if (match == null) { 950 if (imp.isPatch()) 951 match = "perfect"; else 953 match = "compatible"; } 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 if (match != null && !match.equalsIgnoreCase("perfect")) { internalError(Messages.DefaultFeatureParser_wrongMatchForPatch); 966 } 967 if (imp.isFeatureImport() == false) { 968 imp.setPatch(false); 969 internalError(Messages.DefaultFeatureParser_patchWithPlugin); 970 } 971 } 972 973 String os = attributes.getValue("os"); imp.setOS(os); 976 977 String ws = attributes.getValue("ws"); imp.setWS(ws); 979 980 String arch = attributes.getValue("arch"); 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); debug("Processed import: match:" + match); } 989 990 } 991 } 992 993 996 private void processRequire(Attributes attributes) { 997 } 998 999 1002 private void processPlugin(Attributes attributes) { 1003 String id = attributes.getValue("id"); String ver = attributes.getValue("version"); if (id == null || id.trim().equals("") || ver == null || ver.trim().equals("")) { internalError(NLS.bind(Messages.DefaultFeatureParser_IdOrVersionInvalid, (new String [] { id, ver, getState(currentState)}))); 1008 } else { 1009 PluginEntryModel pluginEntry = factory.createPluginEntryModel(); 1010 pluginEntry.setPluginIdentifier(id); 1011 pluginEntry.setPluginVersion(ver); 1012 1013 String fragment = attributes.getValue("fragment"); pluginEntry.isFragment(fragment != null && fragment.trim().equalsIgnoreCase("true")); 1016 String os = attributes.getValue("os"); pluginEntry.setOS(os); 1019 1020 String ws = attributes.getValue("ws"); pluginEntry.setWS(ws); 1023 1024 String nl = attributes.getValue("nl"); pluginEntry.setNL(nl); 1027 1028 String arch = attributes.getValue("arch"); pluginEntry.setArch(arch); 1031 1032 String unpack = attributes.getValue("unpack"); pluginEntry.setUnpack(!"false".equalsIgnoreCase(unpack)); 1036 long download_size = ContentEntryModel.UNKNOWN_SIZE; 1038 String download = attributes.getValue("download-size"); if (download != null && !download.trim().equals("")) { try { 1041 download_size = Long.valueOf(download).longValue(); 1042 } catch (NumberFormatException e) { 1043 } 1045 } 1046 pluginEntry.setDownloadSize(download_size); 1047 1048 long install_size = ContentEntryModel.UNKNOWN_SIZE; 1050 String install = attributes.getValue("install-size"); if (install != null && !install.trim().equals("")) { try { 1053 install_size = Long.valueOf(install).longValue(); 1054 } catch (NumberFormatException e) { 1055 } 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); debug("Processed Plugin: os:" + os + " ws:" + ws + " nl:" + nl); debug("Processed Plugin: download size:" +download_size + " install size:" +install_size); 1068 } 1069 1070 } 1071 } 1072 1073 1076 private void processData(Attributes attributes) { 1077 String id = attributes.getValue("id"); if (id == null || id.trim().equals("")) { internalError(NLS.bind(Messages.DefaultFeatureParser_MissingId, (new String [] { getState(currentState) }))); 1080 } else { 1081 NonPluginEntryModel dataEntry = factory.createNonPluginEntryModel(); 1082 dataEntry.setIdentifier(id); 1083 1084 String os = attributes.getValue("os"); dataEntry.setOS(os); 1087 1088 String ws = attributes.getValue("ws"); dataEntry.setWS(ws); 1091 1092 String nl = attributes.getValue("nl"); dataEntry.setNL(nl); 1095 1096 String arch = attributes.getValue("arch"); dataEntry.setArch(arch); 1099 1100 long download_size = ContentEntryModel.UNKNOWN_SIZE; 1102 String download = attributes.getValue("download-size"); if (download != null && !download.trim().equals("")) { try { 1105 download_size = Long.valueOf(download).longValue(); 1106 } catch (NumberFormatException e) { 1107 } 1109 } 1110 dataEntry.setDownloadSize(download_size); 1111 1112 long install_size = ContentEntryModel.UNKNOWN_SIZE; 1114 String install = attributes.getValue("install-size"); if (install != null && !install.trim().equals("")) { try { 1117 install_size = Long.valueOf(install).longValue(); 1118 } catch (NumberFormatException e) { 1119 } 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); debug("Processed Data: download size:" +download_size + " install size:" +install_size); 1131 } 1132 1133 } 1134 } 1135 1136 private void debug(String s) { 1137 UpdateCore.debug("InternalFeatureParser: " + s); } 1139 1140 private void logStatus(SAXParseException ex) { 1141 String name = ex.getSystemId(); 1142 if (name == null) 1143 name = ""; else 1145 name = name.substring(1 + name.lastIndexOf("/")); 1147 String msg; 1148 if (name.equals("")) { msg = NLS.bind(Messages.DefaultFeatureParser_ErrorParsing, (new String [] { ex.getMessage() })); 1150 } else { 1151 String [] values = new String [] { 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 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 msg) { 1175 stateStack.push(new Integer (STATE_IGNORED_ELEMENT)); 1176 internalError(msg); 1177 } 1178 1179 private void internalError(String message) { 1180 if (location != null) 1181 message += " " + NLS.bind(Messages.DefaultFeatureParser_location, (new String [] { location })); error(new Status(IStatus.ERROR, PLUGIN_ID, Platform.PARSE_PROBLEM, message, null)); 1183 } 1184 1185 1188 private String getState(int state) { 1189 1190 switch (state) { 1191 case STATE_IGNORED_ELEMENT : 1192 return "Ignored"; 1194 case STATE_INITIAL : 1195 return "Initial"; 1197 case STATE_FEATURE : 1198 return "Feature"; 1200 case STATE_HANDLER : 1201 return "Install Handler"; 1203 case STATE_DESCRIPTION : 1204 return "description"; 1206 case STATE_INCLUDES : 1207 return "includes"; 1209 case STATE_COPYRIGHT : 1210 return "Copyright"; 1212 case STATE_LICENSE : 1213 return "License"; 1215 case STATE_URL : 1216 return "URL"; 1218 case STATE_UPDATE : 1219 return "Update URL"; 1221 case STATE_DISCOVERY : 1222 return "Discovery URL"; 1224 case STATE_REQUIRES : 1225 return "Require"; 1227 case STATE_IMPORT : 1228 return "Import"; 1230 case STATE_PLUGIN : 1231 return "Plugin"; 1233 case STATE_DATA : 1234 return "Data"; 1236 default : 1237 return NLS.bind(Messages.DefaultFeatureParser_UnknownState, (new String [] { Integer.toString(state) })); 1238 } 1239 1240 } 1241 1242 1245 public void ignorableWhitespace(char[] arg0, int arg1, int arg2) throws SAXException { 1246 super.ignorableWhitespace(arg0, arg1, arg2); 1247 } 1248} 1249 | Popular Tags |