From 0d6778420d5a80d8216dda94f1bcea541385e18c Mon Sep 17 00:00:00 2001
From: Thorsten Vitt <thorsten.vitt@uni-wuerzburg.de>
Date: Mon, 14 Jan 2013 11:58:05 +0000
Subject: [PATCH] Merge branch 'master' of
 wrzh072.rzhousing.uni-wuerzburg.de:aggregator

Conflicts:
	src/main/java/info/textgrid/services/aggregator/GenericExceptionMapper.java
	src/main/java/info/textgrid/services/aggregator/epub/EPUB.java
	src/test/java/info/textgrid/services/aggregator/EPUBTest.java

git-svn-id: https://develop.sub.uni-goettingen.de/repos/textgrid/trunk/services/aggregator@13732 7c539038-3410-0410-b1ec-0f2a7bf1c452
---
 pom.xml                                       | 571 +++++++++---------
 .../aggregator/GenericExceptionMapper.java    |  12 +-
 .../services/aggregator/epub/EPUB.java        | 129 ++--
 .../textgrid/services/aggregator/TestPDF.java |   5 +-
 4 files changed, 372 insertions(+), 345 deletions(-)

diff --git a/pom.xml b/pom.xml
index a67f0a9..fdb5b64 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,306 +1,317 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-	<modelVersion>4.0.0</modelVersion>
-	<groupId>info.textgrid.services</groupId>
-	<artifactId>aggregator</artifactId>
-	<version>1.0-SNAPSHOT</version>
-	<packaging>war</packaging>
-	<name>TextGrid Aggregator Service</name>
+		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	  <modelVersion>4.0.0</modelVersion>
+	  <groupId>info.textgrid.services</groupId>
+	  <artifactId>aggregator</artifactId>
+	  <version>1.0-SNAPSHOT</version>
+	  <packaging>war</packaging>
+	  <name>TextGrid Aggregator Service</name>
 
-	<developers>
-		<developer>
-			<id>vitt</id>
-			<name>Thorsten Vitt</name>
-			<email>thorsten.vitt@uni-wuerzburg.de</email>
-			<url>http://www.thorstenvitt.de/</url>
-			<organization>Universität Würzburg</organization>
-			<organizationUrl>http://www.germanistik.uni-wuerzburg.de/lehrstuehle/computerphilologie</organizationUrl>
-			<roles>
+	  <developers>
+		    <developer>
+			      <id>vitt</id>
+			      <name>Thorsten Vitt</name>
+			      <email>thorsten.vitt@uni-wuerzburg.de</email>
+			      <url>http://www.thorstenvitt.de/</url>
+			      <organization>Universität Würzburg</organization>
+			      <organizationUrl>http://www.germanistik.uni-wuerzburg.de/lehrstuehle/computerphilologie</organizationUrl>
+			      <roles>
 			</roles>
-		</developer>
-	</developers>
+		    </developer>
+	  </developers>
 
+   <properties>
+      <commons-io-version>2.4</commons-io-version>
+      <link-rewriter-version>0.0.4-SNAPSHOT</link-rewriter-version>
+      <saxon-version>9.4</saxon-version>
+      <cxf-version>2.5.5</cxf-version>
+      <confclient-version>1.0-SNAPSHOT</confclient-version>
+      <tgsearch-version>2.1.0-SNAPSHOT</tgsearch-version>
+      <tgcrud-version>2.4.0-SNAPSHOT</tgcrud-version>
+      <guava-version>13.0.1</guava-version>
+      <junit-version>4.10</junit-version>
+   </properties>
 
-	<repositories>
-		<repository>
-			<id>bibforge.internal.http</id>
-			<name>Bibforge Managed Internal Repository</name>
-			<url>http://repository.bibforge.org/archiva/repository/internal</url>
-			<releases>
-				<enabled>true</enabled>
-			</releases>
-			<snapshots>
-				<enabled>false</enabled>
-			</snapshots>
-		</repository>
-		<repository>
-			<id>bibforge.snapshots.http</id>
-			<name>Bibforge Managed Snapshot Repository</name>
-			<url>http://repository.bibforge.org/archiva/repository/snapshots</url>
-			<releases>
-				<enabled>true</enabled>
-			</releases>
-			<snapshots>
-				<enabled>true</enabled>
-			</snapshots>
-		</repository>
+	  <repositories>
+		    <repository>
+			      <id>bibforge.internal.http</id>
+			      <name>Bibforge Managed Internal Repository</name>
+			      <url>http://repository.bibforge.org/archiva/repository/internal</url>
+			      <releases>
+				        <enabled>true</enabled>
+			      </releases>
+			      <snapshots>
+				        <enabled>false</enabled>
+			      </snapshots>
+		    </repository>
+		    <repository>
+			      <id>bibforge.snapshots.http</id>
+			      <name>Bibforge Managed Snapshot Repository</name>
+			      <url>http://repository.bibforge.org/archiva/repository/snapshots</url>
+			      <releases>
+				        <enabled>true</enabled>
+			      </releases>
+			      <snapshots>
+				        <enabled>true</enabled>
+			      </snapshots>
+		    </repository>
  
- 		<repository>
-			<id>dh.nexus.releases</id>
-			<name>Cophi Nexus Releases</name>
-			<url>http://dev.digital-humanities.de/nexus/content/repositories/releases</url>
-			<releases>
-				<enabled>true</enabled>
-			</releases>
-			<snapshots>
-				<enabled>false</enabled>
-			</snapshots>
-		</repository>
-		<repository>
-			<id>dh.nexus.snapshots</id>
-			<name>Cophi Nexus snapshots</name>
-			<url>http://dev.digital-humanities.de/nexus/content/repositories/snapshots</url>
-			<releases>
-				<enabled>true</enabled>
-			</releases>
-			<snapshots>
-				<enabled>true</enabled>
-			</snapshots>
-		</repository>
+ 		   <repository>
+			      <id>dh.nexus.releases</id>
+			      <name>Cophi Nexus Releases</name>
+			      <url>http://dev.digital-humanities.de/nexus/content/repositories/releases</url>
+			      <releases>
+				        <enabled>true</enabled>
+			      </releases>
+			      <snapshots>
+				        <enabled>false</enabled>
+			      </snapshots>
+		    </repository>
+		    <repository>
+			      <id>dh.nexus.snapshots</id>
+			      <name>Cophi Nexus snapshots</name>
+			      <url>http://dev.digital-humanities.de/nexus/content/repositories/snapshots</url>
+			      <releases>
+				        <enabled>true</enabled>
+			      </releases>
+			      <snapshots>
+				        <enabled>true</enabled>
+			      </snapshots>
+		    </repository>
    
-	</repositories>
+	  </repositories>
 
 
-	<dependencies>
-		<dependency>
-			<groupId>junit</groupId>
-			<artifactId>junit</artifactId>
-			<version>4.10</version>
-			<scope>test</scope>
-		</dependency>
-		<dependency>
-			<groupId>com.google.guava</groupId>
-			<artifactId>guava</artifactId>
-			<version>13.0.1</version>
-		</dependency>
-		<dependency>
-			<groupId>info.textgrid.middleware</groupId>
-			<artifactId>tgcrud-client</artifactId>
-			<version>2.3.4-SNAPSHOT</version>
-		</dependency>
-		<dependency>
-			<groupId>info.textgrid.middleware</groupId>
-			<artifactId>tgsearch-client</artifactId>
-			<version>2.1.0-SNAPSHOT</version>
-		</dependency>
-		<dependency>
-			<groupId>info.textgrid.middleware</groupId>
-			<artifactId>confclient</artifactId>
-			<version>1.0-SNAPSHOT</version>
-		</dependency>
-		<dependency>
-			<groupId>org.apache.cxf</groupId>
-			<artifactId>cxf-rt-frontend-jaxrs</artifactId>
-			<version>2.5.3</version>
-		</dependency>
-		<dependency>
-			<groupId>net.sf.saxon</groupId>
-			<artifactId>Saxon-HE</artifactId>
-			<version>9.4</version>
-		</dependency>
-		<dependency>
-			<groupId>info.textgrid.utils</groupId>
-			<artifactId>link-rewriter-core</artifactId>
-			<version>0.0.4-SNAPSHOT</version>
-		</dependency>
-		<dependency>
-			<groupId>commons-io</groupId>
-			<artifactId>commons-io</artifactId>
-			<version>2.4</version>
-		</dependency>
-	</dependencies>
+	  <dependencies>
+		    <dependency>
+			      <groupId>junit</groupId>
+			      <artifactId>junit</artifactId>
+			      <version>${junit-version}</version>
+			      <scope>test</scope>
+		    </dependency>
+		    <dependency>
+			      <groupId>com.google.guava</groupId>
+			      <artifactId>guava</artifactId>
+			      <version>${guava-version}</version>
+		    </dependency>
+		    <dependency>
+			      <groupId>info.textgrid.middleware</groupId>
+			      <artifactId>tgcrud-client</artifactId>
+			      <version>${tgcrud-version}</version>
+		    </dependency>
+		    <dependency>
+			      <groupId>info.textgrid.middleware</groupId>
+			      <artifactId>tgsearch-client</artifactId>
+			      <version>${tgsearch-version}</version>
+		    </dependency>
+		    <dependency>
+			      <groupId>info.textgrid.middleware</groupId>
+			      <artifactId>confclient</artifactId>
+			      <version>${confclient-version}</version>
+		    </dependency>
+		    <dependency>
+			      <groupId>org.apache.cxf</groupId>
+			      <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+			      <version>${cxf-version}</version>
+		    </dependency>
+		    <dependency>
+			      <groupId>net.sf.saxon</groupId>
+			      <artifactId>Saxon-HE</artifactId>
+			      <version>${saxon-version}</version>
+		    </dependency>
+		    <dependency>
+			      <groupId>info.textgrid.utils</groupId>
+			      <artifactId>link-rewriter-core</artifactId>
+			      <version>${link-rewriter-version}</version>
+		    </dependency>
+		    <dependency>
+			      <groupId>commons-io</groupId>
+			      <artifactId>commons-io</artifactId>
+			      <version>${commons-io-version}</version>
+		    </dependency>
+	  </dependencies>
 	
 	
-	<build>
-		<pluginManagement>
-			<plugins>
-				<plugin>
-					<groupId>org.codehaus.mojo</groupId>
-					<artifactId>tomcat-maven-plugin</artifactId>
-					<version>1.1</version>
-					<executions>
-						<execution>
-							<id>default-cli</id>
-							<goals>
-								<goal>run</goal>
-							</goals>
-							<configuration>
-								<port>13000</port>
-								<path>/aggregator</path>
-								<useSeparateTomcatClassLoader>false</useSeparateTomcatClassLoader>
-							</configuration>
-						</execution>
-					</executions>
-				</plugin>
-				<plugin>
-					<groupId>org.apache.maven.plugins</groupId>
-					<artifactId>maven-compiler-plugin</artifactId>
-					<configuration>
-						<source>1.5</source>
-						<target>1.5</target>
-					</configuration>
-				</plugin>
-				<plugin>
-					<groupId>org.apache.maven.plugins</groupId>
-					<artifactId>maven-eclipse-plugin</artifactId>
-					<configuration>
-						<projectNameTemplate>[artifactId]-[version]</projectNameTemplate>
-						<wtpmanifest>true</wtpmanifest>
-						<wtpapplicationxml>true</wtpapplicationxml>
-						<wtpversion>2.0</wtpversion>
-					</configuration>
-				</plugin>
-				<!--This plugin's configuration is used to store Eclipse m2e settings 
+	  <build>
+		    <pluginManagement>
+			      <plugins>
+				        <plugin>
+					          <groupId>org.codehaus.mojo</groupId>
+					          <artifactId>tomcat-maven-plugin</artifactId>
+					          <version>1.1</version>
+					          <executions>
+						            <execution>
+							              <id>default-cli</id>
+							              <goals>
+								                <goal>run</goal>
+							              </goals>
+							              <configuration>
+								                <port>13000</port>
+								                <path>/aggregator</path>
+								                <useSeparateTomcatClassLoader>false</useSeparateTomcatClassLoader>
+							              </configuration>
+						            </execution>
+					          </executions>
+				        </plugin>
+				        <plugin>
+					          <groupId>org.apache.maven.plugins</groupId>
+					          <artifactId>maven-compiler-plugin</artifactId>
+					          <configuration>
+						            <source>1.5</source>
+						            <target>1.5</target>
+					          </configuration>
+				        </plugin>
+				        <plugin>
+					          <groupId>org.apache.maven.plugins</groupId>
+					          <artifactId>maven-eclipse-plugin</artifactId>
+					          <configuration>
+						            <projectNameTemplate>[artifactId]-[version]</projectNameTemplate>
+						            <wtpmanifest>true</wtpmanifest>
+						            <wtpapplicationxml>true</wtpapplicationxml>
+						            <wtpversion>2.0</wtpversion>
+					          </configuration>
+				        </plugin>
+				        <!--This plugin's configuration is used to store Eclipse m2e settings 
 					only. It has no influence on the Maven build itself. -->
 				<plugin>
-					<groupId>org.eclipse.m2e</groupId>
-					<artifactId>lifecycle-mapping</artifactId>
-					<version>1.0.0</version>
-					<configuration>
-						<lifecycleMappingMetadata>
-							<pluginExecutions>
-								<pluginExecution>
-									<pluginExecutionFilter>
-										<groupId>
+					          <groupId>org.eclipse.m2e</groupId>
+					          <artifactId>lifecycle-mapping</artifactId>
+					          <version>1.0.0</version>
+					          <configuration>
+						            <lifecycleMappingMetadata>
+							              <pluginExecutions>
+								                <pluginExecution>
+									                  <pluginExecutionFilter>
+										                    <groupId>
 											org.codehaus.mojo
 										</groupId>
-										<artifactId>
+										                    <artifactId>
 											build-helper-maven-plugin
 										</artifactId>
-										<versionRange>
+										                    <versionRange>
 											[1.5,)
 										</versionRange>
-										<goals>
-											<goal>
+										                    <goals>
+											                      <goal>
 												reserve-network-port
 											</goal>
-										</goals>
-									</pluginExecutionFilter>
-									<action>
-										<ignore></ignore>
-									</action>
-								</pluginExecution>
-							</pluginExecutions>
-						</lifecycleMappingMetadata>
-					</configuration>
-				</plugin>
-			</plugins>
-		</pluginManagement>
-		<plugins>
-			<plugin>
-				<groupId>org.apache.maven.plugins</groupId>
-				<artifactId>maven-compiler-plugin</artifactId>
-				<version>2.3.1</version>
-				<configuration>
-					<source>1.6</source>
-					<target>1.6</target>
-				</configuration>
-			</plugin>
-			<plugin>
-				<groupId>org.codehaus.mojo</groupId>
-				<artifactId>build-helper-maven-plugin</artifactId>
-				<version>1.5</version>
-				<executions>
-					<execution>
-						<id>reserve-network-port</id>
-						<goals>
-							<goal>reserve-network-port</goal>
-						</goals>
-						<phase>process-test-resources</phase>
-						<configuration>
-							<portNames>
-								<portName>test.server.port</portName>
-							</portNames>
-						</configuration>
-					</execution>
-				</executions>
-			</plugin>
-			<plugin>
-				<groupId>org.codehaus.mojo</groupId>
-				<artifactId>tomcat-maven-plugin</artifactId>
-				<executions>
-					<execution>
-						<id>start-tomcat</id>
-						<goals>
-							<goal>run-war</goal>
-						</goals>
-						<phase>pre-integration-test</phase>
-						<configuration>
-							<port>${test.server.port}</port>
-							<path>/aggregator</path>
-							<fork>true</fork>
-							<useSeparateTomcatClassLoader>true</useSeparateTomcatClassLoader>
-						</configuration>
-					</execution>
-					<execution>
-						<id>stop-tomcat</id>
-						<goals>
-							<goal>shutdown</goal>
-						</goals>
-						<phase>post-integration-test</phase>
-						<configuration>
-							<path>/aggregator</path>
-						</configuration>
-					</execution>
-				</executions>
-			</plugin>
-			<plugin>
-				<groupId>org.apache.maven.plugins</groupId>
-				<artifactId>maven-failsafe-plugin</artifactId>
-				<version>2.8.1</version>
-				<executions>
-					<execution>
-						<id>integration-test</id>
-						<goals>
-							<goal>integration-test</goal>
-						</goals>
-						<configuration>
-							<systemPropertyVariables>
-								<service.url>http://localhost:${test.server.port}/aggregator</service.url>
-							</systemPropertyVariables>
-						</configuration>
-					</execution>
-					<execution>
-						<id>verify</id>
-						<goals>
-							<goal>verify</goal>
-						</goals>
-					</execution>
-				</executions>
-			</plugin>
-		</plugins>
-	</build>
-	<profiles>
-	    <profile>
-		<id>wue</id>
-		<build>
+										                    </goals>
+									                  </pluginExecutionFilter>
+									                  <action>
+										                    <ignore/>
+									                  </action>
+								                </pluginExecution>
+							              </pluginExecutions>
+						            </lifecycleMappingMetadata>
+					          </configuration>
+				        </plugin>
+			      </plugins>
+		    </pluginManagement>
 		    <plugins>
-			<plugin>
-			    <groupId>org.codehaus.mojo</groupId>
-			    <artifactId>tomcat-maven-plugin</artifactId>
-			    <configuration>
-				<url>http://wrzh075.rzhousing.uni-wuerzburg.de:8180/manager</url>
-				<server>wrzh075</server>
-			    </configuration>
-			</plugin>
+			      <plugin>
+				        <groupId>org.apache.maven.plugins</groupId>
+				        <artifactId>maven-compiler-plugin</artifactId>
+				        <version>2.3.1</version>
+				        <configuration>
+					          <source>1.6</source>
+					          <target>1.6</target>
+				        </configuration>
+			      </plugin>
+			      <plugin>
+				        <groupId>org.codehaus.mojo</groupId>
+				        <artifactId>build-helper-maven-plugin</artifactId>
+				        <version>1.5</version>
+				        <executions>
+					          <execution>
+						            <id>reserve-network-port</id>
+						            <goals>
+							              <goal>reserve-network-port</goal>
+						            </goals>
+						            <phase>process-test-resources</phase>
+						            <configuration>
+							              <portNames>
+								                <portName>test.server.port</portName>
+							              </portNames>
+						            </configuration>
+					          </execution>
+				        </executions>
+			      </plugin>
+			      <plugin>
+				        <groupId>org.codehaus.mojo</groupId>
+				        <artifactId>tomcat-maven-plugin</artifactId>
+				        <executions>
+					          <execution>
+						            <id>start-tomcat</id>
+						            <goals>
+							              <goal>run-war</goal>
+						            </goals>
+						            <phase>pre-integration-test</phase>
+						            <configuration>
+							              <port>${test.server.port}</port>
+							              <path>/aggregator</path>
+							              <fork>true</fork>
+							              <useSeparateTomcatClassLoader>true</useSeparateTomcatClassLoader>
+						            </configuration>
+					          </execution>
+					          <execution>
+						            <id>stop-tomcat</id>
+						            <goals>
+							              <goal>shutdown</goal>
+						            </goals>
+						            <phase>post-integration-test</phase>
+						            <configuration>
+							              <path>/aggregator</path>
+						            </configuration>
+					          </execution>
+				        </executions>
+			      </plugin>
+			      <plugin>
+				        <groupId>org.apache.maven.plugins</groupId>
+				        <artifactId>maven-failsafe-plugin</artifactId>
+				        <version>2.8.1</version>
+				        <executions>
+					          <execution>
+						            <id>integration-test</id>
+						            <goals>
+							              <goal>integration-test</goal>
+						            </goals>
+						            <configuration>
+							              <systemPropertyVariables>
+								                <service.url>http://localhost:${test.server.port}/aggregator</service.url>
+							              </systemPropertyVariables>
+						            </configuration>
+					          </execution>
+					          <execution>
+						            <id>verify</id>
+						            <goals>
+							              <goal>verify</goal>
+						            </goals>
+					          </execution>
+				        </executions>
+			      </plugin>
 		    </plugins>
-		</build>
+	  </build>
+	  <profiles>
+	    <profile>
+		       <id>wue</id>
+		       <build>
+		          <plugins>
+			            <plugin>
+			               <groupId>org.codehaus.mojo</groupId>
+			               <artifactId>tomcat-maven-plugin</artifactId>
+			               <configuration>
+				                 <url>http://wrzh075.rzhousing.uni-wuerzburg.de:8180/manager</url>
+				                 <server>wrzh075</server>
+			               </configuration>
+			            </plugin>
+		          </plugins>
+		       </build>
 	    </profile>
-	</profiles>
-	<organization>
-		<name>TextGrid</name>
-		<url>http://www.textgrid.de/</url>
-	</organization>
-	<description>The TextGrid Aggregator is an experimental service that can walk aggregations (including editions and collections) and export the objects therein to various formats, e.g., TEI corpus, EPUB, and (experimentally) PDF.</description>
+	  </profiles>
+	  <organization>
+		    <name>TextGrid</name>
+		    <url>http://www.textgrid.de/</url>
+	  </organization>
+	  <description>The TextGrid Aggregator is an experimental service that can walk aggregations (including editions and collections) and export the objects therein to various formats, e.g., TEI corpus, EPUB, and (experimentally) PDF.</description>
 </project>
diff --git a/src/main/java/info/textgrid/services/aggregator/GenericExceptionMapper.java b/src/main/java/info/textgrid/services/aggregator/GenericExceptionMapper.java
index 504ad0b..1882e5c 100644
--- a/src/main/java/info/textgrid/services/aggregator/GenericExceptionMapper.java
+++ b/src/main/java/info/textgrid/services/aggregator/GenericExceptionMapper.java
@@ -94,12 +94,16 @@ public Response toResponse(final Exception exception) {
 	public static Response toResponse(final StatusType status, final String message, final String detail) {
 		final ResponseBuilder builder = Response.status(status);
 		builder.type(MediaType.APPLICATION_XHTML_XML_TYPE);
-		builder.entity(MessageFormat.format(HTML_TEMPLATE, status
-				.getStatusCode(), status.getReasonPhrase(), HtmlUtils
-				.htmlEscapeHex(message), HtmlUtils
-				.htmlEscapeHex(detail)));
+		builder.entity(prepareXHTMLMessage(status, message, detail));
 		return builder.build();
 	}
 
+	public static String prepareXHTMLMessage(final StatusType status,
+			final String message, final String detail) {
+		return MessageFormat.format(HTML_TEMPLATE, status
+				.getStatusCode(), status.getReasonPhrase(), HtmlUtils
+				.htmlEscapeHex(message), HtmlUtils.htmlEscapeHex(detail));
+	}
+
 
 }
diff --git a/src/main/java/info/textgrid/services/aggregator/epub/EPUB.java b/src/main/java/info/textgrid/services/aggregator/epub/EPUB.java
index a6ace4e..78a7397 100644
--- a/src/main/java/info/textgrid/services/aggregator/epub/EPUB.java
+++ b/src/main/java/info/textgrid/services/aggregator/epub/EPUB.java
@@ -14,6 +14,7 @@
 import info.textgrid.services.aggregator.teicorpus.TEICorpusSerializer;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -26,6 +27,7 @@
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
+import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.Status;
 import javax.xml.transform.stream.StreamSource;
@@ -69,69 +71,76 @@ public Response get(@PathParam("object") final URI uri,
 			@QueryParam("stylesheet") final URI xsluri,
 			@QueryParam("sid") final String sid)
 					throws ObjectNotFoundFault, MetadataParseFault, IoFault, AuthFault,
-					ProtocolNotImplementedFault, IOException, SaxonApiException {
+					ProtocolNotImplementedFault {
 		logger.fine("EPUB called for root object: " + uri);
 		final TGCrudService crud = repository.getCRUDService();
-		final MetadataContainerType container = crud.readMetadata(sid,
-				null, uri.toString());
-		final ObjectType rootObject = container.getObject();
-		final String mimeType = rootObject.getGeneric().getProvided()
-				.getFormat();
-		final boolean aggregation = mimeType.contains("aggregation");
-		if (!aggregation && !mimeType.matches("^text/.*xml.*")) {
-			final String errorMsg = "The EPUB export can only convert aggregations or XML documents to EPUB, however, the document {0} you referred to has the MIME type {1}.";
-			logger.warning("Failing with: " + errorMsg);
-			return Response.status(Status.UNSUPPORTED_MEDIA_TYPE)
-					.entity(MessageFormat.format(errorMsg, uri, mimeType))
-					.type("text/plain").build();
-		}
-
-		final File workingDir = Files.createTempDir();
-		logger.fine("Using " + workingDir + " to build the E-Book");
-
-		final File corpus = new File(workingDir, "corpus.xml");
-		if (aggregation) {
-			// First, use the aggregator to create a TEI corpus file to build on
-			final TEICorpusSerializer corpusSerializer = new TEICorpusSerializer(
-					rootObject, true, sid);
-			final FileOutputStream corpusOutput = new FileOutputStream(corpus);
-			corpusSerializer.write(corpusOutput);
-			corpusOutput.close();
-		} else {
-			final InputStream tei = repository.getContent(uri);
-			Files.copy(new InputSupplier<InputStream>() {
-
-				@Override
-				public InputStream getInput() throws IOException {
-					return tei;
-				}
-			}, corpus);
-		}
-
-		// Now, run the EPUB stylesheet
-		// TODO cache the saxon stuff
-		final XsltTransformer transformer;
-		if (xsluri == null)
-			transformer = teiToEpub.load();
-		else {
-			logger.info("Loading stylesheet from " + xsluri);
-			final StreamSource xsltSource = new StreamSource(xsluri.toURL().openStream());
-			final XsltExecutable xsltExecutable = xsltProcessor.newXsltCompiler().compile(xsltSource);
-			transformer = xsltExecutable.load();
+		try {
+			final MetadataContainerType container = crud.readMetadata(sid,
+					null, uri.toString());
+			final ObjectType rootObject = container.getObject();
+			final String mimeType = rootObject.getGeneric().getProvided()
+					.getFormat();
+			final boolean aggregation = mimeType.contains("aggregation");
+			if (!aggregation && !mimeType.matches("^text/.*xml.*")) {
+				final String errorMsg = "The EPUB export can only convert aggregations or XML documents to EPUB, however, the document {0} you referred to has the MIME type {1}.";
+				logger.warning("Failing with: " + errorMsg);
+				return Response.status(Status.UNSUPPORTED_MEDIA_TYPE)
+						.entity(MessageFormat.format(errorMsg, uri, mimeType))
+						.type("text/plain").build();
+			}
+
+			final File workingDir = Files.createTempDir();
+			logger.fine("Using " + workingDir + " to build the E-Book");
+
+			final File corpus = new File(workingDir, "corpus.xml");
+			if (aggregation) {
+				// First, use the aggregator to create a TEI corpus file to build on
+				final TEICorpusSerializer corpusSerializer = new TEICorpusSerializer(
+						rootObject, true, sid);
+				final FileOutputStream corpusOutput = new FileOutputStream(corpus);
+				corpusSerializer.write(corpusOutput);
+				corpusOutput.close();
+			} else {
+				final InputStream tei = repository.getContent(uri);
+				Files.copy(new InputSupplier<InputStream>() {
+
+					@Override
+					public InputStream getInput() throws IOException {
+						return tei;
+					}
+				}, corpus);
+			}
+
+			// Now, run the EPUB stylesheet
+			// TODO cache the saxon stuff
+			final XsltTransformer transformer;
+			if (xsluri == null)
+				transformer = teiToEpub.load();
+			else {
+				logger.info("Loading stylesheet from " + xsluri);
+				final StreamSource xsltSource = new StreamSource(xsluri.toURL().openStream());
+				final XsltExecutable xsltExecutable = xsltProcessor.newXsltCompiler().compile(xsltSource);
+				transformer = xsltExecutable.load();
+			}
+			transformer.setDestination(xsltProcessor.newSerializer(new File(
+					workingDir, "output.xml")));
+			transformer.setSource(new StreamSource(corpus));
+			transformer.transform();
+
+			return RESTUtils
+					.attachmentResponse(
+							rootObject.getGeneric().getProvided().getTitle()
+							.get(0)
+							+ ".epub").type("application/epub+zip")
+							.entity(new EPUBSerializer(workingDir, repository, corpus)).build();
+
+		} catch (final FileNotFoundException e) {
+			throw new WebApplicationException(e);
+		} catch (final IOException e) {
+			throw new WebApplicationException(e);
+		} catch (final SaxonApiException e) {
+			throw new WebApplicationException(e);
 		}
-		transformer.setDestination(xsltProcessor.newSerializer(new File(
-				workingDir, "output.xml")));
-		transformer.setSource(new StreamSource(corpus));
-		transformer.transform();
-
-		final EPUBSerializer serializer = new EPUBSerializer(workingDir, repository, corpus);
-		return RESTUtils
-				.attachmentResponse(
-						rootObject.getGeneric().getProvided().getTitle()
-						.get(0)
-						+ ".epub").type("application/epub+zip")
-						.entity(serializer).build();
-
 	}
 
 }
diff --git a/src/test/java/info/textgrid/services/aggregator/TestPDF.java b/src/test/java/info/textgrid/services/aggregator/TestPDF.java
index e14f693..f6b7b59 100644
--- a/src/test/java/info/textgrid/services/aggregator/TestPDF.java
+++ b/src/test/java/info/textgrid/services/aggregator/TestPDF.java
@@ -6,6 +6,8 @@
 
 import javax.ws.rs.core.Response;
 
+import junit.framework.Assert;
+
 import org.junit.Test;
 
 public class TestPDF {
@@ -13,7 +15,8 @@ public class TestPDF {
 	@Test
 	public void testGet() {
 		final PDF pdf = new PDF(TextGridRepProvider.getInstance());
-		final Response response = pdf.get(URI.create("textgrid:h4jw.0"), "OeXTtXQpyAmzAWbcIYNV9kn27Dj8lk78KZUF1MGXYsULozHkMEPJsQcLYGZ9jQ91346833336381705");
+		final Response response = pdf.get(URI.create("textgrid:jfss.0"), null);
+		Assert.assertEquals(200, response.getStatus());
 	}
 
 }
-- 
GitLab