1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with 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,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package com.sun.star.report.pentaho.layoutprocessor;
24 
25 import com.sun.star.report.OfficeToken;
26 import com.sun.star.report.pentaho.model.OfficeGroupSection;
27 
28 import org.jfree.layouting.util.AttributeMap;
29 import org.jfree.report.DataSourceException;
30 import org.jfree.report.JFreeReportInfo;
31 import org.jfree.report.ReportDataFactoryException;
32 import org.jfree.report.ReportProcessingException;
33 import org.jfree.report.flow.FlowController;
34 import org.jfree.report.flow.ReportTarget;
35 import org.jfree.report.flow.layoutprocessor.ElementLayoutController;
36 import org.jfree.report.flow.layoutprocessor.LayoutController;
37 import org.jfree.report.flow.layoutprocessor.SectionLayoutController;
38 import org.jfree.report.structure.Element;
39 
40 /**
41  * This layoutcontroller simply checks, whether the parent layout controller
42  * is a OfficeGroupLayoutController and whether this layout controller is
43  * processing the normal flow or an repeating section. If a repeating section
44  * is being processed, an marker attribute is added to the element's call
45  * to OutputProcessor.startElement() and OutputProcessor.endElement().
46  *
47  * @author Thomas Morgner
48  * @since 19.03.2007
49  */
50 public class OfficeGroupSectionLayoutController extends SectionLayoutController
51 {
52 
OfficeGroupSectionLayoutController()53     public OfficeGroupSectionLayoutController()
54     {
55     }
56 
startElement(final ReportTarget target)57     protected LayoutController startElement(final ReportTarget target)
58             throws DataSourceException, ReportProcessingException, ReportDataFactoryException
59     {
60         final OfficeGroupSection section = (OfficeGroupSection) getElement();
61         if (!section.isRepeatSection())
62         {
63             return super.startElement(target);
64         }
65 
66         final LayoutController controller = getParent();
67         if (!(controller instanceof OfficeGroupLayoutController))
68         {
69             return super.startElement(target);
70         }
71         final OfficeGroupLayoutController oglc = (OfficeGroupLayoutController) controller;
72         if (!oglc.isNormalFlowProcessing())
73         {
74             return super.startElement(target);
75         }
76 
77         // Skip the processing if the section is a repeating header or footer and we are processing the normal flow ..
78         final ElementLayoutController clone = (ElementLayoutController) this.clone();
79         clone.setProcessingState(ElementLayoutController.FINISHED);
80         return clone;
81     }
82 
computeAttributes(final FlowController fc, final Element element, final ReportTarget target)83     protected AttributeMap computeAttributes(final FlowController fc,
84             final Element element,
85             final ReportTarget target)
86             throws DataSourceException
87     {
88         final AttributeMap attrs = super.computeAttributes(fc, element, target);
89         final LayoutController controller = getParent();
90         if (!(controller instanceof OfficeGroupLayoutController))
91         {
92             return attrs;
93         }
94         final OfficeGroupLayoutController oglc = (OfficeGroupLayoutController) controller;
95         if (oglc.isNormalFlowProcessing())
96         {
97             return attrs;
98         }
99 
100         final AttributeMap retval = new AttributeMap(attrs);
101         retval.setAttribute(JFreeReportInfo.REPORT_NAMESPACE, "repeated-section", OfficeToken.TRUE);
102         retval.makeReadOnly();
103         return retval;
104     }
105 }
106