User: kz Date: 2008-03-05 17:35:07+0000 Modified: dba/reportdesign/java/com/sun/star/report/pentaho/output/OfficeDocumentReportTarget.java
Log: INTEGRATION: CWS rptchart01_DEV300 (1.3.62); FILE MERGED 2008/02/21 09:57:24 oj 1.3.62.6: #i85225# fixes found with PMD 2008/02/20 10:52:55 oj 1.3.62.5: format changes 2008/02/19 11:40:40 oj 1.3.62.4: #i85225# ongoing work 2008/02/19 09:22:16 oj 1.3.62.3: RESYNC: (1.3-1.4); FILE MERGED 2008/02/19 06:42:49 oj 1.3.62.2: #i85225# ongoing work 2008/02/13 07:04:22 oj 1.3.62.1: #i85225# impl chart readhandler and oleproducer 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.4&r2=1.5 Delta lines: +1403 -1374 ------------------------- --- OfficeDocumentReportTarget.java 2008-01-29 14:34:45+0000 1.4 +++ OfficeDocumentReportTarget.java 2008-03-05 17:35:05+0000 1.5 @@ -33,10 +33,9 @@ * MA 02111-1307 USA * ************************************************************************/ - - package com.sun.star.report.pentaho.output; +import com.sun.star.report.DataSourceFactory; import java.awt.Image; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -62,6 +61,7 @@ import com.sun.star.report.pentaho.model.OfficeStylesCollection; import com.sun.star.report.pentaho.styles.LengthCalculator; import com.sun.star.report.pentaho.styles.StyleMapper; +import java.util.Vector; import org.jfree.io.IOUtils; import org.jfree.layouting.input.style.parser.CSSValueFactory; import org.jfree.layouting.input.style.parser.StyleSheetParserUtil; @@ -104,8 +104,8 @@ */ public abstract class OfficeDocumentReportTarget extends AbstractReportTarget { - public static final String TAG_DEF_PREFIX = "com.sun.star.report.pentaho.output."; + public static final String TAG_DEF_PREFIX = "com.sun.star.report.pentaho.output."; public static final int ROLE_NONE = 0; public static final int ROLE_REPORT_HEADER = 1; public static final int ROLE_REPORT_FOOTER = 2; @@ -120,7 +120,7 @@ public static final int ROLE_TEMPLATE = 11; public static final int ROLE_SPREADSHEET_PAGE_HEADER = 12; public static final int ROLE_SPREADSHEET_PAGE_FOOTER = 13; - + public static final int ROLE_P_BODY = 14; public static final int STATE_IN_DOCUMENT = 0; public static final int STATE_IN_BODY = 1; public static final int STATE_IN_CONTENT = 2; @@ -129,9 +129,18 @@ 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; + public static final String FAILED = "Failed"; + public static final String GRAPHIC = "graphic"; + public static final String GRAPHICS = "Graphics"; + public static final String GRAPHIC_PROPERTIES = "graphic-properties"; + public static final String PARAGRAPH = "paragraph"; + public static final String TRUE = "true"; + public static final String STYLE_NAME = "style-name"; + public static final String BACKGROUND_COLOR = "background-color"; protected static class BufferState { + private XmlWriter xmlWriter; private MemoryByteArrayOutputStream xmlBuffer; private OfficeStylesCollection stylesCollection; @@ -145,7 +154,6 @@ this.xmlBuffer = xmlBuffer; } - public OfficeStylesCollection getStylesCollection() { return stylesCollection; @@ -161,8 +169,7 @@ try { final byte[] zippedData = xmlBuffer.getRaw(); - final InputStreamReader reader = new InputStreamReader - (new InflaterInputStream(new ByteArrayInputStream(zippedData, 0, xmlBuffer.getLength())), "UTF-16"); + final InputStreamReader reader = new InputStreamReader(new InflaterInputStream(new ByteArrayInputStream(zippedData, 0, xmlBuffer.getLength())), "UTF-16"); final StringWriter writer = new StringWriter((zippedData.length / 2) + 1); IOUtils.getInstance().copyWriter(reader, writer); return writer.toString(); @@ -178,8 +185,7 @@ try { final byte[] zippedData = xmlBuffer.getRaw(); - return new InputStreamReader - (new InflaterInputStream(new ByteArrayInputStream(zippedData, 0, xmlBuffer.getLength())), "UTF-16"); + return new InputStreamReader(new InflaterInputStream(new ByteArrayInputStream(zippedData, 0, xmlBuffer.getLength())), "UTF-16"); } catch (IOException e) { @@ -190,6 +196,7 @@ protected static class GroupContext { + private GroupContext parent; private int iterationCount; private boolean groupWithRepeatingSection; @@ -224,7 +231,6 @@ this.groupWithRepeatingSection = groupWithRepeatingSection; } - public String toString() { return "GroupContext{" + @@ -234,30 +240,24 @@ '}'; } } - private FastStack states; private int currentRole; - private FastStack xmlWriters; private XmlWriter rootXmlWriter; - /** * This styles-collection contains all styles that were predefined in the report definition file. The common styles * and the master-styles will be written unmodified, the automatic styles will be ignored. */ private OfficeStylesCollection predefinedStylesCollection; - /** * This styles-collection contains all master-styles that have been generated by the report definition process. It * also contains all automatic styles that have been generated for the page-bands (and the pagebands as well). */ private OfficeStylesCollection globalStylesCollection; - /** * The content styles collection contains all automatic styles that have been generated for the normal-flow content. */ private OfficeStylesCollection contentStylesCollection; - private OutputRepository outputRepository; private AttributeNameGenerator tableNameGenerator; private AttributeNameGenerator autoStyleNameGenerator; @@ -267,10 +267,10 @@ private StyleSheetParserUtil styleSheetParserUtil; private AttributeNameGenerator imageNames; private ImageProducer imageProducer; + private OleProducer oleProducer; private GroupContext groupContext; private static final boolean DEBUG_ELEMENTS = - JFreeReportBoot.getInstance().getExtendedConfig().getBoolProperty - ("com.sun.star.report.pentaho.output.DebugElements"); + JFreeReportBoot.getInstance().getExtendedConfig().getBoolProperty("com.sun.star.report.pentaho.output.DebugElements"); protected OfficeDocumentReportTarget(final ReportJob reportJob, final ResourceManager resourceManager, @@ -278,7 +278,8 @@ final InputRepository inputRepository, final OutputRepository outputRepository, final String target, - final ImageService imageService) + final ImageService imageService, + final DataSourceFactory datasourcefactory) throws ReportProcessingException { super(reportJob, resourceManager, baseResource); @@ -301,6 +302,7 @@ this.imageNames = new AttributeNameGenerator(); this.imageProducer = new ImageProducer(inputRepository, outputRepository, imageService); + this.oleProducer = new OleProducer(inputRepository, outputRepository, imageService, datasourcefactory); try { @@ -381,22 +383,22 @@ predefinedStylesCollection = reportDoc.getStylesCollection(); final OfficeStyles commonStyles = predefinedStylesCollection.getCommonStyles(); - if (commonStyles.containsStyle("graphic", "Graphics") == false) + if (commonStyles.containsStyle(GRAPHIC,GRAPHICS) == false) { final OfficeStyle graphicsDefaultStyle = new OfficeStyle(); - graphicsDefaultStyle.setStyleFamily("graphic"); - graphicsDefaultStyle.setStyleName("Graphics"); - final Element graphicProperties = produceFirstChild(graphicsDefaultStyle, OfficeNamespaces.STYLE_NS, "graphic-properties"); - graphicProperties.setAttribute(OfficeNamespaces.TEXT_NS, "anchor-type", "paragraph"); + graphicsDefaultStyle.setStyleFamily(GRAPHIC); + graphicsDefaultStyle.setStyleName(GRAPHICS); + final Element graphicProperties = produceFirstChild(graphicsDefaultStyle, OfficeNamespaces.STYLE_NS,GRAPHIC_PROPERTIES); + graphicProperties.setAttribute(OfficeNamespaces.TEXT_NS, "anchor-type",PARAGRAPH); graphicProperties.setAttribute(OfficeNamespaces.SVG_NS, "x", "0cm"); graphicProperties.setAttribute(OfficeNamespaces.SVG_NS, "y", "0cm"); graphicProperties.setAttribute(OfficeNamespaces.STYLE_NS, "wrap", "dynamic"); graphicProperties.setAttribute(OfficeNamespaces.STYLE_NS, "number-wrapped-paragraphs", "no-limit"); graphicProperties.setAttribute(OfficeNamespaces.STYLE_NS, "wrap-contour", "false"); graphicProperties.setAttribute(OfficeNamespaces.STYLE_NS, "vertical-pos", "top"); - graphicProperties.setAttribute(OfficeNamespaces.STYLE_NS, "vertical-rel", "paragraph"); + graphicProperties.setAttribute(OfficeNamespaces.STYLE_NS, "vertical-rel",PARAGRAPH); graphicProperties.setAttribute(OfficeNamespaces.STYLE_NS, "horizontal-pos", "center"); - graphicProperties.setAttribute(OfficeNamespaces.STYLE_NS, "horizontal-rel", "paragraph"); + graphicProperties.setAttribute(OfficeNamespaces.STYLE_NS, "horizontal-rel",PARAGRAPH); commonStyles.addStyle(graphicsDefaultStyle); } @@ -410,7 +412,7 @@ } catch (IOException e) { - throw new ReportProcessingException("Failed", e); + throw new ReportProcessingException( FAILED,e); } } @@ -531,8 +533,7 @@ } else { - throw new IllegalStateException - ("The 'office:body' element must have exactly one child of type 'report'"); + throw new IllegalStateException("The 'office:body' element must have exactly one child of type 'report'"); } return; } @@ -550,7 +551,15 @@ // 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)) + if (ReportTargetUtil.isElementOfType(OfficeNamespaces.INTERNAL_NS, "report-pre-body", attrs)) + { + currentRole = OfficeDocumentReportTarget.ROLE_P_BODY; + } + else if (ReportTargetUtil.isElementOfType(OfficeNamespaces.INTERNAL_NS, "report-post-body", attrs)) + { + currentRole = OfficeDocumentReportTarget.ROLE_P_BODY; + } + else if (ReportTargetUtil.isElementOfType(OfficeNamespaces.INTERNAL_NS, "template", attrs)) { currentRole = OfficeDocumentReportTarget.ROLE_TEMPLATE; } @@ -640,12 +649,12 @@ // 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"))) + 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"))) + TRUE.equals(attrs.getAttribute(OfficeNamespaces.INTERNAL_NS, "repeated-section"))) { currentRole = OfficeDocumentReportTarget.ROLE_REPEATING_GROUP_FOOTER; } @@ -751,16 +760,14 @@ final String attrName = (String) entry.getKey(); final String attrValue = String.valueOf(entry.getValue()); - final String styleFamily = styleMapper.getStyleFamilyFor - (elementNamespace, elementName, attrNamespace, attrName); + final String styleFamily = styleMapper.getStyleFamilyFor(elementNamespace, elementName, attrNamespace, attrName); if (styleFamily == null) { // None of the known style attributes. continue; } - if (styleMapper.isListOfStyles - (elementNamespace, elementName, attrNamespace, attrName)) + if (styleMapper.isListOfStyles(elementNamespace, elementName, attrNamespace, attrName)) { // ignored for now. Log.warn("List of styles is not yet implemented."); @@ -779,12 +786,18 @@ getXmlWriter().writeTag(OfficeNamespaces.OFFICE_NS, "body", XmlWriterSupport.OPEN); } + private final boolean allowBuffering(final int role) + { + return (role == OfficeDocumentReportTarget.ROLE_REPEATING_GROUP_FOOTER || + role == OfficeDocumentReportTarget.ROLE_REPEATING_GROUP_HEADER || + role == OfficeDocumentReportTarget.ROLE_P_BODY || + role == OfficeDocumentReportTarget.ROLE_TEMPLATE); + } + protected void startReportSection(final AttributeMap attrs, final int role) throws IOException, DataSourceException, ReportProcessingException { - if (role == OfficeDocumentReportTarget.ROLE_REPEATING_GROUP_FOOTER || - role == OfficeDocumentReportTarget.ROLE_REPEATING_GROUP_HEADER || - role == OfficeDocumentReportTarget.ROLE_TEMPLATE) + if (allowBuffering(role)) { startBuffering(new OfficeStylesCollection(), true); } @@ -797,7 +810,7 @@ throws IOException, DataSourceException, ReportProcessingException { final Object repeatingHeaderOrFooter = attrs.getAttribute(OfficeNamespaces.INTERNAL_NS, "repeating-header-or-footer"); - if ("true".equals(repeatingHeaderOrFooter)) + if (TRUE.equals(repeatingHeaderOrFooter)) { getGroupContext().setGroupWithRepeatingSection(true); } @@ -844,7 +857,7 @@ } catch (IOException e) { - throw new ReportProcessingException("Failed", e); + throw new ReportProcessingException( FAILED,e); } } @@ -907,11 +920,10 @@ } catch (IOException e) { - throw new ReportProcessingException("Failed", e); + throw new ReportProcessingException( FAILED,e); } } - public final void endElement(final AttributeMap attrs) throws DataSourceException, ReportProcessingException { @@ -972,8 +984,7 @@ { throw new ReportProcessingException("IO Error while writing content", ioe); - } - finally + } finally { states.pop(); @@ -1011,9 +1022,7 @@ final int role) throws IOException, DataSourceException, ReportProcessingException { - if (role == OfficeDocumentReportTarget.ROLE_REPEATING_GROUP_FOOTER || - role == OfficeDocumentReportTarget.ROLE_REPEATING_GROUP_HEADER || - role == OfficeDocumentReportTarget.ROLE_TEMPLATE) + if (allowBuffering(role)) { finishBuffering(); } @@ -1044,8 +1053,7 @@ try { final StylesWriter inlineStylesWriter = new StylesWriter(rootXmlWriter); - inlineStylesWriter.writeContentStyles - (predefinedStylesCollection, contentStylesCollection); + inlineStylesWriter.writeContentStyles(predefinedStylesCollection, contentStylesCollection); final BufferState state = finishBuffering(); this.rootXmlWriter.writeStream(state.getXmlAsReader()); @@ -1055,8 +1063,7 @@ final OutputStreamWriter osw = new OutputStreamWriter(stylesOutStream, "UTF-8"); final StylesWriter stylesWriter = new StylesWriter(osw); - stylesWriter.writeGlobalStyles - (predefinedStylesCollection, globalStylesCollection); + stylesWriter.writeGlobalStyles(predefinedStylesCollection, globalStylesCollection); stylesWriter.close(); this.rootXmlWriter.writeCloseTag(); @@ -1064,7 +1071,7 @@ } catch (IOException e) { - throw new ReportProcessingException("Failed", e); + throw new ReportProcessingException( FAILED,e); } } @@ -1177,8 +1184,7 @@ } else { - attrList.setAttribute - (attrNamespace, key, String.valueOf(entry.getValue())); + attrList.setAttribute(attrNamespace, key, String.valueOf(entry.getValue())); } } } @@ -1250,19 +1256,17 @@ return style; } - protected void startImageProcessing(final AttributeMap attrs) throws ReportProcessingException { final Object imageData = attrs.getAttribute(OfficeNamespaces.INTERNAL_NS, "image-data"); - final boolean preserveIRI = "true".equals(attrs.getAttribute(OfficeNamespaces.INTERNAL_NS, "preserve-IRI")); + final boolean preserveIRI = TRUE.equals(attrs.getAttribute(OfficeNamespaces.INTERNAL_NS, "preserve-IRI")); // for the first shot, do nothing fancy .. final ImageProducer.OfficeImage image = imageProducer.produceImage(imageData, preserveIRI); if (image != null) { - final ImageElementContext imageContext = (ImageElementContext) - attrs.getAttribute(OfficeNamespaces.INTERNAL_NS, "image-context"); + final ImageElementContext imageContext = (ImageElementContext) attrs.getAttribute(OfficeNamespaces.INTERNAL_NS, "image-context"); // When scaling, we have to create an image-style. final CSSNumericValue width = image.getWidth(); // always in 100th of a mm @@ -1295,15 +1299,15 @@ final CSSNumericValue normalizedImageHeight = CSSValueResolverUtility.convertLength(height, imageAreaHeightVal.getType()); - final boolean scale = "true".equals(attrs.getAttribute(OfficeNamespaces.INTERNAL_NS, "scale")); + final boolean scale = TRUE.equals(attrs.getAttribute(OfficeNamespaces.INTERNAL_NS, "scale")); if (scale == false && normalizedImageWidth.getValue() > 0 && normalizedImageHeight.getValue() > 0) { final double clipWidth = normalizedImageWidth.getValue() - imageAreaWidthVal.getValue(); final double clipHeight = normalizedImageHeight.getValue() - imageAreaHeightVal.getValue(); if (clipWidth > 0 && clipHeight > 0) { - final OfficeStyle imageStyle = deriveStyle("graphic", "Graphics"); - final Element graphProperties = produceFirstChild(imageStyle, OfficeNamespaces.STYLE_NS, "graphic-properties"); + final OfficeStyle imageStyle = deriveStyle(GRAPHIC,GRAPHICS); + final Element graphProperties = produceFirstChild(imageStyle, OfficeNamespaces.STYLE_NS,GRAPHIC_PROPERTIES); final StringBuffer buffer = new StringBuffer(); buffer.append("rect("); buffer.append(clipHeight / 2); @@ -1325,8 +1329,8 @@ } else if (clipWidth > 0) { - final OfficeStyle imageStyle = deriveStyle("graphic", "Graphics"); - final Element graphProperties = produceFirstChild(imageStyle, OfficeNamespaces.STYLE_NS, "graphic-properties"); + final OfficeStyle imageStyle = deriveStyle(GRAPHIC,GRAPHICS); + final Element graphProperties = produceFirstChild(imageStyle, OfficeNamespaces.STYLE_NS,GRAPHIC_PROPERTIES); final StringBuffer buffer = new StringBuffer(); buffer.append("rect(0cm "); buffer.append(clipWidth / 2); @@ -1343,8 +1347,8 @@ } else if (clipHeight > 0) { - final OfficeStyle imageStyle = deriveStyle("graphic", "Graphics"); - final Element graphProperties = produceFirstChild(imageStyle, OfficeNamespaces.STYLE_NS, "graphic-properties"); + final OfficeStyle imageStyle = deriveStyle(GRAPHIC,GRAPHICS); + final Element graphProperties = produceFirstChild(imageStyle, OfficeNamespaces.STYLE_NS,GRAPHIC_PROPERTIES); final StringBuffer buffer = new StringBuffer(); buffer.append("rect("); buffer.append(clipHeight / 2); @@ -1383,7 +1387,7 @@ { frameList.setAttribute(OfficeNamespaces.DRAWING_NS, "style-name", styleName); } - frameList.setAttribute(OfficeNamespaces.TEXT_NS, "anchor-type", "paragraph"); + frameList.setAttribute(OfficeNamespaces.TEXT_NS, "anchor-type",PARAGRAPH); frameList.setAttribute(OfficeNamespaces.SVG_NS, "z-index", "0"); frameList.setAttribute(OfficeNamespaces.SVG_NS, "x", "0cm"); frameList.setAttribute(OfficeNamespaces.SVG_NS, "y", "0cm"); @@ -1418,7 +1422,7 @@ } catch (IOException ioe) { - throw new ReportProcessingException("Failed", ioe); + throw new ReportProcessingException( FAILED,ioe); } } } @@ -1455,7 +1459,6 @@ return calculator.getResult(); } - protected CSSNumericValue computeRowHeight(final String rowStyle) { final OfficeStylesCollection contentStyles = getContentStylesCollection(); @@ -1522,7 +1525,6 @@ return null; } - protected CSSNumericValue computeColumnWidth(final String colStyle) { final OfficeStylesCollection contentStyles = getContentStylesCollection(); @@ -1604,5 +1606,32 @@ return paragraphProps; } + protected void startChartProcessing(final AttributeMap attrs) + throws ReportProcessingException + { + final String classId = (String) attrs.getAttribute(OfficeNamespaces.INTERNAL_NS, "class-id"); + final String chartUrl = (String) attrs.getAttribute(OfficeNamespaces.INTERNAL_NS, "href"); + final Vector masterColumns = (Vector) attrs.getAttribute(OfficeNamespaces.INTERNAL_NS, "master-columns"); + final Vector masterValues = (Vector) attrs.getAttribute(OfficeNamespaces.INTERNAL_NS, "master-values"); + final Vector detailColumns = (Vector) attrs.getAttribute(OfficeNamespaces.INTERNAL_NS, "detail-columns"); + final String href = oleProducer.produceOle(chartUrl, masterColumns, masterValues, detailColumns); + + final AttributeList oleList = new AttributeList(); + oleList.setAttribute(OfficeNamespaces.DRAWING_NS, "class-id", classId); + oleList.setAttribute(OfficeNamespaces.XLINK_NS, "href", "./" + href); + oleList.setAttribute(OfficeNamespaces.XLINK_NS, "type", "simple"); + oleList.setAttribute(OfficeNamespaces.XLINK_NS, "show", "embed"); + oleList.setAttribute(OfficeNamespaces.XLINK_NS, "actuate", "onLoad"); + + try + { + getXmlWriter().writeTag(OfficeNamespaces.DRAWING_NS, "object-ole", oleList, XmlWriterSupport.CLOSE); + } + catch (IOException ioe) + { + throw new ReportProcessingException( FAILED,ioe); + } + + } } \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
