Coverage Report - org.simpleframework.xml.stream.Format
 
Classes in this File Line Coverage Branch Coverage Complexity
Format
80%
16/20
N/A
1
 
 1  
 /*
 2  
  * Format.java July 2006
 3  
  *
 4  
  * Copyright (C) 2006, Niall Gallagher <niallg@users.sf.net>
 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 
 15  
  * implied. See the License for the specific language governing 
 16  
  * permissions and limitations under the License.
 17  
  */
 18  
 
 19  
 package org.simpleframework.xml.stream;
 20  
 
 21  
 /**
 22  
  * The <code>Format</code> object is used to provide information on 
 23  
  * how a generated XML document should be structured. The information
 24  
  * provided tells the formatter whether an XML prolog is required and
 25  
  * the number of spaces that should be used for indenting. The prolog
 26  
  * specified will be written directly before the XML document.
 27  
  * <p>
 28  
  * Should a <code>Format</code> be created with an indent of zero or
 29  
  * less then no indentation is done, and the generated XML will be on
 30  
  * the same line. The prolog can contain any legal XML heading, which
 31  
  * can domain a DTD declaration and XML comments if required.
 32  
  *
 33  
  * @author Niall Gallagher
 34  
  */ 
 35  
 public class Format {
 36  
 
 37  
    /**
 38  
     * Represents the prolog that appears in the generated XML.
 39  
     */         
 40  
    private String prolog;
 41  
    
 42  
    /**
 43  
     * This is the style that is used internally by the format.
 44  
     */
 45  
    private Style style;
 46  
          
 47  
    /**
 48  
     * Represents the indent size to use for the generated XML.
 49  
     */ 
 50  
    private int indent;        
 51  
 
 52  
    /**
 53  
     * Constructor for the <code>Format</code> object. This creates an
 54  
     * object that is used to describe how the formatter should create
 55  
     * the XML document. This constructor uses an indent size of three.
 56  
     */ 
 57  
    public Format() {
 58  540
       this(3);           
 59  540
    }
 60  
 
 61  
    /**
 62  
     * Constructor for the <code>Format</code> object. This creates an
 63  
     * object that is used to describe how the formatter should create
 64  
     * the XML document. This constructor uses the specified indent
 65  
     * size and a null prolog, which means no prolog is generated.
 66  
     *
 67  
     * @param indent this is the number of spaces used in the indent
 68  
     */ 
 69  
    public Format(int indent) {
 70  545
       this(indent, null, new IdentityStyle());           
 71  545
    }
 72  
    
 73  
    /**
 74  
     * Constructor for the <code>Format</code> object. This creates an
 75  
     * object that is used to describe how the formatter should create
 76  
     * the XML document. This constructor uses the specified prolog 
 77  
     * that is to be inserted at the start of the XML document.
 78  
     *
 79  
     * @param prolog this is the prolog for the generated XML document
 80  
     */    
 81  
    public Format(String prolog) {
 82  0
       this(3, prolog);          
 83  0
    }
 84  
    
 85  
    /**
 86  
     * Constructor for the <code>Format</code> object. This creates an
 87  
     * object that is used to describe how the formatter should create
 88  
     * the XML document. This constructor uses the specified indent
 89  
     * size and the text to use in the generated prolog.
 90  
     *
 91  
     * @param indent this is the number of spaces used in the indent
 92  
     * @param prolog this is the prolog for the generated XML document
 93  
     */    
 94  
    public Format(int indent, String prolog) {
 95  2
       this(indent, prolog, new IdentityStyle());           
 96  2
    }
 97  
    
 98  
    /**
 99  
     * Constructor for the <code>Format</code> object. This creates an
 100  
     * object that is used to describe how the formatter should create
 101  
     * the XML document. This constructor uses the specified style
 102  
     * to style the attributes and elements of the XML document.
 103  
     * 
 104  
     * @param style this is the style to apply to the format object
 105  
     */    
 106  
    public Format(Style  style) {
 107  470
       this(3, null, style);         
 108  470
    }
 109  
    
 110  
    /**
 111  
     * Constructor for the <code>Format</code> object. This creates an
 112  
     * object that is used to describe how the formatter should create
 113  
     * the XML document. This constructor uses the specified indent
 114  
     * size and the style provided to style the XML document.
 115  
     *
 116  
     * @param indent this is the number of spaces used in the indent
 117  
     * @param style this is the style to apply to the format object
 118  
     */    
 119  
    public Format(int indent, Style  style) {
 120  0
       this(indent, null, style);  
 121  0
    }
 122  
    
 123  
    /**
 124  
     * Constructor for the <code>Format</code> object. This creates an
 125  
     * object that is used to describe how the formatter should create
 126  
     * the XML document. This constructor uses the specified indent
 127  
     * size and the text to use in the generated prolog.
 128  
     *
 129  
     * @param indent this is the number of spaces used in the indent
 130  
     * @param prolog this is the prolog for the generated XML document
 131  
     * @param style this is the style to apply to the format object
 132  
     */    
 133  1017
    public Format(int indent, String prolog, Style style) {
 134  1017
       this.prolog = prolog;           
 135  1017
       this.indent = indent;       
 136  1017
       this.style = style;
 137  1017
    }
 138  
    
 139  
    /**
 140  
     * This method returns the size of the indent to use for the XML
 141  
     * generated. The indent size represents the number of spaces that
 142  
     * are used for the indent, and indent of zero means no indenting.
 143  
     * 
 144  
     * @return returns the number of spaces to used for indenting
 145  
     */    
 146  
    public int getIndent() {
 147  24420
       return indent;            
 148  
    }   
 149  
 
 150  
    /**
 151  
     * This method returns the prolog that is to be used at the start
 152  
     * of the generated XML document. This allows a DTD or a version
 153  
     * to be specified at the start of a document. If this returns
 154  
     * null then no prolog is written to the start of the XML document.
 155  
     *
 156  
     * @return this returns the prolog for the start of the document    
 157  
     */ 
 158  
    public String getProlog() {
 159  24420
       return prolog;           
 160  
    }
 161  
    
 162  
    /**
 163  
     * This is used to acquire the <code>Style</code> for the format.
 164  
     * If no style has been set a default style is used, which does 
 165  
     * not modify the attributes and elements that are used to build
 166  
     * the resulting XML document.
 167  
     * 
 168  
     * @return this returns the style used for this format object
 169  
     */
 170  
    public Style getStyle() {
 171  312144
       return style;
 172  
    }
 173  
 }