[Idrs-commit] CVS: Idrs/dev/src/net/sourceforge/idrs/core/report IDRSHead.java~,NONE,1.1 PortalChunk
Brought to you by:
bigman921
|
From: Marc B. <big...@us...> - 2002-11-22 07:16:27
|
Update of /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/core/report In directory sc8-pr-cvs1:/tmp/cvs-serv9439/net/sourceforge/idrs/core/report Modified Files: Line.java TextChunk.java Added Files: IDRSHead.java~ PortalChunk.java SelectChunk.java Log Message: added portal and selectInput tags --- NEW FILE: IDRSHead.java~ --- package net.sourceforge.idrs.core.report; import net.sourceforge.idrs.jdbc.*; import net.sourceforge.idrs.utils.*; import net.sourceforge.idrs.script.embedable.*; import net.sourceforge.idrs.script.*; import net.sourceforge.idrs.core.servlet.MultiPartRequest; import java.util.*; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.sql.*; import java.security.*; public final class IDRSHead implements Serializable, IDRSScript { protected String header; protected String text; protected HashMap dbs; protected HashMap objects; protected String scriptClass; protected HashMap vars; protected HashMap varNames; protected HashMap pos; protected String[] objNames, dbNames; protected transient boolean send = true; static final long serialVersionUID = -4520281654183459125L; transient static final String ERR_NAME = "doc_ERROR"; protected transient HttpSession session; protected transient HttpServletRequest request; protected transient HttpServletResponse response; // protected transient PrintWriter out; protected transient Application app; protected transient HashMap conns; protected transient int userNum; protected transient int docId; protected transient String url; protected transient IDRSScriptLanguage idrs; protected transient IDRSShell me; protected transient HashMap lists; protected transient IDRSPrinter out; protected transient UserInfo userInfo; //recording the names in order is a nessassary step protected transient LinkedList objlNames; protected transient LinkedList dblNames; protected transient HashMap connsInfo; protected transient String digest; /* public void preBuild(HashMap connsInfo) throws Exception { this.connsInfo = connsInfo; Enumeration keys = connsInfo.keys(); String key; conns = new HashMap(); //first get all connections while (keys.hasMoreElements()) { key = (String) keys.nextElement(); conns.put(key,((JDBCInfo) connsInfo.get(key)).build()); } //now put them into the DB's keys = dbs.elements(); DB db; while (keys.hasMoreElements()) { db = (DB) keys.nextElement(); db.setConnection(((Connection) conns.get(db.getDBName()))); } buildScriptContext(); }*/ public Connection getConn(String name) { return (Connection) conns.get(name); } public String getText(IDRSBody body) { String output = text; if (body.isHTML()) { output = header + "</HEAD>\n"; return output; } else { return ""; } } public void addText(String txt) { addText(txt,false); } public void addText(String txt,boolean isHtml) { //System.out.println("TEXTB : " + header); // System.out.println("HEAD : " + txt + ", " + isHtml); if (txt.indexOf("<head") != -1) { if (isHtml) { header = txt; //System.out.println("Is HTML"); } } else if (txt != null && txt.length() != 0) { header += txt; } //System.out.println("TEXTA : " + header); } public IDRSHead() { dbs = new HashMap(); objects = new HashMap(); text = ""; header = ""; vars = new HashMap(); lists = new HashMap(); objlNames=new LinkedList(); dblNames=new LinkedList(); objNames=new String[0]; dbNames=new String[0]; } /** * Used by various chunks */ public int getUserNum() { return userNum; } public int getDocID() { return docId; } public String getURL() { return url; } /** * used to initialize a header object */ public void init(HashMap conns, int userNum, int docID, String url, HttpSession session, HttpServletRequest request,HttpServletResponse response, Application app, IDRSScriptLanguage context,UserInfo userInfo,String digest) throws Exception { this.digest = digest; this.userInfo=userInfo; this.idrs = context; if (conns != null) this.conns = conns; this.userNum = userNum; this.docId = docID; this.url = url; this.session = session; this.request = request; this.response = response; this.app = app; //this.vars = vars; //this.varNames = varNames; //if ((idrs != null) && (scriptClass != null) && (! scriptClass.equals(""))) buildScriptContext(); //build all objects Iterator keys = objects.keySet().iterator(); ObjectStore obj; Object[] vals; String val; String[] varVals; int i; int l,m; Class[] varTypes; //while (keys.hasNext()) { for (l=0,m=objNames.length;l<m;l++){ //obj = (ObjectStore) objects.get((String) keys.next()); obj = (ObjectStore) objects.get(objNames[l]); varTypes = obj.getTypes(); vals = new Object[varTypes.length]; varVals = (String[]) vars.get(obj.getID()); for (i=0;i<varVals.length;i++) { val = varVals[i]; if (val != null) { if (val.equalsIgnoreCase("UserID")) { vals[i] = new Integer(userNum); } if (val.equalsIgnoreCase("Scripter")) { vals[i] = (IDRSScript) this; } else { vals[i] = ObjectStore.getValue((Class) varTypes[i],val,null,(IDRSScript) this); } } } obj.rebuild(vals); if (obj.setProps()) obj.setProps(request); } //initialize all databases //System.out.println("HERE ARE THE DB's"); keys = dbs.keySet().iterator(); // while (keys.hasNext()) { // System.out.println("DB ID : " + keys.next()); // } keys = dbs.keySet().iterator(); Connection con; int place; DB db; String key; //while (keys.hasNext()) { for (l=0,m=dbNames.length;l<m;l++) { //retrieve a connection //key = (String) keys.next(); key = dbNames[l]; System.out.println("KEY : " + key); db = (DB) dbs.get(key); if (conns != null) { con = (Connection) conns.get(db.getDBName()); if (con != null) { db.setConnection(con); } } //initialize the db...vars are added in the servlet //System.out.println("DB ID: " + db.getID()); varVals = (String[]) vars.get(db.getID()); if (varVals != null) { for (i=0;i<varVals.length;i++) { if (varVals[i].equalsIgnoreCase("UserID")) { varVals[i] = Integer.toString(userNum); } } } db.buildDB(varVals,this); } } public void addVarList(String name, Integer size) { lists.put(name,size); } /** * Used by NavTags */ public HashMap getVarNames() { return varNames; } /** * Used by ObjectChunk */ public ObjectStore getObjectStore(String objName) throws Exception { ObjectStore obj = (ObjectStore) objects.get(objName); if (objName == null) throw new Exception(objName + " not a valid object"); return obj; } /** * Used by EvalLongScript, EvalScript */ public IDRSScriptLanguage getScriptContext() { return idrs; } /** * Used by FieldChunck,IfChangeChunck */ public DB getDB(String ID) throws Exception { DB db = (DB) dbs.get(ID); if (db == null) { throw new Exception("DB " + ID + " does not exist"); } return db; } /** * used by NavNext and NavPrev */ public HashMap getAllDBs() { return dbs; } /** * used by NavNext and NavPrev */ public HashMap getAllVars() { return vars; } public void addDB(DB db) throws Exception { dblNames.add(db.getID()); dbs.put(db.getID(),db); } /** * used by ObjectChunck */ public Vector getVarList(String ID) throws Exception { Vector list = (Vector) vars.get(ID); if (list == null) { throw new Exception("Var List " + ID + " does not exist"); } return list; } public void addObject(ObjectStore obj) { objlNames.add(obj.getID()); objects.put(obj.getID(),obj); } /*********************************************************** * This section is the implementation of the IDRSScript object ************************************************************/ /** Used to retrieve a piece of data from a particuler DB with a given format */ public String getFieldData(String db,String field,String format) throws Exception { try { DB Db = (DB) dbs.get(db); if (Db == null) throw new Exception("DB " + db + " not found"); return Db.getFieldData(field.toLowerCase(),format); } catch (Exception e) { throw e; } } /** * Used to retrieve a piece of data from a particuler DB without format */ public String getFieldData(String db,String field) throws Exception { return getFieldData(db,field,null); } /** * Used to move to the next record in a selected db */ public boolean next(String db) throws Exception { DB Db = (DB) dbs.get(db); if (Db == null) throw new Exception("DB " + db + " no found"); return Db.next(); } /** * Used to move to a particuler record */ public boolean moveTo(String db, int record) throws Exception { DB Db = (DB) dbs.get(db); if (Db == null) throw new Exception("DB " + db + " no found"); return Db.moveTo(record); } /** * Used to retrieve a refrence to an object created in an IDRS report */ public Object getObject(String obj) throws Exception { try { ObjectStore objstr = (ObjectStore) objects.get(obj); if (objstr == null) throw new Exception("No Object defined : " + obj); return objstr.getRef(); } catch (Exception e) { throw new Exception("No Object defined : " + obj); } } /** * retrieves printwriter used by the IDRS */ public IDRSPrinter getOut() throws Exception { return out; } /** * Retrieves the session object from webserver */ public HttpSession getSession() throws Exception { return session; } /** * Retrieves request object from webserver */ public HttpServletRequest getRequest() throws Exception { return request; } public HttpServletResponse getResponse() throws Exception { return response; } /** *Retrieves the MultiPartRequest if it exists */ public MultiPartRequest getMultiPartRequest() throws Exception { if (request instanceof MultiPartRequest) { return (MultiPartRequest) request; } else { return null; } } /** * Used to retrieve the results of an update */ public int getInputResults(String db) throws Exception { try { DB Db = (DB) dbs.get(db); if (Db == null) throw new Exception("DB " + db + " no found"); return Db.getUpdateResult(); } catch (Exception e) { throw e; } } public Application getApplication() throws Exception { return this.app; } public void setScriptClass(String scriptClass) { this.scriptClass = scriptClass; } protected void buildScriptContext() throws Exception { if (idrs == null) { try { idrs = (IDRSScriptLanguage) Class.forName(scriptClass).newInstance(); } catch (Exception e1) { throw new Exception(e1.toString() + " : Can't create script object"); } } this.me = new IDRSShell(this); idrs.setVal("idrs",me); if (this.session != null) { idrs.importClass("javax.servlet.http.*"); idrs.importClass("javax.servlet.*"); } idrs.importClass("net.sourceforge.idrs.script.IDRSScript"); idrs.importClass("net.sourceforge.idrs.script.embedable.IDRSShell"); //idrs.importClass("net.sourceforge.idrs.core.IDRSReport"); idrs.importClass("net.sourceforge.idrs.utils.Application"); idrs.importClass("java.io.PrintWriter"); this.out = new IDRSPrinter(); idrs.setVal("out",this.out); idrs.setVal("app",this.app); idrs.setVal("session",this.getSession()); idrs.setVal("request", this.getRequest()); } public void add(String key, String name, String val) { // System.out.println("key : " + key + ", Name:" + name + ", val:" + val); Int i = (Int) pos.get(key); /* if (vars.get(key) == null) { //System.out.println("vars.get(key) is null"); //System.out.println("HERE ARE THE VAR's"); Iterator keys = vars.keySet().iterator(); //while (keys.hasNext()) { // System.out.println("Var ID : " + keys.next()); //} }*/ //System.out.println("i.v:" + i.v); // System.out.println("((Object[]) vars.get(key)).length:" + ((Object[]) vars.get(key)).length); ((Object[]) vars.get(key))[i.v] = val; ((Object[]) varNames.get(key))[i.v] = name; i.v++; } public void seal() throws Exception { pos = new HashMap(); vars = new HashMap(); varNames = new HashMap(); Iterator keys = dbs.keySet().iterator(); String key; DB db; int size; while (keys.hasNext()) { db = (DB) dbs.get((String) keys.next()); size = db.seal(); varNames.put(db.getID(),new String[size]); vars.put(db.getID(),new String[size]); pos.put(db.getID(),new Int()); } ObjectStore obj; keys = objects.keySet().iterator(); while (keys.hasNext()) { key = (String) keys.next(); //System.out.println("Object Key : " + key); obj = (ObjectStore) objects.get(key); size = obj.seal(); //System.out.println("Size : " + size); varNames.put(obj.getID(),new String[size]); vars.put(obj.getID(),new String[size]); pos.put(obj.getID(),new Int()); } Integer sz; keys = lists.keySet().iterator(); while (keys.hasNext()) { key = (String) keys.next(); sz = (Integer) lists.get(key); size = sz.intValue(); varNames.put(key,new String[size]); vars.put(key,new String[size]); pos.put(key,new Int()); } // Re-DO THis when I have it working (SUNDAY) //Now we will load the names into their respective arrays //dbs int i,m; dbNames = new String[dblNames.size()]; for (i=0,m=dblNames.size();i<m;i++) { dbNames[i] = (String) dblNames.get(i); } objNames = new String[objlNames.size()]; for (i=0,m=objlNames.size();i<m;i++) { objNames[i] = (String) objlNames.get(i); } } public void reset() { Iterator e = pos.values().iterator(); while (e.hasNext()) { ((Int) e.next()).v=0; } } public Object clone() { Object deepCopy = null; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(this); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bais); deepCopy = ois.readObject(); } catch (Exception e) { try { e.printStackTrace(System.out); } catch (Exception ee) {} } return deepCopy; } public void setPrintTarget(StringBuffer s) throws Exception { if (out == null) this.out = new IDRSPrinter(); out.setTarget(s); out.print(header); } public void setSendToClient(boolean send) throws Exception { this.send=send; } public boolean getSendToClient() throws Exception { return this.send; } public UserInfo getUserInfo() throws Exception { return this.userInfo; } public void close() throws Exception { DB db; for (int i=0,m=dbNames.length;i<m;i++) { db = (DB) dbs.get(dbNames[i]); db.close(); } } /** *Tells the type of digest *@param plain Plain Text String */ public String getDigest(String plain) throws Exception { if (! this.digest.equalsIgnoreCase("none")) { MessageDigest md = MessageDigest.getInstance(this.digest); md.update(plain.getBytes()); byte[] digest = md.digest(); return new String(digest); } else { return plain; } } /** *Creates an error in the request *@param err as string */ public void createError(String err) { request.setAttribute(ERR_NAME,err); } /** *Determines if there is an error *@return true if there is an error */ public boolean isError() { return request.getAttribute(ERR_NAME) != null; } /** *Retrieves the error */ public String getError() { return (String) request.getAttribute(ERR_NAME); } } class Int implements Serializable { int v; } --- NEW FILE: PortalChunk.java --- /* PortalChunk.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.util.*; import net.sourceforge.idrs.utils.*; import net.sourceforge.idrs.core.report.*; /** This interface is the basis for all pieces of data stored inside of a compiled report */ public class PortalChunk extends Line implements Chunk, Serializable { int[] groups; Line[] lines; boolean sealed; transient LinkedList llines; public PortalChunk(String groups) { StringTokenizer tok = new StringTokenizer(groups,","); this.groups = new int[tok.countTokens()]; int i = 0; sealed = false; while (tok.hasMoreTokens()) { this.groups[i++] = Integer.parseInt(tok.nextToken()); } llines = new LinkedList(); } public String toString(IDRSHead head,StringBuffer buff) throws Exception { UserInfo user = head.getUserInfo(); boolean ok = false; for (int i=0,m=groups.length;i<m;i++) { if (user.inGroup(groups[i])) { ok = true; break; } } if (ok) { for (int i=0,m=lines.length;i<m;i++) { lines[i].toString(head,buff); } //buff.append(super.toString(head)); } return ""; } public void setLines(Vector lines) { for (int i=0,m=lines.size();i<m;i++) { llines.add(lines.get(i)); } } public void seal() { Chunk[] c; if (! sealed) { lines = new Line[llines.size()]; for (int i=0,m=llines.size();i<m;i++) { lines[i] = (Line) llines.get(i); lines[i].seal(); if (lines[i] != null) lines[i].seal(); } sealed = true; } } public String toString(IDRSHead head) throws Exception { return ""; } } --- NEW FILE: SelectChunk.java --- /* SelectChunk.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.util.*; import java.lang.reflect.*; import net.sourceforge.idrs.script.embedable.*; import net.sourceforge.idrs.script.*; /** *Base class for gengeration of html select tags */ public class SelectChunk extends GenTag implements Serializable,Chunk { protected String srcDB; protected String lstId; protected String lstVal; protected int type; public SelectChunk(String name, int type, int srcType, String src, String value, String atts,boolean paramFirst, String listSrc, String lstId, String lstVal) { super(name,srcType,src,atts, paramFirst); this.srcDB = listSrc; this.lstId = lstId; this.lstVal = lstVal; } /** *generate the select statement */ public String toString(IDRSHead idrs) throws Exception { LinkedList list = getList(idrs); HashMap row; String nm, val,lookfor; nm = nameIsScript ? idrs.getScriptContext().eval(name) : name; StringBuffer buff = new StringBuffer(); buff.append("<SELECT name=\"").append(this.name).append("\">\n"); lookfor=getValue(idrs,nm); Iterator it = list.iterator(); while (it.hasNext()) { row = (HashMap) it.next(); val = (String) row.get(lstId); buff.append("<OPTION VALUE=\"").append(val).append("\"").append(val.equals(lookfor) ? "SELECTED" : "").append(">").append(row.get(lstVal)).append("</option>\n"); } buff.append("</SELECT>"); return buff.toString(); } /** *Retrieves the source for the select statement */ protected LinkedList getList(IDRSHead idrs) throws Exception { HashMap row; LinkedList table = (LinkedList) idrs.getRequest().getAttribute("SELECT_" + name); if (table == null) { table = new LinkedList(); while (idrs.next(srcDB)) { row = new HashMap(); row.put(lstId,idrs.getFieldData(srcDB,lstId)); row.put(lstVal,idrs.getFieldData(srcDB,lstVal)); table.add(row); } idrs.getRequest().setAttribute("SELECT_" + name,table); } return table; } } Index: Line.java =================================================================== RCS file: /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/core/report/Line.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Line.java 4 Mar 2002 23:05:34 -0000 1.4 --- Line.java 22 Nov 2002 07:16:24 -0000 1.5 *************** *** 24,39 **** protected transient Vector vchunks; //this array holds all of the chuncks for a given line protected Chunk[] chunks; static final long serialVersionUID = 786019973821495030L; ! ! /** Initializes a Line */ ! public Line() { //this contructor initializes the size of the line this.vchunks = new Vector(); ! ! } ! /** Adds a Chunk to the Line --- 24,40 ---- protected transient Vector vchunks; //this array holds all of the chuncks for a given line protected Chunk[] chunks; + protected transient boolean sealed; static final long serialVersionUID = 786019973821495030L; ! ! /** Initializes a Line */ ! public Line() { //this contructor initializes the size of the line this.vchunks = new Vector(); ! sealed = false; ! } ! /** Adds a Chunk to the Line *************** *** 41,47 **** */ public void addChunk(Chunk chunk) { ! vchunks.add(chunk); } ! /** Retrieves the information about the all of the Chunks stored in the Line --- 42,48 ---- */ public void addChunk(Chunk chunk) { ! vchunks.add(chunk); } ! /** Retrieves the information about the all of the Chunks stored in the Line *************** *** 52,64 **** //StringBuffer vals = new StringBuffer(""); Chunk ch; ! for (int i=0; i<chunks.length;i++) { ch = chunks[i]; buffer.append(ch.toString(head)); } ! //return (vals.toString()); return null; } ! /** Public method to retrieve the information about the all of the Chunks stored in the Line --- 53,66 ---- //StringBuffer vals = new StringBuffer(""); Chunk ch; ! System.out.println("Number of chunks : " + chunks.length); ! for (int i=0; i<chunks.length;i++) { ch = chunks[i]; buffer.append(ch.toString(head)); } ! //return (vals.toString()); return null; } ! /** Public method to retrieve the information about the all of the Chunks stored in the Line *************** *** 74,78 **** } } ! /** Concatinates current line with passed in line --- 76,80 ---- } } ! /** Concatinates current line with passed in line *************** *** 84,105 **** this.vchunks.addElement(e.nextElement()); } ! return this; } ! /** "Seals" the report head into static data structures from dynamic ones */ public void seal() { ! chunks = new Chunk[vchunks.size()]; ! int i=0; for (i=0;i<vchunks.size();i++) { chunks[i] = (Chunk) vchunks.get(i); } vchunks.removeAllElements(); ! ! } } --- 86,109 ---- this.vchunks.addElement(e.nextElement()); } ! return this; } ! /** "Seals" the report head into static data structures from dynamic ones */ public void seal() { ! if (sealed) return; ! //System.out.println("In Line seal"); chunks = new Chunk[vchunks.size()]; ! sealed = true; int i=0; for (i=0;i<vchunks.size();i++) { chunks[i] = (Chunk) vchunks.get(i); + //System.out.println("chunk : " + chunks[i]); } vchunks.removeAllElements(); ! ! } } Index: TextChunk.java =================================================================== RCS file: /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/core/report/TextChunk.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TextChunk.java 15 Sep 2001 17:33:28 -0000 1.3 --- TextChunk.java 22 Nov 2002 07:16:24 -0000 1.4 *************** *** 28,31 **** --- 28,32 ---- */ public TextChunk(String text) { + this.text = text; } *************** *** 37,40 **** --- 38,46 ---- */ public String toString(IDRSHead head) throws Exception { + + return this.text; + } + + public String getText() { return this.text; } |