1 package org.apache.maven.scm.provider.accurev.cli;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Date;
23 import java.util.List;
24 import java.util.Map;
25
26 import org.apache.maven.scm.log.ScmLogger;
27 import org.apache.maven.scm.provider.accurev.Transaction;
28
29
30
31
32 public class HistoryConsumer
33 extends XppStreamConsumer
34 {
35
36 private List<Transaction> transactions;
37
38 private Transaction currentTran;
39
40 private Long elementId;
41
42 private String elementName;
43
44 public HistoryConsumer( ScmLogger logger, List<Transaction> transactions )
45 {
46 super( logger );
47 this.transactions = transactions;
48 }
49
50 @Override
51 protected void startTag( List<String> tagPath, Map<String, String> attributes )
52 {
53 String tagName = getTagName( tagPath );
54 if ( "transaction".equals( tagName ) )
55 {
56 Long id = Long.parseLong( attributes.get( "id" ) );
57 Date when = new Date( Long.parseLong( attributes.get( "time" ) ) * 1000 );
58 String tranType = attributes.get( "type" );
59 String user = attributes.get( "user" );
60 currentTran = new Transaction( id, when, tranType, user );
61 transactions.add( currentTran );
62
63 }
64 else if ( "version".equals( tagName ) )
65 {
66 if ( currentTran != null )
67 {
68
69 if ( attributes.containsKey( "eid" ) )
70 {
71 elementId = Long.parseLong( attributes.get( "eid" ) );
72 elementName = attributes.get( "path" );
73 }
74
75 String virtualSpec = attributes.get( "virtual" );
76 String realSpec = attributes.get( "real" );
77 String ancestor = attributes.get( "ancestor" );
78
79 currentTran.addVersion( elementId, elementName, virtualSpec, realSpec, ancestor );
80 }
81 }
82 else if ( "element".equals( tagName ) )
83 {
84 elementId = Long.parseLong( attributes.get( "eid" ) );
85 elementName = attributes.get( "name" );
86 }
87 }
88
89 @Override
90 protected void endTag( List<String> tagPath )
91 {
92 String tagName = getTagName( tagPath );
93 if ( "element".equals( tagName ) )
94 {
95 elementId = null;
96 elementName = null;
97 }
98 else if ( "transaction".equals( tagName ) )
99 {
100 currentTran = null;
101 }
102
103 }
104
105 @Override
106 protected void text( List<String> tagPath, String text )
107 {
108 String tagName = getTagName( tagPath );
109 if ( currentTran != null && "comment".equals( tagName ) )
110 {
111 currentTran.setComment( text );
112 }
113
114 }
115
116 }