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 Attribute extends Element implements ParseOutput {
009: public Vector vallist;
010: public Vector rpermlist;
011: public Vector wpermlist;
012: public Vector choicelist;
013: public Hashtable _atts;
014: public String name;
015: boolean _debug = false;
016:
017: public void process(String _name, Vector elems, Hashtable atts,
018: String pcdata) {
019: if (_debug) {
020: System.out.println("Attribute:process:name=" + _name
021: + ", pcdata=" + pcdata);
022: }
023:
024: type = Element.ATTRIBUTE_I;
025: int numElems = elems.size();
026: for (int i = 0; i < numElems; i++) {
027: Element el = (Element) elems.elementAt(i);
028: switch (el.type) {
029: case Element.VALUE_I:
030: if (vallist == null)
031: vallist = new Vector();
032: vallist.addElement(el.pcdata);
033: break;
034: case Element.READPERM_I:
035: if (rpermlist == null)
036: rpermlist = new Vector();
037: rpermlist.addElement(el.pcdata);
038: break;
039: case Element.WRITEPERM_I:
040: if (wpermlist == null)
041: wpermlist = new Vector();
042: wpermlist.addElement(el.pcdata);
043: break;
044: case Element.CHOICELST_I:
045: if (choicelist == null)
046: choicelist = new Vector();
047: choicelist.addElement(el.pcdata);
048: break;
049: }
050: }
051: _atts = atts;
052: name = (String) _atts.get(Element.NAME);
053: if (name == null) {
054: System.out.println(bundle.getString("invxml") + _name);
055: System.exit(1);
056: }
057: _atts.remove(Element.NAME);
058: if (wpermlist != null)
059: _atts.put(Element.WRITEPERM, wpermlist.elements());
060: if (rpermlist != null)
061: _atts.put(Element.READPERM, rpermlist.elements());
062: if (vallist != null)
063: _atts.put(Element.ATTVALUE, vallist.elements());
064: if (choicelist != null)
065: _atts.put(Element.CHOICEVALUE, choicelist.elements());
066: }
067:
068: public void addAttribute(String inname, Object stuff) {
069: if (_atts == null)
070: _atts = new Hashtable();
071: _atts.put(inname, stuff);
072: }
073:
074: public void setValues(Enumeration en) {
075: populate_vector(en, (vallist = new Vector()));
076: }
077:
078: public void setRPermListAttribute(Enumeration en) {
079: populate_vector(en, (rpermlist = new Vector()));
080: }
081:
082: public void setWPermListAttribute(Enumeration en) {
083: populate_vector(en, (wpermlist = new Vector()));
084: }
085:
086: public void setChoiceListAttribute(Enumeration en) {
087: populate_vector(en, (choicelist = new Vector()));
088: }
089:
090: public String toString() {
091: return "TODO";
092: }
093:
094: public String toXML() {
095: StringBuffer xml = new StringBuffer(200);
096: String tmp;
097: xml.append("<").append(ATT_E).append(" name=\"").append(name)
098: .append("\"\n");
099:
100: if ((tmp = (String) _atts.get(TYPE)) != null)
101: xml.append(" ").append(TYPE).append("=\"").append(tmp)
102: .append("\"\n");
103:
104: if ((tmp = (String) _atts.get(DESC)) != null)
105: xml.append(" ").append(DESC).append("=\"").append(tmp)
106: .append("\"\n");
107:
108: if ((tmp = (String) _atts.get(INDEX)) != null)
109: xml.append(" ").append(INDEX).append("=\"").append(tmp)
110: .append("\"\n");
111:
112: if ((tmp = (String) _atts.get(USERCONFIGURABLE)) != null)
113: xml.append(" ").append(USERCONFIGURABLE).append("=\"")
114: .append(tmp).append("\"\n");
115:
116: xml.append(" >\n");
117: xml.append(constructXMLElement(VALUELIST, vallist));
118: xml.append(constructXMLElement(WRITEPERM, wpermlist));
119: xml.append(constructXMLElement(READPERM, rpermlist));
120: xml.append(constructXMLElement(CHOICEVALUE, choicelist));
121: xml.append("</").append(ATT_E).append(">\n");
122: return xml.toString();
123: }
124: }
|