Coverage Report - org.codehaus.plexus.util.xml.Xpp3DomWriter
 
Classes in this File Line Coverage Branch Coverage Complexity
Xpp3DomWriter
85%
18/21
100%
8/8
2
 
 1  
 package org.codehaus.plexus.util.xml;
 2  
 
 3  
 /*
 4  
  * Copyright The Codehaus Foundation.
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License");
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 import java.io.PrintWriter;
 20  
 import java.io.Writer;
 21  
 
 22  
 /**
 23  
  * @version $Id$
 24  
  */
 25  0
 public class Xpp3DomWriter
 26  
 {
 27  
     public static void write( Writer writer, Xpp3Dom dom )
 28  
     {
 29  3
         write( new PrettyPrintXMLWriter( writer ), dom );
 30  3
     }
 31  
 
 32  
     public static void write( PrintWriter writer, Xpp3Dom dom )
 33  
     {
 34  0
         write( new PrettyPrintXMLWriter( writer ), dom );
 35  0
     }
 36  
 
 37  
     public static void write( XMLWriter xmlWriter, Xpp3Dom dom )
 38  
     {
 39  5
         write( xmlWriter, dom, true );
 40  5
     }
 41  
 
 42  
     public static void write( XMLWriter xmlWriter, Xpp3Dom dom, boolean escape )
 43  
     {
 44  
         // TODO: move to XMLWriter?
 45  24
         xmlWriter.startElement( dom.getName() );
 46  24
         String[] attributeNames = dom.getAttributeNames();
 47  31
         for ( String attributeName : attributeNames )
 48  
         {
 49  7
             xmlWriter.addAttribute( attributeName, dom.getAttribute( attributeName ) );
 50  
         }
 51  24
         Xpp3Dom[] children = dom.getChildren();
 52  42
         for ( Xpp3Dom aChildren : children )
 53  
         {
 54  18
             write( xmlWriter, aChildren, escape );
 55  
         }
 56  
 
 57  24
         String value = dom.getValue();
 58  24
         if ( value != null )
 59  
         {
 60  12
             if ( escape )
 61  
             {
 62  8
                 xmlWriter.writeText( value );
 63  
             }
 64  
             else
 65  
             {
 66  4
                 xmlWriter.writeMarkup( value );
 67  
             }
 68  
         }
 69  
 
 70  24
         xmlWriter.endElement();
 71  24
     }
 72  
 
 73  
 }