/*
 * Copyright 
 *   2008 axYus - www.axyus.com
 *   2008 L.Meckert - laurent.meckert@axyus.com
 * 
 * This file is part of XEMELIOS.
 * 
 * XEMELIOS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * XEMELIOS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with XEMELIOS; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package fr.gouv.finances.cp.xemelios.plugin.signature;

import org.w3c.dom.*;

/**
 * classe auxiliaire en  phase de développement pour montrer le contenu d'un DOM
 * @author laurent.meckert
 */
public class APXSGSVDebug {

    /**
     * lit recusrsivement le dom et sort son contenu 
     * @param doc
     */
    public static void debugDoc(org.w3c.dom.Document doc) {

        Node root = doc.getDocumentElement();
        System.out.println("Root Node = " + root.getNodeName());
        readNode(root);

    }

    private static void readNode(Node node) {
        System.out.println("Current Node = " + node.getNodeName());
        readAttributes(node);
        readChildren(node);
    }

    private static void readAttributes(Node node) {
        if (!node.hasAttributes()) {
            return;
        }
        System.out.println("Attributes:");
        NamedNodeMap attrNodes = node.getAttributes();
        for (int i = 0; i < attrNodes.getLength(); i++) {
            Attr attr = (Attr) attrNodes.item(i);
            System.out.println(attr.getNodeName() + " => " + attr.getNodeValue());
        }
    }

    private static void readChildren(Node node) {
        if (!node.hasChildNodes()) {
            return;
        }
        System.out.println("Value/s:");
        NodeList childNodes = node.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node child = (Node) childNodes.item(i);
            if (child.getNodeType() == Node.ELEMENT_NODE) {
                readNode(child);
                continue;
            }
            if (child.getNodeType() == Node.TEXT_NODE) {
                if (child.getNodeValue() != null) {
                    System.out.println(child.getNodeValue());
                }
            }
        }
    }
}



   
