001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or 1any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial developer: Florent BENOIT
022: * --------------------------------------------------------------------------
023: * $Id: XML.java 4804 2004-05-25 15:13:29Z benoitf $
024: * --------------------------------------------------------------------------
025: */package org.objectweb.jonas.security.realm.lib;
026:
027: import java.util.Enumeration;
028: import java.util.Hashtable;
029: import java.util.Vector;
030:
031: /**
032: * Useful class. Make xml representation for some objects used for the security
033: * @author Florent Benoit
034: */
035: public class XML {
036:
037: /**
038: * Default constructor (Utility class, private constructor)
039: */
040: private XML() {
041:
042: }
043:
044: /**
045: * Append to the given buffer the hashtable elements with comma separated
046: * list
047: * @param name name of the element
048: * @param buffer the buffer on which append the Hashtable
049: * @param vector the vector where are the elements
050: */
051: public static void appendVectorToBuffer(String name,
052: StringBuffer buffer, Vector vector) {
053: if (vector.size() > 0) {
054: buffer.append(" " + name + "\"");
055: int nb = 0;
056: for (Enumeration e = vector.elements(); e.hasMoreElements();) {
057: if (nb > 0) {
058: buffer.append(",");
059: }
060: String s = (String) e.nextElement();
061: buffer.append(s);
062: nb++;
063: }
064: buffer.append("\"");
065: }
066: }
067:
068: /**
069: * Append to the given buffer the hashtable elements.
070: * @param buffer the buffer on which append the Hashtable
071: * @param vector the vector where are the elements
072: */
073: public static void xmlVector(StringBuffer buffer, Vector vector) {
074: if (vector.size() > 0) {
075: for (Enumeration e = vector.elements(); e.hasMoreElements();) {
076: Object o = e.nextElement();
077: buffer.append(o.toString());
078: buffer.append("\n");
079: }
080: }
081: }
082:
083: /**
084: * Append to the given buffer the hashtable elements.
085: * @param buffer the buffer on which append the Hashtable
086: * @param hashtable the hashtable where are the elements
087: */
088: public static void xmlHashtable(StringBuffer buffer,
089: Hashtable hashtable) {
090: xmlHashtable(buffer, hashtable, "");
091: }
092:
093: /**
094: * Append to the given buffer the hashtable elements.
095: * @param buffer the buffer on which append the Hashtable
096: * @param hashtable the hashtable where are the elements
097: * @param indent the indent to put before the lines
098: */
099: public static void xmlHashtable(StringBuffer buffer,
100: Hashtable hashtable, String indent) {
101: if (hashtable.size() > 0) {
102: for (Enumeration e = hashtable.elements(); e
103: .hasMoreElements();) {
104: Object o = e.nextElement();
105: buffer.append(indent + o.toString());
106: buffer.append("\n");
107: }
108: }
109: }
110:
111: }
|