User: hr Date: 2007-08-03 09:50:47+0000 Modified: dba/reportdesign/java/com/sun/star/report/pentaho/output/OfficeDocumentReportTarget.java
Log: INTEGRATION: CWS rpt23fix02 (1.2.4); FILE MERGED 2007/07/30 13:08:49 tmorgner 1.2.4.2: 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/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/ ===================================================================== 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.3 Delta lines: +267 -144 ----------------------- --- OfficeDocumentReportTarget.java 2007-07-09 11:56:07+0000 1.2 +++ OfficeDocumentReportTarget.java 2007-08-03 09:50:45+0000 1.3 @@ -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)); - currentRole = computeRoleForSection(attrs); + 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)); + 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,11 @@ 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); + if (width == null || height == null) + { + return; + } CSSNumericValue imageAreaWidthVal; CSSNumericValue imageAreaHeightVal; @@ -1151,6 +1266,13 @@ imageAreaWidthVal = computeImageWidth(imageContext); imageAreaHeightVal = computeImageHeight(imageContext); + if (imageAreaWidthVal == null || imageAreaHeightVal == null) + { + Log.debug ("Image data returned from context is invalid. Maybe this is not an image?"); + return; + } + else + { // compute the clip-area .. final CSSNumericValue normalizedImageWidth = CSSValueResolverUtility.convertLength(width, imageAreaWidthVal.getType()); @@ -1227,12 +1349,13 @@ imageAreaHeightVal = normalizedImageHeight; } } + } // If we do scale, then we simply use the given image-area-size as valid image size and dont // care about the image itself .. } 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 +1372,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) { --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
