Coverage Report - org.apache.commons.configuration.tree.TreeUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
TreeUtils
92%
24/26
91%
11/12
3
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *     http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.commons.configuration.tree;
 18  
 
 19  
 import java.io.PrintStream;
 20  
 import java.util.Iterator;
 21  
 
 22  
 /**
 23  
  * Utility methods.
 24  
  * @author <a
 25  
  * href="http://commons.apache.org/configuration/team-list.html">Commons
 26  
  * Configuration team</a>
 27  
  * @version $Id: TreeUtils.java 1301991 2012-03-17 20:18:02Z sebb $
 28  
  * @since 1.7
 29  
  */
 30  
 public final class TreeUtils
 31  
 {
 32  
     /** Prevent creating this class. */
 33  
     private TreeUtils()
 34  0
     {
 35  0
     }
 36  
 
 37  
     /**
 38  
      * Print out the data in the configuration.
 39  
      * @param stream The OutputStream.
 40  
      * @param result The root node of the tree.
 41  
      */
 42  
     public static void printTree(PrintStream stream, ConfigurationNode result)
 43  
     {
 44  16
         if (stream != null)
 45  
         {
 46  16
             printTree(stream, "", result);
 47  
         }
 48  16
     }
 49  
 
 50  
     private static void printTree(PrintStream stream, String indent, ConfigurationNode result)
 51  
     {
 52  575
         StringBuffer buffer = new StringBuffer(indent).append("<").append(result.getName());
 53  575
         Iterator<ConfigurationNode> iter = result.getAttributes().iterator();
 54  723
         while (iter.hasNext())
 55  
         {
 56  148
             ConfigurationNode node = iter.next();
 57  148
             buffer.append(" ").append(node.getName()).append("='").append(node.getValue()).append("'");
 58  148
         }
 59  575
         buffer.append(">");
 60  575
         stream.print(buffer.toString());
 61  575
         if (result.getValue() != null)
 62  
         {
 63  319
             stream.print(result.getValue());
 64  
         }
 65  575
         boolean newline = false;
 66  575
         if (result.getChildrenCount() > 0)
 67  
         {
 68  195
             stream.print("\n");
 69  195
             iter = result.getChildren().iterator();
 70  754
             while (iter.hasNext())
 71  
             {
 72  559
                 printTree(stream, indent + "  ", iter.next());
 73  
             }
 74  195
             newline = true;
 75  
         }
 76  575
         if (newline)
 77  
         {
 78  195
             stream.print(indent);
 79  
         }
 80  575
         stream.println("</" + result.getName() + ">");
 81  575
     }
 82  
 }