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