[HepData-svn] r1333 - in trunk: hepdata-model/src/main/java/cedar/hepdata/model hepdata-webapp/src/main/java/cedar/hepdata/formats hepdata-webapp/src/main/java/cedar/hepdata/webapp/pages

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Mon Jan 4 09:33:30 GMT 2010


Author: whalley
Date: Mon Jan  4 09:33:30 2010
New Revision: 1333

Log:
adding bdms output formatter for internal use

Added:
   trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/BdmsFormatter.java
Modified:
   trunk/hepdata-model/src/main/java/cedar/hepdata/model/Paper.java
   trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/pages/View.java

Modified: trunk/hepdata-model/src/main/java/cedar/hepdata/model/Paper.java
==============================================================================
--- trunk/hepdata-model/src/main/java/cedar/hepdata/model/Paper.java	Thu Dec 17 10:18:09 2009	(r1332)
+++ trunk/hepdata-model/src/main/java/cedar/hepdata/model/Paper.java	Mon Jan  4 09:33:30 2010	(r1333)
@@ -185,6 +185,107 @@
         return firstpreprint;
     }
 
+    public String getReferenceString(int n){
+        StringBuffer s = new StringBuffer();
+        String refstring = null;
+	int nc = 0;
+	for(Reference ref : getReferences()){
+	    nc += 1;
+	    if(nc == n){
+	        if(n==1) { s.append("R = " + ref.getDescription() + ";"); }
+		else     { s.append("R.= " + ref.getDescription() + ";"); }    
+		s.append("    TY = " + ref.getType() + ";");
+		s.append("    D = " + ref.getDate() + ";");	    
+	        refstring = s.toString();
+		break;
+	    }
+	}
+	return refstring;
+    }
+
+    public String getModificationString(int n){
+        StringBuffer s = new StringBuffer();
+        String modstring = null;
+	int nc = 0;
+	for(Modification mod : getModifications()){
+	    nc += 1;
+	    if(nc == n){
+	        if( mod.getModifier()!=null){
+	            if(n==1) { s.append("DES = Modified" + " by " + mod.getModifier() + ";"); }
+		    else     { s.append("DES.= Modified" + " by " + mod.getModifier() + ";"); }    
+	            modstring = s.toString();
+		    break;
+		}
+	    }
+	}
+	return modstring;
+    }
+
+    public String getExperimentString(int n){
+//        StringBuffer s = new StringBuffer();
+        String expstring = null;
+	int nc = 0;
+	for(Experiment exp : getExperiments()){
+	    nc += 1;
+	    if(nc == n){
+	        if( exp.getName()!=null){
+	            if(n==1) { expstring = "EXP = " + exp.getName() + ";"; }
+		    else     { expstring = "EXP.= " + exp.getName() + ";"; }    
+//	            expstring = s.toString();
+		    break;
+		}
+	    }
+	}
+	return expstring;
+    }
+    public String getDetectorString(int n){
+        StringBuffer s = new StringBuffer();
+        String destring = null;
+	int nc = 0;
+	for(Experiment exp : getExperiments()){
+	    nc += 1;
+	    if(nc == n){
+	        if( exp.getInformalName()!=null){
+	            if(n==1) { s.append("DE = " + exp.getInformalName() + ";"); }
+		    else     { s.append("DE.= " + exp.getInformalName() + ";"); }    
+	            destring = s.toString();
+		    break;
+		}
+	    }
+	}
+	return destring;
+    }
+
+    public String getCommentString(int n){
+        StringBuffer s = new StringBuffer();
+        String crstring = null;
+	int nc = 0;
+	for(String cr : getComments()){
+	    nc += 1;
+	    if(nc == n){
+	        if( cr!=null){
+	            if(n==1) { s.append("CR = " + cr + ";"); }
+		    else     { s.append("CR.= " + cr + ";"); } 
+//		    int num = s.length()/80;
+//		    for (int i=0; i<num; i++){
+//		        System.out.println("s.length() " + s.length());
+//		        s.insert(80*(i+1)+1+i,'\n');
+//		    }   
+                    if(s.length()>80) { s.insert(80,"\n"); }
+                    if(s.length()>161){ s.insert(161,"\n"); }
+                    if(s.length()>242){ s.insert(242,"\n"); }
+                    if(s.length()>323){ s.insert(323,"\n"); }
+                    if(s.length()>404){ s.insert(404,"\n"); }
+                    if(s.length()>485){ s.insert(485,"\n"); }
+                    if(s.length()>566){ s.insert(566,"\n"); }
+	            crstring = s.toString();
+		   
+		    break;
+		}
+	    }
+	}
+	return crstring;
+    }
 
     ////////////////////////////////////////////////////////
 

Added: trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/BdmsFormatter.java
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/BdmsFormatter.java	Mon Jan  4 09:33:30 2010	(r1333)
@@ -0,0 +1,56 @@
+package cedar.hepdata.formats;
+
+import cedar.hepdata.model.*;
+import cedar.hepdata.util.*;
+import cedar.hepdata.xml.*;
+import cedar.hepdata.db.*;
+
+import java.util.*;
+
+import org.antlr.stringtemplate.*;
+
+
+public class BdmsFormatter {
+
+    public static String format(Paper p) {
+        if(p == null) return null;
+	StringBuffer s = new StringBuffer();
+	s.append("BDMS output:\n\n");
+	s.append("SC = " + p.getShortName() + ";" + "     RED = " + p.getRedId() + ";\n");
+
+        for (int n=1; n<4; n++){
+	    if(p.getReferenceString(n) != null){ s.append(p.getReferenceString(n) + "\n"); }
+	    else{ break; }	
+        }
+
+        for (int n=1; n<4; n++){
+	    if(p.getModificationString(n) != null){ s.append(p.getModificationString(n) + "\n"); }
+	    else{ break; }	
+        }
+
+        for (int n=1; n<4; n++){
+	    if(p.getCommentString(n) != null){ s.append(p.getCommentString(n) + "\n"); }
+	    else{ break; }	
+        }
+
+        for (int n=1; n<4; n++){
+	    if(p.getExperimentString(n) != null){ s.append(p.getExperimentString(n) + "\n"); }
+	    else{ break; }	
+        }
+
+        for (int n=1; n<4; n++){
+	    if(p.getDetectorString(n) != null){ s.append(p.getDetectorString(n) + "\n"); }
+	    else{ break; }	
+        }
+
+        if(p.getSpiresId()!=null) s.append("IRN = " + p.getSpiresId() + ";\n");
+
+        for (Dataset ds : p.getDatasets()){
+	    s.append("Dataset\n");
+	} 
+	
+        return s.toString();
+    }
+
+
+}

Modified: trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/pages/View.java
==============================================================================
--- trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/pages/View.java	Thu Dec 17 10:18:09 2009	(r1332)
+++ trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/pages/View.java	Mon Jan  4 09:33:30 2010	(r1333)
@@ -36,7 +36,7 @@
         parseBaseViewContext(context);
 
         // Handle pattern parsing separately
-        Pattern patt = Pattern.compile("\\A" + "(short|long|full|plain|yoda|aida|pyroot|root|mpl)" + "\\Z",
+        Pattern patt = Pattern.compile("\\A" + "(short|long|full|plain|yoda|aida|pyroot|root|mpl|bdms)" + "\\Z",
                                        Pattern.CASE_INSENSITIVE);
         for (int i = 0; i < context.getCount(); i++) {
             String ps = context.get(String.class, i);
@@ -51,6 +51,7 @@
         // Now handle the special formats (after parsing *all* context elements)
         String fmt = getQueryParam("format");
         if (fmt != null) {
+            if (fmt.equals("bdms")) return asBDMS();
             if (fmt.equals("plain")) return asPlain();
             if (fmt.equals("aida")) return asAIDA();
             if (fmt.equals("pyroot")) return asPyROOT();
@@ -80,6 +81,18 @@
 
     ///////////////////////////////////////////////
 
+    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");


More information about the HepData-svn mailing list