001    package org.apache.maven.scm.provider.accurev.cli;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     *   http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import java.util.List;
023    import java.util.Map;
024    
025    import org.apache.maven.scm.log.ScmLogger;
026    import org.apache.maven.scm.provider.accurev.FileDifference;
027    
028    public class DiffConsumer
029        extends XppStreamConsumer
030    {
031    
032        private List<FileDifference> results;
033    
034        private FileDifference currentDifference;
035    
036        public DiffConsumer( ScmLogger logger, List<FileDifference> results )
037        {
038            super( logger );
039            this.results = results;
040        }
041    
042        @Override
043        protected void startTag( List<String> tagPath, Map<String, String> attributes )
044        {
045            String tagName = getTagName( tagPath );
046            if ( "Element".equals( tagName ) )
047            {
048                currentDifference = new FileDifference();
049            }
050            else if ( "Stream2".equals( tagName ) && attributes.get( "Name" ) != null)
051            {
052                currentDifference.setElementId( Long.parseLong( attributes.get( "eid" ) ) );
053                currentDifference.setNewVersion( attributes.get( "Name" ), attributes.get( "Version" ) );
054            }
055            else if ( "Stream1".equals( tagName ) && attributes.get( "Name" ) != null )
056            {
057                currentDifference.setElementId( Long.parseLong( attributes.get( "eid" ) ) );
058                currentDifference.setOldVersion( attributes.get( "Name" ), attributes.get( "Version" ) );
059            }
060    
061        }
062    
063        @Override
064        protected void endTag( List<String> tagPath )
065        {
066            String tagName = getTagName( tagPath );
067            if ( "Element".equals( tagName ) )
068            {
069                if (currentDifference.getNewFile() != null || currentDifference.getOldFile() != null) {
070                    results.add( currentDifference );
071                }
072            }
073        }
074    
075    }