|
[HepData-svn] r1386 - trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/pagesblackhole at projects.hepforge.org blackhole at projects.hepforge.orgWed Sep 1 10:31:58 BST 2010
Author: whalley Date: Wed Sep 1 10:31:57 2010 New Revision: 1386 Log: adding table display for review Added: trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/pages/ViewTable.java Added: trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/pages/ViewTable.java ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/pages/ViewTable.java Wed Sep 1 10:31:57 2010 (r1386) @@ -0,0 +1,204 @@ +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 ViewTable 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|bdms|hepml)" + "\\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("hepml")) return asHepML(); + if (fmt.equals("bdms")) return asBDMS(); + 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 getHepMLContext() { + return formatContext("hepml"); + } + public StreamResponse asHepML() { + Paper p = getPaper(); + String asHepML = HepMLFormatter.format(p); + if (asHepML == null) { + asHepML = "No valid paper specified"; + } + return new TextStreamResponse("text/plain", asHepML); + } + + public Object getBdmsContext() { + return formatContext("bdms"); + } + public StreamResponse asBDMS() { + Paper p = getPaper(); + String asBDMS = BdmsFormatter.format(p); + if (asBDMS == null) { + asBDMS = "No valid paper specified"; + } + return new TextStreamResponse("text/plain", asBDMS); + } + + + 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(); + } + + +}
More information about the HepData-svn mailing list |