SVN: toys/cvsstats/web/src/pl/org/pld/cvsstats: QueriesSet.java Query.java

pawelz pawelz at pld-linux.org
Wed Apr 14 18:16:29 CEST 2010


Author: pawelz
Date: Wed Apr 14 18:16:28 2010
New Revision: 11332

Added:
   toys/cvsstats/web/src/pl/org/pld/cvsstats/QueriesSet.java   (contents, props changed)
   toys/cvsstats/web/src/pl/org/pld/cvsstats/Query.java   (contents, props changed)
Log:
missing files. I forgot to commit them.


Added: toys/cvsstats/web/src/pl/org/pld/cvsstats/QueriesSet.java
==============================================================================
--- (empty file)
+++ toys/cvsstats/web/src/pl/org/pld/cvsstats/QueriesSet.java	Wed Apr 14 18:16:28 2010
@@ -0,0 +1,64 @@
+package pl.org.pld.cvsstats;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.apache.xerces.parsers.DOMParser;
+import org.joda.time.Interval;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
+
+public class QueriesSet {
+	
+	ArrayList<Query> queries;
+	String name;
+	
+	String title = null;
+	String description = null;
+	
+	Interval interval;
+	Uid uid;
+		
+	public QueriesSet(Uid u, String N, Stats stats) throws Exception, IOException, SAXException {
+		queries = new ArrayList<Query>();
+		
+		name = N;
+		uid = u;
+		
+		DOMParser p = new DOMParser();
+		p.parse(Configuration.getDataDir()+"/"+name+".xml");
+
+		Document doc = p.getDocument();
+		Node n = doc.getDocumentElement().getFirstChild();
+		Node q;
+
+		while (n != null) {
+			if (n.getNodeName().equals("queries")) {
+				for (q = n.getFirstChild(); q != null; q=q.getNextSibling()) {
+					if (q.getNodeName().equalsIgnoreCase("query")) {
+						queries.add(new Query(q, stats));
+					}
+				}
+			} else if (n.getNodeName().equalsIgnoreCase("description")) {
+				description = n.getTextContent();
+			} else if (n.getNodeName().equalsIgnoreCase("title")) {
+				title = n.getTextContent();
+			}
+			n = n.getNextSibling();
+		}
+	}
+	
+	public String getHtml() {
+		String rv = "";
+		int i = uid.next();
+		rv="<h2><a href='javascript:animatedcollapse.toggle(\""+i+"\")'>"+title+"</a></h2>";
+		rv += "<div id='"+i+"'>";
+		if (description != null) rv="<p>"+description+"</p>";
+		for (int r = 0; r < queries.size(); r++) {
+			rv += queries.get(r).getHTML();
+		}
+		rv += "</div>";
+		return rv;
+	}
+}

Added: toys/cvsstats/web/src/pl/org/pld/cvsstats/Query.java
==============================================================================
--- (empty file)
+++ toys/cvsstats/web/src/pl/org/pld/cvsstats/Query.java	Wed Apr 14 18:16:28 2010
@@ -0,0 +1,49 @@
+package pl.org.pld.cvsstats;
+
+import org.w3c.dom.Node;
+
+public class Query {
+
+	String id = null;
+	String title = null;
+	String description = null;
+	String sql = null;
+	Stats stats;
+	ResultsTable rs;
+	
+	public Query(Node q, Stats s) throws Exception {
+				
+		stats = s;
+		id=q.getAttributes().getNamedItem("id").getNodeValue();
+		
+		for (Node a = q.getFirstChild(); a != null; a=a.getNextSibling()) {
+			if (a.getNodeName().equalsIgnoreCase("title")) {
+				title=a.getTextContent();
+			}
+			if (a.getNodeName().equalsIgnoreCase("description")) {
+				description=a.getTextContent();
+			}
+			if (a.getNodeName().equalsIgnoreCase("sql")) {
+				sql=a.getTextContent();
+			}
+		}
+		rs = s.executeQuery(sql);
+	}
+
+	public String getHTML() {
+		String rv="";
+		if (title != null) {
+			rv+="<h3>"+title+"</h3>";
+		}
+		if (description != null) {
+			rv+="<p>"+description+"</p>";
+		}
+		rv += rs.getHtml();
+			
+		return rv;
+	}
+
+	public String getId() {
+		return id;
+	}
+}
\ No newline at end of file


More information about the pld-cvs-commit mailing list