Backed out changeset 5d23ff274a2f

This commit is contained in:
René Pfeuffer
2018-06-25 11:52:36 +02:00
parent e826b833cc
commit 83d6ab8e9c
48 changed files with 878 additions and 623 deletions

View File

@@ -42,50 +42,65 @@ import sonia.scm.template.TemplateEngineFactory;
//~--- JDK imports ------------------------------------------------------------
import com.sun.jersey.api.view.Viewable;
import com.sun.jersey.spi.template.ViewProcessor;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
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 sonia.scm.template.Viewable;
/**
*
* @author Sebastian Sdorra
*/
@Provider
public class TemplateEngineViewable implements MessageBodyWriter<Viewable>
public class TemplateEngineViewable implements ViewProcessor<String>
{
private final TemplateEngineFactory templateEngineFactory;
/**
* Constructs ...
*
*
* @param templateEngineFactory
*/
@Inject
public TemplateEngineViewable(TemplateEngineFactory templateEngineFactory)
{
this.templateEngineFactory = templateEngineFactory;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param name
*
* @return
*/
@Override
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return type.isAssignableFrom(Viewable.class);
public String resolve(String name)
{
return name;
}
/**
* Method description
*
*
* @param path
* @param viewable
* @param out
*
* @throws IOException
*/
@Override
public long getSize(Viewable viewable, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return -1;
}
@Override
public void writeTo(Viewable viewable, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
String path = viewable.getPath();
public void writeTo(String path, Viewable viewable, OutputStream out)
throws IOException
{
TemplateEngine engine = templateEngineFactory.getEngineByExtension(path);
if (engine == null)
@@ -100,9 +115,14 @@ public class TemplateEngineViewable implements MessageBodyWriter<Viewable>
throw new IOException("could not find template for ".concat(path));
}
PrintWriter writer = new PrintWriter(entityStream);
PrintWriter writer = new PrintWriter(out);
template.execute(writer, viewable.getContext());
template.execute(writer, viewable.getModel());
writer.flush();
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private TemplateEngineFactory templateEngineFactory;
}