|
[HepData-svn] r1880 - in trunk/hepdata-webapp/src/main/java/cedar/hepdata: formats webapp/pagesblackhole at projects.hepforge.org blackhole at projects.hepforge.orgWed Jul 8 17:15:14 BST 2015
Author: watt Date: Wed Jul 8 17:15:13 2015 New Revision: 1880 Log: Allow YAML formatter to export per dataset and recognise index.shtml files in resource area Modified: trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/YamlFormatter.java trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/pages/View.java Modified: trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/YamlFormatter.java ============================================================================== --- trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/YamlFormatter.java Wed Jul 1 18:26:51 2015 (r1879) +++ trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/YamlFormatter.java Wed Jul 8 17:15:13 2015 (r1880) @@ -18,38 +18,37 @@ public class YamlFormatter { - public static String format(Paper p) { + public static String format(Collection<Dataset> ds, Paper p) { + String s4=" "; + String sp=" - "; StringBuffer s = new StringBuffer(); - s.append("---\n"); - String s4=" "; - String sp=" - "; - if(p == null) return null; - - // _header contains all the bibliographic type stuff at the beginning - - s.append(_headerYAML(p)); + + if (p != null) { + s.append("---\n"); + // _headerYAML contains all the bibliographic type stuff at the beginning + s.append(_headerYAML(p)); + } // and now the datasets + for (Dataset d : ds){ + s.append("\n---\n"); + s.append(_metadataYAML(d)); // dataset information in _metadata + s.append("data_file: data"+d.getId()+".yaml\n"); + s.append("additional_resources:\n"); + } + for (Dataset d : ds){ + s.append("\n---\n"); + s.append(_dataYAML(d)); // dataset information in _data + } - for (Dataset ds : p.getDatasets()){ - s.append("\n---\n"); - s.append(_metadataYAML(ds)); // dataset information in _metadata - s.append("data_file: data"+ds.getId()+".yaml\n"); - s.append("additional_resources:\n"); - } - for (Dataset ds : p.getDatasets()){ - s.append("\n---\n"); - s.append(_dataYAML(ds)); // dataset information in _data - } - - // finally finish off (at present does nothing! + // finally finish off (at present does nothing!) s.append(_footerYAML()); - // then write it all out. + // then write it all out. return s.toString(); } - + public static String _getTimestamp(){ DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); Date date = new Date(); @@ -104,7 +103,7 @@ if (p.getHaveRivet()) { s.append(sp+"{location: 'http://rivet.hepforge.org/analyses#"+p.getRivetName()+"', description: 'Rivet analysis'}\n"); } } - // here we deal with the extra resource are description/line files + // here we deal with the extra resource area description/line files String[] descs = { "description1" , "description2" , "description3" , "description4" }; String[] links = { "link1" , "link2" , "link3" , "link4" }; @@ -121,7 +120,7 @@ File testlink = new File(linkfile); String desc=""; String link=""; - if(testdesc.exists() && testlink.exists() ){ + if( testdesc.exists() && testlink.exists() ){ try { BufferedReader in = new BufferedReader(new FileReader(descfile)); desc=in.readLine(); @@ -137,7 +136,25 @@ } } - // next the insert.html file in the resource area + // next the possible index.shtml file in the resource area + for (int j=0; j<ids.length; j++){ + String descfile = "/home/hepdata/resource/" +ids[j] + "/description"; + String linkfile = "/home/hepdata/resource/" +ids[j] + "/index.shtml"; + 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){} + s.append(sp+"{location: '"+link+"', description: '"+desc.replaceAll("'","''")+"'}\n"); + } + } + + // next the possible insert.html file in the resource area for (int j=0; j<ids.length; j++){ String insertfile = "/home/hepdata/resource/" +ids[j] + "/insert.html"; File testinsert = new File(insertfile); 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 Wed Jul 1 18:26:51 2015 (r1879) +++ trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/pages/View.java Wed Jul 8 17:15:13 2015 (r1880) @@ -67,7 +67,7 @@ if (fmt.equals("hepml")) return asHepML(); if (fmt.equals("marcxml")) return asMarcXML(); if (fmt.equals("json")) return asJSON(); - if (fmt.equals("yaml")) return asYAML(); + if (fmt.equals("yaml")) return asYAML(context); if (fmt.equals("bdms")) return asBDMS(); if (fmt.equals("input")) return asINPUT(context); if (fmt.equals("plain.txt")) return asPlain(); @@ -135,6 +135,7 @@ } return new TextStreamResponse("text/xml", asMarcXML); } + public Object getJsonContext() { return formatContext("json"); } @@ -150,13 +151,17 @@ public Object getYamlContext() { return formatContext("yaml"); } - public StreamResponse asYAML() { - Paper p = getPaper(); - String asYAML = YamlFormatter.format(p); + public StreamResponse asYAML(EventContext context) { + Paper p = null; + if(context.getCount()==2) { p = getPaper(); } + Set<Dataset> ds = getDatasets(); + String asYAML = YamlFormatter.format(ds, p); if (asYAML == null) { asYAML = "No valid paper specified"; } - return new TextStreamResponse("text/plain", asYAML); } + return new TextStreamResponse("text/plain", asYAML); + } + public Object getBdmsContext() { return formatContext("bdms"); } @@ -183,7 +188,6 @@ return new TextStreamResponse("text/plain", asINPUT); } - public Object getPlainContext() { return formatContext("plain.txt"); } @@ -196,7 +200,6 @@ return new TextStreamResponse("text/plain", asPlain); } - public Object getYodaContext() { return formatContext("yoda"); } @@ -209,7 +212,6 @@ return new TextStreamResponse("text/plain", asYODA); } - public Object getYodaStatContext() { return formatContext("yodastat"); } @@ -222,7 +224,6 @@ return new TextStreamResponse("text/plain", asYODAstat); } - public Object getAidaContext() { return formatContext("aida"); } @@ -235,7 +236,6 @@ return new TextStreamResponse("text/xml", asAIDA); } - public Object getRootContext() { return formatContext("root"); } @@ -249,7 +249,6 @@ return new TextStreamResponse("text/plain", asRoot); } - public Object getMatplotlibContext() { return formatContext("mpl"); } @@ -263,7 +262,6 @@ return new TextStreamResponse("text/plain", asMpl); } - public Object getPyRootContext() { return formatContext("pyroot.py"); } @@ -276,7 +274,6 @@ return new TextStreamResponse("text/plain", asPyRoot); } - //////////////////////////////////////////
More information about the HepData-svn mailing list |