The Format object is used to provide information on how a generated XML document should be structured. The information provided tells the formatter whether an XML prolog is required and the number of spaces that should be used for indenting. The prolog specified will be written directly before the XML document.

Should a Format be created with an indent of zero or less then no indentation is done, and the generated XML will be on the same line. The prolog can contain any legal XML heading, which can domain a DTD declaration and XML comments if required.

Exemple #1
0
 public void TestCase() {
    Style style = new HyphenStyle();
    Format format = new Format(style);
    Persister writer = new Persister(format);
    Persister reader = new Persister();
    CaseExample example = reader.read(CaseExample.class, SOURCE);
Exemple #2
0
 /// <summary>
 /// Constructor for the <c>Formatter</c> object. This creates
 /// an object that can be used to write XML in an indented format
 /// to the specified writer. The XML written will be well formed.
 /// </summary>
 /// <param name="result">
 /// this is where the XML should be written to
 /// </param>
 /// <param name="format">
 /// this is the format object to use
 /// </param>
 public Formatter(TextWriter result, Format format){
    this.indenter = new Indenter(format);
    this.buffer = new OutputBuffer();
    this.prolog = format.Prolog;
    this.result = result;
 }
Exemple #3
0
 /// <summary>
 /// Constructor for the <c>Persister</c> object. This is used
 /// to create a serializer object that will use the provided matcher
 /// for customizable transformations. The <c>Matcher</c> will
 /// enable the persister to determine the correct way to transform
 /// the types that are not annotated and considered primitives.
 /// <p>
 /// This persister will use the provided <c>Strategy</c> to
 /// intercept the XML elements in order to read and write persistent
 /// data, such as the class name or version of the document.
 /// </summary>
 /// <param name="strategy">
 /// this is the strategy used to resolve classes
 /// </param>
 /// <param name="matcher">
 /// this is used to customize the transformations
 /// </param>
 /// <param name="filter">
 /// the filter used to replace template variables
 /// </param>
 public Persister(Strategy strategy, Filter filter, Matcher matcher, Format format) {
    this.support = new Support(filter, matcher);
    this.style = format.Style;
    this.strategy = strategy;
    this.format = format;
 }
Exemple #4
0
 /// <summary>
 /// Constructor for the <c>Persister</c> object. This is used
 /// to create a serializer object that will use the provided format
 /// instructions. The persister uses the <c>Format</c> object
 /// to structure the generated XML. It determines the indent size
 /// of the document and whether it should contain a prolog.
 /// </summary>
 /// <param name="format">
 /// this is used to structure the generated XML
 /// </param>
 public Persister(Format format) {
    this(new TreeStrategy(), format);
 }
Exemple #5
0
 /// <summary>
 /// Constructor for the <c>Persister</c> object. This is used
 /// to create a serializer object that will use the provided filter.
 /// This persister will replace all variables encountered when
 /// deserializing an object with mappings found in the filter.
 /// <p>
 /// This persister will use the provided <c>Strategy</c> to
 /// intercept the XML elements in order to read and write persistent
 /// data, such as the class name or version of the document.
 /// </summary>
 /// <param name="strategy">
 /// this is the strategy used to resolve classes
 /// </param>
 /// <param name="filter">
 /// the filter used to replace template variables
 /// </param>
 /// <param name="format">
 /// this is used to format the generated XML document
 /// </param>
 public Persister(Strategy strategy, Filter filter, Format format) {
    this(strategy, filter, new EmptyMatcher(), format);
 }
Exemple #6
0
 /// <summary>
 /// Constructor for the <c>Persister</c> object. This is used
 /// to create a serializer object that will use the provided matcher
 /// for customizable transformations. The <c>Matcher</c> will
 /// enable the persister to determine the correct way to transform
 /// the types that are not annotated and considered primitives.
 /// <p>
 /// This persister will use the provided <c>Strategy</c> to
 /// intercept the XML elements in order to read and write persistent
 /// data, such as the class name or version of the document.
 /// </summary>
 /// <param name="strategy">
 /// this is the strategy used to resolve classes
 /// </param>
 /// <param name="matcher">
 /// this is used to customize the transformations
 /// </param>
 /// <param name="format">
 /// this is used to format the generated XML document
 /// </param>
 public Persister(Strategy strategy, Matcher matcher, Format format) {
    this(strategy, new PlatformFilter(), matcher, format);
 }
Exemple #7
0
 /// <summary>
 /// Constructor for the <c>Persister</c> object. This is used
 /// to create a serializer object that will use the provided filter.
 /// This persister will replace all variables encountered when
 /// deserializing an object with mappings found in the filter.
 /// </summary>
 /// <param name="filter">
 /// the filter used to replace template variables
 /// </param>
 /// <param name="matcher">
 /// this is used to customize the transformations
 /// </param>
 /// <param name="format">
 /// this is used to structure the generated XML
 /// </param>
 public Persister(Filter filter, Matcher matcher, Format format) {
    this(new TreeStrategy(), filter, matcher, format);
 }
Exemple #8
0
 /// <summary>
 /// This is used to create an <c>OutputNode</c> that can be
 /// used to write a well formed XML document. The writer specified
 /// will have XML elements, attributes, and text written to it as
 /// output nodes are created and populated.
 /// </summary>
 /// <param name="result">
 /// This contains the result of the generated XML.
 /// </param>
 /// <param name="format">
 /// This is the format to use for the document.
 /// </param>
 public static OutputNode Write(TextWriter result, Format format) {
    return new NodeWriter(result, format).WriteRoot();
 }
Exemple #9
0
 /// <summary>
 /// Constructor for the <c>Persister</c> object. This is used
 /// to create a serializer object that will use the provided matcher
 /// for customizable transformations. The <c>Matcher</c> will
 /// enable the persister to determine the correct way to transform
 /// the types that are not annotated and considered primitives.
 /// </summary>
 /// <param name="matcher">
 /// this is used to customize the transformations
 /// </param>
 /// <param name="format">
 /// this is used to structure the generated XML
 /// </param>
 public Persister(Matcher matcher, Format format) {
    this(new TreeStrategy(), matcher, format);
 }
Exemple #10
0
 /// <summary>
 /// Constructor for the <c>Persister</c> object. This is used
 /// to create a serializer object that will use a strategy object.
 /// This persister will use the provided <c>Strategy</c> to
 /// intercept the XML elements in order to read and write persistent
 /// data, such as the class name or version of the document.
 /// </summary>
 /// <param name="strategy">
 /// this is the strategy used to resolve classes
 /// </param>
 /// <param name="format">
 /// this is used to structure the generated XML
 /// </param>
 public Persister(Strategy strategy, Format format) {
    this(strategy, new HashMap(), format);
 }
Exemple #11
0
 /// <summary>
 /// Constructor for the <c>Persister</c> object. This is used
 /// to create a serializer object that will use a platform filter
 /// object using the overrides within the provided map. This means
 /// that template variables will be replaced firstly with mappings
 /// from within the provided map, followed by system properties.
 /// </summary>
 /// <param name="filter">
 /// this is the map that contains the overrides
 /// </param>
 /// <param name="format">
 /// this is the format used to format the documents
 /// </param>
 public Persister(Dictionary filter, Format format) {
    this(new PlatformFilter(filter));
 }
Exemple #12
0
 /// <summary>
 /// Constructor for the <c>Indenter</c> object. This will
 /// create an indent that uses the specified number of spaces to
 /// create each entry pushed on to the stack. This uses a cache
 /// of the specified size, which is used to optimize the object.
 /// </summary>
 /// <param name="format">
 /// Determines the number of spaces per indent.
 /// </param>
 /// <param name="size">
 /// This is the initial size of the indent cache.
 /// </param>
 private Indenter(Format format, int size) {
    this.cache = new Cache(size);
    this.indent = format.Indent;
 }
Exemple #13
0
 /// <summary>
 /// Constructor for the <c>Indenter</c> object. This will
 /// create an indent that uses the specified number of spaces to
 /// create each entry pushed on to the stack. This uses a cache
 /// size of sixteen, which should be sufficient for most files.
 /// </summary>
 /// <param name="format">
 /// Determines the number of spaces per indent.
 /// </param>
 public Indenter(Format format) : this(format, 16) {
 }
Exemple #14
0
 /// <summary>
 /// Constructor for the <c>NodeWriter</c> object. This will
 /// create the object that is used to control an output elements
 /// access to the generated XML document. This keeps a stack of
 /// active and uncommitted elements.
 /// </summary>
 /// <param name="result">
 /// this is the output for the resulting document
 /// </param>
 /// <param name="format">
 /// this is used to format the generated document
 /// </param>
 public NodeWriter(Writer result, Format format) {
    this(result, format, false);
 }
Exemple #15
0
 /// <summary>
 /// Constructor for the <c>Persister</c> object. This is used
 /// to create a serializer object that will use the provided filter.
 /// This persister will replace all variables encountered when
 /// deserializing an object with mappings found in the filter.
 /// <p>
 /// This persister will use the provided <c>Strategy</c> to
 /// intercept the XML elements in order to read and write persistent
 /// data, such as the class name or version of the document.
 /// </summary>
 /// <param name="strategy">
 /// this is the strategy used to resolve classes
 /// </param>
 /// <param name="data">
 /// the filter data used to replace template variables
 /// </param>
 /// <param name="format">
 /// this is used to format the generated XML document
 /// </param>
 public Persister(Strategy strategy, Dictionary data, Format format) {
    this(strategy, new PlatformFilter(data), format);
 }
Exemple #16
0
 /// <summary>
 /// Constructor for the <c>NodeWriter</c> object. This will
 /// create the object that is used to control an output elements
 /// access to the generated XML document. This keeps a stack of
 /// active and uncommitted elements.
 /// </summary>
 /// <param name="result">
 /// this is the output for the resulting document
 /// </param>
 /// <param name="format">
 /// this is used to format the generated document
 /// </param>
 /// <param name="verbose">
 /// this determines if we expand the namespaces
 /// </param>
 private NodeWriter(Writer result, Format format, bool verbose) {
    this.writer = new Formatter(result, format);
    this.active = new HashSet();
    this.stack = new OutputStack(active);
    this.verbose = verbose;
 }
Exemple #17
0
 /// <summary>
 /// Constructor for the <c>NodeWriter</c> object. This will
 /// create the object that is used to control an output elements
 /// access to the generated XML document. This keeps a stack of
 /// active and uncommitted elements.
 /// </summary>
 /// <param name="result">
 /// This is the output for the resulting document.
 /// </param>
 /// <param name="format">
 /// This is used to format the generated document.
 /// </param>
 public NodeWriter(TextWriter result, Format format) : this(result, format, false)
 {
 }