001package 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
022import java.util.List;
023import java.util.Map;
024
025import org.apache.maven.scm.log.ScmLogger;
026import org.apache.maven.scm.provider.accurev.FileDifference;
027
028/**
029 * 
030 */
031public class DiffConsumer
032    extends XppStreamConsumer
033{
034
035    private List<FileDifference> results;
036
037    private FileDifference currentDifference;
038
039    public DiffConsumer( ScmLogger logger, List<FileDifference> results )
040    {
041        super( logger );
042        this.results = results;
043    }
044
045    @Override
046    protected void startTag( List<String> tagPath, Map<String, String> attributes )
047    {
048        String tagName = getTagName( tagPath );
049        if ( "Element".equals( tagName ) )
050        {
051            currentDifference = new FileDifference();
052        }
053        else if ( "Stream2".equals( tagName ) && attributes.get( "Name" ) != null )
054        {
055            currentDifference.setElementId( Long.parseLong( attributes.get( "eid" ) ) );
056            currentDifference.setNewVersion( attributes.get( "Name" ), attributes.get( "Version" ) );
057        }
058        else if ( "Stream1".equals( tagName ) && attributes.get( "Name" ) != null )
059        {
060            currentDifference.setElementId( Long.parseLong( attributes.get( "eid" ) ) );
061            currentDifference.setOldVersion( attributes.get( "Name" ), attributes.get( "Version" ) );
062        }
063
064    }
065
066    @Override
067    protected void endTag( List<String> tagPath )
068    {
069        String tagName = getTagName( tagPath );
070        if ( "Element".equals( tagName ) )
071        {
072            if ( currentDifference.getNewFile() != null || currentDifference.getOldFile() != null )
073            {
074                results.add( currentDifference );
075            }
076        }
077    }
078
079}