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  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 }