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.OfficeNamespaces;
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.flow.FlowController;
32 import org.jfree.report.flow.ReportTarget;
33 import org.jfree.report.flow.layoutprocessor.SectionLayoutController;
34 import org.jfree.report.structure.Element;
35 import org.jfree.report.structure.Node;
36 import org.jfree.report.structure.Section;
37 import org.jfree.report.util.IntegerCache;
38 
39 /**
40  * Creation-Date: 24.04.2007, 14:40:20
41  *
42  * @author Thomas Morgner
43  */
44 public class OfficeTableLayoutController extends SectionLayoutController
45 {
46 
OfficeTableLayoutController()47     public OfficeTableLayoutController()
48     {
49     }
50 
computeAttributes(final FlowController fc, final Element element, final ReportTarget target)51     protected AttributeMap computeAttributes(final FlowController fc, final Element element, final ReportTarget target)
52             throws DataSourceException
53     {
54         final AttributeMap attributeMap = new AttributeMap(super.computeAttributes(fc, element, target));
55         final Section s = (Section) element;
56         int rowCount = 0;
57         final Node[] nodeArray = s.getNodeArray();
58         for (int i = 0; i < nodeArray.length; i++)
59         {
60             final Node node = nodeArray[i];
61             if (node instanceof Element)
62             {
63                 final Element child = (Element) node;
64                 if (OfficeNamespaces.TABLE_NS.equals(child.getNamespace()) && OfficeToken.TABLE_ROW.equals(child.getType()))
65                 {
66                     rowCount += 1;
67                 }
68             }
69         }
70 
71         attributeMap.setAttribute(JFreeReportInfo.REPORT_NAMESPACE, "table-row-count", IntegerCache.getInteger(rowCount));
72         attributeMap.makeReadOnly();
73         return attributeMap;
74     }
75 }
76