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

Added skeleton zip generator (doesn't generate actual zips yet)

parent 730447bf
Branches
Tags
No related merge requests found
package info.textgrid.services.aggregator.zip;
import info.textgrid.namespaces.metadata.core._2010.MetadataContainerType;
import info.textgrid.namespaces.metadata.core._2010.ObjectType;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.AuthFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.IoFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.MetadataParseFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.ObjectNotFoundFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.TGCrudService;
import info.textgrid.services.aggregator.ITextGridRep;
import info.textgrid.services.aggregator.tree.Aggregation;
import info.textgrid.services.aggregator.tree.AggregationEntry;
import info.textgrid.services.aggregator.tree.AggregationTreeFactory;
import java.net.URI;
import java.util.logging.Logger;
import javax.servlet.ServletContext;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import org.apache.cxf.jaxrs.model.wadl.Description;
@Path("/zip")
public class ZIP {
private final ITextGridRep repository;
final Logger logger = Logger.getLogger(ZIP.class.getCanonicalName());
@Context
private ServletContext servlet;
public ZIP(final ITextGridRep repository) {
this.repository = repository;
}
@GET
@Path(value = "/{object}")
@Produces(value = "text/html")
public Response get(
@Description("The TextGrid URI of the TEI document or aggregation to transform")
@PathParam("object") final URI uri,
@Description("Session ID to access protected resources")
@QueryParam("sid") final String sid) throws MetadataParseFault, ObjectNotFoundFault, IoFault, AuthFault {
final TGCrudService crud = repository.getCRUDService();
final MetadataContainerType container = crud.readMetadata(sid, null, uri.toString());
final ObjectType rootObject = container.getObject();
Aggregation tree = AggregationTreeFactory.create(rootObject, repository, sid);
StringBuilder output = new StringBuilder("Following stuff (+meta) would be zipped:\n\n");
appendLS(tree, output);
return Response.ok().entity(output.toString()).type("text/plain").build();
}
private void appendLS(Aggregation aggregation, StringBuilder output) {
output.append(aggregation.getFileName()).append(":\n");
for(AggregationEntry child : aggregation.getChildren())
if (child instanceof Aggregation)
appendLS((Aggregation) child, output);
else
output.append(' ').append(child.getFileName()).append('\n');
}
}
...@@ -41,6 +41,9 @@ http://cxf.apache.org/schemas/jaxrs.xsd"> ...@@ -41,6 +41,9 @@ http://cxf.apache.org/schemas/jaxrs.xsd">
<bean class="info.textgrid.services.aggregator.html.HTML" scope="singleton"> <bean class="info.textgrid.services.aggregator.html.HTML" scope="singleton">
<constructor-arg ref="stable-repo"/> <constructor-arg ref="stable-repo"/>
</bean> </bean>
<bean class="info.textgrid.services.aggregator.zip.ZIP" scope="singleton">
<constructor-arg ref="stable-repo"/>
</bean>
</jaxrs:serviceBeans> </jaxrs:serviceBeans>
<jaxrs:providers> <jaxrs:providers>
<!-- bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/--> <!-- bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/-->
...@@ -64,6 +67,9 @@ http://cxf.apache.org/schemas/jaxrs.xsd"> ...@@ -64,6 +67,9 @@ http://cxf.apache.org/schemas/jaxrs.xsd">
<bean class="info.textgrid.services.aggregator.html.HTML" scope="singleton"> <bean class="info.textgrid.services.aggregator.html.HTML" scope="singleton">
<constructor-arg ref="dev-repo" /> <constructor-arg ref="dev-repo" />
</bean> </bean>
<bean class="info.textgrid.services.aggregator.zip.ZIP" scope="singleton">
<constructor-arg ref="dev-repo" />
</bean>
</jaxrs:serviceBeans> </jaxrs:serviceBeans>
<jaxrs:providers> <jaxrs:providers>
<!-- bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/ --> <!-- bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/ -->
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment