Subversion Repositories DevTools

Rev

Rev 6914 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6914 Rev 7082
Line 5... Line 5...
5
public class XmlBuilder {
5
public class XmlBuilder {
6
	/**
6
	/**
7
	 * A class to simply the process of creating nice XML
7
	 * A class to simply the process of creating nice XML
8
	 * Designed to only write xml fragments
8
	 * Designed to only write xml fragments
9
	 */
9
	 */
10
	private static final  String mlf = new String( System.getProperty("line.separator") );
10
	private static final  String mlf = System.getProperty("line.separator");
11
	
11
	
12
	String mTagName;
12
	String mTagName;
13
	boolean mComment = false;
13
	boolean mComment = false;
14
	boolean mNoShrink = false;
14
	boolean mNoShrink = false;
15
	ArrayList<attribute> mAttributes = new ArrayList<attribute>();
15
	ArrayList<Attribute> mAttributes = new ArrayList<Attribute>();
16
	ArrayList<XmlBuilder> mElements = new ArrayList<XmlBuilder>();
16
	ArrayList<XmlBuilder> mElements = new ArrayList<XmlBuilder>();
17
	
17
	
18
	/**
18
	/**
19
	 * Class to describe an an XML attribute
19
	 * Class to describe an an XML attribute
20
	 */
20
	 */
21
	private class attribute
21
	private class Attribute
22
	{
22
	{
23
		private String aName;
23
		private String aName;
24
		private String aValue;
24
		private String aValue;
25
		
25
		
26
		attribute( String name, String value)
26
		Attribute( String name, String value)
27
		{
27
		{
28
			aName = name;
28
			aName = name;
29
			aValue = value;
29
			aValue = value;
30
		}
30
		}
31
		
31
		
Line 52... Line 52...
52
	 * @param value - The value of the attribute
52
	 * @param value - The value of the attribute
53
	 * @return The XML element. This allows chaining of operations
53
	 * @return The XML element. This allows chaining of operations
54
	 */
54
	 */
55
	public XmlBuilder addAttribute ( String name, String value)
55
	public XmlBuilder addAttribute ( String name, String value)
56
	{
56
	{
57
		mAttributes.add(new attribute(name,value));
57
		mAttributes.add(new Attribute(name,value));
58
		return this;
58
		return this;
59
	}
59
	}
60
	
60
	
61
	/**	Add an attribute the the XML element
61
	/**	Add an attribute the the XML element
62
	 * 
62
	 * 
63
	 * @param name - The name of the attribute
63
	 * @param name - The name of the attribute
64
     * @param value - The value of the attribute
64
     * @param value - The value of the attribute
65
	 * @return The XML element. This allows chaining of operations
65
	 * @return The XML element. This allows chaining of operations
66
	 */
66
	 */
67
	public XmlBuilder addAttribute(String name, int value) {
67
	public XmlBuilder addAttribute(String name, int value) {
68
		mAttributes.add(new attribute(name,Integer.toString(value)));
68
		mAttributes.add(new Attribute(name,Integer.toString(value)));
69
		return this;
69
		return this;
70
	}
70
	}
71
	
71
	
72
	/**	Add an attribute the the XML element
72
	/**	Add an attribute the the XML element
73
	 * 
73
	 * 
74
	 * @param name - The name of the attribute
74
	 * @param name - The name of the attribute
75
     * @param value - The value of the attribute
75
     * @param value - The value of the attribute
76
	 * @return The XML element. This allows chaining of operations
76
	 * @return The XML element. This allows chaining of operations
77
	 */
77
	 */
78
	public XmlBuilder addAttribute(String name, long value) {
78
	public XmlBuilder addAttribute(String name, long value) {
79
		mAttributes.add(new attribute(name,Long.toString(value)));
79
		mAttributes.add(new Attribute(name,Long.toString(value)));
80
		return this;
80
		return this;
81
	}
81
	}
82
 
82
 
83
	/**Add a child element to the XML element
83
	/**Add a child element to the XML element
84
	 * 
84
	 * 
Line 184... Line 184...
184
		}
184
		}
185
		
185
		
186
		String result = indent + leadin + mTagName;
186
		String result = indent + leadin + mTagName;
187
		
187
		
188
		// Process each attribute
188
		// Process each attribute
189
		for (attribute e : mAttributes) {
189
		for (Attribute e : mAttributes) {
190
		    result += e.toString();
190
		    result += e.toString();
191
		}
191
		}
192
		
192
		
193
		// Process child elements
193
		// Process child elements
194
		if (mElements.isEmpty() && ! mNoShrink)
194
		if (mElements.isEmpty() && ! mNoShrink)