summaryrefslogtreecommitdiff
path: root/plugins/svn4idea/src/org/jetbrains/idea/svn/info/SvnInfoHandler.java
blob: e2e5fa910e389b590b4559c9f97fcc58c247e611 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
/*
 * Copyright 2000-2012 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jetbrains.idea.svn.info;

import com.intellij.openapi.util.Getter;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.Consumer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.svn.SvnUtil;
import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNNodeKind;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.internal.util.SVNDate;
import org.tmatesoft.svn.core.wc.SVNInfo;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import java.io.File;
import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * User: Irina.Chernushina
 * Date: 1/27/12
 * Time: 1:00 PM
 */
public class SvnInfoHandler extends DefaultHandler {
  @Nullable private final File myBase;
  private final Consumer<SVNInfo> myInfoConsumer;
  private Map<File, SVNInfo> myResultsMap;
  private SvnInfoStructure myPending;
  private final Map<String, Getter<ElementHandlerBase>> myElementsMap;
  private final List<ElementHandlerBase> myParseStack;
  private final StringBuilder mySb;

  public SvnInfoHandler(@Nullable File base, final Consumer<SVNInfo> infoConsumer) {
    myBase = base;
    myInfoConsumer = infoConsumer;
    myPending = createPending();
    myElementsMap = new HashMap<String, Getter<ElementHandlerBase>>();
    fillElements();
    myParseStack = new ArrayList<ElementHandlerBase>();
    myParseStack.add(new Fake());
    myResultsMap = new HashMap<File, SVNInfo>();
    mySb = new StringBuilder();
  }

  private void switchPending() throws SAXException {
    final SVNInfo info;
    try {
      info = myPending.convert();
    }
    catch (SVNException e) {
      throw new SAXException(e);
    }
    if (myInfoConsumer != null) {
      myInfoConsumer.consume(info);
    }
    myResultsMap.put(info.getFile(), info);
    myPending = createPending();
  }

  private SvnInfoStructure createPending() {
    SvnInfoStructure pending = new SvnInfoStructure();
    pending.myDepth = SVNDepth.INFINITY;

    return pending;
  }

  @Override
  public void endDocument() throws SAXException {
    assertSAX(! myParseStack.isEmpty());
    for (int i = myParseStack.size() - 1; i >= 0; -- i) {
      ElementHandlerBase current = myParseStack.get(i);
      if (current instanceof Entry) {
        switchPending();
        break;
      }
    }
    myParseStack.clear();
  }

  @Override
  public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    assertSAX(! myParseStack.isEmpty());
    ElementHandlerBase current = myParseStack.get(myParseStack.size() - 1);

    while (true) {
      final boolean createNewChild = current.startElement(uri, localName, qName, attributes);
      if (createNewChild) {
        assertSAX(myElementsMap.containsKey(qName));
        final ElementHandlerBase newChild = myElementsMap.get(qName).get();
        newChild.setParent(current);
        newChild.updateInfo(attributes, myPending);
        myParseStack.add(newChild);
        return;
      } else {
        // go up
        if (current instanceof Entry) {
          switchPending();
        }
        myParseStack.remove(myParseStack.size() - 1);
        assertSAX(! myParseStack.isEmpty());
        current = myParseStack.get(myParseStack.size() - 1);
      }
    }
  }

  @Override
  public void endElement(String uri, String localName, String qName) throws SAXException {
    ElementHandlerBase current = myParseStack.get(myParseStack.size() - 1);
    String value = mySb.toString().trim();

    if (!StringUtil.isEmpty(value)) {
      current.characters(value, myPending);
    }

    mySb.setLength(0);
  }

  @Override
  public void characters(char[] ch, int start, int length) throws SAXException {
    assertSAX(! myParseStack.isEmpty());
    mySb.append(ch, start, length);
  }

  public Map<String, Getter<ElementHandlerBase>> getElementsMap() {
    return myElementsMap;
  }

  private void fillElements() {
    myElementsMap.put("copy-from-url", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new CopyFromUrl();
      }
    });
    myElementsMap.put("copy-from-rev", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new CopyFromRev();
      }
    });
    myElementsMap.put("changelist", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new ChangeList();
      }
    });
    myElementsMap.put("author", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new Author();
      }
    });
    myElementsMap.put("checksum", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new Checksum();
      }
    });
    myElementsMap.put("commit", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new Commit();
      }
    });
    myElementsMap.put("conflict", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new Conflict();
      }
    });
    myElementsMap.put("cur-base-file", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new CurBase();
      }
    });
    myElementsMap.put("date", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new Date();
      }
    });
    myElementsMap.put("depth", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new Depth();
      }
    });
    myElementsMap.put("entry", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new Entry(myBase);
      }
    });
    myElementsMap.put("info", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new Info();
      }
    });
    myElementsMap.put("prev-base-file", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new PrevBase();
      }
    });
    myElementsMap.put("prev-wc-file", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new PrevWc();
      }
    });
    myElementsMap.put("prop-file", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new PropFile();
      }
    });
    myElementsMap.put("repository", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new Repository();
      }
    });
    myElementsMap.put("root", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new Root();
      }
    });
    myElementsMap.put("schedule", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new Schedule();
      }
    });
    myElementsMap.put("text-updated", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new TextUpdated();
      }
    });
    myElementsMap.put("tree-conflict", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new TreeConflict();
      }
    });
    myElementsMap.put("url", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new Url();
      }
    });
    myElementsMap.put("relative-url", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new RelativeUrl();
      }
    });
    myElementsMap.put("lock", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new Lock();
      }
    });
    myElementsMap.put("token", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new LockToken();
      }
    });
    myElementsMap.put("owner", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new LockOwner();
      }
    });
    myElementsMap.put("comment", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new LockComment();
      }
    });
    myElementsMap.put("created", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new LockCreated();
      }
    });
    myElementsMap.put("uuid", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new Uuid();
      }
    });
    myElementsMap.put("version", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new Version();
      }
    });
    myElementsMap.put("wc-info", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new WcInfo();
      }
    });
    myElementsMap.put("moved-to", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new MovedPath();
      }
    });
    myElementsMap.put("moved-from", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new MovedPath();
      }
    });
    myElementsMap.put("wcroot-abspath", new Getter<ElementHandlerBase>() {
      @Override
      public ElementHandlerBase get() {
        return new WcRoot();
      }
    });
  }

  public Map<File, SVNInfo> getResultsMap() {
    return myResultsMap;
  }

  private static void assertSAX(final boolean shouldBeTrue) throws SAXException {
    if (! shouldBeTrue) {
      throw new SAXException("can not parse output");
    }
  }

  private static class Version extends ElementHandlerBase {
    private Version() {
      super(new String[]{}, new String[]{});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException {
      // TODO: Currently information for conflict (not tree-conflict) available in svn 1.8 is not used
      // TODO: And it also not suite well for SVNKit api
      if (getParent() instanceof Conflict) {
        return;
      }

      final String side = attributes.getValue("side");
      if ("source-left".equals(side)) {
        final SvnInfoStructure.ConflictVersion conflictVersion = new SvnInfoStructure.ConflictVersion();
        structure.myTreeConflict.mySourceLeft = conflictVersion;
        setConflictFields(attributes, conflictVersion);
      } else if ("source-right".equals(side)) {
        final SvnInfoStructure.ConflictVersion conflictVersion = new SvnInfoStructure.ConflictVersion();
        structure.myTreeConflict.mySourceRight = conflictVersion;
        setConflictFields(attributes, conflictVersion);
      }
    }

    private void setConflictFields(Attributes attributes, SvnInfoStructure.ConflictVersion conflictVersion) {
      conflictVersion.myKind = attributes.getValue("kind");
      conflictVersion.myPathInRepo = attributes.getValue("path-in-repos");
      conflictVersion.myRepoUrl = attributes.getValue("repos-url");
      conflictVersion.myRevision = attributes.getValue("revision");
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) throws SAXException {
    }
  }

  private static class TreeConflict extends ElementHandlerBase {
    private TreeConflict() {
      super(new String[]{}, new String[]{"version"});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException {
      final SvnInfoStructure.TreeConflictDescription d = new SvnInfoStructure.TreeConflictDescription();
      structure.myTreeConflict = d;
      final String operation = attributes.getValue("operation");
      if (! StringUtil.isEmptyOrSpaces(operation)) {
        d.myOperation = operation;
      }
      final String kind = attributes.getValue("kind");
      if (! StringUtil.isEmptyOrSpaces(kind)) {
        d.myKind = kind;
      }
      final String reason = attributes.getValue("reason");
      if (! StringUtil.isEmptyOrSpaces(reason)) {
        d.myReason = reason;
      }
      final String victim = attributes.getValue("victim");
      if (! StringUtil.isEmptyOrSpaces(victim)) {
        d.myVictim = victim;
      }
      final String action = attributes.getValue("action");
      if (! StringUtil.isEmptyOrSpaces(action)) {
        d.myAction = action;
      }
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) throws SAXException {
    }
  }
  
  private static class PropFile extends ElementHandlerBase {
    private PropFile() {
      super(new String[]{}, new String[]{});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException {
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) throws SAXException {
      // todo check whether base should be added
      structure.myPropRejectFile = s;
    }
  }
  
  private static class CurBase extends ElementHandlerBase {
    private CurBase() {
      super(new String[]{}, new String[]{});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException {
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) throws SAXException {
      structure.myConflictNew = new File(s).getName();
    }
  }

  private static class PrevWc extends ElementHandlerBase {
    private PrevWc() {
      super(new String[]{}, new String[]{});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException {
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) throws SAXException {
      structure.myConflictWorking = new File(s).getName();
    }
  }

  private static class PrevBase extends ElementHandlerBase {
    private PrevBase() {
      super(new String[]{}, new String[]{});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException {
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) throws SAXException {
      structure.myConflictOld = new File(s).getName();
    }
  }

  private static class Conflict extends ElementHandlerBase {
    private Conflict() {
      super(new String[]{"prev-base-file","prev-wc-file","cur-base-file","prop-file"}, new String[]{"version"});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException {
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) throws SAXException {
    }
  }

  private static class Date extends ElementHandlerBase {
    private Date() {
      super(new String[]{}, new String[]{});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException {
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) throws SAXException {
      final SVNDate date = SVNDate.parseDate(s);
      structure.myCommittedDate = date;
    }
  }

  private static class Author extends ElementHandlerBase {
    private Author() {
      super(new String[]{}, new String[]{});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException {
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) throws SAXException {
      structure.myAuthor = s;
    }
  }

  private static class Commit extends ElementHandlerBase {
    private Commit() {
      super(new String[]{"author","date"}, new String[]{});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException {
      final String revision = attributes.getValue("revision");
      try {
        final long number = Long.parseLong(revision);
        structure.myCommittedRevision = number;
      } catch (NumberFormatException e) {
        throw new SAXException(e);
      }
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) throws SAXException {
    }
  }

  private static class Checksum extends ElementHandlerBase {
    private Checksum() {
      super(new String[]{}, new String[]{});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException {
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) throws SAXException {
      structure.myChecksum = s;
    }
  }

  /**
   * "moved-from" and "moved-to" elements are represented by this class.
   */
  private static class MovedPath extends ElementHandlerBase {

    private MovedPath() {
      super(new String[]{}, new String[]{});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException {
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) throws SAXException {
      // TODO: is there some field to initialize from this value?
    }
  }

  private static class TextUpdated extends ElementHandlerBase {
    private TextUpdated() {
      super(new String[]{}, new String[]{});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException {
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) throws SAXException {
      final SVNDate date = SVNDate.parseDate(s);
      structure.myTextTime = date;
    }
  }

  private static class Depth extends ElementHandlerBase {
    private Depth() {
      super(new String[]{}, new String[]{});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException {
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) throws SAXException {
      structure.myDepth = SVNDepth.fromString(s);
    }
  }

  private static class Schedule extends ElementHandlerBase {
    private Schedule() {
      super(new String[]{}, new String[]{});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException {
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) throws SAXException {
      structure.mySchedule = s;
    }
  }

  private static class WcRoot extends ElementHandlerBase {
    private WcRoot() {
      super(new String[]{}, new String[]{});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException {
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) throws SAXException {
      // there is no such thing???
    }
  }
  
  private static class ChangeList extends ElementHandlerBase {
    private ChangeList() {
      super(new String[]{}, new String[]{});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException {
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) throws SAXException {
      structure.myChangelistName = s;
    }
  }

  private static class CopyFromUrl extends ElementHandlerBase {
    private CopyFromUrl() {
      super(new String[]{}, new String[]{});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException {
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) throws SAXException {
      try {
        structure.myCopyFromURL = SVNURL.parseURIEncoded(s);
      }
      catch (SVNException e) {
        throw new SAXException(e);
      }
    }
  }

  private static class CopyFromRev extends ElementHandlerBase {
    private CopyFromRev() {
      super(new String[]{}, new String[]{});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException {
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) throws SAXException {
      try {
        final long number = Long.parseLong(s);
        structure.myCopyFromRevision = number;
      } catch (NumberFormatException e) {
        throw new SAXException(e);
      }
    }
  }

  private static class WcInfo extends ElementHandlerBase {
    private WcInfo() {
      super(new String[]{"wcroot-abspath", "schedule", "depth", "text-updated", "checksum", "changelist", "copy-from-url",
      "copy-from-rev", "moved-to", "moved-from"}, new String[]{});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException {
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) throws SAXException {
    }
  }
  
  private static class Uuid extends ElementHandlerBase {
    private Uuid() {
      super(new String[]{}, new String[]{});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException {
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) throws SAXException {
      structure.myUuid = s;
    }
  }

  private static class Root extends ElementHandlerBase {
    private Root() {
      super(new String[]{}, new String[]{});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException {
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) throws SAXException {
      try {
        structure.myRootURL = SVNURL.parseURIEncoded(s);
      }
      catch (SVNException e) {
        throw new SAXException(e);
      }
    }
  }

  private static class Repository extends ElementHandlerBase {
    private Repository() {
      super(new String[]{"root", "uuid"}, new String[]{});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException {
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) throws SAXException {
    }
  }

  private static class Url extends ElementHandlerBase {
    private Url() {
      super(new String[]{}, new String[]{});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException {
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) throws SAXException {
      try {
        structure.myUrl = SVNURL.parseURIEncoded(s);
      }
      catch (SVNException e) {
        throw new SAXException(e);
      }
    }
  }

  private static class RelativeUrl extends Url{
    @Override
    public void characters(String s, SvnInfoStructure structure) throws SAXException {
      structure.relativeUrl = s;
    }
  }

  private static class Lock extends ElementHandlerBase {
    private Lock() {
      super(new String[]{"token", "owner", "comment", "created"}, new String[]{});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException {
      structure.myLockWrapper = new SVNLockWrapper();
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) throws SAXException {
    }
  }

  private static class LockToken extends ElementHandlerBase {
    private LockToken() {
      super(new String[]{}, new String[]{});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException {
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) throws SAXException {
      structure.myLockWrapper.setID(s);
    }
  }

  private static class LockOwner extends ElementHandlerBase {
    private LockOwner() {
      super(new String[]{}, new String[]{});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException {
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) throws SAXException {
      structure.myLockWrapper.setOwner(s);
    }
  }

  private static class LockComment extends ElementHandlerBase {
    private LockComment() {
      super(new String[]{}, new String[]{});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException {
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) throws SAXException {
      structure.myLockWrapper.setComment(s);
    }
  }

  private static class LockCreated extends ElementHandlerBase {
    private LockCreated() {
      super(new String[]{}, new String[]{});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException {
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) throws SAXException {
      structure.myLockWrapper.setCreationDate(SVNDate.parseDate(s));
    }
  }

  private static class Entry extends ElementHandlerBase {
    @Nullable private final File myBase;

    private Entry(@Nullable final File base) {
      super(new String[]{"url", "relative-url", "lock", "repository","wc-info","commit","conflict","tree-conflict"}, new String[]{});
      myBase = base;
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException {
      final String kind = attributes.getValue("kind");
      assertSAX(! StringUtil.isEmptyOrSpaces(kind));
      structure.myKind = SVNNodeKind.parseKind(kind);

      if (myBase != null) {
        final String path = attributes.getValue("path");
        assertSAX(!StringUtil.isEmptyOrSpaces(path));
        structure.myFile = SvnUtil.resolvePath(myBase, path);
      }

      final String revision = attributes.getValue("revision");
      assertSAX(! StringUtil.isEmptyOrSpaces(revision));
      try {
        final long number = Long.parseLong(revision);
        structure.myRevision = number;
      } catch (NumberFormatException e) {
        structure.myRevision = -1;
        //throw new SAXException(e);
      }
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) {
    }
  }

  private static class Info extends ElementHandlerBase {
    private Info() {
      super(new String[]{}, new String[]{"entry"});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) {
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) {
    }
  }

  private static class Fake extends ElementHandlerBase {
    private Fake() {
      super(new String[]{"info"}, new String[]{});
    }

    @Override
    protected void updateInfo(Attributes attributes, SvnInfoStructure structure) {
    }

    @Override
    public void characters(String s, SvnInfoStructure structure) {
    }
  }

  private abstract static class ElementHandlerBase {
    private final Set<String> myAwaitedChildren;
    private final Set<String> myAwaitedChildrenMultiple;
    private ElementHandlerBase parent;

    ElementHandlerBase(String[] awaitedChildren, String[] awaitedChildrenMultiple) {
      myAwaitedChildren = new HashSet<String>(Arrays.asList(awaitedChildren));
      myAwaitedChildrenMultiple = new HashSet<String>(Arrays.asList(awaitedChildrenMultiple));
    }

    @NotNull
    public ElementHandlerBase getParent() {
      return parent;
    }

    public void setParent(@NotNull ElementHandlerBase parent) {
      this.parent = parent;
    }

    protected abstract void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException;

    public boolean startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
      if (myAwaitedChildrenMultiple.contains(qName)) {
        return true;
      }
      return myAwaitedChildren.remove(qName);
    }

    public abstract void characters(String s, SvnInfoStructure structure) throws SAXException;
  }
}