KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > core > model > ldif > parser > LdifScanner


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.browser.core.model.ldif.parser;
22
23
24 import java.io.EOFException JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.io.Reader JavaDoc;
27
28
29 // RFC 2849
30
//
31
// ldif-file = ldif-content / ldif-changes
32
// ldif-content = version-spec 1*(1*SEP ldif-attrval-record)
33
// ldif-changes = version-spec 1*(1*SEP ldif-change-record)
34
// ldif-attrval-record = dn-spec SEP 1*attrval-spec
35
// ldif-change-record = dn-spec SEP *control changerecord
36
// version-spec = "version:" FILL version-number
37
// version-number = 1*DIGIT
38
// ; version-number MUST be "1" for the
39
// ; LDIF format described in this document.
40
// dn-spec = "dn:" (FILL distinguishedName /
41
// ":" FILL base64-distinguishedName)
42
// distinguishedName = SAFE-STRING
43
// ; a distinguished name, as defined in [3]
44
// base64-distinguishedName = BASE64-UTF8-STRING
45
// ; a distinguishedName which has been base64
46
// ; encoded (see note 10, below)
47
// rdn = SAFE-STRING
48
// ; a relative distinguished name, defined as
49
// ; <name-component> in [3]
50
// base64-rdn = BASE64-UTF8-STRING
51
// ; an rdn which has been base64 encoded (see
52
// ; note 10, below)
53
// control = "control:" FILL ldap-oid ; controlType
54
// 0*1(1*SPACE ("true" / "false")) ; criticality
55
// 0*1(value-spec) ; controlValue
56
// SEP
57
// ; (See note 9, below)
58
// ldap-oid = 1*DIGIT 0*1("." 1*DIGIT)
59
// ; An LDAPOID, as defined in [4]
60
// attrval-spec = AttributeDescription value-spec SEP
61
// value-spec = ":" ( FILL 0*1(SAFE-STRING) /
62
// ":" FILL (BASE64-STRING) /
63
// "<" FILL url)
64
// ; See notes 7 and 8, below
65
// url = <a Uniform Resource Locator,
66
// as defined in [6]>
67
// ; (See Note 6, below)
68
// AttributeDescription = AttributeType [";" options]
69
// ; Definition taken from [4]
70
// AttributeType = ldap-oid / (ALPHA *(attr-type-chars))
71
// options = option / (option ";" options)
72
// option = 1*opt-char
73
// attr-type-chars = ALPHA / DIGIT / "-"
74
// opt-char = attr-type-chars
75
// changerecord = "changetype:" FILL
76
// (change-add / change-delete /
77
// change-modify / change-moddn)
78
// change-add = "add" SEP 1*attrval-spec
79
// change-delete = "delete" SEP
80
// change-moddn = ("modrdn" / "moddn") SEP
81
// "newrdn:" ( FILL rdn /
82
// ":" FILL base64-rdn) SEP
83
// "deleteoldrdn:" FILL ("0" / "1") SEP
84
// 0*1("newsuperior:"
85
// ( FILL distinguishedName /
86
// ":" FILL base64-distinguishedName) SEP)
87
// change-modify = "modify" SEP *mod-spec
88
// mod-spec = ("add:" / "delete:" / "replace:")
89
// FILL AttributeDescription SEP
90
// *attrval-spec
91
// "-" SEP
92
// SPACE = %x20
93
// ; ASCII SP, space
94
// FILL = *SPACE
95
// SEP = (CR LF / LF)
96
// CR = %x0D
97
// ; ASCII CR, carriage return
98
// LF = %x0A
99
// ; ASCII LF, line feed
100
// ALPHA = %x41-5A / %x61-7A
101
// ; A-Z / a-z
102
// DIGIT = %x30-39
103
// ; 0-9
104
// UTF8-1 = %x80-BF
105
// UTF8-2 = %xC0-DF UTF8-1
106
// UTF8-3 = %xE0-EF 2UTF8-1
107
// UTF8-4 = %xF0-F7 3UTF8-1
108
// UTF8-5 = %xF8-FB 4UTF8-1
109
// UTF8-6 = %xFC-FD 5UTF8-1
110
// SAFE-CHAR = %x01-09 / %x0B-0C / %x0E-7F
111
// ; any value <= 127 decimal except NUL, LF,
112
// ; and CR
113
// SAFE-INIT-CHAR = %x01-09 / %x0B-0C / %x0E-1F /
114
// %x21-39 / %x3B / %x3D-7F
115
// ; any value <= 127 except NUL, LF, CR,
116
// ; SPACE, colon (":", ASCII 58 decimal)
117
// ; and less-than ("<" , ASCII 60 decimal)
118
// SAFE-STRING = [SAFE-INIT-CHAR *SAFE-CHAR]
119
// UTF8-CHAR = SAFE-CHAR / UTF8-2 / UTF8-3 /
120
// UTF8-4 / UTF8-5 / UTF8-6
121
// UTF8-STRING = *UTF8-CHAR
122
// BASE64-UTF8-STRING = BASE64-STRING
123
// ; MUST be the base64 encoding of a
124
// ; UTF8-STRING
125
// BASE64-CHAR = %x2B / %x2F / %x30-39 / %x3D / %x41-5A /
126
// %x61-7A
127
// ; +, /, 0-9, =, A-Z, and a-z
128
// ; as specified in [5]
129
// BASE64-STRING = [*(BASE64-CHAR)]
130

131 public class LdifScanner
132 {
133
134     private Reader JavaDoc ldifReader;
135
136     private char[] buffer = new char[256];
137
138     private StringBuffer JavaDoc ldifBuffer;
139
140     private int ldifBufferOffset;
141
142     private int pos;
143
144
145     public LdifScanner()
146     {
147         super();
148     }
149
150
151     public void setLdif( Reader JavaDoc ldifReader )
152     {
153         // this.ldif = ldif;
154
this.ldifReader = ldifReader;
155         this.pos = -1;
156
157         this.ldifBuffer = new StringBuffer JavaDoc();
158         this.ldifBufferOffset = 0;
159     }
160
161
162     char currentChar() throws EOFException JavaDoc
163     {
164
165         // check and fill buffer
166
try
167         {
168             int num = 0;
169             while ( ldifBufferOffset + ldifBuffer.length() <= pos && num > -1 )
170             {
171                 num = this.ldifReader.read( buffer );
172                 if ( num > -1 )
173                 {
174                     ldifBuffer.append( buffer, 0, num );
175                 }
176             }
177         }
178         catch ( IOException JavaDoc e )
179         {
180         }
181
182         if ( 0 <= pos && pos < ldifBufferOffset + ldifBuffer.length() )
183         {
184             try
185             {
186                 return ldifBuffer.charAt( pos - ldifBufferOffset );
187             }
188             catch ( RuntimeException JavaDoc e )
189             {
190                 e.printStackTrace();
191                 throw e;
192             }
193         }
194         else
195         {
196             throw new EOFException JavaDoc();
197         }
198
199         // return 0<=pos&&pos<ldif.length() ? ldif.charAt(pos) : '\u0000';
200
}
201
202
203     void addFolding( StringBuffer JavaDoc sb )
204     {
205
206         int oldPos = pos;
207
208         try
209         {
210             pos++;
211             char c = currentChar();
212             if ( c == '\n' || c == '\r' )
213             {
214                 StringBuffer JavaDoc temp = new StringBuffer JavaDoc( 3 );
215                 temp.append( c );
216                 if ( c == '\r' )
217                 {
218                     pos++;
219                     c = currentChar();
220                     if ( c == '\n' )
221                     {
222                         temp.append( c );
223                     }
224                     else
225                     {
226                         pos--;
227                     }
228                 }
229                 else if ( c == '\n' )
230                 {
231                     pos++;
232                     c = currentChar();
233                     if ( c == '\r' )
234                     {
235                         temp.append( c );
236                     }
237                     else
238                     {
239                         pos--;
240                     }
241                 }
242
243                 pos++;
244                 c = currentChar();
245                 if ( c == ' ' )
246                 {
247                     // space after newline, continue
248
temp.append( c );
249                     sb.append( temp );
250                 }
251                 else
252                 {
253                     for ( int i = 0; i < temp.length(); i++ )
254                     {
255                         pos--;
256                     }
257                     pos--;
258                 }
259             }
260             else
261             {
262                 pos--;
263             }
264         }
265         catch ( EOFException JavaDoc e )
266         {
267             // reset position
268
pos = oldPos;
269         }
270
271     }
272
273
274     /**
275      * Reads the next character from input stram if available. If read was
276      * possible the character is appended to the given StringBuffer and
277      * returned. Otherwise throws a EOFException. Additionally this method
278      * checks folding sequence SEP + SPACE. If any folding sequence was
279      * found the sequence is appended to the given StringBuffer. So it is
280      * possible the StringBuffer doesn't end with the read character after
281      * calling this method but with a folding sequence
282      *
283      * @param sb
284      * @return the next character if available
285      * @throws EOFException
286      */

287     public char read( StringBuffer JavaDoc sb ) throws EOFException JavaDoc
288     {
289         try
290         {
291
292             // check EOF
293
// if(pos > -1) {
294
// currentChar();
295
// }
296

297             // get next char
298
pos++;
299             char c = currentChar();
300             sb.append( c );
301
302             // folding
303
addFolding( sb );
304
305             return c;
306         }
307         catch ( EOFException JavaDoc e )
308         {
309             pos--;
310             throw e;
311         }
312     }
313
314
315     void removeFolding( StringBuffer JavaDoc sb )
316     {
317
318         int oldPos = pos;
319
320         try
321         {
322             char c = currentChar();
323             pos--;
324             if ( c == ' ' )
325             {
326                 StringBuffer JavaDoc temp = new StringBuffer JavaDoc();
327                 temp.insert( 0, c );
328                 c = currentChar();
329                 pos--;
330
331                 if ( c == '\n' || c == '\r' )
332                 {
333                     if ( c == '\r' )
334                     {
335                         temp.insert( 0, c );
336                         c = currentChar();
337                         pos--;
338                         if ( c == '\n' )
339                         {
340                             temp.insert( 0, c );
341                         }
342                         else
343                         {
344                             pos++;
345                         }
346                     }
347                     else if ( c == '\n' )
348                     {
349                         temp.insert( 0, c );
350                         c = currentChar();
351                         pos--;
352                         if ( c == '\r' )
353                         {
354                             temp.insert( 0, c );
355                         }
356                         else
357                         {
358                             pos++;
359                         }
360                     }
361
362                     sb.delete( sb.length() - temp.length(), sb.length() );
363                 }
364                 else
365                 {
366                     pos++;
367                     pos++;
368                 }
369             }
370             else
371             {
372                 pos++;
373             }
374         }
375         catch ( EOFException JavaDoc e )
376         {
377             // reset position
378
pos = oldPos;
379         }
380     }
381
382
383     /**
384      * Inverses the previous read().
385      *
386      * @param sb
387      * @return the previous character if available
388      * @throws EOFException
389      */

390     public void unread( StringBuffer JavaDoc sb )
391     {
392         removeFolding( sb );
393
394         if ( pos > -1 )
395         {
396             pos--;
397
398             if ( sb.length() > 0 )
399             {
400                 sb.deleteCharAt( sb.length() - 1 );
401             }
402         }
403     }
404
405
406     private String JavaDoc getFullLine( String JavaDoc start )
407     {
408         String JavaDoc s1 = this.getWord( start );
409         if ( s1 != null )
410         {
411             String JavaDoc s2 = getContent();
412             return s2 != null ? s1 + s2 : s1;
413         }
414         else
415         {
416             return null;
417         }
418     }
419
420
421     private String JavaDoc getContent()
422     {
423
424         StringBuffer JavaDoc sb = new StringBuffer JavaDoc( 256 );
425
426         try
427         {
428             char c = '\u0000';
429             while ( c != '\n' && c != '\r' )
430             {
431                 c = read( sb );
432             }
433             unread( sb );
434
435         }
436         catch ( EOFException JavaDoc e )
437         {
438         }
439
440         return sb.length() > 0 ? sb.toString() : null;
441     }
442
443
444     // private String getStartAndFill(String start) {
445
// String s = this.getWord(start);
446
// if(s != null) {
447
// StringBuffer sb = new StringBuffer(s);
448
//
449
// try {
450
// char c = '\u0000';
451
// while (c==' ') {
452
// c = read(sb);
453
// }
454
// unread(sb);
455
// } catch (EOFException e) {
456
// }
457
//
458
// return sb.toString();
459
// }
460
// else {
461
// return null;
462
// }
463
// }
464

465     private String JavaDoc getWord( String JavaDoc word )
466     {
467         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
468
469         // read
470
try
471         {
472             boolean matches = true;
473             for ( int i = 0; i < word.length(); i++ )
474             {
475
476                 char c = read( sb );
477                 if ( c != word.charAt( i ) )
478                 {
479                     matches = false;
480                     unread( sb );
481                     break;
482                 }
483             }
484
485             if ( matches )
486             {
487                 return sb.toString();
488             }
489         }
490         catch ( EOFException JavaDoc e )
491         {
492         }
493
494         // unread
495
while ( sb.length() > 0 )
496         {
497             unread( sb );
498         }
499         // prevChar(sb);
500
return null;
501     }
502
503
504     private String JavaDoc getWordTillColon( String JavaDoc word )
505     {
506
507         String JavaDoc wordWithColon = word + ":";
508         String JavaDoc line = getWord( wordWithColon );
509         if ( line != null )
510         {
511             StringBuffer JavaDoc sb = new StringBuffer JavaDoc( line );
512             unread( sb );
513             return sb.toString();
514         }
515
516         // allow eof and sep
517
line = getWord( word );
518         if ( line != null )
519         {
520             StringBuffer JavaDoc sb = new StringBuffer JavaDoc( line );
521             try
522             {
523                 char c = read( sb );
524                 unread( sb );
525                 if ( c == '\r' || c == '\n' )
526                 {
527                     return sb.toString();
528                 }
529                 else
530                 {
531                     while ( sb.length() > 0 )
532                     {
533                         unread( sb );
534                     }
535                     return null;
536                 }
537             }
538             catch ( EOFException JavaDoc e )
539             {
540                 return sb.toString();
541             }
542         }
543
544         return null;
545     }
546
547
548     private void flushBuffer()
549     {
550
551         // System.out.println("flushBuffer():
552
// before("+this.pos+","+this.ldifBufferOffset+")");
553

554         if ( this.ldifBufferOffset < this.pos && this.ldifBuffer.length() > 0 )
555         {
556             int delta = Math.min( pos - this.ldifBufferOffset, this.ldifBuffer.length() );
557             delta--;
558             this.ldifBuffer.delete( 0, delta );
559             this.ldifBufferOffset += delta;
560         }
561
562         // System.out.println("flushBuffer():
563
// after("+this.pos+","+this.ldifBufferOffset+")");
564
}
565
566
567     public LdifToken matchCleanupLine()
568     {
569         this.flushBuffer();
570
571         String JavaDoc line = getContent();
572         LdifToken sep = matchSep();
573
574         if ( line != null || sep != null )
575         {
576             if ( line == null )
577                 line = "";
578
579             if ( sep != null )
580                 line += sep.getValue();
581
582             return new LdifToken( LdifToken.UNKNOWN, line, pos - line.length() + 1 );
583         }
584
585         return null;
586     }
587
588
589     public LdifToken matchOther()
590     {
591         this.flushBuffer();
592
593         String JavaDoc line = getContent();
594         if ( line != null )
595         {
596             LdifToken sep = matchSep();
597             if ( sep != null )
598                 line += sep.getValue();
599             return new LdifToken( LdifToken.UNKNOWN, line, pos - line.length() + 1 );
600         }
601
602         return null;
603     }
604
605
606     public LdifToken matchEOF()
607     {
608         this.flushBuffer();
609
610         StringBuffer JavaDoc sb = new StringBuffer JavaDoc( 1 );
611         try
612         {
613             read( sb );
614             unread( sb );
615             return null;
616         }
617         catch ( EOFException JavaDoc e )
618         {
619             return new LdifToken( LdifToken.EOF, "", pos + 1 );
620         }
621
622     }
623
624
625     public LdifToken matchSep()
626     {
627         this.flushBuffer();
628
629         try
630         {
631             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
632             char c = read( sb );
633             if ( c == '\n' || c == '\r' )
634             {
635
636                 // check for two-char-linebreak
637
try
638                 {
639                     if ( c == '\r' )
640                     {
641                         c = read( sb );
642                         if ( c != '\n' )
643                         {
644                             unread( sb );
645                         }
646                     }
647                     else if ( c == '\n' )
648                     {
649                         c = read( sb );
650                         if ( c != '\r' )
651                         {
652                             unread( sb );
653                         }
654                     }
655                 }
656                 catch ( EOFException JavaDoc e )
657                 {
658                 }
659
660                 return new LdifToken( LdifToken.SEP, sb.toString(), pos - sb.length() + 1 );
661             }
662             else
663             {
664                 unread( sb );
665             }
666         }
667         catch ( EOFException JavaDoc e )
668         {
669         }
670
671         return null;
672     }
673
674
675     public LdifToken matchComment()
676     {
677         this.flushBuffer();
678
679         String JavaDoc line = getFullLine( "#" );
680         if ( line != null )
681         {
682             return new LdifToken( LdifToken.COMMENT, line, pos - line.length() + 1 );
683         }
684
685         return null;
686     }
687
688
689     public LdifToken matchVersionSpec()
690     {
691         this.flushBuffer();
692
693         String JavaDoc line = getWordTillColon( "version" );
694         if ( line != null )
695         {
696             return new LdifToken( LdifToken.VERSION_SPEC, line, pos - line.length() + 1 );
697         }
698
699         return null;
700     }
701
702
703     public LdifToken matchDnSpec()
704     {
705         this.flushBuffer();
706
707         String JavaDoc line = getWordTillColon( "dn" );
708         if ( line != null )
709         {
710             return new LdifToken( LdifToken.DN_SPEC, line, pos - line.length() + 1 );
711         }
712
713         return null;
714     }
715
716
717     public LdifToken matchControlSpec()
718     {
719         this.flushBuffer();
720
721         String JavaDoc line = getWordTillColon( "control" );
722         if ( line != null )
723         {
724             return new LdifToken( LdifToken.CONTROL_SPEC, line, pos - line.length() + 1 );
725         }
726
727         return null;
728     }
729
730
731     public LdifToken matchChangeTypeSpec()
732     {
733         this.flushBuffer();
734
735         String JavaDoc line = getWordTillColon( "changetype" );
736         if ( line != null )
737         {
738             return new LdifToken( LdifToken.CHANGETYPE_SPEC, line, pos - line.length() + 1 );
739         }
740
741         return null;
742     }
743
744
745     public LdifToken matchChangeType()
746     {
747         this.flushBuffer();
748
749         String JavaDoc line = getWord( "add" );
750         if ( line != null )
751         {
752             return new LdifToken( LdifToken.CHANGETYPE_ADD, line, pos - line.length() + 1 );
753         }
754         line = getWord( "modify" );
755         if ( line != null )
756         {
757             return new LdifToken( LdifToken.CHANGETYPE_MODIFY, line, pos - line.length() + 1 );
758         }
759         line = getWord( "delete" );
760         if ( line != null )
761         {
762             return new LdifToken( LdifToken.CHANGETYPE_DELETE, line, pos - line.length() + 1 );
763         }
764         line = getWord( "moddn" );
765         if ( line != null )
766         {
767             return new LdifToken( LdifToken.CHANGETYPE_MODDN, line, pos - line.length() + 1 );
768         }
769         line = getWord( "modrdn" );
770         if ( line != null )
771         {
772             return new LdifToken( LdifToken.CHANGETYPE_MODDN, line, pos - line.length() + 1 );
773         }
774
775         return null;
776     }
777
778
779     public LdifToken matchCriticality()
780     {
781         this.flushBuffer();
782
783         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
784
785         String JavaDoc s = getWord( " " );
786         while ( s != null )
787         {
788             sb.append( s );
789             s = getWord( " " );
790         }
791
792         String JavaDoc t = getWord( "true" );
793         if ( t != null )
794         {
795             sb.append( t );
796             return new LdifToken( LdifToken.CONTROL_CRITICALITY_TRUE, sb.toString(), pos - sb.length() + 1 );
797         }
798         String JavaDoc f = getWord( "false" );
799         if ( f != null )
800         {
801             sb.append( f );
802             return new LdifToken( LdifToken.CONTROL_CRITICALITY_FALSE, sb.toString(), pos - sb.length() + 1 );
803         }
804
805         while ( sb.length() > 0 )
806         {
807             unread( sb );
808         }
809
810         // for(int i=0; i<sb.length(); i++) {
811
// unread(sb);
812
// }
813

814         return null;
815     }
816
817
818     public LdifToken matchNumber()
819     {
820         this.flushBuffer();
821
822         try
823         {
824             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
825             char c = read( sb );
826             if ( '0' <= c && c <= '9' )
827             {
828
829                 try
830                 {
831                     while ( '0' <= c && c <= '9' )
832                     {
833                         c = read( sb );
834                     }
835                     unread( sb );
836                 }
837                 catch ( EOFException JavaDoc e )
838                 {
839                 }
840
841                 return new LdifToken( LdifToken.NUMBER, sb.toString(), pos - sb.length() + 1 );
842             }
843             else
844             {
845                 unread( sb );
846             }
847         }
848         catch ( EOFException JavaDoc e )
849         {
850         }
851
852         return null;
853     }
854
855
856     public LdifToken matchOid()
857     {
858         this.flushBuffer();
859
860         try
861         {
862             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
863             char c = read( sb );
864             if ( '0' <= c && c <= '9' )
865             {
866
867                 try
868                 {
869                     while ( '0' <= c && c <= '9' || c == '.' )
870                     {
871                         c = read( sb );
872                     }
873                     unread( sb );
874                 }
875                 catch ( EOFException JavaDoc e )
876                 {
877                 }
878
879                 return new LdifToken( LdifToken.OID, sb.toString(), pos - sb.length() + 1 );
880             }
881             else
882             {
883                 unread( sb );
884             }
885         }
886         catch ( EOFException JavaDoc e )
887         {
888         }
889
890         return null;
891     }
892
893
894     public LdifToken matchAttributeDescription()
895     {
896         this.flushBuffer();
897
898         try
899         {
900             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
901             char c = read( sb );
902             if ( 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || '0' <= c && c <= '9' )
903             {
904
905                 try
906                 {
907                     while ( 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || '0' <= c && c <= '9' || c == '.'
908                         || c == ';' || c == '-' )
909                     {
910                         c = read( sb );
911                     }
912                     unread( sb );
913                 }
914                 catch ( EOFException JavaDoc e )
915                 {
916                 }
917
918                 return new LdifToken( LdifToken.ATTRIBUTE, sb.toString(), pos - sb.length() + 1 );
919             }
920             else
921             {
922                 unread( sb );
923             }
924         }
925         catch ( EOFException JavaDoc e )
926         {
927         }
928
929         // // a-z,A-Z,0-9,.,-,;
930
// StringBuffer sb = new StringBuffer();
931
// char c = nextChar(sb);
932
// if('a'<=c&&c<='z' || 'A'<=c&&c<='Z' || '0'<=c&&c<='9') {
933
// while('a'<=c&&c<='z' || 'A'<=c&&c<='Z' || '0'<=c&&c<='9' || c=='.' ||
934
// c==';' || c=='-') {
935
// sb.append(c);
936
// c = nextChar(sb);
937
// }
938
// unread(sb);
939
//
940
// return new LdifToken(LdifToken.ATTRIBUTE, sb.toString(),
941
// pos-sb.length()+1);
942
// }
943
// else {
944
// unread(sb);
945
// }
946

947         return null;
948     }
949
950
951     public LdifToken matchModTypeSpec()
952     {
953         this.flushBuffer();
954
955         String JavaDoc line = getWord( "add" );
956         if ( line != null )
957         {
958             return new LdifToken( LdifToken.MODTYPE_ADD_SPEC, line, pos - line.length() + 1 );
959         }
960         line = getWord( "replace" );
961         if ( line != null )
962         {
963             return new LdifToken( LdifToken.MODTYPE_REPLACE_SPEC, line, pos - line.length() + 1 );
964         }
965         line = getWord( "delete" );
966         if ( line != null )
967         {
968             return new LdifToken( LdifToken.MODTYPE_DELETE_SPEC, line, pos - line.length() + 1 );
969         }
970
971         return null;
972     }
973
974
975     public LdifToken matchModSep()
976     {
977         this.flushBuffer();
978
979         String JavaDoc line = getWord( "-" );
980         if ( line != null )
981         {
982             return new LdifToken( LdifToken.MODTYPE_SEP, line, pos - line.length() + 1 );
983         }
984
985         return null;
986     }
987
988
989     public LdifToken matchValueType()
990     {
991         this.flushBuffer();
992
993         try
994         {
995             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
996             char c = read( sb );
997             if ( c == ':' )
998             {
999
1000                int tokenType = LdifToken.VALUE_TYPE_SAFE;
1001                try
1002                {
1003                    c = read( sb );
1004                    if ( c == ':' )
1005                    {
1006                        tokenType = LdifToken.VALUE_TYPE_BASE64;
1007                    }
1008                    else if ( c == '<' )
1009                    {
1010                        tokenType = LdifToken.VALUE_TYPE_URL;
1011                    }
1012                    else
1013                    {
1014                        tokenType = LdifToken.VALUE_TYPE_SAFE;
1015                        unread( sb );
1016                    }
1017
1018                    c = read( sb );
1019                    while ( c == ' ' )
1020                    {
1021                        c = read( sb );
1022                    }
1023                    unread( sb );
1024
1025                }
1026                catch ( EOFException JavaDoc e )
1027                {
1028                }
1029
1030                return new LdifToken( tokenType, sb.toString(), pos - sb.length() + 1 );
1031            }
1032            else
1033            {
1034                unread( sb );
1035            }
1036        }
1037        catch ( EOFException JavaDoc e )
1038        {
1039        }
1040
1041        return null;
1042    }
1043
1044
1045    public LdifToken matchValue()
1046    {
1047        this.flushBuffer();
1048
1049        String JavaDoc line = getContent();
1050        if ( line != null )
1051        {
1052            return new LdifToken( LdifToken.VALUE, line, pos - line.length() + 1 );
1053        }
1054
1055        return null;
1056    }
1057
1058
1059    public LdifToken matchNewrdnSpec()
1060    {
1061        this.flushBuffer();
1062
1063        String JavaDoc line = getWordTillColon( "newrdn" );
1064        if ( line != null )
1065        {
1066            return new LdifToken( LdifToken.MODDN_NEWRDN_SPEC, line, pos - line.length() + 1 );
1067        }
1068
1069        return null;
1070    }
1071
1072
1073    public LdifToken matchDeleteoldrdnSpec()
1074    {
1075        this.flushBuffer();
1076
1077        String JavaDoc line = getWordTillColon( "deleteoldrdn" );
1078        if ( line != null )
1079        {
1080            return new LdifToken( LdifToken.MODDN_DELOLDRDN_SPEC, line, pos - line.length() + 1 );
1081        }
1082
1083        return null;
1084    }
1085
1086
1087    public LdifToken matchNewsuperiorSpec()
1088    {
1089        this.flushBuffer();
1090
1091        String JavaDoc line = getWordTillColon( "newsuperior" );
1092        if ( line != null )
1093        {
1094            return new LdifToken( LdifToken.MODDN_NEWSUPERIOR_SPEC, line, pos - line.length() + 1 );
1095        }
1096
1097        return null;
1098    }
1099
1100}
1101
Popular Tags