KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > simya > ldap > taglib > Connect


1 package net.simya.ldap.taglib;
2
3 import javax.servlet.jsp.tagext.*;
4 import javax.servlet.jsp.*;
5 import javax.naming.Context JavaDoc;
6 import javax.naming.directory.DirContext JavaDoc;
7 import javax.naming.NamingException JavaDoc;
8 import java.util.Enumeration JavaDoc;
9 import net.simya.ldap.beans.*;
10
11 public class Connect
12        extends BodyTagSupport
13 {
14     private LdapConnectBean connectBean = null;
15     
16     private String JavaDoc url = null;
17     private String JavaDoc dn = null;
18     private String JavaDoc password = null;
19     private String JavaDoc ssl = null;
20     private String JavaDoc referral = null;
21     private String JavaDoc authtype = null;
22     
23     public int doStartTag()
24     throws JspException
25     {
26         connectBean = new LdapConnectBean();
27                 
28         for ( Enumeration JavaDoc e = pageContext.getAttributeNamesInScope( pageContext.PAGE_SCOPE ); e.hasMoreElements(); )
29         {
30             String JavaDoc property = (String JavaDoc) e.nextElement();
31             connectBean.setProperty( property, pageContext.getAttribute( property ) );
32         }
33         
34         if ( url != null )
35             connectBean.setProperty( Context.PROVIDER_URL, url );
36         if ( dn != null )
37             connectBean.setProperty( Context.SECURITY_PRINCIPAL, dn );
38         if ( password != null )
39             connectBean.setProperty( Context.SECURITY_CREDENTIALS, password );
40         if ( (ssl != null) && (ssl.equalsIgnoreCase("on")) )
41             connectBean.setProperty(Context.SECURITY_PROTOCOL, "ssl");
42         if ( referral != null )
43             connectBean.setProperty(Context.REFERRAL, referral);
44         if ( authtype != null )
45             connectBean.setProperty(Context.REFERRAL, referral);
46         
47         try
48         {
49             connectBean.connect();
50         } catch ( NamingException JavaDoc ex )
51         {
52             throw new LdapTaglibException( ex );
53         }
54         
55         return EVAL_BODY_TAG;
56     }
57     
58     public int doAfterBody()
59     throws JspException
60     {
61         try
62         {
63             connectBean.disconnect();
64         } catch ( NamingException JavaDoc ex )
65         {
66             throw new LdapTaglibException( ex );
67         }
68         BodyContent body = getBodyContent();
69         try
70         {
71             //System.out.println( "Exiting : " + getPreviousOut() );
72
body.writeOut( getPreviousOut() );
73         }
74         catch ( java.io.IOException JavaDoc ex )
75         {
76             throw new JspTagException( "IO Error" );
77         }
78         //body.clearBody();
79
return SKIP_BODY;
80     }
81     
82     public void release()
83     {
84         connectBean = null;
85         url = null;
86         password = null;
87         dn = null;
88         ssl = null;
89         referral=null;
90         authtype=null;
91     }
92     
93     public DirContext JavaDoc getContext()
94     {
95         return connectBean.getContext();
96     }
97     
98     public java.util.Hashtable JavaDoc getEnv()
99     {
100         return connectBean.getEnv();
101     }
102     
103     public Object JavaDoc getProperty( String JavaDoc name )
104     {
105         return connectBean.getProperty( name );
106     }
107
108     public String JavaDoc getDn() { return this.dn; }
109     public void setDn(String JavaDoc dn) { this.dn = dn; }
110
111     public String JavaDoc getPassword() { return this.password; }
112     public void setPassword(String JavaDoc password) { this.password = password; }
113
114     public String JavaDoc getUrl() { return this.url; }
115     public void setUrl(String JavaDoc url) { this.url = url; }
116     
117     public String JavaDoc getSsl() { return this.url; }
118     public void setSsl(String JavaDoc ssl) { this.ssl = ssl; }
119     
120     public String JavaDoc getReferral() { return this.referral; }
121
122     public void setReferral(String JavaDoc referral) { this.referral = referral; }
123
124     
125     public String JavaDoc getAuthtype()
126     {
127     return this.authtype;
128     }
129
130     public void setAuthtype(String JavaDoc authtype)
131     {
132     this.authtype = authtype;
133     }
134 }
135
Popular Tags