001: /**
002: * %W% %G% Sun Microsystems
003: * Copyright 2002 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.wireless.taglibs.ab;
014:
015: import java.beans.*;
016: import javax.servlet.jsp.*;
017:
018: import com.sun.portal.wireless.taglibs.base.BeanSupport;
019: import com.sun.portal.wireless.taglibs.base.Edit;
020: import com.sun.portal.log.common.PortalLogger;
021:
022: import com.sun.addressbook.Group;
023: import com.sun.addressbook.Element;
024: import java.util.StringTokenizer;
025: import java.util.logging.Logger;
026:
027: /**
028: * ABDeleteGroupMembersTag - add group members to a group
029: *
030: * This class writes the group members to the Group bean found in its parent
031: * entry tag or retrieved from pagecontext using name attribute.
032: *
033: * Attributes:
034: *
035: * members
036: * ',' separated list of element ids to add to the Group
037: * groupid
038: * element from which to delete the members
039: *
040: */
041: public class ABDeleteGroupMembersTag extends ABBaseCommandTag {
042:
043: // Create a logger for this class
044: private static Logger debugLogger = PortalLogger
045: .getLogger(ABDeleteGroupMembersTag.class);
046:
047: /*
048: * Member ids of the group to be deleted
049: */
050: protected String members = null;
051:
052: /**
053: * Get the members attribute
054: *
055: * @return set the members attribute
056: */
057: public String getMembers() {
058: return members;
059: }
060:
061: /**
062: * Set the members attribute
063: *
064: * @param set the members attribute
065: */
066: public void setMembers(String members) {
067: this .members = evalAttribute(members);
068: }
069:
070: /*
071: * groupid of the address book entry to be deleted
072: */
073: protected String groupid = null;
074:
075: /**
076: * Get the groupid attribute
077: *
078: * @return the groupid attribute
079: */
080: public String getGroupid() {
081: return groupid;
082: }
083:
084: /**
085: * Set the groupid attribute
086: *
087: * @param set the groupid attribute
088: */
089: public void setGroupid(String groupid) {
090: this .groupid = evalAttribute(groupid);
091: }
092:
093: /**
094: * Verifying if the groupid attribute exists..
095: *
096: * @exception JspException
097: */
098: public void verifyGroupid() throws JspException {
099: // groupid is mandatory attribute for modify. delete
100: if (groupid == null) {
101: throw new JspException(
102: "ABDeleteGroupMembersTag.verifyGroupid(): 'groupid' attribute not specified");
103: }
104: }
105:
106: /**
107: * Edit bean...
108: */
109: private Edit edit = null;
110:
111: /**
112: * Set the edit bean
113: */
114: public void setEdit(String edit) {
115: this .edit = (Edit) pageContext.getAttribute(edit);
116: }
117:
118: /**
119: * Execute the delete group members command on the address book.
120: * Returns the command status.
121: * If the command fails then the tag body is included,
122: * Else if the command succeeds then the tag body is skipped.
123: *
124: * @return true if the command succeeds.
125: * false if the command fails.
126: * @exception JspException
127: */
128: public boolean execute() throws JspException {
129:
130: // groupid attribute must be present for delete.. if not jsp
131: // exception is throw
132: verifyGroupid();
133:
134: // Get the contactDB object interacting with the Backend LDAP server
135: ContactDB contactDB = getContactDB();
136: // Get the element object corresponsing to the groupid, from context
137: Element element = getEntry(Integer.parseInt(groupid));
138: if (element.getElementType() != Element.GROUP) {
139: debugLogger.fine("PSMA_CSPWTA0009");
140: getABContext().setErrorCode("");
141: return false;
142: }
143: Group group = (Group) element;
144:
145: if (edit != null) {
146: members = edit.editString(members.toString());
147: }
148:
149: if ((members != null) && (!members.equals(""))) {
150: // Delete all entries individually to the group using
151: // deleteElementFromGroup
152: StringTokenizer tok = new StringTokenizer(members, ",");
153: while (tok.hasMoreTokens()) {
154: Element elemToDel = getABContext().getGroupmember(
155: Integer.parseInt(tok.nextToken()));
156: if (!contactDB.deleteElementFromGroup(elemToDel, group)) {
157: debugLogger.fine("PSMA_CSPWTA0010");
158: getABContext().setErrorCode("");
159: return false;
160: }
161: }
162: }
163:
164: return true;
165: }
166:
167: /**
168: * Cleanup
169: */
170: public void release() {
171: super.release();
172: members = null;
173: edit = null;
174: }
175:
176: }
|