Commits

Sam Adams committed a91c898

Refactoring templating; added '@' var

  • Participants
  • Parent commits 5be2497

Comments (0)

Files changed (3)

crystallography-handler/src/main/java/uk/ac/cam/ch/wwmm/chempound/crystal/display/CrystalContentType.java

 
     @Override
     public SplashPageWriter getWriter(final Model model, final URI aggregationUri) {
-        return injector.getInstance(CrystalWriter.class);
+        return injector.getInstance(CrystalStructureSplashPageWriter.class);
     }
 
 }

crystallography-handler/src/main/java/uk/ac/cam/ch/wwmm/chempound/crystal/display/CrystalStructureSplashPageWriter.java

+package uk.ac.cam.ch.wwmm.chempound.crystal.display;
+
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.Resource;
+import freemarker.ext.beans.BeanModel;
+import freemarker.ext.beans.BeansWrapper;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
+import freemarker.template.TemplateHashModel;
+import org.apache.commons.io.IOUtils;
+import uk.ac.cam.ch.wwmm.chempound.crystal.rdf.CrystalEyeEntry;
+import uk.ac.cam.ch.wwmm.chempound.crystal.rdf.CrystalStructure;
+import uk.ac.cam.ch.wwmm.chempound.crystal.rdf.ont.CifDict;
+import uk.ac.cam.ch.wwmm.chempound.crystal.rdf.ont.Cryst;
+import uk.ac.cam.ch.wwmm.chempound.rdf.DCTerms;
+import uk.ac.cam.ch.wwmm.chempound.services.FreemarkerService;
+import uk.ac.cam.ch.wwmm.chempound.webapp.output.SplashPageWriter;
+
+import javax.inject.Inject;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Sam Adams
+ */
+public class CrystalStructureSplashPageWriter implements SplashPageWriter {
+
+    private static final String style;
+    private static final String headers;
+
+    static {
+        style = read("/uk/ac/cam/ch/wwmm/chempound/crystal/includes/style.css");
+        headers = read("/uk/ac/cam/ch/wwmm/chempound/crystal/includes/headers.html");
+    }
+
+    private static String read(final String s) {
+        final InputStream in = CrystalStructureSplashPageWriter.class.getResourceAsStream(s);
+        try {
+            return IOUtils.toString(in);
+        } catch (IOException e) {
+            throw new RuntimeException("Error reading file: "+s, e);
+        } finally {
+            IOUtils.closeQuietly(in);
+        }
+    }
+
+    private final FreemarkerService freemarker;
+
+    @Inject
+    public CrystalStructureSplashPageWriter(final FreemarkerService freemarker) {
+        this.freemarker = freemarker;
+    }
+
+    @Override
+    public String write(final Model model, final URI aggregationUri, final Map<String, Object> map) throws IOException, TemplateException {
+
+        map.put("style", style);
+        map.put("headers", headers);
+
+        final Map<String,Object> o = new HashMap<String, Object>(map);
+
+        final Resource r = model.getResource(aggregationUri.toString());
+
+        final CrystalStructure cryst = r.as(CrystalStructure.class);
+        final CrystalEyeEntry entry = r.as(CrystalEyeEntry.class);
+
+        final BeansWrapper wrapper = BeansWrapper.getDefaultInstance();
+        final TemplateHashModel staticModels = wrapper.getStaticModels();
+
+        o.put("entry", new BeanModel(entry, wrapper));
+        o.put("cryst", new BeanModel(cryst, wrapper));
+        o.put("DC", staticModels.get(DCTerms.class.getName()));
+        o.put("CIF", staticModels.get(Cryst.class.getName()));
+        o.put("IUCR", staticModels.get(CifDict.class.getName()));
+
+        final StringWriter buffer = new StringWriter();
+
+        final Template template = freemarker.getTemplate("/plugins/crystal/crystal.ftl");
+        template.process(o, buffer);
+
+        return buffer.toString();
+    }
+
+}

crystallography-handler/src/main/java/uk/ac/cam/ch/wwmm/chempound/crystal/display/CrystalWriter.java

-package uk.ac.cam.ch.wwmm.chempound.crystal.display;
-
-import com.hp.hpl.jena.rdf.model.Model;
-import com.hp.hpl.jena.rdf.model.Resource;
-import freemarker.ext.beans.BeanModel;
-import freemarker.ext.beans.BeansWrapper;
-import freemarker.template.Template;
-import freemarker.template.TemplateException;
-import freemarker.template.TemplateHashModel;
-import org.apache.commons.io.IOUtils;
-import uk.ac.cam.ch.wwmm.chempound.crystal.rdf.CrystalEyeEntry;
-import uk.ac.cam.ch.wwmm.chempound.crystal.rdf.CrystalStructure;
-import uk.ac.cam.ch.wwmm.chempound.crystal.rdf.ont.CifDict;
-import uk.ac.cam.ch.wwmm.chempound.crystal.rdf.ont.Cryst;
-import uk.ac.cam.ch.wwmm.chempound.rdf.DCTerms;
-import uk.ac.cam.ch.wwmm.chempound.services.FreemarkerService;
-import uk.ac.cam.ch.wwmm.chempound.webapp.output.SplashPageWriter;
-
-import javax.inject.Inject;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringWriter;
-import java.net.URI;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author Sam Adams
- */
-public class CrystalWriter implements SplashPageWriter {
-
-    private static final String style;
-    private static final String headers;
-
-    static {
-        style = read("/uk/ac/cam/ch/wwmm/chempound/crystal/includes/style.css");
-        headers = read("/uk/ac/cam/ch/wwmm/chempound/crystal/includes/headers.html");
-    }
-
-    private static String read(final String s) {
-        final InputStream in = CrystalWriter.class.getResourceAsStream(s);
-        try {
-            return IOUtils.toString(in);
-        } catch (IOException e) {
-            throw new RuntimeException("Error reading file: "+s, e);
-        } finally {
-            IOUtils.closeQuietly(in);
-        }
-    }
-
-    private final FreemarkerService freemarker;
-
-    @Inject
-    public CrystalWriter(final FreemarkerService freemarker) {
-        this.freemarker = freemarker;
-    }
-
-    @Override
-    public String write(final Model model, final URI aggregationUri, final Map<String, Object> map) throws IOException, TemplateException {
-
-        map.put("style", style);
-        map.put("headers", headers);
-
-        final Map<String,Object> o = new HashMap<String, Object>(map);
-
-        final Resource r = model.getResource(aggregationUri.toString());
-
-        final CrystalStructure cryst = r.as(CrystalStructure.class);
-        final CrystalEyeEntry entry = r.as(CrystalEyeEntry.class);
-
-        final BeansWrapper wrapper = BeansWrapper.getDefaultInstance();
-        final TemplateHashModel staticModels = wrapper.getStaticModels();
-
-        o.put("entry", new BeanModel(entry, wrapper));
-        o.put("cryst", new BeanModel(cryst, wrapper));
-        o.put("DC", staticModels.get(DCTerms.class.getName()));
-        o.put("CIF", staticModels.get(Cryst.class.getName()));
-        o.put("IUCR", staticModels.get(CifDict.class.getName()));
-
-        final StringWriter buffer = new StringWriter();
-
-        final Template template = freemarker.getTemplate("/plugins/crystal/crystal.ftl");
-        template.process(o, buffer);
-
-        return buffer.toString();
-    }
-
-}