1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 package com.sun.star.report.pentaho.layoutprocessor;
28 
29 import com.sun.star.report.OfficeToken;
30 import com.sun.star.report.pentaho.OfficeNamespaces;
31 
32 import org.jfree.layouting.util.AttributeMap;
33 import org.jfree.report.DataSourceException;
34 import org.jfree.report.JFreeReportInfo;
35 import org.jfree.report.flow.FlowController;
36 import org.jfree.report.flow.ReportTarget;
37 import org.jfree.report.flow.layoutprocessor.SectionLayoutController;
38 import org.jfree.report.structure.Element;
39 import org.jfree.report.structure.Node;
40 import org.jfree.report.structure.Section;
41 import org.jfree.report.util.IntegerCache;
42 
43 /**
44  * Creation-Date: 24.04.2007, 14:40:20
45  *
46  * @author Thomas Morgner
47  */
48 public class OfficeTableLayoutController extends SectionLayoutController
49 {
50 
51     public OfficeTableLayoutController()
52     {
53     }
54 
55     protected AttributeMap computeAttributes(final FlowController fc, final Element element, final ReportTarget target)
56             throws DataSourceException
57     {
58         final AttributeMap attributeMap = new AttributeMap(super.computeAttributes(fc, element, target));
59         final Section s = (Section) element;
60         int rowCount = 0;
61         final Node[] nodeArray = s.getNodeArray();
62         for (int i = 0; i < nodeArray.length; i++)
63         {
64             final Node node = nodeArray[i];
65             if (node instanceof Element)
66             {
67                 final Element child = (Element) node;
68                 if (OfficeNamespaces.TABLE_NS.equals(child.getNamespace()) && OfficeToken.TABLE_ROW.equals(child.getType()))
69                 {
70                     rowCount += 1;
71                 }
72             }
73         }
74 
75         attributeMap.setAttribute(JFreeReportInfo.REPORT_NAMESPACE, "table-row-count", IntegerCache.getInteger(rowCount));
76         attributeMap.makeReadOnly();
77         return attributeMap;
78     }
79 }
80