[HepData-svn] r1330 - in trunk/hepdata-webapp/src/main: java/cedar/hepdata/webapp/pages resources/cedar/hepdata/webapp/pages

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Wed Dec 16 09:06:42 GMT 2009


Author: whalley
Date: Wed Dec 16 09:06:42 2009
New Revision: 1330

Log:
first steps to edit db via java model

Added:
   trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/pages/Edit.java
   trunk/hepdata-webapp/src/main/resources/cedar/hepdata/webapp/pages/Edit.tml

Added: trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/pages/Edit.java
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/pages/Edit.java	Wed Dec 16 09:06:42 2009	(r1330)
@@ -0,0 +1,178 @@
+package cedar.hepdata.webapp.pages;
+
+import cedar.hepdata.model.*;
+import cedar.hepdata.util.*;
+import cedar.hepdata.xml.*;
+import cedar.hepdata.db.*;
+import cedar.hepdata.formats.*;
+
+import org.apache.tapestry5.EventContext;
+import org.apache.tapestry5.StreamResponse;
+import org.apache.tapestry5.util.TextStreamResponse;
+import org.apache.tapestry5.annotations.*;
+import org.apache.tapestry5.ioc.annotations.*;
+import org.apache.tapestry5.services.*;
+
+import org.hibernate.*;
+import org.hibernate.criterion.*;
+import java.util.*;
+import java.util.regex.*;
+import java.io.File;
+
+
+public class Edit extends ViewBase {
+
+    // @Inject
+    // private Request _req;
+    // public Request getRequest() { return _req; }
+
+    // @Inject
+    // private org.hibernate.Session _session;
+
+
+    // Decode URL context into the params map
+    public StreamResponse onActivate(EventContext context) {
+        // Do the basic parsing via the base class
+        parseBaseViewContext(context);
+
+        // Handle pattern parsing separately
+        Pattern patt = Pattern.compile("\\A" + "(short|long|full|plain|yoda|aida|pyroot|root|mpl)" + "\\Z",
+                                       Pattern.CASE_INSENSITIVE);
+        for (int i = 0; i < context.getCount(); i++) {
+            String ps = context.get(String.class, i);
+            Matcher m = patt.matcher(ps);
+            if (m.matches()) {
+                setQueryParam("format", m.group(1).toLowerCase());
+            } else {
+                setQueryParam("format", "full");
+            }
+        }
+
+        // Now handle the special formats (after parsing *all* context elements)
+        String fmt = getQueryParam("format");
+        if (fmt != null) {
+            if (fmt.equals("plain")) return asPlain();
+            if (fmt.equals("aida")) return asAIDA();
+            if (fmt.equals("pyroot")) return asPyROOT();
+            if (fmt.equals("yoda")) return asYODA();
+            if (fmt.equals("root")) return asROOT();
+            //if (fmt.equals("mpl")) return asPlain();
+            //if (fmt.equals("gnuplot")) return asPlain();
+        }
+
+        // Normal rendering
+        return null;
+    }
+
+
+    public Object formatContext(String fmt) {
+        Vector<String> ctx = new Vector<String>(getBaseContext());
+        ctx.add(fmt);
+        return ctx;
+    }
+    public Object getShortContext() {
+        return formatContext("short");
+    }
+    public Object getFullContext() {
+        return getBaseContext();
+    }
+
+
+    ///////////////////////////////////////////////
+
+
+    public Object getPlainContext() {
+        return formatContext("plain");
+    }
+    public StreamResponse asPlain() {
+        Set<Dataset> ds = getDatasets();
+        String asPlain = PlainFormatter.format(ds, getQueryX(), getQueryY());
+        if (asPlain == null) {
+            asPlain = "No valid paper and dataset specified";
+        }
+        return new TextStreamResponse("text/plain", asPlain);
+    }
+
+
+    public Object getYodaContext() {
+        return formatContext("yoda");
+    }
+    public StreamResponse asYODA() {
+        Set<Dataset> ds = getDatasets();
+        String asYODA = YodaFormatter.format(ds);
+        if (asYODA == null) {
+            asYODA = "No valid paper and dataset specified";
+        }
+        return new TextStreamResponse("text/plain", asYODA);
+    }
+
+
+    public Object getAidaContext() {
+        return formatContext("aida");
+    }
+    public StreamResponse asAIDA() {
+        Set<Dataset> ds = getDatasets();
+        String asAIDA = AidaFormatter.format(ds);
+        if (asAIDA == null) {
+            asAIDA = "No valid paper and dataset specified";
+        }
+        return new TextStreamResponse("text/xml", asAIDA);
+    }
+
+
+    public Object getRootContext() {
+        return formatContext("root");
+    }
+    public StreamResponse asROOT() {
+        return new TextStreamResponse("text/plain",
+                                      "This will be a ROOT macro once I get round to it...");
+    }
+
+
+    public Object getPyRootContext() {
+        return formatContext("pyroot");
+    }
+    public StreamResponse asPyROOT() {
+        Set<Dataset> ds = getDatasets();
+        String asPyRoot = PyRootFormatter.format(ds);
+        if (asPyRoot == null) {
+            asPyRoot = "No valid paper and dataset specified";
+        }
+        return new TextStreamResponse("text/plain", asPyRoot);
+    }
+
+
+    //////////////////////////////////////////
+
+
+    public String getFormat() {
+        String fmt = getQueryParam("format");
+        if (fmt == null) fmt = "full";
+        return fmt;
+    }
+
+    public boolean getShortFormat() {
+        return getFormat().equals("short");
+    }
+
+    public boolean getLongFormat() {
+        return getFormat().equals("full");
+    }
+
+    public boolean getShowList() {
+        return getShortFormat();
+    }
+
+
+    public boolean getShowSys() {
+        return getLongFormat();
+    }
+
+    public boolean getHaveSys() {
+	    String filename = "/home/whalley/systematics/files/" + getPaper().getSpiresId() + ".sys";
+        File testfile = new File(filename);
+        return testfile.exists();
+    }
+
+
+}

Added: trunk/hepdata-webapp/src/main/resources/cedar/hepdata/webapp/pages/Edit.tml
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/hepdata-webapp/src/main/resources/cedar/hepdata/webapp/pages/Edit.tml	Wed Dec 16 09:06:42 2009	(r1330)
@@ -0,0 +1,114 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html t:type="layout" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+
+  <t:if test="paper.hepdataId">
+    <h2> Reaction Database Edit Record</h2>
+    Edit
+    <title>HepData &ndash; ${paper.shortName}</title>
+
+    <div class="paperbox">
+      <h2 class="papertitle">
+        <a href="#" t:type="pagelink" t:page="view" t:context="paperContext">${paper.shortName}</a> 
+        &mdash; ${paper.title}
+      </h2>
+
+      <t:if test="queryD">
+        <h4>
+          Showing only dataset(s): ${queryD} 
+          (<a href="#" t:type="pagelink" t:page="view" t:context="paperContext">show all</a>)
+        </h4>
+      </t:if>
+
+
+      <p>
+        Experiment:
+        <a href="http://durpdg.dur.ac.uk/cgi-bin/spiface/experiments/www2?fin+expt+${paper.experimentName}">
+          <b>${paper.experimentName} (${paper.informalName})</b></a>
+        <br/>
+        Published in <b>${paper.firstPublished}</b>
+        <br/>
+        Preprinted as <b>${paper.firstPreprint}</b> 
+        <br/>
+        <t:if test="paper.spiresId">
+          Spires ID (IRN): <b>${paper.spiresId}</b>
+          <a href="http://durpdg.dur.ac.uk/cgi-bin/spiface/hep/www?irn+${paper.spiresId}">(View)</a> 
+        </t:if>
+       </p>
+
+      <div class="papercomments">
+        <t:displayPaperComments p="paper" />
+      </div>
+      <p>
+          <a href="/saveplot?list=all"
+           title="Show the datasets which have been selected for combined plotting">View list of currently selected plots</a>
+        <!-- <t:if test="searchquery"> -->
+        <!--   | <a href="search?q=${searchquery}">Back to search...</a> -->
+        <!-- </t:if> -->
+     </p>
+
+      <t:if test="showSys">
+         <t:if test="haveSys">
+            <h4 class="datasettitle">
+            Additional Systematic Errors and Comments
+            </h4>
+            <div class="systematics">        
+                <t:displaySystematics p="paper" />
+            </div>
+        </t:if>
+      </t:if>
+
+      <t:if test="isMultiPage">
+        <p>
+          Total number of tables: <b>${paper.datasets.size()}</b>.&nbsp; 
+          Displaying: <b>${counter}</b> to <b>${counterend}</b>.&nbsp; 
+          <a href="#" t:type="pagelink" t:page="view" t:context="firstcontext">First</a>&nbsp;|&nbsp; 
+          <a href="#" t:type="pagelink" t:page="view" t:context="prevcontext">Previous</a>&nbsp;|&nbsp;
+          <a href="#" t:type="pagelink" t:page="view" t:context="nextcontext">Next</a>&nbsp;|&nbsp;
+          <a href="#" t:type="pagelink" t:page="view" t:context="lastcontext">Last</a>
+        </p>
+      </t:if>
+      
+      <t:loop source="datasetsnew" value="dataset">
+        <div class="datasetbox">
+          <h3 class="datasettitle">
+            <a href="#" t:type="pagelink" t:page="view" t:context="baseContext">Table ${dataset.id}</a>
+          </h3>
+          <!-- <p class="altdsformats"> -->
+          as:
+          <a href="#" t:type="pagelink" t:page="view" t:context="plainContext">plain text</a>&nbsp;
+          <a href="#" t:type="pagelink" t:page="view" t:context="aidaContext">AIDA</a>&nbsp;
+          <a href="#" t:type="pagelink" t:page="view" t:context="pyrootContext">PyROOT</a>&nbsp;
+          <!-- <a href="#" t:type="pagelink" t:page="view" t:context="yodaContext">YODA</a> -->
+          <!-- </p> -->
+          <t:datasetAsHtml dataset="dataset" format="${format}" />
+        </div>
+      </t:loop>
+      <t:if test="isMultiPage">
+        <p>
+          Total number of tables: <b>${paper.datasets.size()}</b>.&nbsp; 
+          Displaying: <b>${counter}</b> to <b>${counterend}</b>.&nbsp; 
+          <a href="#" t:type="pagelink" t:page="view" t:context="firstcontext">First</a>&nbsp;|&nbsp; 
+          <a href="#" t:type="pagelink" t:page="view" t:context="prevcontext">Previous</a>&nbsp;|&nbsp;
+          <a href="#" t:type="pagelink" t:page="view" t:context="nextcontext">Next</a>&nbsp;|&nbsp;
+          <a href="#" t:type="pagelink" t:page="view" t:context="lastcontext">Last</a>
+        </p>
+      </t:if>
+      
+    </div>
+    
+    <t:parameter name="else">
+      
+      <title>HepData paper view</title>
+      <h2>No valid paper could be found with the given ID/IRN</h2>
+      
+    </t:parameter>
+  </t:if>
+  <p class="permalinks">
+    Permalinks: 
+    <a href="#" t:type="pagelink" t:page="view" t:context="hdpaperContext">by HepData ID</a> |
+    <a href="#" t:type="pagelink" t:page="view" t:context="spiresContext">by Spires ID</a>
+    <br/>
+   (Reaction db ID=${paper.id}, RED=${paper.redid})
+  </p>
+
+</html>


More information about the HepData-svn mailing list