ehatcher 2003/05/29 10:22:48 Added: contributions/taglib/WEB-INF/classes/com/netwebapps/taglib/search ColumnTag.java ColumnTagTei.java FieldTag.java FieldTagTei.java Log: new files from Bryan LaPlante Revision Changes Path 1.1 jakarta-lucene-sandbox/contributions/taglib/WEB-INF/classes/com/netwebapps/taglib/search/ColumnTag.java Index: ColumnTag.java =================================================================== /* * Created on May 24, 2003 */ package com.netwebapps.taglib.search; import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Iterator; import java.util.Set; import javax.servlet.jsp.JspException; import javax.servlet.jsp.PageContext; import javax.servlet.jsp.tagext.BodyTagSupport; /** * @company Network Web Application * @url http://www.netwebapps.com * @author Bryan LaPlante */ public class ColumnTag extends BodyTagSupport{ private Object parent = null; private Set fieldSet = null; private ArrayList fieldArray = new ArrayList(); private Iterator fieldNames = null; private Iterator nextField = null; private Method getFieldsMethod = null; private boolean abort = false; public boolean throwOnException = false; public String columnName = ""; public boolean runOnce = false; public int columnCount = 0; public int doStartTag() throws JspException{ parent = findAncestorWithClass(this,com.netwebapps.taglib.search.SearchTag.class); if(runOnce && getLoopCount() > 1){ abort = true; return SKIP_BODY; } try { getFieldsMethod = (Method) parent.getClass().getMethod("getFields",null); fieldSet = (Set) getFieldsMethod.invoke(parent, null); } catch (SecurityException e) { if(throwOnException){ throw new JspException("A security violation occurred: " + e); } abort = true; } catch (IllegalArgumentException e) { if(throwOnException){ throw new JspException("IllegalArgumentException: " + e); } abort = true; } catch (NoSuchMethodException e) { if(throwOnException){ throw new JspException("Unable to declair the getField method : " + e); } abort = true; } catch (IllegalAccessException e) { if(throwOnException){ throw new JspException("Access denied: " + e); } abort = true; } catch (InvocationTargetException e) { if(throwOnException){ throw new JspException("This tag must be nested in a Search tag in order to work: " + e); } abort = true; }catch(NullPointerException e){ if(throwOnException){ throw new JspException(e); } abort = true; } if(abort){ return SKIP_BODY; } if(fieldSet != null){ nextField = fieldSet.iterator(); while(nextField.hasNext()){ fieldArray.add(nextField.next()); } columnCount = fieldSet.size(); pageContext.setAttribute(getId(),this,PageContext.PAGE_SCOPE); return EVAL_BODY_AGAIN; } return SKIP_BODY; } public void doInitBody() throws JspException{ if(!abort){ if (fieldArray.size() > 0) { fieldNames = fieldArray.iterator(); if(fieldNames.hasNext()){ columnName = (String) fieldNames.next(); columnCount = fieldSet.size(); pageContext.setAttribute(getId(),this,PageContext.PAGE_SCOPE); } } } } public int doAfterBody() throws JspException{ if(abort){ return SKIP_BODY; } columnName = ""; try{ getBodyContent().writeOut(getPreviousOut()); getBodyContent().clearBody(); } catch(IOException e){ throw new JspException(e.toString()); } if(fieldNames != null){ if(fieldNames.hasNext()){ columnName = (String) fieldNames.next(); columnCount = fieldSet.size(); pageContext.setAttribute(getId(),this,PageContext.PAGE_SCOPE); return EVAL_BODY_AGAIN; } } return SKIP_BODY; } public void release(){ parent = null; fieldSet = null; fieldArray = null; fieldNames = null; nextField = null; getFieldsMethod = null; } private int getLoopCount() throws JspException{ Field getLoopCountMember = null; int rc = 0; try { getLoopCountMember = (Field) parent.getClass().getField("loopCount"); rc = new Integer(getLoopCountMember.get(parent).toString()).intValue(); } catch (SecurityException e) { if(throwOnException){ throw new JspException("A security violation occurred: " + e); } } catch (NoSuchFieldException e) { if(throwOnException){ throw new JspException("Unable to find the loopCount field : " + e); } }catch(IllegalAccessException e){ if(throwOnException){ throw new JspException("Access denied: " + e); } }catch(IllegalArgumentException e){ if(throwOnException){ throw new JspException("Bad argument: " + e); } } return rc; } /** * @param string */ public void setcolumnName(String columnName) { this.columnName = columnName; } /** * @param b */ public void setThrowOnException(String b) { throwOnException = new Boolean(b).booleanValue(); } public void setThrowOnException(boolean b) { throwOnException = b; } public void setRunOnce(boolean b){ runOnce = b; } public void setRunOnce(String b){ runOnce = new Boolean(b).booleanValue(); } } 1.1 jakarta-lucene-sandbox/contributions/taglib/WEB-INF/classes/com/netwebapps/taglib/search/ColumnTagTei.java Index: ColumnTagTei.java =================================================================== /* * Created on May 24, 2003 */ package com.netwebapps.taglib.search; /** * @company Network Web Application * @url http://www.netwebapps.com * @author Bryan LaPlante */ import javax.servlet.jsp.tagext.*; public class ColumnTagTei extends TagExtraInfo { public ColumnTagTei(){ } /* * VariableInfo is provided by the servlet container and allows the * FieldTag class to output it's tag variables to the PageContext at runtime * @see javax.servlet.jsp.tagext.TagExtraInfo#getVariableInfo(javax.servlet.jsp.tagext.TagData) */ public VariableInfo[] getVariableInfo(TagData tagdata) { VariableInfo avariableinfo[] = new VariableInfo[1]; avariableinfo[0] = new VariableInfo(tagdata.getId(),"com.netwebapps.taglib.search.ColumnTag", true, VariableInfo.NESTED); return avariableinfo; } } 1.1 jakarta-lucene-sandbox/contributions/taglib/WEB-INF/classes/com/netwebapps/taglib/search/FieldTag.java Index: FieldTag.java =================================================================== /* * Created on May 23, 2003 * */ package com.netwebapps.taglib.search; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import javax.servlet.jsp.JspException; import javax.servlet.jsp.PageContext; import javax.servlet.jsp.tagext.TagSupport; /** * @company Network Web Application * @url http://www.netwebapps.com * @author Bryan LaPlante */ public class FieldTag extends TagSupport{ public String name = ""; public boolean throwOnException = false; public String value = ""; private boolean abort = false; /* (non-Javadoc) * @see javax.servlet.jsp.tagext.BodyTagSupport#doEndTag() */ public int doStartTag() throws JspException { Object parent = findAncestorWithClass(this,com.netwebapps.taglib.search.SearchTag.class); try { Method getFieldMethod = parent.getClass().getMethod("getField", new Class[] {Class.forName("java.lang.String")}); value = getFieldMethod.invoke(parent, new String[] {name}).toString(); } catch (SecurityException e) { if(throwOnException){ throw new JspException("A security violation occurred: " + e); } abort = true; } catch (NoSuchMethodException e) { if(throwOnException){ throw new JspException("Unable to declair the getField method : " + e); } abort = true; } catch (ClassNotFoundException e) { if(throwOnException){ throw new JspException("ClassNotFoundException: " + e); } }catch (IllegalAccessException e) { if(throwOnException){ throw new JspException("Access denied: " + e); } abort = true; }catch (InvocationTargetException e) { if(throwOnException){ throw new JspException("This tag must be nested in a Search tag in order to work: " + e); } abort = true; }catch(NullPointerException e){ if(throwOnException){ throw new JspException("This tag must be nested in a Search tag in order to work: " + e); } abort = true; } if(abort){ pageContext.setAttribute(getId(),this,PageContext.PAGE_SCOPE); return SKIP_BODY; } pageContext.setAttribute(getId(),this,PageContext.PAGE_SCOPE); return EVAL_BODY_INCLUDE; } public void release(){ name = ""; throwOnException = false; value = ""; } /** * @param string */ public void setName(String string) { name = string; } /** * @param b */ public void setThrowOnException(String b) { throwOnException = new Boolean(b).booleanValue(); } public void setThrowOnException(boolean b) { throwOnException = b; } } 1.1 jakarta-lucene-sandbox/contributions/taglib/WEB-INF/classes/com/netwebapps/taglib/search/FieldTagTei.java Index: FieldTagTei.java =================================================================== /* * Created on May 24, 2003 */ package com.netwebapps.taglib.search; /** * @company Network Web Application * @url http://www.netwebapps.com * @author Bryan LaPlante */ import javax.servlet.jsp.tagext.*; public class FieldTagTei extends TagExtraInfo { public FieldTagTei(){ } /* * VariableInfo is provided by the servlet container and allows the * FieldTag class to output it's tag variables to the PageContext at runtime * @see javax.servlet.jsp.tagext.TagExtraInfo#getVariableInfo(javax.servlet.jsp.tagext.TagData) */ public VariableInfo[] getVariableInfo(TagData tagdata) { VariableInfo avariableinfo[] = new VariableInfo[1]; avariableinfo[0] = new VariableInfo(tagdata.getId(),"com.netwebapps.taglib.search.FieldTag", true, VariableInfo.NESTED); return avariableinfo; } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]