/*
 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
 * Copyright (C) 2006, 2007 XStream Committers.
 * All rights reserved.
 *
 * The software in this package is published under the terms of the BSD
 * style license a copy of which has been included with this distribution in
 * the LICENSE.txt file.
 * 
 * Created on 07. March 2004 by Joe Walnes
 */
package com.thoughtworks.xstream.io.path;

import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import com.thoughtworks.xstream.io.WriterWrapper;
import com.thoughtworks.xstream.io.xml.XmlFriendlyWriter;

/**
 * Wrapper for HierarchicalStreamWriter that tracks the path (a subset of XPath) of the current node that is being written.
 *
 * @see PathTracker
 * @see Path
 *
 * @author Joe Walnes
 */
public class PathTrackingWriter extends WriterWrapper {

    private final PathTracker pathTracker;
    private final boolean isXmlFriendly;

    public PathTrackingWriter(HierarchicalStreamWriter writer, PathTracker pathTracker) {
        super(writer);
        this.isXmlFriendly = writer.underlyingWriter() instanceof XmlFriendlyWriter;
        this.pathTracker = pathTracker;
    }

    public void startNode(String name) {
        pathTracker.pushElement(isXmlFriendly ? ((XmlFriendlyWriter)wrapped.underlyingWriter()).escapeXmlName(name) : name);
        super.startNode(name); 
    }

    public void startNode(String name, Class clazz) {
        pathTracker.pushElement(isXmlFriendly ? ((XmlFriendlyWriter)wrapped.underlyingWriter()).escapeXmlName(name) : name);
        super.startNode(name, clazz);
    }

    public void endNode() {
        super.endNode();
        pathTracker.popElement();
    }

}

@@ -69,16 +69,22 @@
 06, 2007
+, 2011
  XStream
@@ -391,16 +391,67 @@
 .path;%0A%0A
+import com.thoughtworks.xstream.io.AbstractWriter;%0A
 import c
@@ -556,66 +556,8 @@
 per;
-%0Aimport com.thoughtworks.xstream.io.xml.XmlFriendlyWriter;
 %0A%0A/*
@@ -875,27 +875,28 @@
 olean is
-XmlFriendly
+NameEncoding
 ;%0A%0A    p
@@ -1018,27 +1018,28 @@
  this.is
-XmlFriendly
+NameEncoding
  = write
@@ -1070,27 +1070,24 @@
 tanceof 
-XmlFriendly
+Abstract
 Writer;%0A
@@ -1212,35 +1212,33 @@
 t(is
-XmlFriendly ? ((XmlFriendly
+NameEncoding ? ((Abstract
 Writ
@@ -1265,35 +1265,32 @@
 gWriter()).e
-scapeXmlNam
+ncodeNod
 e(name) : na
@@ -1425,35 +1425,33 @@
 t(is
-XmlFriendly ? ((XmlFriendly
+NameEncoding ? ((Abstract
 Writ
@@ -1486,19 +1486,16 @@
 )).e
-scapeXmlNam
+ncodeNod
 e(na
@@ -1645,11 +1645,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

Fix usage of deprecated stuff.