summaryrefslogtreecommitdiff
path: root/reportbuilder/java/com/sun/star/report/pentaho/output/StylesWriter.java
diff options
context:
space:
mode:
authorOliver Bolte <obo@openoffice.org>2009-03-04 15:27:10 +0000
committerOliver Bolte <obo@openoffice.org>2009-03-04 15:27:10 +0000
commit9544c14f4a931d8d8b2e66a6cb87fb53d4505cd4 (patch)
tree29b05df340e2c19c9e60947d63bf7b425cfb95c2 /reportbuilder/java/com/sun/star/report/pentaho/output/StylesWriter.java
parent4f4fe6aa7203aac35a774108f4880553df5b93a4 (diff)
CWS-TOOLING: integrate CWS rptfix04
2009-02-23 01:59:54 +0100 rene r268341 : #i10000# fix system-jfreereport build 2009-02-13 10:17:16 +0100 oj r267696 : #i98549# integrate zip form pentaho package 2009-02-03 14:48:34 +0100 oj r267330 : set formula locale to doc locale 2009-02-03 14:45:54 +0100 oj r267329 : set formula locale to doc locale 2009-02-03 11:50:03 +0100 oj r267311 : set formula locale to doc locale 2009-02-03 08:55:02 +0100 oj r267297 : unix line ends 2009-01-28 11:21:24 +0100 rene r267043 : #i98549# s/DESIGN/BUILDER/ also for Sun 2009-01-27 17:17:50 +0100 rene r267012 : merge builfix from trunk 2009-01-27 14:16:30 +0100 rene r266991 : #i10000# fix rebase which left out the whole changes in former config_office; sync variable names (s/LIB_//) and some other things 2009-01-27 10:01:09 +0100 oj r266959 : CWS-TOOLING: rebase CWS rptfix04 to trunk@266944 (milestone: DEV300:m40) 2009-01-27 08:00:16 +0100 oj r266951 : conflict in mergeinfo 2009-01-26 12:23:03 +0100 oj r266914 : #i98383# fix grouping 2009-01-23 22:03:03 +0100 rene r266852 : fix --enable-report-builder description 2009-01-23 10:37:27 +0100 oj r266778 : set escape processing when set at query 2009-01-23 09:17:16 +0100 fs r266770 : add CWS name to version 2009-01-21 13:57:35 +0100 oj r266669 : merge for build bots 2009-01-20 09:07:24 +0100 oj r266552 : CWS-TOOLING: rebase CWS rptfix04 to trunk@266428 (milestone: DEV300:m39) 2009-01-20 08:34:16 +0100 oj r266551 : rebase 2009-01-20 08:33:59 +0100 oj r266550 : rebase 2009-01-20 08:32:50 +0100 oj r266549 : rebase 2009-01-20 08:30:13 +0100 oj r266548 : rebase 2009-01-20 08:29:30 +0100 oj r266547 : rebase 2009-01-20 08:22:33 +0100 oj r266546 : merge short cuts from dba31g 2009-01-19 21:04:08 +0100 rene r266525 : #i10000# we need officecfg for component-update.dtd 2009-01-19 21:01:26 +0100 rene r266524 : #i10000# fix import 2009-01-19 20:26:20 +0100 rene r266523 : #i10000# remove svn conflicts markers; fix build 2009-01-19 14:23:56 +0100 rene r266496 : libbase depends on apache-commons.. 2009-01-19 14:00:42 +0100 oj r266495 : merge from m39 2009-01-19 12:39:00 +0100 oj r266489 : CWS-TOOLING: rebase CWS rptfix04 to trunk@266428 (milestone: DEV300:m39) 2009-01-16 11:47:04 +0100 oj r266410 : #i97560# add , between expressions 2009-01-09 17:11:38 +0100 rene r266103 : don't show "checking which Apache commons-* libs to use" when we neither build the wiki editor nor the SRB 2009-01-09 16:48:02 +0100 rene r266099 : #i10000# reportbuilder needs apache-commons 2009-01-09 15:43:35 +0100 oj r266093 : use of new nspaces 2009-01-09 15:41:34 +0100 oj r266092 : use of new nspaces 2009-01-09 14:44:15 +0100 rene r266088 : fix typo/description 2009-01-09 12:48:51 +0100 rene r266074 : #i10000# fix install 2009-01-09 11:52:53 +0100 rene r266070 : #i10000# more build fixes 2009-01-09 10:53:13 +0100 rene r266062 : #i10000# ENABLE_REPORTBUILDER also in set_soenv.in, fix typo 2009-01-09 10:40:24 +0100 rene r266060 : #i10000# configure fix for new reportbuilder module, typo fix at libfonts 2009-01-09 10:01:52 +0100 rene r266055 : #i10000# adapt to current configure.in 2009-01-09 09:59:32 +0100 oj r266054 : add new pentaho jars 2009-01-09 09:47:54 +0100 oj r266049 : merge changes from DEV300_m39 2009-01-09 09:14:08 +0100 oj r266048 : merge from DEV300_m39 2009-01-09 08:28:43 +0100 oj r266045 : merge changes from dba31g 2009-01-09 07:58:10 +0100 oj r266044 : replace JCOMMON with LIB 2009-01-08 13:42:24 +0100 oj r266005 : move ext to reportbuilder 2009-01-08 13:41:38 +0100 oj r266004 : add dep for license 2009-01-08 13:27:56 +0100 oj r266001 : new module for Sun report Builder extension 2009-01-07 12:58:13 +0100 oj r265960 : CWS-TOOLING: rebase CWS rptfix04 to trunk@265758 (milestone: DEV300:m38) 2008-12-15 13:47:18 +0100 oj r265481 : new pentaho resources 2008-12-15 10:04:01 +0100 oj r265462 : integrate new pentaho sources 2008-12-15 10:02:54 +0100 oj r265461 : #i96888# fix date time function 2008-12-12 09:23:29 +0100 oj r265389 : #97174# check of res < 0 removed 2008-12-12 09:15:54 +0100 oj r265388 : #i9716# fix for DayFunction 2008-12-11 12:24:24 +0100 oj r265281 : integrate new pentaho sources 2008-12-11 11:49:16 +0100 oj r265273 : integrate new pentaho sources 2008-12-11 09:34:07 +0100 oj r265248 : integrate new pentaho sources 2008-12-10 18:58:06 +0100 oj r265227 : introduce new pentaho sources 2008-12-10 18:56:43 +0100 oj r265226 : introduce new pentaho sources 2008-12-10 18:54:26 +0100 oj r265225 : introduce new pentaho sources 2008-12-10 18:42:59 +0100 oj r265221 : introduce new pentaho sources 2008-12-10 17:24:23 +0100 oj r265212 : introduce new pentaho sources 2008-12-10 17:24:07 +0100 oj r265211 : new pentaho sources 2008-12-10 17:23:00 +0100 oj r265210 : introduce new pentaho sources
Diffstat (limited to 'reportbuilder/java/com/sun/star/report/pentaho/output/StylesWriter.java')
-rw-r--r--reportbuilder/java/com/sun/star/report/pentaho/output/StylesWriter.java374
1 files changed, 374 insertions, 0 deletions
diff --git a/reportbuilder/java/com/sun/star/report/pentaho/output/StylesWriter.java b/reportbuilder/java/com/sun/star/report/pentaho/output/StylesWriter.java
new file mode 100644
index 000000000000..4300d44defd3
--- /dev/null
+++ b/reportbuilder/java/com/sun/star/report/pentaho/output/StylesWriter.java
@@ -0,0 +1,374 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: StylesWriter.java,v $
+ * $Revision: 1.4 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+
+package com.sun.star.report.pentaho.output;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.TreeMap;
+
+import com.sun.star.report.pentaho.OfficeNamespaces;
+import com.sun.star.report.pentaho.model.FontFaceDeclsSection;
+import com.sun.star.report.pentaho.model.FontFaceElement;
+import com.sun.star.report.pentaho.model.OfficeStyle;
+import com.sun.star.report.pentaho.model.OfficeStyles;
+import com.sun.star.report.pentaho.model.OfficeStylesCollection;
+import com.sun.star.report.pentaho.model.OfficeMasterStyles;
+import com.sun.star.report.pentaho.model.OfficeMasterPage;
+import com.sun.star.report.pentaho.model.DataStyle;
+import com.sun.star.report.pentaho.model.PageLayout;
+import com.sun.star.report.pentaho.model.RawText;
+import org.jfree.layouting.namespace.Namespaces;
+import org.jfree.layouting.util.AttributeMap;
+import org.jfree.report.JFreeReportBoot;
+import org.jfree.report.JFreeReportInfo;
+import org.jfree.report.ReportProcessingException;
+import org.jfree.report.structure.Element;
+import org.jfree.report.structure.Node;
+import org.jfree.report.structure.Section;
+import org.jfree.report.structure.StaticText;
+import org.pentaho.reporting.libraries.xmlns.common.AttributeList;
+import org.pentaho.reporting.libraries.xmlns.writer.DefaultTagDescription;
+import org.pentaho.reporting.libraries.xmlns.writer.XmlWriter;
+import org.pentaho.reporting.libraries.xmlns.writer.XmlWriterSupport;
+
+/**
+ * This class writes the style collection into a 'styles.xml' document.
+ *
+ * @author Thomas Morgner
+ * @since 09.03.2007
+ */
+public class StylesWriter
+{
+ private final XmlWriter xmlWriter;
+ private final boolean writeOpeningTag;
+
+ public StylesWriter(final Writer writer)
+ {
+ final DefaultTagDescription tagDescription = new DefaultTagDescription();
+ tagDescription.configure (JFreeReportBoot.getInstance().getGlobalConfig(),
+ OfficeDocumentReportTarget.TAG_DEF_PREFIX);
+
+ this.xmlWriter = new XmlWriter(writer, tagDescription);
+ this.xmlWriter.setAlwaysAddNamespace(true);
+ this.writeOpeningTag = true;
+ }
+
+ public StylesWriter(final XmlWriter xmlWriter)
+ {
+ this.xmlWriter = xmlWriter;
+ this.writeOpeningTag = false;
+ }
+
+ public void writeContentStyles (final OfficeStylesCollection predefined,
+ final OfficeStylesCollection globals)
+ throws IOException, ReportProcessingException
+ {
+ writeFontFaces(new OfficeStylesCollection[] { globals });
+ writeAutomaticStylesSection(new OfficeStylesCollection[] { globals });
+ }
+
+ public void writeGlobalStyles (final OfficeStylesCollection predefined,
+ final OfficeStylesCollection globals)
+ throws IOException, ReportProcessingException
+ {
+ if (writeOpeningTag)
+ {
+ performWriteRootTag();
+ }
+
+ writeFontFaces(new OfficeStylesCollection[] { globals });
+ writeAutomaticStylesSection(new OfficeStylesCollection[] { globals });
+ writeCommonStylesSection(new OfficeStylesCollection[] { globals });
+ writeMasterStylesSection(new OfficeStylesCollection[] { globals });
+
+ if (writeOpeningTag)
+ {
+ xmlWriter.writeCloseTag();
+ }
+ }
+
+ private void writeMasterStylesSection(final OfficeStylesCollection[] osc)
+ throws IOException
+ {
+ xmlWriter.writeTag
+ (OfficeNamespaces.OFFICE_NS, "master-styles", XmlWriterSupport.OPEN);
+ for (int sci = 0; sci < osc.length; sci++)
+ {
+ final OfficeStylesCollection collection = osc[sci];
+ final OfficeMasterStyles officeStyles = collection.getMasterStyles();
+ final OfficeMasterPage[] officeMasterPages = officeStyles.getAllMasterPages();
+ for (int i = 0; i < officeMasterPages.length; i++)
+ {
+ final OfficeMasterPage masterPage = officeMasterPages[i];
+ writeSection(masterPage);
+ }
+
+ writeSectionChilds(officeStyles.getOtherNodes().getNodeArray());
+ }
+
+ xmlWriter.writeCloseTag();
+ }
+
+ private void writeCommonStylesSection(final OfficeStylesCollection[] osc)
+ throws IOException
+ {
+ xmlWriter.writeTag
+ (OfficeNamespaces.OFFICE_NS, "styles", XmlWriterSupport.OPEN);
+
+ for (int sci = 0; sci < osc.length; sci++)
+ {
+ final OfficeStylesCollection collection = osc[sci];
+ final OfficeStyles officeStyles = collection.getCommonStyles();
+ writeStyles(officeStyles);
+ }
+
+ xmlWriter.writeCloseTag();
+ }
+
+ private void writeAutomaticStylesSection(final OfficeStylesCollection[] osc)
+ throws IOException
+ {
+ xmlWriter.writeTag
+ (OfficeNamespaces.OFFICE_NS, "automatic-styles", XmlWriterSupport.OPEN);
+ for (int sci = 0; sci < osc.length; sci++)
+ {
+ final OfficeStylesCollection collection = osc[sci];
+ final OfficeStyles officeStyles = collection.getAutomaticStyles();
+ writeStyles(officeStyles);
+ }
+
+ xmlWriter.writeCloseTag();
+ }
+
+ private void writeFontFaces(final OfficeStylesCollection[] osc)
+ throws IOException
+ {
+ xmlWriter.writeTag
+ (OfficeNamespaces.OFFICE_NS, "font-face-decls", XmlWriterSupport.OPEN);
+
+ final TreeMap fontFaces = new TreeMap();
+ for (int sci = 0; sci < osc.length; sci++)
+ {
+ final OfficeStylesCollection collection = osc[sci];
+ final FontFaceDeclsSection fontFaceDecls = collection.getFontFaceDecls();
+ final FontFaceElement[] fontFaceElements = fontFaceDecls.getAllFontFaces();
+ for (int i = 0; i < fontFaceElements.length; i++)
+ {
+ final FontFaceElement element = fontFaceElements[i];
+ fontFaces.put (element.getStyleName(), element);
+ }
+ }
+
+ final Iterator values = fontFaces.values().iterator();
+ while (values.hasNext())
+ {
+ final FontFaceElement element = (FontFaceElement) values.next();
+ writeElement(element);
+ }
+
+ xmlWriter.writeCloseTag();
+ }
+
+ private void writeStyles (final OfficeStyles styles)
+ throws IOException
+ {
+ final OfficeStyle[] allStyles = styles.getAllStyles();
+ for (int i = 0; i < allStyles.length; i++)
+ {
+ final OfficeStyle style = allStyles[i];
+ writeSection(style);
+ }
+
+ final DataStyle[] allDataStyles = styles.getAllDataStyles();
+ for (int i = 0; i < allDataStyles.length; i++)
+ {
+ final DataStyle style = allDataStyles[i];
+ writeSection(style);
+ }
+
+ final PageLayout[] allPageStyles = styles.getAllPageStyles();
+ for (int i = 0; i < allPageStyles.length; i++)
+ {
+ final PageLayout style = allPageStyles[i];
+ writeSection(style);
+ }
+
+ writeSectionChilds(styles.getOtherStyles());
+ }
+
+ private void writeElement (final Element element)
+ throws IOException
+ {
+ final String type = element.getType();
+ final String namespace = element.getNamespace();
+ final AttributeList attrList = buildAttributeList(element.getAttributeMap());
+ xmlWriter.writeTag(namespace, type, attrList, XmlWriterSupport.CLOSE);
+ }
+
+ private void writeSection (final Section section)
+ throws IOException
+ {
+ final String type = section.getType();
+ final String namespace = section.getNamespace();
+ final AttributeList attrList = buildAttributeList(section.getAttributeMap());
+ if (section.getNodeCount() == 0)
+ {
+ xmlWriter.writeTag(namespace, type, attrList, XmlWriterSupport.CLOSE);
+ return;
+ }
+
+ xmlWriter.writeTag(namespace, type, attrList, XmlWriterSupport.OPEN);
+ writeSectionChilds(section.getNodeArray());
+
+ xmlWriter.writeCloseTag();
+ }
+
+ private void writeSectionChilds(final Node[] nodes)
+ throws IOException
+ {
+ for (int i = 0; i < nodes.length; i++)
+ {
+ final Node node = nodes[i];
+ if (node instanceof Section)
+ {
+ writeSection((Section) node);
+ }
+ else if (node instanceof Element)
+ {
+ writeElement((Element) node);
+ }
+ else if (node instanceof RawText)
+ {
+ final RawText text = (RawText) node;
+ xmlWriter.writeText(text.getText());
+ }
+ else if (node instanceof StaticText)
+ {
+ final StaticText text = (StaticText) node;
+ xmlWriter.writeTextNormalized(text.getText(), false);
+ }
+ }
+ }
+
+ protected AttributeList buildAttributeList(final AttributeMap attrs)
+ {
+ final AttributeList attrList = new AttributeList();
+ final String[] namespaces = attrs.getNameSpaces();
+ for (int i = 0; i < namespaces.length; i++)
+ {
+ final String attrNamespace = namespaces[i];
+ if (isFilteredNamespace(attrNamespace))
+ {
+ continue;
+ }
+
+ final Map localAttributes = attrs.getAttributes(attrNamespace);
+ final Iterator entries = localAttributes.entrySet().iterator();
+ while (entries.hasNext())
+ {
+ final Map.Entry entry = (Map.Entry) entries.next();
+ final String key = String.valueOf(entry.getKey());
+ attrList.setAttribute(attrNamespace, key, String.valueOf(entry.getValue()));
+ }
+ }
+ return attrList;
+ }
+
+ protected boolean isFilteredNamespace(final String namespace)
+ {
+ if (Namespaces.LIBLAYOUT_NAMESPACE.equals(namespace))
+ {
+ return true;
+ }
+ if (JFreeReportInfo.REPORT_NAMESPACE.equals(namespace))
+ {
+ return true;
+ }
+ if (JFreeReportInfo.COMPATIBILITY_NAMESPACE.equals(namespace))
+ {
+ return true;
+ }
+ if (OfficeNamespaces.OOREPORT_NS.equals(namespace))
+ {
+ return true;
+ }
+ return false;
+ }
+
+ private void performWriteRootTag()
+ throws IOException
+ {
+ final AttributeList rootAttributes = new AttributeList();
+ rootAttributes.addNamespaceDeclaration("office",
+ OfficeNamespaces.OFFICE_NS);
+ rootAttributes.addNamespaceDeclaration("style", OfficeNamespaces.STYLE_NS);
+ rootAttributes.addNamespaceDeclaration("text", OfficeNamespaces.TEXT_NS);
+ rootAttributes.addNamespaceDeclaration("table", OfficeNamespaces.TABLE_NS);
+ rootAttributes.addNamespaceDeclaration("draw", OfficeNamespaces.DRAWING_NS);
+ rootAttributes.addNamespaceDeclaration("fo", OfficeNamespaces.FO_NS);
+ rootAttributes.addNamespaceDeclaration("xlink", OfficeNamespaces.XLINK_NS);
+ rootAttributes.addNamespaceDeclaration("dc", OfficeNamespaces.PURL_NS);
+ rootAttributes.addNamespaceDeclaration("meta", OfficeNamespaces.META_NS);
+ rootAttributes.addNamespaceDeclaration("number",
+ OfficeNamespaces.DATASTYLE_NS);
+ rootAttributes.addNamespaceDeclaration("svg", OfficeNamespaces.SVG_NS);
+ rootAttributes.addNamespaceDeclaration("chart", OfficeNamespaces.CHART_NS);
+ rootAttributes.addNamespaceDeclaration("dr3d", OfficeNamespaces.DR3D_NS);
+ rootAttributes.addNamespaceDeclaration("math", OfficeNamespaces.MATHML_NS);
+ rootAttributes.addNamespaceDeclaration("form", OfficeNamespaces.FORM_NS);
+ rootAttributes.addNamespaceDeclaration("script",
+ OfficeNamespaces.SCRIPT_NS);
+ rootAttributes.addNamespaceDeclaration("ooo", OfficeNamespaces.OO2004_NS);
+ rootAttributes.addNamespaceDeclaration("ooow", OfficeNamespaces.OOW2004_NS);
+ rootAttributes.addNamespaceDeclaration("oooc", OfficeNamespaces.OOC2004_NS);
+ rootAttributes.addNamespaceDeclaration("dom",
+ OfficeNamespaces.XML_EVENT_NS);
+ rootAttributes.addNamespaceDeclaration("xforms",
+ OfficeNamespaces.XFORMS_NS);
+ rootAttributes.addNamespaceDeclaration("xsd", OfficeNamespaces.XSD_NS);
+ rootAttributes.addNamespaceDeclaration("xsi", OfficeNamespaces.XSI_NS);
+ rootAttributes.setAttribute(OfficeNamespaces.OFFICE_NS, "version", "1.0");
+
+ this.xmlWriter.writeXmlDeclaration("UTF-8");
+ this.xmlWriter.writeTag(OfficeNamespaces.OFFICE_NS,
+ "document-content", rootAttributes, XmlWriterSupport.OPEN);
+ }
+
+ public void close()
+ throws IOException
+ {
+ xmlWriter.close();
+ }
+
+}