package de.peacei.gae.foodsupplier.out;
import java.io.OutputStream;
import java.util.List;
import com.google.inject.Singleton;
import de.peacei.gae.foodsupplier.Finals;
import de.peacei.gae.foodsupplier.data.Comment;
import de.peacei.gae.foodsupplier.data.Weekplan;
import de.peacei.gae.foodsupplier.out.json.JSONRenderer;
import de.peacei.gae.foodsupplier.out.xml.XMLRenderer;
@Singleton
public class RenderingService {
public void renderWeekplan(Weekplan weekplan, OutputStream os, String format) {
this.renderWeekplan(weekplan, os, format, null);
}
public void renderWeekplan(Weekplan weekplan, OutputStream os, String format, String callback) {
Renderer renderer = null;
renderer = getRenderer(format);
if (renderer != null) {
if(callback != null) {
renderer.setCallback(callback);
}
renderer.renderWeekplan(weekplan, os);
}
}
public void renderComments(List<Comment> comments, OutputStream os, String format) {
}
public void renderComments(List<Comment> comments, OutputStream os, String format, String callback) {
Renderer renderer = null;
renderer = getRenderer(format);
if (renderer != null) {
if(callback != null) {
renderer.setCallback(callback);
}
renderer.renderComments(comments, os);
}
}
private Renderer getRenderer(String format) {
if (format.equals(Finals.FORMAT_JSON)) {
return new JSONRenderer();
}
if (format.equals(Finals.FORMAT_XML)) {
return new XMLRenderer();
}
return null;
}
}