KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.simya.ldap.taglib;
2
3 import javax.servlet.jsp.tagext.*;
4 import javax.servlet.jsp.*;
5 import javax.naming.directory.DirContext JavaDoc;
6 import javax.naming.directory.Attribute JavaDoc;
7 import javax.naming.NamingException JavaDoc;
8 import net.simya.ldap.beans.*;
9
10 public class Query
11        extends BodyTagSupport
12 {
13     private LdapSearchBean searchBean = new LdapSearchBean();
14
15     //private String id = null;
16

17     public int doStartTag()
18     throws JspException
19     {
20         Connect connectTag = (Connect) getParent();
21         if ( connectTag == null )
22             throw new JspTagException( "<query> tag should be child node of <connect> tag." );
23
24         try
25         {
26             searchBean.search( connectTag.getContext() );
27             if ( !searchBean.next() )
28                 return SKIP_BODY;
29         } catch (NamingException JavaDoc ex)
30         {
31             throw new LdapTaglibException( ex );
32         }
33         if ( id != null )
34             pageContext.setAttribute( id, searchBean );
35         return EVAL_BODY_TAG;
36     }
37
38     public int doAfterBody()
39     throws JspException
40     {
41         BodyContent body = getBodyContent();
42         try
43         {
44             body.writeOut( getPreviousOut() );
45         }
46         catch ( java.io.IOException JavaDoc ex )
47         {
48             throw new JspTagException( "IO Error" );
49         }
50
51         body.clearBody();
52         try
53         {
54             if ( searchBean.next() )
55                 return EVAL_BODY_TAG;
56         } catch (NamingException JavaDoc ex)
57         {
58             throw new LdapTaglibException( ex );
59         }
60         return SKIP_BODY;
61     }
62
63     public Attribute JavaDoc getAttribute( String JavaDoc name )
64     throws NamingException JavaDoc
65     {
66         return searchBean.getAttribute( name );
67     }
68
69     public void release()
70     {
71         searchBean = new LdapSearchBean();
72         id=null;
73     }
74
75     public void setFilter( String JavaDoc filter ){ searchBean.setFilter( filter );}
76
77     public void setAttributes( String JavaDoc attributes ){ searchBean.setReturningAttributes( attributes );}
78
79     public void setLimit( String JavaDoc limit ){ searchBean.setLimit( limit ); }
80
81     public void setBasedn( String JavaDoc basedn ){ searchBean.setSearchBase( basedn );}
82
83     public String JavaDoc getDN (){ return searchBean.getDN();}
84
85     public void setScope (String JavaDoc scope) { searchBean.setScope(scope);}
86     public String JavaDoc getScope (){ return searchBean.getScope();}
87
88     /*
89     public String getId()
90     {
91         return this.id;
92     }
93
94     public void setId(String id)
95     {
96         this.id = id;
97     }
98     */

99 }
100
Popular Tags