Page Menu
Home
HEPForge
Search
Configure Global Search
Log In
Files
F19250777
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
11 KB
Referenced Files
None
Subscribers
None
View Options
Index: trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/JsonFormatter.java
===================================================================
--- trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/JsonFormatter.java (revision 1851)
+++ trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/JsonFormatter.java (revision 1852)
@@ -1,186 +1,218 @@
package cedar.hepdata.formats;
import cedar.hepdata.model.*;
import cedar.hepdata.util.*;
import cedar.hepdata.xml.*;
import cedar.hepdata.db.*;
import cedar.hepdata.webapp.components.*;
import java.util.*;
import java.text.*;
import java.io.File;
import java.io.*;
import org.antlr.stringtemplate.*;
-
import com.Ostermiller.util.SignificantFigures;
public class JsonFormatter {
public static String format(Paper p) {
StringBuffer s = new StringBuffer();
String s4=" ";
if(p == null) return null;
- s.append("\"record\": {\n");
+ s.append("{\n");
s.append(_headerXML(p));
String[] descs = { "description1" , "description2" , "description3" , "description4" };
String[] links = { "link1" , "link2" , "link3" , "link4" };
String[] ids = new String[3];
if(p.getSpiresId() != null ) { ids[0]=p.getSpiresId().toString(); } else { ids[0]=""; }
if(p.getInspireId() != null ) { ids[1]=p.getInspireId().toString(); } else { ids[1]=""; }
if(p.getRedId() != null ) { ids[2]=p.getRedId().toString(); } else { ids[2]=""; }
for (int i=0; i<descs.length; i++){
for(int j=0; j<ids.length; j++){
String descfile = "/home/hepdata/resource/" +ids[j] + "/" + descs[i];
String linkfile = "/home/hepdata/resource/" +ids[j] + "/" + links[i];
File testdesc = new File(descfile);
File testlink = new File(linkfile);
String desc="";
String link="";
if(testdesc.exists() && testlink.exists() ){
try {
BufferedReader in = new BufferedReader(new FileReader(descfile));
desc=in.readLine();
}
catch (IOException e){}
try {
BufferedReader in = new BufferedReader(new FileReader(linkfile));
link=in.readLine();
}
catch (IOException e){}
s.append(s4+"\"extra\" : {\n");
s.append(s4+s4+"\"description\" : \""+desc+"\"\n");
s.append(s4+s4+"\"link\" : \""+link+"\"\n");
s.append(s4+"}\n");
}
}
}
for (int j=0; j<ids.length; j++){
String insertfile = "/home/hepdata/resource/" +ids[j] + "/insert.html";
File testinsert = new File(insertfile);
String insert="";
if(testinsert.exists()){
s.append(s4+"\"inserthtml\": \"/resource/"+ids[j]+"/insert.html\"\n");
}
}
for (Dataset ds : p.getDatasets()){
- s.append(s4+"\"dataset\": {\n");
+ if(ds.getId() == 1) {
+ s.append(s4+"\"datasets\": [\n");
+ }
s.append(_metadataXML(ds));
- s.append(s4+"}\n");
+ if(ds.getId() == p.getDatasets().size()) {
+ s.append(s4+"}]\n");
+ } else {
+ s.append(s4+"},\n");
+ }
}
s.append(_footerXML());
s.append("}\n");
return s.toString();
}
public static String _getTimestamp(){
DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
Date date = new Date();
return dateFormat.format(date);
}
public static String _headerXML(Paper p) {
String s4=" ";
StringBuffer s = new StringBuffer();
- s.append(s4+"\"inspireid\": \""+p.getInspireId()+"\"\n");
- if(p.getArchive()!=null) { s.append(s4+"\"archive\": \""+p.getArchive().replaceAll("ARXIV","arXiv")+"\"\n"); }
- s.append(s4+"\"dateupdated\": \""+p.getDateUpdated()+"\"\n");
- s.append(s4+"\"collaboration\": \""+p.getInformalName()+"\"\n");
+ s.append(s4+"\"inspireid\": \""+p.getInspireId()+"\",\n");
+ if(p.getArchive()!=null) { s.append(s4+"\"archive\": \""+p.getArchive().replaceAll("ARXIV","arXiv")+"\",\n"); }
+ s.append(s4+"\"dateupdated\": \""+p.getDateUpdated()+"\",\n");
+ s.append(s4+"\"collaboration\": \""+p.getInformalName()+"\",\n");
for (String comment : p.getComments()){
s.append(" \"comment\": \""+comment+"\",\n");
}
return s.toString();
}
public static String _footerXML() {
StringBuffer s = new StringBuffer();
return s.toString();
}
public static String _metadataXML(Dataset ds){
String s4=" ";
StringBuffer s = new StringBuffer();
int idbase=9000000;
int id=idbase+ds.getId();
String location = "";
Paper p = ds.getPaper();
for (String ct : ds.getComments()){
if(ct.startsWith("Location:")) {
location = ct.replaceFirst("Location:","");
- s.append(s4+s4+"\"label\": \""+ct.replaceFirst("Location:","Data from")+" from: "+p.getTitle()+"\"\n");
+ s.append(s4+s4+"{\"label\": \""+ct.replaceFirst("Location:","Data from")+" from: "+p.getTitle()+"\",\n");
}
}
for (String ct : ds.getComments()){
if(!ct.startsWith("Location:")) {
- s.append(s4+s4+"\"comment\": \""+ct.replaceFirst("VERBATIM","").replaceAll(">",">").replaceAll("<","<")+"\"\n");
+ s.append(s4+s4+"\"comment\": \""+ct.replaceFirst("VERBATIM","").replaceAll(">",">").replaceAll("<","<")+"\",\n");
}
}
for (String dsreac : ds.getDsReactions()){
- s.append(s4+s4+"\"reackey\": \""+dsreac+"\"\n");
+ s.append(s4+s4+"\"reackey\": \""+dsreac+"\",\n");
}
for (String dsobs : ds.getDsObservables()){
- s.append(s4+s4+"\"obskey\": \""+dsobs+"\"\n");
+ s.append(s4+s4+"\"obskey\": \""+dsobs+"\",\n");
}
for (String dsplab : ds.getDsPlabs()){
- s.append(s4+s4+"\"plabkey\": \""+dsplab+"\"\n");
+ s.append(s4+s4+"\"plabkey\": \""+dsplab+"\",\n");
}
+ s.append(s4+s4+"\"xaxes\": [\n");
for (XAxis xax : ds.getXAxes()){
- s.append(s4+s4+"\"xaxis\": {\n");
- s.append(s4+s4+s4+"\"xheader\": \""+xax.getHeader()+"\"\n");
- for (Bin bin : xax.getBins()){
- s.append(s4+s4+s4+"\"bin\": {\n");
- s.append(s4+s4+s4+s4+"\"id\": \""+bin.getId()+"\"\n");
- s.append(s4+s4+s4+s4+"\"relation\": \""+bin.getRelation()+"\"\n");
- s.append(s4+s4+s4+s4+"\"focus\": \""+bin.getFocus()+"\"\n");
- s.append(s4+s4+s4+s4+"\"high\": \""+bin.getHighValue()+"\"\n");
- s.append(s4+s4+s4+s4+"\"low\": \""+bin.getLowValue()+"\"\n");
- if(bin.getDescription() != null ) { s.append(s4+s4+s4+s4+"\"description\": \""+bin.getDescription()+"\"\n"); }
+ s.append(s4+s4+s4+"{\"xheader\": \""+xax.getHeader()+"\", \n");
+ s.append(s4+s4+s4+"\"bins\": [\n");
+ for (Bin bin : xax.getBins()){
+ s.append(s4+s4+s4+s4+"{\"id\": \""+bin.getId()+"\", ");
+ if(bin.getDescription() != null ) { s.append("\"description\": \""+bin.getDescription()+"\", \n"); }
+ s.append("\"relation\": \""+bin.getRelation()+"\", ");
+ s.append("\"focus\": \""+bin.getFocus()+"\", ");
+ s.append("\"high\": \""+bin.getHighValue()+"\", ");
+ s.append("\"low\": \""+bin.getLowValue()+"\"");
+ if(bin.getId() < xax.getBins().size()) {
+ s.append("},\n");
+ } else{
+ // s.append("}] * end of bin\n");
+ s.append("}]\n");
+ }
+ }
+ if(xax.getId() < ds.getXAxes().size()){
+ s.append(s4+s4+s4+"},\n");
+ } else {
s.append(s4+s4+s4+"}\n");
}
- s.append(s4+s4+"}\n");
}
+ s.append(s4+s4+"],\n");
+ s.append(s4+s4+"\"yaxes\": [\n");
for (YAxis yax : ds.getYAxes()){
- s.append(s4+s4+"\"yaxis\": {\n");
- s.append(s4+s4+s4+"\"yheader\": \""+yax.getHeader()+"\"\n");
+ s.append(s4+s4+s4+"{\"yheader\": \""+yax.getHeader()+"\", \n");
for (Property prop : yax.getProperties()){
- s.append(s4+s4+s4+"\"property\": \""+prop.getFull()+"\"\n");
+ s.append(s4+s4+s4+"\"property\": \""+prop.getFull()+"\", \n");
}
for (String comment : yax.getComments()){
- s.append(s4+s4+s4+"\"comment\": \""+comment+"\"\n");
+ s.append(s4+s4+s4+"\"comment\": \""+comment+"\", \n");
}
+ s.append(s4+s4+s4+"\"points\": [\n");
for (Point point : yax.getPoints()){
- s.append(s4+s4+s4+"\"point\": {\n");
- s.append(s4+s4+s4+s4+"\"id\": \""+point.getId()+"\"\n");
- s.append(s4+s4+s4+s4+"\"value\": \""+point.getValue()+"\"\n");
- for(PointError error : point.getErrors()){
- s.append(s4+s4+s4+s4+"\"error\": {\n");
- s.append(s4+s4+s4+s4+s4+"\"plus\": \""+error.getPlus()+"\"\n");
- s.append(s4+s4+s4+s4+s4+"\"minus\": \""+error.getMinus()+"\"\n");
- s.append(s4+s4+s4+s4+s4+"\"norm\": \""+error.getNormType()+"\"\n");
- s.append(s4+s4+s4+s4+s4+"\"type\": \""+error.getSourceType()+"\"\n");
-
- s.append(s4+s4+s4+s4+"}\n");
+ s.append(s4+s4+s4+s4+"{\"id\": \""+point.getId()+"\", ");
+ s.append("\"value\": \""+point.getValue()+"\"");
+ if(point.getErrors().size()>0){
+ s.append(", ");
+ s.append("\"errors\": [ ");
+ boolean first = true;
+ for(PointError error : point.getErrors()){
+ if(!first) { s.append(s4+s4+s4+s4+s4+s4+s4+s4+s4); }
+ first = false;
+ s.append("{\"plus\": \""+error.getPlus()+"\", ");
+ s.append("\"minus\": \""+error.getMinus()+"\", ");
+ s.append("\"norm\": \""+error.getNormType()+"\", ");
+ s.append("\"type\": \""+error.getSourceType()+"\"}");
+ if(error.getId() < point.getErrors().size()) {
+ s.append(",\n");
+ } else {
+ s.append("]\n");
+ }
+ }
}
+ if(point.getId() < yax.getPoints().size()){
+ s.append(s4+s4+s4+s4+"},\n");
+ } else {
+ s.append(s4+s4+s4+s4+"}]\n");
+ }
+ }
+ if(yax.getId() < ds.getYAxes().size()){
+ s.append(s4+s4+s4+"},\n");
+ } else {
s.append(s4+s4+s4+"}\n");
}
-
- s.append(s4+s4+"}\n");
}
+ s.append(s4+s4+"]\n");
return s.toString();
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Sep 30, 5:44 AM (11 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6566314
Default Alt Text
(11 KB)
Attached To
Mode
rHEPDATASVN hepdatasvn
Attached
Detach File
Event Timeline
Log In to Comment