1
/* Copyright 2002, 2003 Elliotte Rusty Harold
3
This library is free software; you can redistribute it and/or modify
4
it under the terms of version 2.1 of the GNU Lesser General Public
5
License as published by the Free Software Foundation.
7
This library is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU Lesser General Public License for more details.
12
You should have received a copy of the GNU Lesser General Public
13
License along with this library; if not, write to the
14
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
15
Boston, MA 02111-1307 USA
17
You can contact Elliotte Rusty Harold by sending e-mail to
18
elharo@metalab.unc.edu. Please include the word "XOM" in the
19
subject line. The XOM home page is located at http://www.xom.nu/
22
package nu.xom.samples;
24
import java.util.ArrayList;
25
import java.util.Iterator;
26
import java.util.List;
29
import nu.xom.Attribute;
30
import nu.xom.Element;
36
* Demonstrates the building of a structured XML document,
37
* from flat, tabular data. A different version of this
38
* example was originally developed for Chapter 4 of
39
* <cite><a target="_top"
40
* href="http://www.cafeconleche.org/books/xmljava/">Processing
41
* XML with Java</a></cite>.
44
* @author Elliotte Rusty Harold
50
private List agencies = new ArrayList();
53
public Budget(String year) {
58
public void add(Agency agency) {
59
if (!agencies.contains(agency)) agencies.add(agency);
62
public void add(Map lineItem) {
64
String agencyName = (String) lineItem.get("AgencyName");
65
String agencyCode = (String) lineItem.get("AgencyCode");
66
String treasuryAgencyCode
67
= (String) lineItem.get("TreasuryAgencyCode");
68
Agency agency = Agency.getInstance(agencyName, agencyCode,
69
treasuryAgencyCode, year);
72
String bureauName = (String) lineItem.get("BureauName");
73
String bureauCode = (String) lineItem.get("BureauCode");
74
Bureau bureau = Bureau.getInstance(bureauName, bureauCode,
78
// Names and codes of two accounts in different bureaus
80
String accountName = (String) lineItem.get("AccountName");
81
String accountCode = (String) lineItem.get("AccountCode");
82
String category = (String) lineItem.get("BEACategory");
83
Account account = Account.getInstance(accountName,
84
accountCode, category, bureauCode, agencyCode, year);
87
// Names and codes of two subfunctions in different accounts
89
String subfunctionTitle = (String) lineItem.get("SubfunctionTitle");
90
String subfunctionCode
91
= (String) lineItem.get("SubfunctionCode");
92
String yearKey = year;
93
if (!yearKey.equals("TransitionalQuarter")) {
97
= 1000L * Long.parseLong((String) lineItem.get(yearKey));
98
Subfunction subfunction = new Subfunction(subfunctionTitle,
99
subfunctionCode, amount);
100
account.add(subfunction);
104
public Element getXML() {
106
Element budget = new Element("Budget");
107
budget.addAttribute(new Attribute("year", String.valueOf(year)));
108
Iterator iterator = agencies.iterator();
109
while (iterator.hasNext()) {
110
Agency agency = (Agency) iterator.next();
111
budget.appendChild(agency.getXML());
b'\\ No newline at end of file'