diff options
Diffstat (limited to 'reportbuilder/java/com/sun/star/report/pentaho/parser/rpt')
14 files changed, 1611 insertions, 0 deletions
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); + } +} |