Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
212 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...fcrepo/provider/GraphStreamingOutput.java → ...crepo/responses/GraphStreamingOutput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
fcrepo-http-commons/src/main/java/org/fcrepo/responses/HtmlProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
|
||
package org.fcrepo.responses; | ||
|
||
import static com.google.common.collect.ImmutableList.of; | ||
import static javax.ws.rs.core.MediaType.TEXT_HTML; | ||
import static javax.ws.rs.core.MediaType.TEXT_HTML_TYPE; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.io.OutputStreamWriter; | ||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Type; | ||
import java.util.Properties; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.ws.rs.WebApplicationException; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.MultivaluedMap; | ||
import javax.ws.rs.ext.MessageBodyWriter; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
import org.apache.velocity.Template; | ||
import org.apache.velocity.VelocityContext; | ||
import org.apache.velocity.app.VelocityEngine; | ||
import org.apache.velocity.context.Context; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.hp.hpl.jena.query.Dataset; | ||
|
||
@Provider | ||
@Component | ||
public class HtmlProvider implements MessageBodyWriter<Dataset> { | ||
|
||
VelocityEngine velocity = new VelocityEngine(); | ||
|
||
Template template; | ||
|
||
@PostConstruct | ||
void init() throws IOException { | ||
final Properties properties = new Properties(); | ||
try (final InputStream propertiesStream = | ||
this.getClass().getResource("velocity.properties").openStream()) { | ||
properties.load(propertiesStream); | ||
} | ||
velocity.init(properties); | ||
template = velocity.getTemplate("html-template"); | ||
} | ||
|
||
@Override | ||
public void writeTo(final Dataset rdf, final Class<?> type, | ||
final Type genericType, final Annotation[] annotations, | ||
final MediaType mediaType, | ||
final MultivaluedMap<String, Object> httpHeaders, | ||
final OutputStream entityStream) throws IOException, | ||
WebApplicationException { | ||
|
||
// add a Content-type header | ||
httpHeaders.put("Content-type", of((Object) TEXT_HTML)); | ||
|
||
final Context context = new VelocityContext(); | ||
context.put("rdf", rdf); | ||
// the contract of MessageBodyWriter is not to close the stream | ||
// after writing to it | ||
template.merge(context, new OutputStreamWriter(entityStream)); | ||
|
||
} | ||
|
||
@Override | ||
public boolean isWriteable(final Class<?> type, final Type genericType, | ||
final Annotation[] annotations, final MediaType mediaType) { | ||
return mediaType.equals(TEXT_HTML_TYPE) && | ||
(type.equals(Dataset.class) || genericType.getClass().equals( | ||
Dataset.class)); | ||
} | ||
|
||
@Override | ||
public long getSize(final Dataset t, final Class<?> type, | ||
final Type genericType, final Annotation[] annotations, | ||
final MediaType mediaType) { | ||
// we don't know in advance how large the result might be | ||
return -1; | ||
} | ||
|
||
} |
Oops, something went wrong.
Where did the caching headers end up?