package org.apache.maven.release;

/* ====================================================================
 *   Copyright 2001-2004 The Apache Software Foundation.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 * ====================================================================
 */

import org.dom4j.Node;

/**
 * This is a simple POM manipulator that doesn't take into account any sort of
 * POM inheritance. When the interpolation and inheritance is cleaned up in the
 * Maven we will be able to serialize a POM directly with greater ease. But we
 * may stick with this Jaxen solution anyway because it's so easy. Just turn the
 * POM in memory into a Dom4j document and perform the same operation as we are
 * here.
 */
public class DummySnapshotResolver
    extends AbstractPomTransformer
{
    // -------------------------------------------------------------------------
    // Accessors
    // -------------------------------------------------------------------------

    public String selectNodesXPathExpression()
    {
        return "/project/dependencies/dependency[version='SNAPSHOT']";
    }

    public String selectNodeXPath()
    {
        return "version";
    }

    public String getNodeContent( Node node )
        throws Exception
    {
        return "NON-SNAPSHOT";
    }

    public void transformNode( Node node )
        throws Exception
    {
        // Now with our xpath expression we have the whole <dependency/>
        // element and we want to alter the <version/> element.
        Node version = node.selectSingleNode( selectNodeXPath() );
        version.setText( getNodeContent( node ) );
    }

    public Node getTransformedNode( Node node )
        throws Exception
    {
        // Now with our xpath expression we have the whole <dependency/>
        // element and we want to alter the <version/> element.
        Node version = node.selectSingleNode( selectNodeXPath() );
        Node transformedNode = (Node) version.clone();
        transformedNode.setText( getNodeContent( node ) );

        return transformedNode;
    }

}
