01: /*
02: * XML input/output support for FindBugs
03: * Copyright (C) 2004, University of Maryland
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: */
19:
20: package edu.umd.cs.findbugs.xml;
21:
22: import java.io.IOException;
23: import java.util.Collection;
24: import java.util.Iterator;
25:
26: /**
27: * Utility routines for writing to XMLOutput.
28: *
29: * @see XMLOutput
30: * @author David Hovemeyer
31: */
32: public abstract class XMLOutputUtil {
33: /**
34: * Write a list of Strings to document as elements
35: * with given tag name.
36: *
37: * @param xmlOutput the XMLOutput object to write to
38: * @param tagName the tag name
39: * @param listValues Collection of String values to write
40: */
41: public static void writeElementList(XMLOutput xmlOutput,
42: String tagName, Collection<String> listValues)
43: throws IOException {
44: writeElementList(xmlOutput, tagName, listValues.iterator());
45: }
46:
47: /**
48: * Write a list of Strings to document as elements
49: * with given tag name.
50: *
51: * @param xmlOutput the XMLOutput object to write to
52: * @param tagName the tag name
53: * @param listValueIterator Iterator over String values to write
54: */
55: public static void writeElementList(XMLOutput xmlOutput,
56: String tagName, Iterator<String> listValueIterator)
57: throws IOException {
58: while (listValueIterator.hasNext()) {
59: xmlOutput.openTag(tagName);
60: xmlOutput.writeText(listValueIterator.next());
61: xmlOutput.closeTag(tagName);
62: }
63: }
64:
65: /**
66: * Write a Collection of XMLWriteable objects.
67: *
68: * @param xmlOutput the XMLOutput object to write to
69: * @param collection Collection of XMLWriteable objects
70: */
71: public static void writeCollection(XMLOutput xmlOutput,
72: Collection<? extends XMLWriteable> collection)
73: throws IOException {
74: for (XMLWriteable obj : collection) {
75: obj.writeXML(xmlOutput);
76: }
77: }
78: }
79:
80: // vim:ts=4
|