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 public class HistoryConsumer
30 extends XppStreamConsumer
31 {
32
33 private List<Transaction> transactions;
34
35 private Transaction currentTran;
36
37 private Long elementId;
38
39 private String elementName;
40
41 public HistoryConsumer( ScmLogger logger, List<Transaction> transactions )
42 {
43 super( logger );
44 this.transactions = transactions;
45 }
46
47 @Override
48 protected void startTag( List<String> tagPath, Map<String, String> attributes )
49 {
50 String tagName = getTagName( tagPath );
51 if ( "transaction".equals( tagName ) )
52 {
53 Long id = Long.parseLong( attributes.get( "id" ) );
54 Date when = new Date( Long.parseLong( attributes.get( "time" ) ) * 1000 );
55 String tranType = attributes.get( "type" );
56 String user = attributes.get( "user" );
57 currentTran = new Transaction( id, when, tranType, user );
58 transactions.add( currentTran );
59
60 }
61 else if ( "version".equals( tagName ) )
62 {
63 if ( currentTran != null )
64 {
65
66 if ( attributes.containsKey( "eid" ) )
67 {
68 elementId = Long.parseLong( attributes.get( "eid" ) );
69 elementName = attributes.get( "path" );
70 }
71
72 String virtualSpec = attributes.get( "virtual" );
73 String realSpec = attributes.get( "real" );
74 String ancestor = attributes.get( "ancestor" );
75
76 currentTran.addVersion( elementId, elementName, virtualSpec, realSpec, ancestor );
77 }
78 }
79 else if ( "element".equals( tagName ) )
80 {
81 elementId = Long.parseLong( attributes.get( "eid" ) );
82 elementName = attributes.get( "name" );
83 }
84 }
85
86 @Override
87 protected void endTag( List<String> tagPath )
88 {
89 String tagName = getTagName( tagPath );
90 if ( "element".equals( tagName ) )
91 {
92 elementId = null;
93 elementName = null;
94 }
95 else if ( "transaction".equals( tagName ) )
96 {
97 currentTran = null;
98 }
99
100 }
101
102 @Override
103 protected void text( List<String> tagPath, String text )
104 {
105 String tagName = getTagName( tagPath );
106 if ( currentTran != null && "comment".equals( tagName ) )
107 {
108 currentTran.setComment( text );
109 }
110
111 }
112
113 }