001: /*
002: * This file is part of the QuickServer library
003: * Copyright (C) 2003-2005 QuickServer.org
004: *
005: * Use, modification, copying and distribution of this software is subject to
006: * the terms and conditions of the GNU Lesser General Public License.
007: * You should have received a copy of the GNU LGP License along with this
008: * library; if not, you can download a copy from <http://www.quickserver.org/>.
009: *
010: * For questions, suggestions, bug-reports, enhancement-requests etc.
011: * visit http://www.quickserver.org
012: *
013: */
014:
015: package org.quickserver.util.xmlreader;
016:
017: import java.util.*;
018:
019: /**
020: * This class encapsulate the IP based Filter config.
021: * The xml is <ip-filter>...</ip-filter><br>
022: * <b>Note:</b> Make sure that access from 127.0.0.1 is allowed at
023: * all times, else some of the QsAdmin command will fail.
024: * @author Akshathkumar Shetty
025: * @since 1.3.3
026: */
027: public class IpFilterConfig implements java.io.Serializable {
028: private ArrayList ipCollection = null;
029: private boolean enable = false;
030: private boolean allowAccess = false;
031:
032: public IpFilterConfig() {
033: ipCollection = new ArrayList();
034: }
035:
036: /**
037: * Adds a Client Ip Address to the list
038: */
039: public void addClientIpAddress(String clientIpAddress) {
040: if (clientIpAddress != null) {
041: ipCollection.add(clientIpAddress);
042: }
043: }
044:
045: /**
046: * Returns ClientIpAddress collection
047: */
048: public ArrayList getIpCollection() {
049: return ipCollection;
050: }
051:
052: public Iterator iterator() {
053: return ipCollection.iterator();
054: }
055:
056: /**
057: * Sets the IP filter enable flag.
058: * XML Tag: <ip-filter><enable>true</enable></ip-filter>
059: * Allowed values = <code>true</code> | <code>false</code>
060: * @see #getEnable
061: */
062: public void setEnable(boolean enable) {
063: this .enable = enable;
064: }
065:
066: /**
067: * Returns the IP filter enable flag.
068: * @see #setEnable
069: */
070: public boolean getEnable() {
071: return enable;
072: }
073:
074: /**
075: * Sets the allow access flag.
076: * XML Tag: <ip-filter><allow-access>true</allow-access></ip-filter>
077: * Allowed values = <code>true</code> | <code>false</code>
078: * @see #getAllowAccess
079: */
080: public void setAllowAccess(boolean enable) {
081: this .allowAccess = enable;
082: }
083:
084: /**
085: * Returns the allow access flag.
086: * @see #setAllowAccess
087: */
088: public boolean getAllowAccess() {
089: return allowAccess;
090: }
091:
092: /**
093: * Returns XML config of this class.
094: * @since 1.3
095: */
096: public String toXML(String pad) {
097: if (pad == null)
098: pad = "";
099: StringBuffer sb = new StringBuffer();
100: sb.append(pad + "<ip-filter>\n");
101: sb.append(pad + "\t<enable>" + getEnable() + "</enable>\n");
102: sb.append(pad + "\t<allow-access>" + getAllowAccess()
103: + "</allow-access>\n");
104: sb.append(pad + "\t<ip-collection>\n");
105: Iterator iterator = iterator();
106: while (iterator.hasNext()) {
107: String cip = (String) iterator.next();
108: sb.append(pad + "\t\t<client-ip-address>" + cip
109: + "</client-ip-address>\n");
110: }
111: sb.append(pad + "\t</ip-collection>\n");
112: sb.append(pad + "</ip-filter>\n");
113: return sb.toString();
114: }
115: }
|