001: /*
002: * %W% %G% Sun Microsystems
003: *
004: * Copyright 2000 Sun Microsystems, Inc. All rights reserved.
005: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
006: */
007:
008: package com.sun.portal.wireless.taglibs.ab;
009:
010: import javax.servlet.jsp.*;
011: import javax.servlet.jsp.tagext.*;
012: import java.util.*;
013: import com.sun.portal.wireless.taglibs.base.*;
014:
015: import com.sun.addressbook.Entry;
016: import com.sun.addressbook.Element;
017: import com.sun.addressbook.Group;
018:
019: /**
020: * ABEntryTag - tag that represents an ical DateTime bean
021: *
022: * @author Mihir Sambhus
023: * @version 1.0
024: * @see com.iplanet.portalserver.ical.DateTime
025: */
026:
027: public class ABEntryTag extends BeanTag {
028:
029: /**
030: * The entryid for the bean
031: */
032: protected String entryid = null;
033:
034: /**
035: * The element type for the bean .. can be Element.GROUP, Element.ENTRY,
036: * Element.ADDRESSBOOK and Element.UNSPECIFIED
037: */
038: protected int elementtype = Element.UNSPECIFIED;
039:
040: /**
041: * Get the entryid
042: *
043: * @return the entryid
044: */
045: public String getEntryid() {
046: return entryid;
047: }
048:
049: /**
050: * Set the entryid
051: *
052: * @param entryid the entryid String
053: */
054: public void setEntryid(String entryid) {
055: this .entryid = evalAttribute(entryid);
056: }
057:
058: /**
059: * Get the element type
060: *
061: * @return the element type
062: */
063: public String getElementtype() {
064: if (elementtype == Element.ENTRY) {
065: return "contact";
066: } else if (elementtype == Element.GROUP) {
067: return "group";
068: } else {
069: // default type is entry
070: return "contact";
071: }
072: }
073:
074: /**
075: * Set the element type
076: *
077: * @param type the element type String
078: */
079: public void setElementtype(String elementtype) {
080: if (evalAttribute(elementtype).equals("contact")) {
081: this .elementtype = Element.ENTRY;
082: } else if (evalAttribute(elementtype).equals("group")) {
083: this .elementtype = Element.GROUP;
084: } else {
085: // default is of type entry
086: this .elementtype = Element.ENTRY;
087: }
088: }
089:
090: /**
091: * Create a new Entry bean object
092: *
093: * @return the Entry object
094: */
095: public Object newBean() throws Exception {
096: if (elementtype == Element.ENTRY) {
097: return new Entry();
098: } else if (elementtype == Element.GROUP) {
099: return new Group();
100: }
101: // default .. return entry
102: return new Entry();
103: }
104:
105: /**
106: * Find the bean
107: *
108: * If the "entryid" attribute is specified then get
109: * the bean from collection in the context.
110: *
111: * Otherwise call super.findBean()
112: *
113: * @return the found bean
114: */
115: public Object findBean() throws Exception {
116:
117: // Override super.findBean only for the case where entryid is
118: // specified
119: if (entryid == null) {
120: return super .findBean();
121: }
122:
123: Element element = null;
124:
125: // try to retrieve address book context from pagecontext ..
126: ABContext abContext;
127:
128: // get context; allow exception to be thrown
129: abContext = ABContext.getContext(pageContext);
130:
131: if (abContext == null) {
132: throw new Exception(
133: "ABEntryTag.findBean(): Element bean corresponding to entryid"
134: + " not found in the collection");
135: }
136:
137: element = abContext.getEntry(Integer.parseInt(entryid));
138:
139: if (element == null) {
140: throw new Exception(
141: "ABEntryTag.findBean(): Element bean corresponding to entryid"
142: + " not found in the collection");
143: }
144:
145: if (id != null) {
146: pageContext.setAttribute(id, element);
147: }
148:
149: return element;
150: }
151:
152: /**
153: * Cleanup
154: *
155: */
156: public void release() {
157: super.release();
158: entryid = null;
159: }
160: }
|