001: package migration.modules.ldap;
002:
003: import java.util.Hashtable;
004: import java.util.Vector;
005: import java.util.Enumeration;
006: import com.iplanet.portalserver.parser.ParseOutput;
007:
008: public class Privilege extends Element implements ParseOutput {
009: public Vector vallist;
010: public Vector denylist;
011: public Vector allowlist;
012: public Vector rpermlist;
013: public Vector wpermlist;
014: public String booleanval;
015: public Hashtable _atts;
016: public String name;
017:
018: public void process(String nm, Vector elems, Hashtable atts,
019: String pcdata) {
020: type = Element.PRIVILEGE_I;
021: int numElems = elems.size();
022: for (int i = 0; i < numElems; i++) {
023: Element el = (Element) elems.elementAt(i);
024: switch (el.type) {
025: case Element.DENYLST_I:
026: if (denylist == null)
027: denylist = new Vector();
028: denylist.addElement(el.pcdata);
029: break;
030: case Element.ALLOWLST_I:
031: if (allowlist == null)
032: allowlist = new Vector();
033: allowlist.addElement(el.pcdata);
034: break;
035: case Element.READPERM_I:
036: if (rpermlist == null)
037: rpermlist = new Vector();
038: rpermlist.addElement(el.pcdata);
039: break;
040: case Element.WRITEPERM_I:
041: if (wpermlist == null)
042: wpermlist = new Vector();
043: wpermlist.addElement(el.pcdata);
044: break;
045: case Element.VALUE_I:
046: if (vallist == null)
047: vallist = new Vector();
048: vallist.addElement(el.pcdata);
049: break;
050: }
051: }
052: _atts = atts;
053: name = (String) _atts.get(Element.NAME);
054: if (name == null) {
055: System.out.println(bundle.getString("invxml") + nm);
056: System.exit(1);
057: }
058: String val = (String) _atts.remove(Element.VALUE);
059: if (val != null) {
060: _atts.put(Element.ACVALUE, val);
061: booleanval = val;
062: } else if (vallist != null) {
063: _atts.put(Element.ACVALUE, vallist.elementAt(0));
064: booleanval = val;
065: }
066: _atts.remove(Element.NAME);
067: if (denylist != null)
068: _atts.put(Element.DENYLIST, denylist.elements());
069: if (allowlist != null)
070: _atts.put(Element.ALLOWLIST, allowlist.elements());
071: if (wpermlist != null)
072: _atts.put(Element.WRITEPERM, wpermlist.elements());
073: if (rpermlist != null)
074: _atts.put(Element.READPERM, rpermlist.elements());
075: }
076:
077: public String toString() {
078: return "Privilege : name=" + name + " Att=" + _atts;
079: }
080:
081: public void setRPermListAttribute(Enumeration en) {
082: populate_vector(en, (rpermlist = new Vector()));
083: }
084:
085: public void setWPermListAttribute(Enumeration en) {
086: populate_vector(en, (wpermlist = new Vector()));
087: }
088:
089: public void setDenyListAttribute(Enumeration en) {
090: populate_vector(en, (denylist = new Vector()));
091: }
092:
093: public void setAllowListAttribute(Enumeration en) {
094: populate_vector(en, (allowlist = new Vector()));
095: }
096:
097: public void addAttribute(String inname, Object stuff) {
098: if (_atts == null)
099: _atts = new Hashtable();
100: _atts.put(inname, stuff);
101: }
102:
103: public String toXML() {
104: StringBuffer xml = new StringBuffer(200);
105: String tmp;
106: xml.append("<").append(PRIV_E).append(" name=\"").append(name)
107: .append("\"\n");
108:
109: if (_atts != null && (tmp = (String) _atts.get(TYPE)) != null)
110: xml.append(" ").append(TYPE).append("=\"").append(tmp)
111: .append("\"\n");
112:
113: if (_atts != null && (tmp = (String) _atts.get(DESC)) != null)
114: xml.append(" ").append(DESC).append("=\"").append(tmp)
115: .append("\"\n");
116:
117: if (_atts != null && (tmp = (String) _atts.get(INDEX)) != null)
118: xml.append(" ").append(INDEX).append("=\"").append(tmp)
119: .append("\"\n");
120:
121: if (booleanval != null)
122: xml.append(" ").append(VALUE).append("=\"").append(
123: booleanval).append("\"\n");
124:
125: xml.append(" >\n");
126: xml.append(constructXMLElement(WRITEPERM, wpermlist));
127: xml.append(constructXMLElement(READPERM, rpermlist));
128: xml.append(constructXMLElement(ALLOWLIST, allowlist));
129: xml.append(constructXMLElement(DENYLIST, denylist));
130: xml.append("</").append(PRIV_E).append(">\n");
131: return xml.toString();
132: }
133: }
|