View Javadoc

1   package org.apache.myfaces.tobago.renderkit.fo.standard.standard.tag;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one or more
5    * contributor license agreements.  See the NOTICE file distributed with
6    * this work for additional information regarding copyright ownership.
7    * The ASF licenses this file to You under the Apache License, Version 2.0
8    * (the "License"); you may not use this file except in compliance with
9    * the License.  You may obtain a copy of the License at
10   *
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
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   * Created: Nov 18, 2004 6:06:54 PM
32   * User: bommel
33   * $Id:PageRenderer.java 472227 2006-11-07 21:05:00 +0100 (Tue, 07 Nov 2006) bommel $
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      //writer.startElement("fo:region-before", page);
82      //writer.writeAttribute("extent", Layout.getMM(margin), null);
83      //writer.endElement("fo:region-before");
84      //writer.startElement("fo:region-after", page);
85      //writer.writeAttribute("extent", Layout.getMM(margin), null);
86      //writer.endElement("fo:region-after");
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 }