Skip to content
Snippets Groups Projects
Commit a160af60 authored by Thorsten Vitt's avatar Thorsten Vitt
Browse files

Return useful file name

parent 25a35a6d
No related branches found
No related tags found
No related merge requests found
...@@ -8,9 +8,10 @@ ...@@ -8,9 +8,10 @@
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.ObjectNotFoundFault; import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.ObjectNotFoundFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.TGCrudService; import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.TGCrudService;
import info.textgrid.services.aggregator.ITextGridRep; import info.textgrid.services.aggregator.ITextGridRep;
import info.textgrid.services.aggregator.RESTUtils;
import info.textgrid.services.aggregator.tree.Aggregation; import info.textgrid.services.aggregator.tree.Aggregation;
import info.textgrid.services.aggregator.tree.AggregationEntry; import info.textgrid.services.aggregator.tree.AggregationEntry;
import info.textgrid.services.aggregator.tree.AggregationTreeFactory; import info.textgrid.services.aggregator.tree.FilenamePolicy;
import java.net.URI; import java.net.URI;
import java.text.MessageFormat; import java.text.MessageFormat;
...@@ -27,7 +28,6 @@ ...@@ -27,7 +28,6 @@
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.StreamingOutput;
import org.apache.cxf.jaxrs.model.wadl.Description; import org.apache.cxf.jaxrs.model.wadl.Description;
...@@ -46,7 +46,7 @@ public ZIP(final ITextGridRep repository) { ...@@ -46,7 +46,7 @@ public ZIP(final ITextGridRep repository) {
@GET @GET
@Path(value = "/{object}") @Path(value = "/{object}")
@Produces(value = "application/zip") @Produces(value = "application/zip")
public StreamingOutput get( public Response get(
@Description("The TextGrid URI of the TEI document or aggregation to transform") @Description("The TextGrid URI of the TEI document or aggregation to transform")
@PathParam("object") final URI uri, @PathParam("object") final URI uri,
@Description("Session ID to access protected resources") @Description("Session ID to access protected resources")
...@@ -66,16 +66,22 @@ public StreamingOutput get( ...@@ -66,16 +66,22 @@ public StreamingOutput get(
format)).build()); format)).build());
} }
return new ZipResult(rootObject, repository, sid); return RESTUtils
.attachmentResponse(FilenamePolicy.getTransliterator()
.transliterate(rootObject.getGeneric().getProvided().getTitle().get(0)).concat(".zip"))
.type("application/zip")
.entity(new ZipResult(rootObject, repository, sid))
.build();
} }
private void appendLS(Aggregation aggregation, StringBuilder output) { private void appendLS(final Aggregation aggregation, final StringBuilder output) {
output.append(aggregation.getFileName(true)).append(":\n"); output.append(aggregation.getFileName(true)).append(":\n");
for(AggregationEntry child : aggregation.getChildren()) for(final AggregationEntry child : aggregation.getChildren())
if (child instanceof Aggregation) if (child instanceof Aggregation) {
appendLS((Aggregation) child, output); appendLS((Aggregation) child, output);
else } else {
output.append(' ').append(child.getFileName(true)).append('\n'); output.append(' ').append(child.getFileName(true)).append('\n');
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment