001/* 002 =================== DO NOT EDIT THIS FILE ==================== 003 004 Generated by Modello 2.4.0, 005 006 any modifications will be overwritten. 007 008 ============================================================== 009 */ 010 011package org.apache.maven.tools.plugin.extractor.model.io.xpp3; 012 013 //---------------------------------/ 014 //- Imported classes and packages -/ 015//---------------------------------/ 016 017import java.io.IOException; 018import java.io.InputStream; 019import java.io.Reader; 020import java.text.DateFormat; 021import org.apache.maven.tools.plugin.extractor.model.Component; 022import org.apache.maven.tools.plugin.extractor.model.LifecycleExecution; 023import org.apache.maven.tools.plugin.extractor.model.Mojo; 024import org.apache.maven.tools.plugin.extractor.model.Parameter; 025import org.apache.maven.tools.plugin.extractor.model.PluginMetadata; 026import org.codehaus.plexus.util.xml.XmlStreamReader; 027import org.codehaus.plexus.util.xml.pull.EntityReplacementMap; 028import org.codehaus.plexus.util.xml.pull.MXParser; 029import org.codehaus.plexus.util.xml.pull.XmlPullParser; 030import org.codehaus.plexus.util.xml.pull.XmlPullParserException; 031 032/** 033 * Class PluginMetadataXpp3Reader. 034 * 035 * @version $Revision$ $Date$ 036 */ 037@SuppressWarnings( "all" ) 038public class PluginMetadataXpp3Reader 039{ 040 041 //--------------------------/ 042 //- Class/Member Variables -/ 043 //--------------------------/ 044 045 /** 046 * If set the parser will be loaded with all single characters 047 * from the XHTML specification. 048 * The entities used: 049 * <ul> 050 * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent</li> 051 * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent</li> 052 * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent</li> 053 * </ul> 054 */ 055 private boolean addDefaultEntities = true; 056 057 /** 058 * Field contentTransformer. 059 */ 060 public final ContentTransformer contentTransformer; 061 062 063 //----------------/ 064 //- Constructors -/ 065 //----------------/ 066 067 public PluginMetadataXpp3Reader() 068 { 069 this( new ContentTransformer() 070 { 071 public String transform( String source, String fieldName ) 072 { 073 return source; 074 } 075 } ); 076 } //-- org.apache.maven.tools.plugin.extractor.model.io.xpp3.PluginMetadataXpp3Reader() 077 078 public PluginMetadataXpp3Reader(ContentTransformer contentTransformer) 079 { 080 this.contentTransformer = contentTransformer; 081 } //-- org.apache.maven.tools.plugin.extractor.model.io.xpp3.PluginMetadataXpp3Reader(ContentTransformer) 082 083 084 //-----------/ 085 //- Methods -/ 086 //-----------/ 087 088 /** 089 * Method checkFieldWithDuplicate. 090 * 091 * @param parser a parser object. 092 * @param parsed a parsed object. 093 * @param alias a alias object. 094 * @param tagName a tagName object. 095 * @throws XmlPullParserException XmlPullParserException if 096 * any. 097 * @return boolean 098 */ 099 private boolean checkFieldWithDuplicate( XmlPullParser parser, String tagName, String alias, java.util.Set<String> parsed ) 100 throws XmlPullParserException 101 { 102 if ( !( parser.getName().equals( tagName ) || parser.getName().equals( alias ) ) ) 103 { 104 return false; 105 } 106 if ( !parsed.add( tagName ) ) 107 { 108 throw new XmlPullParserException( "Duplicated tag: '" + tagName + "'", parser, null ); 109 } 110 return true; 111 } //-- boolean checkFieldWithDuplicate( XmlPullParser, String, String, java.util.Set ) 112 113 /** 114 * Method checkUnknownAttribute. 115 * 116 * @param parser a parser object. 117 * @param strict a strict object. 118 * @param tagName a tagName object. 119 * @param attribute a attribute object. 120 * @throws XmlPullParserException XmlPullParserException if 121 * any. 122 * @throws IOException IOException if any. 123 */ 124 private void checkUnknownAttribute( XmlPullParser parser, String attribute, String tagName, boolean strict ) 125 throws XmlPullParserException, IOException 126 { 127 // strictXmlAttributes = true for model: if strict == true, not only elements are checked but attributes too 128 if ( strict ) 129 { 130 throw new XmlPullParserException( "Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser, null ); 131 } 132 } //-- void checkUnknownAttribute( XmlPullParser, String, String, boolean ) 133 134 /** 135 * Method checkUnknownElement. 136 * 137 * @param parser a parser object. 138 * @param strict a strict object. 139 * @throws XmlPullParserException XmlPullParserException if 140 * any. 141 * @throws IOException IOException if any. 142 */ 143 private void checkUnknownElement( XmlPullParser parser, boolean strict ) 144 throws XmlPullParserException, IOException 145 { 146 if ( strict ) 147 { 148 throw new XmlPullParserException( "Unrecognised tag: '" + parser.getName() + "'", parser, null ); 149 } 150 151 for ( int unrecognizedTagCount = 1; unrecognizedTagCount > 0; ) 152 { 153 int eventType = parser.next(); 154 if ( eventType == XmlPullParser.START_TAG ) 155 { 156 unrecognizedTagCount++; 157 } 158 else if ( eventType == XmlPullParser.END_TAG ) 159 { 160 unrecognizedTagCount--; 161 } 162 } 163 } //-- void checkUnknownElement( XmlPullParser, boolean ) 164 165 /** 166 * Returns the state of the "add default entities" flag. 167 * 168 * @return boolean 169 */ 170 public boolean getAddDefaultEntities() 171 { 172 return addDefaultEntities; 173 } //-- boolean getAddDefaultEntities() 174 175 /** 176 * Method getBooleanValue. 177 * 178 * @param s a s object. 179 * @param parser a parser object. 180 * @param attribute a attribute object. 181 * @throws XmlPullParserException XmlPullParserException if 182 * any. 183 * @return boolean 184 */ 185 private boolean getBooleanValue( String s, String attribute, XmlPullParser parser ) 186 throws XmlPullParserException 187 { 188 return getBooleanValue( s, attribute, parser, null ); 189 } //-- boolean getBooleanValue( String, String, XmlPullParser ) 190 191 /** 192 * Method getBooleanValue. 193 * 194 * @param s a s object. 195 * @param defaultValue a defaultValue object. 196 * @param parser a parser object. 197 * @param attribute a attribute object. 198 * @throws XmlPullParserException XmlPullParserException if 199 * any. 200 * @return boolean 201 */ 202 private boolean getBooleanValue( String s, String attribute, XmlPullParser parser, String defaultValue ) 203 throws XmlPullParserException 204 { 205 if ( s != null && s.length() != 0 ) 206 { 207 return Boolean.valueOf( s ).booleanValue(); 208 } 209 if ( defaultValue != null ) 210 { 211 return Boolean.valueOf( defaultValue ).booleanValue(); 212 } 213 return false; 214 } //-- boolean getBooleanValue( String, String, XmlPullParser, String ) 215 216 /** 217 * Method getByteValue. 218 * 219 * @param s a s object. 220 * @param strict a strict object. 221 * @param parser a parser object. 222 * @param attribute a attribute object. 223 * @throws XmlPullParserException XmlPullParserException if 224 * any. 225 * @return byte 226 */ 227 private byte getByteValue( String s, String attribute, XmlPullParser parser, boolean strict ) 228 throws XmlPullParserException 229 { 230 if ( s != null ) 231 { 232 try 233 { 234 return Byte.valueOf( s ).byteValue(); 235 } 236 catch ( NumberFormatException nfe ) 237 { 238 if ( strict ) 239 { 240 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a byte", parser, nfe ); 241 } 242 } 243 } 244 return 0; 245 } //-- byte getByteValue( String, String, XmlPullParser, boolean ) 246 247 /** 248 * Method getCharacterValue. 249 * 250 * @param s a s object. 251 * @param parser a parser object. 252 * @param attribute a attribute object. 253 * @throws XmlPullParserException XmlPullParserException if 254 * any. 255 * @return char 256 */ 257 private char getCharacterValue( String s, String attribute, XmlPullParser parser ) 258 throws XmlPullParserException 259 { 260 if ( s != null ) 261 { 262 return s.charAt( 0 ); 263 } 264 return 0; 265 } //-- char getCharacterValue( String, String, XmlPullParser ) 266 267 /** 268 * Method getDateValue. 269 * 270 * @param s a s object. 271 * @param parser a parser object. 272 * @param attribute a attribute object. 273 * @throws XmlPullParserException XmlPullParserException if 274 * any. 275 * @return Date 276 */ 277 private java.util.Date getDateValue( String s, String attribute, XmlPullParser parser ) 278 throws XmlPullParserException 279 { 280 return getDateValue( s, attribute, null, parser ); 281 } //-- java.util.Date getDateValue( String, String, XmlPullParser ) 282 283 /** 284 * Method getDateValue. 285 * 286 * @param s a s object. 287 * @param parser a parser object. 288 * @param dateFormat a dateFormat object. 289 * @param attribute a attribute object. 290 * @throws XmlPullParserException XmlPullParserException if 291 * any. 292 * @return Date 293 */ 294 private java.util.Date getDateValue( String s, String attribute, String dateFormat, XmlPullParser parser ) 295 throws XmlPullParserException 296 { 297 if ( s != null ) 298 { 299 String effectiveDateFormat = dateFormat; 300 if ( dateFormat == null ) 301 { 302 effectiveDateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS"; 303 } 304 if ( "long".equals( effectiveDateFormat ) ) 305 { 306 try 307 { 308 return new java.util.Date( Long.parseLong( s ) ); 309 } 310 catch ( NumberFormatException e ) 311 { 312 throw new XmlPullParserException( e.getMessage(), parser, e ); 313 } 314 } 315 else 316 { 317 try 318 { 319 DateFormat dateParser = new java.text.SimpleDateFormat( effectiveDateFormat, java.util.Locale.US ); 320 return dateParser.parse( s ); 321 } 322 catch ( java.text.ParseException e ) 323 { 324 throw new XmlPullParserException( e.getMessage(), parser, e ); 325 } 326 } 327 } 328 return null; 329 } //-- java.util.Date getDateValue( String, String, String, XmlPullParser ) 330 331 /** 332 * Method getDoubleValue. 333 * 334 * @param s a s object. 335 * @param strict a strict object. 336 * @param parser a parser object. 337 * @param attribute a attribute object. 338 * @throws XmlPullParserException XmlPullParserException if 339 * any. 340 * @return double 341 */ 342 private double getDoubleValue( String s, String attribute, XmlPullParser parser, boolean strict ) 343 throws XmlPullParserException 344 { 345 if ( s != null ) 346 { 347 try 348 { 349 return Double.valueOf( s ).doubleValue(); 350 } 351 catch ( NumberFormatException nfe ) 352 { 353 if ( strict ) 354 { 355 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe ); 356 } 357 } 358 } 359 return 0; 360 } //-- double getDoubleValue( String, String, XmlPullParser, boolean ) 361 362 /** 363 * Method getFloatValue. 364 * 365 * @param s a s object. 366 * @param strict a strict object. 367 * @param parser a parser object. 368 * @param attribute a attribute object. 369 * @throws XmlPullParserException XmlPullParserException if 370 * any. 371 * @return float 372 */ 373 private float getFloatValue( String s, String attribute, XmlPullParser parser, boolean strict ) 374 throws XmlPullParserException 375 { 376 if ( s != null ) 377 { 378 try 379 { 380 return Float.valueOf( s ).floatValue(); 381 } 382 catch ( NumberFormatException nfe ) 383 { 384 if ( strict ) 385 { 386 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe ); 387 } 388 } 389 } 390 return 0; 391 } //-- float getFloatValue( String, String, XmlPullParser, boolean ) 392 393 /** 394 * Method getIntegerValue. 395 * 396 * @param s a s object. 397 * @param strict a strict object. 398 * @param parser a parser object. 399 * @param attribute a attribute object. 400 * @throws XmlPullParserException XmlPullParserException if 401 * any. 402 * @return int 403 */ 404 private int getIntegerValue( String s, String attribute, XmlPullParser parser, boolean strict ) 405 throws XmlPullParserException 406 { 407 if ( s != null ) 408 { 409 try 410 { 411 return Integer.valueOf( s ).intValue(); 412 } 413 catch ( NumberFormatException nfe ) 414 { 415 if ( strict ) 416 { 417 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be an integer", parser, nfe ); 418 } 419 } 420 } 421 return 0; 422 } //-- int getIntegerValue( String, String, XmlPullParser, boolean ) 423 424 /** 425 * Method getLongValue. 426 * 427 * @param s a s object. 428 * @param strict a strict object. 429 * @param parser a parser object. 430 * @param attribute a attribute object. 431 * @throws XmlPullParserException XmlPullParserException if 432 * any. 433 * @return long 434 */ 435 private long getLongValue( String s, String attribute, XmlPullParser parser, boolean strict ) 436 throws XmlPullParserException 437 { 438 if ( s != null ) 439 { 440 try 441 { 442 return Long.valueOf( s ).longValue(); 443 } 444 catch ( NumberFormatException nfe ) 445 { 446 if ( strict ) 447 { 448 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a long integer", parser, nfe ); 449 } 450 } 451 } 452 return 0; 453 } //-- long getLongValue( String, String, XmlPullParser, boolean ) 454 455 /** 456 * Method getRequiredAttributeValue. 457 * 458 * @param s a s object. 459 * @param strict a strict object. 460 * @param parser a parser object. 461 * @param attribute a attribute object. 462 * @throws XmlPullParserException XmlPullParserException if 463 * any. 464 * @return String 465 */ 466 private String getRequiredAttributeValue( String s, String attribute, XmlPullParser parser, boolean strict ) 467 throws XmlPullParserException 468 { 469 if ( s == null ) 470 { 471 if ( strict ) 472 { 473 throw new XmlPullParserException( "Missing required value for attribute '" + attribute + "'", parser, null ); 474 } 475 } 476 return s; 477 } //-- String getRequiredAttributeValue( String, String, XmlPullParser, boolean ) 478 479 /** 480 * Method getShortValue. 481 * 482 * @param s a s object. 483 * @param strict a strict object. 484 * @param parser a parser object. 485 * @param attribute a attribute object. 486 * @throws XmlPullParserException XmlPullParserException if 487 * any. 488 * @return short 489 */ 490 private short getShortValue( String s, String attribute, XmlPullParser parser, boolean strict ) 491 throws XmlPullParserException 492 { 493 if ( s != null ) 494 { 495 try 496 { 497 return Short.valueOf( s ).shortValue(); 498 } 499 catch ( NumberFormatException nfe ) 500 { 501 if ( strict ) 502 { 503 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a short integer", parser, nfe ); 504 } 505 } 506 } 507 return 0; 508 } //-- short getShortValue( String, String, XmlPullParser, boolean ) 509 510 /** 511 * Method getTrimmedValue. 512 * 513 * @param s a s object. 514 * @return String 515 */ 516 private String getTrimmedValue( String s ) 517 { 518 if ( s != null ) 519 { 520 s = s.trim(); 521 } 522 return s; 523 } //-- String getTrimmedValue( String ) 524 525 /** 526 * Method interpolatedTrimmed. 527 * 528 * @param value a value object. 529 * @param context a context object. 530 * @return String 531 */ 532 private String interpolatedTrimmed( String value, String context ) 533 { 534 return getTrimmedValue( contentTransformer.transform( value, context ) ); 535 } //-- String interpolatedTrimmed( String, String ) 536 537 /** 538 * Method nextTag. 539 * 540 * @param parser a parser object. 541 * @throws IOException IOException if any. 542 * @throws XmlPullParserException XmlPullParserException if 543 * any. 544 * @return int 545 */ 546 private int nextTag( XmlPullParser parser ) 547 throws IOException, XmlPullParserException 548 { 549 int eventType = parser.next(); 550 if ( eventType == XmlPullParser.TEXT ) 551 { 552 eventType = parser.next(); 553 } 554 if ( eventType != XmlPullParser.START_TAG && eventType != XmlPullParser.END_TAG ) 555 { 556 throw new XmlPullParserException( "expected START_TAG or END_TAG not " + XmlPullParser.TYPES[eventType], parser, null ); 557 } 558 return eventType; 559 } //-- int nextTag( XmlPullParser ) 560 561 /** 562 * Method read. 563 * 564 * @param parser a parser object. 565 * @param strict a strict object. 566 * @throws IOException IOException if any. 567 * @throws XmlPullParserException XmlPullParserException if 568 * any. 569 * @return PluginMetadata 570 */ 571 public PluginMetadata read( XmlPullParser parser, boolean strict ) 572 throws IOException, XmlPullParserException 573 { 574 PluginMetadata pluginMetadata = null; 575 int eventType = parser.getEventType(); 576 boolean parsed = false; 577 while ( eventType != XmlPullParser.END_DOCUMENT ) 578 { 579 if ( eventType == XmlPullParser.START_TAG ) 580 { 581 if ( strict && ! "pluginMetadata".equals( parser.getName() ) ) 582 { 583 throw new XmlPullParserException( "Expected root element 'pluginMetadata' but found '" + parser.getName() + "'", parser, null ); 584 } 585 else if ( parsed ) 586 { 587 // fallback, already expected a XmlPullParserException due to invalid XML 588 throw new XmlPullParserException( "Duplicated tag: 'pluginMetadata'", parser, null ); 589 } 590 pluginMetadata = parsePluginMetadata( parser, strict ); 591 pluginMetadata.setModelEncoding( parser.getInputEncoding() ); 592 parsed = true; 593 } 594 eventType = parser.next(); 595 } 596 if ( parsed ) 597 { 598 return pluginMetadata; 599 } 600 throw new XmlPullParserException( "Expected root element 'pluginMetadata' but found no element at all: invalid XML document", parser, null ); 601 } //-- PluginMetadata read( XmlPullParser, boolean ) 602 603 /** 604 * @see XmlStreamReader 605 * 606 * @param reader a reader object. 607 * @param strict a strict object. 608 * @throws IOException IOException if any. 609 * @throws XmlPullParserException XmlPullParserException if 610 * any. 611 * @return PluginMetadata 612 */ 613 public PluginMetadata read( Reader reader, boolean strict ) 614 throws IOException, XmlPullParserException 615 { 616 XmlPullParser parser = addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser( ); 617 618 parser.setInput( reader ); 619 620 621 return read( parser, strict ); 622 } //-- PluginMetadata read( Reader, boolean ) 623 624 /** 625 * @see XmlStreamReader 626 * 627 * @param reader a reader object. 628 * @throws IOException IOException if any. 629 * @throws XmlPullParserException XmlPullParserException if 630 * any. 631 * @return PluginMetadata 632 */ 633 public PluginMetadata read( Reader reader ) 634 throws IOException, XmlPullParserException 635 { 636 return read( reader, true ); 637 } //-- PluginMetadata read( Reader ) 638 639 /** 640 * Method read. 641 * 642 * @param in a in object. 643 * @param strict a strict object. 644 * @throws IOException IOException if any. 645 * @throws XmlPullParserException XmlPullParserException if 646 * any. 647 * @return PluginMetadata 648 */ 649 public PluginMetadata read( InputStream in, boolean strict ) 650 throws IOException, XmlPullParserException 651 { 652 return read( new XmlStreamReader( in ), strict ); 653 } //-- PluginMetadata read( InputStream, boolean ) 654 655 /** 656 * Method read. 657 * 658 * @param in a in object. 659 * @throws IOException IOException if any. 660 * @throws XmlPullParserException XmlPullParserException if 661 * any. 662 * @return PluginMetadata 663 */ 664 public PluginMetadata read( InputStream in ) 665 throws IOException, XmlPullParserException 666 { 667 return read( new XmlStreamReader( in ) ); 668 } //-- PluginMetadata read( InputStream ) 669 670 /** 671 * Method parseComponent. 672 * 673 * @param parser a parser object. 674 * @param strict a strict object. 675 * @throws IOException IOException if any. 676 * @throws XmlPullParserException XmlPullParserException if 677 * any. 678 * @return Component 679 */ 680 private Component parseComponent( XmlPullParser parser, boolean strict ) 681 throws IOException, XmlPullParserException 682 { 683 String tagName = parser.getName(); 684 Component component = new Component(); 685 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- ) 686 { 687 String name = parser.getAttributeName( i ); 688 String value = parser.getAttributeValue( i ); 689 690 if ( name.indexOf( ':' ) >= 0 ) 691 { 692 // just ignore attributes with non-default namespace (for example: xmlns:xsi) 693 } 694 else 695 { 696 checkUnknownAttribute( parser, name, tagName, strict ); 697 } 698 } 699 java.util.Set<String> parsed = new java.util.HashSet<String>(); 700 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG ) 701 { 702 if ( checkFieldWithDuplicate( parser, "role", null, parsed ) ) 703 { 704 component.setRole( interpolatedTrimmed( parser.nextText(), "role" ) ); 705 } 706 else if ( checkFieldWithDuplicate( parser, "hint", null, parsed ) ) 707 { 708 component.setHint( interpolatedTrimmed( parser.nextText(), "hint" ) ); 709 } 710 else 711 { 712 checkUnknownElement( parser, strict ); 713 } 714 } 715 return component; 716 } //-- Component parseComponent( XmlPullParser, boolean ) 717 718 /** 719 * Method parseLifecycleExecution. 720 * 721 * @param parser a parser object. 722 * @param strict a strict object. 723 * @throws IOException IOException if any. 724 * @throws XmlPullParserException XmlPullParserException if 725 * any. 726 * @return LifecycleExecution 727 */ 728 private LifecycleExecution parseLifecycleExecution( XmlPullParser parser, boolean strict ) 729 throws IOException, XmlPullParserException 730 { 731 String tagName = parser.getName(); 732 LifecycleExecution lifecycleExecution = new LifecycleExecution(); 733 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- ) 734 { 735 String name = parser.getAttributeName( i ); 736 String value = parser.getAttributeValue( i ); 737 738 if ( name.indexOf( ':' ) >= 0 ) 739 { 740 // just ignore attributes with non-default namespace (for example: xmlns:xsi) 741 } 742 else 743 { 744 checkUnknownAttribute( parser, name, tagName, strict ); 745 } 746 } 747 java.util.Set<String> parsed = new java.util.HashSet<String>(); 748 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG ) 749 { 750 if ( checkFieldWithDuplicate( parser, "lifecycle", null, parsed ) ) 751 { 752 lifecycleExecution.setLifecycle( interpolatedTrimmed( parser.nextText(), "lifecycle" ) ); 753 } 754 else if ( checkFieldWithDuplicate( parser, "phase", null, parsed ) ) 755 { 756 lifecycleExecution.setPhase( interpolatedTrimmed( parser.nextText(), "phase" ) ); 757 } 758 else if ( checkFieldWithDuplicate( parser, "goal", null, parsed ) ) 759 { 760 lifecycleExecution.setGoal( interpolatedTrimmed( parser.nextText(), "goal" ) ); 761 } 762 else 763 { 764 checkUnknownElement( parser, strict ); 765 } 766 } 767 return lifecycleExecution; 768 } //-- LifecycleExecution parseLifecycleExecution( XmlPullParser, boolean ) 769 770 /** 771 * Method parseMojo. 772 * 773 * @param parser a parser object. 774 * @param strict a strict object. 775 * @throws IOException IOException if any. 776 * @throws XmlPullParserException XmlPullParserException if 777 * any. 778 * @return Mojo 779 */ 780 private Mojo parseMojo( XmlPullParser parser, boolean strict ) 781 throws IOException, XmlPullParserException 782 { 783 String tagName = parser.getName(); 784 Mojo mojo = new Mojo(); 785 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- ) 786 { 787 String name = parser.getAttributeName( i ); 788 String value = parser.getAttributeValue( i ); 789 790 if ( name.indexOf( ':' ) >= 0 ) 791 { 792 // just ignore attributes with non-default namespace (for example: xmlns:xsi) 793 } 794 else 795 { 796 checkUnknownAttribute( parser, name, tagName, strict ); 797 } 798 } 799 java.util.Set<String> parsed = new java.util.HashSet<String>(); 800 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG ) 801 { 802 if ( checkFieldWithDuplicate( parser, "goal", null, parsed ) ) 803 { 804 mojo.setGoal( interpolatedTrimmed( parser.nextText(), "goal" ) ); 805 } 806 else if ( checkFieldWithDuplicate( parser, "phase", null, parsed ) ) 807 { 808 mojo.setPhase( interpolatedTrimmed( parser.nextText(), "phase" ) ); 809 } 810 else if ( checkFieldWithDuplicate( parser, "aggregator", null, parsed ) ) 811 { 812 mojo.setAggregator( getBooleanValue( interpolatedTrimmed( parser.nextText(), "aggregator" ), "aggregator", parser, "false" ) ); 813 } 814 else if ( checkFieldWithDuplicate( parser, "requiresDependencyResolution", null, parsed ) ) 815 { 816 mojo.setRequiresDependencyResolution( interpolatedTrimmed( parser.nextText(), "requiresDependencyResolution" ) ); 817 } 818 else if ( checkFieldWithDuplicate( parser, "requiresProject", null, parsed ) ) 819 { 820 mojo.setRequiresProject( getBooleanValue( interpolatedTrimmed( parser.nextText(), "requiresProject" ), "requiresProject", parser, "false" ) ); 821 } 822 else if ( checkFieldWithDuplicate( parser, "requiresReports", null, parsed ) ) 823 { 824 mojo.setRequiresReports( getBooleanValue( interpolatedTrimmed( parser.nextText(), "requiresReports" ), "requiresReports", parser, "false" ) ); 825 } 826 else if ( checkFieldWithDuplicate( parser, "requiresOnline", null, parsed ) ) 827 { 828 mojo.setRequiresOnline( getBooleanValue( interpolatedTrimmed( parser.nextText(), "requiresOnline" ), "requiresOnline", parser, "false" ) ); 829 } 830 else if ( checkFieldWithDuplicate( parser, "inheritByDefault", null, parsed ) ) 831 { 832 mojo.setInheritByDefault( getBooleanValue( interpolatedTrimmed( parser.nextText(), "inheritByDefault" ), "inheritByDefault", parser, "false" ) ); 833 } 834 else if ( checkFieldWithDuplicate( parser, "requiresDirectInvocation", null, parsed ) ) 835 { 836 mojo.setRequiresDirectInvocation( getBooleanValue( interpolatedTrimmed( parser.nextText(), "requiresDirectInvocation" ), "requiresDirectInvocation", parser, "false" ) ); 837 } 838 else if ( checkFieldWithDuplicate( parser, "execution", null, parsed ) ) 839 { 840 mojo.setExecution( parseLifecycleExecution( parser, strict ) ); 841 } 842 else if ( checkFieldWithDuplicate( parser, "components", null, parsed ) ) 843 { 844 java.util.List<Component> components = new java.util.ArrayList<Component>(); 845 while ( parser.nextTag() == XmlPullParser.START_TAG ) 846 { 847 if ( "component".equals( parser.getName() ) ) 848 { 849 components.add( parseComponent( parser, strict ) ); 850 } 851 else 852 { 853 checkUnknownElement( parser, strict ); 854 } 855 } 856 mojo.setComponents( components ); 857 } 858 else if ( checkFieldWithDuplicate( parser, "parameters", null, parsed ) ) 859 { 860 java.util.List<Parameter> parameters = new java.util.ArrayList<Parameter>(); 861 while ( parser.nextTag() == XmlPullParser.START_TAG ) 862 { 863 if ( "parameter".equals( parser.getName() ) ) 864 { 865 parameters.add( parseParameter( parser, strict ) ); 866 } 867 else 868 { 869 checkUnknownElement( parser, strict ); 870 } 871 } 872 mojo.setParameters( parameters ); 873 } 874 else if ( checkFieldWithDuplicate( parser, "description", null, parsed ) ) 875 { 876 mojo.setDescription( interpolatedTrimmed( parser.nextText(), "description" ) ); 877 } 878 else if ( checkFieldWithDuplicate( parser, "deprecated", null, parsed ) ) 879 { 880 mojo.setDeprecation( interpolatedTrimmed( parser.nextText(), "deprecated" ) ); 881 } 882 else if ( checkFieldWithDuplicate( parser, "since", null, parsed ) ) 883 { 884 mojo.setSince( interpolatedTrimmed( parser.nextText(), "since" ) ); 885 } 886 else if ( checkFieldWithDuplicate( parser, "call", null, parsed ) ) 887 { 888 mojo.setCall( interpolatedTrimmed( parser.nextText(), "call" ) ); 889 } 890 else 891 { 892 checkUnknownElement( parser, strict ); 893 } 894 } 895 return mojo; 896 } //-- Mojo parseMojo( XmlPullParser, boolean ) 897 898 /** 899 * Method parseParameter. 900 * 901 * @param parser a parser object. 902 * @param strict a strict object. 903 * @throws IOException IOException if any. 904 * @throws XmlPullParserException XmlPullParserException if 905 * any. 906 * @return Parameter 907 */ 908 private Parameter parseParameter( XmlPullParser parser, boolean strict ) 909 throws IOException, XmlPullParserException 910 { 911 String tagName = parser.getName(); 912 Parameter parameter = new Parameter(); 913 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- ) 914 { 915 String name = parser.getAttributeName( i ); 916 String value = parser.getAttributeValue( i ); 917 918 if ( name.indexOf( ':' ) >= 0 ) 919 { 920 // just ignore attributes with non-default namespace (for example: xmlns:xsi) 921 } 922 else 923 { 924 checkUnknownAttribute( parser, name, tagName, strict ); 925 } 926 } 927 java.util.Set<String> parsed = new java.util.HashSet<String>(); 928 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG ) 929 { 930 if ( checkFieldWithDuplicate( parser, "name", null, parsed ) ) 931 { 932 parameter.setName( interpolatedTrimmed( parser.nextText(), "name" ) ); 933 } 934 else if ( checkFieldWithDuplicate( parser, "alias", null, parsed ) ) 935 { 936 parameter.setAlias( interpolatedTrimmed( parser.nextText(), "alias" ) ); 937 } 938 else if ( checkFieldWithDuplicate( parser, "property", null, parsed ) ) 939 { 940 parameter.setProperty( interpolatedTrimmed( parser.nextText(), "property" ) ); 941 } 942 else if ( checkFieldWithDuplicate( parser, "required", null, parsed ) ) 943 { 944 parameter.setRequired( getBooleanValue( interpolatedTrimmed( parser.nextText(), "required" ), "required", parser, "false" ) ); 945 } 946 else if ( checkFieldWithDuplicate( parser, "readonly", null, parsed ) ) 947 { 948 parameter.setReadonly( getBooleanValue( interpolatedTrimmed( parser.nextText(), "readonly" ), "readonly", parser, "false" ) ); 949 } 950 else if ( checkFieldWithDuplicate( parser, "expression", null, parsed ) ) 951 { 952 parameter.setExpression( interpolatedTrimmed( parser.nextText(), "expression" ) ); 953 } 954 else if ( checkFieldWithDuplicate( parser, "defaultValue", null, parsed ) ) 955 { 956 parameter.setDefaultValue( interpolatedTrimmed( parser.nextText(), "defaultValue" ) ); 957 } 958 else if ( checkFieldWithDuplicate( parser, "type", null, parsed ) ) 959 { 960 parameter.setType( interpolatedTrimmed( parser.nextText(), "type" ) ); 961 } 962 else if ( checkFieldWithDuplicate( parser, "description", null, parsed ) ) 963 { 964 parameter.setDescription( interpolatedTrimmed( parser.nextText(), "description" ) ); 965 } 966 else if ( checkFieldWithDuplicate( parser, "deprecated", null, parsed ) ) 967 { 968 parameter.setDeprecation( interpolatedTrimmed( parser.nextText(), "deprecated" ) ); 969 } 970 else if ( checkFieldWithDuplicate( parser, "since", null, parsed ) ) 971 { 972 parameter.setSince( interpolatedTrimmed( parser.nextText(), "since" ) ); 973 } 974 else 975 { 976 checkUnknownElement( parser, strict ); 977 } 978 } 979 return parameter; 980 } //-- Parameter parseParameter( XmlPullParser, boolean ) 981 982 /** 983 * Method parsePluginMetadata. 984 * 985 * @param parser a parser object. 986 * @param strict a strict object. 987 * @throws IOException IOException if any. 988 * @throws XmlPullParserException XmlPullParserException if 989 * any. 990 * @return PluginMetadata 991 */ 992 private PluginMetadata parsePluginMetadata( XmlPullParser parser, boolean strict ) 993 throws IOException, XmlPullParserException 994 { 995 String tagName = parser.getName(); 996 PluginMetadata pluginMetadata = new PluginMetadata(); 997 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- ) 998 { 999 String name = parser.getAttributeName( i ); 1000 String value = parser.getAttributeValue( i ); 1001 1002 if ( name.indexOf( ':' ) >= 0 ) 1003 { 1004 // just ignore attributes with non-default namespace (for example: xmlns:xsi) 1005 } 1006 else if ( "xmlns".equals( name ) ) 1007 { 1008 // ignore xmlns attribute in root class, which is a reserved attribute name 1009 } 1010 else 1011 { 1012 checkUnknownAttribute( parser, name, tagName, strict ); 1013 } 1014 } 1015 java.util.Set<String> parsed = new java.util.HashSet<String>(); 1016 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG ) 1017 { 1018 if ( checkFieldWithDuplicate( parser, "mojos", null, parsed ) ) 1019 { 1020 java.util.List<Mojo> mojos = new java.util.ArrayList<Mojo>(); 1021 while ( parser.nextTag() == XmlPullParser.START_TAG ) 1022 { 1023 if ( "mojo".equals( parser.getName() ) ) 1024 { 1025 mojos.add( parseMojo( parser, strict ) ); 1026 } 1027 else 1028 { 1029 checkUnknownElement( parser, strict ); 1030 } 1031 } 1032 pluginMetadata.setMojos( mojos ); 1033 } 1034 else 1035 { 1036 checkUnknownElement( parser, strict ); 1037 } 1038 } 1039 return pluginMetadata; 1040 } //-- PluginMetadata parsePluginMetadata( XmlPullParser, boolean ) 1041 1042 /** 1043 * Sets the state of the "add default entities" flag. 1044 * 1045 * @param addDefaultEntities a addDefaultEntities object. 1046 */ 1047 public void setAddDefaultEntities( boolean addDefaultEntities ) 1048 { 1049 this.addDefaultEntities = addDefaultEntities; 1050 } //-- void setAddDefaultEntities( boolean ) 1051 1052 public static interface ContentTransformer 1053{ 1054 /** 1055 * Interpolate the value read from the xpp3 document 1056 * @param source The source value 1057 * @param fieldName A description of the field being interpolated. The implementation may use this to 1058 * log stuff. 1059 * @return The interpolated value. 1060 */ 1061 String transform( String source, String fieldName ); 1062} 1063 1064}