1 package net.simya.ldap.taglib; 2 3 import javax.servlet.jsp.tagext.*; 4 import javax.servlet.jsp.*; 5 import javax.naming.directory.DirContext ; 6 import javax.naming.directory.Attribute ; 7 import javax.naming.NamingException ; 8 import net.simya.ldap.beans.*; 9 10 public class Query 11 extends BodyTagSupport 12 { 13 private LdapSearchBean searchBean = new LdapSearchBean(); 14 15 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 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 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 ex) 57 { 58 throw new LdapTaglibException( ex ); 59 } 60 return SKIP_BODY; 61 } 62 63 public Attribute getAttribute( String name ) 64 throws NamingException 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 filter ){ searchBean.setFilter( filter );} 76 77 public void setAttributes( String attributes ){ searchBean.setReturningAttributes( attributes );} 78 79 public void setLimit( String limit ){ searchBean.setLimit( limit ); } 80 81 public void setBasedn( String basedn ){ searchBean.setSearchBase( basedn );} 82 83 public String getDN (){ return searchBean.getDN();} 84 85 public void setScope (String scope) { searchBean.setScope(scope);} 86 public String getScope (){ return searchBean.getScope();} 87 88 99 } 100 | Popular Tags |