From: Niels Erik G. Nielsen Date: Thu, 9 May 2013 19:10:40 +0000 (-0400) Subject: Adds option to download any command respond X-Git-Tag: v0.0.7~116 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=3915cce4801de80bdb6db7f12a26d04d4371689f;p=mkjsf-moved-to-github.git Adds option to download any command respond .. changes init doc response download to use generic download method --- diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java b/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java index 87a7322..a2e212f 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java @@ -14,7 +14,6 @@ import org.apache.myfaces.custom.fileupload.UploadedFile; import com.indexdata.mkjsf.config.ConfigurationReader; import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Commands; import com.indexdata.mkjsf.pazpar2.commands.sp.InitDocUpload; -import com.indexdata.mkjsf.pazpar2.data.InitResponse; import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; import com.indexdata.mkjsf.pazpar2.data.ResponseParser; import com.indexdata.mkjsf.pazpar2.data.Responses; diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/InitDocUpload.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/InitDocUpload.java index 2770618..f85a5c6 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/InitDocUpload.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/InitDocUpload.java @@ -8,7 +8,6 @@ import javax.inject.Named; import org.apache.log4j.Logger; import org.apache.myfaces.custom.fileupload.UploadedFile; -import com.indexdata.mkjsf.pazpar2.ClientCommandResponse; import com.indexdata.mkjsf.pazpar2.HttpResponseWrapper; import com.indexdata.mkjsf.pazpar2.ServiceProxyExtensions; import com.indexdata.mkjsf.utils.FileUpload; diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/ResponseDataObject.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/ResponseDataObject.java index 0db67d3..57c17e1 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/ResponseDataObject.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/ResponseDataObject.java @@ -120,5 +120,9 @@ public class ResponseDataObject implements Serializable { } return xml == null ? "" : xml; } + + public boolean getHasResults () { + return (xml != null && xml.length()>0); + } } diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/Responses.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/Responses.java index 80d9ce3..71769c7 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/Responses.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/Responses.java @@ -1,13 +1,18 @@ package com.indexdata.mkjsf.pazpar2.data; +import java.io.IOException; import java.io.Serializable; +import java.io.UnsupportedEncodingException; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import javax.enterprise.context.SessionScoped; +import javax.faces.context.ExternalContext; +import javax.faces.context.FacesContext; import javax.inject.Named; +import org.apache.commons.io.FilenameUtils; import org.apache.log4j.Logger; import com.indexdata.mkjsf.errors.ErrorHelper; @@ -148,4 +153,15 @@ public class Responses implements Serializable { return null; } -} + public void download(String commandName) throws UnsupportedEncodingException, IOException { + logger.info(Utils.objectId(this) + " got a download request for " + + commandName); + FacesContext facesContext = FacesContext.getCurrentInstance(); + ExternalContext externalContext = facesContext.getExternalContext(); + externalContext.setResponseHeader("Content-Type","application/xml; charset=\"utf-8\""); + externalContext.setResponseHeader("Content-Length",String.valueOf(dataObjects.get(commandName).getXml().getBytes("UTF-8").length)); + externalContext.setResponseHeader("Content-Disposition","attachment;filename=\"" + commandName + ".xml\""); + externalContext.getResponseOutputStream().write(dataObjects.get(commandName).getXml().getBytes("UTF-8")); + facesContext.responseComplete(); + } +} \ No newline at end of file diff --git a/src/main/java/com/indexdata/mkjsf/utils/FileUpload.java b/src/main/java/com/indexdata/mkjsf/utils/FileUpload.java index ba8c242..b974437 100644 --- a/src/main/java/com/indexdata/mkjsf/utils/FileUpload.java +++ b/src/main/java/com/indexdata/mkjsf/utils/FileUpload.java @@ -38,18 +38,5 @@ public abstract class FileUpload implements Serializable { externalContext.getResponseOutputStream().write(getUploadedFile().getBytes()); facesContext.responseComplete(); } - - public void downloadResponse () throws IOException { - logger.info(Utils.objectId(this) + " got a download request"); - FacesContext facesContext = FacesContext.getCurrentInstance(); - ExternalContext externalContext = facesContext.getExternalContext(); - externalContext.setResponseHeader("Content-Type", response.getContentType()); - externalContext.setResponseHeader("Content-Length", String.valueOf((response.getBytes().length))); - externalContext.setResponseHeader("Content-Disposition", "attachment;filename=\"initresponse.xml\""); - externalContext.getResponseOutputStream().write(response.getBytes()); - facesContext.responseComplete(); - } - - }