[HepData-svn] r1376 - trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Wed Aug 11 17:12:28 BST 2010


Author: whalley
Date: Wed Aug 11 17:12:28 2010
New Revision: 1376

Log:
adding trial HepML formatter

Added:
   trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/HepMLFormatter.java

Added: trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/HepMLFormatter.java
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/HepMLFormatter.java	Wed Aug 11 17:12:28 2010	(r1376)
@@ -0,0 +1,177 @@
+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 HepMLFormatter {
+
+    public static String format(Paper p) {
+        if(p == null) return null;
+	    StringBuffer s = new StringBuffer();
+        s.append("<hepml>\n");
+        s.append("  <data timestamp=''>\n");
+        s.append("    <paper hepdataId='" + p.getHepdataId() + "' spiresId='" + p.getSpiresId() + "' redId='" + p.getRedId() + "' preprintDate=''>\n");
+        s.append("      <title>\n");
+        s.append("        " + p.getTitle() + "\n");
+        s.append("      </title>\n");
+        for (Modification mod : p.getModifications()){
+            s.append("      <modification who='" + mod.getModifier() + "' when='" + mod.getComment() + "' />\n");
+        }
+        for (String cr : p.getComments()){
+            s.append("      <comment>\n");    
+            s.append("        " + cr + "\n");
+            s.append("      </comment>\n");    
+        }
+        for (String auth : p.getAuthors()){
+            s.append("      <author>\n");    
+            s.append("        " + auth + "\n");
+            s.append("      </author>\n");    
+        }
+        for (Reference ref : p.getReferences()){
+            s.append("      <reference description='" + ref.getDescription() + "' type='" + ref.getType() + "' date='" + ref.getDate() + "' />\n");
+        }
+        for (Experiment exp : p.getExperiments()){
+            s.append("      <experiment name='" + exp.getName() + "' laboratory='" + exp.getLaboratory() + "' informalname='" + exp.getInformalName() + "' />\n");
+        }
+    
+        for (Dataset ds : p.getDatasets()){
+            s.append("      <dataset id='ds-99-" + ds.getId() + "' datasetId='" + ds.getId() + "'>\n");    
+            for (String ct : ds.getComments()){
+                s.append("        <comment>\n");    
+                s.append("          " + ct + "\n");
+                s.append("        </comment>\n");    
+            }
+            for (String dr : ds.getDsReactions()){
+                s.append("        <dsreaction>\n");    
+                s.append("          " + dr + "\n");
+                s.append("        </dsreaction>\n");    
+            }
+            for (String ob : ds.getDsObservables()){
+                s.append("        <dsobservable>\n");    
+                s.append("          " + ob + "\n");
+                s.append("        </dsobservable>\n");    
+            }
+            for (String pl : ds.getDsPlabs()){
+                s.append("        <dsplab>\n");    
+                s.append("          " + pl + "\n");
+                s.append("        </dsplab>\n");    
+            }
+            for (DatasetProperty dsprop : ds.getProperties()){
+                s.append("        <property");
+                if(dsprop.getName() != null){ s.append(" name='" + dsprop.getName() + "'"); }
+                if(dsprop.getUnit() != null){ s.append(" unit='" + dsprop.getUnit() + "'"); }
+                if(dsprop.getLowValue() != null){ s.append(" low='" + dsprop.getLowValue() + "'"); }
+                if(dsprop.getHighValue() != null){ s.append(" high='" + dsprop.getHighValue() + "'"); }
+                if(dsprop.getFocus() != null){ s.append(" focus='" + dsprop.getFocus() + "'"); }
+                s.append(" />\n");
+            }
+            for (DatasetError err : ds.getErrors()){
+                s.append("        <error");
+                if(err.getPlus() != null){ s.append(" plus='" + err.getPlus() + "'"); }
+                if(err.getMinus() != null){ s.append(" minus='" + err.getMinus() + "'"); }
+                if(err.getSourceType() != null){ s.append(" source='" + err.getSourceType().toShortString() + "'"); }
+                if(err.getNormType() != null){ s.append(" norm='" + err.getNormType().toSymbol() + "'"); }
+                if(err.getComment() != null){ s.append(" comment='" + err.getComment() + "'"); }
+                s.append(" />\n");
+            }
+            for (XAxis xax : ds.getXAxes()){
+                s.append("        <xaxis id='xax-99-" + xax.getId() + "' xaxisId='" + xax.getId() + "' header='" + xax.getHeader() + "'>\n");    
+                s.append("          <bins>\n");    
+                for (Bin bn : xax.getBins()){
+                    s.append("            <bin binId='" + bn.getId() + "'");
+                    if(bn.getFocus() != null){ s.append(" focus='" + bn.getFocus() + "'"); }
+                    if(bn.getLowValue() != null){ s.append(" low='" + bn.getLowValue() + "'"); }
+                    if(bn.getHighValue() != null){ s.append(" high='" + bn.getHighValue() + "'"); }
+                    if(bn.getWidth() != null){ s.append(" width='" + bn.getWidth() + "'"); }
+                    if(bn.getRelation() != null){ s.append(" relation='" + bn.getRelation().toString() + "'"); }
+                    s.append(" />\n");
+                }
+                s.append("          </bins>\n");    
+                s.append("        </xaxis>\n");    
+            }
+            for (YAxis yax : ds.getYAxes()){
+                s.append("        <yaxis id='yax-99-" + yax.getId() + "' yaxisId='" + yax.getId() + "' header='" + yax.getHeader() + "'>\n");    
+                for (AxisReaction re : yax.getReactions()){
+                    s.append("          <reaction>\n"); 
+                    s.append("            <initialstate>\n"); 
+                    for (Particle part : re.getInitialState()){
+                        s.append("              <particle");
+                        if(part.getName() != null){ s.append(" name='" + part.getName() + "'"); }
+                        if(part.getMultRelation() != null){ s.append(" relation='" + part.getMultRelation() + "'"); }
+                        if(part.getMultiplicity() != null){ s.append(" multiplicity='" + part.getMultiplicity() + "'"); }
+                        s.append(" />\n");
+                    }
+                    s.append("            </initialstate>\n"); 
+                    s.append("            <finalstate>\n"); 
+                    for (Particle part : re.getFinalState()){
+                         s.append("              <particle");
+                        if(part.getName() != null){ s.append(" name='" + part.getName() + "'"); }
+                        if(part.getMultRelation() != null){ s.append(" relation='" + part.getMultRelation() + "'"); }
+                        if(part.getMultiplicity() != null){ s.append(" multiplicity='" + part.getMultiplicity() + "'"); }
+                        s.append(" />\n");
+                    }
+                    s.append("            </finalstate>\n"); 
+                    s.append("          </reaction>\n");    
+                }
+                for (String cy : yax.getComments()){
+                    s.append("          <comment>\n");    
+                    s.append("            " + cy + "\n");
+                    s.append("          </comment>\n");    
+                }
+                for (Property prop : yax.getProperties()){
+                    s.append("          <property");
+                    if(prop.getName() != null){ s.append(" name='" + prop.getName() + "'"); }
+                    if(prop.getUnit() != null){ s.append(" unit='" + prop.getUnit() + "'"); }
+                    if(prop.getLowValue() != null){ s.append(" low='" + prop.getLowValue() + "'"); }
+                    if(prop.getHighValue() != null){ s.append(" high='" + prop.getHighValue() + "'"); }
+                    if(prop.getFocus() != null){ s.append(" focus='" + prop.getFocus() + "'"); }
+                    s.append(" />\n");
+                }
+                s.append("          <points>\n");    
+                for (AxisError err : yax.getErrors()){
+                    s.append("          <error");
+                    if(err.getPlus() != null){ s.append(" plus='" + err.getPlus() + "'"); }
+                    if(err.getMinus() != null){ s.append(" minus='" + err.getMinus() + "'"); }
+                    if(err.getSourceType() != null){ s.append(" source='" + err.getSourceType().toShortString() + "'"); }
+                    if(err.getNormType() != null){ s.append(" norm='" + err.getNormType().toSymbol() + "'"); }
+                    if(err.getComment() != null){ s.append(" comment='" + err.getComment() + "'"); }
+                    s.append(" />\n");
+                }
+                for (Point pt : yax.getPoints()){
+                    s.append("            <point pointId='" + pt.getId() + "'");
+                    if(pt.getValue() != null){ s.append(" value='" + pt.getValue() + "'"); }
+                    if(pt.getRelation() != null){ s.append(" relation='" + pt.getRelation() + "'"); }
+                    s.append(">\n");
+                    for (PointError err : pt.getErrors()){
+                        s.append("              <error");
+                        if(err.getPlus() != null){ s.append(" plus='" + err.getPlus() + "'"); }
+                        if(err.getMinus() != null){ s.append(" minus='" + err.getMinus() + "'"); }
+                        if(err.getSourceType() != null){ s.append(" source='" + err.getSourceType().toShortString() + "'"); }
+                        if(err.getNormType() != null){ s.append(" norm='" + err.getNormType().toSymbol() + "'"); }
+                        if(err.getComment() != null){ s.append(" comment='" + err.getComment() + "'"); }
+                        s.append(" />\n");
+                    }
+                    s.append("            </point>\n");
+                }
+                
+                s.append("          </points>\n");    
+                s.append("        </yaxis>\n");    
+            }
+           s.append("      </dataset>\n");    
+       }
+
+        s.append("    </paper>\n");
+        s.append("  </data>\n");
+        s.append("</hepml>\n");
+       return s.toString();
+    }
+
+
+}


More information about the HepData-svn mailing list