Tag: cws_src680_oj14
User: oj      
Date: 2007-05-15 06:50:28+0000
Modified:
   dba/reportdesign/java/com/sun/star/report/pentaho/StarReportData.java
   
dba/reportdesign/java/com/sun/star/report/pentaho/layoutprocessor/FormattedTextLayoutController.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/styles/stylemapper.xml

Log:
 #i77241# new memory footprint

File Changes:

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

File [changed]: StarReportData.java
Url: 
http://dba.openoffice.org/source/browse/dba/reportdesign/java/com/sun/star/report/pentaho/StarReportData.java?r1=1.1.2.2&r2=1.1.2.3
Delta lines:  +12 -4
--------------------
--- StarReportData.java 2007-05-14 06:21:07+0000        1.1.2.2
+++ StarReportData.java 2007-05-15 06:50:24+0000        1.1.2.3
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: StarReportData.java,v $
  *
- *  $Revision: 1.1.2.2 $
+ *  $Revision: 1.1.2.3 $
  *
- *  last change: $Author: oj $ $Date: 2007/05/14 06:21:07 $
+ *  last change: $Author: oj $ $Date: 2007/05/15 06:50:24 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -40,6 +40,8 @@
 import com.sun.star.report.DataSource;
 import org.jfree.report.DataSourceException;
 import org.jfree.report.ReportData;
+import org.jfree.util.Log;
+import org.jfree.base.log.MemoryUsageMessage;
 
 public class StarReportData implements ReportData
 {
@@ -105,12 +107,18 @@
    */
   public boolean isAdvanceable() throws DataSourceException
   {
+    // We cannot advance beyond the last row. If we are on the last row, do 
not return true (this is what the -1 does)
     return currentRow < (rowCount - 1);
   }
 
   public boolean next ()
           throws DataSourceException
   {
+    if ((currentRow % 1000) == 0)
+    {
+      Log.debug (new MemoryUsageMessage("Current row: " + currentRow));
+    }
+
     try
     {
       if (dataSource.next())

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

File [changed]: FormattedTextLayoutController.java
Url: 
http://dba.openoffice.org/source/browse/dba/reportdesign/java/com/sun/star/report/pentaho/layoutprocessor/FormattedTextLayoutController.java?r1=1.1.2.1&r2=1.1.2.2
Delta lines:  +1 -1
-------------------
--- FormattedTextLayoutController.java  2007-05-09 12:20:15+0000        1.1.2.1
+++ FormattedTextLayoutController.java  2007-05-15 06:50:24+0000        1.1.2.2
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: FormattedTextLayoutController.java,v $
  *
- *  $Revision: 1.1.2.1 $
+ *  $Revision: 1.1.2.2 $
  *
- *  last change: $Author: oj $ $Date: 2007/05/09 12:20:15 $
+ *  last change: $Author: oj $ $Date: 2007/05/15 06:50:24 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -212,7 +212,7 @@
     if (result == null)
     {
       // ignore it. Ignoring it is much better than printing 'null'.
-      Log.debug("Formula '" + formulaExpression.getFormula() + "' evaluated to 
null");
+      Log.debug("Formula '" + formulaExpression.getFormula() + "' evaluated to 
null.");
     }
     else if (result instanceof DataFlags)
     {

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.1.2.2&r2=1.1.2.3
Delta lines:  +101 -30
----------------------
--- OfficeDocumentReportTarget.java     2007-05-14 06:21:07+0000        1.1.2.2
+++ OfficeDocumentReportTarget.java     2007-05-15 06:50:25+0000        1.1.2.3
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: OfficeDocumentReportTarget.java,v $
  *
- *  $Revision: 1.1.2.2 $
+ *  $Revision: 1.1.2.3 $
  *
- *  last change: $Author: oj $ $Date: 2007/05/14 06:21:07 $
+ *  last change: $Author: oj $ $Date: 2007/05/15 06:50:25 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -39,14 +39,19 @@
 
 import java.awt.Image;
 import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
+import java.io.Reader;
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.io.Writer;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.zip.DeflaterOutputStream;
+import java.util.zip.InflaterInputStream;
 
 import com.sun.star.report.InputRepository;
 import com.sun.star.report.OutputRepository;
@@ -58,6 +63,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 org.jfree.io.IOUtils;
 import org.jfree.layouting.input.style.parser.CSSValueFactory;
 import org.jfree.layouting.input.style.parser.StyleSheetParserUtil;
 import org.jfree.layouting.input.style.values.CSSNumericValue;
@@ -78,11 +84,13 @@
 import org.jfree.report.structure.Section;
 import org.jfree.report.util.AttributeNameGenerator;
 import org.jfree.report.util.IntegerCache;
+import org.jfree.report.util.MemoryByteArrayOutputStream;
 import org.jfree.resourceloader.ResourceException;
 import org.jfree.resourceloader.ResourceKey;
 import org.jfree.resourceloader.ResourceManager;
 import org.jfree.util.FastStack;
 import org.jfree.util.Log;
+import org.jfree.util.LineBreakIterator;
 import org.jfree.xmlns.common.AttributeList;
 import org.jfree.xmlns.writer.DefaultTagDescription;
 import org.jfree.xmlns.writer.XmlWriter;
@@ -120,14 +128,14 @@
   public static final int STATE_IN_SECTION = 5;
   public static final int STATE_IN_OTHER = 6;
 
-  private static class BufferState
+  protected static class BufferState
   {
     private XmlWriter xmlWriter;
-    private StringWriter xmlBuffer;
+    private MemoryByteArrayOutputStream xmlBuffer;
     private OfficeStylesCollection stylesCollection;
 
     protected BufferState(final XmlWriter xmlWriter,
-                          final StringWriter xmlBuffer,
+                          final MemoryByteArrayOutputStream xmlBuffer,
                           final OfficeStylesCollection stylesCollection)
     {
       this.stylesCollection = stylesCollection;
@@ -146,9 +154,35 @@
       return xmlWriter;
     }
 
-    public StringWriter getXmlBuffer()
+    public String getXmlBuffer() throws ReportProcessingException
     {
-      return xmlBuffer;
+      try
+      {
+        final byte[] zippedData = xmlBuffer.getRaw();
+        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();
+      }
+      catch (IOException e)
+      {
+        throw new ReportProcessingException("Failed to copy buffer", e);
+      }
+    }
+
+    public Reader getXmlAsReader() throws ReportProcessingException
+    {
+      try
+      {
+        final byte[] zippedData = xmlBuffer.getRaw();
+        return new InputStreamReader
+            (new InflaterInputStream(new ByteArrayInputStream(zippedData, 0, 
xmlBuffer.getLength())), "UTF-16");
+      }
+      catch (IOException e)
+      {
+        throw new ReportProcessingException("Failed to copy buffer", e);
+      }
     }
   }
 
@@ -205,12 +239,13 @@
   private AttributeNameGenerator tableNameGenerator;
   private AttributeNameGenerator autoStyleNameGenerator;
   private String target;
-  private static final int INITIAL_BUFFER_SIZE = 4096;
+  private static final int INITIAL_BUFFER_SIZE = 40960;
   private StyleMapper styleMapper;
   private StyleSheetParserUtil styleSheetParserUtil;
   private AttributeNameGenerator imageNames;
   private ImageProducer imageProducer;
   private GroupContext groupContext;
+  private static final boolean DEBUG_ELEMENTS = true;
 
   protected OfficeDocumentReportTarget(final ReportJob reportJob,
                                        final ResourceManager resourceManager,
@@ -401,7 +436,12 @@
       throws DataSourceException, ReportProcessingException
   {
     // todo
-    Log.debug("Starting " + getCurrentState() + "/" + states.size() + " " + 
ReportTargetUtil.getNamespaceFromAttribute(attrs) + " -> " + 
ReportTargetUtil.getElemenTypeFromAttribute(attrs));
+    if (DEBUG_ELEMENTS)
+    {
+      Log.debug("Starting " + getCurrentState() + "/" + states.size() + " " +
+          ReportTargetUtil.getNamespaceFromAttribute(attrs) + " -> " +
+          ReportTargetUtil.getElemenTypeFromAttribute(attrs));
+    }
     try
     {
       switch (getCurrentState())
@@ -636,7 +676,18 @@
   {
     try
     {
-      getXmlWriter().writeText(XmlWriterSupport.normalize(text, false));
+      final XmlWriter xmlWriter = getXmlWriter();
+      final LineBreakIterator lb = new LineBreakIterator(text);
+      while (lb.hasNext())
+      {
+        final String line = (String) lb.next();
+        final String normalizedText = XmlWriterSupport.normalize(line, false);
+        xmlWriter.writeText(normalizedText);
+        if (lb.hasNext())
+        {
+          xmlWriter.writeTag(OfficeNamespaces.TEXT_NS, "line-break", 
XmlWriterSupport.CLOSE);
+        }
+      }
     }
     catch (IOException e)
     {
@@ -775,10 +826,13 @@
     finally
     {
       states.pop();
-//      Log.debug ("Finishing " + getNamespaceFromAttribute(attrs) + ":" +
-//                 getElemenTypeFromAttribute(attrs) + " -> " + i + " -> " + 
getCurrentState());
-      // todo
-      Log.debug ("Finished " + getCurrentState() + "/" + states.size() + " " + 
ReportTargetUtil.getElemenTypeFromAttribute(attrs));
+
+      if (DEBUG_ELEMENTS)
+      {
+        Log.debug("Finished " + getCurrentState() + "/" + states.size() + " " +
+            ReportTargetUtil.getNamespaceFromAttribute(attrs) + ":" +
+            ReportTargetUtil.getElemenTypeFromAttribute(attrs));
+      }
 
     }
   }
@@ -837,7 +891,8 @@
       inlineStylesWriter.writeContentStyles
           (predefinedStylesCollection, contentStylesCollection);
 
-      this.rootXmlWriter.writeText(finishBuffering());
+      final BufferState state = finishBuffering();
+      this.rootXmlWriter.writeStream(state.getXmlAsReader());
 
       final OutputStream stylesOutStream =
           outputRepository.createOutputStream("styles.xml");
@@ -870,7 +925,7 @@
   }
 
   public void startBuffering(final OfficeStylesCollection stylesCollection,
-                             final boolean indent)
+                             final boolean indent) throws 
ReportProcessingException
   {
     final XmlWriter currentWriter;
     if (xmlWriters.isEmpty())
@@ -883,10 +938,15 @@
       currentWriter = bufferState.getXmlWriter();
     }
 
-    final StringWriter xmlBuffer = new StringWriter
-        (OfficeDocumentReportTarget.INITIAL_BUFFER_SIZE);
-    final XmlWriter contentXmlWriter =
-        new XmlWriter(xmlBuffer, createTagDescription());
+    try
+    {
+      final MemoryByteArrayOutputStream out =
+          new MemoryByteArrayOutputStream(INITIAL_BUFFER_SIZE, 256 * 
INITIAL_BUFFER_SIZE);
+      final DeflaterOutputStream deflateOut = new DeflaterOutputStream(out);
+      final OutputStreamWriter xmlBuffer = new OutputStreamWriter(deflateOut, 
"UTF-16");
+      //    final StringWriter xmlBuffer = new StringWriter
+      //        (OfficeDocumentReportTarget.INITIAL_BUFFER_SIZE);
+      final XmlWriter contentXmlWriter = new XmlWriter(xmlBuffer, 
createTagDescription());
     contentXmlWriter.copyNamespaces(currentWriter);
     if (indent)
     {
@@ -898,15 +958,26 @@
       contentXmlWriter.setWriteFinalLinebreak(false);
     }
     contentXmlWriter.setAlwaysAddNamespace(true);
-    xmlWriters.push(new BufferState
-        (contentXmlWriter, xmlBuffer, stylesCollection));
+      xmlWriters.push(new BufferState(contentXmlWriter, out, 
stylesCollection));
+    }
+    catch (IOException ioe)
+    {
+      throw new ReportProcessingException("Unable to create the buffer");
+    }
   }
 
-  public String finishBuffering()
+  public BufferState finishBuffering() throws ReportProcessingException
   {
     final BufferState state = (BufferState) xmlWriters.pop();
-    final StringWriter stringWriter = state.getXmlBuffer();
-    return stringWriter.toString();
+    try
+    {
+      state.getXmlWriter().close();
+    }
+    catch (IOException e)
+    {
+      e.printStackTrace();
+    }
+    return state;
   }
 
   public void commit()

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.1.2.1&r2=1.1.2.2
Delta lines:  +18 -15
---------------------
--- TextRawReportTarget.java    2007-05-09 12:31:52+0000        1.1.2.1
+++ TextRawReportTarget.java    2007-05-15 06:50:25+0000        1.1.2.2
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: TextRawReportTarget.java,v $
  *
- *  $Revision: 1.1.2.1 $
+ *  $Revision: 1.1.2.2 $
  *
- *  last change: $Author: oj $ $Date: 2007/05/09 12:31:52 $
+ *  last change: $Author: oj $ $Date: 2007/05/15 06:50:25 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -334,9 +334,9 @@
     return null;
   }
 
-  private String applyColumnsToPageBand(final String contents,
+  private BufferState applyColumnsToPageBand(final BufferState contents,
                                         final int numberOfColumns)
-      throws IOException
+      throws IOException, ReportProcessingException
   {
     if (numberOfColumns <= 1)
     {
@@ -353,8 +353,11 @@
     attrs.setAttribute(OfficeNamespaces.TEXT_NS, "style-name", 
generateSectionStyle(numberOfColumns));
     attrs.setAttribute(OfficeNamespaces.TEXT_NS, "name", 
sectionNames.generateName("Section"));
     writer.writeTag(OfficeNamespaces.TEXT_NS, "section", attrs, 
XmlWriterSupport.OPEN);
-    writer.writeText(contents);
-    writer.writeText(contents);
+    for (int i = 0; i < numberOfColumns; i++)
+    {
+      writer.writeStream(contents.getXmlAsReader());
+    }
+
     writer.writeCloseTag();
     return finishBuffering();
   }
@@ -1021,37 +1024,37 @@
     if (role == OfficeDocumentReportTarget.ROLE_PAGE_HEADER)
     {
       final PageContext pageContext = getCurrentContext();
-      pageContext.setHeader(applyColumnsToPageBand(finishBuffering(), 
pageContext.getActiveColumns()), result);
+      pageContext.setHeader(applyColumnsToPageBand(finishBuffering(), 
pageContext.getActiveColumns()).getXmlBuffer(), result);
     }
     else if (role == OfficeDocumentReportTarget.ROLE_PAGE_FOOTER)
     {
       final PageContext pageContext = getCurrentContext();
-      pageContext.setFooter(applyColumnsToPageBand(finishBuffering(), 
pageContext.getActiveColumns()), result);
+      pageContext.setFooter(applyColumnsToPageBand(finishBuffering(), 
pageContext.getActiveColumns()).getXmlBuffer(), result);
     }
     else if (role == OfficeDocumentReportTarget.ROLE_REPEATING_GROUP_HEADER)
     {
       final PageContext pageContext = getCurrentContext();
-      pageContext.setHeader(applyColumnsToPageBand(finishBuffering(), 
pageContext.getActiveColumns()), result);
+      pageContext.setHeader(applyColumnsToPageBand(finishBuffering(), 
pageContext.getActiveColumns()).getXmlBuffer(), result);
     }
     else if (role == OfficeDocumentReportTarget.ROLE_REPEATING_GROUP_FOOTER)
     {
       final PageContext pageContext = getCurrentContext();
-      pageContext.setFooter(applyColumnsToPageBand(finishBuffering(), 
pageContext.getActiveColumns()), result);
+      pageContext.setFooter(applyColumnsToPageBand(finishBuffering(), 
pageContext.getActiveColumns()).getXmlBuffer(), result);
     }
     else if (role == OfficeDocumentReportTarget.ROLE_VARIABLES)
     {
       if (variables == null)
       {
-        variables = finishBuffering();
+        variables = finishBuffering().getXmlBuffer();
       }
       else
       {
-        variables += finishBuffering();
+        variables += finishBuffering().getXmlBuffer();
       }
     }
     else if (role == OfficeDocumentReportTarget.ROLE_GROUP_HEADER)
     {
-      final String headerText = finishBuffering();
+      final String headerText = finishBuffering().getXmlBuffer();
       final int iterationCount = 
getGroupContext().getParent().getIterationCount();
       final boolean repeat = 
"true".equals(attrs.getAttribute(OfficeNamespaces.OOREPORT_NS, 
"repeat-section"));
       if (repeat == false || iterationCount > 0)
@@ -1061,7 +1064,7 @@
     }
     else if (role == OfficeDocumentReportTarget.ROLE_GROUP_FOOTER)
     {
-      final String footerText = finishBuffering();
+      final String footerText = finishBuffering().getXmlBuffer();
       // how do we detect whether this is the last group footer?
       getXmlWriter().writeText(footerText);
     }
@@ -1212,7 +1215,7 @@
       throws IOException, DataSourceException, ReportProcessingException
   {
     finishSection();
-    final String bodyText = finishBuffering();
+    final BufferState bodyText = finishBuffering();
     final XmlWriter writer = getXmlWriter();
 
     final Map definedMappings = variablesDeclarations.getDefinedMappings();
@@ -1231,7 +1234,7 @@
       writer.writeCloseTag();
     }
 
-    writer.writeText(bodyText);
+    writer.writeStream(bodyText.getXmlAsReader());
     writer.setLineEmpty(true);
     writer.writeCloseTag();
   }

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

File [changed]: stylemapper.xml
Url: 
http://dba.openoffice.org/source/browse/dba/reportdesign/java/com/sun/star/report/pentaho/styles/stylemapper.xml?r1=1.1.2.1&r2=1.1.2.2
Delta lines:  +3 -9
-------------------
--- stylemapper.xml     2007-05-09 12:39:39+0000        1.1.2.1
+++ stylemapper.xml     2007-05-15 06:50:25+0000        1.1.2.2
@@ -5,9 +5,9 @@
 
                $RCSfile: stylemapper.xml,v $
 
-               $Revision: 1.1.2.1 $
+               $Revision: 1.1.2.2 $
 
-               last change: $Author: oj $ $Date: 2007/05/09 12:39:39 $
+               last change: $Author: oj $ $Date: 2007/05/15 06:50:25 $
 
                The Contents of this file are made available subject to
                the terms of GNU Lesser General Public License Version 2.1.
@@ -107,10 +107,4 @@
            attribute-name="style-name"
            style-family="table-cell"
            type="styleNameRef"/>
-  <mapping 
element-namespace="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
-           element-name="custom-shape"
-           
attribute-namespace="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
-           attribute-name="style-name"
-           style-family="graphic"
-           type="styleNameRef"/>
 </style-mapper-definition>




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

Reply via email to