KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > security > realm > lib > XML


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or 1any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer: Florent BENOIT
22  * --------------------------------------------------------------------------
23  * $Id: XML.java,v 1.2 2004/05/25 15:13:28 benoitf Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas.security.realm.lib;
28
29 import java.util.Enumeration JavaDoc;
30 import java.util.Hashtable JavaDoc;
31 import java.util.Vector JavaDoc;
32
33 /**
34  * Useful class. Make xml representation for some objects used for the security
35  * @author Florent Benoit
36  */

37 public class XML {
38
39     /**
40      * Default constructor (Utility class, private constructor)
41      */

42     private XML() {
43
44     }
45
46     /**
47      * Append to the given buffer the hashtable elements with comma separated
48      * list
49      * @param name name of the element
50      * @param buffer the buffer on which append the Hashtable
51      * @param vector the vector where are the elements
52      */

53     public static void appendVectorToBuffer(String JavaDoc name, StringBuffer JavaDoc buffer, Vector JavaDoc vector) {
54         if (vector.size() > 0) {
55             buffer.append(" " + name + "\"");
56             int nb = 0;
57             for (Enumeration JavaDoc e = vector.elements(); e.hasMoreElements();) {
58                 if (nb > 0) {
59                     buffer.append(",");
60                 }
61                 String JavaDoc s = (String JavaDoc) e.nextElement();
62                 buffer.append(s);
63                 nb++;
64             }
65             buffer.append("\"");
66         }
67     }
68
69     /**
70      * Append to the given buffer the hashtable elements.
71      * @param buffer the buffer on which append the Hashtable
72      * @param vector the vector where are the elements
73      */

74     public static void xmlVector(StringBuffer JavaDoc buffer, Vector JavaDoc vector) {
75         if (vector.size() > 0) {
76             for (Enumeration JavaDoc e = vector.elements(); e.hasMoreElements();) {
77                 Object JavaDoc o = e.nextElement();
78                 buffer.append(o.toString());
79                 buffer.append("\n");
80             }
81         }
82     }
83
84     /**
85      * Append to the given buffer the hashtable elements.
86      * @param buffer the buffer on which append the Hashtable
87      * @param hashtable the hashtable where are the elements
88      */

89     public static void xmlHashtable(StringBuffer JavaDoc buffer, Hashtable JavaDoc hashtable) {
90         xmlHashtable(buffer, hashtable, "");
91     }
92
93     /**
94      * Append to the given buffer the hashtable elements.
95      * @param buffer the buffer on which append the Hashtable
96      * @param hashtable the hashtable where are the elements
97      * @param indent the indent to put before the lines
98      */

99     public static void xmlHashtable(StringBuffer JavaDoc buffer, Hashtable JavaDoc hashtable, String JavaDoc indent) {
100         if (hashtable.size() > 0) {
101             for (Enumeration JavaDoc e = hashtable.elements(); e.hasMoreElements();) {
102                 Object JavaDoc o = e.nextElement();
103                 buffer.append(indent + o.toString());
104                 buffer.append("\n");
105             }
106         }
107     }
108
109 }
Popular Tags