1 package org.apache.myfaces.tobago.renderkit.fo.standard.standard.tag;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.apache.myfaces.tobago.component.UIPage;
23 import org.apache.myfaces.tobago.renderkit.PageRendererBase;
24
25 import javax.faces.component.UIComponent;
26 import javax.faces.context.FacesContext;
27 import javax.faces.context.ResponseWriter;
28 import java.io.IOException;
29
30
31
32
33
34
35 public class PageRenderer extends PageRendererBase {
36
37 private static final Log LOG = LogFactory.getLog(PageRenderer.class);
38
39 private static final String HEADER = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
40 private static final String FO_ROOT = "fo:root";
41 private static final String FO_XMLNS = "xmlns:fo";
42 private static final String FO_LAYOUT = "fo:layout-master-set";
43 private static final String FO_URL = "http://www.w3.org/1999/XSL/Format";
44 private static final String PAGE_MASTER = "fo:simple-page-master";
45 private static final String MASTER_NAME = "master-name";
46
47 public void encodeChildren(FacesContext facesContext, UIComponent component)
48 throws IOException {
49 LOG.error("Encode Children");
50 super.encodeChildren(facesContext, component);
51 }
52
53 public boolean getRendersChildren() {
54 return true;
55 }
56
57 public void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException {
58 UIPage page = (UIPage) component;
59 Layout layout = new Layout(2100, 2970);
60 int margin = 60;
61 Layout in = layout.createWithMargin(margin * 2, margin * 2, margin, margin);
62 in.setParent(layout);
63
64
65 ResponseWriter writer = facesContext.getResponseWriter();
66 writer.startElement(FO_ROOT, page);
67 writer.writeAttribute(FO_XMLNS, FO_URL, null);
68 writer.startElement(FO_LAYOUT, page);
69 writer.startElement(PAGE_MASTER, page);
70 writer.writeAttribute(MASTER_NAME, "simple", null);
71 writer.writeAttribute("page-height", layout.getHeightMM(), null);
72 writer.writeAttribute("page-width", layout.getWidthMM(), null);
73 writer.writeAttribute("margin-top", Layout.getMM(margin), null);
74 writer.writeAttribute("margin-bottom", Layout.getMM(margin), null);
75 writer.writeAttribute("margin-left", Layout.getMM(margin), null);
76 writer.writeAttribute("margin-right", Layout.getMM(margin), null);
77 writer.startElement("fo:region-body", page);
78 writer.writeAttribute("margin-top", Layout.getMM(margin), null);
79 writer.writeAttribute("margin-bottom", Layout.getMM(margin), null);
80 writer.endElement("fo:region-body");
81
82
83
84
85
86
87 writer.endElement(PAGE_MASTER);
88 writer.endElement(FO_LAYOUT);
89 writer.startElement("fo:page-sequence", page);
90 writer.writeAttribute("master-reference", "simple", null);
91 writer.startElement("fo:flow", page);
92 writer.writeAttribute("flow-name", "xsl-region-body", null);
93 Layout.putLayout(page, in);
94 }
95
96 public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {
97
98
99 ResponseWriter writer = facesContext.getResponseWriter();
100
101 writer.endElement("fo:flow");
102 writer.endElement("fo:page-sequence");
103 writer.endElement(FO_ROOT);
104
105 writer.flush();
106 }
107
108
109 }