diff options
Diffstat (limited to 'reportbuilder/java/com/sun/star/report/pentaho/parser')
71 files changed, 6491 insertions, 0 deletions
diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/AttributeSpecification.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/AttributeSpecification.java new file mode 100644 index 000000000000..98a47a23aae7 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/AttributeSpecification.java @@ -0,0 +1,57 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser; + +public final class AttributeSpecification +{ + + private final String namespaceUrl; + private final String attributName; + private final String mapperImplementation; + + public AttributeSpecification(String namespaceUrl, String attributName, String mapperImplementation) + { + this.namespaceUrl = namespaceUrl; + this.attributName = attributName; + this.mapperImplementation = mapperImplementation; + } + + public String getAttributName() + { + return attributName; + } + + public String getMapperImplementation() + { + return mapperImplementation; + } + + public String getNamespaceUrl() + { + return namespaceUrl; + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/ElementReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/ElementReadHandler.java new file mode 100644 index 000000000000..c90f6425d971 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/ElementReadHandler.java @@ -0,0 +1,91 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.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 + * + * @author Thomas Morgner + */ +public abstract class ElementReadHandler extends AbstractXmlReadHandler +{ + + public ElementReadHandler() + { + } + + /** + * Starts parsing. + * + * @param attrs the attributes. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + 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/com/sun/star/report/pentaho/parser/OfficeDocumentXmlResourceFactory.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/OfficeDocumentXmlResourceFactory.java new file mode 100644 index 000000000000..4177a75f81be --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/OfficeDocumentXmlResourceFactory.java @@ -0,0 +1,51 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser; + +import com.sun.star.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. + * + * @author Thomas Morgner + * @since 09.03.2007 + */ +public class OfficeDocumentXmlResourceFactory extends JFreeReportXmlResourceFactory +{ + + public OfficeDocumentXmlResourceFactory() + { + } + + public Class getFactoryType() + { + return OfficeDocument.class; + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/OfficeParserUtil.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/OfficeParserUtil.java new file mode 100644 index 000000000000..5272a987957f --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/OfficeParserUtil.java @@ -0,0 +1,191 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Properties; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.jfree.layouting.namespace.NamespaceDefinition; +import org.jfree.layouting.namespace.Namespaces; +import org.jfree.report.JFreeReportBoot; + +import org.pentaho.reporting.libraries.base.config.DefaultConfiguration; +import org.pentaho.reporting.libraries.resourceloader.Resource; +import org.pentaho.reporting.libraries.resourceloader.ResourceException; +import org.pentaho.reporting.libraries.resourceloader.ResourceManager; + + +public class OfficeParserUtil +{ + + private static final Log LOGGER = LogFactory.getLog(OfficeParserUtil.class); + private static OfficeParserUtil instance; + private static final String NAMESPACES_PREFIX = "namespaces."; + + public static synchronized OfficeParserUtil getInstance() + { + if (instance == null) + { + instance = new OfficeParserUtil(); + } + return instance; + } + private final DefaultConfiguration props; + private final NamespaceDefinition[] namespaces; + + private OfficeParserUtil() + { + props = new DefaultConfiguration(); + + final ResourceManager resourceManager = new ResourceManager(); + resourceManager.registerDefaults(); + try + { + final Resource res = resourceManager.createDirectly("res://com/sun/star/report/pentaho/parser/selectors.properties", Properties.class); + final Properties resProps = (Properties) res.getResource(); + props.putAll(resProps); + } + catch (ResourceException e) + { + LOGGER.warn("Unable to load mapping rules. Parsing services may not be available.", e); + } + + namespaces = Namespaces.createFromConfig(JFreeReportBoot.getInstance().getGlobalConfig(), + "org.jfree.report.namespaces.", resourceManager); + } + + public NamespaceDefinition getNamespaceDeclaration(final String uri) + { + if (uri == null) + { + throw new NullPointerException("URI must not be null"); + } + + for (int i = 0; i < namespaces.length; i++) + { + final NamespaceDefinition definition = namespaces[i]; + if (uri.equals(definition.getURI())) + { + return definition; + } + } + return null; + } + + public String getGenericFont(final String officeFont) + { + return props.getProperty("font-family." + officeFont.toLowerCase(), officeFont); + } + + public String getNamespaceURI(final String namespacePrefix) + { + return props.getProperty(NAMESPACES_PREFIX + namespacePrefix); + } + + public String getNamespaceForStyleFamily(final String styleFamily) + { + return props.getProperty("style-family." + styleFamily); + } + + public Map getNamespaces() + { + final Map map = new HashMap(); + final Iterator keys = props.findPropertyKeys(NAMESPACES_PREFIX); + while (keys.hasNext()) + { + final String key = (String) keys.next(); + final String value = props.getConfigProperty(key); + map.put(key.substring(NAMESPACES_PREFIX.length()), value); + } + return map; + } + + public String getNamespacePrefix(final String namespaceURI) + { + final Iterator keys = props.findPropertyKeys(NAMESPACES_PREFIX); + while (keys.hasNext()) + { + final String key = (String) keys.next(); + final String value = props.getConfigProperty(key); + if (namespaceURI.equals(value)) + { + return key.substring(NAMESPACES_PREFIX.length()); + } + } + return null; + } + + public AttributeSpecification parseStyleAttrDefinition(final String key, final String prefix, final String tagname) + { + final String configPrefix = "attr." + prefix + "." + tagname + "."; + final String configSuffix = key.substring(configPrefix.length()); + final int dotPosition = configSuffix.indexOf('.'); + if (dotPosition == -1) + { + return null; + } + final String namespaceUri = getNamespaceURI(configSuffix.substring(0, dotPosition)); + final String attrName = configSuffix.substring(dotPosition + 1); + final String value = props.getProperty(key); + return new AttributeSpecification(namespaceUri, attrName, value); + } + + public Iterator findStylesForElement(final String prefix, + final String tagname) + { + final String configPrefix = "attr." + prefix + "." + tagname + "."; + return props.findPropertyKeys(configPrefix); + } + + public boolean isValidStyleElement(final String uri, final String tagName) + { + final String prefix = getNamespacePrefix(uri); + if (prefix == null) + { + return false; + } + + final Iterator stylesForElement = findStylesForElement(prefix, tagName); + return stylesForElement.hasNext(); + } + + public String getSelectorPattern() + { + return props.getConfigProperty("style-selector.pattern"); + } + + public static void main(final String[] args) + { + JFreeReportBoot.getInstance().start(); + System.out.print(OfficeParserUtil.getInstance().getNamespaces()); + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/OfficeStylesXmlResourceFactory.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/OfficeStylesXmlResourceFactory.java new file mode 100644 index 000000000000..28d646eb8a23 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/OfficeStylesXmlResourceFactory.java @@ -0,0 +1,59 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser; + +import com.sun.star.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. + * + * @author Thomas Morgner + * @since 09.03.2007 + */ +public class OfficeStylesXmlResourceFactory extends AbstractXmlResourceFactory +{ + + public OfficeStylesXmlResourceFactory() + { + } + + protected Configuration getConfiguration() + { + return JFreeReportBoot.getInstance().getGlobalConfig(); + } + + public Class getFactoryType() + { + return OfficeStylesCollection.class; + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/StarStyleXmlFactoryModule.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/StarStyleXmlFactoryModule.java new file mode 100644 index 000000000000..baa6531fbd08 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/StarStyleXmlFactoryModule.java @@ -0,0 +1,62 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser; + +import com.sun.star.report.pentaho.OfficeNamespaces; +import com.sun.star.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; + +public class StarStyleXmlFactoryModule implements XmlFactoryModule +{ + + public StarStyleXmlFactoryModule() + { + } + + 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/com/sun/star/report/pentaho/parser/StarXmlFactoryModule.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/StarXmlFactoryModule.java new file mode 100644 index 000000000000..ce16d222eaba --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/StarXmlFactoryModule.java @@ -0,0 +1,62 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser; + +import com.sun.star.report.pentaho.OfficeNamespaces; +import com.sun.star.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; + +public class StarXmlFactoryModule implements XmlFactoryModule +{ + + public StarXmlFactoryModule() + { + } + + 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/com/sun/star/report/pentaho/parser/StyleMapper.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/StyleMapper.java new file mode 100644 index 000000000000..aaae0b7795b5 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/StyleMapper.java @@ -0,0 +1,38 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser; + +import org.jfree.layouting.input.style.CSSDeclarationRule; + +public interface StyleMapper +{ + + void updateStyle(final String uri, + final String attrName, + final String attrValue, + final CSSDeclarationRule targetRule); +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/chart/ChartReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/chart/ChartReadHandler.java new file mode 100644 index 000000000000..9f899389b27b --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/chart/ChartReadHandler.java @@ -0,0 +1,115 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.chart; + +import com.sun.star.report.pentaho.OfficeNamespaces; +import com.sun.star.report.pentaho.parser.ElementReadHandler; +import com.sun.star.report.pentaho.parser.rpt.DetailRootTableReadHandler; +import com.sun.star.report.pentaho.parser.rpt.ReportReadHandler; +import com.sun.star.report.pentaho.parser.text.TextContentReadHandler; + +import java.lang.Object; + +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; + + +/** + * + * @author Ocke Janssen + */ +public class ChartReadHandler extends ElementReadHandler +{ + + private final Section element; + private final List children; + private final ReportReadHandler reportHandler; + + public ChartReadHandler(ReportReadHandler reportHandler) + { + this.reportHandler = reportHandler; + children = new ArrayList(); + 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. + */ + 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. + */ + protected void doneParsing() throws SAXException + { + for (Object aChildren : children) + { + final ElementReadHandler handler = (ElementReadHandler) aChildren; + element.addNode(handler.getElement()); + } + } + + public Element getElement() + { + return element; + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/data/DataStyleReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/data/DataStyleReadHandler.java new file mode 100644 index 000000000000..e2effde8dfc3 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/data/DataStyleReadHandler.java @@ -0,0 +1,130 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.data; + +import com.sun.star.report.pentaho.OfficeNamespaces; +import com.sun.star.report.pentaho.model.DataStyle; +import com.sun.star.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 children; + private final boolean hasCData; + + public DataStyleReadHandler(final boolean hasCData) + { + this.hasCData = hasCData; + this.dataStyle = new DataStyle(); + this.children = new ArrayList(); + } + + /** + * 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. + */ + 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. + */ + 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. + */ + 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; + } + + public Element getElement() + { + return dataStyle; + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/draw/ObjectOleReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/draw/ObjectOleReadHandler.java new file mode 100644 index 000000000000..e5d38f2d364a --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/draw/ObjectOleReadHandler.java @@ -0,0 +1,85 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.draw; + +import com.sun.star.report.pentaho.OfficeNamespaces; +import com.sun.star.report.pentaho.model.ObjectOleElement; +import com.sun.star.report.pentaho.parser.ElementReadHandler; + +import org.jfree.report.structure.Element; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * + * @author Ocke Janssen + */ +public class ObjectOleReadHandler extends ElementReadHandler +{ + + private final static String RPT_CHART_CLASS_ID = "80243D39-6741-46C5-926E-069164FF87BB"; + private final static 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. + */ + 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); + } + } + + public Element getElement() + { + return element; + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/office/BodyReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/office/BodyReadHandler.java new file mode 100644 index 000000000000..b77c0e80e321 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/office/BodyReadHandler.java @@ -0,0 +1,91 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.office; + +import com.sun.star.report.pentaho.OfficeNamespaces; +import com.sun.star.report.pentaho.parser.ElementReadHandler; +import com.sun.star.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. + */ + 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. + */ + protected void doneParsing() throws SAXException + { + if (reportReadHandler != null) + { + body.addNode(reportReadHandler.getElement()); + } + } + + public Element getElement() + { + return body; + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/office/DocumentContentReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/office/DocumentContentReadHandler.java new file mode 100644 index 000000000000..1f57c7c61205 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/office/DocumentContentReadHandler.java @@ -0,0 +1,236 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.office; + +import com.sun.star.report.pentaho.OfficeNamespaces; +import com.sun.star.report.pentaho.model.OfficeDocument; +import com.sun.star.report.pentaho.model.OfficeStylesCollection; +import com.sun.star.report.pentaho.parser.style.OfficeStylesReadHandler; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +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/> + * Alternativly, there is the option to keep everything in one file. The root + * element for that format is 'office:document'. + */ +public class DocumentContentReadHandler extends AbstractXmlReadHandler +{ + + private static final Log LOGGER = LogFactory.getLog(DocumentContentReadHandler.class); + private OfficeDocument report; + private FontFaceDeclsReadHandler fontFaceReadHandler; + private BodyReadHandler bodyReadHandler; + private OfficeStylesCollection officeStylesCollection; + + public DocumentContentReadHandler() + { + } + + /** + * Starts parsing. + * + * @param attrs the attributes. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + 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.debug("Failed to create resource-key for 'styles.xml'. Ignoring.", e); + } + catch (ResourceException e) + { + // ignore .. + LOGGER.debug("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.debug("Failed to create resource-key for 'content.xml'. Ignoring."); + } + catch (ResourceException e) + { + // ignore .. + LOGGER.debug("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. + */ + 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. + */ + 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/com/sun/star/report/pentaho/parser/office/DocumentStylesReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/office/DocumentStylesReadHandler.java new file mode 100644 index 000000000000..c8bf1268ab3c --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/office/DocumentStylesReadHandler.java @@ -0,0 +1,106 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.office; + +import com.sun.star.report.pentaho.OfficeNamespaces; +import com.sun.star.report.pentaho.model.OfficeStylesCollection; +import com.sun.star.report.pentaho.parser.ElementReadHandler; +import com.sun.star.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. + * + * @author Thomas Morgner + * @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. + */ + 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; + } + + public Element getElement() + { + return officeStylesCollection; + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/office/FontFaceDeclsReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/office/FontFaceDeclsReadHandler.java new file mode 100644 index 000000000000..bfd0e99e170d --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/office/FontFaceDeclsReadHandler.java @@ -0,0 +1,117 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.office; + +import com.sun.star.report.pentaho.OfficeNamespaces; +import com.sun.star.report.pentaho.model.FontFaceDeclsSection; +import com.sun.star.report.pentaho.model.FontFaceElement; +import com.sun.star.report.pentaho.parser.ElementReadHandler; +import com.sun.star.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. + * + * @author Thomas Morgner + * @since 13.03.2007 + */ +public class FontFaceDeclsReadHandler extends ElementReadHandler +{ + + private final FontFaceDeclsSection fontFaceDecls; + private final List fontFaceReadHandlers; + + public FontFaceDeclsReadHandler(final FontFaceDeclsSection fontFaceDecls) + { + this.fontFaceDecls = fontFaceDecls; + this.fontFaceReadHandlers = new ArrayList(); + } + + public FontFaceDeclsSection getFontFaceDecls() + { + return fontFaceDecls; + } + + /** + * 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. + */ + 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. + */ + protected void doneParsing() + throws SAXException + { + for (int i = 0; i < fontFaceReadHandlers.size(); i++) + { + final FontFaceReadHandler handler = (FontFaceReadHandler) fontFaceReadHandlers.get(i); + fontFaceDecls.addFontFace((FontFaceElement) handler.getElement()); + } + } + + public Element getElement() + { + return fontFaceDecls; + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/office/MasterStylesReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/office/MasterStylesReadHandler.java new file mode 100644 index 000000000000..61263a216dca --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/office/MasterStylesReadHandler.java @@ -0,0 +1,125 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.office; + +import com.sun.star.report.pentaho.OfficeNamespaces; +import com.sun.star.report.pentaho.model.OfficeMasterStyles; +import com.sun.star.report.pentaho.parser.ElementReadHandler; +import com.sun.star.report.pentaho.parser.style.MasterPageReadHandler; +import com.sun.star.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! + * + * @author Thomas Morgner + * @since 13.03.2007 + */ +public class MasterStylesReadHandler extends ElementReadHandler +{ + + private final OfficeMasterStyles masterStyles; + private final List otherHandlers; + private final List masterPageHandlers; + + public MasterStylesReadHandler(final OfficeMasterStyles masterStyles) + { + this.masterStyles = masterStyles; + this.masterPageHandlers = new ArrayList(); + this.otherHandlers = new ArrayList(); + } + + public OfficeMasterStyles getMasterStyles() + { + return masterStyles; + } + + /** + * 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. + */ + 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. + */ + protected void doneParsing() + throws SAXException + { + for (int i = 0; i < otherHandlers.size(); i++) + { + final ElementReadHandler handler = + (ElementReadHandler) otherHandlers.get(i); + masterStyles.getOtherNodes().addNode(handler.getElement()); + } + + for (int i = 0; i < masterPageHandlers.size(); i++) + { + final MasterPageReadHandler handler = + (MasterPageReadHandler) masterPageHandlers.get(i); + masterStyles.addMasterPage(handler.getMasterPage()); + } + } + + public Element getElement() + { + return masterStyles; + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt-schema-v1.0-os.xsd b/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt-schema-v1.0-os.xsd new file mode 100644 index 000000000000..82984c73afe2 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt-schema-v1.0-os.xsd @@ -0,0 +1,414 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + + Copyright 2000, 2010 Oracle and/or its affiliates. + + OpenOffice.org - a multi-platform office productivity suite + + This file is part of OpenOffice.org. + + OpenOffice.org is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + OpenOffice.org is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details + (a copy is included in the LICENSE file that accompanied this code). + + You should have received a copy of the GNU Lesser General Public License + version 3 along with OpenOffice.org. If not, see + <http://www.openoffice.org/license.html> + for a copy of the LGPLv3 License. + + --> + +<!----> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" + elementFormDefault="qualified" + targetNamespace="urn:oasis:names:tc:opendocument:xmlns:report:1.0" + xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" + xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" + xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" + xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" + xmlns:xlink="http://www.w3.org/1999/xlink" + xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" + xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" + xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" + xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" + xmlns:rpt="urn:oasis:names:tc:opendocument:xmlns:report:1.0" + xmlns:anim="urn:oasis:names:tc:opendocument:xmlns:animation:1.0" + xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" + xmlns:smil="urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0" + xmlns:xforms="http://www.w3.org/2002/xforms" + xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" + xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" + xmlns:ns1="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" + xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" + xmlns:math="http://www.w3.org/1998/Math/MathML" + xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" + xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" + xmlns:dc="http://purl.org/dc/elements/1.1/"> + <xs:import namespace="http://purl.org/dc/elements/1.1/" schemaLocation="dc.xsd"/> + <xs:import namespace="http://www.w3.org/1998/Math/MathML" schemaLocation="math.xsd"/> + <xs:import namespace="http://www.w3.org/1999/xlink" schemaLocation="xlink.xsd"/> + <xs:import namespace="http://www.w3.org/2002/xforms" schemaLocation="xforms.xsd"/> + <xs:import namespace="urn:oasis:names:tc:opendocument:xmlns:animation:1.0" schemaLocation="anim.xsd"/> + <xs:import namespace="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" schemaLocation="chart.xsd"/> + <xs:import namespace="urn:oasis:names:tc:opendocument:xmlns:config:1.0" schemaLocation="config.xsd"/> + <xs:import namespace="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" schemaLocation="ns1.xsd"/> + <xs:import namespace="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" schemaLocation="dr3d.xsd"/> + <xs:import namespace="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" schemaLocation="draw.xsd"/> + <xs:import namespace="urn:oasis:names:tc:opendocument:xmlns:form:1.0" schemaLocation="form.xsd"/> + <xs:import namespace="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" schemaLocation="meta.xsd"/> + <xs:import namespace="urn:oasis:names:tc:opendocument:xmlns:office:1.0" schemaLocation="office.xsd"/> + <xs:import namespace="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" schemaLocation="presentation.xsd"/> + <xs:import namespace="urn:oasis:names:tc:opendocument:xmlns:script:1.0" schemaLocation="script.xsd"/> + <xs:import namespace="urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0" schemaLocation="smil.xsd"/> + <xs:import namespace="urn:oasis:names:tc:opendocument:xmlns:style:1.0" schemaLocation="style.xsd"/> + <xs:import namespace="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" schemaLocation="svg.xsd"/> + <xs:import namespace="urn:oasis:names:tc:opendocument:xmlns:table:1.0" schemaLocation="table.xsd"/> + <xs:import namespace="urn:oasis:names:tc:opendocument:xmlns:text:1.0" schemaLocation="OpenDocument-schema-v1.0-os.xsd"/> + <xs:import namespace="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" schemaLocation="fo.xsd"/> + <xs:attributeGroup name="office-report-attlist"> + <xs:attribute name="command-type" default="command" form="qualified"> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="table"/> + <xs:enumeration value="query"/> + <xs:enumeration value="command"/> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + <xs:attribute name="command" form="qualified" type="text:string"/> + <xs:attribute name="escape-processing" default="true" form="qualified" type="text:boolean"/> + <xs:attribute name="filter" form="qualified" type="text:string"/> + <xs:attribute name="caption" form="qualified" type="text:string"/> + </xs:attributeGroup> + <xs:element name="report-component"> + <xs:complexType> + <xs:attributeGroup ref="text:common-draw-name-attlist"/> + </xs:complexType> + </xs:element> + <xs:element name="group"> + <xs:complexType> + <xs:sequence> + <xs:element minOccurs="0" maxOccurs="unbounded" ref="rpt:function"/> + <xs:element minOccurs="0" ref="rpt:group-header"/> + <xs:choice> + <xs:element ref="rpt:group"/> + <xs:element ref="rpt:detail"/> + </xs:choice> + <xs:element minOccurs="0" ref="rpt:group-footer"/> + </xs:sequence> + <xs:attributeGroup ref="rpt:rpt-group-attlist"/> + </xs:complexType> + </xs:element> + <xs:attributeGroup name="rpt-group-attlist"> + <xs:attribute name="sort-ascending" use="required" form="qualified"> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="true"/> + <xs:enumeration value="false"/> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + <xs:attribute name="start-new-column" default="false" form="qualified"> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="true"/> + <xs:enumeration value="false"/> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + <xs:attribute name="reset-page-number" default="false" form="qualified"> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="true"/> + <xs:enumeration value="false"/> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + <xs:attribute name="print-header-on-each-page" default="false" form="qualified"> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="true"/> + <xs:enumeration value="false"/> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + <xs:attribute name="group-expression" use="required" form="qualified" type="text:string"/> + <xs:attribute name="keep-together" default="no" form="qualified"> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="no"/> + <xs:enumeration value="whole-group"/> + <xs:enumeration value="with-first-detail"/> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + </xs:attributeGroup> + <xs:element name="group-header"> + <xs:complexType> + <xs:sequence> + <xs:element ref="table:table"/> + </xs:sequence> + <xs:attributeGroup ref="rpt:rpt-group-section-attlist"/> + </xs:complexType> + </xs:element> + <xs:element name="group-footer"> + <xs:complexType> + <xs:sequence> + <xs:element ref="table:table"/> + </xs:sequence> + <xs:attributeGroup ref="rpt:rpt-group-section-attlist"/> + </xs:complexType> + </xs:element> + <xs:element name="report-header"> + <xs:complexType> + <xs:sequence> + <xs:element ref="table:table"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="page-header"> + <xs:complexType> + <xs:sequence> + <xs:element ref="table:table"/> + </xs:sequence> + <xs:attributeGroup ref="rpt:rpt-page-attlist"/> + </xs:complexType> + </xs:element> + <xs:element name="column-header"> + <xs:complexType> + <xs:sequence> + <xs:element ref="table:table"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="detail"> + <xs:complexType> + <xs:sequence> + <xs:element ref="table:table"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="column-footer"> + <xs:complexType> + <xs:sequence> + <xs:element ref="table:table"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="page-footer"> + <xs:complexType> + <xs:sequence> + <xs:element ref="table:table"/> + </xs:sequence> + <xs:attributeGroup ref="rpt:rpt-page-attlist"/> + </xs:complexType> + </xs:element> + <xs:element name="report-footer"> + <xs:complexType> + <xs:sequence> + <xs:element ref="table:table"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:attributeGroup name="rpt-page-attlist"> + <xs:attribute name="page-print-option" default="all-pages" form="qualified"> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="all-pages"/> + <xs:enumeration value="not-with-report-header"/> + <xs:enumeration value="not-with-report-footer"/> + <xs:enumeration value="not-with-report-header-nor-footer"/> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + </xs:attributeGroup> + <xs:attributeGroup name="rpt-section-attlist"> + <xs:attribute name="visible" default="true" form="qualified"> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="true"/> + <xs:enumeration value="false"/> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + <xs:attribute name="force-new-page" default="none" form="qualified"> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="none"/> + <xs:enumeration value="before-section"/> + <xs:enumeration value="after-section"/> + <xs:enumeration value="before-after-section"/> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + <xs:attribute name="new-row-or-column" default="none" form="qualified"> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="none"/> + <xs:enumeration value="before-section"/> + <xs:enumeration value="after-section"/> + <xs:enumeration value="before-after-section"/> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + <xs:attribute name="keep-together" default="false" form="qualified"> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="true"/> + <xs:enumeration value="false"/> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + </xs:attributeGroup> + <xs:attributeGroup name="rpt-group-section-attlist"> + <xs:attribute name="repeat-section" default="false" form="qualified"> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="true"/> + <xs:enumeration value="false"/> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + </xs:attributeGroup> + <xs:element name="sub-document"> + <xs:complexType> + <xs:sequence> + <xs:group ref="rpt:report-master-detail-fields"/> + <xs:element ref="rpt:report-element"/> + <xs:choice minOccurs="0"> + <xs:element ref="office:document"/> + <xs:element ref="math:math"/> + </xs:choice> + </xs:sequence> + <xs:attributeGroup ref="rpt:report-sub-document-attlist"/> + </xs:complexType> + </xs:element> + <xs:attributeGroup name="report-sub-document-attlist"> + <xs:attribute ref="xlink:href"/> + <xs:attribute ref="xlink:type"/> + <xs:attributeGroup ref="xlink:show"/> + <xs:attributeGroup ref="xlink:actuate"/> + </xs:attributeGroup> + <xs:group name="report-master-detail-fields"> + <xs:sequence> + <xs:element minOccurs="0" ref="rpt:master-detail-fields"/> + </xs:sequence> + </xs:group> + <xs:element name="master-detail-fields"> + <xs:complexType> + <xs:sequence> + <xs:element minOccurs="0" maxOccurs="unbounded" ref="rpt:master-detail-field"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="master-detail-field"> + <xs:complexType> + <xs:attribute name="master" use="required" form="qualified" type="text:string"/> + <xs:attribute name="detail" form="qualified" type="text:string"/> + </xs:complexType> + </xs:element> + <xs:element name="function"> + <xs:complexType> + <xs:attribute name="formula" use="required" form="qualified" type="text:formula"/> + <xs:attribute name="name" use="required" form="qualified" type="text:string"/> + <xs:attribute name="pre-evaluated" use="required" form="qualified"> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="true"/> + <xs:enumeration value="false"/> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + </xs:complexType> + </xs:element> + <xs:element name="report-element"> + <xs:complexType> + <xs:sequence> + <xs:element minOccurs="0" ref="rpt:conditional-print-expression"/> + <xs:element minOccurs="0" ref="rpt:report-component"/> + <xs:element minOccurs="0" maxOccurs="unbounded" ref="rpt:format-condition"/> + </xs:sequence> + <xs:attributeGroup ref="rpt:rpt-report-element-attlist"/> + </xs:complexType> + </xs:element> + <xs:attributeGroup name="rpt-report-element-attlist"> + <xs:attribute name="print-when-group-change" default="false" form="qualified"> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="true"/> + <xs:enumeration value="false"/> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + <xs:attribute name="print-repeated-values" default="true" form="qualified"> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="true"/> + <xs:enumeration value="false"/> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + </xs:attributeGroup> + <xs:element name="conditional-print-expression" type="xs:string"/> + <xs:element name="format-condition"> + <xs:complexType> + <xs:attributeGroup ref="rpt:rpt-format-condition-attlist"/> + </xs:complexType> + </xs:element> + <xs:attributeGroup name="rpt-format-condition-attlist"> + <xs:attribute name="enabled" default="false" form="qualified"> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="true"/> + <xs:enumeration value="false"/> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + <xs:attribute name="formula" form="qualified" type="text:formula"/> + </xs:attributeGroup> + <xs:element name="fixed-content"> + <xs:complexType> + <xs:sequence> + <xs:element ref="rpt:report-element"/> + <xs:element ref="text:p"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="formatted-text"> + <xs:complexType> + <xs:sequence> + <xs:element ref="rpt:report-element"/> + <xs:group ref="text:common-form-control-content"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:attributeGroup name="rpt-formatted-text-attlist"> + <xs:attributeGroup ref="text:common-data-field-attlist"/> + </xs:attributeGroup> + <xs:element name="image"> + <xs:complexType> + <xs:sequence> + <xs:element ref="rpt:report-element"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:attributeGroup name="rpt-image-attlist"> + <xs:attributeGroup ref="text:common-data-field-attlist"/> + <xs:attributeGroup ref="text:image-data"/> + <xs:attribute name="scale" use="required" form="qualified"> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="true"/> + <xs:enumeration value="false"/> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + </xs:attributeGroup> +</xs:schema> diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/ConditionalPrintExpressionReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/ConditionalPrintExpressionReadHandler.java new file mode 100644 index 000000000000..02d23aec10bd --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/ConditionalPrintExpressionReadHandler.java @@ -0,0 +1,81 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.rpt; + +import com.sun.star.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. + * + * @author Thomas Morgner + * @since 02.03.2007 + */ +public class ConditionalPrintExpressionReadHandler + extends AbstractXmlReadHandler +{ + + private final Element element; + + public ConditionalPrintExpressionReadHandler(final Element element) + { + this.element = element; + } + + 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/com/sun/star/report/pentaho/parser/rpt/DetailRootTableReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/DetailRootTableReadHandler.java new file mode 100644 index 000000000000..a8252667ff1f --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/DetailRootTableReadHandler.java @@ -0,0 +1,38 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.rpt; + +import com.sun.star.report.pentaho.model.OfficeDetailSection; + +public class DetailRootTableReadHandler extends RootTableReadHandler +{ + + public DetailRootTableReadHandler() + { + super(new OfficeDetailSection()); + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/FixedContentReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/FixedContentReadHandler.java new file mode 100644 index 000000000000..e414a1bbe16c --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/FixedContentReadHandler.java @@ -0,0 +1,98 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.rpt; + +import com.sun.star.report.OfficeToken; +import com.sun.star.report.pentaho.OfficeNamespaces; +import com.sun.star.report.pentaho.model.FixedTextElement; +import com.sun.star.report.pentaho.parser.ElementReadHandler; +import com.sun.star.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 + * + * @author Thomas Morgner + */ +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. + */ + 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 modifiy 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; + } + + public Element getElement() + { + return element; + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/FormatConditionReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/FormatConditionReadHandler.java new file mode 100644 index 000000000000..581dd79f418e --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/FormatConditionReadHandler.java @@ -0,0 +1,100 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.rpt; + +import com.sun.star.report.OfficeToken; +import com.sun.star.report.pentaho.OfficeNamespaces; +import com.sun.star.report.pentaho.model.FormatCondition; +import com.sun.star.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? + * + * @author Ocke Janssen + */ +public class FormatConditionReadHandler extends AbstractXmlReadHandler +{ + + private final ReportElement element; + + public FormatConditionReadHandler(final ReportElement element) + { + if (element == null) + { + throw new NullPointerException(); + } + this.element = element; + } + + 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/com/sun/star/report/pentaho/parser/rpt/FormattedTextReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/FormattedTextReadHandler.java new file mode 100644 index 000000000000..4c94cb910d79 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/FormattedTextReadHandler.java @@ -0,0 +1,118 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.rpt; + +import com.sun.star.report.pentaho.OfficeNamespaces; +import com.sun.star.report.pentaho.model.FormattedTextElement; +import com.sun.star.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 + * + * @author Thomas Morgner + */ +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. + */ + 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-Changes + + // * Print-When-Section-Overflows + // That property cannot be evaluated yet, as this would require us to + // have a clue about pagebreaking. We dont 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. + */ + 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 modifiy 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; + } + + public Element getElement() + { + return element; + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/FunctionReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/FunctionReadHandler.java new file mode 100644 index 000000000000..233e0692dd07 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/FunctionReadHandler.java @@ -0,0 +1,116 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.rpt; + +import com.sun.star.report.OfficeToken; +import com.sun.star.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 an unique name. + * + * @author Thomas Morgner + */ +public class FunctionReadHandler extends AbstractXmlReadHandler +{ + + private Expression expression; + + public FunctionReadHandler() + { + } + + /** + * Starts parsing. + * + * @param attrs the attributes. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + 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/com/sun/star/report/pentaho/parser/rpt/GroupReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/GroupReadHandler.java new file mode 100644 index 000000000000..3516f6e047ad --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/GroupReadHandler.java @@ -0,0 +1,182 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.rpt; + +import com.sun.star.report.OfficeToken; +import com.sun.star.report.pentaho.OfficeNamespaces; +import com.sun.star.report.pentaho.model.OfficeGroup; +import com.sun.star.report.pentaho.model.OfficeGroupInstanceSection; +import com.sun.star.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 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(); + } + + /** + * Starts parsing. + * + * @param attrs the attributes. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + 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); + } + } + + /** + * 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. + */ + 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. + */ + protected void doneParsing() throws SAXException + { + for (int i = 0; i < functionHandlers.size(); i++) + { + final FunctionReadHandler handler = + (FunctionReadHandler) 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()); + } + } + + public Element getElement() + { + return group; + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/GroupSectionReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/GroupSectionReadHandler.java new file mode 100644 index 000000000000..99a34abc1d42 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/GroupSectionReadHandler.java @@ -0,0 +1,38 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.rpt; + +import com.sun.star.report.pentaho.model.OfficeGroupSection; + +public class GroupSectionReadHandler extends RootTableReadHandler +{ + + public GroupSectionReadHandler() + { + super(new OfficeGroupSection()); + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/ImageReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/ImageReadHandler.java new file mode 100644 index 000000000000..1695eac68fe0 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/ImageReadHandler.java @@ -0,0 +1,141 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.rpt; + +import com.sun.star.report.OfficeToken; +import com.sun.star.report.pentaho.OfficeNamespaces; +import com.sun.star.report.pentaho.model.ImageElement; +import com.sun.star.report.pentaho.parser.ElementReadHandler; +import com.sun.star.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. + * + * @author Thomas Morgner + */ +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. + */ + protected void startParsing(final Attributes attrs) throws SAXException + { + super.startParsing(attrs); + final String formula = attrs.getValue(OfficeNamespaces.OOREPORT_NS, "formula"); +// final String preserveIRI = attrs.getValue(OfficeNamespaces.OOREPORT_NS, OfficeToken.PRESERVE_IRI); + if (formula != null && formula.length() != 0) + { + // now, the evaulated 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. + */ + 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 modifiy 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. + */ + protected void doneParsing() throws SAXException + { + // if we have static content (as well 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()); + } + } + + public Element getElement() + { + return contentElement; + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/MasterDetailReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/MasterDetailReadHandler.java new file mode 100644 index 000000000000..59671bfbbe60 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/MasterDetailReadHandler.java @@ -0,0 +1,109 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.rpt; + +import com.sun.star.report.pentaho.OfficeNamespaces; +import com.sun.star.report.pentaho.model.ObjectOleElement; +import com.sun.star.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; + +/** + * + * @author Ocke Janssen + */ +public class MasterDetailReadHandler extends ElementReadHandler +{ + + private final ObjectOleElement element; + private final boolean parseMasterDetail; + + public MasterDetailReadHandler(final ObjectOleElement element) + { + this.element = element; + parseMasterDetail = false; + } + + public 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. + */ + 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. + */ + 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 modifiy the current + // element (as we do not separate the elements that strictly ..) + return new MasterDetailReadHandler(element, true); + } + + return null; + } + + public Element getElement() + { + return element; + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/ReportElementReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/ReportElementReadHandler.java new file mode 100644 index 000000000000..4359581da3a6 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/ReportElementReadHandler.java @@ -0,0 +1,109 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.rpt; + +import com.sun.star.report.OfficeToken; +import com.sun.star.report.pentaho.OfficeNamespaces; +import com.sun.star.report.pentaho.model.ReportElement; +import com.sun.star.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; + } + + public Element getElement() + { + return element; + } + + /** + * Starts parsing. + * + * @param attrs the attributes. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + protected void startParsing(final Attributes attrs) + throws SAXException + { + super.startParsing(attrs); + final String printWhenGroupChanges = attrs.getValue(OfficeNamespaces.OOREPORT_NS, "print-when-group-changes"); + element.setPrintWhenGroupChanges(OfficeToken.TRUE.equals(printWhenGroupChanges)); + 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. + */ + 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/com/sun/star/report/pentaho/parser/rpt/ReportReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/ReportReadHandler.java new file mode 100644 index 000000000000..f6db6905da13 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/ReportReadHandler.java @@ -0,0 +1,239 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.rpt; + +import com.sun.star.report.pentaho.OfficeNamespaces; +import com.sun.star.report.pentaho.model.OfficeReport; +import com.sun.star.report.pentaho.parser.ElementReadHandler; +import com.sun.star.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; + + public void setDetail(final RootTableReadHandler detail) + { + this.detail = detail; + } + + public final RootTableReadHandler getDetail() + { + return detail; + } + private GroupReadHandler groups; + private final OfficeReport rootSection; + private final List functionHandlers; + private final List preBodyHandlers; + private final List postBodyHandlers; + private boolean pre = true; + + public ReportReadHandler() + { + rootSection = new OfficeReport(); + rootSection.setAttribute(JFreeReportInfo.REPORT_NAMESPACE, "simple-report-structure", Boolean.TRUE); + functionHandlers = new ArrayList(); + preBodyHandlers = new ArrayList(); + postBodyHandlers = new ArrayList(); + } + + /** + * 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. + */ + protected XmlReadHandler getHandlerForChild(final String uri, + final String tagName, + final Attributes atts) + throws SAXException + { + final XmlReadHandler erh; + if (OfficeNamespaces.CHART_NS.equals(uri)) + { + erh = new ChartReadHandler(this); + if (pre) + { + preBodyHandlers.add(erh); + } + else + { + postBodyHandlers.add(erh); + } + } + else if (OfficeNamespaces.OOREPORT_NS.equals(uri)) + { + if ("function".equals(tagName)) + { + erh = new FunctionReadHandler(); + functionHandlers.add(erh); + } + 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. + */ + 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 = + (FunctionReadHandler) functionHandlers.get(i); + rootSection.addExpression(handler.getExpression()); + } + } + + public Element getElement() + { + return rootSection; + } + + private final Section createSection(final String name, final List 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 = (ElementReadHandler) handler.get(i); + section.addNode(erh.getElement()); + } + return section; + } + return null; + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/RootTableReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/RootTableReadHandler.java new file mode 100644 index 000000000000..70075f96b017 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/RootTableReadHandler.java @@ -0,0 +1,105 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.rpt; + +import com.sun.star.report.pentaho.OfficeNamespaces; +import com.sun.star.report.pentaho.parser.ElementReadHandler; +import com.sun.star.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. + */ + 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. + */ + protected void doneParsing() + throws SAXException + { + if (sectionTableReadHandler != null) + { + section.addNode(sectionTableReadHandler.getElement()); + } + } + + public Element getElement() + { + return section; + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/SubDocumentReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/SubDocumentReadHandler.java new file mode 100644 index 000000000000..081e8bf2020e --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/rpt/SubDocumentReadHandler.java @@ -0,0 +1,137 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.rpt; + +import com.sun.star.report.OfficeToken; +import com.sun.star.report.pentaho.OfficeNamespaces; +import com.sun.star.report.pentaho.model.ObjectOleElement; +import com.sun.star.report.pentaho.parser.draw.ObjectOleReadHandler; +import com.sun.star.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; + +/** + * + * @author Ocke Janssen + */ +public class SubDocumentReadHandler extends NoCDATATextContentReadHandler +{ + + private final ObjectOleElement element; + private boolean ignore = false; + + public SubDocumentReadHandler(final ObjectOleElement element) + { + this.element = element; + } + + public 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. + */ + 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. + */ + 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 modifiy 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/com/sun/star/report/pentaho/parser/selectors.properties b/reportbuilder/java/com/sun/star/report/pentaho/parser/selectors.properties new file mode 100644 index 000000000000..19ba06839e62 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/selectors.properties @@ -0,0 +1,113 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +# x-no-translate + +# <style:style style:name="S1" style:family="graphics"> +# <style:section-properties fo:background-color="#ffffff"/> +# </style:style> +# +# gets translated into: +# +# *[draw|style-name~="S1"] + +namespaces.draw=urn:oasis:names:tc:opendocument:xmlns:drawing:1.0 +namespaces.fo=urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0 +namespaces.style=urn:oasis:names:tc:opendocument:xmlns:style:1.0 +namespaces.table=urn:oasis:names:tc:opendocument:xmlns:table:1.0 +namespaces.chart=urn:oasis:names:tc:opendocument:xmlns:chart:1.0 +namespaces.rpt=http://openoffice.org/2005/report + +# +# maps the style family type (graphics) into a style rule of the +# common form: *[<namespace>|<style-name>~="<classname>"] +# +style-family.graphic=draw +style-family.graphics=draw +style-family.control=control +style-family.report-element=rpt +style-family.table-column=table +style-family.table-row=table +style-family.table-cell=table +style-family.table=table + +# Builds the selector pattern for a star-office stylesheet +# +# 0: Namespace prefix +# 1: Style-class attribute name (from the global namespace definition) +# 2: Style-class value +style-selector.pattern=*[{0}|{1}~="{2}"] + +# +# The following properties map the OpenOffice-generic font names +# into their CSS counterparts. As I dont have a clue, whats the difference +# between modern and swiss typeface, I am ignorant for now and ignore +# them. Blame me for that :) +font-family.roman=serif +font-family.swiss=sans-serif +font-family.modern=sans-serif +font-family.decorative=fantasy +font-family.script=cursive +font-family.system=monospace + + +# +# Defines the style property mapping for the resolve process from the +# OpenOffice report format into the internal LibLayout format +# +# attr.style.<group>.<namespace>.<attr-name>=<class> +# +# Group is an selector, which corresponds to one of the sub-elements of +# the style element of the OpenDocument format. (It must match the element +# name for which the attributes are defined.) +# +# Namespace is a defined namespace prefix from this file as defined in the +# namespaces.<prefix> section above +# +# AttrName is the defined attribute name for this namespace as defined by the +# opendocument standard. +attr.style.graphic-properties.draw.textarea-vertical-align=com.sun.star.report.pentaho.parser.stylemapper.draw.TextAreaVerticalAlignMapper +attr.style.section-properties.fo.background-color=com.sun.star.report.pentaho.parser.stylemapper.fo.BackgroundColorMapper +attr.style.paragraph-properties.fo.text-align=com.sun.star.report.pentaho.parser.stylemapper.fo.TextAlignMapper +attr.style.paragraph-properties.style.vertical-align=com.sun.star.report.pentaho.parser.stylemapper.style.VerticalAlignMapper +attr.style.text-properties.fo.color=com.sun.star.report.pentaho.parser.stylemapper.fo.ColorMapper +attr.style.text-properties.style.font-name=com.sun.star.report.pentaho.parser.stylemapper.style.FontNameMapper +attr.style.text-properties.fo.font-family=com.sun.star.report.pentaho.parser.stylemapper.style.FontFamilyMapper +attr.style.table-properties.fo.background-color=com.sun.star.report.pentaho.parser.stylemapper.fo.BackgroundColorMapper +#attr.style.text-properties.style.font-style-name= +attr.style.text-properties.style.font-family-generic=com.sun.star.report.pentaho.parser.stylemapper.style.FontFamilyGenericMapper +attr.style.text-properties.style.font-pitch=com.sun.star.report.pentaho.parser.stylemapper.style.FontPitchMapper +attr.style.text-properties.fo.font-size=com.sun.star.report.pentaho.parser.stylemapper.fo.FontSizeMapper +attr.style.text-properties.fo.font-style=com.sun.star.report.pentaho.parser.stylemapper.fo.FontStyleMapper +attr.style.text-properties.style.text-underline-style=com.sun.star.report.pentaho.parser.stylemapper.style.TextUnderlineStyleMapper +attr.style.text-properties.style.text-underline-width=com.sun.star.report.pentaho.parser.stylemapper.style.TextUnderlineWidthMapper +attr.style.text-properties.style.text-underline-color=com.sun.star.report.pentaho.parser.stylemapper.style.TextUnderlineColorMapper +attr.style.text-properties.fo.font-weight=com.sun.star.report.pentaho.parser.stylemapper.fo.FontWeightMapper +attr.style.text-properties.style.text-emphasize=com.sun.star.report.pentaho.parser.stylemapper.style.TextEmphasizeMapper +attr.style.text-properties.style.font-relief=com.sun.star.report.pentaho.parser.stylemapper.style.FontReliefMapper +attr.style.table-column-properties.table.column-width=com.sun.star.report.pentaho.parser.stylemapper.table.ColumnWidthMapper +attr.style.table-row-properties.table.row-height=com.sun.star.report.pentaho.parser.stylemapper.table.RowHeightMapper +attr.style.table-cell-properties.fo.border-right=com.sun.star.report.pentaho.parser.stylemapper.fo.BorderRightMapper diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/style-mapping.txt b/reportbuilder/java/com/sun/star/report/pentaho/parser/style-mapping.txt new file mode 100644 index 000000000000..6b1ede5d98cf --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/style-mapping.txt @@ -0,0 +1,8 @@ + <style:style style:name="S1" style:family="graphics"> + <style:section-properties fo:background-color="#ffffff"/> + </style:style> + +gets translated into: + +*[draw|style-name~="S1"] + diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/style/FontFaceReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/style/FontFaceReadHandler.java new file mode 100644 index 000000000000..fb20e3783123 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/style/FontFaceReadHandler.java @@ -0,0 +1,56 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.style; + +import com.sun.star.report.pentaho.model.FontFaceElement; +import com.sun.star.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. + * + * @author Thomas Morgner + * @since 13.03.2007 + */ +public class FontFaceReadHandler extends ElementReadHandler +{ + + private final FontFaceElement fontFaceElement; + + public FontFaceReadHandler() + { + this.fontFaceElement = new FontFaceElement(); + } + + public Element getElement() + { + return fontFaceElement; + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/style/MasterPageReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/style/MasterPageReadHandler.java new file mode 100644 index 000000000000..d662e8028ab6 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/style/MasterPageReadHandler.java @@ -0,0 +1,106 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.style; + +import com.sun.star.report.pentaho.model.OfficeMasterPage; +import com.sun.star.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! + * + * @author Thomas Morgner + * @since 13.03.2007 + */ +public class MasterPageReadHandler extends ElementReadHandler +{ + + private final OfficeMasterPage masterPage; + private final List otherHandlers; + + public MasterPageReadHandler() + { + masterPage = new OfficeMasterPage(); + this.otherHandlers = new ArrayList(); + } + + 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. + */ + 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. + */ + protected void doneParsing() + throws SAXException + { + for (int i = 0; i < otherHandlers.size(); i++) + { + final ElementReadHandler handler = + (ElementReadHandler) otherHandlers.get(i); + masterPage.addNode(handler.getElement()); + } + } + + public Element getElement() + { + return masterPage; + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/style/OfficeStyleReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/style/OfficeStyleReadHandler.java new file mode 100644 index 000000000000..2433a7dfa2c1 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/style/OfficeStyleReadHandler.java @@ -0,0 +1,105 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.style; + +import com.sun.star.report.pentaho.model.OfficeStyle; +import com.sun.star.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 childs; + + public OfficeStyleReadHandler() + { + this.officeStyle = new OfficeStyle(); + this.childs = new ArrayList(); + } + + /** + * 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. + */ + protected XmlReadHandler getHandlerForChild(final String uri, + final String tagName, + final Attributes atts) + throws SAXException + { +// if (OfficeParserUtil.getInstance().isValidStyleElement(uri, tagName)) +// { +// } + final StyleDefinitionReadHandler readHandler = + new StyleDefinitionReadHandler(); + childs.add(readHandler); + return readHandler; + } + + /** + * Done parsing. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + protected void doneParsing() throws SAXException + { + for (int i = 0; i < childs.size(); i++) + { + final ElementReadHandler handler = (ElementReadHandler) childs.get(i); + officeStyle.addNode(handler.getElement()); + } + } + + public OfficeStyle getOfficeStyle() + { + return officeStyle; + } + + public Element getElement() + { + return officeStyle; + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/style/OfficeStylesReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/style/OfficeStylesReadHandler.java new file mode 100644 index 000000000000..d679c1c0f412 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/style/OfficeStylesReadHandler.java @@ -0,0 +1,143 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.style; + +import com.sun.star.report.pentaho.OfficeNamespaces; +import com.sun.star.report.pentaho.model.OfficeStyles; +import com.sun.star.report.pentaho.parser.ElementReadHandler; +import com.sun.star.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 textStyleChilds; + private final List dataStyleChilds; + private final List otherStyleChilds; + private final List pageLayoutChilds; + private final OfficeStyles officeStyles; + + public OfficeStylesReadHandler(final OfficeStyles officeStyles) + { + this.officeStyles = officeStyles; + this.pageLayoutChilds = new ArrayList(); + this.dataStyleChilds = new ArrayList(); + this.textStyleChilds = new ArrayList(); + this.otherStyleChilds = new ArrayList(); + } + + /** + * 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. + */ + 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(); + textStyleChilds.add(xrh); + return xrh; + } + else if ("page-layout".equals(tagName)) + { + final PageLayoutReadHandler prh = new PageLayoutReadHandler(); + pageLayoutChilds.add(prh); + return prh; + } + } + else if (OfficeNamespaces.DATASTYLE_NS.equals(uri)) + { + final DataStyleReadHandler xrh = new DataStyleReadHandler(false); + dataStyleChilds.add(xrh); + return xrh; + } + + final SectionReadHandler genericReadHander = new SectionReadHandler(); + otherStyleChilds.add(genericReadHander); + return genericReadHander; + } + + /** + * Done parsing. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + protected void doneParsing() throws SAXException + { + for (int i = 0; i < textStyleChilds.size(); i++) + { + final OfficeStyleReadHandler handler = + (OfficeStyleReadHandler) textStyleChilds.get(i); + officeStyles.addStyle(handler.getOfficeStyle()); + } + + for (int i = 0; i < pageLayoutChilds.size(); i++) + { + final PageLayoutReadHandler handler = + (PageLayoutReadHandler) pageLayoutChilds.get(i); + officeStyles.addPageStyle(handler.getPageLayout()); + } + + for (int i = 0; i < dataStyleChilds.size(); i++) + { + final DataStyleReadHandler handler = + (DataStyleReadHandler) dataStyleChilds.get(i); + officeStyles.addDataStyle(handler.getDataStyle()); + } + + for (int i = 0; i < otherStyleChilds.size(); i++) + { + final SectionReadHandler handler = + (SectionReadHandler) otherStyleChilds.get(i); + officeStyles.addOtherNode((Element) handler.getNode()); + } + } + + public Element getElement() + { + return officeStyles; + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/style/PageLayoutReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/style/PageLayoutReadHandler.java new file mode 100644 index 000000000000..d781a05305f7 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/style/PageLayoutReadHandler.java @@ -0,0 +1,104 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.style; + +import com.sun.star.report.pentaho.model.PageLayout; +import com.sun.star.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. + * + * @author Thomas Morgner + * @since 13.03.2007 + */ +public class PageLayoutReadHandler extends ElementReadHandler +{ + + private final PageLayout pageLayout; + private final List childs; + + public PageLayoutReadHandler() + { + this.pageLayout = new PageLayout(); + this.childs = new ArrayList(); + } + + /** + * 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. + */ + protected XmlReadHandler getHandlerForChild(final String uri, + final String tagName, + final Attributes atts) + throws SAXException + { + final StyleDefinitionReadHandler readHandler = + new StyleDefinitionReadHandler(); + childs.add(readHandler); + return readHandler; + } + + /** + * Done parsing. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + protected void doneParsing() throws SAXException + { + for (int i = 0; i < childs.size(); i++) + { + final ElementReadHandler handler = (ElementReadHandler) childs.get(i); + pageLayout.addNode(handler.getElement()); + } + } + + public PageLayout getPageLayout() + { + return pageLayout; + } + + public Element getElement() + { + return pageLayout; + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/style/StyleDefinitionReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/style/StyleDefinitionReadHandler.java new file mode 100644 index 000000000000..5dcd52d04782 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/style/StyleDefinitionReadHandler.java @@ -0,0 +1,99 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.style; + +import com.sun.star.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 childs 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 childs; + + public StyleDefinitionReadHandler() + { + this.rawSection = new Section(); + this.childs = new ArrayList(); + } + + /** + * 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. + */ + protected XmlReadHandler getHandlerForChild(final String uri, + final String tagName, + final Attributes atts) + throws SAXException + { + final StyleDefinitionReadHandler readHandler = + new StyleDefinitionReadHandler(); + childs.add(readHandler); + return readHandler; + } + + /** + * Done parsing. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + protected void doneParsing() + throws SAXException + { + for (int i = 0; i < childs.size(); i++) + { + final ElementReadHandler handler = (ElementReadHandler) childs.get(i); + rawSection.addNode(handler.getElement()); + } + } + + public Element getElement() + { + return rawSection; + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/OneOfConstantsMapper.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/OneOfConstantsMapper.java new file mode 100644 index 000000000000..2832007d5ec0 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/OneOfConstantsMapper.java @@ -0,0 +1,77 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.stylemapper; + +import com.sun.star.report.pentaho.parser.StyleMapper; + +import java.util.HashMap; +import java.util.Map; + +import org.jfree.layouting.input.style.CSSDeclarationRule; +import org.jfree.layouting.input.style.StyleKey; +import org.jfree.layouting.input.style.values.CSSValue; + + +public abstract class OneOfConstantsMapper implements StyleMapper +{ + + private final StyleKey styleKey; + private final Map mappings; + + protected OneOfConstantsMapper(final StyleKey styleKey) + { + this.styleKey = styleKey; + this.mappings = new HashMap(); + } + + public void addMapping(final String value, final CSSValue target) + { + mappings.put(value, target); + } + + public void updateStyle(final String uri, + final String attrName, + final String attrValue, + final CSSDeclarationRule targetRule) + { + final CSSValue value = lookupMapping(attrValue); + if (value != null) + { + targetRule.setPropertyValue(styleKey, value); + } + } + + public StyleKey getStyleKey() + { + return styleKey; + } + + protected CSSValue lookupMapping(final String attrValue) + { + return (CSSValue) mappings.get(attrValue); + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/draw/TextAreaVerticalAlignMapper.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/draw/TextAreaVerticalAlignMapper.java new file mode 100644 index 000000000000..eb3217022f97 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/draw/TextAreaVerticalAlignMapper.java @@ -0,0 +1,45 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.stylemapper.draw; + +import com.sun.star.report.pentaho.parser.stylemapper.OneOfConstantsMapper; + +import org.jfree.layouting.input.style.keys.box.BoxStyleKeys; +import org.jfree.layouting.input.style.values.CSSConstant; + +public class TextAreaVerticalAlignMapper extends OneOfConstantsMapper +{ + + public TextAreaVerticalAlignMapper() + { + super(BoxStyleKeys.BOX_VERTICAL_ALIGN); + addMapping("top", new CSSConstant("top")); + addMapping("bottom", new CSSConstant("bottom")); + addMapping("middle", new CSSConstant("middle")); + addMapping("justify", new CSSConstant("justify")); + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/fo/BackgroundColorMapper.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/fo/BackgroundColorMapper.java new file mode 100644 index 000000000000..f5f680ce295e --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/fo/BackgroundColorMapper.java @@ -0,0 +1,50 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.stylemapper.fo; + +import com.sun.star.report.pentaho.parser.StyleMapper; + +import org.jfree.layouting.input.style.CSSDeclarationRule; +import org.jfree.layouting.input.style.keys.border.BorderStyleKeys; +import org.jfree.layouting.input.style.values.CSSColorValue; +import org.jfree.layouting.util.ColorUtil; + +public class BackgroundColorMapper implements StyleMapper +{ + + public void updateStyle(final String uri, + final String attrName, + final String attrValue, + final CSSDeclarationRule targetRule) + { + final CSSColorValue cv = (CSSColorValue) ColorUtil.parseColor(attrValue); + if (cv != null) + { + targetRule.setPropertyValue(BorderStyleKeys.BACKGROUND_COLOR, cv); + } + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/fo/BorderRightMapper.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/fo/BorderRightMapper.java new file mode 100644 index 000000000000..c4769b9f2708 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/fo/BorderRightMapper.java @@ -0,0 +1,55 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +/* + * BorderRightMapper.java + * + * Created on 16. Februar 2007, 13:00 + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ +package com.sun.star.report.pentaho.parser.stylemapper.fo; + +import com.sun.star.report.pentaho.parser.StyleMapper; + +import org.jfree.layouting.input.style.CSSDeclarationRule; + +/** + * + * @author oj93728 + */ +public class BorderRightMapper implements StyleMapper +{ + + public void updateStyle(final String uri, + final String attrName, + final String attrValue, + final CSSDeclarationRule targetRule) + { + targetRule.setPropertyValueAsString(attrName, attrValue); + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/fo/ColorMapper.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/fo/ColorMapper.java new file mode 100644 index 000000000000..6ab7454dbc59 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/fo/ColorMapper.java @@ -0,0 +1,52 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.stylemapper.fo; + +import com.sun.star.report.pentaho.parser.StyleMapper; + +import org.jfree.layouting.input.style.CSSDeclarationRule; +import org.jfree.layouting.input.style.keys.color.ColorStyleKeys; +import org.jfree.layouting.input.style.values.CSSColorValue; +import org.jfree.layouting.util.ColorUtil; + +public class ColorMapper implements StyleMapper +{ + + public ColorMapper() + { + } + + public void updateStyle(final String uri, final String attrName, final String attrValue, + final CSSDeclarationRule targetRule) + { + final CSSColorValue cv = (CSSColorValue) ColorUtil.parseColor(attrValue); + if (cv != null) + { + targetRule.setPropertyValue(ColorStyleKeys.COLOR, cv); + } + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/fo/FontSizeMapper.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/fo/FontSizeMapper.java new file mode 100644 index 000000000000..a28c293feef3 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/fo/FontSizeMapper.java @@ -0,0 +1,46 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.stylemapper.fo; + +import com.sun.star.report.pentaho.parser.StyleMapper; + +import org.jfree.layouting.input.style.CSSDeclarationRule; +import org.jfree.layouting.input.style.keys.font.FontStyleKeys; + +public class FontSizeMapper implements StyleMapper +{ + + public FontSizeMapper() + { + } + + public void updateStyle(final String uri, final String attrName, final String attrValue, + final CSSDeclarationRule targetRule) + { + targetRule.setPropertyValueAsString(FontStyleKeys.FONT_SIZE, attrValue); + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/fo/FontStyleMapper.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/fo/FontStyleMapper.java new file mode 100644 index 000000000000..e33a3c437c46 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/fo/FontStyleMapper.java @@ -0,0 +1,46 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.stylemapper.fo; + +import com.sun.star.report.pentaho.parser.StyleMapper; + +import org.jfree.layouting.input.style.CSSDeclarationRule; +import org.jfree.layouting.input.style.keys.font.FontStyleKeys; + +public class FontStyleMapper implements StyleMapper +{ + + public FontStyleMapper() + { + } + + public void updateStyle(final String uri, final String attrName, final String attrValue, + final CSSDeclarationRule targetRule) + { + targetRule.setPropertyValueAsString(FontStyleKeys.FONT_STYLE, attrValue); + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/fo/FontWeightMapper.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/fo/FontWeightMapper.java new file mode 100644 index 000000000000..c611b09cc444 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/fo/FontWeightMapper.java @@ -0,0 +1,46 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.stylemapper.fo; + +import com.sun.star.report.pentaho.parser.StyleMapper; + +import org.jfree.layouting.input.style.CSSDeclarationRule; +import org.jfree.layouting.input.style.keys.font.FontStyleKeys; + +public class FontWeightMapper implements StyleMapper +{ + + public FontWeightMapper() + { + } + + public void updateStyle(final String uri, final String attrName, final String attrValue, + final CSSDeclarationRule targetRule) + { + targetRule.setPropertyValueAsString(FontStyleKeys.FONT_WEIGHT, attrValue); + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/fo/TextAlignMapper.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/fo/TextAlignMapper.java new file mode 100644 index 000000000000..2820dc3d83f7 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/fo/TextAlignMapper.java @@ -0,0 +1,47 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.stylemapper.fo; + +import com.sun.star.report.pentaho.parser.stylemapper.OneOfConstantsMapper; + +import org.jfree.layouting.input.style.keys.text.TextAlign; +import org.jfree.layouting.input.style.keys.text.TextStyleKeys; + +public class TextAlignMapper extends OneOfConstantsMapper +{ + + public TextAlignMapper() + { + super(TextStyleKeys.TEXT_ALIGN); + addMapping("start", TextAlign.START); + addMapping("end", TextAlign.END); + addMapping("left", TextAlign.LEFT); + addMapping("center", TextAlign.CENTER); + addMapping("right", TextAlign.RIGHT); + addMapping("justify", TextAlign.JUSTIFY); + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/FontFamilyGenericMapper.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/FontFamilyGenericMapper.java new file mode 100644 index 000000000000..c3159f54e1a3 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/FontFamilyGenericMapper.java @@ -0,0 +1,65 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.stylemapper.style; + +import com.sun.star.report.pentaho.parser.StyleMapper; + +import org.jfree.layouting.input.style.CSSDeclarationRule; +import org.jfree.layouting.input.style.keys.font.FontStyleKeys; +import org.jfree.layouting.input.style.values.CSSStringType; +import org.jfree.layouting.input.style.values.CSSStringValue; +import org.jfree.layouting.input.style.values.CSSValue; +import org.jfree.layouting.input.style.values.CSSValueList; + +public class FontFamilyGenericMapper implements StyleMapper +{ + + public FontFamilyGenericMapper() + { + } + + public void updateStyle(final String uri, final String attrName, final String attrValue, + final CSSDeclarationRule targetRule) + { + final CSSValue value = targetRule.getPropertyCSSValue(FontStyleKeys.FONT_FAMILY); + if (!(value instanceof CSSValueList)) + { + final CSSStringValue cssVal = new CSSStringValue(CSSStringType.STRING, attrValue); + targetRule.setPropertyValue(FontStyleKeys.FONT_FAMILY, + new CSSValueList(new CSSValue[] + { + cssVal + })); + } + else + { + final CSSValueList list = (CSSValueList) value; + targetRule.setPropertyValue(FontStyleKeys.FONT_FAMILY, + CSSValueList.insertLast(list, value)); + } + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/FontFamilyMapper.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/FontFamilyMapper.java new file mode 100644 index 000000000000..808c57523361 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/FontFamilyMapper.java @@ -0,0 +1,65 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.stylemapper.style; + +import com.sun.star.report.pentaho.parser.StyleMapper; + +import org.jfree.layouting.input.style.CSSDeclarationRule; +import org.jfree.layouting.input.style.keys.font.FontStyleKeys; +import org.jfree.layouting.input.style.values.CSSStringType; +import org.jfree.layouting.input.style.values.CSSStringValue; +import org.jfree.layouting.input.style.values.CSSValue; +import org.jfree.layouting.input.style.values.CSSValueList; + +public class FontFamilyMapper implements StyleMapper +{ + + public FontFamilyMapper() + { + } + + public void updateStyle(final String uri, final String attrName, final String attrValue, + final CSSDeclarationRule targetRule) + { + final CSSValue value = targetRule.getPropertyCSSValue(FontStyleKeys.FONT_FAMILY); + if (!(value instanceof CSSValueList)) + { + final CSSStringValue cssVal = new CSSStringValue(CSSStringType.STRING, attrValue); + targetRule.setPropertyValue(FontStyleKeys.FONT_FAMILY, + new CSSValueList(new CSSValue[] + { + cssVal + })); + } + else + { + final CSSValueList list = (CSSValueList) value; + targetRule.setPropertyValue(FontStyleKeys.FONT_FAMILY, + CSSValueList.insertFirst(list, value)); + } + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/FontNameMapper.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/FontNameMapper.java new file mode 100644 index 000000000000..8cc6721cffc3 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/FontNameMapper.java @@ -0,0 +1,49 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.stylemapper.style; + +import com.sun.star.report.pentaho.parser.StyleMapper; + +import org.jfree.layouting.input.style.CSSDeclarationRule; +import org.jfree.layouting.input.style.keys.font.FontStyleKeys; +import org.jfree.layouting.input.style.values.CSSStringType; +import org.jfree.layouting.input.style.values.CSSStringValue; + +public class FontNameMapper implements StyleMapper +{ + + public FontNameMapper() + { + } + + public void updateStyle(final String uri, final String attrName, final String attrValue, + final CSSDeclarationRule targetRule) + { + targetRule.setPropertyValue(FontStyleKeys.FONT_NAME, + new CSSStringValue(CSSStringType.STRING, attrValue)); + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/FontPitchMapper.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/FontPitchMapper.java new file mode 100644 index 000000000000..c7f10d61cb00 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/FontPitchMapper.java @@ -0,0 +1,43 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.stylemapper.style; + +import com.sun.star.report.pentaho.parser.stylemapper.OneOfConstantsMapper; + +import org.jfree.layouting.input.style.keys.font.FontStyleKeys; +import org.jfree.layouting.input.style.values.CSSConstant; + +public class FontPitchMapper extends OneOfConstantsMapper +{ + + public FontPitchMapper() + { + super(FontStyleKeys.FONT_PITCH); + addMapping("variable", new CSSConstant("variable")); + addMapping("fixed", new CSSConstant("fixed")); + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/FontReliefMapper.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/FontReliefMapper.java new file mode 100644 index 000000000000..6d4f90c3beda --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/FontReliefMapper.java @@ -0,0 +1,46 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.stylemapper.style; + +import com.sun.star.report.pentaho.parser.StyleMapper; + +import org.jfree.layouting.input.style.CSSDeclarationRule; +import org.jfree.layouting.input.style.keys.font.FontStyleKeys; + +public class FontReliefMapper implements StyleMapper +{ + + public FontReliefMapper() + { + } + + public void updateStyle(final String uri, final String attrName, final String attrValue, + final CSSDeclarationRule targetRule) + { + targetRule.setPropertyValueAsString(FontStyleKeys.FONT_EFFECT, attrValue); + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/TextEmphasizeMapper.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/TextEmphasizeMapper.java new file mode 100644 index 000000000000..1ba4c480d58d --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/TextEmphasizeMapper.java @@ -0,0 +1,45 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.stylemapper.style; + +import com.sun.star.report.pentaho.parser.StyleMapper; + +import org.jfree.layouting.input.style.CSSDeclarationRule; + +public class TextEmphasizeMapper implements StyleMapper +{ + + public TextEmphasizeMapper() + { + } + + public void updateStyle(final String uri, final String attrName, final String attrValue, + final CSSDeclarationRule targetRule) + { + targetRule.setPropertyValueAsString("font-emphasize", attrValue); + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/TextUnderlineColorMapper.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/TextUnderlineColorMapper.java new file mode 100644 index 000000000000..f247f2c171fc --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/TextUnderlineColorMapper.java @@ -0,0 +1,54 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.stylemapper.style; + +import com.sun.star.report.pentaho.parser.StyleMapper; + +import org.jfree.layouting.input.style.CSSDeclarationRule; +import org.jfree.layouting.input.style.keys.text.TextStyleKeys; +import org.jfree.layouting.input.style.values.CSSColorValue; +import org.jfree.layouting.util.ColorUtil; + +public class TextUnderlineColorMapper implements StyleMapper +{ + + public TextUnderlineColorMapper() + { + } + + public void updateStyle(final String uri, + final String attrName, + final String attrValue, + final CSSDeclarationRule targetRule) + { + final CSSColorValue cv = (CSSColorValue) ColorUtil.parseColor(attrValue); + if (cv != null) + { + targetRule.setPropertyValue(TextStyleKeys.TEXT_UNDERLINE_COLOR, cv); + } + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/TextUnderlineStyleMapper.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/TextUnderlineStyleMapper.java new file mode 100644 index 000000000000..bfb1f64a8035 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/TextUnderlineStyleMapper.java @@ -0,0 +1,49 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.stylemapper.style; + +import com.sun.star.report.pentaho.parser.stylemapper.OneOfConstantsMapper; + +import org.jfree.layouting.input.style.keys.text.TextDecorationStyle; +import org.jfree.layouting.input.style.keys.text.TextStyleKeys; + +public class TextUnderlineStyleMapper extends OneOfConstantsMapper +{ + + public TextUnderlineStyleMapper() + { + super(TextStyleKeys.TEXT_UNDERLINE_STYLE); + addMapping("none", TextDecorationStyle.NONE); + addMapping("solid", TextDecorationStyle.SOLID); + addMapping("dotted", TextDecorationStyle.DOTTED); + addMapping("dash", TextDecorationStyle.DASHED); + addMapping("long-dash", TextDecorationStyle.LONG_DASH); + addMapping("dot-dash", TextDecorationStyle.DOT_DASH); + addMapping("dot-dot-dash", TextDecorationStyle.DOT_DOT_DASH); + addMapping("wave", TextDecorationStyle.WAVE); + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/TextUnderlineWidthMapper.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/TextUnderlineWidthMapper.java new file mode 100644 index 000000000000..63628b9ed60d --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/TextUnderlineWidthMapper.java @@ -0,0 +1,76 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.stylemapper.style; + +import com.sun.star.report.pentaho.parser.stylemapper.OneOfConstantsMapper; + +import org.jfree.layouting.input.style.CSSDeclarationRule; +import org.jfree.layouting.input.style.keys.border.BorderWidth; +import org.jfree.layouting.input.style.keys.text.TextDecorationWidth; +import org.jfree.layouting.input.style.keys.text.TextStyleKeys; +import org.jfree.layouting.input.style.values.CSSAutoValue; +import org.jfree.layouting.input.style.values.CSSValue; + +public class TextUnderlineWidthMapper extends OneOfConstantsMapper +{ + + public TextUnderlineWidthMapper() + { + super(TextStyleKeys.TEXT_UNDERLINE_WIDTH); + addMapping("auto", CSSAutoValue.getInstance()); + addMapping("normal", BorderWidth.MEDIUM); + addMapping("bold", TextDecorationWidth.BOLD); + addMapping("thin", BorderWidth.THIN); + addMapping("dash", TextDecorationWidth.DASH); + addMapping("medium", BorderWidth.MEDIUM); + addMapping("thick", BorderWidth.THICK); + } + + public void updateStyle(final String uri, + final String attrName, + final String attrValue, + final CSSDeclarationRule targetRule) + { + if (attrName == null) + { + throw new NullPointerException(); + } + + final CSSValue value = lookupMapping(attrValue); + if (value != null) + { + targetRule.setPropertyValue(getStyleKey(), value); + } + else + // percent + // positive integer + // positive length + { + targetRule.setPropertyValueAsString(getStyleKey(), attrValue); + } + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/TextUnderlineWordMode.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/TextUnderlineWordMode.java new file mode 100644 index 000000000000..9cc2a62c157e --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/TextUnderlineWordMode.java @@ -0,0 +1,43 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.stylemapper.style; + +import com.sun.star.report.pentaho.parser.stylemapper.OneOfConstantsMapper; + +import org.jfree.layouting.input.style.keys.text.TextDecorationMode; +import org.jfree.layouting.input.style.keys.text.TextStyleKeys; + +public class TextUnderlineWordMode extends OneOfConstantsMapper +{ + + public TextUnderlineWordMode() + { + super(TextStyleKeys.TEXT_UNDERLINE_MODE); + addMapping("continuous", TextDecorationMode.CONTINUOUS); + addMapping("skip-white-space", TextDecorationMode.SKIP_WHITE_SPACE); + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/VerticalAlignMapper.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/VerticalAlignMapper.java new file mode 100644 index 000000000000..9994a1413b4f --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/style/VerticalAlignMapper.java @@ -0,0 +1,47 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.stylemapper.style; + +import com.sun.star.report.pentaho.parser.stylemapper.OneOfConstantsMapper; + +import org.jfree.layouting.input.style.keys.line.LineStyleKeys; +import org.jfree.layouting.input.style.values.CSSAutoValue; +import org.jfree.layouting.input.style.values.CSSConstant; + +public class VerticalAlignMapper extends OneOfConstantsMapper +{ + + public VerticalAlignMapper() + { + super(LineStyleKeys.VERTICAL_ALIGN); + addMapping("top", new CSSConstant("top")); + addMapping("bottom", new CSSConstant("bottom")); + addMapping("middle", new CSSConstant("middle")); + addMapping("baseline", new CSSConstant("baseline")); + addMapping("auto", CSSAutoValue.getInstance()); + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/table/ColumnWidthMapper.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/table/ColumnWidthMapper.java new file mode 100644 index 000000000000..89c5769f15a6 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/table/ColumnWidthMapper.java @@ -0,0 +1,53 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.stylemapper.table; + +import com.sun.star.report.pentaho.parser.StyleMapper; + +import org.jfree.layouting.input.style.CSSDeclarationRule; +import org.jfree.layouting.input.style.keys.box.BoxStyleKeys; + +/** + * Creation-Date: 03.07.2006, 13:08:27 + * + * @author Thomas Morgner + */ +public class ColumnWidthMapper implements StyleMapper +{ + + public ColumnWidthMapper() + { + } + + public void updateStyle(final String uri, + final String attrName, + final String attrValue, + final CSSDeclarationRule targetRule) + { + targetRule.setPropertyValueAsString(BoxStyleKeys.WIDTH, attrValue); + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/table/RowHeightMapper.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/table/RowHeightMapper.java new file mode 100644 index 000000000000..5d94f4101059 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/stylemapper/table/RowHeightMapper.java @@ -0,0 +1,53 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.stylemapper.table; + +import com.sun.star.report.pentaho.parser.StyleMapper; + +import org.jfree.layouting.input.style.CSSDeclarationRule; +import org.jfree.layouting.input.style.keys.box.BoxStyleKeys; + +/** + * Creation-Date: 03.07.2006, 13:08:27 + * + * @author Thomas Morgner + */ +public class RowHeightMapper implements StyleMapper +{ + + public RowHeightMapper() + { + } + + public void updateStyle(final String uri, + final String attrName, + final String attrValue, + final CSSDeclarationRule targetRule) + { + targetRule.setPropertyValueAsString(BoxStyleKeys.HEIGHT, attrValue); + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/table/CoveredCellReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/table/CoveredCellReadHandler.java new file mode 100644 index 000000000000..34158230c3c1 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/table/CoveredCellReadHandler.java @@ -0,0 +1,54 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.table; + +import com.sun.star.report.pentaho.parser.ElementReadHandler; + +import org.jfree.report.structure.Element; +import org.jfree.report.structure.Section; + +/** + * Todo: Document me! + * + * @author Thomas Morgner + * @since 14.03.2007 + */ +public class CoveredCellReadHandler extends ElementReadHandler +{ + + private final Element coveredCell; + + public CoveredCellReadHandler() + { + coveredCell = new Section(); + } + + public Element getElement() + { + return coveredCell; + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/table/TableCellReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/table/TableCellReadHandler.java new file mode 100644 index 000000000000..9d963fd46326 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/table/TableCellReadHandler.java @@ -0,0 +1,46 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.table; + +import com.sun.star.report.pentaho.model.TableCellElement; +import com.sun.star.report.pentaho.parser.text.NoCDATATextContentReadHandler; + +/** + * A read handler for table-cell contents. This is basicly a text-content + * read handler; we may extend this implementation later. + * + * @author Thomas Morgner + * @since 05.03.2007 + */ +public class TableCellReadHandler extends NoCDATATextContentReadHandler +{ + + public TableCellReadHandler() + { + super(new TableCellElement(), true); + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/table/TableColumnReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/table/TableColumnReadHandler.java new file mode 100644 index 000000000000..4b8bc8498d91 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/table/TableColumnReadHandler.java @@ -0,0 +1,53 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.table; + +import com.sun.star.report.pentaho.parser.ElementReadHandler; + +import org.jfree.report.structure.Element; +import org.jfree.report.structure.Section; + +/** + * Creation-Date: 03.07.2006, 14:26:55 + * + * @author Thomas Morgner + */ +public class TableColumnReadHandler extends ElementReadHandler +{ + + private final Section tableColumn; + + public TableColumnReadHandler() + { + tableColumn = new Section(); + } + + public Element getElement() + { + return tableColumn; + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/table/TableColumnsReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/table/TableColumnsReadHandler.java new file mode 100644 index 000000000000..d1c23bb63957 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/table/TableColumnsReadHandler.java @@ -0,0 +1,103 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.table; + +import com.sun.star.report.OfficeToken; +import com.sun.star.report.pentaho.OfficeNamespaces; +import com.sun.star.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 + * + * @author Thomas Morgner + */ +public class TableColumnsReadHandler extends ElementReadHandler +{ + + private final List columns; + private final Section tableColumns; + + public TableColumnsReadHandler() + { + columns = new ArrayList(); + 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. + */ + 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. + */ + protected void doneParsing() throws SAXException + { + for (int i = 0; i < columns.size(); i++) + { + final TableColumnReadHandler handler = (TableColumnReadHandler) columns.get(i); + tableColumns.addNode(handler.getElement()); + } + } + + public Element getElement() + { + return tableColumns; + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/table/TableReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/table/TableReadHandler.java new file mode 100644 index 000000000000..2eb20bdc96ac --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/table/TableReadHandler.java @@ -0,0 +1,145 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.table; + +import com.sun.star.report.OfficeToken; +import com.sun.star.report.pentaho.OfficeNamespaces; +import com.sun.star.report.pentaho.model.OfficeTableSection; +import com.sun.star.report.pentaho.parser.ElementReadHandler; +import com.sun.star.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 + * + * @author Thomas Morgner + */ +public class TableReadHandler extends ElementReadHandler +{ + + private final List children; + private final Section table; + + public TableReadHandler() + { + children = new ArrayList(); + table = new OfficeTableSection(); + } + + /** + * Starts parsing. + * + * @param attrs the attributes. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + 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. + */ + 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. + */ + protected void doneParsing() throws SAXException + { + for (int i = 0; i < children.size(); i++) + { + final ElementReadHandler handler = (ElementReadHandler) children.get(i); + table.addNode(handler.getElement()); + } + } + + public Element getElement() + { + return table; + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/table/TableRowReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/table/TableRowReadHandler.java new file mode 100644 index 000000000000..d86410140103 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/table/TableRowReadHandler.java @@ -0,0 +1,126 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.table; + +import com.sun.star.report.OfficeToken; +import com.sun.star.report.pentaho.OfficeNamespaces; +import com.sun.star.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 + * + * @author Thomas Morgner + */ +public class TableRowReadHandler extends ElementReadHandler +{ + + private final List tableCells; + private final Section tableRow; + + public TableRowReadHandler() + { + tableCells = new ArrayList(); + 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. + */ + protected XmlReadHandler getHandlerForChild(final String uri, + final String tagName, + final Attributes atts) + throws SAXException + { + final XmlReadHandler 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. + */ + protected void doneParsing() throws SAXException + { + for (int i = 0; i < tableCells.size(); i++) + { + final ElementReadHandler handler = (ElementReadHandler) 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. + */ + public Element getElement() + { + return tableRow; + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/table/TableRowsReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/table/TableRowsReadHandler.java new file mode 100644 index 000000000000..00a61ffb8573 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/table/TableRowsReadHandler.java @@ -0,0 +1,102 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.table; + +import com.sun.star.report.OfficeToken; +import com.sun.star.report.pentaho.OfficeNamespaces; +import com.sun.star.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; + + +/** + * + * @author Ocke Janssen + */ +public class TableRowsReadHandler extends ElementReadHandler +{ + + private final List rows; + private final Section tableRows; + + public TableRowsReadHandler() + { + rows = new ArrayList(); + 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. + */ + 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. + */ + protected void doneParsing() throws SAXException + { + for (int i = 0; i < rows.size(); i++) + { + final TableRowReadHandler handler = (TableRowReadHandler) rows.get(i); + tableRows.addNode(handler.getElement()); + } + } + + public Element getElement() + { + return tableRows; + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/text/NoCDATATextContentReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/text/NoCDATATextContentReadHandler.java new file mode 100644 index 000000000000..95ba86623639 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/text/NoCDATATextContentReadHandler.java @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2007, Your Corporation. All Rights Reserved. + */ +package com.sun.star.report.pentaho.parser.text; + +import com.sun.star.report.OfficeToken; +import com.sun.star.report.pentaho.OfficeNamespaces; +import com.sun.star.report.pentaho.parser.ElementReadHandler; +import com.sun.star.report.pentaho.parser.rpt.FixedContentReadHandler; +import com.sun.star.report.pentaho.parser.rpt.FormattedTextReadHandler; +import com.sun.star.report.pentaho.parser.rpt.ImageReadHandler; +import com.sun.star.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. + * + * @author Thomas Morgner + */ +public class NoCDATATextContentReadHandler extends ElementReadHandler +{ + + private Section section; + private List children; + private boolean copyType; + + public NoCDATATextContentReadHandler(final Section section, + final boolean copyType) + { + this.children = new ArrayList(); + 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. + */ + 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. + */ + 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); + // children.add(subDocReadHandler); + 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 getChildren() + { + return children; + } + + /** + * Done parsing. + * + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + 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); + } + } + } + + public Element getElement() + { + return section; + } +} diff --git a/reportbuilder/java/com/sun/star/report/pentaho/parser/text/TextContentReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/text/TextContentReadHandler.java new file mode 100644 index 000000000000..ae0c29f13d3c --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/text/TextContentReadHandler.java @@ -0,0 +1,70 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.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. + * + * @author Thomas Morgner + */ +public class TextContentReadHandler extends NoCDATATextContentReadHandler +{ + + public TextContentReadHandler(final Section section, final boolean copyType) + { + super(section, copyType); + } + + 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. + */ + 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/com/sun/star/report/pentaho/parser/xlink/XLinkReadHandler.java b/reportbuilder/java/com/sun/star/report/pentaho/parser/xlink/XLinkReadHandler.java new file mode 100644 index 000000000000..54a6cae8eaaa --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/parser/xlink/XLinkReadHandler.java @@ -0,0 +1,97 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho.parser.xlink; + +import com.sun.star.report.pentaho.OfficeNamespaces; + +import org.pentaho.reporting.libraries.xmlns.parser.AbstractXmlReadHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * An image reference. + * + * @author Thomas Morgner + */ +public class XLinkReadHandler extends AbstractXmlReadHandler +{ + + private String uri; + private String type; + private String show; + private String actuate; + + public XLinkReadHandler() + { + } + + /** + * Starts parsing. + * + * @param attrs the attributes. + * @throws org.xml.sax.SAXException if there is a parsing error. + */ + protected void startParsing(final Attributes attrs) throws SAXException + { + uri = attrs.getValue(OfficeNamespaces.XLINK_NS, "uri"); + type = attrs.getValue(OfficeNamespaces.XLINK_NS, "type"); + show = attrs.getValue(OfficeNamespaces.XLINK_NS, "show"); + actuate = attrs.getValue(OfficeNamespaces.XLINK_NS, "actuate"); + } + + /** + * 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; + } + + public String getUri() + { + return uri; + } + + public String getType() + { + return type; + } + + public String getShow() + { + return show; + } + + public String getActuate() + { + return actuate; + } +} |