Tag: cws_src680_rpt23fix02
User: tmorgner
Date: 2007-07-25 15:05:49+0000
Added:
   
dba/reportdesign/java/com/sun/star/report/pentaho/layoutprocessor/OfficeGroupInstanceSectionLayoutController.java
   
dba/reportdesign/java/com/sun/star/report/pentaho/model/OfficeGroupInstanceSection.java

Modified:
   dba/reportdesign/java/com/sun/star/report/pentaho/configuration.properties
   
dba/reportdesign/java/com/sun/star/report/pentaho/layoutprocessor/OfficeGroupLayoutController.java
   
dba/reportdesign/java/com/sun/star/report/pentaho/layoutprocessor/OfficeGroupSectionLayoutController.java
   dba/reportdesign/java/com/sun/star/report/pentaho/model/OfficeGroup.java
   
dba/reportdesign/java/com/sun/star/report/pentaho/output/OfficeDocumentReportTarget.java
   
dba/reportdesign/java/com/sun/star/report/pentaho/output/text/TextRawReportTarget.java
   
dba/reportdesign/java/com/sun/star/report/pentaho/parser/rpt/GroupReadHandler.java

Log:
 Issue number:  78128
 
 This commit fixes the messed up repeating-header system. The whole thing has
 been redesigned to create a clean state-flow that can be debugged and traced
 without any weird mind-bending activities. The report-targets now have a 
 new state (IN_GROUP_INSTANCE) to keep track of the group's processing and
 to separate repeating headers and footers from ordinary headers and footers.
 
 This patch also enforces a clean state-flow in the OfficeReportOutputTarget
 and explicitly checks for all allowed band-types and throws exceptions on
 every illegal state.
 
 
 

File Changes:

Directory: /dba/reportdesign/java/com/sun/star/report/pentaho/
==============================================================

File [changed]: configuration.properties
Url: 
http://dba.openoffice.org/source/browse/dba/reportdesign/java/com/sun/star/report/pentaho/configuration.properties?r1=1.2&r2=1.2.4.1
Delta lines:  +3 -2
-------------------
--- configuration.properties    2007-07-09 11:56:04+0000        1.2
+++ configuration.properties    2007-07-25 15:05:45+0000        1.2.4.1
@@ -4,9 +4,9 @@
 #
 #   $RCSfile: configuration.properties,v $
 #
-#   $Revision: 1.2 $
+#   $Revision: 1.2.4.1 $
 #
-#   last change: $Author: rt $ $Date: 2007/07/09 11:56:04 $
+#   last change: $Author: tmorgner $ $Date: 2007/07/25 15:05:45 $
 #
 #   The Contents of this file are made available subject to
 #   the terms of GNU Lesser General Public License Version 2.1.
@@ -150,3 +150,4 @@
 
org.jfree.report.flow.structure.com.sun.star.report.pentaho.model.VariablesDeclarationSection=com.sun.star.report.pentaho.layoutprocessor.VariablesDeclarationLayoutController
 
org.jfree.report.flow.structure.com.sun.star.report.pentaho.model.OfficeDetailSection=com.sun.star.report.pentaho.layoutprocessor.OfficeDetailLayoutController
 
org.jfree.report.flow.structure.com.sun.star.report.pentaho.model.OfficeTableSection=com.sun.star.report.pentaho.layoutprocessor.OfficeTableLayoutController
+org.jfree.report.flow.structure.com.sun.star.report.pentaho.model.OfficeGroupInstanceSection=com.sun.star.report.pentaho.layoutprocessor.OfficeGroupInstanceSectionLayoutController

Directory: /dba/reportdesign/java/com/sun/star/report/pentaho/layoutprocessor/
==============================================================================

File [added]: OfficeGroupInstanceSectionLayoutController.java
Url: 
http://dba.openoffice.org/source/browse/dba/reportdesign/java/com/sun/star/report/pentaho/layoutprocessor/OfficeGroupInstanceSectionLayoutController.java?rev=1.1.2.1&content-type=text/vnd.viewcvs-markup
Added lines: 159
----------------
package com.sun.star.report.pentaho.layoutprocessor;

import org.jfree.report.flow.layoutprocessor.SectionLayoutController;
import org.jfree.report.flow.layoutprocessor.LayoutController;
import org.jfree.report.flow.layoutprocessor.ElementLayoutController;
import org.jfree.report.flow.layoutprocessor.LayoutControllerFactory;
import org.jfree.report.flow.layoutprocessor.LayoutControllerUtil;
import org.jfree.report.flow.FlowController;
import org.jfree.report.flow.ReportTarget;
import org.jfree.report.flow.ReportContext;
import org.jfree.report.DataSourceException;
import org.jfree.report.ReportDataFactoryException;
import org.jfree.report.ReportProcessingException;
import org.jfree.report.expressions.Expression;
import org.jfree.report.structure.Element;
import org.jfree.report.structure.Node;
import org.jfree.layouting.util.AttributeMap;
import com.sun.star.report.pentaho.model.VariablesDeclarationSection;
import com.sun.star.report.pentaho.model.OfficeGroupSection;
import com.sun.star.report.pentaho.OfficeNamespaces;

/**
 * Creation-Date: 25.07.2007, 14:50:45
 *
 * @author Thomas Morgner
 */
public class OfficeGroupInstanceSectionLayoutController extends 
SectionLayoutController
{
  public static final int STATE_PROCESS_VARIABLES = 2;
  public static final int STATE_PROCESS_NORMAL_FLOW = 3;
  private int state;
  private boolean waitForJoin;

  public OfficeGroupInstanceSectionLayoutController()
  {
  }

  public void initialize(final Object node, final FlowController 
flowController, final LayoutController parent)
      throws DataSourceException, ReportDataFactoryException, 
ReportProcessingException
  {
    super.initialize(node, flowController, parent);
    state = STATE_PROCESS_VARIABLES;
  }

  protected LayoutController processContent(final ReportTarget target)
      throws DataSourceException, ReportProcessingException, 
ReportDataFactoryException
  {
    if (state == 
OfficeGroupInstanceSectionLayoutController.STATE_PROCESS_VARIABLES)
    {
      // todo: Fill the variables section with something sensible ..
      final VariablesDeclarationSection variables = new 
VariablesDeclarationSection();
      final OfficeGroupInstanceSectionLayoutController controller =
          (OfficeGroupInstanceSectionLayoutController) clone();
      controller.state =
          OfficeGroupLayoutController.STATE_PROCESS_NORMAL_FLOW;
      controller.waitForJoin = true;
      return processChild(controller, variables, getFlowController());
    }
    return super.processContent(target);
  }

  // isDisplayable is private in version 0.9.1, so until the upgrade we keep 
this copy of the method
  // todo: Delete it unce the sun-cvs contains version 0.9.2.
  protected LayoutController processChild(final SectionLayoutController derived,
                                          final Node node,
                                          final FlowController flowController)
      throws DataSourceException, ReportProcessingException,
      ReportDataFactoryException
  {
    final ReportContext reportContext = flowController.getReportContext();
    final LayoutControllerFactory layoutControllerFactory = 
reportContext.getLayoutControllerFactory();
    if (isDisplayable(node))
    {
      derived.setProcessingState(ElementLayoutController.WAITING_FOR_JOIN);
      return layoutControllerFactory.create(flowController, node, derived);
    }
    else
    {
      derived.setProcessingState(ElementLayoutController.WAITING_FOR_JOIN);
      final LayoutController childLc = 
layoutControllerFactory.create(flowController, node, derived);
      return LayoutControllerUtil.skipInvisibleElement(childLc);
    }
  }

  protected boolean isDisplayable(final Node node) throws DataSourceException
  {
    if (node instanceof OfficeGroupSection == false)
    {
      return _isDisplayable(node);
    }

    final OfficeGroupSection section = (OfficeGroupSection) node;
    if (section.isRepeatSection())
    {
      return false;
    }
    return _isDisplayable(node);
  }

  protected boolean _isDisplayable(final Node node)
      throws DataSourceException
  {
    // temp method until the pending upgrade to 0.9.2. Later we just call 
super.isDisplayable(..) instead.
    if (node.isEnabled() == false)
    {
      return false;
    }

    final Expression expression = node.getDisplayCondition();
    if (expression == null)
    {
      return true;
    }

    final Object result = 
LayoutControllerUtil.evaluateExpression(getFlowController(), node, expression);
    if (Boolean.TRUE.equals(result))
    {
      return true;
    }
    return false;
  }

  protected void resetSectionForRepeat()
  {
    super.resetSectionForRepeat();
    state = STATE_PROCESS_VARIABLES;
  }

  /**
   * Joins with a delegated process flow. This is generally called from a child
   * flow and should *not* (I mean it!) be called from outside. If you do,
   * you'll suffer.
   *
   * @param flowController the flow controller of the parent.
   * @return the joined layout controller that incorperates all changes from the
   *         delegate.
   */
  public LayoutController join(final FlowController flowController)
  {
    if (waitForJoin)
    {
      final OfficeGroupInstanceSectionLayoutController derived = 
(OfficeGroupInstanceSectionLayoutController) clone();
      derived.setProcessingState(ElementLayoutController.OPENED);
      derived.setFlowController(flowController);
      derived.waitForJoin = false;
      return derived;
    }
    return super.join(flowController);
  }

  protected AttributeMap computeAttributes(final FlowController fc, final 
Element element, final ReportTarget target)
      throws DataSourceException
  {
    final AttributeMap map = super.computeAttributes(fc, element, target);
    map.setAttribute(OfficeNamespaces.INTERNAL_NS, "iteration-count", new 
Integer(getIterationCount()));
    return map;
  }

}

File [changed]: OfficeGroupLayoutController.java
Url: 
http://dba.openoffice.org/source/browse/dba/reportdesign/java/com/sun/star/report/pentaho/layoutprocessor/OfficeGroupLayoutController.java?r1=1.2&r2=1.2.4.1
Delta lines:  +31 -30
---------------------
--- OfficeGroupLayoutController.java    2007-07-09 11:56:05+0000        1.2
+++ OfficeGroupLayoutController.java    2007-07-25 15:05:45+0000        1.2.4.1
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: OfficeGroupLayoutController.java,v $
  *
- *  $Revision: 1.2 $
+ *  $Revision: 1.2.4.1 $
  *
- *  last change: $Author: rt $ $Date: 2007/07/09 11:56:05 $
+ *  last change: $Author: tmorgner $ $Date: 2007/07/25 15:05:45 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -40,15 +40,16 @@
 import com.sun.star.report.pentaho.OfficeNamespaces;
 import com.sun.star.report.pentaho.model.OfficeGroup;
 import com.sun.star.report.pentaho.model.OfficeGroupSection;
-import com.sun.star.report.pentaho.model.VariablesDeclarationSection;
+import org.jfree.layouting.util.AttributeMap;
 import org.jfree.report.DataSourceException;
 import org.jfree.report.ReportDataFactoryException;
 import org.jfree.report.ReportProcessingException;
 import org.jfree.report.flow.FlowController;
 import org.jfree.report.flow.ReportTarget;
+import org.jfree.report.flow.layoutprocessor.ElementLayoutController;
 import org.jfree.report.flow.layoutprocessor.LayoutController;
 import org.jfree.report.flow.layoutprocessor.SectionLayoutController;
-import org.jfree.report.flow.layoutprocessor.ElementLayoutController;
+import org.jfree.report.structure.Element;
 
 /**
  * Todo: Document me!
@@ -61,11 +62,12 @@
 {
   public static final int STATE_PROCESS_REPEATING_HEADER = 0;
   public static final int STATE_PROCESS_REPEATING_FOOTER = 1;
-  public static final int STATE_PROCESS_VARIABLES = 2;
   public static final int STATE_PROCESS_NORMAL_FLOW = 3;
   private boolean waitForJoin;
   private int state;
   private VariablesCollection variablesCollection;
+  private boolean repeatHeader;
+  private boolean repeatFooter;
 
   public OfficeGroupLayoutController()
   {
@@ -99,6 +101,14 @@
     super.initialize(node, flowController, parent);
     state = OfficeGroupLayoutController.STATE_PROCESS_REPEATING_HEADER;
     variablesCollection = new VariablesCollection(computeVariablesPrefix());
+
+
+    final OfficeGroup group = (OfficeGroup) getElement();
+    final OfficeGroupSection header = group.getHeader();
+    repeatHeader = (header != null && header.isRepeatSection());
+
+    final OfficeGroupSection footer = group.getFooter();
+    repeatFooter = (footer != null && footer.isRepeatSection());
   }
 
 
@@ -108,65 +118,47 @@
   {
     if (state == OfficeGroupLayoutController.STATE_PROCESS_REPEATING_HEADER)
     {
-      final OfficeGroup group = (OfficeGroup) getElement();
-      final OfficeGroupSection header =
-          (OfficeGroupSection) group.findFirstChild
-          (OfficeNamespaces.OOREPORT_NS, "group-header");
 
       final OfficeGroupLayoutController controller =
           (OfficeGroupLayoutController) clone();
       controller.state =
           OfficeGroupLayoutController.STATE_PROCESS_REPEATING_FOOTER;
 
-      if (header == null || header.isRepeatSection() == false)
+      if (repeatHeader == false)
       {
         return controller;
       }
 
+      final OfficeGroup group = (OfficeGroup) getElement();
+      final OfficeGroupSection header = group.getHeader();
       controller.waitForJoin = true;
       return processChild(controller, header, getFlowController());
     }
 
     if (state == OfficeGroupLayoutController.STATE_PROCESS_REPEATING_FOOTER)
     {
-      final OfficeGroup group = (OfficeGroup) getElement();
-      final OfficeGroupSection footer =
-          (OfficeGroupSection) group.findFirstChild
-          (OfficeNamespaces.OOREPORT_NS, "group-footer");
 
       final OfficeGroupLayoutController controller =
           (OfficeGroupLayoutController) clone();
-      controller.state =
-          OfficeGroupLayoutController.STATE_PROCESS_VARIABLES;
+      controller.state = OfficeGroupLayoutController.STATE_PROCESS_NORMAL_FLOW;
 
-      if (footer == null || footer.isRepeatSection() == false)
+      if (repeatFooter == false)
       {
         return controller;
       }
 
+      final OfficeGroup group = (OfficeGroup) getElement();
+      final OfficeGroupSection footer = group.getFooter();
       controller.waitForJoin = true;
       return processChild(controller, footer, getFlowController());
     }
 
-    if (state == OfficeGroupLayoutController.STATE_PROCESS_VARIABLES)
-    {
-      // todo: Fill the variables section with something sensible ..
-      final VariablesDeclarationSection variables =
-          new VariablesDeclarationSection();
-      final OfficeGroupLayoutController controller =
-          (OfficeGroupLayoutController) clone();
-      controller.state =
-          OfficeGroupLayoutController.STATE_PROCESS_NORMAL_FLOW;
-      controller.waitForJoin = true;
-      return processChild(controller, variables, getFlowController());
-    }
     return super.processContent(target);
   }
 
   protected void resetSectionForRepeat()
   {
     super.resetSectionForRepeat();
-    state = STATE_PROCESS_VARIABLES;
   }
 
   /**
@@ -215,4 +207,13 @@
   {
     return variablesCollection;
   }
+
+  protected AttributeMap computeAttributes(final FlowController fc, final 
Element element, final ReportTarget target)
+      throws DataSourceException
+  {
+    final AttributeMap map = super.computeAttributes(fc, element, target);
+    final String value = String.valueOf(repeatHeader || repeatFooter);
+    map.setAttribute(OfficeNamespaces.INTERNAL_NS, 
"repeating-header-or-footer", value);
+    return map;
+  }
 }

File [changed]: OfficeGroupSectionLayoutController.java
Url: 
http://dba.openoffice.org/source/browse/dba/reportdesign/java/com/sun/star/report/pentaho/layoutprocessor/OfficeGroupSectionLayoutController.java?r1=1.2&r2=1.2.4.1
Delta lines:  +34 -4
--------------------
--- OfficeGroupSectionLayoutController.java     2007-07-09 11:56:05+0000        
1.2
+++ OfficeGroupSectionLayoutController.java     2007-07-25 15:05:45+0000        
1.2.4.1
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: OfficeGroupSectionLayoutController.java,v $
  *
- *  $Revision: 1.2 $
+ *  $Revision: 1.2.4.1 $
  *
- *  last change: $Author: rt $ $Date: 2007/07/09 11:56:05 $
+ *  last change: $Author: tmorgner $ $Date: 2007/07/25 15:05:45 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -39,12 +39,16 @@
 
 import org.jfree.report.flow.layoutprocessor.SectionLayoutController;
 import org.jfree.report.flow.layoutprocessor.LayoutController;
+import org.jfree.report.flow.layoutprocessor.ElementLayoutController;
 import org.jfree.report.flow.FlowController;
 import org.jfree.report.flow.ReportTarget;
 import org.jfree.report.structure.Element;
 import org.jfree.report.DataSourceException;
+import org.jfree.report.ReportProcessingException;
+import org.jfree.report.ReportDataFactoryException;
 import org.jfree.layouting.util.AttributeMap;
 import com.sun.star.report.pentaho.OfficeNamespaces;
+import com.sun.star.report.pentaho.model.OfficeGroupSection;
 
 /**
  * This layoutcontroller simply checks, whether the parent layout controller
@@ -63,6 +67,31 @@
   {
   }
 
+  protected LayoutController startElement(final ReportTarget target)
+      throws DataSourceException, ReportProcessingException, 
ReportDataFactoryException
+  {
+    final OfficeGroupSection section = (OfficeGroupSection) getElement();
+    if (section.isRepeatSection() == false)
+    {
+      return super.startElement(target);
+    }
+
+    final LayoutController controller = getParent();
+    if (controller instanceof OfficeGroupLayoutController == false)
+    {
+      return super.startElement(target);
+    }
+    final OfficeGroupLayoutController oglc = (OfficeGroupLayoutController) 
controller;
+    if (oglc.isNormalFlowProcessing() == false)
+    {
+      return super.startElement(target);
+    }
+
+    // Skip the processing if the section is a repeating header or footer and 
we are processing the normal flow ..
+    final ElementLayoutController clone = (ElementLayoutController) 
this.clone();
+    clone.setProcessingState(ElementLayoutController.FINISHED);
+    return clone;
+  }
 
   protected AttributeMap computeAttributes(final FlowController fc,
                                            final Element element,
@@ -75,8 +104,7 @@
     {
       return attrs;
     }
-    final OfficeGroupLayoutController oglc =
-        (OfficeGroupLayoutController) controller;
+    final OfficeGroupLayoutController oglc = (OfficeGroupLayoutController) 
controller;
     if (oglc.isNormalFlowProcessing())
     {
       return attrs;
@@ -85,4 +113,6 @@
     attrs.setAttribute(OfficeNamespaces.INTERNAL_NS, "repeated-section", 
"true");
     return attrs;
   }
+
+
 }

Directory: /dba/reportdesign/java/com/sun/star/report/pentaho/model/
====================================================================

File [changed]: OfficeGroup.java
Url: 
http://dba.openoffice.org/source/browse/dba/reportdesign/java/com/sun/star/report/pentaho/model/OfficeGroup.java?r1=1.2&r2=1.2.4.1
Delta lines:  +31 -4
--------------------
--- OfficeGroup.java    2007-07-09 11:56:06+0000        1.2
+++ OfficeGroup.java    2007-07-25 15:05:45+0000        1.2.4.1
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: OfficeGroup.java,v $
  *
- *  $Revision: 1.2 $
+ *  $Revision: 1.2.4.1 $
  *
- *  last change: $Author: rt $ $Date: 2007/07/09 11:56:06 $
+ *  last change: $Author: tmorgner $ $Date: 2007/07/25 15:05:45 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -37,8 +37,9 @@
 
 package com.sun.star.report.pentaho.model;
 
-import org.jfree.report.structure.Group;
 import com.sun.star.report.pentaho.OfficeNamespaces;
+import org.jfree.report.structure.Section;
+import org.jfree.report.structure.Element;
 
 /**
  * An office group is a virtual section that contains the group header, footer
@@ -47,7 +48,7 @@
  * @author Thomas Morgner
  * @since 02.03.2007
  */
-public class OfficeGroup extends Group
+public class OfficeGroup extends Section
 {
   public OfficeGroup()
   {
@@ -64,4 +65,30 @@
     return "true".equals
         (getAttribute(OfficeNamespaces.OOREPORT_NS, "reset-page-number"));
   }
+
+  public OfficeGroupSection getHeader()
+  {
+    final OfficeGroupInstanceSection instanceSection =
+        (OfficeGroupInstanceSection) 
findFirstChild(OfficeNamespaces.INTERNAL_NS, "group-instance");
+    if (instanceSection == null)
+    {
+      return null;
+    }
+    return (OfficeGroupSection) instanceSection.findFirstChild
+        (OfficeNamespaces.OOREPORT_NS, "group-header");
+
+  }
+
+  public OfficeGroupSection getFooter()
+  {
+    final OfficeGroupInstanceSection instanceSection =
+        (OfficeGroupInstanceSection) 
findFirstChild(OfficeNamespaces.INTERNAL_NS, "group-instance");
+    if (instanceSection == null)
+    {
+      return null;
+    }
+    return (OfficeGroupSection) instanceSection.findFirstChild
+        (OfficeNamespaces.OOREPORT_NS, "group-footer");
+
+  }
 }

File [added]: OfficeGroupInstanceSection.java
Url: 
http://dba.openoffice.org/source/browse/dba/reportdesign/java/com/sun/star/report/pentaho/model/OfficeGroupInstanceSection.java?rev=1.1.2.1&content-type=text/vnd.viewcvs-markup
Added lines: 15
---------------
package com.sun.star.report.pentaho.model;

import org.jfree.report.structure.Group;

/**
 * Creation-Date: 25.07.2007, 14:41:54
 *
 * @author Thomas Morgner
 */
public class OfficeGroupInstanceSection extends Group
{
  public OfficeGroupInstanceSection()
  {
  }
}

Directory: /dba/reportdesign/java/com/sun/star/report/pentaho/output/
=====================================================================

File [changed]: OfficeDocumentReportTarget.java
Url: 
http://dba.openoffice.org/source/browse/dba/reportdesign/java/com/sun/star/report/pentaho/output/OfficeDocumentReportTarget.java?r1=1.2&r2=1.2.4.1
Delta lines:  +182 -71
----------------------
--- OfficeDocumentReportTarget.java     2007-07-09 11:56:07+0000        1.2
+++ OfficeDocumentReportTarget.java     2007-07-25 15:05:46+0000        1.2.4.1
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: OfficeDocumentReportTarget.java,v $
  *
- *  $Revision: 1.2 $
+ *  $Revision: 1.2.4.1 $
  *
- *  last change: $Author: rt $ $Date: 2007/07/09 11:56:07 $
+ *  last change: $Author: tmorgner $ $Date: 2007/07/25 15:05:46 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -126,6 +126,7 @@
   public static final int STATE_IN_GROUP_BODY = 4;
   public static final int STATE_IN_SECTION = 5;
   public static final int STATE_IN_OTHER = 6;
+  public static final int STATE_IN_GROUP_INSTANCE = 7;
 
   protected static class BufferState
   {
@@ -189,6 +190,7 @@
   {
     private GroupContext parent;
     private int iterationCount;
+    private boolean groupWithRepeatingSection;
 
     protected GroupContext(final GroupContext parent)
     {
@@ -205,9 +207,29 @@
       return iterationCount;
     }
 
-    public void iterationFinished()
+    public void setIterationCount(final int iterationCount)
     {
-      iterationCount += 1;
+      this.iterationCount = iterationCount;
+    }
+
+    public boolean isGroupWithRepeatingSection()
+    {
+      return groupWithRepeatingSection;
+    }
+
+    public void setGroupWithRepeatingSection(final boolean 
groupWithRepeatingSection)
+    {
+      this.groupWithRepeatingSection = groupWithRepeatingSection;
+    }
+
+
+    public String toString()
+    {
+      return "GroupContext{" +
+          "parent=" + parent +
+          ", iterationCount=" + iterationCount +
+          ", groupWithRepeatingSection=" + groupWithRepeatingSection +
+          '}';
     }
   }
 
@@ -313,7 +335,7 @@
     final DefaultTagDescription tagDescription = createTagDescription();
     try
     {
-      final OutputStream outputStream = 
outputRepository.createOutputStream(target,"text/xml");
+      final OutputStream outputStream = 
outputRepository.createOutputStream(target, "text/xml");
       final Writer writer = new OutputStreamWriter(outputStream, "UTF-8");
 
       this.rootXmlWriter = new XmlWriter(writer, tagDescription);
@@ -513,17 +535,57 @@
           return;
         }
         case OfficeDocumentReportTarget.STATE_IN_CONTENT:
-        case OfficeDocumentReportTarget.STATE_IN_GROUP:
-        case OfficeDocumentReportTarget.STATE_IN_GROUP_BODY:
         {
+          // Either a ordinary section or a group ..
           // A group.
-          if (ReportTargetUtil.isElementOfType(OfficeNamespaces.INTERNAL_NS, 
"group-body", attrs) ||
-              ReportTargetUtil.isElementOfType(OfficeNamespaces.INTERNAL_NS, 
"report-body", attrs))
+          if (ReportTargetUtil.isElementOfType(OfficeNamespaces.INTERNAL_NS, 
"report-body", attrs))
           {
             
states.push(IntegerCache.getInteger(OfficeDocumentReportTarget.STATE_IN_GROUP_BODY));
             startGroupBody(attrs);
           }
-          else if 
(ReportTargetUtil.isElementOfType(OfficeNamespaces.OOREPORT_NS, "group", attrs))
+          else
+          {
+            // Either a template-section, page-header, page-footer, 
report-header, report-footer
+            // or variables-section
+            
states.push(IntegerCache.getInteger(OfficeDocumentReportTarget.STATE_IN_SECTION));
+            if (ReportTargetUtil.isElementOfType(OfficeNamespaces.INTERNAL_NS, 
"template", attrs))
+            {
+              currentRole = OfficeDocumentReportTarget.ROLE_TEMPLATE;
+            }
+            else if 
(ReportTargetUtil.isElementOfType(OfficeNamespaces.OOREPORT_NS, "page-header", 
attrs))
+            {
+              currentRole = OfficeDocumentReportTarget.ROLE_PAGE_HEADER;
+            }
+            else if 
(ReportTargetUtil.isElementOfType(OfficeNamespaces.OOREPORT_NS, "page-footer", 
attrs))
+            {
+              currentRole = OfficeDocumentReportTarget.ROLE_PAGE_FOOTER;
+            }
+            else if 
(ReportTargetUtil.isElementOfType(OfficeNamespaces.OOREPORT_NS, 
"report-header", attrs))
+            {
+              currentRole = OfficeDocumentReportTarget.ROLE_REPORT_HEADER;
+            }
+            else if 
(ReportTargetUtil.isElementOfType(OfficeNamespaces.OOREPORT_NS, 
"report-footer", attrs))
+            {
+              currentRole = OfficeDocumentReportTarget.ROLE_REPORT_FOOTER;
+            }
+            else if 
(ReportTargetUtil.isElementOfType(OfficeNamespaces.INTERNAL_NS, 
"variables-section", attrs))
+            {
+              currentRole = OfficeDocumentReportTarget.ROLE_VARIABLES;
+            }
+            else
+            {
+              throw new IllegalStateException("Expected either 'template', 
'report-body', " +
+                  "'report-header', 'report-footer', 'variables-section', 
'page-header' or 'page-footer'");
+            }
+            startReportSection(attrs, currentRole);
+          }
+          return;
+        }
+        case OfficeDocumentReportTarget.STATE_IN_GROUP_BODY:
+        {
+          // We now expect either an other group or a detail band.
+
+          if (ReportTargetUtil.isElementOfType(OfficeNamespaces.OOREPORT_NS, 
"group", attrs))
           {
             
states.push(IntegerCache.getInteger(OfficeDocumentReportTarget.STATE_IN_GROUP));
             groupContext = new GroupContext(groupContext);
@@ -531,10 +593,82 @@
           }
           else
           {
-            // Either a page-header, page-footer, report-header, report-footer
-            // or detail-band or variables-section
+            // Either a variables-section, or a detail-band
+            
states.push(IntegerCache.getInteger(OfficeDocumentReportTarget.STATE_IN_SECTION));
+            if (ReportTargetUtil.isElementOfType(OfficeNamespaces.OOREPORT_NS, 
"detail", attrs))
+            {
+              currentRole = OfficeDocumentReportTarget.ROLE_DETAIL;
+            }
+            else if 
(ReportTargetUtil.isElementOfType(OfficeNamespaces.INTERNAL_NS, 
"variables-section", attrs))
+            {
+              currentRole = OfficeDocumentReportTarget.ROLE_VARIABLES;
+            }
+            else
+            {
+              throw new IllegalStateException("Expected either 'group', 
'detail' or 'variables-section'");
+            }
+            startReportSection(attrs, currentRole);
+          }
+          return;
+        }
+        case OfficeDocumentReportTarget.STATE_IN_GROUP:
+        {
+          // A group can carry a repeating group header/footer or a 
group-instance section.
+          if (ReportTargetUtil.isElementOfType(OfficeNamespaces.INTERNAL_NS, 
"group-instance", attrs))
+          {
+            
states.push(IntegerCache.getInteger(OfficeDocumentReportTarget.STATE_IN_GROUP_INSTANCE));
+            startGroupInstance(attrs);
+          }
+          else
+          {
+            // repeating group header/footer, but *no* variables section
+            
states.push(IntegerCache.getInteger(OfficeDocumentReportTarget.STATE_IN_SECTION));
+            if (ReportTargetUtil.isElementOfType(OfficeNamespaces.OOREPORT_NS, 
"group-header", attrs) &&
+                "true".equals(attrs.getAttribute(OfficeNamespaces.INTERNAL_NS, 
"repeated-section")))
+            {
+              currentRole = 
OfficeDocumentReportTarget.ROLE_REPEATING_GROUP_HEADER;
+            }
+            else if 
(ReportTargetUtil.isElementOfType(OfficeNamespaces.OOREPORT_NS, "group-footer", 
attrs) &&
+                     
"true".equals(attrs.getAttribute(OfficeNamespaces.INTERNAL_NS, 
"repeated-section")))
+            {
+              currentRole = 
OfficeDocumentReportTarget.ROLE_REPEATING_GROUP_FOOTER;
+            }
+            else
+            {
+              throw new IllegalStateException("Expected either 
'group-instance', " +
+                  "'repeating group-header' or 'repeating group-footer'");
+            }
+            startReportSection(attrs, currentRole);
+          }
+          return;
+        }
+        case OfficeDocumentReportTarget.STATE_IN_GROUP_INSTANCE:
+        {
+          if (ReportTargetUtil.isElementOfType(OfficeNamespaces.INTERNAL_NS, 
"group-body", attrs))
+          {
+            
states.push(IntegerCache.getInteger(OfficeDocumentReportTarget.STATE_IN_GROUP_BODY));
+            startGroupBody(attrs);
+          }
+          else
+          {
+            // Either a group-header or group-footer or variables-section
             
states.push(IntegerCache.getInteger(OfficeDocumentReportTarget.STATE_IN_SECTION));
-            currentRole = computeRoleForSection(attrs);
+            if (ReportTargetUtil.isElementOfType(OfficeNamespaces.OOREPORT_NS, 
"group-header", attrs))
+            {
+              currentRole = OfficeDocumentReportTarget.ROLE_GROUP_HEADER;
+            }
+            else if 
(ReportTargetUtil.isElementOfType(OfficeNamespaces.OOREPORT_NS, "group-footer", 
attrs))
+            {
+              currentRole = OfficeDocumentReportTarget.ROLE_GROUP_FOOTER;
+            }
+            else if 
(ReportTargetUtil.isElementOfType(OfficeNamespaces.INTERNAL_NS, 
"variables-section", attrs))
+            {
+              currentRole = OfficeDocumentReportTarget.ROLE_VARIABLES;
+            }
+            else
+            {
+              throw new IllegalStateException("Expected either 'group-body', 
'group-header', 'group-footer' or 'variables-section'");
+            }
             startReportSection(attrs, currentRole);
           }
           return;
@@ -623,57 +757,6 @@
     }
   }
 
-
-  private int computeRoleForSection(final AttributeMap attrs)
-  {
-    if (ReportTargetUtil.isElementOfType(OfficeNamespaces.INTERNAL_NS, 
"template", attrs))
-    {
-      return OfficeDocumentReportTarget.ROLE_TEMPLATE;
-    }
-    if (ReportTargetUtil.isElementOfType(OfficeNamespaces.OOREPORT_NS, 
"group-header", attrs))
-    {
-      if ("true".equals(attrs.getAttribute(OfficeNamespaces.INTERNAL_NS, 
"repeated-section")))
-      {
-        return OfficeDocumentReportTarget.ROLE_REPEATING_GROUP_HEADER;
-      }
-      return OfficeDocumentReportTarget.ROLE_GROUP_HEADER;
-    }
-    if (ReportTargetUtil.isElementOfType(OfficeNamespaces.OOREPORT_NS, 
"group-footer", attrs))
-    {
-      if ("true".equals(attrs.getAttribute(OfficeNamespaces.INTERNAL_NS, 
"repeated-section")))
-      {
-        return OfficeDocumentReportTarget.ROLE_REPEATING_GROUP_FOOTER;
-      }
-      return OfficeDocumentReportTarget.ROLE_GROUP_FOOTER;
-    }
-    if (ReportTargetUtil.isElementOfType(OfficeNamespaces.OOREPORT_NS, 
"page-header", attrs))
-    {
-      return OfficeDocumentReportTarget.ROLE_PAGE_HEADER;
-    }
-    if (ReportTargetUtil.isElementOfType(OfficeNamespaces.OOREPORT_NS, 
"page-footer", attrs))
-    {
-      return OfficeDocumentReportTarget.ROLE_PAGE_FOOTER;
-    }
-    if (ReportTargetUtil.isElementOfType(OfficeNamespaces.OOREPORT_NS, 
"report-header", attrs))
-    {
-      return OfficeDocumentReportTarget.ROLE_REPORT_HEADER;
-    }
-    if (ReportTargetUtil.isElementOfType(OfficeNamespaces.OOREPORT_NS, 
"report-footer", attrs))
-    {
-      return OfficeDocumentReportTarget.ROLE_REPORT_FOOTER;
-    }
-    if (ReportTargetUtil.isElementOfType(OfficeNamespaces.OOREPORT_NS, 
"detail", attrs))
-    {
-      return OfficeDocumentReportTarget.ROLE_DETAIL;
-    }
-    if (ReportTargetUtil.isElementOfType(OfficeNamespaces.INTERNAL_NS, 
"variables-section", attrs))
-    {
-      return OfficeDocumentReportTarget.ROLE_VARIABLES;
-    }
-    throw new IllegalStateException();
-    //return OfficeDocumentReportTarget.ROLE_NONE;
-  }
-
   protected void startBody(final AttributeMap attrs)
       throws IOException
   {
@@ -697,6 +780,24 @@
   protected void startGroup(final AttributeMap attrs)
       throws IOException, DataSourceException, ReportProcessingException
   {
+    final Object repeatingHeaderOrFooter = 
attrs.getAttribute(OfficeNamespaces.INTERNAL_NS, "repeating-header-or-footer");
+    if ("true".equals(repeatingHeaderOrFooter))
+    {
+      getGroupContext().setGroupWithRepeatingSection(true);
+    }
+
+    final Object iterationCount = 
attrs.getAttribute(OfficeNamespaces.INTERNAL_NS, "iteration-count");
+    if (iterationCount instanceof Number)
+    {
+      final Number itNumber = (Number) iterationCount;
+      getGroupContext().setIterationCount(itNumber.intValue());
+    }
+  }
+
+  protected void startGroupInstance(final AttributeMap attrs)
+      throws IOException, DataSourceException, ReportProcessingException
+  {
+
   }
 
   protected void startGroupBody(final AttributeMap attrs)
@@ -795,7 +896,7 @@
   }
 
 
-  public void endElement(final AttributeMap attrs)
+  public final void endElement(final AttributeMap attrs)
       throws DataSourceException, ReportProcessingException
   {
     // final int oldState = getCurrentState();
@@ -819,7 +920,11 @@
         {
           endGroup(attrs);
           groupContext = groupContext.getParent();
-          groupContext.iterationFinished();
+          return;
+        }
+        case OfficeDocumentReportTarget.STATE_IN_GROUP_INSTANCE:
+        {
+          endGroupInstance(attrs);
           return;
         }
         case OfficeDocumentReportTarget.STATE_IN_GROUP_BODY:
@@ -872,6 +977,12 @@
 
   }
 
+  protected void endGroupInstance(final AttributeMap attrs)
+      throws IOException, DataSourceException, ReportProcessingException
+  {
+
+  }
+
   public int getCurrentRole()
   {
     return currentRole;
@@ -924,7 +1035,7 @@
       this.rootXmlWriter.writeStream(state.getXmlAsReader());
 
       final OutputStream stylesOutStream =
-          outputRepository.createOutputStream("styles.xml","text/xml");
+          outputRepository.createOutputStream("styles.xml", "text/xml");
       final OutputStreamWriter osw =
           new OutputStreamWriter(stylesOutStream, "UTF-8");
       final StylesWriter stylesWriter = new StylesWriter(osw);
@@ -1141,7 +1252,7 @@
       final CSSNumericValue width = image.getWidth(); // always in 100th of a 
mm
       final CSSNumericValue height = image.getHeight(); // always in 100th of 
a mm
 
-      Log.debug ("Image " + imageData + " Width: " + width + ", Height: " + 
height);
+      Log.debug("Image " + imageData + " Width: " + width + ", Height: " + 
height);
 
       CSSNumericValue imageAreaWidthVal;
       CSSNumericValue imageAreaHeightVal;
@@ -1232,7 +1343,7 @@
       }
       else
       {
-        Log.debug ("There is no image-context, so we have to rely on the 
image's natural bounds. " +
+        Log.debug("There is no image-context, so we have to rely on the 
image's natural bounds. " +
             "This may go awfully wrong.");
         imageAreaWidthVal = image.getWidth();
         imageAreaHeightVal = image.getHeight();
@@ -1249,7 +1360,7 @@
       frameList.setAttribute(OfficeNamespaces.SVG_NS, "x", "0cm");
       frameList.setAttribute(OfficeNamespaces.SVG_NS, "y", "0cm");
 
-      Log.debug ("Image " + imageData + " A-Width: " + imageAreaWidthVal + ", 
A-Height: " + imageAreaHeightVal);
+      Log.debug("Image " + imageData + " A-Width: " + imageAreaWidthVal + ", 
A-Height: " + imageAreaHeightVal);
 
       if (imageAreaWidthVal != null)
       {

Directory: /dba/reportdesign/java/com/sun/star/report/pentaho/output/text/
==========================================================================

File [changed]: TextRawReportTarget.java
Url: 
http://dba.openoffice.org/source/browse/dba/reportdesign/java/com/sun/star/report/pentaho/output/text/TextRawReportTarget.java?r1=1.2&r2=1.2.4.1
Delta lines:  +14 -18
---------------------
--- TextRawReportTarget.java    2007-07-09 11:56:08+0000        1.2
+++ TextRawReportTarget.java    2007-07-25 15:05:46+0000        1.2.4.1
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: TextRawReportTarget.java,v $
  *
- *  $Revision: 1.2 $
+ *  $Revision: 1.2.4.1 $
  *
- *  last change: $Author: rt $ $Date: 2007/07/09 11:56:08 $
+ *  last change: $Author: tmorgner $ $Date: 2007/07/25 15:05:46 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -679,6 +679,7 @@
     getXmlWriter().writeTag(OfficeNamespaces.TABLE_NS, "table-row", attrList, 
XmlWriterSupport.OPEN);
   }
 
+  // todo
   private void startTable(final AttributeMap attrs)
       throws ReportProcessingException, IOException
   {
@@ -737,30 +738,18 @@
       {
         // no pagebreaks ..
       }
-      else if (currentMasterPage == null)
+      else if (currentMasterPage == null ||
+               isPagebreakPending())
       {
         // Must be the first table, as we have no master-page yet.
         masterPageName = createMasterPage(true, true);
-        if (masterPageName == null)
-        {
-          // we should always have a master-page ...
-          masterPageName = currentMasterPage.getStyleName();
-        }
-        breakDefinition = new PageBreakDefinition(isResetPageNumber());
-      }
-      else if (isPagebreakPending())
-      {
-        // Derive an automatic style for the pagebreak.
-//        Log.debug("Manual pagebreak at begin of section: " + 
getCurrentRole());
-        breakDefinition = getPagebreakDefinition();
         setPagebreakDefinition(null);
-        masterPageName = createMasterPage(true, true);
         if (masterPageName == null)
         {
           // we should always have a master-page ...
           masterPageName = currentMasterPage.getStyleName();
         }
-
+        breakDefinition = new PageBreakDefinition(isResetPageNumber());
       }
     }
     else if (isPagebreakPending() &&
@@ -948,7 +937,6 @@
     final String elementType = 
ReportTargetUtil.getElemenTypeFromAttribute(attrs);
     final AttributeList attrList = buildAttributeList(attrs);
     xmlWriter.writeTag(namespace, elementType, attrList, 
XmlWriterSupport.OPEN);
-
   }
 
   private boolean isTableMergeActive()
@@ -1090,6 +1078,14 @@
     }
   }
 
+  protected void startGroupInstance(final AttributeMap attrs)
+      throws IOException, DataSourceException, ReportProcessingException
+  {
+    if (getGroupContext().isGroupWithRepeatingSection())
+    {
+      setPagebreakDefinition(new PageBreakDefinition(isResetPageNumber()));
+    }
+  }
 
   protected void endGroup(final AttributeMap attrs)
       throws IOException, DataSourceException, ReportProcessingException

Directory: /dba/reportdesign/java/com/sun/star/report/pentaho/parser/rpt/
=========================================================================

File [changed]: GroupReadHandler.java
Url: 
http://dba.openoffice.org/source/browse/dba/reportdesign/java/com/sun/star/report/pentaho/parser/rpt/GroupReadHandler.java?r1=1.2&r2=1.2.4.1
Delta lines:  +15 -13
---------------------
--- GroupReadHandler.java       2007-07-09 11:56:09+0000        1.2
+++ GroupReadHandler.java       2007-07-25 15:05:46+0000        1.2.4.1
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: GroupReadHandler.java,v $
  *
- *  $Revision: 1.2 $
+ *  $Revision: 1.2.4.1 $
  *
- *  last change: $Author: rt $ $Date: 2007/07/09 11:56:09 $
+ *  last change: $Author: tmorgner $ $Date: 2007/07/25 15:05:46 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -39,16 +39,13 @@
 
 import java.util.ArrayList;
 
+import com.sun.star.report.pentaho.OfficeNamespaces;
 import com.sun.star.report.pentaho.model.OfficeGroup;
+import com.sun.star.report.pentaho.model.OfficeGroupInstanceSection;
 import com.sun.star.report.pentaho.parser.ElementReadHandler;
-import com.sun.star.report.pentaho.parser.StarXmlFactoryModule;
-import com.sun.star.report.pentaho.OfficeNamespaces;
 import org.jfree.report.expressions.FormulaExpression;
-import org.jfree.report.structure.Group;
-import org.jfree.report.structure.Node;
 import org.jfree.report.structure.Element;
 import org.jfree.report.structure.Section;
-import org.jfree.report.JFreeReportInfo;
 import org.jfree.xmlns.parser.XmlReadHandler;
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
@@ -59,12 +56,17 @@
   private GroupSectionReadHandler groupFooter;
   private GroupReadHandler childGroup;
   private RootTableReadHandler detailSection;
-  private Group group;
+  private OfficeGroup group;
+  private OfficeGroupInstanceSection groupInstanceSection;
   private ArrayList functionHandlers;
 
   public GroupReadHandler()
   {
     group = new OfficeGroup();
+    groupInstanceSection = new OfficeGroupInstanceSection();
+    groupInstanceSection.setNamespace(OfficeNamespaces.INTERNAL_NS);
+    groupInstanceSection.setType("group-instance");
+    group.addNode(groupInstanceSection);
     functionHandlers = new ArrayList();
   }
 
@@ -84,7 +86,7 @@
     {
       final FormulaExpression function = new FormulaExpression();
       function.setFormula(groupExpr);
-      group.setGroupingExpression(function);
+      groupInstanceSection.setGroupingExpression(function);
     }
   }
 
@@ -145,18 +147,18 @@
     {
       final FunctionReadHandler handler =
           (FunctionReadHandler) functionHandlers.get(i);
-      group.addExpression(handler.getExpression());
+      groupInstanceSection.addExpression(handler.getExpression());
     }
 
     if (groupHeader != null)
     {
-      group.addNode(groupHeader.getElement());
+      groupInstanceSection.addNode(groupHeader.getElement());
     }
 
     final Section groupBody = new Section();
     groupBody.setNamespace(OfficeNamespaces.INTERNAL_NS);
     groupBody.setType("group-body");
-    group.addNode(groupBody);
+    groupInstanceSection.addNode(groupBody);
     // XOR: Either the detail or the group section can be set ..
     if (detailSection != null)
     {
@@ -169,7 +171,7 @@
 
     if (groupFooter != null)
     {
-      group.addNode(groupFooter.getElement());
+      groupInstanceSection.addNode(groupFooter.getElement());
     }
   }
 




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to