001// =================== DO NOT EDIT THIS FILE ==================== 002// Generated by Modello 1.8.1, 003// any modifications will be overwritten. 004// ============================================================== 005 006package org.apache.maven.usability.plugin.io.xpp3; 007 008 //---------------------------------/ 009 //- Imported classes and packages -/ 010//---------------------------------/ 011 012import java.io.IOException; 013import java.io.InputStream; 014import java.io.Reader; 015import java.text.DateFormat; 016import org.apache.maven.usability.plugin.Expression; 017import org.apache.maven.usability.plugin.ExpressionDocumentation; 018import org.codehaus.plexus.util.ReaderFactory; 019import org.codehaus.plexus.util.xml.pull.EntityReplacementMap; 020import org.codehaus.plexus.util.xml.pull.MXParser; 021import org.codehaus.plexus.util.xml.pull.XmlPullParser; 022import org.codehaus.plexus.util.xml.pull.XmlPullParserException; 023 024/** 025 * Class ParamdocXpp3Reader. 026 * 027 * @version $Revision$ $Date$ 028 */ 029@SuppressWarnings( "all" ) 030public class ParamdocXpp3Reader 031{ 032 033 //--------------------------/ 034 //- Class/Member Variables -/ 035 //--------------------------/ 036 037 /** 038 * If set the parser will be loaded with all single characters 039 * from the XHTML specification. 040 * The entities used: 041 * <ul> 042 * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent</li> 043 * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent</li> 044 * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent</li> 045 * </ul> 046 */ 047 private boolean addDefaultEntities = true; 048 049 050 //-----------/ 051 //- Methods -/ 052 //-----------/ 053 054 /** 055 * Method checkFieldWithDuplicate. 056 * 057 * @param parser 058 * @param parsed 059 * @param alias 060 * @param tagName 061 * @throws XmlPullParserException 062 * @return boolean 063 */ 064 private boolean checkFieldWithDuplicate( XmlPullParser parser, String tagName, String alias, java.util.Set parsed ) 065 throws XmlPullParserException 066 { 067 if ( !( parser.getName().equals( tagName ) || parser.getName().equals( alias ) ) ) 068 { 069 return false; 070 } 071 if ( !parsed.add( tagName ) ) 072 { 073 throw new XmlPullParserException( "Duplicated tag: '" + tagName + "'", parser, null ); 074 } 075 return true; 076 } //-- boolean checkFieldWithDuplicate( XmlPullParser, String, String, java.util.Set ) 077 078 /** 079 * Method checkUnknownAttribute. 080 * 081 * @param parser 082 * @param strict 083 * @param tagName 084 * @param attribute 085 * @throws XmlPullParserException 086 * @throws IOException 087 */ 088 private void checkUnknownAttribute( XmlPullParser parser, String attribute, String tagName, boolean strict ) 089 throws XmlPullParserException, IOException 090 { 091 // strictXmlAttributes = true for model: if strict == true, not only elements are checked but attributes too 092 if ( strict ) 093 { 094 throw new XmlPullParserException( "Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser, null ); 095 } 096 } //-- void checkUnknownAttribute( XmlPullParser, String, String, boolean ) 097 098 /** 099 * Method checkUnknownElement. 100 * 101 * @param parser 102 * @param strict 103 * @throws XmlPullParserException 104 * @throws IOException 105 */ 106 private void checkUnknownElement( XmlPullParser parser, boolean strict ) 107 throws XmlPullParserException, IOException 108 { 109 if ( strict ) 110 { 111 throw new XmlPullParserException( "Unrecognised tag: '" + parser.getName() + "'", parser, null ); 112 } 113 114 for ( int unrecognizedTagCount = 1; unrecognizedTagCount > 0; ) 115 { 116 int eventType = parser.next(); 117 if ( eventType == XmlPullParser.START_TAG ) 118 { 119 unrecognizedTagCount++; 120 } 121 else if ( eventType == XmlPullParser.END_TAG ) 122 { 123 unrecognizedTagCount--; 124 } 125 } 126 } //-- void checkUnknownElement( XmlPullParser, boolean ) 127 128 /** 129 * Returns the state of the "add default entities" flag. 130 * 131 * @return boolean 132 */ 133 public boolean getAddDefaultEntities() 134 { 135 return addDefaultEntities; 136 } //-- boolean getAddDefaultEntities() 137 138 /** 139 * Method getBooleanValue. 140 * 141 * @param s 142 * @param parser 143 * @param attribute 144 * @throws XmlPullParserException 145 * @return boolean 146 */ 147 private boolean getBooleanValue( String s, String attribute, XmlPullParser parser ) 148 throws XmlPullParserException 149 { 150 return getBooleanValue( s, attribute, parser, null ); 151 } //-- boolean getBooleanValue( String, String, XmlPullParser ) 152 153 /** 154 * Method getBooleanValue. 155 * 156 * @param s 157 * @param defaultValue 158 * @param parser 159 * @param attribute 160 * @throws XmlPullParserException 161 * @return boolean 162 */ 163 private boolean getBooleanValue( String s, String attribute, XmlPullParser parser, String defaultValue ) 164 throws XmlPullParserException 165 { 166 if ( s != null && s.length() != 0 ) 167 { 168 return Boolean.valueOf( s ).booleanValue(); 169 } 170 if ( defaultValue != null ) 171 { 172 return Boolean.valueOf( defaultValue ).booleanValue(); 173 } 174 return false; 175 } //-- boolean getBooleanValue( String, String, XmlPullParser, String ) 176 177 /** 178 * Method getByteValue. 179 * 180 * @param s 181 * @param strict 182 * @param parser 183 * @param attribute 184 * @throws XmlPullParserException 185 * @return byte 186 */ 187 private byte getByteValue( String s, String attribute, XmlPullParser parser, boolean strict ) 188 throws XmlPullParserException 189 { 190 if ( s != null ) 191 { 192 try 193 { 194 return Byte.valueOf( s ).byteValue(); 195 } 196 catch ( NumberFormatException nfe ) 197 { 198 if ( strict ) 199 { 200 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a byte", parser, nfe ); 201 } 202 } 203 } 204 return 0; 205 } //-- byte getByteValue( String, String, XmlPullParser, boolean ) 206 207 /** 208 * Method getCharacterValue. 209 * 210 * @param s 211 * @param parser 212 * @param attribute 213 * @throws XmlPullParserException 214 * @return char 215 */ 216 private char getCharacterValue( String s, String attribute, XmlPullParser parser ) 217 throws XmlPullParserException 218 { 219 if ( s != null ) 220 { 221 return s.charAt( 0 ); 222 } 223 return 0; 224 } //-- char getCharacterValue( String, String, XmlPullParser ) 225 226 /** 227 * Method getDateValue. 228 * 229 * @param s 230 * @param parser 231 * @param attribute 232 * @throws XmlPullParserException 233 * @return Date 234 */ 235 private java.util.Date getDateValue( String s, String attribute, XmlPullParser parser ) 236 throws XmlPullParserException 237 { 238 return getDateValue( s, attribute, null, parser ); 239 } //-- java.util.Date getDateValue( String, String, XmlPullParser ) 240 241 /** 242 * Method getDateValue. 243 * 244 * @param s 245 * @param parser 246 * @param dateFormat 247 * @param attribute 248 * @throws XmlPullParserException 249 * @return Date 250 */ 251 private java.util.Date getDateValue( String s, String attribute, String dateFormat, XmlPullParser parser ) 252 throws XmlPullParserException 253 { 254 if ( s != null ) 255 { 256 String effectiveDateFormat = dateFormat; 257 if ( dateFormat == null ) 258 { 259 effectiveDateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS"; 260 } 261 if ( "long".equals( effectiveDateFormat ) ) 262 { 263 try 264 { 265 return new java.util.Date( Long.parseLong( s ) ); 266 } 267 catch ( NumberFormatException e ) 268 { 269 throw new XmlPullParserException( e.getMessage(), parser, e ); 270 } 271 } 272 else 273 { 274 try 275 { 276 DateFormat dateParser = new java.text.SimpleDateFormat( effectiveDateFormat, java.util.Locale.US ); 277 return dateParser.parse( s ); 278 } 279 catch ( java.text.ParseException e ) 280 { 281 throw new XmlPullParserException( e.getMessage(), parser, e ); 282 } 283 } 284 } 285 return null; 286 } //-- java.util.Date getDateValue( String, String, String, XmlPullParser ) 287 288 /** 289 * Method getDoubleValue. 290 * 291 * @param s 292 * @param strict 293 * @param parser 294 * @param attribute 295 * @throws XmlPullParserException 296 * @return double 297 */ 298 private double getDoubleValue( String s, String attribute, XmlPullParser parser, boolean strict ) 299 throws XmlPullParserException 300 { 301 if ( s != null ) 302 { 303 try 304 { 305 return Double.valueOf( s ).doubleValue(); 306 } 307 catch ( NumberFormatException nfe ) 308 { 309 if ( strict ) 310 { 311 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe ); 312 } 313 } 314 } 315 return 0; 316 } //-- double getDoubleValue( String, String, XmlPullParser, boolean ) 317 318 /** 319 * Method getFloatValue. 320 * 321 * @param s 322 * @param strict 323 * @param parser 324 * @param attribute 325 * @throws XmlPullParserException 326 * @return float 327 */ 328 private float getFloatValue( String s, String attribute, XmlPullParser parser, boolean strict ) 329 throws XmlPullParserException 330 { 331 if ( s != null ) 332 { 333 try 334 { 335 return Float.valueOf( s ).floatValue(); 336 } 337 catch ( NumberFormatException nfe ) 338 { 339 if ( strict ) 340 { 341 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe ); 342 } 343 } 344 } 345 return 0; 346 } //-- float getFloatValue( String, String, XmlPullParser, boolean ) 347 348 /** 349 * Method getIntegerValue. 350 * 351 * @param s 352 * @param strict 353 * @param parser 354 * @param attribute 355 * @throws XmlPullParserException 356 * @return int 357 */ 358 private int getIntegerValue( String s, String attribute, XmlPullParser parser, boolean strict ) 359 throws XmlPullParserException 360 { 361 if ( s != null ) 362 { 363 try 364 { 365 return Integer.valueOf( s ).intValue(); 366 } 367 catch ( NumberFormatException nfe ) 368 { 369 if ( strict ) 370 { 371 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be an integer", parser, nfe ); 372 } 373 } 374 } 375 return 0; 376 } //-- int getIntegerValue( String, String, XmlPullParser, boolean ) 377 378 /** 379 * Method getLongValue. 380 * 381 * @param s 382 * @param strict 383 * @param parser 384 * @param attribute 385 * @throws XmlPullParserException 386 * @return long 387 */ 388 private long getLongValue( String s, String attribute, XmlPullParser parser, boolean strict ) 389 throws XmlPullParserException 390 { 391 if ( s != null ) 392 { 393 try 394 { 395 return Long.valueOf( s ).longValue(); 396 } 397 catch ( NumberFormatException nfe ) 398 { 399 if ( strict ) 400 { 401 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a long integer", parser, nfe ); 402 } 403 } 404 } 405 return 0; 406 } //-- long getLongValue( String, String, XmlPullParser, boolean ) 407 408 /** 409 * Method getRequiredAttributeValue. 410 * 411 * @param s 412 * @param strict 413 * @param parser 414 * @param attribute 415 * @throws XmlPullParserException 416 * @return String 417 */ 418 private String getRequiredAttributeValue( String s, String attribute, XmlPullParser parser, boolean strict ) 419 throws XmlPullParserException 420 { 421 if ( s == null ) 422 { 423 if ( strict ) 424 { 425 throw new XmlPullParserException( "Missing required value for attribute '" + attribute + "'", parser, null ); 426 } 427 } 428 return s; 429 } //-- String getRequiredAttributeValue( String, String, XmlPullParser, boolean ) 430 431 /** 432 * Method getShortValue. 433 * 434 * @param s 435 * @param strict 436 * @param parser 437 * @param attribute 438 * @throws XmlPullParserException 439 * @return short 440 */ 441 private short getShortValue( String s, String attribute, XmlPullParser parser, boolean strict ) 442 throws XmlPullParserException 443 { 444 if ( s != null ) 445 { 446 try 447 { 448 return Short.valueOf( s ).shortValue(); 449 } 450 catch ( NumberFormatException nfe ) 451 { 452 if ( strict ) 453 { 454 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a short integer", parser, nfe ); 455 } 456 } 457 } 458 return 0; 459 } //-- short getShortValue( String, String, XmlPullParser, boolean ) 460 461 /** 462 * Method getTrimmedValue. 463 * 464 * @param s 465 * @return String 466 */ 467 private String getTrimmedValue( String s ) 468 { 469 if ( s != null ) 470 { 471 s = s.trim(); 472 } 473 return s; 474 } //-- String getTrimmedValue( String ) 475 476 /** 477 * Method nextTag. 478 * 479 * @param parser 480 * @throws IOException 481 * @throws XmlPullParserException 482 * @return int 483 */ 484 private int nextTag( XmlPullParser parser ) 485 throws IOException, XmlPullParserException 486 { 487 int eventType = parser.next(); 488 if ( eventType == XmlPullParser.TEXT ) 489 { 490 eventType = parser.next(); 491 } 492 if ( eventType != XmlPullParser.START_TAG && eventType != XmlPullParser.END_TAG ) 493 { 494 throw new XmlPullParserException( "expected START_TAG or END_TAG not " + XmlPullParser.TYPES[eventType], parser, null ); 495 } 496 return eventType; 497 } //-- int nextTag( XmlPullParser ) 498 499 /** 500 * @see ReaderFactory#newXmlReader 501 * 502 * @param reader 503 * @param strict 504 * @throws IOException 505 * @throws XmlPullParserException 506 * @return ExpressionDocumentation 507 */ 508 public ExpressionDocumentation read( Reader reader, boolean strict ) 509 throws IOException, XmlPullParserException 510 { 511 XmlPullParser parser = addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser( ); 512 513 parser.setInput( reader ); 514 515 516 return read( parser, strict ); 517 } //-- ExpressionDocumentation read( Reader, boolean ) 518 519 /** 520 * @see ReaderFactory#newXmlReader 521 * 522 * @param reader 523 * @throws IOException 524 * @throws XmlPullParserException 525 * @return ExpressionDocumentation 526 */ 527 public ExpressionDocumentation read( Reader reader ) 528 throws IOException, XmlPullParserException 529 { 530 return read( reader, true ); 531 } //-- ExpressionDocumentation read( Reader ) 532 533 /** 534 * Method read. 535 * 536 * @param in 537 * @param strict 538 * @throws IOException 539 * @throws XmlPullParserException 540 * @return ExpressionDocumentation 541 */ 542 public ExpressionDocumentation read( InputStream in, boolean strict ) 543 throws IOException, XmlPullParserException 544 { 545 return read( ReaderFactory.newXmlReader( in ), strict ); 546 } //-- ExpressionDocumentation read( InputStream, boolean ) 547 548 /** 549 * Method read. 550 * 551 * @param in 552 * @throws IOException 553 * @throws XmlPullParserException 554 * @return ExpressionDocumentation 555 */ 556 public ExpressionDocumentation read( InputStream in ) 557 throws IOException, XmlPullParserException 558 { 559 return read( ReaderFactory.newXmlReader( in ) ); 560 } //-- ExpressionDocumentation read( InputStream ) 561 562 /** 563 * Method parseExpression. 564 * 565 * @param parser 566 * @param strict 567 * @throws IOException 568 * @throws XmlPullParserException 569 * @return Expression 570 */ 571 private Expression parseExpression( XmlPullParser parser, boolean strict ) 572 throws IOException, XmlPullParserException 573 { 574 String tagName = parser.getName(); 575 Expression expression = new Expression(); 576 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- ) 577 { 578 String name = parser.getAttributeName( i ); 579 String value = parser.getAttributeValue( i ); 580 581 if ( name.indexOf( ':' ) >= 0 ) 582 { 583 // just ignore attributes with non-default namespace (for example: xmlns:xsi) 584 } 585 else 586 { 587 checkUnknownAttribute( parser, name, tagName, strict ); 588 } 589 } 590 java.util.Set parsed = new java.util.HashSet(); 591 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG ) 592 { 593 if ( checkFieldWithDuplicate( parser, "syntax", null, parsed ) ) 594 { 595 expression.setSyntax( getTrimmedValue( parser.nextText() ) ); 596 } 597 else if ( checkFieldWithDuplicate( parser, "description", null, parsed ) ) 598 { 599 expression.setDescription( getTrimmedValue( parser.nextText() ) ); 600 } 601 else if ( checkFieldWithDuplicate( parser, "configuration", null, parsed ) ) 602 { 603 expression.setConfiguration( getTrimmedValue( parser.nextText() ) ); 604 } 605 else if ( checkFieldWithDuplicate( parser, "cliOptions", null, parsed ) ) 606 { 607 while ( parser.nextTag() == XmlPullParser.START_TAG ) 608 { 609 if ( "cliOption".equals( parser.getName() ) ) 610 { 611 String key = null; 612 String value = null; 613 // explode mode. 614 while ( parser.nextTag() == XmlPullParser.START_TAG ) 615 { 616 if ( "key".equals( parser.getName() ) ) 617 { 618 key = parser.nextText(); 619 } 620 else if ( "value".equals( parser.getName() ) ) 621 { 622 value = parser.nextText().trim(); 623 } 624 else 625 { 626 parser.nextText(); 627 } 628 } 629 expression.addCliOption( key, value ); 630 } 631 parser.next(); 632 } 633 } 634 else if ( checkFieldWithDuplicate( parser, "apiMethods", null, parsed ) ) 635 { 636 while ( parser.nextTag() == XmlPullParser.START_TAG ) 637 { 638 if ( "apiMethod".equals( parser.getName() ) ) 639 { 640 String key = null; 641 String value = null; 642 // explode mode. 643 while ( parser.nextTag() == XmlPullParser.START_TAG ) 644 { 645 if ( "key".equals( parser.getName() ) ) 646 { 647 key = parser.nextText(); 648 } 649 else if ( "value".equals( parser.getName() ) ) 650 { 651 value = parser.nextText().trim(); 652 } 653 else 654 { 655 parser.nextText(); 656 } 657 } 658 expression.addApiMethod( key, value ); 659 } 660 parser.next(); 661 } 662 } 663 else if ( checkFieldWithDuplicate( parser, "deprecation", null, parsed ) ) 664 { 665 expression.setDeprecation( getTrimmedValue( parser.nextText() ) ); 666 } 667 else if ( checkFieldWithDuplicate( parser, "ban", null, parsed ) ) 668 { 669 expression.setBan( getTrimmedValue( parser.nextText() ) ); 670 } 671 else if ( checkFieldWithDuplicate( parser, "editable", null, parsed ) ) 672 { 673 expression.setEditable( getBooleanValue( getTrimmedValue( parser.nextText() ), "editable", parser, "true" ) ); 674 } 675 else 676 { 677 checkUnknownElement( parser, strict ); 678 } 679 } 680 return expression; 681 } //-- Expression parseExpression( XmlPullParser, boolean ) 682 683 /** 684 * Method parseExpressionDocumentation. 685 * 686 * @param parser 687 * @param strict 688 * @throws IOException 689 * @throws XmlPullParserException 690 * @return ExpressionDocumentation 691 */ 692 private ExpressionDocumentation parseExpressionDocumentation( XmlPullParser parser, boolean strict ) 693 throws IOException, XmlPullParserException 694 { 695 String tagName = parser.getName(); 696 ExpressionDocumentation expressionDocumentation = new ExpressionDocumentation(); 697 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- ) 698 { 699 String name = parser.getAttributeName( i ); 700 String value = parser.getAttributeValue( i ); 701 702 if ( name.indexOf( ':' ) >= 0 ) 703 { 704 // just ignore attributes with non-default namespace (for example: xmlns:xsi) 705 } 706 else if ( "xmlns".equals( name ) ) 707 { 708 // ignore xmlns attribute in root class, which is a reserved attribute name 709 } 710 else 711 { 712 checkUnknownAttribute( parser, name, tagName, strict ); 713 } 714 } 715 java.util.Set parsed = new java.util.HashSet(); 716 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG ) 717 { 718 if ( checkFieldWithDuplicate( parser, "expressions", null, parsed ) ) 719 { 720 java.util.List expressions = new java.util.ArrayList/*<Expression>*/(); 721 expressionDocumentation.setExpressions( expressions ); 722 while ( parser.nextTag() == XmlPullParser.START_TAG ) 723 { 724 if ( "expression".equals( parser.getName() ) ) 725 { 726 expressions.add( parseExpression( parser, strict ) ); 727 } 728 else 729 { 730 checkUnknownElement( parser, strict ); 731 } 732 } 733 } 734 else 735 { 736 checkUnknownElement( parser, strict ); 737 } 738 } 739 return expressionDocumentation; 740 } //-- ExpressionDocumentation parseExpressionDocumentation( XmlPullParser, boolean ) 741 742 /** 743 * Method read. 744 * 745 * @param parser 746 * @param strict 747 * @throws IOException 748 * @throws XmlPullParserException 749 * @return ExpressionDocumentation 750 */ 751 private ExpressionDocumentation read( XmlPullParser parser, boolean strict ) 752 throws IOException, XmlPullParserException 753 { 754 int eventType = parser.getEventType(); 755 while ( eventType != XmlPullParser.END_DOCUMENT ) 756 { 757 if ( eventType == XmlPullParser.START_TAG ) 758 { 759 if ( strict && ! "paramdoc".equals( parser.getName() ) ) 760 { 761 throw new XmlPullParserException( "Expected root element 'paramdoc' but found '" + parser.getName() + "'", parser, null ); 762 } 763 ExpressionDocumentation expressionDocumentation = parseExpressionDocumentation( parser, strict ); 764 expressionDocumentation.setModelEncoding( parser.getInputEncoding() ); 765 return expressionDocumentation; 766 } 767 eventType = parser.next(); 768 } 769 throw new XmlPullParserException( "Expected root element 'paramdoc' but found no element at all: invalid XML document", parser, null ); 770 } //-- ExpressionDocumentation read( XmlPullParser, boolean ) 771 772 /** 773 * Sets the state of the "add default entities" flag. 774 * 775 * @param addDefaultEntities 776 */ 777 public void setAddDefaultEntities( boolean addDefaultEntities ) 778 { 779 this.addDefaultEntities = addDefaultEntities; 780 } //-- void setAddDefaultEntities( boolean ) 781 782}