Anonymous avatar Anonymous committed be7f023

Remove redundant fields/parameters

Comments (0)

Files changed (7)

chempound-webapi/src/main/java/net/chempound/webapp/output/AbstractSplashPageWriter.java

 import com.hp.hpl.jena.rdf.model.Model;
 import com.hp.hpl.jena.rdf.model.Resource;
 import freemarker.template.TemplateException;
-import net.chempound.services.FreemarkerService;
 
 import java.io.IOException;
 import java.net.URI;
-import java.util.Map;
 
 /**
  * @author Sam Adams
  */
 public abstract class AbstractSplashPageWriter implements SplashPageWriter {
 
-    protected final FreemarkerService freemarker;
-
-    protected AbstractSplashPageWriter(final FreemarkerService freemarker) {
-        this.freemarker = freemarker;
-    }
-
     protected abstract Class<? extends Resource> getResourceType();
 
     protected abstract String getTemplateName();
 
-    public void write(final Model model, final URI aggregationUri, final Map<String, Object> map, final Page page) throws IOException, TemplateException {
+    public void write(final Model model, final URI aggregationUri, final Page page) throws IOException, TemplateException {
 
         page.setTemplatePath(getTemplateName());
 

chempound-webapi/src/main/java/net/chempound/webapp/output/Page.java

 package net.chempound.webapp.output;
 
+import java.util.List;
 import java.util.Map;
 
 public class Page {
 
     private final Map<String, Object> model;
+    private final List<String> headers;
 
     private String templatePath;
 
-    public Page(final Map<String, Object> model) {
+    public Page(final Map<String, Object> model, final List<String> headers) {
         this.model = model;
+        this.headers = headers;
     }
 
     public void setTemplatePath(final String templatePath) {
         model.put(name, value);
     }
 
+    public void addHeader(final String header) {
+        headers.add(header);
+    }
+
     public String getTemplatePath() {
         return templatePath;
     }

chempound-webapi/src/main/java/net/chempound/webapp/output/SplashPageWriter.java

 import com.hp.hpl.jena.rdf.model.Model;
 
 import java.net.URI;
-import java.util.Map;
 
 /**
  * @author Sam Adams
  */
 public interface SplashPageWriter {
 
-    void write(Model model, URI aggregationUri, Map<String, Object> map, final Page page) throws Exception;
+    void write(Model model, URI aggregationUri, Page page) throws Exception;
 
 }

chempound-webapp/src/main/java/net/chempound/webapp/splashpage/DefaultCollectionSplashPageWriter.java

 import net.chempound.config.BaseUri;
 import net.chempound.datastore.TripleStore;
 import net.chempound.rdf.chempound.Collection;
-import net.chempound.services.FreemarkerService;
 import net.chempound.webapp.output.Page;
 import net.chempound.webapp.output.SplashPageWriter;
 
 import javax.inject.Inject;
+import javax.inject.Singleton;
 import java.io.IOException;
 import java.net.URI;
 import java.util.HashMap;
 /**
  * @author sea36
  */
+@Singleton
 public class DefaultCollectionSplashPageWriter implements SplashPageWriter {
 
-    private final FreemarkerService freemarker;
     private final TripleStore tripleStore;
     private final URI depositBase;
     private final URI contentUri;
 
     @Inject
-    public DefaultCollectionSplashPageWriter(final FreemarkerService freemarker, final TripleStore triplesStore, final @BaseUri URI baseUri) {
-        this.freemarker = freemarker;
+    public DefaultCollectionSplashPageWriter(final TripleStore triplesStore, final @BaseUri URI baseUri) {
         this.tripleStore = triplesStore;
 
         final URI swordBase = baseUri.resolve("sword/");
     }
 
     @Override
-    public void write(final Model model, final URI collectionUri, final Map<String, Object> map, final Page page) throws IOException, TemplateException {
+    public void write(final Model model, final URI collectionUri, final Page page) throws IOException, TemplateException {
 
         final List<ItemInfo> itemList = tripleStore.getItems(collectionUri);
         final Map<String,ItemInfo> itemMap = buildMap(itemList);
         page.addParam("title", aggregation.getTitle());
 
         page.setTemplatePath("default/collection.ftl");
-
-        final StringBuilder headers = new StringBuilder();
-        if (map.containsKey("headers")) {
-            headers.append(map.get("headers")).append('\n');
-        }
-        headers.append("<link rel='http://purl.org/net/sword/terms/deposit' href='" + getSwordUri(collectionUri) + "' />");
-        page.addParam("headers", headers.toString());
+        page.addHeader("<link rel='http://purl.org/net/sword/terms/deposit' href='" + getSwordUri(collectionUri) + "' />");
     }
 
     private URI getSwordUri(final URI collectionUri) {

chempound-webapp/src/main/java/net/chempound/webapp/splashpage/DefaultItemSplashPageWriter.java

 
 import net.chempound.rdf.chempound.Item;
 import net.chempound.rdf.ore.Aggregation;
-import net.chempound.services.FreemarkerService;
 import net.chempound.webapp.output.AbstractSplashPageWriter;
 
-import javax.inject.Inject;
+import javax.inject.Singleton;
 
 /**
  * @author sea36
  */
+@Singleton
 public class DefaultItemSplashPageWriter extends AbstractSplashPageWriter {
 
     private static final String DEFAULT_TEMPLATE_NAME = "default/resource.ftl";
 
-    @Inject
-    public DefaultItemSplashPageWriter(final FreemarkerService freemarker) {
-        super(freemarker);
-    }
-
     @Override
     protected Class<? extends Aggregation> getResourceType() {
         return Item.class;

chempound-webapp/src/main/java/net/chempound/webapp/splashpage/SplashPageGenerator.java

 
 import javax.inject.Inject;
 import java.net.URI;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
         }
 
         final Map<String,Object> map = new HashMap<String, Object>();
-        final Page page = new Page(map);
+        final List<String> headers = new ArrayList<String>();
+        final Page page = new Page(map, headers);
         map.put("uri", aggregationUri);
 
-        writer.write(model, aggregationUri, map, page);
+        writer.write(model, aggregationUri, page);
 
         map.put("uri", aggregationUri);
         map.put("template", page.getTemplatePath());
+        if (!headers.isEmpty()) {
+            map.put("headers", headers);
+        }
 
         final Template template = freemarker.getTemplate("splash.ftl");
         return new TemplateRepresentation(template, map, MediaType.TEXT_HTML);

chempound-webapp/src/test/java/net/chempound/webapp/pingback/PingbackIntegrationTest.java

 import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.entity.BasicHttpEntity;
 import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.util.EntityUtils;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
         HttpClient client = new DefaultHttpClient();
         HttpUriRequest request = new HttpGet("http://localhost:8717/repo/content/foo/");
         HttpResponse response = client.execute(request);
-        assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
+        try {
+            assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
 
-        Header pingback = response.getFirstHeader("X-Pingback");
-        assertNotNull(pingback);
-        assertEquals("http://localhost:8717/repo/pingback", pingback.getValue());
+            Header pingback = response.getFirstHeader("X-Pingback");
+            assertNotNull(pingback);
+            assertEquals("http://localhost:8717/repo/pingback", pingback.getValue());
+        } finally {
+            EntityUtils.consume(response.getEntity());
+        }
     }
 
     @Test
         @Override
         public Restlet createInboundRoot() {
             LocalReference ref = LocalReference.createClapReference(getClass().getPackage());
-            Directory directory = new Directory(getContext(), ref);
-            return directory;
+            return new Directory(getContext(), ref);
         }
 
     }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.