[Idrs-commit] CVS: Idrs/dev/src/net/sourceforge/idrs/core/report WhileLine.java,NONE,1.1
Brought to you by:
bigman921
|
From: Marc B. <big...@us...> - 2004-09-11 20:08:48
|
Update of /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/core/report In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19267/src/net/sourceforge/idrs/core/report Added Files: WhileLine.java Log Message: Added a "while" tag that allows a condition for looping : <while condition="value < x"> . . . </while> Previosly a script block had to be used to do while loops. The condition is in the form of whatever the scriptcontext uses --- NEW FILE: WhileLine.java --- /* Copyright (C) 2002-2004 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.util.ArrayList; import java.util.Vector; import org.apache.log4j.Logger; import org.w3c.dom.Document; import org.w3c.dom.Element; /** * @author mlb * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ public class WhileLine extends Line implements Chunk, Serializable { /** The condintion to continue the loop */ String condition; static Logger logger = Logger.getLogger(WhileLine.class.getName()); private Vector vlines; private Line[] lines; /** * @param arg0 */ public WhileLine(String condition) { this.condition = condition; } /** * Sets the vector constaing the lines for the containor @param line Line to add */ public void addLine(Line line) { vlines.add(line); } /** * Sets the vector constaing the lines for the containor *@param lines Lines being used */ public void setLines(Vector lines) { this.vlines = lines; } /* (non-Javadoc) * @see net.sourceforge.idrs.core.report.Chunk#toString(net.sourceforge.idrs.core.report.IDRSHead) */ public String toString(IDRSHead head) throws Exception { // TODO Auto-generated method stub return ""; } /** * "Seals" the report head into static data structures from dynamic ones */ public void seal() { if (! sealed) { ArrayList llines = new ArrayList(); int i=0; for (i=0;i<vlines.size();i++) { Line l = (Line) (Line) vlines.get(i); if (l != null) { //((Line) lines[i]).seal(); } else { lines[i] = new Line(); ((Line) lines[i]).addChunk(new TextChunk("")); ((Line) lines[i]).seal(); } llines.add(l); } lines = new Line[llines.size()]; System.arraycopy(llines.toArray(),0,lines,0,lines.length); sealed = true; vlines.removeAllElements(); } } /** Public method to retrieve the information about the all of the Chunks stored in the Line @param head IDRSHead of report @param buffer Buffered output of report */ public String toString(IDRSHead head, StringBuffer buffer) throws Exception { StringBuffer tmp = new StringBuffer(100); String conditionRes = head.getScriptContext().eval(condition); while (conditionRes.equalsIgnoreCase("true") || conditionRes.equals("1")) { int i = 0; while (i < this.lines.length) { Line line = lines[i]; String ln = line.toString(head,tmp); //if (ln != null) if (tmp.charAt(tmp.length()-1)!='\n') { tmp.append("\n"); } i++; } i=0; tmp.deleteCharAt(tmp.length()-1); conditionRes = head.getScriptContext().eval(condition); } buffer.append(tmp); return null; } public void toDOM(IDRSHead head, Document doc, Element root) throws Exception { StringBuffer tmp = new StringBuffer(100); String conditionRes = head.getScriptContext().eval(condition); while (conditionRes.equalsIgnoreCase("true") || conditionRes.equals("1")) { int i = 0; while (i < this.lines.length) { Line line = lines[i]; line.toDOM(head,doc,root); i++; } i=0; conditionRes = head.getScriptContext().eval(condition); } } } |