[Idrs-commit] CVS: Idrs/dev/src/net/sourceforge/idrs/core/report YesNo.java,NONE,1.1 IDRSBody.java,1
Brought to you by:
bigman921
|
From: Marc B. <big...@us...> - 2002-04-11 21:08:31
|
Update of /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/core/report
In directory usw-pr-cvs1:/tmp/cvs-serv4319/dev/src/net/sourceforge/idrs/core/report
Modified Files:
IDRSBody.java
Added Files:
YesNo.java
Log Message:
Added YesNo class, updated docs
--- NEW FILE: YesNo.java ---
/*
YesNo.java
Copyright (C) 2001 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.*;
/**
*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
*@param name Name of input tag
*@param singe One of the SINGLE constants. Allows for a Yes/No to be broken up
*@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;
}
}
/*
*Returns the generated input tag
*/
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 ");
}
return tag.toString();
}
/**
*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() ;
}
}
Index: IDRSBody.java
===================================================================
RCS file: /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/core/report/IDRSBody.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** IDRSBody.java 5 Apr 2002 14:37:51 -0000 1.5
--- IDRSBody.java 11 Apr 2002 20:37:06 -0000 1.6
***************
*** 91,97 ****
//output += ln.toString(head) + "\n";
ln.toString(head,buffer);
! /*
! if (buffer.charAt(buffer.length()-1)!='\n')
! buffer.append("\n");*/
}
}
--- 91,97 ----
//output += ln.toString(head) + "\n";
ln.toString(head,buffer);
!
! //if (buffer.charAt(buffer.length()-1)!='\n')
! buffer.append("\n");
}
}
|