01: package com.flexive.faces.components;
02:
03: import com.flexive.faces.FxJsfComponentUtils;
04: import com.flexive.faces.FxJsfUtils;
05: import com.flexive.shared.XPathElement;
06: import com.flexive.shared.content.FxPK;
07: import com.flexive.shared.exceptions.FxInvalidParameterException;
08: import com.flexive.shared.value.BinaryDescriptor;
09: import com.flexive.shared.value.FxBinary;
10: import com.flexive.war.servlet.ThumbnailServlet;
11:
12: import javax.faces.component.UIOutput;
13: import javax.faces.component.html.HtmlGraphicImage;
14: import javax.faces.context.FacesContext;
15: import java.io.IOException;
16:
17: /**
18: * A basic component for displaying thumbnails of content instances. Renders URLs
19: * to the {@link com.flexive.war.servlet.ThumbnailServlet}.
20: *
21: * @author Daniel Lichtenberger, UCS
22: * @version $Rev$
23: */
24: public class Thumbnail extends UIOutput {
25: private FxPK pk;
26: private FxBinary binary;
27: private HtmlGraphicImage image;
28:
29: public Thumbnail() {
30: setRendererType(null);
31: }
32:
33: @Override
34: public void encodeBegin(FacesContext facesContext)
35: throws IOException {
36: image = (HtmlGraphicImage) FxJsfUtils.addChildComponent(this ,
37: HtmlGraphicImage.COMPONENT_TYPE);
38: final String link;
39: if (getPk() != null) {
40: link = ThumbnailServlet.getLink(getPk(),
41: BinaryDescriptor.PreviewSizes.PREVIEW2);
42: } else if (getBinary() != null) {
43: link = ThumbnailServlet.getLink(XPathElement
44: .getPK(getBinary().getXPath()),
45: BinaryDescriptor.PreviewSizes.PREVIEW2, getBinary()
46: .getXPath());
47: } else {
48: throw new FxInvalidParameterException("pk",
49: "ex.jsf.thumbnail.empty").asRuntimeException();
50: }
51: image.setUrl(link);
52: }
53:
54: @Override
55: public void encodeEnd(FacesContext facesContext) throws IOException {
56: getChildren().remove(image);
57: }
58:
59: public FxPK getPk() {
60: if (pk == null) {
61: return (FxPK) FxJsfComponentUtils.getValue(this , "pk");
62: }
63: return pk;
64: }
65:
66: public void setPk(FxPK pk) {
67: this .pk = pk;
68: }
69:
70: public FxBinary getBinary() {
71: if (binary == null) {
72: return (FxBinary) FxJsfComponentUtils.getValue(this ,
73: "binary");
74: }
75: return binary;
76: }
77:
78: public void setBinary(FxBinary binary) {
79: this.binary = binary;
80: }
81: }
|