[Idrs-commit] CVS: Idrs/dev/src/net/sourceforge/idrs/core/report GenTag.java,NONE,1.1 InputChunk.jav
Brought to you by:
bigman921
|
From: Marc B. <big...@us...> - 2002-04-13 16:06:41
|
Update of /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/core/report
In directory usw-pr-cvs1:/tmp/cvs-serv29359/dev/src/net/sourceforge/idrs/core/report
Modified Files:
YesNo.java
Added Files:
GenTag.java InputChunk.java
Log Message:
added YesNo and formInput tags
--- NEW FILE: GenTag.java ---
/*
GenTag.java
Copyright (C) 2002 Marc Boorshtein
The contents of this file are subject to the Mozilla Public License Version 1.0 (the License);
you may not use this file except in compliance with the License. You may obtain a copy of the
License at http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific
language governing rights and limitations under the License.
*/
package net.sourceforge.idrs.core.report;
import java.io.Serializable;
import java.lang.reflect.*;
import net.sourceforge.idrs.script.embedable.*;
import net.sourceforge.idrs.script.*;
/**
*Base class for gengeration of html input tags
*/
public class GenTag implements Serializable {
public static final int SRC_PARAM=0;
public static final int SRC_DB=1;
public static final int SRC_PROP=2;
String src;
String owner;
int srcType;
String atts;
String name;
boolean nameIsScript;
boolean paramFirst;
/** Creates new YesNo
*@param name Name of input tag
*@param srcType One of the SRC constants. Where the data is coming from
*@param src The name of the source
*@param atts Extra attributes
*@param paramFirst Determine if a paramater will be checked first
*/
public GenTag(String name, int srcType, String src, String atts,boolean paramFirst) {
this.paramFirst = paramFirst;
this.name = name;
this.atts = atts;
if (name.charAt(0) == '=') {
this.nameIsScript = true;
this.name = name.substring(1);
}
this.srcType = srcType;
if (srcType == SRC_DB || srcType == SRC_PROP) {
this.owner = src.substring(0,src.indexOf('.'));
this.src = srcType == SRC_PROP ? "get" + src.substring(src.indexOf('.') + 1) : src.substring(src.indexOf('.') + 1);
}
else {
this.src = src;
}
}
/**
*Retrieves a value based on what the source is
*@param head IDRS
*@param name Name of tag
*@return value of tag
*/
protected boolean getValueBool(IDRSHead head,String name) throws Exception {
String sval;
String db,field;
switch (srcType) {
case SRC_PARAM : return (sval = head.getRequest().getParameter(src)) != null ? sval.equalsIgnoreCase("true") : false;
case SRC_DB : return getValDBBool(head,name);
case SRC_PROP : return getValObjBool(head,name);
default : return false;
}
}
/**
*Retrieves a value based on what the source is
*@param head IDRS
*@param name Name of tag
*@return value of tag
*/
protected boolean getValDBBool(IDRSHead head,String name) throws Exception {
String sval;
if (this.paramFirst) {
sval = head.getRequest().getParameter(name);
if (sval == null) {
return (sval = head.getFieldData(owner,src)) != null ? sval.equalsIgnoreCase("true") : false;
}
else {
return sval.equalsIgnoreCase("true");
}
}
else {
return (sval = head.getFieldData(owner,src)) != null ? sval.equalsIgnoreCase("true") : false;
}
}
/**
*Retrieves a value based on what the source is
*@param head IDRS
*@param name Name of tag
*@return value of tag
*/
protected boolean getValObjBool(IDRSHead head, String name) throws Exception {
String sval;
if (this.paramFirst) {
sval = head.getRequest().getParameter(name);
if (sval == null) {
return getPropDataBool(head);
}
else {
return sval.equalsIgnoreCase("true");
}
}
else {
return getPropDataBool(head);
}
}
/**
*Retrieves a value based on what the source is
*@param head IDRS
*@param name Name of tag
*@return value of tag
*/
protected String getValue(IDRSHead head,String name) throws Exception {
Object sval;
String db,field;
switch (srcType) {
case SRC_PARAM : return (sval = head.getRequest().getParameter(src)) != null ? sval.toString() : "";
case SRC_DB : return getValDB(head,name);
case SRC_PROP : return getValObj(head,name);
default : return "";
}
}
/**
*Uses reflection to retrieve data from a bean property
*/
protected boolean getPropDataBool(IDRSHead idrs) throws Exception {
Object obj = idrs.getObject(owner);
Class cls = obj.getClass();
Method meth = cls.getMethod(src,new Class[0]);
return ((Boolean) meth.invoke(obj,new Object[0])).booleanValue() ;
}
/**
*Uses reflection to retrieve data from a bean property
*/
protected Object getPropData(IDRSHead idrs) throws Exception {
Object obj = idrs.getObject(owner);
Class cls = obj.getClass();
Method meth = cls.getMethod(src,new Class[0]);
return meth.invoke(obj,new Object[0]);
}
/**
*Retrieves a value based on what the source is
*@param head IDRS
*@param name Name of tag
*@return value of tag
*/
protected String getValDB(IDRSHead head,String name) throws Exception {
String sval;
if (this.paramFirst) {
sval = head.getRequest().getParameter(name);
if (sval == null) {
return (sval = head.getFieldData(owner,src)) != null ? sval : "";
}
else {
return sval;
}
}
else {
return (sval = head.getFieldData(owner,src)) != null ? sval : "";
}
}
/**
*Retrieves a value based on what the source is
*@param head IDRS
*@param name Name of tag
*@return value of tag
*/
protected String getValObj(IDRSHead head,String name) throws Exception {
String sval;
if (this.paramFirst) {
sval = head.getRequest().getParameter(name);
if (sval == null) {
return getPropData(head).toString();
}
else {
return sval;
}
}
else {
return getPropData(head).toString();
}
}
}
--- NEW FILE: InputChunk.java ---
/*
* InputChunk.java
*
* Created on April 13, 2002, 9:57 AM
*/
package net.sourceforge.idrs.core.report;
/**
*
* @author mlb
* @version
*/
public class InputChunk extends net.sourceforge.idrs.core.report.GenTag implements net.sourceforge.idrs.core.report.Chunk, java.io.Serializable {
public static final int INPUT_TEXT = 0;
public static final int INPUT_CHECKBOX = 1;
public static final int INPUT_PASSWORD = 2;
public static final int INPUT_RADIO = 3;
public static final int INPUT_TEXTAREA = 4;
public static final int INPUT_HIDDEN = 5;
String value;
int type;
/** Creates new InputChunk
*@param name Name of input tag
*@param type One of the INPUT constants. Determines final tag type
*@param srcType One of the SRC constants. Where the data is coming from
*@param src The name of the source
*@param atts Extra attributes
*@param paramFirst Determine if a paramater will be checked first
*/
public InputChunk(String name, int type, int srcType, String src, String value, String atts,boolean paramFirst) {
super(name,srcType,src,atts, paramFirst);
this.value = value;
this.type = type;
}
public String toString(IDRSHead head) throws Exception {
StringBuffer tag = new StringBuffer();
String nm = nameIsScript ? head.getScriptContext().eval(name) : name;
switch (type) {
case INPUT_HIDDEN : getTextTag(nm,"HIDDEN",head,tag); break;
case INPUT_TEXT : getTextTag(nm,"TEXT",head,tag); break;
case INPUT_PASSWORD : getTextTag(nm,"PASSWORD",head,tag); break;
case INPUT_RADIO : getBoolTag(nm,"RADIO",head,tag); break;
case INPUT_CHECKBOX : getBoolTag(nm,"CHECKBOX",head,tag); break;
case INPUT_TEXTAREA : tag.append("<TEXTAREA NAME=\"").append(nm).append("\" ").append(atts).append(" >").append(getValue(head,nm)).append("</TEXTAREA>");
}
return tag.toString();
}
/**
*Generates a text style tag
*@param nm The name of the tag
*@param type The type of tags
*@param head The IDRS
*@param tag String Buffer containing tag to generate
*/
protected void getTextTag(String nm,String type, IDRSHead head,StringBuffer tag) throws Exception {
tag.append("<INPUT TYPE=\"").append(type).append("\" NAME=\"");
tag.append(nm).append("\" VALUE=\"").append(getValue(head,nm)).append("\" ");
tag.append(atts).append(" >");
}
/**
*Generates a boolean style tag
*@param nm The name of the tag
*@param type The type of tags
*@param head The IDRS
*@param tag String Buffer containing tag to generate
*/
protected void getBoolTag(String nm, String type, IDRSHead head,StringBuffer tag) throws Exception {
tag.append("<INPUT TYPE=\"").append(type).append("\" NAME=\"");
tag.append(nm).append("\" VALUE=\"").append(value).append("\" ");
tag.append(atts).append(getValue(head,nm).equalsIgnoreCase(value) ? "CHECKED" : "").append(" >");
}
}
Index: YesNo.java
===================================================================
RCS file: /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/core/report/YesNo.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** YesNo.java 11 Apr 2002 20:37:06 -0000 1.1
--- YesNo.java 13 Apr 2002 16:06:35 -0000 1.2
***************
*** 15,18 ****
--- 15,19 ----
import java.io.Serializable;
import java.lang.reflect.*;
+ import net.sourceforge.idrs.script.embedable.*;
import net.sourceforge.idrs.script.*;
***************
*** 20,40 ****
*Allows for the creation of a Yes/No option button with a current value retrieved from a request parameter, database value or bean property
*/
! public class YesNo implements net.sourceforge.idrs.core.report.Chunk {
public static final int NOT_SINGLE=-1;
public static final int SINGLE_YES=0;
public static final int SINGLE_NO=1;
- public static final int SRC_PARAM=0;
- public static final int SRC_DB=1;
- public static final int SRC_PROP=2;
- String src;
- String owner;
- int srcType;
- int single;
- String name;
-
! StringBuffer tag;
/** Creates new YesNo
--- 21,34 ----
*Allows for the creation of a Yes/No option button with a current value retrieved from a request parameter, database value or bean property
*/
! public class YesNo extends GenTag implements net.sourceforge.idrs.core.report.Chunk {
public static final int NOT_SINGLE=-1;
public static final int SINGLE_YES=0;
public static final int SINGLE_NO=1;
!
!
! int single;
/** Creates new YesNo
***************
*** 43,61 ****
*@param srcType One of the SRC constants. Where the data is coming from
*@param src The name of the source
*/
! public YesNo(String name, int single, int srcType, String src) {
! tag = new StringBuffer();
! this.name = name;
this.single = single;
- this.srcType = srcType;
-
- if (srcType == SRC_DB || srcType == SRC_PROP) {
- this.owner = src.substring(0,src.indexOf('.'));
- this.src = srcType == SRC_PROP ? "get" + src.substring(src.indexOf('.') + 1) : src.substring(src.indexOf('.') + 1);
- }
- else {
- this.src = src;
- }
}
/*
--- 37,49 ----
*@param srcType One of the SRC constants. Where the data is coming from
*@param src The name of the source
+ *@param atts Extra attributes
+ *@param paramFirst Determine if a paramater will be checked first
*/
! public YesNo(String name, int single, int srcType, String src,String atts,boolean paramFirst) {
! super(name,srcType,src,atts,paramFirst);
this.single = single;
}
+
+
/*
***************
*** 63,74 ****
*/
public String toString(IDRSHead head) throws Exception {
! tag.setLength(0);
! boolean yes = getValue(head);
if (single == NOT_SINGLE || single == SINGLE_YES) {
! tag.append("<INPUT TYPE=\"RADIO\" VALUE=\"true\" NAME=\"").append(name).append("\" ").append(yes ? "CHECKED" : "").append("> Yes ");
}
if (single == NOT_SINGLE || single == SINGLE_NO) {
! tag.append("<INPUT TYPE=\"RADIO\" VALUE=\"false\" NAME=\"").append(name).append("\" ").append(! yes ? "CHECKED" : "").append("> No ");
}
--- 51,64 ----
*/
public String toString(IDRSHead head) throws Exception {
! StringBuffer tag = new StringBuffer();
!
! String nm = nameIsScript ? head.getScriptContext().eval(name) : name;
! boolean yes = getValueBool(head,nm);
if (single == NOT_SINGLE || single == SINGLE_YES) {
! tag.append("<INPUT TYPE=\"RADIO\" VALUE=\"true\" NAME=\"").append(nm).append("\" ").append(yes ? "CHECKED" : "").append(atts).append("> Yes ");
}
if (single == NOT_SINGLE || single == SINGLE_NO) {
! tag.append("<INPUT TYPE=\"RADIO\" VALUE=\"false\" NAME=\"").append(nm).append("\" ").append(! yes ? "CHECKED" : "").append(atts).append("> No ");
}
***************
*** 76,103 ****
}
- /**
- *Retrieves a value based on what the source is
- */
- protected boolean getValue(IDRSHead head) throws Exception {
- String sval;
- String db,field;
- switch (srcType) {
- case SRC_PARAM : return (sval = head.getRequest().getParameter(src)) != null ? sval.equalsIgnoreCase("true") : false;
- case SRC_DB : return (sval = head.getFieldData(owner,src)) != null ? sval.equalsIgnoreCase("true") : false;
- case SRC_PROP : return getPropData(head);
- default : return false;
- }
- }
- /**
- *Uses reflection to retrieve data from a bean property
- */
- protected boolean getPropData(IDRSHead idrs) throws Exception {
-
- Object obj = idrs.getObject(owner);
- Class cls = obj.getClass();
- Method meth = cls.getMethod(src,new Class[0]);
- return ((Boolean) meth.invoke(obj,new Object[0])).booleanValue() ;
- }
}
--- 66,70 ----
|