User: hr Date: 2007-08-03 09:51:24+0000 Modified: dba/reportdesign/java/com/sun/star/report/pentaho/output/text/TextRawReportTarget.java
Log: INTEGRATION: CWS rpt23fix02 (1.2.4); FILE MERGED 2007/07/31 09:34:15 tmorgner 1.2.4.6: Fixed the non-display of shapes that was caused by some unnecessary CDATA copied from the original XML file. We now ignore all CDATA from <draw:*> elements. 2007/07/30 13:08:49 tmorgner 1.2.4.5: Issue number: 80157 Keep-Together is now applied to the paragraph-style instead of the cell-style. However, as cell-styles dont (yet) get inherited if the paragraph has a style defined, this now breaks the fonts of the first cell. Either we or the text/ style team should fix or work around this issue. Also fixed: A possible nullpointer if the image-data is invalid. 2007/07/26 12:27:36 tmorgner 1.2.4.4: Issue number: 77610 Now the keep-together is working. We apply the keep-together to the first paragraph in every table-row (most of the time in the first-cell, but if the first cell is a covered cell, we choose the next cell until we find a paragraph in that row). Along with the "TableRowKeep" compatiblity mode, this makes the keep-together setting work. Keep-together will be silently ignored on older versions of OpenOffice/StarOffice, as they did not implement the 'TableRowKeep' compatibility mode. 2007/07/26 11:10:37 tmorgner 1.2.4.3: Issue number: 78128 .. and enforce the pagebreak after the group (to trigger the change of the master page) just to make sure that the page-header/footer is correct if the group has a parent-group. *Now* we've coverd all cases. 2007/07/26 11:06:15 tmorgner 1.2.4.2: Issue number: 78128 After a group that has a repeating group header, we have to reset the master-page to the correct template (one that does no longer contain the repeating header's tables) 2007/07/25 15:05:46 tmorgner 1.2.4.1: 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/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.3 Delta lines: +123 -42 ---------------------- --- TextRawReportTarget.java 2007-07-09 11:56:08+0000 1.2 +++ TextRawReportTarget.java 2007-08-03 09:51:21+0000 1.3 @@ -71,6 +71,7 @@ import org.jfree.resourceloader.ResourceManager; import org.jfree.util.FastStack; import org.jfree.util.ObjectUtilities; +//import org.jfree.util.Log; import org.jfree.xmlns.common.AttributeList; import org.jfree.xmlns.writer.XmlWriter; import org.jfree.xmlns.writer.XmlWriterSupport; @@ -128,6 +129,7 @@ private int tableLayoutConfig; private int expectedTableRowCount; private boolean firstCellSeen; + private boolean cellEmpty; public TextRawReportTarget(final ReportJob reportJob, final ResourceManager resourceManager, @@ -313,6 +315,8 @@ } else { + // reuse the existing one .. + currentMasterPage = masterPage; masterPageName = currentMasterPage.getStyleName(); } } @@ -617,7 +621,7 @@ { // This cannot happen as long as the report sections only contain tables. But at some point in the // future they will be made of paragraphs, and then we are prepared .. -// Log.debug("Variables-Section in own paragraph " + variables); + // Log.debug("Variables-Section in own paragraph " + variables); StyleUtilities.copyStyle("paragraph", TextRawReportTarget.VARIABLES_HIDDEN_STYLE_WITH_KEEPWNEXT, getStylesCollection(), @@ -629,25 +633,99 @@ variables = null; } - // todo: If keep-together is active and the modify the paragraph's style .. + if (ReportTargetUtil.isElementOfType(OfficeNamespaces.TABLE_NS, "table-cell", attrs)) + { + cellEmpty = true; + } + + boolean keepTogetherOnParagraph = true; + + if (keepTogetherOnParagraph) + { + if (ReportTargetUtil.isElementOfType(OfficeNamespaces.TEXT_NS, "p", attrs)) + { + cellEmpty = false; + if (firstCellSeen == false && sectionKeepTogether) + { + final String styleName = (String) attrs.getAttribute(OfficeNamespaces.TEXT_NS, "style-name"); + final OfficeStyle style = deriveStyle("paragraph", styleName); + // Lets set the 'keep-together' flag.. + + Element paragraphProps = style.getParagraphProperties(); + if (paragraphProps == null) + { + paragraphProps = new Section(); + paragraphProps.setNamespace(OfficeNamespaces.STYLE_NS); + paragraphProps.setType("paragraph-properties"); + style.addNode(paragraphProps); + } + paragraphProps.setAttribute(OfficeNamespaces.FO_NS, "keep-together", "always"); + final int keepTogetherState = getCurrentContext().getKeepTogether(); + // We prevent pagebreaks within the two adjacent rows (this one and the next one) if + // either a group-wide keep-together is defined or if we haven't reached the end of the + // current section yet. + if (keepTogetherState == PageContext.KEEP_TOGETHER_GROUP || expectedTableRowCount > 0) + { + paragraphProps.setAttribute(OfficeNamespaces.FO_NS, "keep-with-next", "always"); + } + + attrs.setAttribute(OfficeNamespaces.TEXT_NS, "style-name", style.getStyleName()); + } + } + } + else + { + if (ReportTargetUtil.isElementOfType(OfficeNamespaces.TABLE_NS, "table-cell", attrs)) + { + cellEmpty = false; + if (firstCellSeen == false && sectionKeepTogether) + { + final String styleName = (String) attrs.getAttribute(OfficeNamespaces.TABLE_NS, "style-name"); + final OfficeStyle style = deriveStyle("table-cell", styleName); + // Lets set the 'keep-together' flag.. + + Element paragraphProps = style.getParagraphProperties(); + if (paragraphProps == null) + { + paragraphProps = new Section(); + paragraphProps.setNamespace(OfficeNamespaces.STYLE_NS); + paragraphProps.setType("paragraph-properties"); + style.addNode(paragraphProps); + } + paragraphProps.setAttribute(OfficeNamespaces.FO_NS, "keep-together", "always"); + final int keepTogetherState = getCurrentContext().getKeepTogether(); + // We prevent pagebreaks within the two adjacent rows (this one and the next one) if + // either a group-wide keep-together is defined or if we haven't reached the end of the + // current section yet. + if (keepTogetherState == PageContext.KEEP_TOGETHER_GROUP || expectedTableRowCount > 0) + { + paragraphProps.setAttribute(OfficeNamespaces.FO_NS, "keep-with-next", "always"); + } + + attrs.setAttribute(OfficeNamespaces.TABLE_NS, "style-name", style.getStyleName()); + } + } + } // process the styles as usual performStyleProcessing(attrs); final AttributeList attrList = buildAttributeList(attrs); - xmlWriter.writeTag(namespace, elementType, attrList, - XmlWriterSupport.OPEN); + xmlWriter.writeTag(namespace, elementType, attrList, XmlWriterSupport.OPEN); - if (tableLayoutConfig != TABLE_LAYOUT_VARIABLES_PARAGRAPH && - ReportTargetUtil.isElementOfType(OfficeNamespaces.TEXT_NS, "p", attrs)) + if (ReportTargetUtil.isElementOfType(OfficeNamespaces.TEXT_NS, "p", attrs)) + { + cellEmpty = false; + if (tableLayoutConfig != TABLE_LAYOUT_VARIABLES_PARAGRAPH) { if (variables != null) { -// Log.debug("Variables-Section in existing cell " + variables); + //Log.debug("Variables-Section in existing cell " + variables); xmlWriter.writeText(variables); variables = null; } } + } } @@ -661,17 +739,17 @@ // Log.debug("Adding row-Style: " + rowStyle + " " + rowHeight); sectionHeight.add(rowHeight); - if (expectedTableRowCount > 0) - { - // Some other row. Create a keep-together - - } - else - { - // This is the last row before the section will end. - // or (in some weird cases) There is no information when the row will end. - // Anyway, if we are here, we do not create a keep-together style on the table-row .. - } +// if (expectedTableRowCount > 0) +// { +// // Some other row. Create a keep-together +// +// } +// else +// { +// // This is the last row before the section will end. +// // or (in some weird cases) There is no information when the row will end. +// // Anyway, if we are here, we do not create a keep-together style on the table-row .. +// } // process the styles as usual performStyleProcessing(attrs); @@ -737,30 +815,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 +1014,6 @@ final String elementType = ReportTargetUtil.getElemenTypeFromAttribute(attrs); final AttributeList attrList = buildAttributeList(attrs); xmlWriter.writeTag(namespace, elementType, attrList, XmlWriterSupport.OPEN); - } private boolean isTableMergeActive() @@ -1090,10 +1155,23 @@ } } + 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 { + if (getGroupContext().isGroupWithRepeatingSection()) + { + setPagebreakDefinition(new PageBreakDefinition(isResetPageNumber())); + } + super.endGroup(attrs); finishSection(); @@ -1190,9 +1268,11 @@ final AttributeList rootAttributes = new AttributeList(); rootAttributes.addNamespaceDeclaration("office", OfficeNamespaces.OFFICE_NS); rootAttributes.addNamespaceDeclaration("config", OfficeNamespaces.CONFIG); + rootAttributes.addNamespaceDeclaration("ooo", OfficeNamespaces.OO2004_NS); rootAttributes.setAttribute(OfficeNamespaces.OFFICE_NS, "version", "1.0"); final OutputStream outputStream = getOutputRepository().createOutputStream("settings.xml","text/xml"); final XmlWriter xmlWriter = new XmlWriter(new OutputStreamWriter(outputStream, "UTF-8"), createTagDescription()); + xmlWriter.setAlwaysAddNamespace(true); xmlWriter.writeXmlDeclaration("UTF-8"); xmlWriter.writeTag(OfficeNamespaces.OFFICE_NS, "document-settings", rootAttributes, XmlWriterSupport.OPEN); xmlWriter.writeTag(OfficeNamespaces.OFFICE_NS, "settings", XmlWriterSupport.OPEN); @@ -1241,7 +1321,7 @@ { // This cannot happen as long as the report sections only contain tables. But at some point in the // future they will be made of paragraphs, and then we are prepared .. -// Log.debug("Variables-Section " + variables); + //Log.debug("Variables-Section " + variables); if (sectionKeepTogether == true && expectedTableRowCount > 0) { StyleUtilities.copyStyle("paragraph", @@ -1266,7 +1346,8 @@ } } // Only generate the empty paragraph, if we have to add the keep-together .. - else if (expectedTableRowCount > 0 && sectionKeepTogether == true && firstCellSeen == false) + else if (cellEmpty && expectedTableRowCount > 0 && + sectionKeepTogether == true && firstCellSeen == false) { // we have no variables .. StyleUtilities.copyStyle("paragraph", --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
