001// $ANTLR 2.7.7 (20060906): "distinguishedName.g" -> "AntlrDnParser.java"$ 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 * 021 */ 022package org.apache.directory.api.ldap.model.name; 023 024import java.io.StringReader; 025import java.util.ArrayList; 026import java.util.HashMap; 027import java.util.List; 028import java.util.Map; 029 030import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException; 031import javax.naming.NameParser; 032import org.apache.directory.api.ldap.model.entry.Value; 033import org.apache.directory.api.ldap.model.schema.SchemaManager; 034import org.apache.directory.api.ldap.model.schema.AttributeType; 035import org.apache.directory.api.util.ExpansibleByteBuffer; 036import org.apache.directory.api.util.Strings; 037import org.apache.directory.api.util.Unicode; 038 039import antlr.TokenBuffer; 040import antlr.TokenStreamException; 041import antlr.TokenStreamIOException; 042import antlr.ANTLRException; 043import antlr.LLkParser; 044import antlr.Token; 045import antlr.TokenStream; 046import antlr.RecognitionException; 047import antlr.NoViableAltException; 048import antlr.MismatchedTokenException; 049import antlr.SemanticException; 050import antlr.ParserSharedInputState; 051import antlr.collections.impl.BitSet; 052 053/** 054 * An antlr generated Dn parser. 055 * 056 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 057 */ 058public class AntlrDnParser extends antlr.LLkParser implements AntlrDnTokenTypes 059 { 060 061 private void matchedProduction( String msg ) 062 { 063 } 064 065 /** 066 * This class is used to store the decoded value 067 */ 068 private static class UpAndNormValue 069 { 070 // The value as a byte array 071 ExpansibleByteBuffer bytes = new ExpansibleByteBuffer(); 072 073 // The user provided value 074 StringBuilder upValue = new StringBuilder(); 075 076 // The normalized value 077 StringBuilder normValue = new StringBuilder(); 078 079 // A flag set to false if we have a binary value 080 boolean isHR = true; 081 } 082 083protected AntlrDnParser(TokenBuffer tokenBuf, int k) { 084 super(tokenBuf,k); 085 tokenNames = _tokenNames; 086} 087 088public AntlrDnParser(TokenBuffer tokenBuf) { 089 this(tokenBuf,3); 090} 091 092protected AntlrDnParser(TokenStream lexer, int k) { 093 super(lexer,k); 094 tokenNames = _tokenNames; 095} 096 097public AntlrDnParser(TokenStream lexer) { 098 this(lexer,3); 099} 100 101public AntlrDnParser(ParserSharedInputState state) { 102 super(state,3); 103 tokenNames = _tokenNames; 104} 105 106/** 107 * Parses a Dn string. 108 * 109 * RFC 4514, Section 3 110 * <pre> 111 * distinguishedName = [ relativeDistinguishedName 112 * *( COMMA relativeDistinguishedName ) ] 113 * </pre> 114 * 115 * RFC 2253, Section 3 116 * <pre> 117 * distinguishedName = [name] 118 * name = name-component *("," name-component) 119 * </pre> 120 * 121 * RFC 1779, Section 2.3 122 * <pre> 123 * <name> ::= <name-component> ( <spaced-separator> ) 124 * | <name-component> <spaced-separator> <name> 125 * <spaced-separator> ::= <optional-space> 126 * <separator> 127 * <optional-space> 128 * <separator> ::= "," | ";" 129 * <optional-space> ::= ( <CR> ) *( " " ) 130 * </pre> 131 * 132 * @param schemaManager The SchemaManager 133 * @param dn The Dn to update 134 * @throws RecognitionException If the token is invalid 135 * @throws TokenStreamException When we weren't able to fetch a token 136 */ 137 public final void distinguishedName( 138 SchemaManager schemaManager, Dn dn 139 ) throws RecognitionException, TokenStreamException { 140 141 142 matchedProduction( "distinguishedName()" ); 143 Rdn rdn = new Rdn( schemaManager ); 144 145 146 { 147 switch ( LA(1)) { 148 case SPACE: 149 case NUMERICOID: 150 case ALPHA: 151 { 152 relativeDistinguishedName(schemaManager, rdn); 153 154 try 155 { 156 dn.add( rdn ); 157 158 } 159 catch ( LdapInvalidDnException lide ) 160 { 161 // Do nothing, can't get an exception here 162 } 163 164 { 165 _loop53: 166 do { 167 if ((LA(1)==COMMA||LA(1)==SEMI)) { 168 { 169 switch ( LA(1)) { 170 case COMMA: 171 { 172 match(COMMA); 173 break; 174 } 175 case SEMI: 176 { 177 match(SEMI); 178 break; 179 } 180 default: 181 { 182 throw new NoViableAltException(LT(1), getFilename()); 183 } 184 } 185 } 186 187 rdn = new Rdn( schemaManager ); 188 189 relativeDistinguishedName(schemaManager, rdn); 190 191 try 192 { 193 dn.add( rdn ); 194 } 195 catch ( LdapInvalidDnException lide ) 196 { 197 // Do nothing, can't get an exception here 198 } 199 200 } 201 else { 202 break _loop53; 203 } 204 205 } while (true); 206 } 207 match(Token.EOF_TYPE); 208 break; 209 } 210 case EOF: 211 { 212 break; 213 } 214 default: 215 { 216 throw new NoViableAltException(LT(1), getFilename()); 217 } 218 } 219 } 220 } 221 222/** 223 * Parses a Rdn string. 224 * 225 * RFC 4514, Section 3 226 * <pre> 227 * relativeDistinguishedName = attributeTypeAndValue 228 * *( PLUS attributeTypeAndValue ) 229 * </pre> 230 * 231 * RFC 2253, Section 3 232 * <pre> 233 * name-component = attributeTypeAndValue *("+" attributeTypeAndValue) 234 * </pre> 235 * 236 * RFC 1779, Section 2.3 237 * <pre> 238 * <name-component> ::= <attribute> 239 * | <attribute> <optional-space> "+" 240 * <optional-space> <name-component> 241 * </pre> 242 * 243 * @param schemaManager The SchemaManager 244 * @param rdn The Rdn to update 245 * @throws RecognitionException If the token is invalid 246 * @throws TokenStreamException When we weren't able to fetch a token 247 */ 248 public final void relativeDistinguishedName( 249 SchemaManager schemaManager, Rdn rdn 250 ) throws RecognitionException, TokenStreamException { 251 252 253 matchedProduction( "relativeDistinguishedName()" ); 254 String tmp; 255 256 // The rdnStr variable is used to gather the full RDN string 257 // as provided 258 StringBuilder rdnStr = new StringBuilder(); 259 StringBuilder rdnNormStr = new StringBuilder(); 260 int avaPos = 0; 261 Ava currentAva; 262 AttributeType attributeType; 263 Value val; 264 265 266 { 267 tmp=attributeTypeAndValue(schemaManager, rdn); 268 269 rdnStr.append( tmp ); 270 currentAva = rdn.getAva( avaPos ); 271 272 attributeType = currentAva.getAttributeType(); 273 274 if ( schemaManager == null ) 275 { 276 rdnNormStr.append( currentAva.getNormType() ); 277 rdnNormStr.append( '=' ); 278 } 279 280 val = currentAva.getValue(); 281 282 if ( ( schemaManager == null ) && ( val != null ) && ( val.getNormalized() != null ) ) 283 { 284 rdnNormStr.append( val.getNormalized() ); 285 } 286 287 { 288 _loop62: 289 do { 290 if ((LA(1)==PLUS)) { 291 match(PLUS); 292 293 rdnStr.append( '+' ); 294 295 if ( schemaManager == null ) 296 { 297 rdnNormStr.append( '+' ); 298 } 299 300 avaPos++; 301 302 tmp=attributeTypeAndValue(schemaManager, rdn); 303 304 rdnStr.append( tmp ); 305 currentAva = rdn.getAva( avaPos ); 306 attributeType = currentAva.getAttributeType(); 307 308 if ( schemaManager == null ) 309 { 310 rdnNormStr.append( tmp ); 311 rdnNormStr.append( '=' ); 312 } 313 314 val = currentAva.getValue(); 315 316 if ( ( schemaManager == null ) &&( val != null ) && ( val.getNormalized() != null ) ) 317 { 318 rdnNormStr.append( val.getNormalized() ); 319 } 320 321 } 322 else { 323 break _loop62; 324 } 325 326 } while (true); 327 } 328 } 329 330 rdn.hashCode(); 331 rdn.setUpName( rdnStr.toString() ); 332 333 if ( schemaManager != null ) 334 { 335 // process the multi-value RDN, ordering them by attributes 336 boolean isFirst = true; 337 338 for ( Ava ava : rdn ) 339 { 340 if ( isFirst ) 341 { 342 isFirst = false; 343 } 344 else 345 { 346 rdnNormStr.append( '+' ); 347 } 348 349 rdnNormStr.append( ava.getAttributeType().getOid() ); 350 rdnNormStr.append( '=' ); 351 352 val = ava.getValue(); 353 354 if ( ( val != null ) && ( val.getNormalized() != null ) ) 355 { 356 rdnNormStr.append( val.getNormalized() ); 357 } 358 } 359 } 360 361 rdn.setNormName( rdnNormStr.toString() ); 362 363 } 364 365/** 366 * Parses a Dn string. 367 * 368 * RFC 4514, Section 3 369 * <pre> 370 * distinguishedName = [ relativeDistinguishedName 371 * *( COMMA relativeDistinguishedName ) ] 372 * </pre> 373 * 374 * RFC 2253, Section 3 375 * <pre> 376 * distinguishedName = [name] 377 * name = name-component *("," name-component) 378 * </pre> 379 * 380 * RFC 1779, Section 2.3 381 * <pre> 382 * <name> ::= <name-component> ( <spaced-separator> ) 383 * | <name-component> <spaced-separator> <name> 384 * <spaced-separator> ::= <optional-space> 385 * <separator> 386 * <optional-space> 387 * <separator> ::= "," | ";" 388 * <optional-space> ::= ( <CR> ) *( " " ) 389 * </pre> 390 * 391 * @param schemaManager The SchemaManager 392 * @param rdns The list of Rdns to update 393 * @return The normalized Dn 394 * @throws RecognitionException If the token is invalid 395 * @throws TokenStreamException When we weren't able to fetch a token 396 */ 397 public final String relativeDistinguishedNames( 398 SchemaManager schemaManager, List<Rdn> rdns 399 ) throws RecognitionException, TokenStreamException { 400 String normNameStr; 401 402 403 matchedProduction( "relativeDistinguishedNames()" ); 404 Rdn rdn = new Rdn( schemaManager ); 405 StringBuilder dnNormSb = new StringBuilder(); 406 407 408 { 409 switch ( LA(1)) { 410 case SPACE: 411 case NUMERICOID: 412 case ALPHA: 413 { 414 relativeDistinguishedName( schemaManager, rdn); 415 416 rdns.add( rdn ); 417 dnNormSb.append( rdn.getNormName() ); 418 rdn = new Rdn( schemaManager ); 419 420 { 421 _loop58: 422 do { 423 if ((LA(1)==COMMA||LA(1)==SEMI)) { 424 { 425 switch ( LA(1)) { 426 case COMMA: 427 { 428 match(COMMA); 429 break; 430 } 431 case SEMI: 432 { 433 match(SEMI); 434 break; 435 } 436 default: 437 { 438 throw new NoViableAltException(LT(1), getFilename()); 439 } 440 } 441 } 442 relativeDistinguishedName(schemaManager, rdn); 443 444 rdns.add( rdn ); 445 dnNormSb.append( ',' ); 446 dnNormSb.append( rdn.getNormName() ); 447 rdn = new Rdn( schemaManager ); 448 449 } 450 else { 451 break _loop58; 452 } 453 454 } while (true); 455 } 456 match(Token.EOF_TYPE); 457 break; 458 } 459 case EOF: 460 { 461 break; 462 } 463 default: 464 { 465 throw new NoViableAltException(LT(1), getFilename()); 466 } 467 } 468 } 469 470 normNameStr = dnNormSb.toString(); 471 472 return normNameStr; 473 } 474 475/** 476 * RFC 4514, Section 3 477 * <pre> 478 * attributeTypeAndValue = attributeType EQUALS attributeValue 479 * </pre> 480 * 481 * RFC 2253, Section 3 482 * <pre> 483 * attributeTypeAndValue = attributeType "=" attributeValue 484 * </pre> 485 * 486 * @param schemaManager The SchemaManager 487 * @param rdn The Rdn to update 488 * @return The user provided Ava 489 * @throws RecognitionException If the token is invalid 490 * @throws TokenStreamException When we weren't able to fetch a token 491 */ 492 public final String attributeTypeAndValue( 493 SchemaManager schemaManager, Rdn rdn 494 ) throws RecognitionException, TokenStreamException { 495 String upNameStr; 496 497 498 matchedProduction( "attributeTypeAndValue()" ); 499 String type = null; 500 UpAndNormValue value = new UpAndNormValue(); 501 StringBuilder rdnUpName = new StringBuilder(); 502 503 504 { 505 { 506 _loop66: 507 do { 508 if ((LA(1)==SPACE)) { 509 match(SPACE); 510 rdnUpName.append( ' ' ); 511 } 512 else { 513 break _loop66; 514 } 515 516 } while (true); 517 } 518 type=attributeType(); 519 rdnUpName.append( type ); 520 { 521 _loop68: 522 do { 523 if ((LA(1)==SPACE)) { 524 match(SPACE); 525 rdnUpName.append( ' ' ); 526 } 527 else { 528 break _loop68; 529 } 530 531 } while (true); 532 } 533 match(EQUALS); 534 rdnUpName.append( '=' ); 535 { 536 _loop70: 537 do { 538 if ((LA(1)==SPACE) && (_tokenSet_0.member(LA(2))) && (_tokenSet_1.member(LA(3)))) { 539 match(SPACE); 540 rdnUpName.append( ' ' ); 541 } 542 else { 543 break _loop70; 544 } 545 546 } while (true); 547 } 548 attributeValue(value); 549 550 try 551 { 552 // We have to remove the ending spaces that may have been added, as the tutf1 rule 553 // cannot be processed 554 rdnUpName.append( value.upValue ); 555 AttributeType attributeType = null; 556 Ava ava = null; 557 558 if ( schemaManager != null ) 559 { 560 if ( ( type.startsWith( "oid." ) ) || ( type.startsWith( "OID." ) ) ) 561 { 562 type = type.substring( 4 ); 563 } 564 565 attributeType = schemaManager.getAttributeType( type ); 566 } 567 568 if ( ( ( attributeType != null ) && attributeType.isHR() ) || value.isHR ) 569 { 570 int valueLength = value.upValue.length(); 571 int pos = value.bytes.position(); 572 573 for ( int i = valueLength - 1; i >= 0; i-- ) 574 { 575 if ( value.upValue.charAt( i ) == ' ' ) 576 { 577 if ( i == 0 ) 578 { 579 // The value is empty 580 ava = new Ava( schemaManager, type, rdnUpName.toString(), ( String ) null ); 581 break; 582 } 583 else if ( value.upValue.charAt( i - 1 ) != '\\' ) 584 { 585 // This is a trailing space, get rid of it 586 value.upValue.deleteCharAt( i ); 587 pos--; 588 value.bytes.position( pos ); 589 } 590 else 591 { 592 // This is an escaped space, get out 593 break; 594 } 595 } 596 else 597 { 598 break; 599 } 600 } 601 602 if ( ava == null ) 603 { 604 ava = new Ava( schemaManager, type, rdnUpName.toString(), Strings.utf8ToString( value.bytes.copyOfUsedBytes() ) ); 605 } 606 } 607 else 608 { 609 ava = new Ava( schemaManager, type, rdnUpName.toString(), value.bytes.copyOfUsedBytes() ); 610 } 611 612 rdn.addAVA( schemaManager, ava ); 613 } 614 catch ( LdapInvalidDnException e ) 615 { 616 throw new SemanticException( e.getMessage() ); 617 } 618 619 { 620 _loop72: 621 do { 622 if ((LA(1)==SPACE)) { 623 match(SPACE); 624 rdnUpName.append( ' ' ); 625 } 626 else { 627 break _loop72; 628 } 629 630 } while (true); 631 } 632 } 633 634 upNameStr = rdnUpName.toString(); 635 636 return upNameStr; 637 } 638 639/** 640 * RFC 4514 Section 3 641 * 642 * <pre> 643 * attributeType = descr / numericoid 644 * </pre> 645 * 646 * @return The AttributeType 647 * @throws RecognitionException If the token is invalid 648 * @throws TokenStreamException When we weren't able to fetch a token 649 */ 650 public final String attributeType() throws RecognitionException, TokenStreamException { 651 String attributeType; 652 653 654 matchedProduction( "attributeType()" ); 655 656 657 { 658 switch ( LA(1)) { 659 case ALPHA: 660 { 661 attributeType=descr(); 662 break; 663 } 664 case NUMERICOID: 665 { 666 attributeType=numericoid(); 667 break; 668 } 669 default: 670 { 671 throw new NoViableAltException(LT(1), getFilename()); 672 } 673 } 674 } 675 return attributeType; 676 } 677 678/** 679 * RFC 4514, Section 3 680 * <pre> 681 * attributeValue = string / hexstring 682 * </pre> 683 * 684 * RFC 2253, Section 3 685 * <pre> 686 * attributeValue = string 687 * string = *( stringchar / pair ) 688 * / "#" hexstring 689 * / QUOTATION *( quotechar / pair ) QUOTATION ; only from v2 690 * 691 * We still accept both forms, which means we can have a value surrounded by '"' 692 * </pre> 693 * 694 * @param value The value to update 695 * @throws RecognitionException If the token is invalid 696 * @throws TokenStreamException When we weren't able to fetch a token 697 */ 698 public final void attributeValue( 699 UpAndNormValue value 700 ) throws RecognitionException, TokenStreamException { 701 702 703 matchedProduction( "attributeValue()" ); 704 705 706 { 707 switch ( LA(1)) { 708 case DQUOTE: 709 { 710 quotestring(value); 711 break; 712 } 713 case EQUALS: 714 case HYPHEN: 715 case UNDERSCORE: 716 case NUMERICOID: 717 case DIGIT: 718 case ALPHA: 719 case HEXPAIR: 720 case ESC: 721 case ESCESC: 722 case ESCSHARP: 723 case UTFMB: 724 case CHAR_REST: 725 { 726 string(value); 727 break; 728 } 729 case HEXVALUE: 730 { 731 hexstring(value); 732 break; 733 } 734 case EOF: 735 case COMMA: 736 case PLUS: 737 case SEMI: 738 case SPACE: 739 { 740 break; 741 } 742 default: 743 { 744 throw new NoViableAltException(LT(1), getFilename()); 745 } 746 } 747 } 748 } 749 750/** 751 * RFC 4512 Section 1.4 752 * 753 * <pre> 754 * descr = keystring 755 * keystring = leadkeychar *keychar 756 * leadkeychar = ALPHA 757 * keychar = ALPHA / DIGIT / HYPHEN 758 * </pre> 759 * 760 * We additionally add UNDERSCORE because some servers allow them. 761 * 762 * @return The description 763 * @throws RecognitionException If the token is invalid 764 * @throws TokenStreamException When we weren't able to fetch a token 765 */ 766 public final String descr() throws RecognitionException, TokenStreamException { 767 String descr; 768 769 Token leadkeychar = null; 770 Token alpha = null; 771 Token digit = null; 772 773 matchedProduction( "descr()" ); 774 StringBuilder descrSb = new StringBuilder(); 775 776 777 leadkeychar = LT(1); 778 match(ALPHA); 779 descrSb.append( leadkeychar.getText() ); 780 { 781 _loop77: 782 do { 783 switch ( LA(1)) { 784 case ALPHA: 785 { 786 alpha = LT(1); 787 match(ALPHA); 788 descrSb.append( alpha.getText() ); 789 break; 790 } 791 case DIGIT: 792 { 793 digit = LT(1); 794 match(DIGIT); 795 descrSb.append( digit.getText() ); 796 break; 797 } 798 case HYPHEN: 799 { 800 match(HYPHEN); 801 descrSb.append( '-' ); 802 break; 803 } 804 case UNDERSCORE: 805 { 806 match(UNDERSCORE); 807 descrSb.append( '_' ); 808 break; 809 } 810 default: 811 { 812 break _loop77; 813 } 814 } 815 } while (true); 816 } 817 818 descr = descrSb.toString(); 819 820 return descr; 821 } 822 823/** 824 * RFC 4512 Section 1.4 825 * 826 * <pre> 827 * numericoid = number 1*( DOT number ) 828 * number = DIGIT / ( LDIGIT 1*DIGIT ) 829 * DIGIT = %x30 / LDIGIT ; "0"-"9" 830 * LDIGIT = %x31-39 ; "1"-"9" 831 * </pre> 832 * 833 * @return The numeric OID 834 * @throws RecognitionException If the token is invalid 835 * @throws TokenStreamException When we weren't able to fetch a token 836 */ 837 public final String numericoid() throws RecognitionException, TokenStreamException { 838 String numericoid = ""; 839 840 Token noid = null; 841 842 matchedProduction( "numericoid()" ); 843 844 845 noid = LT(1); 846 match(NUMERICOID); 847 numericoid = noid.getText(); 848 return numericoid; 849 } 850 851/** 852 * RFC 2253, Section 3 853 * <pre> 854 * / QUOTATION *( quotechar / pair ) QUOTATION ; only from v2 855 * quotechar = <any character except "\" or QUOTATION > 856 * </pre> 857 * 858 * @param value The value to update 859 * @throws RecognitionException If the token is invalid 860 * @throws TokenStreamException When we weren't able to fetch a token 861 */ 862 public final void quotestring( 863 UpAndNormValue value 864 ) throws RecognitionException, TokenStreamException { 865 866 Token s = null; 867 868 matchedProduction( "quotestring()" ); 869 870 871 { 872 match(DQUOTE); 873 value.upValue.append( '"' ); 874 { 875 _loop86: 876 do { 877 switch ( LA(1)) { 878 case COMMA: 879 case EQUALS: 880 case PLUS: 881 case HYPHEN: 882 case UNDERSCORE: 883 case SEMI: 884 case LANGLE: 885 case RANGLE: 886 case SPACE: 887 case NUMERICOID_OR_ALPHA_OR_DIGIT: 888 case NUMERICOID: 889 case DOT: 890 case NUMBER: 891 case LDIGIT: 892 case DIGIT: 893 case ALPHA: 894 case HEXPAIR_OR_ESCESC_ESCSHARP_OR_ESC: 895 case HEX: 896 case HEXVALUE_OR_SHARP: 897 case HEXVALUE: 898 case SHARP: 899 case UTFMB: 900 case CHAR_REST: 901 { 902 { 903 { 904 s = LT(1); 905 match(_tokenSet_2); 906 } 907 908 value.upValue.append( s.getText() ); 909 value.bytes.append( Strings.getBytesUtf8( s.getText() ) ); 910 911 } 912 break; 913 } 914 case HEXPAIR: 915 case ESC: 916 case ESCESC: 917 case ESCSHARP: 918 { 919 pair(value); 920 break; 921 } 922 default: 923 { 924 break _loop86; 925 } 926 } 927 } while (true); 928 } 929 match(DQUOTE); 930 value.upValue.append( '"' ); 931 } 932 } 933 934/** 935 * RFC 4514 Section 3 936 * 937 * <pre> 938 * ; The following characters are to be escaped when they appear 939 * ; in the value to be encoded: ESC, one of <escaped>, <leading> 940 * ; SHARP or SPACE, trailing SPACE, and NULL. 941 * string = [ ( leadchar / pair ) [ *( stringchar / pair ) ( trailchar / pair ) ] ] 942 * leadchar = LUTF1 | UTFMB 943 * stringchar = SUTF1 / UTFMB 944 * trailchar = TUTF1 / UTFMB 945 * </pre> 946 * 947 * @param value The value to update 948 * @throws RecognitionException If the token is invalid 949 * @throws TokenStreamException When we weren't able to fetch a token 950 */ 951 public final void string( 952 UpAndNormValue value 953 ) throws RecognitionException, TokenStreamException { 954 955 956 matchedProduction( "string()" ); 957 958 959 { 960 { 961 switch ( LA(1)) { 962 case EQUALS: 963 case HYPHEN: 964 case UNDERSCORE: 965 case NUMERICOID: 966 case DIGIT: 967 case ALPHA: 968 case CHAR_REST: 969 { 970 lutf1(value); 971 break; 972 } 973 case UTFMB: 974 { 975 utfmb(value); 976 break; 977 } 978 case HEXPAIR: 979 case ESC: 980 case ESCESC: 981 case ESCSHARP: 982 { 983 pair(value); 984 break; 985 } 986 default: 987 { 988 throw new NoViableAltException(LT(1), getFilename()); 989 } 990 } 991 } 992 { 993 _loop92: 994 do { 995 switch ( LA(1)) { 996 case UTFMB: 997 { 998 utfmb(value); 999 break; 1000 } 1001 case HEXPAIR: 1002 case ESC: 1003 case ESCESC: 1004 case ESCSHARP: 1005 { 1006 pair(value); 1007 break; 1008 } 1009 default: 1010 if ((_tokenSet_3.member(LA(1))) && (_tokenSet_4.member(LA(2))) && (_tokenSet_5.member(LA(3)))) { 1011 sutf1(value); 1012 } 1013 else { 1014 break _loop92; 1015 } 1016 } 1017 } while (true); 1018 } 1019 } 1020 } 1021 1022/** 1023 * RFC 4514 Section 3 1024 * 1025 * <pre> 1026 * hexstring = SHARP 1*hexpair 1027 * 1028 * If in <hexstring> form, a BER representation can be obtained from 1029 * converting each <hexpair> of the <hexstring> to the octet indicated 1030 * by the <hexpair>. 1031 * </pre> 1032 * 1033 * @param value The value to update 1034 * @throws RecognitionException If the token is invalid 1035 * @throws TokenStreamException When we weren't able to fetch a token 1036 */ 1037 public final void hexstring( 1038 UpAndNormValue value 1039 ) throws RecognitionException, TokenStreamException { 1040 1041 Token hexValue = null; 1042 1043 matchedProduction( "hexstring()" ); 1044 1045 1046 hexValue = LT(1); 1047 match(HEXVALUE); 1048 1049 String hexStr = hexValue.getText(); 1050 value.upValue.append( '#' ).append( hexStr ); 1051 value.bytes.append( Strings.toByteArray( hexStr ) ); 1052 value.isHR = false; 1053 1054 } 1055 1056/** 1057 * RFC 4514, Section 3 1058 * <pre> 1059 * pair = ESC ( ESC / special / hexpair ) 1060 * special = escaped / SPACE / SHARP / EQUALS 1061 * escaped = DQUOTE / PLUS / COMMA / SEMI / LANGLE / RANGLE 1062 * hexpair = HEX HEX 1063 * 1064 * If in <string> form, a LDAP string representation asserted value can 1065 * be obtained by replacing (left to right, non-recursively) each <pair> 1066 * appearing in the <string> as follows: 1067 * replace <ESC><ESC> with <ESC>; 1068 * replace <ESC><special> with <special>; 1069 * replace <ESC><hexpair> with the octet indicated by the <hexpair>. 1070 * </pre> 1071 * 1072 * RFC 2253, Section 3 1073 * <pre> 1074 * pair = "\" ( special / "\" / QUOTATION / hexpair ) 1075 * special = "," / "=" / "+" / "<" / ">" / "#" / ";" 1076 * </pre> 1077 * 1078 * RFC 1779, Section 2.3 1079 * <pre> 1080 * <pair> ::= "\" ( <special> | "\" | '"') 1081 * <special> ::= "," | "=" | <CR> | "+" | "<" | ">" 1082 * | "#" | ";" 1083 * </pre> 1084 * 1085 * @param value The value to update 1086 * @throws RecognitionException If the token is invalid 1087 * @throws TokenStreamException When we weren't able to fetch a token 1088 */ 1089 public final void pair( 1090 UpAndNormValue value 1091 ) throws RecognitionException, TokenStreamException { 1092 1093 Token hexpair = null; 1094 1095 matchedProduction( "pair()" ); 1096 char specialChar; 1097 1098 1099 switch ( LA(1)) { 1100 case ESCESC: 1101 { 1102 { 1103 match(ESCESC); 1104 1105 value.upValue.append( "\\\\" ); 1106 value.bytes.append( '\\' ); 1107 1108 } 1109 break; 1110 } 1111 case ESCSHARP: 1112 { 1113 { 1114 match(ESCSHARP); 1115 1116 value.upValue.append( "\\#" ); 1117 value.bytes.append( '#' ); 1118 1119 } 1120 break; 1121 } 1122 case ESC: 1123 { 1124 { 1125 match(ESC); 1126 specialChar=special(); 1127 1128 value.upValue.append( '\\' ).append( specialChar ); 1129 value.bytes.append( specialChar ); 1130 1131 } 1132 break; 1133 } 1134 case HEXPAIR: 1135 { 1136 { 1137 hexpair = LT(1); 1138 match(HEXPAIR); 1139 1140 value.upValue.append( '\\' ).append( hexpair.getText() ); 1141 value.bytes.append( Strings.toByteArray( hexpair.getText() ) ); 1142 1143 } 1144 break; 1145 } 1146 default: 1147 { 1148 throw new NoViableAltException(LT(1), getFilename()); 1149 } 1150 } 1151 } 1152 1153/** 1154 * RFC 4514, Section 3: 1155 * <pre> 1156 * LUTF1 = %x01-1F / %x21 / %x24-2A / %x2D-3A / 1157 * %x3D / %x3F-5B / %x5D-7F 1158 * 1159 * The rule CHAR_REST doesn't contain the following charcters, 1160 * so we must check them additionally 1161 * EQUALS (0x3D) 1162 * HYPHEN (0x2D) 1163 * UNDERSCORE (0x5F) 1164 * DIGIT (0x30-0x39) 1165 * ALPHA (0x41-0x5A and 0x61-0x7A) 1166 * </pre> 1167 * 1168 * @param value The value to update 1169 * @throws RecognitionException If the token is invalid 1170 * @throws TokenStreamException When we weren't able to fetch a token 1171 */ 1172 public final void lutf1( 1173 UpAndNormValue value 1174 ) throws RecognitionException, TokenStreamException { 1175 1176 Token rest = null; 1177 Token digit = null; 1178 Token alpha = null; 1179 Token numericoid = null; 1180 1181 matchedProduction( "lutf1()" ); 1182 1183 1184 switch ( LA(1)) { 1185 case CHAR_REST: 1186 { 1187 rest = LT(1); 1188 match(CHAR_REST); 1189 1190 char c = rest.getText().charAt( 0 ); 1191 value.upValue.append( c ); 1192 value.bytes.append( ( byte ) c ); 1193 1194 break; 1195 } 1196 case EQUALS: 1197 { 1198 match(EQUALS); 1199 1200 value.upValue.append( '=' ); 1201 value.bytes.append( '=' ); 1202 1203 break; 1204 } 1205 case HYPHEN: 1206 { 1207 match(HYPHEN); 1208 1209 value.upValue.append( '-' ); 1210 value.bytes.append( '-' ); 1211 1212 break; 1213 } 1214 case UNDERSCORE: 1215 { 1216 match(UNDERSCORE); 1217 1218 value.upValue.append( '_' ); 1219 value.bytes.append( '_' ); 1220 1221 break; 1222 } 1223 case DIGIT: 1224 { 1225 digit = LT(1); 1226 match(DIGIT); 1227 1228 char c = digit.getText().charAt( 0 ); 1229 value.upValue.append( c ); 1230 value.bytes.append( ( byte ) c ); 1231 1232 break; 1233 } 1234 case ALPHA: 1235 { 1236 alpha = LT(1); 1237 match(ALPHA); 1238 1239 char c = alpha.getText().charAt( 0 ); 1240 value.upValue.append( c ); 1241 value.bytes.append( ( byte ) c ); 1242 1243 break; 1244 } 1245 case NUMERICOID: 1246 { 1247 numericoid = LT(1); 1248 match(NUMERICOID); 1249 1250 String number = numericoid.getText(); 1251 value.upValue.append( number ); 1252 value.bytes.append( Strings.getBytesUtf8( number ) ); 1253 1254 break; 1255 } 1256 default: 1257 { 1258 throw new NoViableAltException(LT(1), getFilename()); 1259 } 1260 } 1261 } 1262 1263/** 1264 * Process a UTFMB char 1265 * 1266 * @param value The value to update 1267 * @throws RecognitionException If the token is invalid 1268 * @throws TokenStreamException When we weren't able to fetch a token 1269 */ 1270 public final void utfmb( 1271 UpAndNormValue value 1272 ) throws RecognitionException, TokenStreamException { 1273 1274 Token s = null; 1275 1276 matchedProduction( "utfmb()" ); 1277 1278 1279 s = LT(1); 1280 match(UTFMB); 1281 1282 char c = s.getText().charAt( 0 ); 1283 value.upValue.append( c ); 1284 value.bytes.append( Unicode.charToBytes( c ) ); 1285 1286 } 1287 1288/** 1289 * RFC 4514, Section 3: 1290 * <pre> 1291 * SUTF1 = %x01-21 / %x23-2A / %x2D-3A / 1292 * %x3D / %x3F-5B / %x5D-7F 1293 * 1294 * The rule CHAR_REST doesn't contain the following charcters, 1295 * so we must check them additionally 1296 * EQUALS (0x3D) 1297 * HYPHEN (0x2D) 1298 * UNDERSCORE (0x5F) 1299 * DIGIT (0x30-0x39) 1300 * ALPHA (0x41-0x5A and 0x61-0x7A) 1301 * SHARP (0x23) 1302 * SPACE (0x20) 1303 * </pre> 1304 * 1305 * @param value The value to update 1306 * @throws RecognitionException If the token is invalid 1307 * @throws TokenStreamException When we weren't able to fetch a token 1308 */ 1309 public final void sutf1( 1310 UpAndNormValue value 1311 ) throws RecognitionException, TokenStreamException { 1312 1313 Token rest = null; 1314 Token digit = null; 1315 Token alpha = null; 1316 Token hex = null; 1317 Token numericoid = null; 1318 1319 matchedProduction( "sutf1()" ); 1320 1321 1322 switch ( LA(1)) { 1323 case CHAR_REST: 1324 { 1325 rest = LT(1); 1326 match(CHAR_REST); 1327 1328 char c = rest.getText().charAt( 0 ); 1329 value.upValue.append( c ); 1330 value.bytes.append( ( byte ) c ); 1331 1332 break; 1333 } 1334 case EQUALS: 1335 { 1336 match(EQUALS); 1337 1338 value.upValue.append( '=' ); 1339 value.bytes.append( '=' ); 1340 1341 break; 1342 } 1343 case HYPHEN: 1344 { 1345 match(HYPHEN); 1346 1347 value.upValue.append( '-' ); 1348 value.bytes.append( '-' ); 1349 1350 break; 1351 } 1352 case UNDERSCORE: 1353 { 1354 match(UNDERSCORE); 1355 1356 value.upValue.append( '_' ); 1357 value.bytes.append( '_' ); 1358 1359 break; 1360 } 1361 case DIGIT: 1362 { 1363 digit = LT(1); 1364 match(DIGIT); 1365 1366 char c = digit.getText().charAt( 0 ); 1367 value.upValue.append( c ); 1368 value.bytes.append( ( byte ) c ); 1369 1370 break; 1371 } 1372 case ALPHA: 1373 { 1374 alpha = LT(1); 1375 match(ALPHA); 1376 1377 char c = alpha.getText().charAt( 0 ); 1378 value.upValue.append( c ); 1379 value.bytes.append( ( byte ) c ); 1380 1381 break; 1382 } 1383 case SHARP: 1384 { 1385 match(SHARP); 1386 1387 value.upValue.append( '#' ); 1388 value.bytes.append( '#' ); 1389 1390 break; 1391 } 1392 case SPACE: 1393 { 1394 match(SPACE); 1395 1396 value.upValue.append( ' ' ); 1397 value.bytes.append( ' ' ); 1398 1399 break; 1400 } 1401 case HEXVALUE: 1402 { 1403 hex = LT(1); 1404 match(HEXVALUE); 1405 1406 String hexStr = hex.getText(); 1407 value.upValue.append( '#' ).append( hexStr ); 1408 value.bytes.append( '#' ); 1409 value.bytes.append( Strings.getBytesUtf8( hexStr ) ); 1410 1411 break; 1412 } 1413 case NUMERICOID: 1414 { 1415 numericoid = LT(1); 1416 match(NUMERICOID); 1417 1418 String number = numericoid.getText(); 1419 value.upValue.append( number ); 1420 value.bytes.append( Strings.getBytesUtf8( number ) ); 1421 1422 break; 1423 } 1424 default: 1425 { 1426 throw new NoViableAltException(LT(1), getFilename()); 1427 } 1428 } 1429 } 1430 1431/** 1432 * RFC 4514 Section 3 1433 * 1434 * <pre> 1435 * special = escaped / SPACE / SHARP / EQUALS 1436 * escaped = DQUOTE / PLUS / COMMA / SEMI / LANGLE / RANGLE 1437 * </pre> 1438 * 1439 * @return The special char 1440 * @throws RecognitionException If the token is invalid 1441 * @throws TokenStreamException When we weren't able to fetch a token 1442 */ 1443 public final char special() throws RecognitionException, TokenStreamException { 1444 char special; 1445 1446 1447 matchedProduction( "()" ); 1448 1449 1450 { 1451 switch ( LA(1)) { 1452 case DQUOTE: 1453 { 1454 match(DQUOTE); 1455 special = '"'; 1456 break; 1457 } 1458 case PLUS: 1459 { 1460 match(PLUS); 1461 special = '+'; 1462 break; 1463 } 1464 case COMMA: 1465 { 1466 match(COMMA); 1467 special = ','; 1468 break; 1469 } 1470 case SEMI: 1471 { 1472 match(SEMI); 1473 special = ';'; 1474 break; 1475 } 1476 case LANGLE: 1477 { 1478 match(LANGLE); 1479 special = '<'; 1480 break; 1481 } 1482 case RANGLE: 1483 { 1484 match(RANGLE); 1485 special = '>'; 1486 break; 1487 } 1488 case SPACE: 1489 { 1490 match(SPACE); 1491 special = ' '; 1492 break; 1493 } 1494 case SHARP: 1495 { 1496 match(SHARP); 1497 special = '#'; 1498 break; 1499 } 1500 case EQUALS: 1501 { 1502 match(EQUALS); 1503 special = '='; 1504 break; 1505 } 1506 default: 1507 { 1508 throw new NoViableAltException(LT(1), getFilename()); 1509 } 1510 } 1511 } 1512 return special; 1513 } 1514 1515 1516 public static final String[] _tokenNames = { 1517 "<0>", 1518 "EOF", 1519 "<2>", 1520 "NULL_TREE_LOOKAHEAD", 1521 "COMMA", 1522 "EQUALS", 1523 "PLUS", 1524 "HYPHEN", 1525 "UNDERSCORE", 1526 "DQUOTE", 1527 "SEMI", 1528 "LANGLE", 1529 "RANGLE", 1530 "SPACE", 1531 "NUMERICOID_OR_ALPHA_OR_DIGIT", 1532 "NUMERICOID", 1533 "DOT", 1534 "NUMBER", 1535 "LDIGIT", 1536 "DIGIT", 1537 "ALPHA", 1538 "HEXPAIR_OR_ESCESC_ESCSHARP_OR_ESC", 1539 "HEXPAIR", 1540 "ESC", 1541 "ESCESC", 1542 "ESCSHARP", 1543 "HEX", 1544 "HEXVALUE_OR_SHARP", 1545 "HEXVALUE", 1546 "SHARP", 1547 "UTFMB", 1548 "CHAR_REST" 1549 }; 1550 1551 private static final long[] mk_tokenSet_0() { 1552 long[] data = { 3554191346L, 0L}; 1553 return data; 1554 } 1555 public static final BitSet _tokenSet_0 = new BitSet(mk_tokenSet_0()); 1556 private static final long[] mk_tokenSet_1() { 1557 long[] data = { 4294967282L, 0L, 0L, 0L}; 1558 return data; 1559 } 1560 public static final BitSet _tokenSet_1 = new BitSet(mk_tokenSet_1()); 1561 private static final long[] mk_tokenSet_2() { 1562 long[] data = { 4232052208L, 0L, 0L, 0L}; 1563 return data; 1564 } 1565 public static final BitSet _tokenSet_2 = new BitSet(mk_tokenSet_2()); 1566 private static final long[] mk_tokenSet_3() { 1567 long[] data = { 2954404256L, 0L}; 1568 return data; 1569 } 1570 public static final BitSet _tokenSet_3 = new BitSet(mk_tokenSet_3()); 1571 private static final long[] mk_tokenSet_4() { 1572 long[] data = { 4091061746L, 0L}; 1573 return data; 1574 } 1575 public static final BitSet _tokenSet_4 = new BitSet(mk_tokenSet_4()); 1576 private static final long[] mk_tokenSet_5() { 1577 long[] data = { 4091068402L, 0L}; 1578 return data; 1579 } 1580 public static final BitSet _tokenSet_5 = new BitSet(mk_tokenSet_5()); 1581 1582 }