KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > xml > XMLOutputUtil


1 /*
2  * XML input/output support for FindBugs
3  * Copyright (C) 2004, University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
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 JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.Iterator JavaDoc;
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, String JavaDoc tagName,
42             Collection JavaDoc<String JavaDoc> listValues) throws IOException JavaDoc {
43         writeElementList(xmlOutput, tagName, listValues.iterator());
44     }
45
46     /**
47      * Write a list of Strings to document as elements
48      * with given tag name.
49      *
50      * @param xmlOutput the XMLOutput object to write to
51      * @param tagName the tag name
52      * @param listValueIterator Iterator over String values to write
53      */

54     public static void writeElementList(XMLOutput xmlOutput, String JavaDoc tagName,
55             Iterator JavaDoc<String JavaDoc> listValueIterator) throws IOException JavaDoc {
56         while (listValueIterator.hasNext()) {
57             xmlOutput.openTag(tagName);
58             xmlOutput.writeText(listValueIterator.next());
59             xmlOutput.closeTag(tagName);
60         }
61     }
62
63     /**
64      * Write a Collection of XMLWriteable objects.
65      *
66      * @param xmlOutput the XMLOutput object to write to
67      * @param collection Collection of XMLWriteable objects
68      */

69     public static void writeCollection(XMLOutput xmlOutput, Collection JavaDoc<? extends XMLWriteable> collection)
70             throws IOException JavaDoc {
71         for (XMLWriteable obj : collection) {
72             obj.writeXML(xmlOutput);
73         }
74     }
75 }
76
77 // vim:ts=4
78
Popular Tags