diff options
Diffstat (limited to 'reportbuilder/java/org/libreoffice/report/pentaho/parser')
43 files changed, 4130 insertions, 0 deletions
diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/ElementReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/ElementReadHandler.java new file mode 100644 index 000000000..fdec734c0 --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/ElementReadHandler.java @@ -0,0 +1,78 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser; + +import org.jfree.report.structure.Element; + +import org.pentaho.reporting.libraries.xmlns.parser.AbstractXmlReadHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * Creation-Date: 03.07.2006, 14:22:34 + * + */ +public abstract class ElementReadHandler extends AbstractXmlReadHandler +{ + + /** + * Starts parsing. + * + * @param attrs the attributes. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void startParsing(final Attributes attrs) throws SAXException + { + final Element element = getElement(); + copyElementType(element); + copyAttributes(attrs, element); + } + + protected void copyElementType(final Element element) + { + element.setType(getTagName()); + element.setNamespace(getUri()); + } + + protected void copyAttributes(final Attributes attrs, final Element element) + { + final int length = attrs.getLength(); + for (int i = 0; i < length; i++) + { + final String value = attrs.getValue(i); + final String namespace = attrs.getURI(i); + final String attr = attrs.getLocalName(i); + element.setAttribute(namespace, attr, value); + } + } + + /** + * Returns the object for this element or null, if this element does not + * create an object. + * + * @return the object. + */ + public Object getObject() throws SAXException + { + return getElement(); + } + + public abstract Element getElement(); +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/OfficeDocumentXmlResourceFactory.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/OfficeDocumentXmlResourceFactory.java new file mode 100644 index 000000000..5322e52ef --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/OfficeDocumentXmlResourceFactory.java @@ -0,0 +1,39 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser; + +import org.libreoffice.report.pentaho.model.OfficeDocument; + +import org.jfree.report.modules.factories.report.base.JFreeReportXmlResourceFactory; + +/** + * A LibLoader resource factory for OfficeDocument objects. OfficeDocuments are + * JFreeReport instances which have some additional properties. + * + * @since 09.03.2007 + */ +@SuppressWarnings("ucd") +public class OfficeDocumentXmlResourceFactory extends JFreeReportXmlResourceFactory +{ + + @Override + public Class getFactoryType() + { + return OfficeDocument.class; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/OfficeStylesXmlResourceFactory.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/OfficeStylesXmlResourceFactory.java new file mode 100644 index 000000000..8a12da80c --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/OfficeStylesXmlResourceFactory.java @@ -0,0 +1,47 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser; + +import org.libreoffice.report.pentaho.model.OfficeStylesCollection; + +import org.jfree.report.JFreeReportBoot; + +import org.pentaho.reporting.libraries.base.config.Configuration; +import org.pentaho.reporting.libraries.xmlns.parser.AbstractXmlResourceFactory; + +/** + * A LibLoader resource factory for loading an OfficeStyles-collection. This + * implementation is meant to parse the 'styles.xml' file. + * + * @since 09.03.2007 + */ +@SuppressWarnings("ucd") +public class OfficeStylesXmlResourceFactory extends AbstractXmlResourceFactory +{ + + @Override + protected Configuration getConfiguration() + { + return JFreeReportBoot.getInstance().getGlobalConfig(); + } + + public Class getFactoryType() + { + return OfficeStylesCollection.class; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/StarStyleXmlFactoryModule.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/StarStyleXmlFactoryModule.java new file mode 100644 index 000000000..7c7b70533 --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/StarStyleXmlFactoryModule.java @@ -0,0 +1,50 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser; + +import org.libreoffice.report.pentaho.OfficeNamespaces; +import org.libreoffice.report.pentaho.parser.office.DocumentStylesReadHandler; + +import org.pentaho.reporting.libraries.xmlns.parser.XmlDocumentInfo; +import org.pentaho.reporting.libraries.xmlns.parser.XmlFactoryModule; +import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; + +@SuppressWarnings("ucd") +public class StarStyleXmlFactoryModule implements XmlFactoryModule +{ + + public XmlReadHandler createReadHandler(final XmlDocumentInfo documentInfo) + { + return new DocumentStylesReadHandler(); + } + + public int getDocumentSupport(final XmlDocumentInfo documentInfo) + { + final String rootNamespace = documentInfo.getRootElementNameSpace(); + if (OfficeNamespaces.OFFICE_NS.equals(rootNamespace) && "document-styles".equals(documentInfo.getRootElement())) + { + return XmlFactoryModule.RECOGNIZED_BY_NAMESPACE; + } + return XmlFactoryModule.NOT_RECOGNIZED; + } + + public String getDefaultNamespace(final XmlDocumentInfo documentInfo) + { + return null; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/StarXmlFactoryModule.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/StarXmlFactoryModule.java new file mode 100644 index 000000000..ef81b23ad --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/StarXmlFactoryModule.java @@ -0,0 +1,50 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser; + +import org.libreoffice.report.pentaho.OfficeNamespaces; +import org.libreoffice.report.pentaho.parser.office.DocumentContentReadHandler; + +import org.pentaho.reporting.libraries.xmlns.parser.XmlDocumentInfo; +import org.pentaho.reporting.libraries.xmlns.parser.XmlFactoryModule; +import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; + +@SuppressWarnings("ucd") +public class StarXmlFactoryModule implements XmlFactoryModule +{ + + public XmlReadHandler createReadHandler(final XmlDocumentInfo documentInfo) + { + return new DocumentContentReadHandler(); + } + + public int getDocumentSupport(final XmlDocumentInfo documentInfo) + { + final String rootNamespace = documentInfo.getRootElementNameSpace(); + if (OfficeNamespaces.OFFICE_NS.equals(rootNamespace) && ("document-content".equals(documentInfo.getRootElement()) || "document".equals(documentInfo.getRootElement()))) + { + return XmlFactoryModule.RECOGNIZED_BY_NAMESPACE; + } + return XmlFactoryModule.NOT_RECOGNIZED; + } + + public String getDefaultNamespace(final XmlDocumentInfo documentInfo) + { + return null; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/chart/ChartReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/chart/ChartReadHandler.java new file mode 100644 index 000000000..4956dfb7a --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/chart/ChartReadHandler.java @@ -0,0 +1,102 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.chart; + +import org.libreoffice.report.pentaho.OfficeNamespaces; +import org.libreoffice.report.pentaho.parser.ElementReadHandler; +import org.libreoffice.report.pentaho.parser.rpt.DetailRootTableReadHandler; +import org.libreoffice.report.pentaho.parser.rpt.ReportReadHandler; +import org.libreoffice.report.pentaho.parser.text.TextContentReadHandler; + +import java.util.ArrayList; +import java.util.List; + +import org.jfree.report.structure.Element; +import org.jfree.report.structure.Section; + +import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + + +public class ChartReadHandler extends ElementReadHandler +{ + + private final Section element; + private final List<ElementReadHandler> children; + private final ReportReadHandler reportHandler; + + public ChartReadHandler(ReportReadHandler reportHandler) + { + this.reportHandler = reportHandler; + children = new ArrayList<ElementReadHandler>(); + element = new Section(); + } + + /** + * Returns the handler for a child element. + * + * @param tagName the tag name. + * @param atts the attributes. + * @return the handler or null, if the tagname is invalid. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected XmlReadHandler getHandlerForChild(final String uri, + final String tagName, + final Attributes atts) + throws SAXException + { + if ("detail".equals(tagName)) + { + final DetailRootTableReadHandler detail = new DetailRootTableReadHandler(); + reportHandler.setDetail(detail); + return detail; + } + else if ("p".equals(tagName) && OfficeNamespaces.TEXT_NS.equals(uri)) + { + final TextContentReadHandler readHandler = new TextContentReadHandler(); + children.add(readHandler); + return readHandler; + } + final ChartReadHandler erh = new ChartReadHandler(reportHandler); + children.add(erh); + return erh; + } + + /** + * Done parsing. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void doneParsing() throws SAXException + { + for (ElementReadHandler handler : children) + { + element.addNode(handler.getElement()); + } + } + + @Override + public Element getElement() + { + return element; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/data/DataStyleReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/data/DataStyleReadHandler.java new file mode 100644 index 000000000..a3ef5963f --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/data/DataStyleReadHandler.java @@ -0,0 +1,125 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.data; + +import org.libreoffice.report.pentaho.OfficeNamespaces; +import org.libreoffice.report.pentaho.model.DataStyle; +import org.libreoffice.report.pentaho.parser.ElementReadHandler; + +import java.util.ArrayList; +import java.util.List; + +import org.jfree.report.structure.Element; +import org.jfree.report.structure.StaticText; + +import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + + +public class DataStyleReadHandler extends ElementReadHandler +{ + + private final DataStyle dataStyle; + private final List<Object> children; + private final boolean hasCData; + + public DataStyleReadHandler(final boolean hasCData) + { + this.hasCData = hasCData; + this.dataStyle = new DataStyle(); + this.children = new ArrayList<Object>(); + } + + /** + * Returns the handler for a child element. + * + * @param tagName the tag name. + * @param atts the attributes. + * @return the handler or null, if the tagname is invalid. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected XmlReadHandler getHandlerForChild(final String uri, + final String tagName, + final Attributes atts) + throws SAXException + { + if (OfficeNamespaces.DATASTYLE_NS.equals(uri) || OfficeNamespaces.STYLE_NS.equals(uri)) + { + final DataStyleReadHandler xrh = new DataStyleReadHandler("text".equals(tagName) || "currency-symbol".equals(tagName) || "embedded-text".equals(tagName)); + children.add(xrh); + return xrh; + } + + return null; + } + + /** + * This method is called to process the character data between element tags. + * + * @param ch the character buffer. + * @param start the start index. + * @param length the length. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + public void characters(final char[] ch, final int start, final int length) + throws SAXException + { + if (hasCData) + { + children.add(new StaticText(new String(ch, start, length))); + } + } + + /** + * Done parsing. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void doneParsing() throws SAXException + { + for (int i = 0; i < children.size(); i++) + { + final Object o = children.get(i); + if (o instanceof ElementReadHandler) + { + final ElementReadHandler handler = (ElementReadHandler) o; + dataStyle.addNode(handler.getElement()); + } + else if (o instanceof StaticText) + { + dataStyle.addNode((StaticText) o); + } + } + } + + public DataStyle getDataStyle() + { + return dataStyle; + } + + @Override + public Element getElement() + { + return dataStyle; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/draw/ObjectOleReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/draw/ObjectOleReadHandler.java new file mode 100644 index 000000000..1b7e8cb73 --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/draw/ObjectOleReadHandler.java @@ -0,0 +1,77 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.draw; + +import org.libreoffice.report.pentaho.OfficeNamespaces; +import org.libreoffice.report.pentaho.model.ObjectOleElement; +import org.libreoffice.report.pentaho.parser.ElementReadHandler; + +import org.jfree.report.structure.Element; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * + */ +public class ObjectOleReadHandler extends ElementReadHandler +{ + + private static final String RPT_CHART_CLASS_ID = "80243D39-6741-46C5-926E-069164FF87BB"; + private static final String OOO_CHART_CLASS_ID = "12DCAE26-281F-416F-A234-C3086127382E"; + private final ObjectOleElement element; + + public ObjectOleReadHandler(final ObjectOleElement element) + { + this.element = element; + } + + /** + * Starts parsing. + * + * @param attrs the attributes. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void startParsing(final Attributes attrs) throws SAXException + { + super.startParsing(attrs); + + final String url = attrs.getValue(OfficeNamespaces.XLINK_NS, "href"); + if (url != null) + { + element.setUrl(url); + } + + String classid = attrs.getValue(OfficeNamespaces.DRAWING_NS, "class-id"); + if (classid != null) + { + if (classid.equalsIgnoreCase(RPT_CHART_CLASS_ID)) + { + classid = OOO_CHART_CLASS_ID; + } + element.setClassId(classid); + } + } + + @Override + public Element getElement() + { + return element; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/office/BodyReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/office/BodyReadHandler.java new file mode 100644 index 000000000..d7d7fafb8 --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/office/BodyReadHandler.java @@ -0,0 +1,85 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.office; + +import org.libreoffice.report.pentaho.OfficeNamespaces; +import org.libreoffice.report.pentaho.parser.ElementReadHandler; +import org.libreoffice.report.pentaho.parser.rpt.ReportReadHandler; + +import org.jfree.report.structure.Element; +import org.jfree.report.structure.Section; + +import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +public class BodyReadHandler extends ElementReadHandler +{ + + private ElementReadHandler reportReadHandler; + private final Section body; + + public BodyReadHandler() + { + body = new Section(); + } + + /** + * Returns the handler for a child element. + * + * @param tagName the tag name. + * @param atts the attributes. + * @return the handler or null, if the tagname is invalid. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected XmlReadHandler getHandlerForChild(final String uri, final String tagName, + final Attributes atts) + throws SAXException + { + if (OfficeNamespaces.OFFICE_NS.equals(uri) && "report".equals(tagName)) + { + reportReadHandler = new ReportReadHandler(); + return reportReadHandler; + } + + return null; + } + + /** + * Done parsing. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void doneParsing() throws SAXException + { + if (reportReadHandler != null) + { + body.addNode(reportReadHandler.getElement()); + } + } + + @Override + public Element getElement() + { + return body; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/office/DocumentContentReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/office/DocumentContentReadHandler.java new file mode 100644 index 000000000..65a48252e --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/office/DocumentContentReadHandler.java @@ -0,0 +1,225 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.office; + +import org.libreoffice.report.pentaho.OfficeNamespaces; +import org.libreoffice.report.pentaho.model.OfficeDocument; +import org.libreoffice.report.pentaho.model.OfficeStylesCollection; +import org.libreoffice.report.pentaho.parser.style.OfficeStylesReadHandler; + +import java.util.logging.Logger; + +import org.jfree.report.JFreeReport; + +import org.pentaho.reporting.libraries.resourceloader.Resource; +import org.pentaho.reporting.libraries.resourceloader.ResourceException; +import org.pentaho.reporting.libraries.resourceloader.ResourceKey; +import org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException; +import org.pentaho.reporting.libraries.resourceloader.ResourceManager; +import org.pentaho.reporting.libraries.xmlns.parser.AbstractXmlReadHandler; +import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * This is the root handler for the document context. The + * 'office:document-context' element is encountered, if the document is split + * into separate files. + * + * <p>Alternatively, there is the option to keep everything in one file. The root + * element for that format is 'office:document'.</p> + */ +public class DocumentContentReadHandler extends AbstractXmlReadHandler +{ + + private static final Logger LOGGER = Logger.getLogger(DocumentContentReadHandler.class.getName()); + private OfficeDocument report; + private FontFaceDeclsReadHandler fontFaceReadHandler; + private BodyReadHandler bodyReadHandler; + private OfficeStylesCollection officeStylesCollection; + + /** + * Starts parsing. + * + * @param attrs the attributes. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void startParsing(final Attributes attrs) + throws SAXException + { + super.startParsing(attrs); + // parse the external 'styles.xml' if it exists + // parse the external 'meta.xml' if it exists + // parse the external 'settings.xml' if it exists + this.report = parseContentXml(); + this.report.setVirtual(true); + this.report.setType("document-content"); + this.report.setNamespace(OfficeNamespaces.OFFICE_NS); + this.report.setVirtual(true); + this.officeStylesCollection = parseStylesXml(); + } + + private OfficeStylesCollection parseStylesXml() + { + final ResourceKey contextKey = getRootHandler().getContext(); + final ResourceManager resourceManager = getRootHandler().getResourceManager(); + + try + { + final ResourceKey key = + resourceManager.deriveKey(contextKey, "styles.xml"); + final Resource resource = + resourceManager.create(key, contextKey, OfficeStylesCollection.class); + final OfficeStylesCollection styles = + (OfficeStylesCollection) resource.getResource(); + if (styles != null) + { + return styles; + } + } + catch (ResourceKeyCreationException e) + { + // ignore .. + LOGGER.config("Failed to create resource-key for 'styles.xml'. Ignoring: " + e); + } + catch (ResourceException e) + { + // ignore .. + LOGGER.config("Failed to parse resource for 'styles.xml'. Ignoring: " + e); + } + + return new OfficeStylesCollection(); + } + + private OfficeDocument parseContentXml() + { + // Check whether this is a content.xml. + if (!OfficeNamespaces.OFFICE_NS.equals(getUri()) || "document-content".equals(getTagName())) + { + return new OfficeDocument(); + } + + // we may have to parse an existing content.xml. + final ResourceKey contextKey = getRootHandler().getContext(); + final ResourceManager resourceManager = getRootHandler().getResourceManager(); + try + { + final ResourceKey key = + resourceManager.deriveKey(contextKey, "content.xml"); + final Resource resource = + resourceManager.create(key, contextKey, JFreeReport.class); + final OfficeDocument doc = (OfficeDocument) resource.getResource(); + if (doc != null) + { + return doc; + } + } + catch (ResourceKeyCreationException e) + { + // ignore .. + LOGGER.config("Failed to create resource-key for 'content.xml'. Ignoring."); + } + catch (ResourceException e) + { + // ignore .. + LOGGER.config("Failed to parse resource for 'content.xml'. Ignoring."); + } + return new OfficeDocument(); + + } + + /** + * Returns the handler for a child element. + * + * @param tagName the tag name. + * @param atts the attributes. + * @return the handler or null, if the tagname is invalid. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected XmlReadHandler getHandlerForChild(final String uri, + final String tagName, + final Attributes atts) + throws SAXException + { + if (OfficeNamespaces.OFFICE_NS.equals(uri)) + { + if ("font-face-decls".equals(tagName)) + { + if (fontFaceReadHandler == null) + { + fontFaceReadHandler = new FontFaceDeclsReadHandler(officeStylesCollection.getFontFaceDecls()); + } + return fontFaceReadHandler; + } + else if ("automatic-styles".equals(tagName)) + { + return new OfficeStylesReadHandler(officeStylesCollection.getAutomaticStyles()); + } + else if ("styles".equals(tagName)) + { + return new OfficeStylesReadHandler(officeStylesCollection.getCommonStyles()); + } + else if ("master-styles".equals(tagName)) + { + return new MasterStylesReadHandler(officeStylesCollection.getMasterStyles()); + } + else if ("body".equals(tagName)) + { + bodyReadHandler = new BodyReadHandler(); + return bodyReadHandler; + } + } + return null; + } + + /** + * Done parsing. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void doneParsing() + throws SAXException + { + // The office-document is the only node of the report. It allows us to + // switch the layout-processing implementation later on. + + report.setStylesCollection(officeStylesCollection); + + if (bodyReadHandler != null) + { + report.addNode(bodyReadHandler.getElement()); + } + } + + /** + * Returns the object for this element or null, if this element does not + * create an object. + * + * @return the object. + */ + public Object getObject() + throws SAXException + { + return report; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/office/DocumentStylesReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/office/DocumentStylesReadHandler.java new file mode 100644 index 000000000..70320ce5e --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/office/DocumentStylesReadHandler.java @@ -0,0 +1,98 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.office; + +import org.libreoffice.report.pentaho.OfficeNamespaces; +import org.libreoffice.report.pentaho.model.OfficeStylesCollection; +import org.libreoffice.report.pentaho.parser.ElementReadHandler; +import org.libreoffice.report.pentaho.parser.style.OfficeStylesReadHandler; + +import org.jfree.report.structure.Element; + +import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * The root parser for a 'styles.xml' document. This generates the global + * (or common) style collection. These styles contain the named common styles + * and the page layouts. + * + * @since 08.03.2007 + */ +public class DocumentStylesReadHandler extends ElementReadHandler +{ + + private final OfficeStylesCollection officeStylesCollection; + private FontFaceDeclsReadHandler fontFaceReadHandler; + + public DocumentStylesReadHandler() + { + officeStylesCollection = new OfficeStylesCollection(); + } + + /** + * Returns the handler for a child element. + * + * @param tagName the tag name. + * @param atts the attributes. + * @return the handler or null, if the tagname is invalid. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected XmlReadHandler getHandlerForChild(final String uri, + final String tagName, + final Attributes atts) + throws SAXException + { + if (!OfficeNamespaces.OFFICE_NS.equals(uri)) + { + return null; + } + + if ("font-face-decls".equals(tagName)) + { + if (fontFaceReadHandler == null) + { + fontFaceReadHandler = new FontFaceDeclsReadHandler(officeStylesCollection.getFontFaceDecls()); + } + return fontFaceReadHandler; + } + else if ("automatic-styles".equals(tagName)) + { + return new OfficeStylesReadHandler(officeStylesCollection.getAutomaticStyles()); + } + else if ("styles".equals(tagName)) + { + return new OfficeStylesReadHandler(officeStylesCollection.getCommonStyles()); + } + else if ("master-styles".equals(tagName)) + { + return new MasterStylesReadHandler(officeStylesCollection.getMasterStyles()); + } + return null; + } + + @Override + public Element getElement() + { + return officeStylesCollection; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/office/FontFaceDeclsReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/office/FontFaceDeclsReadHandler.java new file mode 100644 index 000000000..83c5b1f6a --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/office/FontFaceDeclsReadHandler.java @@ -0,0 +1,105 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.office; + +import org.libreoffice.report.pentaho.OfficeNamespaces; +import org.libreoffice.report.pentaho.model.FontFaceDeclsSection; +import org.libreoffice.report.pentaho.model.FontFaceElement; +import org.libreoffice.report.pentaho.parser.ElementReadHandler; +import org.libreoffice.report.pentaho.parser.style.FontFaceReadHandler; + +import java.util.ArrayList; +import java.util.List; + +import org.jfree.report.structure.Element; + +import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + + +/** + * Reads the font-face declarations section. This one can only contain + * font-face elements. + * + * @since 13.03.2007 + */ +public class FontFaceDeclsReadHandler extends ElementReadHandler +{ + + private final FontFaceDeclsSection fontFaceDecls; + private final List<FontFaceReadHandler> fontFaceReadHandlers; + + public FontFaceDeclsReadHandler(final FontFaceDeclsSection fontFaceDecls) + { + this.fontFaceDecls = fontFaceDecls; + this.fontFaceReadHandlers = new ArrayList<FontFaceReadHandler>(); + } + + /** + * Returns the handler for a child element. + * + * @param tagName the tag name. + * @param atts the attributes. + * @return the handler or null, if the tagname is invalid. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected XmlReadHandler getHandlerForChild(final String uri, + final String tagName, + final Attributes atts) + throws SAXException + { + if (!OfficeNamespaces.STYLE_NS.equals(uri)) + { + return null; + } + + if ("font-face".equals(tagName)) + { + final FontFaceReadHandler frh = new FontFaceReadHandler(); + fontFaceReadHandlers.add(frh); + return frh; + } + return null; + } + + /** + * Done parsing. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void doneParsing() + throws SAXException + { + for (int i = 0; i < fontFaceReadHandlers.size(); i++) + { + final FontFaceReadHandler handler = fontFaceReadHandlers.get(i); + fontFaceDecls.addFontFace((FontFaceElement) handler.getElement()); + } + } + + @Override + public Element getElement() + { + return fontFaceDecls; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/office/MasterStylesReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/office/MasterStylesReadHandler.java new file mode 100644 index 000000000..f86cae8e5 --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/office/MasterStylesReadHandler.java @@ -0,0 +1,111 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.office; + +import org.libreoffice.report.pentaho.OfficeNamespaces; +import org.libreoffice.report.pentaho.model.OfficeMasterStyles; +import org.libreoffice.report.pentaho.parser.ElementReadHandler; +import org.libreoffice.report.pentaho.parser.style.MasterPageReadHandler; +import org.libreoffice.report.pentaho.parser.style.StyleDefinitionReadHandler; + +import java.util.ArrayList; +import java.util.List; + +import org.jfree.report.structure.Element; + +import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + + +/** + * Todo: Document me! + * + * @since 13.03.2007 + */ +public class MasterStylesReadHandler extends ElementReadHandler +{ + + private final OfficeMasterStyles masterStyles; + private final List<ElementReadHandler> otherHandlers; + private final List<MasterPageReadHandler> masterPageHandlers; + + public MasterStylesReadHandler(final OfficeMasterStyles masterStyles) + { + this.masterStyles = masterStyles; + this.masterPageHandlers = new ArrayList<MasterPageReadHandler>(); + this.otherHandlers = new ArrayList<ElementReadHandler>(); + } + + /** + * Returns the handler for a child element. + * + * @param tagName the tag name. + * @param atts the attributes. + * @return the handler or null, if the tagname is invalid. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected XmlReadHandler getHandlerForChild(final String uri, + final String tagName, + final Attributes atts) + throws SAXException + { + if (OfficeNamespaces.STYLE_NS.equals(uri) && "master-page".equals(tagName)) + { + final MasterPageReadHandler mrh = new MasterPageReadHandler(); + masterPageHandlers.add(mrh); + return mrh; + } + + final StyleDefinitionReadHandler readHandler = + new StyleDefinitionReadHandler(); + otherHandlers.add(readHandler); + return readHandler; + } + + /** + * Done parsing. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void doneParsing() + throws SAXException + { + for (int i = 0; i < otherHandlers.size(); i++) + { + final ElementReadHandler handler = otherHandlers.get(i); + masterStyles.getOtherNodes().addNode(handler.getElement()); + } + + for (int i = 0; i < masterPageHandlers.size(); i++) + { + final MasterPageReadHandler handler = masterPageHandlers.get(i); + masterStyles.addMasterPage(handler.getMasterPage()); + } + } + + @Override + public Element getElement() + { + return masterStyles; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/ConditionalPrintExpressionReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/ConditionalPrintExpressionReadHandler.java new file mode 100644 index 000000000..cb70d4436 --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/ConditionalPrintExpressionReadHandler.java @@ -0,0 +1,72 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.rpt; + +import org.libreoffice.report.pentaho.OfficeNamespaces; + +import org.jfree.report.expressions.FormulaFunction; +import org.jfree.report.structure.Element; + +import org.pentaho.reporting.libraries.xmlns.parser.AbstractXmlReadHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * Handles the 'report:conditional-print-expression' element that can appear + * in all report elements and all root-level sections. + * + * @since 02.03.2007 + */ +public class ConditionalPrintExpressionReadHandler + extends AbstractXmlReadHandler +{ + + private final Element element; + + public ConditionalPrintExpressionReadHandler(final Element element) + { + this.element = element; + } + + @Override + protected void startParsing(final Attributes attrs) throws SAXException + { + super.startParsing(attrs); + final String formula = attrs.getValue(OfficeNamespaces.OOREPORT_NS, "formula"); + if (formula != null) + { + final FormulaFunction valueExpression = new FormulaFunction(); + valueExpression.setFormula(formula); + element.setDisplayCondition(valueExpression); + } + + } + + /** + * Returns the object for this element or null, if this element does not + * create an object. + * + * @return the object. + */ + public Object getObject() + throws SAXException + { + return element; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/DetailRootTableReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/DetailRootTableReadHandler.java new file mode 100644 index 000000000..2a0677065 --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/DetailRootTableReadHandler.java @@ -0,0 +1,29 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.rpt; + +import org.libreoffice.report.pentaho.model.OfficeDetailSection; + +public class DetailRootTableReadHandler extends RootTableReadHandler +{ + + public DetailRootTableReadHandler() + { + super(new OfficeDetailSection()); + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/FixedContentReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/FixedContentReadHandler.java new file mode 100644 index 000000000..9896c7a93 --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/FixedContentReadHandler.java @@ -0,0 +1,90 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.rpt; + +import org.libreoffice.report.OfficeToken; +import org.libreoffice.report.pentaho.OfficeNamespaces; +import org.libreoffice.report.pentaho.model.FixedTextElement; +import org.libreoffice.report.pentaho.parser.ElementReadHandler; +import org.libreoffice.report.pentaho.parser.text.TextContentReadHandler; + +import org.jfree.report.structure.Element; + +import org.pentaho.reporting.libraries.xmlns.parser.IgnoreAnyChildReadHandler; +import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * Creation-Date: 01.10.2006, 18:48:11 + * + */ +public class FixedContentReadHandler extends ElementReadHandler +{ + + private final FixedTextElement element; + + public FixedContentReadHandler() + { + element = new FixedTextElement(); + } + + /** + * Returns the handler for a child element. + * + * @param tagName the tag name. + * @param atts the attributes. + * @return the handler or null, if the tagname is invalid. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected XmlReadHandler getHandlerForChild(final String uri, + final String tagName, + final Attributes atts) + throws SAXException + { + if (OfficeNamespaces.TEXT_NS.equals(uri) && OfficeToken.P.equals(tagName)) + { + // expect a paragraph (which will be ignored; it is a structural + // component that needs not to be printed at all. + return new TextContentReadHandler(element.getContent()); + } + + if (OfficeNamespaces.OOREPORT_NS.equals(uri)) + { + // expect a report control. The control will modify the current + // element (as we do not separate the elements that strictly ..) + if ("report-control".equals(tagName)) + { + return new IgnoreAnyChildReadHandler(); + } + if ("report-element".equals(tagName)) + { + return new ReportElementReadHandler(element); + } + } + return null; + } + + @Override + public Element getElement() + { + return element; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/FormatConditionReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/FormatConditionReadHandler.java new file mode 100644 index 000000000..8c3cb6ca9 --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/FormatConditionReadHandler.java @@ -0,0 +1,91 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.rpt; + +import org.libreoffice.report.OfficeToken; +import org.libreoffice.report.pentaho.OfficeNamespaces; +import org.libreoffice.report.pentaho.model.FormatCondition; +import org.libreoffice.report.pentaho.model.ReportElement; + +import org.jfree.report.expressions.FormulaExpression; + +import org.pentaho.reporting.libraries.xmlns.parser.AbstractXmlReadHandler; +import org.pentaho.reporting.libraries.xmlns.parser.ParseException; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * I'm quite sure I should parse something here. But what? + * + */ +public class FormatConditionReadHandler extends AbstractXmlReadHandler +{ + + private final ReportElement element; + + public FormatConditionReadHandler(final ReportElement element) + { + if (element == null) + { + throw new NullPointerException(); + } + this.element = element; + } + + @Override + protected void startParsing(final Attributes attrs) throws SAXException + { + super.startParsing(attrs); + + + final String formula = + attrs.getValue(OfficeNamespaces.OOREPORT_NS, "formula"); + if (formula == null) + { + throw new ParseException("Required attribute 'formula' is missing.", getLocator()); + } + final String stylename = + attrs.getValue(OfficeNamespaces.OOREPORT_NS, OfficeToken.STYLE_NAME); + if (stylename == null) + { + throw new ParseException("Required attribute 'style-name' is missing.", getLocator()); + } + final FormulaExpression valueExpression = new FormulaExpression(); + valueExpression.setFormula(formula); + + final String enabledText = attrs.getValue(OfficeNamespaces.OOREPORT_NS, "enabled"); + final boolean enabled = (enabledText == null || OfficeToken.TRUE.equals(enabledText)); + final FormatCondition formatCondition = + new FormatCondition(valueExpression, stylename, enabled); + element.addFormatCondition(formatCondition); + + } + + /** + * Returns the object for this element or null, if this element does not + * create an object. + * + * @return the object. + */ + public Object getObject() + throws SAXException + { + return element; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/FormattedTextReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/FormattedTextReadHandler.java new file mode 100644 index 000000000..7810f972e --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/FormattedTextReadHandler.java @@ -0,0 +1,111 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.rpt; + +import org.libreoffice.report.pentaho.OfficeNamespaces; +import org.libreoffice.report.pentaho.model.FormattedTextElement; +import org.libreoffice.report.pentaho.parser.ElementReadHandler; + +import org.jfree.report.expressions.FormulaExpression; +import org.jfree.report.structure.Element; + +import org.pentaho.reporting.libraries.xmlns.parser.IgnoreAnyChildReadHandler; +import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * Creation-Date: 01.10.2006, 19:06:45 + * + */ +public class FormattedTextReadHandler extends ElementReadHandler +{ + + private final FormattedTextElement element; + + public FormattedTextReadHandler() + { + element = new FormattedTextElement(); + } + + /** + * Starts parsing. + * + * @param attrs the attributes. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void startParsing(final Attributes attrs) throws SAXException + { + super.startParsing(attrs); + + final String formula = attrs.getValue(OfficeNamespaces.OOREPORT_NS, "formula"); + if (formula != null) + { + final FormulaExpression valueExpression = new FormulaExpression(); + valueExpression.setFormula(formula); + element.setValueExpression(valueExpression); + } + + // * Print-Repeated-Values + // * Print-In-First-New-Section + // * Print-When-Group-Change + + // * Print-When-Section-Overflows + // That property cannot be evaluated yet, as this would require us to + // have a clue about pagebreaking. We don't have that - not yet and never + // in the future, as pagebreaks are computed by OpenOffice instead + } + + /** + * Returns the handler for a child element. + * + * @param tagName the tag name. + * @param atts the attributes. + * @return the handler or null, if the tagname is invalid. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected XmlReadHandler getHandlerForChild(final String uri, + final String tagName, + final Attributes atts) + throws SAXException + { + if (OfficeNamespaces.OOREPORT_NS.equals(uri)) + { + // expect a report control. The control will modify the current + // element (as we do not separate the elements that strictly...) + if ("report-control".equals(tagName)) + { + return new IgnoreAnyChildReadHandler(); + } + if ("report-element".equals(tagName)) + { + return new ReportElementReadHandler(element); + } + } + return null; + } + + @Override + public Element getElement() + { + return element; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/FunctionReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/FunctionReadHandler.java new file mode 100644 index 000000000..14def5e75 --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/FunctionReadHandler.java @@ -0,0 +1,103 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.rpt; + +import org.libreoffice.report.OfficeToken; +import org.libreoffice.report.pentaho.OfficeNamespaces; + +import org.jfree.report.expressions.Expression; +import org.jfree.report.expressions.FormulaExpression; +import org.jfree.report.expressions.FormulaFunction; + +import org.pentaho.reporting.libraries.xmlns.parser.AbstractXmlReadHandler; +import org.pentaho.reporting.libraries.xmlns.parser.ParseException; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * Parses a named expression. These expressions are encountered on reports and + * groups and compute global values. Expressions must have a unique name. + * + */ +public class FunctionReadHandler extends AbstractXmlReadHandler +{ + + private Expression expression; + + /** + * Starts parsing. + * + * @param attrs the attributes. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void startParsing(final Attributes attrs) + throws SAXException + { + final String formula = attrs.getValue(OfficeNamespaces.OOREPORT_NS, "formula"); + if (formula == null) + { + throw new ParseException("Required attribute 'formula' is missing", getLocator()); + } + + final String name = attrs.getValue(OfficeNamespaces.OOREPORT_NS, "name"); + if (name == null) + { + throw new ParseException("Required attribute 'name' is missing", getLocator()); + } + final String initialFormula = attrs.getValue(OfficeNamespaces.OOREPORT_NS, "initial-formula"); + final String deepTraversing = attrs.getValue(OfficeNamespaces.OOREPORT_NS, "deep-traversing"); + + if (initialFormula != null) + { + final FormulaFunction function = new FormulaFunction(); + function.setInitial(initialFormula); + function.setFormula(formula); + this.expression = function; + } + else + { + final FormulaExpression expression = new FormulaExpression(); + expression.setFormula(formula); + this.expression = expression; + } + + expression.setName(name); + expression.setDeepTraversing(OfficeToken.TRUE.equals(deepTraversing)); + final String preEvaluated = attrs.getValue(OfficeNamespaces.OOREPORT_NS, "pre-evaluated"); + expression.setPrecompute(OfficeToken.TRUE.equals(preEvaluated)); + } + + /** + * Returns the object for this element or null, if this element does not + * create an object. + * + * @return the object. + */ + public Object getObject() + throws SAXException + { + return getExpression(); + } + + public Expression getExpression() + { + return expression; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/GroupReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/GroupReadHandler.java new file mode 100644 index 000000000..642c6ded9 --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/GroupReadHandler.java @@ -0,0 +1,181 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.rpt; + +import org.libreoffice.report.OfficeToken; +import org.libreoffice.report.pentaho.OfficeNamespaces; +import org.libreoffice.report.pentaho.model.OfficeGroup; +import org.libreoffice.report.pentaho.model.OfficeGroupInstanceSection; +import org.libreoffice.report.pentaho.parser.ElementReadHandler; + +import java.util.ArrayList; +import java.util.List; + +import org.jfree.report.JFreeReportInfo; +import org.jfree.report.expressions.FormulaExpression; +import org.jfree.report.structure.Element; +import org.jfree.report.structure.Section; + +import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + + +public class GroupReadHandler extends ElementReadHandler +{ + + private GroupSectionReadHandler groupHeader; + private GroupSectionReadHandler groupFooter; + private GroupReadHandler childGroup; + private RootTableReadHandler detailSection; + private final OfficeGroup group; + private final OfficeGroupInstanceSection groupInstanceSection; + private final List<FunctionReadHandler> functionHandlers; + private final ReportReadHandler rh; + + public GroupReadHandler(final ReportReadHandler _rh) + { + rh = _rh; + group = new OfficeGroup(); + groupInstanceSection = new OfficeGroupInstanceSection(); + groupInstanceSection.setNamespace(JFreeReportInfo.REPORT_NAMESPACE); + groupInstanceSection.setType("group-instance"); + group.addNode(groupInstanceSection); + functionHandlers = new ArrayList<FunctionReadHandler>(); + } + + /** + * Starts parsing. + * + * @param attrs the attributes. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void startParsing(final Attributes attrs) throws SAXException + { + super.startParsing(attrs); + + final String groupExpr = attrs.getValue(OfficeNamespaces.OOREPORT_NS, "group-expression"); + if (groupExpr != null && !"".equals(groupExpr)) + { + final FormulaExpression function = new FormulaExpression(); + function.setFormula(groupExpr); + groupInstanceSection.setGroupingExpression(function); + } + final String sortExpr = attrs.getValue(OfficeNamespaces.OOREPORT_NS, "sort-expression"); + if (sortExpr != null && !"".equals(sortExpr)) + { + groupInstanceSection.setSortingExpression(sortExpr); + } + } + + /** + * Returns the handler for a child element. + * + * @param tagName the tag name. + * @param atts the attributes. + * @return the handler or null, if the tagname is invalid. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected XmlReadHandler getHandlerForChild(final String uri, + final String tagName, + final Attributes atts) + throws SAXException + { + if (!OfficeNamespaces.OOREPORT_NS.equals(uri)) + { + return null; + } + if ("function".equals(tagName)) + { + final FunctionReadHandler erh = new FunctionReadHandler(); + functionHandlers.add(erh); + return erh; + } + if ("group-header".equals(tagName)) + { + groupHeader = new GroupSectionReadHandler(); + return groupHeader; + } + if ("group".equals(tagName)) + { + childGroup = new GroupReadHandler(rh); + return childGroup; + } + if ("detail".equals(tagName)) + { + detailSection = new DetailRootTableReadHandler(); + rh.setDetail(detailSection); + return detailSection; + } + if ("group-footer".equals(tagName)) + { + ((Element) ((Section) rh.getDetail().getElement()).getNode(0)).setAttribute(JFreeReportInfo.REPORT_NAMESPACE, "has-group-footer", OfficeToken.TRUE); + groupFooter = new GroupSectionReadHandler(); + return groupFooter; + } + return null; + } + + /** + * Done parsing. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void doneParsing() throws SAXException + { + for (int i = 0; i < functionHandlers.size(); i++) + { + final FunctionReadHandler handler = functionHandlers.get(i); + groupInstanceSection.addExpression(handler.getExpression()); + } + + if (groupHeader != null) + { + groupInstanceSection.addNode(groupHeader.getElement()); + } + + final Section groupBody = new Section(); + groupBody.setNamespace(JFreeReportInfo.REPORT_NAMESPACE); + groupBody.setType("group-body"); + groupInstanceSection.addNode(groupBody); + // XOR: Either the detail or the group section can be set .. + if (detailSection != null) + { + groupBody.addNode(detailSection.getElement()); + } + else if (childGroup != null) + { + groupBody.addNode(childGroup.getElement()); + } + + if (groupFooter != null) + { + groupInstanceSection.addNode(groupFooter.getElement()); + } + } + + @Override + public Element getElement() + { + return group; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/GroupSectionReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/GroupSectionReadHandler.java new file mode 100644 index 000000000..461cf6784 --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/GroupSectionReadHandler.java @@ -0,0 +1,29 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.rpt; + +import org.libreoffice.report.pentaho.model.OfficeGroupSection; + +public class GroupSectionReadHandler extends RootTableReadHandler +{ + + public GroupSectionReadHandler() + { + super(new OfficeGroupSection()); + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/ImageReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/ImageReadHandler.java new file mode 100644 index 000000000..86dd423d5 --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/ImageReadHandler.java @@ -0,0 +1,134 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.rpt; + +import org.libreoffice.report.OfficeToken; +import org.libreoffice.report.pentaho.OfficeNamespaces; +import org.libreoffice.report.pentaho.model.ImageElement; +import org.libreoffice.report.pentaho.parser.ElementReadHandler; +import org.libreoffice.report.pentaho.parser.xlink.XLinkReadHandler; + +import org.jfree.report.expressions.FormulaExpression; +import org.jfree.report.structure.Element; + +import org.pentaho.reporting.libraries.xmlns.parser.IgnoreAnyChildReadHandler; +import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * Deals with Image-content. There are two ways to specify the image; + * as formula or as static image data. + * + */ +public class ImageReadHandler extends ElementReadHandler +{ + + private final ImageElement contentElement; + private XLinkReadHandler xLinkReadHandler; + + public ImageReadHandler() + { + contentElement = new ImageElement(); + } + + /** + * Starts parsing. + * + * @param attrs the attributes. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void startParsing(final Attributes attrs) throws SAXException + { + super.startParsing(attrs); + final String formula = attrs.getValue(OfficeNamespaces.OOREPORT_NS, "formula"); + if (formula != null && formula.length() != 0) + { + // now, the evaluated content ends up in the 'content' attribute of the + // element. + final FormulaExpression valueExpression = new FormulaExpression(); + valueExpression.setFormula(formula); + contentElement.setFormula(valueExpression); + } + + contentElement.setNamespace(OfficeNamespaces.FORM_NS); + contentElement.setType(OfficeToken.IMAGE); + } + + /** + * Returns the handler for a child element. + * + * @param tagName the tag name. + * @param atts the attributes. + * @return the handler or null, if the tagname is invalid. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected XmlReadHandler getHandlerForChild(final String uri, + final String tagName, + final Attributes atts) + throws SAXException + { + if (OfficeNamespaces.DRAWING_NS.equals(uri) && OfficeToken.IMAGE_DATA.equals(tagName)) + { + xLinkReadHandler = new XLinkReadHandler(); + return xLinkReadHandler; + } + + if (OfficeNamespaces.OOREPORT_NS.equals(uri)) + { + // expect a report control. The control will modify the current + // element (as we do not separate the elements that strictly...) + if ("report-control".equals(tagName)) + { + return new IgnoreAnyChildReadHandler(); + } + if ("report-element".equals(tagName)) + { + return new ReportElementReadHandler(contentElement); + } + } + return null; + } + + /** + * Done parsing. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void doneParsing() throws SAXException + { + // if we have static content (as well as or only), that one goes into the + // alternate-content attribute right now. It is part of the output target + // and style rules to deal with them properly. + if (xLinkReadHandler != null) + { + contentElement.setAttribute(OfficeNamespaces.OOREPORT_NS, + "alternate-content", xLinkReadHandler.getUri()); + } + } + + @Override + public Element getElement() + { + return contentElement; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/MasterDetailReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/MasterDetailReadHandler.java new file mode 100644 index 000000000..da1eff8b7 --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/MasterDetailReadHandler.java @@ -0,0 +1,99 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.rpt; + +import org.libreoffice.report.pentaho.OfficeNamespaces; +import org.libreoffice.report.pentaho.model.ObjectOleElement; +import org.libreoffice.report.pentaho.parser.ElementReadHandler; + +import org.jfree.report.structure.Element; + +import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +public class MasterDetailReadHandler extends ElementReadHandler +{ + + private final ObjectOleElement element; + private final boolean parseMasterDetail; + + public MasterDetailReadHandler(final ObjectOleElement element) + { + this.element = element; + parseMasterDetail = false; + } + + private MasterDetailReadHandler(final ObjectOleElement element, final boolean parseMasterDetail) + { + this.element = element; + this.parseMasterDetail = parseMasterDetail; + } + + /** + * Starts parsing. + * + * @param attrs the attributes. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void startParsing(final Attributes attrs) throws SAXException + { + super.startParsing(attrs); + if (parseMasterDetail) + { + final String master = attrs.getValue(OfficeNamespaces.OOREPORT_NS, "master"); + if (master != null && master.length() > 0) + { + final String detail = attrs.getValue(OfficeNamespaces.OOREPORT_NS, "detail"); + element.addMasterDetailFields(master, detail); + } + } + } + + /** + * Returns the handler for a child element. + * + * @param tagName the tag name. + * @param atts the attributes. + * @return the handler or null, if the tagname is invalid. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected XmlReadHandler getHandlerForChild(final String uri, + final String tagName, + final Attributes atts) + throws SAXException + { + if (OfficeNamespaces.OOREPORT_NS.equals(uri) && "master-detail-field".equals(tagName)) + { + // expect a report control. The control will modify the current + // element (as we do not separate the elements that strictly...) + return new MasterDetailReadHandler(element, true); + } + + return null; + } + + @Override + public Element getElement() + { + return element; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/ReportElementReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/ReportElementReadHandler.java new file mode 100644 index 000000000..6e032aaaa --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/ReportElementReadHandler.java @@ -0,0 +1,103 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.rpt; + +import org.libreoffice.report.OfficeToken; +import org.libreoffice.report.pentaho.OfficeNamespaces; +import org.libreoffice.report.pentaho.model.ReportElement; +import org.libreoffice.report.pentaho.parser.ElementReadHandler; + +import org.jfree.report.structure.Element; + +import org.pentaho.reporting.libraries.xmlns.parser.IgnoreAnyChildReadHandler; +import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +public class ReportElementReadHandler extends ElementReadHandler +{ + + private final ReportElement element; + + public ReportElementReadHandler(final ReportElement element) + { + if (element == null) + { + throw new NullPointerException(); + } + + this.element = element; + } + + @Override + public Element getElement() + { + return element; + } + + /** + * Starts parsing. + * + * @param attrs the attributes. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void startParsing(final Attributes attrs) + throws SAXException + { + super.startParsing(attrs); + final String printWhenGroupChange = attrs.getValue(OfficeNamespaces.OOREPORT_NS, "print-when-group-change"); + element.setPrintWhenGroupChange(OfficeToken.TRUE.equals(printWhenGroupChange)); + final String printRepeatingValues = attrs.getValue(OfficeNamespaces.OOREPORT_NS, "print-repeated-values"); + element.setPrintRepeatedValues(printRepeatingValues == null || OfficeToken.TRUE.equals(printRepeatingValues)); + } + + /** + * Returns the handler for a child element. + * + * @param tagName the tag name. + * @param atts the attributes. + * @return the handler or null, if the tagname is invalid. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected XmlReadHandler getHandlerForChild(final String uri, + final String tagName, + final Attributes atts) + throws SAXException + { + if (!OfficeNamespaces.OOREPORT_NS.equals(uri)) + { + return null; + } + if ("conditional-print-expression".equals(tagName)) + { + return new ConditionalPrintExpressionReadHandler(element); + } + if ("format-condition".equals(tagName)) + { + return new FormatConditionReadHandler(element); + } + if ("report-component".equals(tagName)) + { + return new IgnoreAnyChildReadHandler(); + } + return null; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/ReportReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/ReportReadHandler.java new file mode 100644 index 000000000..55b413b5e --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/ReportReadHandler.java @@ -0,0 +1,235 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.rpt; + +import org.libreoffice.report.pentaho.OfficeNamespaces; +import org.libreoffice.report.pentaho.model.OfficeReport; +import org.libreoffice.report.pentaho.parser.ElementReadHandler; +import org.libreoffice.report.pentaho.parser.chart.ChartReadHandler; + +import java.util.ArrayList; +import java.util.List; + +import org.jfree.report.JFreeReportInfo; +import org.jfree.report.structure.Element; +import org.jfree.report.structure.Section; + +import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + + +public class ReportReadHandler extends ElementReadHandler +{ + + private RootTableReadHandler pageHeader; + private RootTableReadHandler pageFooter; + private RootTableReadHandler reportHeader; + private RootTableReadHandler reportFooter; + private RootTableReadHandler detail; + private GroupReadHandler groups; + private final OfficeReport rootSection; + private final List<FunctionReadHandler> functionHandlers; + private final List<ElementReadHandler> preBodyHandlers; + private final List<ElementReadHandler> postBodyHandlers; + private boolean pre = true; + + public ReportReadHandler() + { + rootSection = new OfficeReport(); + rootSection.setAttribute(JFreeReportInfo.REPORT_NAMESPACE, "simple-report-structure", Boolean.TRUE); + functionHandlers = new ArrayList<FunctionReadHandler>(); + preBodyHandlers = new ArrayList<ElementReadHandler>(); + postBodyHandlers = new ArrayList<ElementReadHandler>(); + } + + /** + * Returns the handler for a child element. + * + * @param tagName the tag name. + * @param atts the attributes. + * @return the handler or null, if the tagname is invalid. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected XmlReadHandler getHandlerForChild(final String uri, + final String tagName, + final Attributes atts) + throws SAXException + { + final XmlReadHandler erh; + if (OfficeNamespaces.CHART_NS.equals(uri)) + { + ChartReadHandler crh = new ChartReadHandler(this); + if (pre) + { + preBodyHandlers.add(crh); + } + else + { + postBodyHandlers.add(crh); + } + erh = crh; + } + else if (OfficeNamespaces.OOREPORT_NS.equals(uri)) + { + if ("function".equals(tagName)) + { + FunctionReadHandler frh = new FunctionReadHandler(); + functionHandlers.add(frh); + erh = frh; + } + else if ("page-header".equals(tagName)) + { + pageHeader = new RootTableReadHandler(); + erh = pageHeader; + } + else if ("report-header".equals(tagName)) + { + reportHeader = new RootTableReadHandler(); + erh = reportHeader; + } + else if ("report-footer".equals(tagName)) + { + reportFooter = new RootTableReadHandler(); + erh = reportFooter; + } + else if ("page-footer".equals(tagName)) + { + pageFooter = new RootTableReadHandler(); + erh = pageFooter; + } + else if ("detail".equals(tagName)) + { + pre = false; + detail = new DetailRootTableReadHandler(); + erh = detail; + } + else if ("group".equals(tagName)) + { + groups = new GroupReadHandler(this); + erh = groups; + } + else + { + erh = null; + } + } + else + { + erh = null; + } + return erh; + } + + /** + * Done parsing. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void doneParsing() throws SAXException + { + if (pageHeader != null) + { + rootSection.setPageHeader(pageHeader.getElement()); + } + if (pageFooter != null) + { + rootSection.setPageFooter(pageFooter.getElement()); + } + if (reportHeader != null) + { + rootSection.setReportHeader(reportHeader.getElement()); + } + + final Section preBody = createSection("report-pre-body", preBodyHandlers); + if (preBody != null) + { + rootSection.setPreBodySection(preBody); + } + + final Section groupBody = new Section(); + groupBody.setNamespace(JFreeReportInfo.REPORT_NAMESPACE); + groupBody.setType("report-body"); + rootSection.setBodySection(groupBody); + + // XOR: Either the detail or the group section can be set .. + if (groups != null) + { + groupBody.addNode(groups.getElement()); + } + else if (detail != null) + { + groupBody.addNode(detail.getElement()); + } + + final Section postBody = createSection("report-post-body", postBodyHandlers); + if (postBody != null) + { + rootSection.setPostBodySection(postBody); + } + + if (reportFooter != null) + { + rootSection.setReportFooter(reportFooter.getElement()); + } + + for (int i = 0; i < functionHandlers.size(); i++) + { + final FunctionReadHandler handler = functionHandlers.get(i); + rootSection.addExpression(handler.getExpression()); + } + } + + @Override + public Element getElement() + { + return rootSection; + } + + private final Section createSection(final String name, final List<ElementReadHandler> handler) + { + if (!handler.isEmpty()) + { + final Section section = new Section(); + section.setNamespace(JFreeReportInfo.REPORT_NAMESPACE); + section.setType(name); + + for (int i = 0; i < handler.size(); i++) + { + final ElementReadHandler erh = handler.get(i); + section.addNode(erh.getElement()); + } + return section; + } + return null; + } + + public void setDetail(final RootTableReadHandler detail) + { + this.detail = detail; + } + + public final RootTableReadHandler getDetail() + { + return detail; + } + +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/RootTableReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/RootTableReadHandler.java new file mode 100644 index 000000000..c7d2aaf37 --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/RootTableReadHandler.java @@ -0,0 +1,99 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.rpt; + +import org.libreoffice.report.pentaho.OfficeNamespaces; +import org.libreoffice.report.pentaho.parser.ElementReadHandler; +import org.libreoffice.report.pentaho.parser.table.TableReadHandler; + +import org.jfree.report.structure.Element; +import org.jfree.report.structure.Section; + +import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +public class RootTableReadHandler extends ElementReadHandler +{ + + private TableReadHandler sectionTableReadHandler; + private final Section section; + + public RootTableReadHandler() + { + section = new Section(); + } + + protected RootTableReadHandler(final Section section) + { + if (section == null) + { + throw new NullPointerException(); + } + this.section = section; + } + + /** + * Returns the handler for a child element. + * + * @param tagName the tag name. + * @param atts the attributes. + * @return the handler or null, if the tagname is invalid. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected XmlReadHandler getHandlerForChild(final String uri, + final String tagName, + final Attributes atts) + throws SAXException + { + if (OfficeNamespaces.TABLE_NS.equals(uri) && "table".equals(tagName)) + { + sectionTableReadHandler = new TableReadHandler(); + return sectionTableReadHandler; + } + if (OfficeNamespaces.OOREPORT_NS.equals(uri) && "conditional-print-expression".equals(tagName)) + { + return new ConditionalPrintExpressionReadHandler(section); + } + return null; + } + + /** + * Done parsing. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void doneParsing() + throws SAXException + { + if (sectionTableReadHandler != null) + { + section.addNode(sectionTableReadHandler.getElement()); + } + } + + @Override + public Element getElement() + { + return section; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/SubDocumentReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/SubDocumentReadHandler.java new file mode 100644 index 000000000..6706408be --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/SubDocumentReadHandler.java @@ -0,0 +1,121 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.rpt; + +import org.libreoffice.report.OfficeToken; +import org.libreoffice.report.pentaho.OfficeNamespaces; +import org.libreoffice.report.pentaho.model.ObjectOleElement; +import org.libreoffice.report.pentaho.parser.draw.ObjectOleReadHandler; +import org.libreoffice.report.pentaho.parser.text.NoCDATATextContentReadHandler; + +import org.jfree.report.structure.Section; + +import org.pentaho.reporting.libraries.xmlns.parser.IgnoreAnyChildReadHandler; +import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +public class SubDocumentReadHandler extends NoCDATATextContentReadHandler +{ + + private final ObjectOleElement element; + private boolean ignore = false; + + private SubDocumentReadHandler(final Section section, final ObjectOleElement element) + { + super(section); + this.element = element; + } + + public SubDocumentReadHandler(final Section section) + { + this(section, new ObjectOleElement()); + ignore = true; + } + + /** + * Starts parsing. + * + * @param attrs the attributes. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void startParsing(final Attributes attrs) throws SAXException + { + if (!ignore) + { + super.startParsing(attrs); + } + } + + /** + * Returns the handler for a child element. + * + * @param tagName the tag name. + * @param atts the attributes. + * @return the handler or null, if the tagname is invalid. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected XmlReadHandler getHandlerForChild(final String uri, + final String tagName, + final Attributes atts) + throws SAXException + { + if (OfficeNamespaces.OOREPORT_NS.equals(uri)) + { + // expect a report control. The control will modify the current + // element (as we do not separate the elements that strictly...) + if ("report-control".equals(tagName)) + { + return new IgnoreAnyChildReadHandler(); + } + if ("report-element".equals(tagName)) + { + return new ReportElementReadHandler(element); + } + if ("master-detail-fields".equals(tagName)) + { + return new MasterDetailReadHandler(element); + } + } + if (OfficeNamespaces.DRAWING_NS.equals(uri)) + { + final XmlReadHandler readHandler; + if (OfficeToken.OBJECT_OLE.equals(tagName)) + { + readHandler = new ObjectOleReadHandler(element); + } + else if ("frame".equals(tagName)) + { + readHandler = new SubDocumentReadHandler(new Section(), element); + } + else + { + readHandler = null; + } + if (readHandler != null) + { + getChildren().add(readHandler); + return readHandler; + } + } + return super.getHandlerForChild(uri, tagName, atts); + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/style/FontFaceReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/style/FontFaceReadHandler.java new file mode 100644 index 000000000..6430cf664 --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/style/FontFaceReadHandler.java @@ -0,0 +1,47 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.style; + +import org.libreoffice.report.pentaho.model.FontFaceElement; +import org.libreoffice.report.pentaho.parser.ElementReadHandler; + +import org.jfree.report.structure.Element; + +/** + * Reads a single font-face declaration. This is equal to the @font rule of + * the CSS standard. We do not interpret the attributes of the element in + * any way yet. + * + * @since 13.03.2007 + */ +public class FontFaceReadHandler extends ElementReadHandler +{ + + private final FontFaceElement fontFaceElement; + + public FontFaceReadHandler() + { + this.fontFaceElement = new FontFaceElement(); + } + + @Override + public Element getElement() + { + return fontFaceElement; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/style/MasterPageReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/style/MasterPageReadHandler.java new file mode 100644 index 000000000..82438add7 --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/style/MasterPageReadHandler.java @@ -0,0 +1,98 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.style; + +import org.libreoffice.report.pentaho.model.OfficeMasterPage; +import org.libreoffice.report.pentaho.parser.ElementReadHandler; + +import java.util.ArrayList; +import java.util.List; + +import org.jfree.report.structure.Element; + +import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + + +/** + * Todo: Document me! + * + * @since 13.03.2007 + */ +public class MasterPageReadHandler extends ElementReadHandler +{ + + private final OfficeMasterPage masterPage; + private final List<ElementReadHandler> otherHandlers; + + public MasterPageReadHandler() + { + masterPage = new OfficeMasterPage(); + this.otherHandlers = new ArrayList<ElementReadHandler>(); + } + + public OfficeMasterPage getMasterPage() + { + return masterPage; + } + + /** + * Returns the handler for a child element. + * + * @param tagName the tag name. + * @param atts the attributes. + * @return the handler or null, if the tagname is invalid. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected XmlReadHandler getHandlerForChild(final String uri, + final String tagName, + final Attributes atts) + throws SAXException + { + final StyleDefinitionReadHandler readHandler = + new StyleDefinitionReadHandler(); + otherHandlers.add(readHandler); + return readHandler; + } + + /** + * Done parsing. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void doneParsing() + throws SAXException + { + for (int i = 0; i < otherHandlers.size(); i++) + { + final ElementReadHandler handler = otherHandlers.get(i); + masterPage.addNode(handler.getElement()); + } + } + + @Override + public Element getElement() + { + return masterPage; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/style/OfficeStyleReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/style/OfficeStyleReadHandler.java new file mode 100644 index 000000000..0c4a7d20c --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/style/OfficeStyleReadHandler.java @@ -0,0 +1,96 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.style; + +import org.libreoffice.report.pentaho.model.OfficeStyle; +import org.libreoffice.report.pentaho.parser.ElementReadHandler; + +import java.util.ArrayList; +import java.util.List; + +import org.jfree.report.structure.Element; + +import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + + +/** + * This class reads a single style rule. The resulting 'office-style' element + * is added to an 'office-styles' set. + */ +public class OfficeStyleReadHandler extends ElementReadHandler +{ + + private final OfficeStyle officeStyle; + private final List<ElementReadHandler> children; + + public OfficeStyleReadHandler() + { + this.officeStyle = new OfficeStyle(); + this.children = new ArrayList<ElementReadHandler>(); + } + + /** + * Returns the handler for a child element. + * + * @param tagName the tag name. + * @param atts the attributes. + * @return the handler or null, if the tagname is invalid. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected XmlReadHandler getHandlerForChild(final String uri, + final String tagName, + final Attributes atts) + throws SAXException + { + final StyleDefinitionReadHandler readHandler = + new StyleDefinitionReadHandler(); + children.add(readHandler); + return readHandler; + } + + /** + * Done parsing. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void doneParsing() throws SAXException + { + for (int i = 0; i < children.size(); i++) + { + final ElementReadHandler handler = children.get(i); + officeStyle.addNode(handler.getElement()); + } + } + + public OfficeStyle getOfficeStyle() + { + return officeStyle; + } + + @Override + public Element getElement() + { + return officeStyle; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/style/OfficeStylesReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/style/OfficeStylesReadHandler.java new file mode 100644 index 000000000..4afd86768 --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/style/OfficeStylesReadHandler.java @@ -0,0 +1,133 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.style; + +import org.libreoffice.report.pentaho.OfficeNamespaces; +import org.libreoffice.report.pentaho.model.OfficeStyles; +import org.libreoffice.report.pentaho.parser.ElementReadHandler; +import org.libreoffice.report.pentaho.parser.data.DataStyleReadHandler; + +import java.util.ArrayList; +import java.util.List; + +import org.jfree.report.modules.factories.report.flow.SectionReadHandler; +import org.jfree.report.structure.Element; + +import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +public class OfficeStylesReadHandler extends ElementReadHandler +{ + + private final List<OfficeStyleReadHandler> textStyleChildren; + private final List<DataStyleReadHandler> dataStyleChildren; + private final List<SectionReadHandler> otherStyleChildren; + private final List<PageLayoutReadHandler> pageLayoutChildren; + private final OfficeStyles officeStyles; + + public OfficeStylesReadHandler(final OfficeStyles officeStyles) + { + this.officeStyles = officeStyles; + this.pageLayoutChildren = new ArrayList<PageLayoutReadHandler>(); + this.dataStyleChildren = new ArrayList<DataStyleReadHandler>(); + this.textStyleChildren = new ArrayList<OfficeStyleReadHandler>(); + this.otherStyleChildren = new ArrayList<SectionReadHandler>(); + } + + /** + * Returns the handler for a child element. + * + * @param tagName the tag name. + * @param atts the attributes. + * @return the handler or null, if the tagname is invalid. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected XmlReadHandler getHandlerForChild(final String uri, final String tagName, + final Attributes atts) + throws SAXException + { + if (OfficeNamespaces.STYLE_NS.equals(uri)) + { + if ("style".equals(tagName)) + { + final OfficeStyleReadHandler xrh = new OfficeStyleReadHandler(); + textStyleChildren.add(xrh); + return xrh; + } + else if ("page-layout".equals(tagName)) + { + final PageLayoutReadHandler prh = new PageLayoutReadHandler(); + pageLayoutChildren.add(prh); + return prh; + } + } + else if (OfficeNamespaces.DATASTYLE_NS.equals(uri)) + { + final DataStyleReadHandler xrh = new DataStyleReadHandler(false); + dataStyleChildren.add(xrh); + return xrh; + } + + final SectionReadHandler genericReadHandler = new SectionReadHandler(); + otherStyleChildren.add(genericReadHandler); + return genericReadHandler; + } + + /** + * Done parsing. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void doneParsing() throws SAXException + { + for (int i = 0; i < textStyleChildren.size(); i++) + { + final OfficeStyleReadHandler handler = textStyleChildren.get(i); + officeStyles.addStyle(handler.getOfficeStyle()); + } + + for (int i = 0; i < pageLayoutChildren.size(); i++) + { + final PageLayoutReadHandler handler = pageLayoutChildren.get(i); + officeStyles.addPageStyle(handler.getPageLayout()); + } + + for (int i = 0; i < dataStyleChildren.size(); i++) + { + final DataStyleReadHandler handler = dataStyleChildren.get(i); + officeStyles.addDataStyle(handler.getDataStyle()); + } + + for (int i = 0; i < otherStyleChildren.size(); i++) + { + final SectionReadHandler handler = otherStyleChildren.get(i); + officeStyles.addOtherNode((Element) handler.getNode()); + } + } + + @Override + public Element getElement() + { + return officeStyles; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/style/PageLayoutReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/style/PageLayoutReadHandler.java new file mode 100644 index 000000000..06346e6b0 --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/style/PageLayoutReadHandler.java @@ -0,0 +1,97 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.style; + +import org.libreoffice.report.pentaho.model.PageLayout; +import org.libreoffice.report.pentaho.parser.ElementReadHandler; + +import java.util.ArrayList; +import java.util.List; + +import org.jfree.report.structure.Element; + +import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + + +/** + * Reads a page-layout element. + * + * @since 13.03.2007 + */ +public class PageLayoutReadHandler extends ElementReadHandler +{ + + private final PageLayout pageLayout; + private final List<ElementReadHandler> children; + + public PageLayoutReadHandler() + { + this.pageLayout = new PageLayout(); + this.children = new ArrayList<ElementReadHandler>(); + } + + /** + * Returns the handler for a child element. + * + * @param tagName the tag name. + * @param atts the attributes. + * @return the handler or null, if the tagname is invalid. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected XmlReadHandler getHandlerForChild(final String uri, + final String tagName, + final Attributes atts) + throws SAXException + { + final StyleDefinitionReadHandler readHandler = + new StyleDefinitionReadHandler(); + children.add(readHandler); + return readHandler; + } + + /** + * Done parsing. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void doneParsing() throws SAXException + { + for (int i = 0; i < children.size(); i++) + { + final ElementReadHandler handler = children.get(i); + pageLayout.addNode(handler.getElement()); + } + } + + public PageLayout getPageLayout() + { + return pageLayout; + } + + @Override + public Element getElement() + { + return pageLayout; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/style/StyleDefinitionReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/style/StyleDefinitionReadHandler.java new file mode 100644 index 000000000..667a4964a --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/style/StyleDefinitionReadHandler.java @@ -0,0 +1,93 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.style; + +import org.libreoffice.report.pentaho.parser.ElementReadHandler; + +import java.util.ArrayList; +import java.util.List; + +import org.jfree.report.structure.Element; +import org.jfree.report.structure.Section; + +import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + + +/** + * Reads all children of a style-definition. This simply copies everything that + * is contained in the source-file into a generic structure that can be + * written out later. + */ +public class StyleDefinitionReadHandler extends ElementReadHandler +{ + + private final Section rawSection; + private final List<ElementReadHandler> children; + + public StyleDefinitionReadHandler() + { + this.rawSection = new Section(); + this.children = new ArrayList<ElementReadHandler>(); + } + + /** + * Returns the handler for a child element. + * + * @param tagName the tag name. + * @param atts the attributes. + * @return the handler or null, if the tagname is invalid. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected XmlReadHandler getHandlerForChild(final String uri, + final String tagName, + final Attributes atts) + throws SAXException + { + final StyleDefinitionReadHandler readHandler = + new StyleDefinitionReadHandler(); + children.add(readHandler); + return readHandler; + } + + /** + * Done parsing. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void doneParsing() + throws SAXException + { + for (int i = 0; i < children.size(); i++) + { + final ElementReadHandler handler = children.get(i); + rawSection.addNode(handler.getElement()); + } + } + + @Override + public Element getElement() + { + return rawSection; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/table/CoveredCellReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/table/CoveredCellReadHandler.java new file mode 100644 index 000000000..5adb6d596 --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/table/CoveredCellReadHandler.java @@ -0,0 +1,45 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.table; + +import org.libreoffice.report.pentaho.parser.ElementReadHandler; + +import org.jfree.report.structure.Element; +import org.jfree.report.structure.Section; + +/** + * Todo: Document me! + * + * @since 14.03.2007 + */ +public class CoveredCellReadHandler extends ElementReadHandler +{ + + private final Element coveredCell; + + public CoveredCellReadHandler() + { + coveredCell = new Section(); + } + + @Override + public Element getElement() + { + return coveredCell; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/table/TableCellReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/table/TableCellReadHandler.java new file mode 100644 index 000000000..f37ac00f7 --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/table/TableCellReadHandler.java @@ -0,0 +1,36 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.table; + +import org.libreoffice.report.pentaho.model.TableCellElement; +import org.libreoffice.report.pentaho.parser.text.NoCDATATextContentReadHandler; + +/** + * A read handler for table-cell contents. This is basically a text-content + * read handler; we may extend this implementation later. + * + * @since 05.03.2007 + */ +public class TableCellReadHandler extends NoCDATATextContentReadHandler +{ + + public TableCellReadHandler() + { + super(new TableCellElement(), true); + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/table/TableColumnReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/table/TableColumnReadHandler.java new file mode 100644 index 000000000..adfc956da --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/table/TableColumnReadHandler.java @@ -0,0 +1,44 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.table; + +import org.libreoffice.report.pentaho.parser.ElementReadHandler; + +import org.jfree.report.structure.Element; +import org.jfree.report.structure.Section; + +/** + * Creation-Date: 03.07.2006, 14:26:55 + * + */ +public class TableColumnReadHandler extends ElementReadHandler +{ + + private final Section tableColumn; + + public TableColumnReadHandler() + { + tableColumn = new Section(); + } + + @Override + public Element getElement() + { + return tableColumn; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/table/TableColumnsReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/table/TableColumnsReadHandler.java new file mode 100644 index 000000000..35da849ce --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/table/TableColumnsReadHandler.java @@ -0,0 +1,96 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.table; + +import org.libreoffice.report.OfficeToken; +import org.libreoffice.report.pentaho.OfficeNamespaces; +import org.libreoffice.report.pentaho.parser.ElementReadHandler; + +import java.util.ArrayList; +import java.util.List; + +import org.jfree.report.structure.Element; +import org.jfree.report.structure.Section; + +import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + + +/** + * Creation-Date: 03.07.2006, 13:50:41 + * + */ +public class TableColumnsReadHandler extends ElementReadHandler +{ + + private final List<TableColumnReadHandler> columns; + private final Section tableColumns; + + public TableColumnsReadHandler() + { + columns = new ArrayList<TableColumnReadHandler>(); + tableColumns = new Section(); + } + + /** + * Returns the handler for a child element. + * + * @param tagName the tag name. + * @param atts the attributes. + * @return the handler or null, if the tagname is invalid. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected XmlReadHandler getHandlerForChild(final String uri, + final String tagName, + final Attributes atts) + throws SAXException + { + if (OfficeNamespaces.TABLE_NS.equals(uri) && OfficeToken.TABLE_COLUMN.equals(tagName)) + { + final TableColumnReadHandler readHandler = new TableColumnReadHandler(); + columns.add(readHandler); + return readHandler; + } + + return null; + } + + /** + * Done parsing. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void doneParsing() throws SAXException + { + for (int i = 0; i < columns.size(); i++) + { + final TableColumnReadHandler handler = columns.get(i); + tableColumns.addNode(handler.getElement()); + } + } + + @Override + public Element getElement() + { + return tableColumns; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/table/TableReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/table/TableReadHandler.java new file mode 100644 index 000000000..3c8e90f20 --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/table/TableReadHandler.java @@ -0,0 +1,139 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.table; + +import org.libreoffice.report.OfficeToken; +import org.libreoffice.report.pentaho.OfficeNamespaces; +import org.libreoffice.report.pentaho.model.OfficeTableSection; +import org.libreoffice.report.pentaho.parser.ElementReadHandler; +import org.libreoffice.report.pentaho.parser.rpt.ConditionalPrintExpressionReadHandler; + +import java.util.ArrayList; +import java.util.List; + +import org.jfree.report.structure.Element; +import org.jfree.report.structure.Section; + +import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + + +/** + * Creation-Date: 03.07.2006, 13:47:47 + * + */ +public class TableReadHandler extends ElementReadHandler +{ + + private final List<ElementReadHandler> children; + private final Section table; + + public TableReadHandler() + { + children = new ArrayList<ElementReadHandler>(); + table = new OfficeTableSection(); + } + + /** + * Starts parsing. + * + * @param attrs the attributes. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void startParsing(final Attributes attrs) + throws SAXException + { + super.startParsing(attrs); + final String enabled = attrs.getValue(OfficeNamespaces.OOREPORT_NS, "visible"); + if (enabled == null || OfficeToken.TRUE.equals(enabled)) + { + table.setEnabled(true); + } + else + { + table.setEnabled(false); + } + + } + + /** + * Returns the handler for a child element. + * + * @param tagName the tag name. + * @param atts the attributes. + * @return the handler or null, if the tagname is invalid. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected XmlReadHandler getHandlerForChild(final String uri, + final String tagName, + final Attributes atts) + throws SAXException + { + if (OfficeNamespaces.OOREPORT_NS.equals(uri) && "conditional-print-expression".equals(tagName)) + { + return new ConditionalPrintExpressionReadHandler(table); + } + else if (OfficeNamespaces.TABLE_NS.equals(uri)) + { + if (OfficeToken.TABLE_COLUMNS.equals(tagName) || OfficeToken.TABLE_HEADER_COLUMNS.equals(tagName)) + { + final TableColumnsReadHandler columns = new TableColumnsReadHandler(); + children.add(columns); + return columns; + } + else if (OfficeToken.TABLE_ROW.equals(tagName)) + { + final TableRowReadHandler rowHandler = new TableRowReadHandler(); + children.add(rowHandler); + return rowHandler; + } + else if (OfficeToken.TABLE_ROWS.equals(tagName) || OfficeToken.TABLE_HEADER_ROWS.equals(tagName)) + { + final TableRowsReadHandler rowsHandler = new TableRowsReadHandler(); + children.add(rowsHandler); + return rowsHandler; + } + } + return null; + } + + /** + * Done parsing. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void doneParsing() throws SAXException + { + for (int i = 0; i < children.size(); i++) + { + final ElementReadHandler handler = children.get(i); + table.addNode(handler.getElement()); + } + } + + @Override + public Element getElement() + { + return table; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/table/TableRowReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/table/TableRowReadHandler.java new file mode 100644 index 000000000..2f4bad5a4 --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/table/TableRowReadHandler.java @@ -0,0 +1,119 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.table; + +import org.libreoffice.report.OfficeToken; +import org.libreoffice.report.pentaho.OfficeNamespaces; +import org.libreoffice.report.pentaho.parser.ElementReadHandler; + +import java.util.ArrayList; +import java.util.List; + +import org.jfree.report.structure.Element; +import org.jfree.report.structure.Section; + +import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + + +/** + * Creation-Date: 03.07.2006, 13:51:47 + * + */ +public class TableRowReadHandler extends ElementReadHandler +{ + + private final List<ElementReadHandler> tableCells; + private final Section tableRow; + + public TableRowReadHandler() + { + tableCells = new ArrayList<ElementReadHandler>(); + tableRow = new Section(); + } + + /** + * Returns the handler for a child element. + * + * @param tagName the tag name. + * @param atts the attributes. + * @return the handler or null, if the tagname is invalid. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected XmlReadHandler getHandlerForChild(final String uri, + final String tagName, + final Attributes atts) + throws SAXException + { + final ElementReadHandler rh; + if (OfficeNamespaces.TABLE_NS.equals(uri)) + { + if (OfficeToken.TABLE_CELL.equals(tagName)) + { + rh = new TableCellReadHandler(); + } + else if (OfficeToken.COVERED_TABLE_CELL.equals(tagName)) + { + rh = new CoveredCellReadHandler(); + } + else + { + rh = null; + } + if (rh != null) + { + tableCells.add(rh); + } + } + else + { + rh = null; + } + return rh; + } + + /** + * Done parsing. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void doneParsing() throws SAXException + { + for (int i = 0; i < tableCells.size(); i++) + { + final ElementReadHandler handler = tableCells.get(i); + tableRow.addNode(handler.getElement()); + } + } + + /** + * Returns the object for this element or null, if this element does not + * create an object. + * + * @return the object. + */ + @Override + public Element getElement() + { + return tableRow; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/table/TableRowsReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/table/TableRowsReadHandler.java new file mode 100644 index 000000000..33e253f24 --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/table/TableRowsReadHandler.java @@ -0,0 +1,92 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.table; + +import org.libreoffice.report.OfficeToken; +import org.libreoffice.report.pentaho.OfficeNamespaces; +import org.libreoffice.report.pentaho.parser.ElementReadHandler; + +import java.util.ArrayList; +import java.util.List; + +import org.jfree.report.structure.Element; +import org.jfree.report.structure.Section; + +import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + + +public class TableRowsReadHandler extends ElementReadHandler +{ + + private final List<TableRowReadHandler> rows; + private final Section tableRows; + + public TableRowsReadHandler() + { + rows = new ArrayList<TableRowReadHandler>(); + tableRows = new Section(); + } + + /** + * Returns the handler for a child element. + * + * @param tagName the tag name. + * @param atts the attributes. + * @return the handler or null, if the tagname is invalid. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected XmlReadHandler getHandlerForChild(final String uri, + final String tagName, + final Attributes atts) + throws SAXException + { + if (OfficeNamespaces.TABLE_NS.equals(uri) && OfficeToken.TABLE_ROW.equals(tagName)) + { + final TableRowReadHandler readHandler = new TableRowReadHandler(); + rows.add(readHandler); + return readHandler; + } + + return null; + } + + /** + * Done parsing. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void doneParsing() throws SAXException + { + for (int i = 0; i < rows.size(); i++) + { + final TableRowReadHandler handler = rows.get(i); + tableRows.addNode(handler.getElement()); + } + } + + @Override + public Element getElement() + { + return tableRows; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/text/NoCDATATextContentReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/text/NoCDATATextContentReadHandler.java new file mode 100644 index 000000000..83ab022a1 --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/text/NoCDATATextContentReadHandler.java @@ -0,0 +1,185 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package org.libreoffice.report.pentaho.parser.text; + +import org.libreoffice.report.OfficeToken; +import org.libreoffice.report.pentaho.OfficeNamespaces; +import org.libreoffice.report.pentaho.parser.ElementReadHandler; +import org.libreoffice.report.pentaho.parser.rpt.FixedContentReadHandler; +import org.libreoffice.report.pentaho.parser.rpt.FormattedTextReadHandler; +import org.libreoffice.report.pentaho.parser.rpt.ImageReadHandler; +import org.libreoffice.report.pentaho.parser.rpt.SubDocumentReadHandler; + +import java.util.ArrayList; +import java.util.List; + +import org.jfree.report.structure.Element; +import org.jfree.report.structure.Section; +import org.jfree.report.structure.StaticText; + +import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + + +/** + * This is a generic implementation that accepts all input and adds special + * handlers for the report-elements. + * + */ +public class NoCDATATextContentReadHandler extends ElementReadHandler +{ + + private Section section; + private List<Object> children; + private boolean copyType; + + public NoCDATATextContentReadHandler(final Section section, + final boolean copyType) + { + this.children = new ArrayList<Object>(); + this.section = section; + this.copyType = copyType; + } + + public NoCDATATextContentReadHandler(final Section section) + { + this(section, false); + } + + public NoCDATATextContentReadHandler() + { + this(new Section(), true); + } + + /** + * Starts parsing. + * + * @param attrs the attributes. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void startParsing(final Attributes attrs) throws SAXException + { + super.startParsing(attrs); + final Element element = getElement(); + if (copyType) + { + copyElementType(element); + } + copyAttributes(attrs, element); + } + + /** + * Returns the handler for a child element. + * + * @param tagName the tag name. + * @param atts the attributes. + * @return the handler or null, if the tagname is invalid. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected XmlReadHandler getHandlerForChild(final String uri, + final String tagName, + final Attributes atts) + throws SAXException + { + if (OfficeNamespaces.OOREPORT_NS.equals(uri)) + { + if ("fixed-content".equals(tagName)) + { + final FixedContentReadHandler fixedContentReadHandler = new FixedContentReadHandler(); + children.add(fixedContentReadHandler); + return fixedContentReadHandler; + } + if ("formatted-text".equals(tagName)) + { + final FormattedTextReadHandler formattedTextReadHandler = new FormattedTextReadHandler(); + children.add(formattedTextReadHandler); + return formattedTextReadHandler; + } + if (OfficeToken.IMAGE.equals(tagName)) + { + final ImageReadHandler imageReadHandler = new ImageReadHandler(); + children.add(imageReadHandler); + return imageReadHandler; + } + if ("sub-document".equals(tagName)) + { + final SubDocumentReadHandler subDocReadHandler = new SubDocumentReadHandler(section); + return subDocReadHandler; + } + } + if (OfficeNamespaces.DRAWING_NS.equals(uri)) + { + final XmlReadHandler readHandler; + if (OfficeToken.IMAGE.equals(tagName)) + { + readHandler = new ImageReadHandler(); + } + else + { + readHandler = new NoCDATATextContentReadHandler(); + } + children.add(readHandler); + return readHandler; + } + else + { + final TextContentReadHandler readHandler = new TextContentReadHandler(); + children.add(readHandler); + return readHandler; + } + } + + public List<Object> getChildren() + { + return children; + } + + /** + * Done parsing. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void doneParsing() throws SAXException + { + for (int i = 0; i < children.size(); i++) + { + final Object o = children.get(i); + if (o instanceof ElementReadHandler) + { + final ElementReadHandler handler = (ElementReadHandler) o; + section.addNode(handler.getElement()); + } + else if (o instanceof StaticText) + { + section.addNode((StaticText) o); + } + } + } + + @Override + public Element getElement() + { + return section; + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/text/TextContentReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/text/TextContentReadHandler.java new file mode 100644 index 000000000..fc0b1481e --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/text/TextContentReadHandler.java @@ -0,0 +1,56 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.text; + +import org.jfree.report.structure.Section; +import org.jfree.report.structure.StaticText; + +import org.xml.sax.SAXException; + +/** + * This is a generic implementation that accepts all input and adds special + * handlers for the report-elements. + * + */ +public class TextContentReadHandler extends NoCDATATextContentReadHandler +{ + + public TextContentReadHandler(final Section section) + { + super(section); + } + + public TextContentReadHandler() + { + } + + /** + * This method is called to process the character data between element tags. + * + * @param ch the character buffer. + * @param start the start index. + * @param length the length. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + public void characters(final char[] ch, final int start, final int length) + throws SAXException + { + getChildren().add(new StaticText(new String(ch, start, length))); + } +} diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/xlink/XLinkReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/xlink/XLinkReadHandler.java new file mode 100644 index 000000000..cadf200c0 --- /dev/null +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/xlink/XLinkReadHandler.java @@ -0,0 +1,65 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package org.libreoffice.report.pentaho.parser.xlink; + +import org.libreoffice.report.pentaho.OfficeNamespaces; + +import org.pentaho.reporting.libraries.xmlns.parser.AbstractXmlReadHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * An image reference. + * + */ +public class XLinkReadHandler extends AbstractXmlReadHandler +{ + + private String uri; + + /** + * Starts parsing. + * + * @param attrs the attributes. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + @Override + protected void startParsing(final Attributes attrs) throws SAXException + { + uri = attrs.getValue(OfficeNamespaces.XLINK_NS, "uri"); + } + + /** + * Returns the object for this element or null, if this element does not + * create an object. + * + * @return the object. + */ + public Object getObject() throws SAXException + { + return uri; + } + + @Override + public String getUri() + { + return uri; + } + +} |