Adds option to download any command respond
authorNiels Erik G. Nielsen <nielserik@indexdata.com>
Thu, 9 May 2013 19:10:40 +0000 (15:10 -0400)
committerNiels Erik G. Nielsen <nielserik@indexdata.com>
Thu, 9 May 2013 19:10:40 +0000 (15:10 -0400)
.. changes init doc response download to use generic download method

src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java
src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/InitDocUpload.java
src/main/java/com/indexdata/mkjsf/pazpar2/data/ResponseDataObject.java
src/main/java/com/indexdata/mkjsf/pazpar2/data/Responses.java
src/main/java/com/indexdata/mkjsf/utils/FileUpload.java

index 87a7322..a2e212f 100644 (file)
@@ -14,7 +14,6 @@ import org.apache.myfaces.custom.fileupload.UploadedFile;
 import com.indexdata.mkjsf.config.ConfigurationReader;\r
 import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Commands;\r
 import com.indexdata.mkjsf.pazpar2.commands.sp.InitDocUpload;\r
-import com.indexdata.mkjsf.pazpar2.data.InitResponse;\r
 import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject;\r
 import com.indexdata.mkjsf.pazpar2.data.ResponseParser;\r
 import com.indexdata.mkjsf.pazpar2.data.Responses;\r
index 2770618..f85a5c6 100644 (file)
@@ -8,7 +8,6 @@ import javax.inject.Named;
 import org.apache.log4j.Logger;\r
 import org.apache.myfaces.custom.fileupload.UploadedFile;\r
 \r
-import com.indexdata.mkjsf.pazpar2.ClientCommandResponse;\r
 import com.indexdata.mkjsf.pazpar2.HttpResponseWrapper;\r
 import com.indexdata.mkjsf.pazpar2.ServiceProxyExtensions;\r
 import com.indexdata.mkjsf.utils.FileUpload;\r
index 0db67d3..57c17e1 100644 (file)
@@ -120,5 +120,9 @@ public class ResponseDataObject implements Serializable {
     }      \r
     return xml == null ? "" : xml;\r
   }\r
+  \r
+  public boolean getHasResults () {\r
+    return (xml != null && xml.length()>0);\r
+  }\r
         \r
 }\r
index 80d9ce3..71769c7 100644 (file)
@@ -1,13 +1,18 @@
 package com.indexdata.mkjsf.pazpar2.data;\r
 \r
+import java.io.IOException;\r
 import java.io.Serializable;\r
+import java.io.UnsupportedEncodingException;\r
 import java.util.List;\r
 import java.util.Map;\r
 import java.util.concurrent.ConcurrentHashMap;\r
 \r
 import javax.enterprise.context.SessionScoped;\r
+import javax.faces.context.ExternalContext;\r
+import javax.faces.context.FacesContext;\r
 import javax.inject.Named;\r
 \r
+import org.apache.commons.io.FilenameUtils;\r
 import org.apache.log4j.Logger;\r
 \r
 import com.indexdata.mkjsf.errors.ErrorHelper;\r
@@ -148,4 +153,15 @@ public class Responses implements Serializable {
     return null;\r
   }\r
 \r
-}\r
+  public void download(String commandName) throws UnsupportedEncodingException, IOException {\r
+    logger.info(Utils.objectId(this) + " got a download request for "\r
+        + commandName);\r
+    FacesContext facesContext = FacesContext.getCurrentInstance();\r
+    ExternalContext externalContext = facesContext.getExternalContext();\r
+    externalContext.setResponseHeader("Content-Type","application/xml; charset=\"utf-8\"");\r
+    externalContext.setResponseHeader("Content-Length",String.valueOf(dataObjects.get(commandName).getXml().getBytes("UTF-8").length));\r
+    externalContext.setResponseHeader("Content-Disposition","attachment;filename=\"" + commandName + ".xml\"");\r
+    externalContext.getResponseOutputStream().write(dataObjects.get(commandName).getXml().getBytes("UTF-8"));\r
+    facesContext.responseComplete();\r
+  }\r
+}
\ No newline at end of file
index ba8c242..b974437 100644 (file)
@@ -38,18 +38,5 @@ public abstract class FileUpload implements Serializable {
     externalContext.getResponseOutputStream().write(getUploadedFile().getBytes());\r
     facesContext.responseComplete();\r
   }\r
-  \r
-  public void downloadResponse () throws IOException {\r
-    logger.info(Utils.objectId(this) + " got a download request");\r
-    FacesContext facesContext = FacesContext.getCurrentInstance();\r
-    ExternalContext externalContext = facesContext.getExternalContext();\r
-    externalContext.setResponseHeader("Content-Type", response.getContentType());\r
-    externalContext.setResponseHeader("Content-Length", String.valueOf((response.getBytes().length)));\r
-    externalContext.setResponseHeader("Content-Disposition", "attachment;filename=\"initresponse.xml\"");\r
-    externalContext.getResponseOutputStream().write(response.getBytes());\r
-    facesContext.responseComplete();\r
-  }\r
-\r
-\r
 \r
 }\r