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 * https://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 ) ) 283 { 284 if ( val.getNormalized() != null ) 285 { 286 rdnNormStr.append( val.getNormalized() ); 287 } 288 else 289 { 290 // We can't tell if the value is HR or not. 291 // Use the Value User Provided value 292 rdnNormStr.append( val.getUpValue() ); 293 } 294 } 295 296 { 297 _loop62: 298 do { 299 if ((LA(1)==PLUS)) { 300 match(PLUS); 301 302 rdnStr.append( '+' ); 303 304 if ( schemaManager == null ) 305 { 306 rdnNormStr.append( '+' ); 307 } 308 309 avaPos++; 310 311 tmp=attributeTypeAndValue(schemaManager, rdn); 312 313 rdnStr.append( tmp ); 314 currentAva = rdn.getAva( avaPos ); 315 attributeType = currentAva.getAttributeType(); 316 317 if ( schemaManager == null ) 318 { 319 rdnNormStr.append( tmp ); 320 rdnNormStr.append( '=' ); 321 } 322 323 val = currentAva.getValue(); 324 325 if ( ( schemaManager == null ) && ( val != null ) ) 326 { 327 if ( val.getNormalized() != null ) 328 { 329 rdnNormStr.append( val.getNormalized() ); 330 } 331 else 332 { 333 // We can't tell if the value is HR or not. 334 // Use the Value User Provided value 335 rdnNormStr.append( val.getUpValue() ); 336 } 337 } 338 339 } 340 else { 341 break _loop62; 342 } 343 344 } while (true); 345 } 346 } 347 348 rdn.hashCode(); 349 rdn.setUpName( rdnStr.toString() ); 350 351 if ( schemaManager != null ) 352 { 353 // process the multi-value RDN, ordering them by attributes 354 boolean isFirst = true; 355 356 for ( Ava ava : rdn ) 357 { 358 if ( isFirst ) 359 { 360 isFirst = false; 361 } 362 else 363 { 364 rdnNormStr.append( '+' ); 365 } 366 367 rdnNormStr.append( ava.getAttributeType().getOid() ); 368 rdnNormStr.append( '=' ); 369 370 val = ava.getValue(); 371 372 if ( ( val != null ) && ( val.getNormalized() != null ) ) 373 { 374 rdnNormStr.append( val.getNormalized() ); 375 } 376 } 377 } 378 379 rdn.setNormName( rdnNormStr.toString() ); 380 381 } 382 383/** 384 * Parses a Dn string. 385 * 386 * RFC 4514, Section 3 387 * <pre> 388 * distinguishedName = [ relativeDistinguishedName 389 * *( COMMA relativeDistinguishedName ) ] 390 * </pre> 391 * 392 * RFC 2253, Section 3 393 * <pre> 394 * distinguishedName = [name] 395 * name = name-component *("," name-component) 396 * </pre> 397 * 398 * RFC 1779, Section 2.3 399 * <pre> 400 * <name> ::= <name-component> ( <spaced-separator> ) 401 * | <name-component> <spaced-separator> <name> 402 * <spaced-separator> ::= <optional-space> 403 * <separator> 404 * <optional-space> 405 * <separator> ::= "," | ";" 406 * <optional-space> ::= ( <CR> ) *( " " ) 407 * </pre> 408 * 409 * @param schemaManager The SchemaManager 410 * @param rdns The list of Rdns to update 411 * @return The normalized Dn 412 * @throws RecognitionException If the token is invalid 413 * @throws TokenStreamException When we weren't able to fetch a token 414 */ 415 public final String relativeDistinguishedNames( 416 SchemaManager schemaManager, List<Rdn> rdns 417 ) throws RecognitionException, TokenStreamException { 418 String normNameStr; 419 420 421 matchedProduction( "relativeDistinguishedNames()" ); 422 Rdn rdn = new Rdn( schemaManager ); 423 StringBuilder dnNormSb = new StringBuilder(); 424 425 426 { 427 switch ( LA(1)) { 428 case SPACE: 429 case NUMERICOID: 430 case ALPHA: 431 { 432 relativeDistinguishedName( schemaManager, rdn); 433 434 rdns.add( rdn ); 435 dnNormSb.append( rdn.getNormName() ); 436 rdn = new Rdn( schemaManager ); 437 438 { 439 _loop58: 440 do { 441 if ((LA(1)==COMMA||LA(1)==SEMI)) { 442 { 443 switch ( LA(1)) { 444 case COMMA: 445 { 446 match(COMMA); 447 break; 448 } 449 case SEMI: 450 { 451 match(SEMI); 452 break; 453 } 454 default: 455 { 456 throw new NoViableAltException(LT(1), getFilename()); 457 } 458 } 459 } 460 relativeDistinguishedName(schemaManager, rdn); 461 462 rdns.add( rdn ); 463 dnNormSb.append( ',' ); 464 dnNormSb.append( rdn.getNormName() ); 465 rdn = new Rdn( schemaManager ); 466 467 } 468 else { 469 break _loop58; 470 } 471 472 } while (true); 473 } 474 match(Token.EOF_TYPE); 475 break; 476 } 477 case EOF: 478 { 479 break; 480 } 481 default: 482 { 483 throw new NoViableAltException(LT(1), getFilename()); 484 } 485 } 486 } 487 488 normNameStr = dnNormSb.toString(); 489 490 return normNameStr; 491 } 492 493/** 494 * RFC 4514, Section 3 495 * <pre> 496 * attributeTypeAndValue = attributeType EQUALS attributeValue 497 * </pre> 498 * 499 * RFC 2253, Section 3 500 * <pre> 501 * attributeTypeAndValue = attributeType "=" attributeValue 502 * </pre> 503 * 504 * @param schemaManager The SchemaManager 505 * @param rdn The Rdn to update 506 * @return The user provided Ava 507 * @throws RecognitionException If the token is invalid 508 * @throws TokenStreamException When we weren't able to fetch a token 509 */ 510 public final String attributeTypeAndValue( 511 SchemaManager schemaManager, Rdn rdn 512 ) throws RecognitionException, TokenStreamException { 513 String upNameStr; 514 515 516 matchedProduction( "attributeTypeAndValue()" ); 517 String type = null; 518 UpAndNormValue value = new UpAndNormValue(); 519 StringBuilder rdnUpName = new StringBuilder(); 520 521 522 { 523 { 524 _loop66: 525 do { 526 if ((LA(1)==SPACE)) { 527 match(SPACE); 528 rdnUpName.append( ' ' ); 529 } 530 else { 531 break _loop66; 532 } 533 534 } while (true); 535 } 536 type=attributeType(); 537 rdnUpName.append( type ); 538 { 539 _loop68: 540 do { 541 if ((LA(1)==SPACE)) { 542 match(SPACE); 543 rdnUpName.append( ' ' ); 544 } 545 else { 546 break _loop68; 547 } 548 549 } while (true); 550 } 551 match(EQUALS); 552 rdnUpName.append( '=' ); 553 { 554 _loop70: 555 do { 556 if ((LA(1)==SPACE) && (_tokenSet_0.member(LA(2))) && (_tokenSet_1.member(LA(3)))) { 557 match(SPACE); 558 rdnUpName.append( ' ' ); 559 } 560 else { 561 break _loop70; 562 } 563 564 } while (true); 565 } 566 attributeValue(value); 567 568 try 569 { 570 // We have to remove the ending spaces that may have been added, as the tutf1 rule 571 // cannot be processed 572 rdnUpName.append( value.upValue ); 573 AttributeType attributeType = null; 574 Ava ava = null; 575 576 if ( schemaManager != null ) 577 { 578 if ( ( type.startsWith( "oid." ) ) || ( type.startsWith( "OID." ) ) ) 579 { 580 type = type.substring( 4 ); 581 } 582 583 attributeType = schemaManager.getAttributeType( type ); 584 } 585 586 if ( ( ( attributeType != null ) && attributeType.isHR() ) || value.isHR ) 587 { 588 int valueLength = value.upValue.length(); 589 int pos = value.bytes.position(); 590 591 for ( int i = valueLength - 1; i >= 0; i-- ) 592 { 593 if ( value.upValue.charAt( i ) == ' ' ) 594 { 595 if ( i == 0 ) 596 { 597 // The value is empty 598 ava = new Ava( schemaManager, type, rdnUpName.toString(), ( String ) null ); 599 break; 600 } 601 else if ( value.upValue.charAt( i - 1 ) != '\\' ) 602 { 603 // This is a trailing space, get rid of it 604 value.upValue.deleteCharAt( i ); 605 pos--; 606 value.bytes.position( pos ); 607 } 608 else 609 { 610 // This is an escaped space, get out 611 break; 612 } 613 } 614 else 615 { 616 break; 617 } 618 } 619 620 if ( ava == null ) 621 { 622 ava = new Ava( schemaManager, type, rdnUpName.toString(), Strings.utf8ToString( value.bytes.copyOfUsedBytes() ) ); 623 } 624 } 625 else 626 { 627 ava = new Ava( schemaManager, type, rdnUpName.toString(), value.bytes.copyOfUsedBytes() ); 628 } 629 630 rdn.addAVA( schemaManager, ava ); 631 } 632 catch ( LdapInvalidDnException e ) 633 { 634 throw new SemanticException( e.getMessage() ); 635 } 636 637 { 638 _loop72: 639 do { 640 if ((LA(1)==SPACE)) { 641 match(SPACE); 642 rdnUpName.append( ' ' ); 643 } 644 else { 645 break _loop72; 646 } 647 648 } while (true); 649 } 650 } 651 652 upNameStr = rdnUpName.toString(); 653 654 return upNameStr; 655 } 656 657/** 658 * RFC 4514 Section 3 659 * 660 * <pre> 661 * attributeType = descr / numericoid 662 * </pre> 663 * 664 * @return The AttributeType 665 * @throws RecognitionException If the token is invalid 666 * @throws TokenStreamException When we weren't able to fetch a token 667 */ 668 public final String attributeType() throws RecognitionException, TokenStreamException { 669 String attributeType; 670 671 672 matchedProduction( "attributeType()" ); 673 674 675 { 676 switch ( LA(1)) { 677 case ALPHA: 678 { 679 attributeType=descr(); 680 break; 681 } 682 case NUMERICOID: 683 { 684 attributeType=numericoid(); 685 break; 686 } 687 default: 688 { 689 throw new NoViableAltException(LT(1), getFilename()); 690 } 691 } 692 } 693 return attributeType; 694 } 695 696/** 697 * RFC 4514, Section 3 698 * <pre> 699 * attributeValue = string / hexstring 700 * </pre> 701 * 702 * RFC 2253, Section 3 703 * <pre> 704 * attributeValue = string 705 * string = *( stringchar / pair ) 706 * / "#" hexstring 707 * / QUOTATION *( quotechar / pair ) QUOTATION ; only from v2 708 * 709 * We still accept both forms, which means we can have a value surrounded by '"' 710 * </pre> 711 * 712 * @param value The value to update 713 * @throws RecognitionException If the token is invalid 714 * @throws TokenStreamException When we weren't able to fetch a token 715 */ 716 public final void attributeValue( 717 UpAndNormValue value 718 ) throws RecognitionException, TokenStreamException { 719 720 721 matchedProduction( "attributeValue()" ); 722 723 724 { 725 switch ( LA(1)) { 726 case DQUOTE: 727 { 728 quotestring(value); 729 break; 730 } 731 case EQUALS: 732 case HYPHEN: 733 case UNDERSCORE: 734 case NUMERICOID: 735 case DIGIT: 736 case ALPHA: 737 case HEXPAIR: 738 case ESC: 739 case ESCESC: 740 case ESCSHARP: 741 case UTFMB: 742 case CHAR_REST: 743 { 744 string(value); 745 break; 746 } 747 case HEXVALUE: 748 { 749 hexstring(value); 750 break; 751 } 752 case EOF: 753 case COMMA: 754 case PLUS: 755 case SEMI: 756 case SPACE: 757 { 758 break; 759 } 760 default: 761 { 762 throw new NoViableAltException(LT(1), getFilename()); 763 } 764 } 765 } 766 } 767 768/** 769 * RFC 4512 Section 1.4 770 * 771 * <pre> 772 * descr = keystring 773 * keystring = leadkeychar *keychar 774 * leadkeychar = ALPHA 775 * keychar = ALPHA / DIGIT / HYPHEN 776 * </pre> 777 * 778 * We additionally add UNDERSCORE because some servers allow them. 779 * 780 * @return The description 781 * @throws RecognitionException If the token is invalid 782 * @throws TokenStreamException When we weren't able to fetch a token 783 */ 784 public final String descr() throws RecognitionException, TokenStreamException { 785 String descr; 786 787 Token leadkeychar = null; 788 Token alpha = null; 789 Token digit = null; 790 791 matchedProduction( "descr()" ); 792 StringBuilder descrSb = new StringBuilder(); 793 794 795 leadkeychar = LT(1); 796 match(ALPHA); 797 descrSb.append( leadkeychar.getText() ); 798 { 799 _loop77: 800 do { 801 switch ( LA(1)) { 802 case ALPHA: 803 { 804 alpha = LT(1); 805 match(ALPHA); 806 descrSb.append( alpha.getText() ); 807 break; 808 } 809 case DIGIT: 810 { 811 digit = LT(1); 812 match(DIGIT); 813 descrSb.append( digit.getText() ); 814 break; 815 } 816 case HYPHEN: 817 { 818 match(HYPHEN); 819 descrSb.append( '-' ); 820 break; 821 } 822 case UNDERSCORE: 823 { 824 match(UNDERSCORE); 825 descrSb.append( '_' ); 826 break; 827 } 828 default: 829 { 830 break _loop77; 831 } 832 } 833 } while (true); 834 } 835 836 descr = descrSb.toString(); 837 838 return descr; 839 } 840 841/** 842 * RFC 4512 Section 1.4 843 * 844 * <pre> 845 * numericoid = number 1*( DOT number ) 846 * number = DIGIT / ( LDIGIT 1*DIGIT ) 847 * DIGIT = %x30 / LDIGIT ; "0"-"9" 848 * LDIGIT = %x31-39 ; "1"-"9" 849 * </pre> 850 * 851 * @return The numeric OID 852 * @throws RecognitionException If the token is invalid 853 * @throws TokenStreamException When we weren't able to fetch a token 854 */ 855 public final String numericoid() throws RecognitionException, TokenStreamException { 856 String numericoid = ""; 857 858 Token noid = null; 859 860 matchedProduction( "numericoid()" ); 861 862 863 noid = LT(1); 864 match(NUMERICOID); 865 numericoid = noid.getText(); 866 return numericoid; 867 } 868 869/** 870 * RFC 2253, Section 3 871 * <pre> 872 * / QUOTATION *( quotechar / pair ) QUOTATION ; only from v2 873 * quotechar = <any character except "\" or QUOTATION > 874 * </pre> 875 * 876 * @param value The value to update 877 * @throws RecognitionException If the token is invalid 878 * @throws TokenStreamException When we weren't able to fetch a token 879 */ 880 public final void quotestring( 881 UpAndNormValue value 882 ) throws RecognitionException, TokenStreamException { 883 884 Token s = null; 885 886 matchedProduction( "quotestring()" ); 887 888 889 { 890 match(DQUOTE); 891 value.upValue.append( '"' ); 892 { 893 _loop86: 894 do { 895 switch ( LA(1)) { 896 case COMMA: 897 case EQUALS: 898 case PLUS: 899 case HYPHEN: 900 case UNDERSCORE: 901 case SEMI: 902 case LANGLE: 903 case RANGLE: 904 case SPACE: 905 case NUMERICOID_OR_ALPHA_OR_DIGIT: 906 case NUMERICOID: 907 case DOT: 908 case NUMBER: 909 case LDIGIT: 910 case DIGIT: 911 case ALPHA: 912 case HEXPAIR_OR_ESCESC_ESCSHARP_OR_ESC: 913 case HEX: 914 case HEXVALUE_OR_SHARP: 915 case HEXVALUE: 916 case SHARP: 917 case UTFMB: 918 case CHAR_REST: 919 { 920 { 921 { 922 s = LT(1); 923 match(_tokenSet_2); 924 } 925 926 value.upValue.append( s.getText() ); 927 value.bytes.append( Strings.getBytesUtf8( s.getText() ) ); 928 929 } 930 break; 931 } 932 case HEXPAIR: 933 case ESC: 934 case ESCESC: 935 case ESCSHARP: 936 { 937 pair(value); 938 break; 939 } 940 default: 941 { 942 break _loop86; 943 } 944 } 945 } while (true); 946 } 947 match(DQUOTE); 948 value.upValue.append( '"' ); 949 } 950 } 951 952/** 953 * RFC 4514 Section 3 954 * 955 * <pre> 956 * ; The following characters are to be escaped when they appear 957 * ; in the value to be encoded: ESC, one of <escaped>, <leading> 958 * ; SHARP or SPACE, trailing SPACE, and NULL. 959 * string = [ ( leadchar / pair ) [ *( stringchar / pair ) ( trailchar / pair ) ] ] 960 * leadchar = LUTF1 | UTFMB 961 * stringchar = SUTF1 / UTFMB 962 * trailchar = TUTF1 / UTFMB 963 * </pre> 964 * 965 * @param value The value to update 966 * @throws RecognitionException If the token is invalid 967 * @throws TokenStreamException When we weren't able to fetch a token 968 */ 969 public final void string( 970 UpAndNormValue value 971 ) throws RecognitionException, TokenStreamException { 972 973 974 matchedProduction( "string()" ); 975 976 977 { 978 { 979 switch ( LA(1)) { 980 case EQUALS: 981 case HYPHEN: 982 case UNDERSCORE: 983 case NUMERICOID: 984 case DIGIT: 985 case ALPHA: 986 case CHAR_REST: 987 { 988 lutf1(value); 989 break; 990 } 991 case UTFMB: 992 { 993 utfmb(value); 994 break; 995 } 996 case HEXPAIR: 997 case ESC: 998 case ESCESC: 999 case ESCSHARP: 1000 { 1001 pair(value); 1002 break; 1003 } 1004 default: 1005 { 1006 throw new NoViableAltException(LT(1), getFilename()); 1007 } 1008 } 1009 } 1010 { 1011 _loop92: 1012 do { 1013 switch ( LA(1)) { 1014 case UTFMB: 1015 { 1016 utfmb(value); 1017 break; 1018 } 1019 case HEXPAIR: 1020 case ESC: 1021 case ESCESC: 1022 case ESCSHARP: 1023 { 1024 pair(value); 1025 break; 1026 } 1027 default: 1028 if ((_tokenSet_3.member(LA(1))) && (_tokenSet_4.member(LA(2))) && (_tokenSet_5.member(LA(3)))) { 1029 sutf1(value); 1030 } 1031 else { 1032 break _loop92; 1033 } 1034 } 1035 } while (true); 1036 } 1037 } 1038 } 1039 1040/** 1041 * RFC 4514 Section 3 1042 * 1043 * <pre> 1044 * hexstring = SHARP 1*hexpair 1045 * 1046 * If in <hexstring> form, a BER representation can be obtained from 1047 * converting each <hexpair> of the <hexstring> to the octet indicated 1048 * by the <hexpair>. 1049 * </pre> 1050 * 1051 * @param value The value to update 1052 * @throws RecognitionException If the token is invalid 1053 * @throws TokenStreamException When we weren't able to fetch a token 1054 */ 1055 public final void hexstring( 1056 UpAndNormValue value 1057 ) throws RecognitionException, TokenStreamException { 1058 1059 Token hexValue = null; 1060 1061 matchedProduction( "hexstring()" ); 1062 1063 1064 hexValue = LT(1); 1065 match(HEXVALUE); 1066 1067 String hexStr = hexValue.getText(); 1068 value.upValue.append( '#' ).append( hexStr ); 1069 value.bytes.append( Strings.toByteArray( hexStr ) ); 1070 value.isHR = false; 1071 1072 } 1073 1074/** 1075 * RFC 4514, Section 3 1076 * <pre> 1077 * pair = ESC ( ESC / special / hexpair ) 1078 * special = escaped / SPACE / SHARP / EQUALS 1079 * escaped = DQUOTE / PLUS / COMMA / SEMI / LANGLE / RANGLE 1080 * hexpair = HEX HEX 1081 * 1082 * If in <string> form, a LDAP string representation asserted value can 1083 * be obtained by replacing (left to right, non-recursively) each <pair> 1084 * appearing in the <string> as follows: 1085 * replace <ESC><ESC> with <ESC>; 1086 * replace <ESC><special> with <special>; 1087 * replace <ESC><hexpair> with the octet indicated by the <hexpair>. 1088 * </pre> 1089 * 1090 * RFC 2253, Section 3 1091 * <pre> 1092 * pair = "\" ( special / "\" / QUOTATION / hexpair ) 1093 * special = "," / "=" / "+" / "<" / ">" / "#" / ";" 1094 * </pre> 1095 * 1096 * RFC 1779, Section 2.3 1097 * <pre> 1098 * <pair> ::= "\" ( <special> | "\" | '"') 1099 * <special> ::= "," | "=" | <CR> | "+" | "<" | ">" 1100 * | "#" | ";" 1101 * </pre> 1102 * 1103 * @param value The value to update 1104 * @throws RecognitionException If the token is invalid 1105 * @throws TokenStreamException When we weren't able to fetch a token 1106 */ 1107 public final void pair( 1108 UpAndNormValue value 1109 ) throws RecognitionException, TokenStreamException { 1110 1111 Token hexpair = null; 1112 1113 matchedProduction( "pair()" ); 1114 char specialChar; 1115 1116 1117 switch ( LA(1)) { 1118 case ESCESC: 1119 { 1120 { 1121 match(ESCESC); 1122 1123 value.upValue.append( "\\\\" ); 1124 value.bytes.append( '\\' ); 1125 1126 } 1127 break; 1128 } 1129 case ESCSHARP: 1130 { 1131 { 1132 match(ESCSHARP); 1133 1134 value.upValue.append( "\\#" ); 1135 value.bytes.append( '#' ); 1136 1137 } 1138 break; 1139 } 1140 case ESC: 1141 { 1142 { 1143 match(ESC); 1144 specialChar=special(); 1145 1146 value.upValue.append( '\\' ).append( specialChar ); 1147 value.bytes.append( specialChar ); 1148 1149 } 1150 break; 1151 } 1152 case HEXPAIR: 1153 { 1154 { 1155 hexpair = LT(1); 1156 match(HEXPAIR); 1157 1158 value.upValue.append( '\\' ).append( hexpair.getText() ); 1159 value.bytes.append( Strings.toByteArray( hexpair.getText() ) ); 1160 1161 } 1162 break; 1163 } 1164 default: 1165 { 1166 throw new NoViableAltException(LT(1), getFilename()); 1167 } 1168 } 1169 } 1170 1171/** 1172 * RFC 4514, Section 3: 1173 * <pre> 1174 * LUTF1 = %x01-1F / %x21 / %x24-2A / %x2D-3A / 1175 * %x3D / %x3F-5B / %x5D-7F 1176 * 1177 * The rule CHAR_REST doesn't contain the following charcters, 1178 * so we must check them additionally 1179 * EQUALS (0x3D) 1180 * HYPHEN (0x2D) 1181 * UNDERSCORE (0x5F) 1182 * DIGIT (0x30-0x39) 1183 * ALPHA (0x41-0x5A and 0x61-0x7A) 1184 * </pre> 1185 * 1186 * @param value The value to update 1187 * @throws RecognitionException If the token is invalid 1188 * @throws TokenStreamException When we weren't able to fetch a token 1189 */ 1190 public final void lutf1( 1191 UpAndNormValue value 1192 ) throws RecognitionException, TokenStreamException { 1193 1194 Token rest = null; 1195 Token digit = null; 1196 Token alpha = null; 1197 Token numericoid = null; 1198 1199 matchedProduction( "lutf1()" ); 1200 1201 1202 switch ( LA(1)) { 1203 case CHAR_REST: 1204 { 1205 rest = LT(1); 1206 match(CHAR_REST); 1207 1208 char c = rest.getText().charAt( 0 ); 1209 value.upValue.append( c ); 1210 value.bytes.append( ( byte ) c ); 1211 1212 break; 1213 } 1214 case EQUALS: 1215 { 1216 match(EQUALS); 1217 1218 value.upValue.append( '=' ); 1219 value.bytes.append( '=' ); 1220 1221 break; 1222 } 1223 case HYPHEN: 1224 { 1225 match(HYPHEN); 1226 1227 value.upValue.append( '-' ); 1228 value.bytes.append( '-' ); 1229 1230 break; 1231 } 1232 case UNDERSCORE: 1233 { 1234 match(UNDERSCORE); 1235 1236 value.upValue.append( '_' ); 1237 value.bytes.append( '_' ); 1238 1239 break; 1240 } 1241 case DIGIT: 1242 { 1243 digit = LT(1); 1244 match(DIGIT); 1245 1246 char c = digit.getText().charAt( 0 ); 1247 value.upValue.append( c ); 1248 value.bytes.append( ( byte ) c ); 1249 1250 break; 1251 } 1252 case ALPHA: 1253 { 1254 alpha = LT(1); 1255 match(ALPHA); 1256 1257 char c = alpha.getText().charAt( 0 ); 1258 value.upValue.append( c ); 1259 value.bytes.append( ( byte ) c ); 1260 1261 break; 1262 } 1263 case NUMERICOID: 1264 { 1265 numericoid = LT(1); 1266 match(NUMERICOID); 1267 1268 String number = numericoid.getText(); 1269 value.upValue.append( number ); 1270 value.bytes.append( Strings.getBytesUtf8( number ) ); 1271 1272 break; 1273 } 1274 default: 1275 { 1276 throw new NoViableAltException(LT(1), getFilename()); 1277 } 1278 } 1279 } 1280 1281/** 1282 * Process a UTFMB char 1283 * 1284 * @param value The value to update 1285 * @throws RecognitionException If the token is invalid 1286 * @throws TokenStreamException When we weren't able to fetch a token 1287 */ 1288 public final void utfmb( 1289 UpAndNormValue value 1290 ) throws RecognitionException, TokenStreamException { 1291 1292 Token s = null; 1293 1294 matchedProduction( "utfmb()" ); 1295 1296 1297 s = LT(1); 1298 match(UTFMB); 1299 1300 char c = s.getText().charAt( 0 ); 1301 value.upValue.append( c ); 1302 value.bytes.append( Unicode.charToBytes( c ) ); 1303 1304 } 1305 1306/** 1307 * RFC 4514, Section 3: 1308 * <pre> 1309 * SUTF1 = %x01-21 / %x23-2A / %x2D-3A / 1310 * %x3D / %x3F-5B / %x5D-7F 1311 * 1312 * The rule CHAR_REST doesn't contain the following charcters, 1313 * so we must check them additionally 1314 * EQUALS (0x3D) 1315 * HYPHEN (0x2D) 1316 * UNDERSCORE (0x5F) 1317 * DIGIT (0x30-0x39) 1318 * ALPHA (0x41-0x5A and 0x61-0x7A) 1319 * SHARP (0x23) 1320 * SPACE (0x20) 1321 * </pre> 1322 * 1323 * @param value The value to update 1324 * @throws RecognitionException If the token is invalid 1325 * @throws TokenStreamException When we weren't able to fetch a token 1326 */ 1327 public final void sutf1( 1328 UpAndNormValue value 1329 ) throws RecognitionException, TokenStreamException { 1330 1331 Token rest = null; 1332 Token digit = null; 1333 Token alpha = null; 1334 Token hex = null; 1335 Token numericoid = null; 1336 1337 matchedProduction( "sutf1()" ); 1338 1339 1340 switch ( LA(1)) { 1341 case CHAR_REST: 1342 { 1343 rest = LT(1); 1344 match(CHAR_REST); 1345 1346 char c = rest.getText().charAt( 0 ); 1347 value.upValue.append( c ); 1348 value.bytes.append( ( byte ) c ); 1349 1350 break; 1351 } 1352 case EQUALS: 1353 { 1354 match(EQUALS); 1355 1356 value.upValue.append( '=' ); 1357 value.bytes.append( '=' ); 1358 1359 break; 1360 } 1361 case HYPHEN: 1362 { 1363 match(HYPHEN); 1364 1365 value.upValue.append( '-' ); 1366 value.bytes.append( '-' ); 1367 1368 break; 1369 } 1370 case UNDERSCORE: 1371 { 1372 match(UNDERSCORE); 1373 1374 value.upValue.append( '_' ); 1375 value.bytes.append( '_' ); 1376 1377 break; 1378 } 1379 case DIGIT: 1380 { 1381 digit = LT(1); 1382 match(DIGIT); 1383 1384 char c = digit.getText().charAt( 0 ); 1385 value.upValue.append( c ); 1386 value.bytes.append( ( byte ) c ); 1387 1388 break; 1389 } 1390 case ALPHA: 1391 { 1392 alpha = LT(1); 1393 match(ALPHA); 1394 1395 char c = alpha.getText().charAt( 0 ); 1396 value.upValue.append( c ); 1397 value.bytes.append( ( byte ) c ); 1398 1399 break; 1400 } 1401 case SHARP: 1402 { 1403 match(SHARP); 1404 1405 value.upValue.append( '#' ); 1406 value.bytes.append( '#' ); 1407 1408 break; 1409 } 1410 case SPACE: 1411 { 1412 match(SPACE); 1413 1414 value.upValue.append( ' ' ); 1415 value.bytes.append( ' ' ); 1416 1417 break; 1418 } 1419 case HEXVALUE: 1420 { 1421 hex = LT(1); 1422 match(HEXVALUE); 1423 1424 String hexStr = hex.getText(); 1425 value.upValue.append( '#' ).append( hexStr ); 1426 value.bytes.append( '#' ); 1427 value.bytes.append( Strings.getBytesUtf8( hexStr ) ); 1428 1429 break; 1430 } 1431 case NUMERICOID: 1432 { 1433 numericoid = LT(1); 1434 match(NUMERICOID); 1435 1436 String number = numericoid.getText(); 1437 value.upValue.append( number ); 1438 value.bytes.append( Strings.getBytesUtf8( number ) ); 1439 1440 break; 1441 } 1442 default: 1443 { 1444 throw new NoViableAltException(LT(1), getFilename()); 1445 } 1446 } 1447 } 1448 1449/** 1450 * RFC 4514 Section 3 1451 * 1452 * <pre> 1453 * special = escaped / SPACE / SHARP / EQUALS 1454 * escaped = DQUOTE / PLUS / COMMA / SEMI / LANGLE / RANGLE 1455 * </pre> 1456 * 1457 * @return The special char 1458 * @throws RecognitionException If the token is invalid 1459 * @throws TokenStreamException When we weren't able to fetch a token 1460 */ 1461 public final char special() throws RecognitionException, TokenStreamException { 1462 char special; 1463 1464 1465 matchedProduction( "()" ); 1466 1467 1468 { 1469 switch ( LA(1)) { 1470 case DQUOTE: 1471 { 1472 match(DQUOTE); 1473 special = '"'; 1474 break; 1475 } 1476 case PLUS: 1477 { 1478 match(PLUS); 1479 special = '+'; 1480 break; 1481 } 1482 case COMMA: 1483 { 1484 match(COMMA); 1485 special = ','; 1486 break; 1487 } 1488 case SEMI: 1489 { 1490 match(SEMI); 1491 special = ';'; 1492 break; 1493 } 1494 case LANGLE: 1495 { 1496 match(LANGLE); 1497 special = '<'; 1498 break; 1499 } 1500 case RANGLE: 1501 { 1502 match(RANGLE); 1503 special = '>'; 1504 break; 1505 } 1506 case SPACE: 1507 { 1508 match(SPACE); 1509 special = ' '; 1510 break; 1511 } 1512 case SHARP: 1513 { 1514 match(SHARP); 1515 special = '#'; 1516 break; 1517 } 1518 case EQUALS: 1519 { 1520 match(EQUALS); 1521 special = '='; 1522 break; 1523 } 1524 default: 1525 { 1526 throw new NoViableAltException(LT(1), getFilename()); 1527 } 1528 } 1529 } 1530 return special; 1531 } 1532 1533 1534 public static final String[] _tokenNames = { 1535 "<0>", 1536 "EOF", 1537 "<2>", 1538 "NULL_TREE_LOOKAHEAD", 1539 "COMMA", 1540 "EQUALS", 1541 "PLUS", 1542 "HYPHEN", 1543 "UNDERSCORE", 1544 "DQUOTE", 1545 "SEMI", 1546 "LANGLE", 1547 "RANGLE", 1548 "SPACE", 1549 "NUMERICOID_OR_ALPHA_OR_DIGIT", 1550 "NUMERICOID", 1551 "DOT", 1552 "NUMBER", 1553 "LDIGIT", 1554 "DIGIT", 1555 "ALPHA", 1556 "HEXPAIR_OR_ESCESC_ESCSHARP_OR_ESC", 1557 "HEXPAIR", 1558 "ESC", 1559 "ESCESC", 1560 "ESCSHARP", 1561 "HEX", 1562 "HEXVALUE_OR_SHARP", 1563 "HEXVALUE", 1564 "SHARP", 1565 "UTFMB", 1566 "CHAR_REST" 1567 }; 1568 1569 private static final long[] mk_tokenSet_0() { 1570 long[] data = { 3554191346L, 0L}; 1571 return data; 1572 } 1573 public static final BitSet _tokenSet_0 = new BitSet(mk_tokenSet_0()); 1574 private static final long[] mk_tokenSet_1() { 1575 long[] data = { 4294967282L, 0L, 0L, 0L}; 1576 return data; 1577 } 1578 public static final BitSet _tokenSet_1 = new BitSet(mk_tokenSet_1()); 1579 private static final long[] mk_tokenSet_2() { 1580 long[] data = { 4232052208L, 0L, 0L, 0L}; 1581 return data; 1582 } 1583 public static final BitSet _tokenSet_2 = new BitSet(mk_tokenSet_2()); 1584 private static final long[] mk_tokenSet_3() { 1585 long[] data = { 2954404256L, 0L}; 1586 return data; 1587 } 1588 public static final BitSet _tokenSet_3 = new BitSet(mk_tokenSet_3()); 1589 private static final long[] mk_tokenSet_4() { 1590 long[] data = { 4091061746L, 0L}; 1591 return data; 1592 } 1593 public static final BitSet _tokenSet_4 = new BitSet(mk_tokenSet_4()); 1594 private static final long[] mk_tokenSet_5() { 1595 long[] data = { 4091068402L, 0L}; 1596 return data; 1597 } 1598 public static final BitSet _tokenSet_5 = new BitSet(mk_tokenSet_5()); 1599 1600 }