User: kz Date: 2008-05-05 14:35:57+0000 Modified: dba/reportdesign/java/com/sun/star/report/pentaho/output/chart/ChartRawReportTarget.java
Log: INTEGRATION: CWS dba30beta (1.3.6); FILE MERGED 2008/04/22 10:30:28 oj 1.3.6.1: #i88503# merge changes from rptchart02 File Changes: Directory: /dba/reportdesign/java/com/sun/star/report/pentaho/output/chart/ =========================================================================== File [changed]: ChartRawReportTarget.java Url: http://dba.openoffice.org/source/browse/dba/reportdesign/java/com/sun/star/report/pentaho/output/chart/ChartRawReportTarget.java?r1=1.3&r2=1.4 Delta lines: +184 -2 --------------------- --- ChartRawReportTarget.java 2008-04-10 17:37:21+0000 1.3 +++ ChartRawReportTarget.java 2008-05-05 14:35:54+0000 1.4 @@ -33,20 +33,37 @@ import com.sun.star.report.ImageService; import com.sun.star.report.InputRepository; import com.sun.star.report.OutputRepository; +import com.sun.star.report.pentaho.OfficeNamespaces; +import com.sun.star.report.OfficeToken; import com.sun.star.report.pentaho.PentahoReportEngineMetaData; -import com.sun.star.report.pentaho.output.spreadsheet.SpreadsheetRawReportTarget; +import com.sun.star.report.pentaho.output.OfficeDocumentReportTarget; +import java.io.IOException; +import org.jfree.layouting.util.AttributeMap; +import org.jfree.report.DataFlags; +import org.jfree.report.DataSourceException; import org.jfree.report.ReportProcessingException; import org.jfree.report.flow.ReportJob; +import org.jfree.report.flow.ReportTargetUtil; import org.jfree.resourceloader.ResourceKey; import org.jfree.resourceloader.ResourceManager; +import org.jfree.util.Log; +import org.jfree.util.PrintStreamLogTarget; +import org.jfree.xmlns.common.AttributeList; +import org.jfree.xmlns.writer.XmlWriter; +import org.jfree.xmlns.writer.XmlWriterSupport; /** * * @author Ocke Janssen */ -public class ChartRawReportTarget extends SpreadsheetRawReportTarget +public class ChartRawReportTarget extends OfficeDocumentReportTarget { + private boolean inFilterElements = false; + private boolean tableRowsStarted = false; + private int tableCount = 0; + private int closeTags = 0; + public ChartRawReportTarget(final ReportJob reportJob, final ResourceManager resourceManager, final ResourceKey baseResource, @@ -58,6 +75,7 @@ throws ReportProcessingException { super(reportJob, resourceManager, baseResource, inputRepository, outputRepository, target, imageService, dataSourceFactory); + Log.getInstance().addTarget(new PrintStreamLogTarget()); } protected String getTargetMimeType() @@ -74,4 +92,168 @@ { return "raw/" + PentahoReportEngineMetaData.OPENDOCUMENT_CHART; } + + protected void startContent(final AttributeMap attrs) throws IOException, DataSourceException, ReportProcessingException + { + inFilterElements = false; + closeTags = 0; + tableCount = 0; + final XmlWriter xmlWriter = getXmlWriter(); + xmlWriter.writeTag(OfficeNamespaces.OFFICE_NS, getStartContent(), null, XmlWriterSupport.OPEN); + ++closeTags; + } + + protected void endContent(final AttributeMap attrs) throws IOException, DataSourceException, ReportProcessingException + { + final XmlWriter xmlWriter = getXmlWriter(); + //xmlWriter.writeCloseTag(); + while (closeTags > 0) + { + xmlWriter.writeCloseTag(); + --closeTags; + } + } + + protected void startReportSection(final AttributeMap attrs, final int role) + throws IOException, DataSourceException, ReportProcessingException + { + } + + protected void endReportSection(final AttributeMap attrs, final int role) + throws IOException, DataSourceException, ReportProcessingException + { + } + + protected void startOther(final AttributeMap attrs) throws IOException, DataSourceException, ReportProcessingException + { + final String namespace = ReportTargetUtil.getNamespaceFromAttribute(attrs); + if (!isFilteredNamespace(namespace)) + { + final String elementType = ReportTargetUtil.getElemenTypeFromAttribute(attrs); + try + { + processElement(attrs, namespace, elementType); + } + catch (IOException e) + { + throw new ReportProcessingException("Failed", e); + } + } + } + + private boolean isFiltered(final String elementType) + { + return OfficeToken.TABLE_HEADER_COLUMNS.equals(elementType) || + OfficeToken.TABLE_HEADER_ROWS.equals(elementType) || + OfficeToken.TABLE_COLUMNS.equals(elementType); + } + + protected void endOther(final AttributeMap attrs) throws IOException, DataSourceException, ReportProcessingException + { + if ( tableRowsStarted && getCurrentRole() == ROLE_TEMPLATE) + { + return; + } + final String namespace = ReportTargetUtil.getNamespaceFromAttribute(attrs); + if (!isFilteredNamespace(namespace)) + { + final String elementType = ReportTargetUtil.getElemenTypeFromAttribute(attrs); + // if this is the report namespace, write out a table definition .. + if (OfficeNamespaces.TABLE_NS.equals(namespace)) + { + if (OfficeToken.TABLE.equals(elementType) || + OfficeToken.TABLE_ROWS.equals(elementType)) + { + return; + } + else if (isFiltered(elementType)) + { + inFilterElements = false; + if (tableCount > 1) + { + return; + } + } + } + else if (OfficeNamespaces.CHART_NS.equals(namespace) && "chart".equals(elementType)) + { + return; + } + if (inFilterElements && tableCount > 1) + { + return; + } + final XmlWriter xmlWriter = getXmlWriter(); + xmlWriter.writeCloseTag(); + --closeTags; + } + } + + public void processContent(final DataFlags value) + throws DataSourceException, ReportProcessingException + { + if ( !(tableRowsStarted && getCurrentRole() == ROLE_TEMPLATE)) + { + super.processContent(value); + } + } + + private void processElement(final AttributeMap attrs, final String namespace, final String elementType) + throws IOException, ReportProcessingException + { + if ( tableRowsStarted && getCurrentRole() == ROLE_TEMPLATE) + { + return; + } + if (OfficeNamespaces.TABLE_NS.equals(namespace)) + { + if (OfficeToken.TABLE.equals(elementType)) + { + tableCount += 1; + if (tableCount > 1) + { + return; + } + } + else if (OfficeToken.TABLE_ROWS.equals(elementType)) + { + if (tableCount > 1) + { + return; + } + tableRowsStarted = true; + } + else if (isFiltered(elementType)) + { + inFilterElements = true; + if (tableCount > 1) + { + return; + } + } + } + if (inFilterElements && tableCount > 1) + { + return; + } + + // All styles have to be processed or you will loose the paragraph-styles and inline text-styles. + // .. + performStyleProcessing(attrs); + + final AttributeList attrList = buildAttributeList(attrs); + final XmlWriter xmlWriter = getXmlWriter(); + xmlWriter.writeTag(namespace, elementType, attrList, XmlWriter.OPEN); + ++closeTags; + // System.out.println("elementType = " + elementType); + } + // ///////////////////////////////////////////////////////////////////////// + public void processText(final String text) throws DataSourceException, ReportProcessingException + { + if (inFilterElements && tableCount > 1) + { + return; + } + super.processText(text); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
