[Idrs-commit] CVS: Idrs/dev/src/net/sourceforge/idrs/core/report AttributeLine.java,NONE,1.1 TagLine
Brought to you by:
bigman921
|
From: Marc B. <big...@us...> - 2004-08-22 23:52:48
|
Update of /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/core/report In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18432/src/net/sourceforge/idrs/core/report Modified Files: IDRSCompiler.java Line.java IDRSRep.java PortalChunk.java RepeatLine.java IfResultsChunk.java IfChangeChunk.java IDRSBody.java Added Files: AttributeLine.java TagLine.java Log Message: * Added tags to handle the creation of XML tags <tag name="xmltag"> <attribute name="attribname"> . . . </attribute> . . . </tag> The tags work in text mode, but are designed for XML mode * Added the ability for an IDRS report to be generated to a DOM. This eliminates the performance loss die to parsing the resulting XML before it is added to a SOAP Body. --- NEW FILE: AttributeLine.java --- /* * Created on Aug 22, 2004 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ package net.sourceforge.idrs.core.report; import java.io.Serializable; import java.util.Vector; 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 AttributeLine extends Line implements Serializable, Chunk { String attribName; private Vector vlines; private Line[] lines; public AttributeLine(String name) { this.attribName = name; vlines = new Vector(); } /** * 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) { this.lines = new Line[vlines.size()]; int i=0; for (i=0;i<vlines.size();i++) { this.lines[i] = (Line) vlines.get(i); if (lines[i] != null) { //((Line) lines[i]).seal(); } else { lines[i] = new Line(); ((Line) lines[i]).addChunk(new TextChunk("")); ((Line) lines[i]).seal(); } } 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(500); int i =0; Line line; String ln; //StringBuffer output = new StringBuffer(""); buffer.append(' ').append(this.attribName).append("=\""); while (i < this.lines.length) { line = lines[i]; ln = line.toString(head,tmp); if (ln != null) { ln = ln.replaceAll("\n",""); tmp.append(ln); } i++; } i=0; if (tmp.charAt(tmp.length()-1) == ' ') tmp.deleteCharAt(tmp.length()-1); buffer.append(tmp.toString().trim()); buffer.append("\""); //return output.toString(); return null; } /* (non-Javadoc) * @see net.sourceforge.idrs.core.report.Line#toDOM(net.sourceforge.idrs.core.report.IDRSHead, org.w3c.dom.Document, org.w3c.dom.Element) */ public void toDOM(IDRSHead head, Document doc, Element root) throws Exception { StringBuffer tmp = new StringBuffer(500); int i =0; Line line; String ln; while (i < this.lines.length) { line = lines[i]; ln = line.toString(head,tmp); if (ln != null) { ln = ln.replaceAll("\n",""); tmp.append(ln); } i++; } if (tmp.charAt(tmp.length()-1) == ' ') tmp.deleteCharAt(tmp.length()-1); root.setAttribute(this.attribName,tmp.toString().trim()); } } --- NEW FILE: TagLine.java --- /* * Created on Aug 22, 2004 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ package net.sourceforge.idrs.core.report; import java.io.Serializable; import java.util.ArrayList; import java.util.Vector; import org.w3c.dom.Document; import org.w3c.dom.Element; import net.sourceforge.idrs.utils.DB; /** * @author mlb * *Respnonsable for generating XML tags */ public class TagLine extends Line implements Chunk, Serializable { String tagName; private Vector vlines; private Line[] lines; private AttributeLine[] attribs; boolean trim; public TagLine(String name,boolean trim) { this.tagName = name; vlines = new Vector(); this.trim = trim; } /** * 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(); ArrayList lattribs = 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(); } if (l instanceof AttributeLine) { lattribs.add(l); } else { llines.add(l); } } lines = new Line[llines.size()]; System.arraycopy(llines.toArray(),0,lines,0,lines.length); attribs = new AttributeLine[lattribs.size()]; System.arraycopy(lattribs.toArray(),0,attribs,0,attribs.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(500); int i =0,m; Line line; String ln; //StringBuffer output = new StringBuffer(""); buffer.append('<').append(this.tagName).append(' '); for (i=0,m=attribs.length;i<m;i++) { attribs[i].toString(head,buffer); } buffer.append(">\n"); i = 0; while (i < this.lines.length) { line = lines[i]; 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); if (trim) { buffer.append(tmp.toString().trim()); } else { buffer.append(tmp); } buffer.append("</").append(this.tagName).append(">\n"); //return output.toString(); return null; } /* (non-Javadoc) * @see net.sourceforge.idrs.core.report.Line#toDOM(net.sourceforge.idrs.core.report.IDRSHead, org.w3c.dom.Document, org.w3c.dom.Element) */ public void toDOM(IDRSHead head, Document doc, Element root) throws Exception { StringBuffer tmp = new StringBuffer(500); int i =0,m; Line line; String ln; //StringBuffer output = new StringBuffer(""); Element element = doc.createElement(tagName); if (root == null) { doc.appendChild(element); } else { root.appendChild(element); } for (i=0,m=attribs.length;i<m;i++) { attribs[i].toDOM(head,doc,element); } i = 0; while (i < this.lines.length) { line = lines[i]; line.toDOM(head,doc,element); i++; } i=0; } } Index: IDRSCompiler.java =================================================================== RCS file: /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/core/report/IDRSCompiler.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** IDRSCompiler.java 18 Jan 2002 15:26:17 -0000 1.5 --- IDRSCompiler.java 22 Aug 2004 23:52:31 -0000 1.6 *************** *** 81,84 **** --- 81,85 ---- PrintWriter logOutw; PrintStream logOuts; + private String tagName; *************** *** 928,931 **** --- 929,935 ---- ObjectChunk objChunk; RepeatLine repLine; + TagLine tagLine; + String tagName; + String attribname; Vector tmpVec; String dbname; *************** *** 933,936 **** --- 937,943 ---- Line tmpLn; IfResultsChunk ifrs; + AttributeLine attribLine; + + boolean trim; if (start < line.length()) { //TODO:Create an ObjectChunk with a given varlist, methodName, and objName *************** *** 1121,1125 **** start = line.length(); } ! /* We're ignoring this for now --- 1128,1181 ---- start = line.length(); } ! else if (line.indexOf("<tag") != -1) { ! start = line.indexOf("\"",line.indexOf("name")) + 1; ! end = line.indexOf("\"",start + 1) ; ! ! ! ! ! ! tagName = useLine.substring(start,end); ! ! if (line.indexOf("trim",end) != 1) { ! start = line.indexOf("\"",line.indexOf("trim")) + 1; ! end = line.indexOf("\"",start + 1) ; ! trim = useLine.substring(start,end).equals("true"); ! } else { ! trim = true; ! } ! ! tagLine = new TagLine(tagName,trim); ! currentLine = tagLine; ! Vector lines = new Vector(); ! useLine = getLine(); ! line = useLine.toLowerCase(); ! while (line.indexOf("</tag>") == -1) { ! tagLine.addLine(procLine(useLine,0,null,repLn)); ! ! useLine = getLine(); ! line = useLine.toLowerCase(); ! } ! tagLine.seal(); ! start = line.length(); ! } ! else if (line.indexOf("<attribute") != -1) { ! start = line.indexOf("\"",line.indexOf("name")) + 1; ! end = line.indexOf("\"",start + 1) ; ! attribname = useLine.substring(start,end); ! attribLine = new AttributeLine(attribname); ! currentLine = attribLine; ! Vector lines = new Vector(); ! useLine = getLine(); ! line = useLine.toLowerCase(); ! while (line.indexOf("</attribute>") == -1) { ! attribLine.addLine(procLine(useLine,0,null,repLn)); ! ! useLine = getLine(); ! line = useLine.toLowerCase(); ! } ! attribLine.seal(); ! start = line.length(); ! } /* We're ignoring this for now *************** *** 1171,1175 **** } else { ! currentLine = createLine(currentLine); currentLine.addChunk(new TextChunk(useLine.substring(start))); --- 1227,1231 ---- } else { ! currentLine = createLine(currentLine); currentLine.addChunk(new TextChunk(useLine.substring(start))); Index: Line.java =================================================================== RCS file: /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/core/report/Line.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Line.java 6 Feb 2003 20:13:45 -0000 1.6 --- Line.java 22 Aug 2004 23:52:31 -0000 1.7 *************** *** 16,19 **** --- 16,28 ---- import java.util.*; + import javax.xml.parsers.DocumentBuilder; + import javax.xml.parsers.DocumentBuilderFactory; + + import org.apache.crimson.tree.TextNode; + import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl; + import org.w3c.dom.Document; + import org.w3c.dom.Element; + import org.w3c.dom.Text; + /** Line<br> *************** *** 76,79 **** --- 85,113 ---- } } + + public void toDOM(IDRSHead head,Document doc,Element root) throws Exception { + // StringBuffer vals = new StringBuffer(""); + + if (root == null) { + return; + } + Chunk ch; + //System.out.println("Number of chunks : " + chunks.length); + StringBuffer buff = new StringBuffer(500); + for (int i=0; i<chunks.length;i++) { + ch = chunks[i]; + String text = ch.toString(head).trim(); + if (text.length() != 0) { + buff.append(text); + } + + } + + if (buff.length() != 0) { + Text txt = doc.createTextNode(buff.toString()); + root.appendChild(txt); + } + } + /** Index: IDRSRep.java =================================================================== RCS file: /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/core/report/IDRSRep.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** IDRSRep.java 14 Sep 2001 23:46:42 -0000 1.3 --- IDRSRep.java 22 Aug 2004 23:52:31 -0000 1.4 *************** *** 15,18 **** --- 15,20 ---- import java.io.*; + import org.w3c.dom.Document; + /** IDRSRep<br> *************** *** 71,75 **** --- 73,85 ---- return e.toString(); } + + } + + public Document buildDDMReport() throws Exception { + + return body.toDOM(head); + + } /** Index: PortalChunk.java =================================================================== RCS file: /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/core/report/PortalChunk.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PortalChunk.java 22 Nov 2002 07:16:24 -0000 1.1 --- PortalChunk.java 22 Aug 2004 23:52:31 -0000 1.2 *************** *** 14,17 **** --- 14,21 ---- import java.io.Serializable; import java.util.*; + + import org.w3c.dom.Document; + import org.w3c.dom.Element; + import net.sourceforge.idrs.utils.*; import net.sourceforge.idrs.core.report.*; *************** *** 68,72 **** --- 72,109 ---- return ""; } + + + + + /* (non-Javadoc) + * @see net.sourceforge.idrs.core.report.Line#toDOM(net.sourceforge.idrs.core.report.IDRSHead, org.w3c.dom.Document, org.w3c.dom.Element) + */ + public void toDOM(IDRSHead head, Document doc, Element root) + 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].toDOM(head,doc,root); + } + //buff.append(super.toString(head)); + } + } public void setLines(Vector lines) { Index: RepeatLine.java =================================================================== RCS file: /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/core/report/RepeatLine.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RepeatLine.java 21 Sep 2002 16:13:03 -0000 1.6 --- RepeatLine.java 22 Aug 2004 23:52:31 -0000 1.7 *************** *** 17,20 **** --- 17,24 ---- import java.util.*; import java.io.*; + + import org.w3c.dom.Document; + import org.w3c.dom.Element; + import net.sourceforge.idrs.utils.*; *************** *** 91,95 **** lineNum++; } ! buffer.deleteCharAt(buffer.length()-1); lineNum=0; --- 95,99 ---- lineNum++; } ! if (buffer.charAt(buffer.length()-1) == ' ') buffer.deleteCharAt(buffer.length()-1); lineNum=0; *************** *** 100,103 **** --- 104,134 ---- + /* (non-Javadoc) + * @see net.sourceforge.idrs.core.report.Line#toDOM(net.sourceforge.idrs.core.report.IDRSHead, org.w3c.dom.Document, org.w3c.dom.Element) + */ + public void toDOM(IDRSHead head, Document doc, Element root) + throws Exception { + DB db = head.getDB(id); + lineNum = 0; + int i =0; + Line line; + String ln; + //StringBuffer output = new StringBuffer(""); + while (db.next()) { + while (i < this.lines.length) { + line = lines[i]; + + line.toDOM(head,doc,root); + + + i++; + } + + i=0; + lineNum++; + } + + lineNum=0; + } /** Wether or not the set should has another results Index: IfResultsChunk.java =================================================================== RCS file: /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/core/report/IfResultsChunk.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** IfResultsChunk.java 6 Feb 2003 20:13:44 -0000 1.5 --- IfResultsChunk.java 22 Aug 2004 23:52:31 -0000 1.6 *************** *** 16,19 **** --- 16,23 ---- import java.io.*; import java.util.*; + + import org.w3c.dom.Document; + import org.w3c.dom.Element; + import net.sourceforge.idrs.utils.*; *************** *** 137,141 **** } ! buffer.deleteCharAt(buffer.length()-1); --- 141,145 ---- } ! if (buffer.charAt(buffer.length()-1) == ' ') buffer.deleteCharAt(buffer.length()-1); *************** *** 144,147 **** --- 148,188 ---- } + + + + /* (non-Javadoc) + * @see net.sourceforge.idrs.core.report.Line#toDOM(net.sourceforge.idrs.core.report.IDRSHead, org.w3c.dom.Document, org.w3c.dom.Element) + */ + public void toDOM(IDRSHead head, Document doc, Element root) + throws Exception { + DB db = head.getDB(dbname); + + int i =0; + Line line; + String ln; + + if (db.hasResults()) { + while (i < this.elines.length) { + line = elines[i]; + + line.toDOM(head,doc,root); + + + i++; + } + } + else { + while (i < this.dlines.length) { + line = dlines[i]; + + line.toDOM(head,doc,root); + + + i++; + } + } + + + } /** Does nothing, fulfills Chunk interface Index: IfChangeChunk.java =================================================================== RCS file: /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/core/report/IfChangeChunk.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** IfChangeChunk.java 4 Mar 2002 23:05:34 -0000 1.4 --- IfChangeChunk.java 22 Aug 2004 23:52:31 -0000 1.5 *************** *** 18,21 **** --- 18,24 ---- import java.io.*; + import org.w3c.dom.Document; + import org.w3c.dom.Element; + /** *************** *** 99,102 **** --- 102,141 ---- } + + + + /* (non-Javadoc) + * @see net.sourceforge.idrs.core.report.Line#toDOM(net.sourceforge.idrs.core.report.IDRSHead, org.w3c.dom.Document, org.w3c.dom.Element) + */ + public void toDOM(IDRSHead head, Document doc, Element root) + throws Exception { + Line line; + //StringBuffer output = new StringBuffer(""); + + //first we'll check if the value has been initiated + DB data = head.getDB(db); + String dataVal = data.getFieldData(field,null); + + boolean run = false; + + + run = ((! dataVal.equalsIgnoreCase(current)) || (current == null)); + + + //we'll update current regardless + current = dataVal; + + //loop throuhg all of the lines and retrieve the lines of data + if (run) { + int i =0; + while (i < lines.length) { + line = lines[i]; + //buffer.append( line.toString(head) ); + line.toDOM(head,doc,root); + i++; + } + } + + } /** "Seals" the report head into static data structures from dynamic ones Index: IDRSBody.java =================================================================== RCS file: /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/core/report/IDRSBody.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** IDRSBody.java 21 Sep 2002 16:13:03 -0000 1.7 --- IDRSBody.java 22 Aug 2004 23:52:31 -0000 1.8 *************** *** 16,19 **** --- 16,25 ---- import java.util.*; + import javax.xml.parsers.DocumentBuilder; + import javax.xml.parsers.DocumentBuilderFactory; + + import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl; + import org.w3c.dom.Document; + /** * IDRSBody<br> *************** *** 102,105 **** --- 108,146 ---- } + public Document toDOM(IDRSHead head) throws Exception { + prepBody(); + buffer = new StringBuffer(); + head.setPrintTarget(buffer); + int i = 0; + String output = head.getText(this); + Line ln; + // System.out.println("lines : " + lines.length) + DocumentBuilderFactory factory = new DocumentBuilderFactoryImpl();//DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + + DocumentBuilder builder = factory.newDocumentBuilder(); + + Document doc = builder.newDocument(); + for (i=0; i< lines.length; i++) { + ln = lines[i]; + if (ln == null) { + //output += "\n"; + + + } + else { + //output += ln.toString(head) + "\n"; + //ln.toString(head,buffer); + ln.toDOM(head,doc,null); + + + } + } + + + return doc; + + } + /** * Defines wether or not a report is HTML |