diff options
10 files changed, 87 insertions, 10 deletions
diff --git a/reportbuilder/java/org/libreoffice/report/SDBCReportDataFactory.java b/reportbuilder/java/org/libreoffice/report/SDBCReportDataFactory.java index a22be04503cc..24e1fe10ba52 100644 --- a/reportbuilder/java/org/libreoffice/report/SDBCReportDataFactory.java +++ b/reportbuilder/java/org/libreoffice/report/SDBCReportDataFactory.java @@ -139,6 +139,7 @@ public class SDBCReportDataFactory implements DataSourceFactory private static final Log LOGGER = LogFactory.getLog(SDBCReportDataFactory.class); public static final String COMMAND_TYPE = "command-type"; public static final String ESCAPE_PROCESSING = "escape-processing"; + public static final String SORT_EXPRESSIONS = "sort-expressions"; public static final String GROUP_EXPRESSIONS = "group-expressions"; public static final String MASTER_VALUES = "master-values"; public static final String MASTER_COLUMNS = "master-columns"; @@ -229,10 +230,10 @@ public class SDBCReportDataFactory implements DataSourceFactory } } - private String getOrderStatement(final int commandType, final String command, final List groupExpressions) + private String getOrderStatement(final int commandType, final String command, final List sortExpressions) { final StringBuffer order = new StringBuffer(); - final int count = groupExpressions.size(); + final int count = sortExpressions.size(); if (count != 0) { try @@ -244,7 +245,7 @@ public class SDBCReportDataFactory implements DataSourceFactory { for (int i = 0; i < count; i++) { - final Object[] pair = (Object[]) groupExpressions.get(i); + final Object[] pair = (Object[]) sortExpressions.get(i); String expression = (String) pair[0]; if (!expression.startsWith(quote) && columns.hasByName(expression)) @@ -533,7 +534,7 @@ public class SDBCReportDataFactory implements DataSourceFactory WrappedTargetException, NoSuchElementException { - final StringBuffer order = new StringBuffer(getOrderStatement(commandType, command, (ArrayList<?>) parameters.get(GROUP_EXPRESSIONS))); + final StringBuffer order = new StringBuffer(getOrderStatement(commandType, command, (ArrayList<?>) parameters.get(SORT_EXPRESSIONS))); if (order.length() > 0 && commandType != CommandType.TABLE) { String statement = command; diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/PentahoReportJob.java b/reportbuilder/java/org/libreoffice/report/pentaho/PentahoReportJob.java index e1cf4f3900e9..fc8b4ff4b2d1 100644 --- a/reportbuilder/java/org/libreoffice/report/pentaho/PentahoReportJob.java +++ b/reportbuilder/java/org/libreoffice/report/pentaho/PentahoReportJob.java @@ -311,6 +311,37 @@ public class PentahoReportJob implements ReportJob } } + private void collectSortExpressions(final Node[] nodes, final List<Object[]> expressions, final FormulaParser parser, final Expression reportFunctions[]) + { + for (int i = 0; i < nodes.length; i++) + { + final Node node = nodes[i]; + if (node instanceof OfficeGroup) + { + final OfficeGroup group = (OfficeGroup) node; + final String exp = group.getSortingExpression(); + if (exp == null) + { + continue; + } + + final Object[] pair = new Object[2]; + pair[0] = exp; + pair[1] = group.getAttribute(OfficeNamespaces.OOREPORT_NS, "sort-ascending"); + expressions.add(pair); + } + else if (node instanceof OfficeDetailSection) + { + return; + } + if (node instanceof Section) + { + final Section section = (Section) node; + collectSortExpressions(section.getNodeArray(), expressions, parser, reportFunctions); + } + } + } + private void setMetaDataProperties(DefaultReportJob job) { job.getConfiguration().setConfigProperty(ReportEngineParameterNames.AUTHOR, (String) jobProperties.getProperty(ReportEngineParameterNames.AUTHOR)); @@ -343,11 +374,14 @@ public class PentahoReportJob implements ReportJob final Node[] nodes = report.getNodeArray(); final FormulaParser parser = new FormulaParser(); - final ArrayList<Object[]> expressions = new ArrayList<Object[]>(); final OfficeReport officeReport = (OfficeReport) ((Section) nodes[0]).getNode(0); final Section reportBody = (Section) officeReport.getBodySection(); - collectGroupExpressions(reportBody.getNodeArray(), expressions, parser, officeReport.getExpressions()); - parameters.put(SDBCReportDataFactory.GROUP_EXPRESSIONS, expressions); + final ArrayList<Object[]> sortExpressions = new ArrayList<Object[]>(); + collectSortExpressions(reportBody.getNodeArray(), sortExpressions, parser, officeReport.getExpressions()); + parameters.put(SDBCReportDataFactory.SORT_EXPRESSIONS, sortExpressions); + final ArrayList<Object[]> groupExpressions = new ArrayList<Object[]>(); + collectGroupExpressions(reportBody.getNodeArray(), groupExpressions, parser, officeReport.getExpressions()); + parameters.put(SDBCReportDataFactory.GROUP_EXPRESSIONS, groupExpressions); final String command = (String) officeReport.getAttribute(OfficeNamespaces.OOREPORT_NS, "command"); final String commandType = (String) officeReport.getAttribute(OfficeNamespaces.OOREPORT_NS, SDBCReportDataFactory.COMMAND_TYPE); final String escapeProcessing = (String) officeReport.getAttribute(OfficeNamespaces.OOREPORT_NS, SDBCReportDataFactory.ESCAPE_PROCESSING); diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/model/OfficeGroup.java b/reportbuilder/java/org/libreoffice/report/pentaho/model/OfficeGroup.java index b10aab188d0c..79ea585ebf3a 100644 --- a/reportbuilder/java/org/libreoffice/report/pentaho/model/OfficeGroup.java +++ b/reportbuilder/java/org/libreoffice/report/pentaho/model/OfficeGroup.java @@ -81,4 +81,15 @@ public class OfficeGroup extends Section } return instanceSection.getGroupingExpression(); } + + public String getSortingExpression() + { + final OfficeGroupInstanceSection instanceSection = + (OfficeGroupInstanceSection) findFirstChild(JFreeReportInfo.REPORT_NAMESPACE, "group-instance"); + if (instanceSection == null) + { + return null; + } + return instanceSection.getSortingExpression(); + } } diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/model/OfficeGroupInstanceSection.java b/reportbuilder/java/org/libreoffice/report/pentaho/model/OfficeGroupInstanceSection.java index a9adad301c41..cd7ed7b694c1 100644 --- a/reportbuilder/java/org/libreoffice/report/pentaho/model/OfficeGroupInstanceSection.java +++ b/reportbuilder/java/org/libreoffice/report/pentaho/model/OfficeGroupInstanceSection.java @@ -27,7 +27,20 @@ import org.jfree.report.structure.Group; public class OfficeGroupInstanceSection extends Group { + String sortingExpression; + public OfficeGroupInstanceSection() { } + + public void setSortingExpression(String s) + { + sortingExpression=s; + } + + public String getSortingExpression() + { + return sortingExpression; + } + } diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/GroupReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/GroupReadHandler.java index 22def36e179b..7843d8afd160 100644 --- a/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/GroupReadHandler.java +++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/GroupReadHandler.java @@ -77,6 +77,11 @@ public class GroupReadHandler extends ElementReadHandler function.setFormula(groupExpr); groupInstanceSection.setGroupingExpression(function); } + final String sortExpr = attrs.getValue(OfficeNamespaces.OOREPORT_NS, "sort-expression"); + if (sortExpr != null && !"".equals(sortExpr)) + { + groupInstanceSection.setSortingExpression(sortExpr); + } } /** diff --git a/reportdesign/source/filter/xml/xmlEnums.hxx b/reportdesign/source/filter/xml/xmlEnums.hxx index 53df992246ea..1d98a4d92eff 100644 --- a/reportdesign/source/filter/xml/xmlEnums.hxx +++ b/reportdesign/source/filter/xml/xmlEnums.hxx @@ -60,6 +60,7 @@ namespace rptxml XML_TOK_START_NEW_COLUMN , XML_TOK_RESET_PAGE_NUMBER , XML_TOK_PRINT_HEADER_ON_EACH_PAGE , + XML_TOK_SORT_EXPRESSION , XML_TOK_GROUP_EXPRESSION , XML_TOK_GROUP_HEADER , XML_TOK_GROUP_GROUP , diff --git a/reportdesign/source/filter/xml/xmlExport.cxx b/reportdesign/source/filter/xml/xmlExport.cxx index ba25f5e15e0e..781c71304269 100644 --- a/reportdesign/source/filter/xml/xmlExport.cxx +++ b/reportdesign/source/filter/xml/xmlExport.cxx @@ -1078,7 +1078,8 @@ sal_Bool ORptExport::exportGroup(const Reference<XReportDefinition>& _xReportDef if ( xGroup->getResetPageNumber() ) AddAttribute(XML_NAMESPACE_REPORT, XML_RESET_PAGE_NUMBER, XML_TRUE ); - ::rtl::OUString sExpression = xGroup->getExpression(); + const ::rtl::OUString sField = xGroup->getExpression(); + ::rtl::OUString sExpression = sField; if ( !sExpression.isEmpty() ) { static ::rtl::OUString s_sQuote(RTL_CONSTASCII_USTRINGPARAM("\"\"")); @@ -1097,6 +1098,7 @@ sal_Bool ORptExport::exportGroup(const Reference<XReportDefinition>& _xReportDef sFormula += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\")")); sExpression = sFormula; } + AddAttribute(XML_NAMESPACE_REPORT, XML_SORT_EXPRESSION, sField); AddAttribute(XML_NAMESPACE_REPORT, XML_GROUP_EXPRESSION,sExpression); sal_Int16 nRet = xGroup->getKeepTogether(); ::rtl::OUStringBuffer sValue; @@ -1525,6 +1527,7 @@ void ORptExport::exportGroupsExpressionAsFunction(const Reference< XGroups>& _xG ::rtl::OUString sFunction,sPrefix,sPostfix; ::rtl::OUString sExpression = xGroup->getExpression(); ::rtl::OUString sFunctionName; + ::rtl::OUString sInitialFormula; switch(nGroupOn) { case report::GroupOn::PREFIX_CHARACTERS: @@ -1558,14 +1561,18 @@ void ORptExport::exportGroupsExpressionAsFunction(const Reference< XGroups>& _xG { sFunction = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("INT")); uno::Reference< XFunction> xCountFunction = xFunctions->createFunction(); - xCountFunction->setInitialFormula(beans::Optional< ::rtl::OUString>(sal_True,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:1")))); + xCountFunction->setInitialFormula(beans::Optional< ::rtl::OUString>(sal_True,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:0")))); ::rtl::OUString sCountName = sFunction + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_count_")) + sExpression; xCountFunction->setName(sCountName); xCountFunction->setFormula(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:[")) + sCountName + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("] + 1"))); exportFunction(xCountFunction); sExpression = sCountName; - sPrefix = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" / ")) + ::rtl::OUString::valueOf(xGroup->getGroupInterval()); + // The reference to sCountName in the formula of sFunctionName refers to the *old* value + // so we need to expand the the formula of sCountName + sPrefix = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" + 1) / ")) + ::rtl::OUString::valueOf(xGroup->getGroupInterval()); sFunctionName = sFunction + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_")) + sExpression; + sFunction = sFunction + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("(")); + sInitialFormula = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:0")); } break; default: @@ -1580,6 +1587,8 @@ void ORptExport::exportGroupsExpressionAsFunction(const Reference< XGroups>& _xG sFunctionName = sFunctionName.replace(pReplaceChars[j],'_'); xFunction->setName(sFunctionName); + if ( !sInitialFormula.isEmpty() ) + xFunction->setInitialFormula(beans::Optional< ::rtl::OUString>(sal_True, sInitialFormula)); sFunction = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:")) + sFunction; sFunction += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("([")); sFunction += sExpression; diff --git a/reportdesign/source/filter/xml/xmlfilter.cxx b/reportdesign/source/filter/xml/xmlfilter.cxx index 22fbd1550575..71c8e679c577 100644 --- a/reportdesign/source/filter/xml/xmlfilter.cxx +++ b/reportdesign/source/filter/xml/xmlfilter.cxx @@ -797,6 +797,7 @@ const SvXMLTokenMap& ORptFilter::GetGroupElemTokenMap() const { XML_NAMESPACE_REPORT, XML_RESET_PAGE_NUMBER , XML_TOK_RESET_PAGE_NUMBER }, { XML_NAMESPACE_REPORT, XML_PRINT_HEADER_ON_EACH_PAGE , XML_TOK_PRINT_HEADER_ON_EACH_PAGE }, { XML_NAMESPACE_REPORT, XML_RESET_PAGE_NUMBER , XML_TOK_RESET_PAGE_NUMBER }, + { XML_NAMESPACE_REPORT, XML_SORT_EXPRESSION , XML_TOK_SORT_EXPRESSION }, { XML_NAMESPACE_REPORT, XML_GROUP_EXPRESSION , XML_TOK_GROUP_EXPRESSION }, { XML_NAMESPACE_REPORT, XML_GROUP_HEADER , XML_TOK_GROUP_HEADER }, { XML_NAMESPACE_REPORT, XML_GROUP , XML_TOK_GROUP_GROUP }, diff --git a/xmloff/inc/xmloff/xmltoken.hxx b/xmloff/inc/xmloff/xmltoken.hxx index e7e886eb72fd..605256f9229e 100644 --- a/xmloff/inc/xmloff/xmltoken.hxx +++ b/xmloff/inc/xmloff/xmltoken.hxx @@ -2941,6 +2941,7 @@ namespace xmloff { namespace token { XML_START_NEW_COLUMN , XML_RESET_PAGE_NUMBER , XML_PRINT_HEADER_ON_EACH_PAGE , + XML_SORT_EXPRESSION , XML_GROUP_EXPRESSION , XML_GROUP_HEADER , XML_GROUP_FOOTER , diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx index afd52bad83a9..46e3a4f46083 100644 --- a/xmloff/source/core/xmltoken.cxx +++ b/xmloff/source/core/xmltoken.cxx @@ -2937,6 +2937,7 @@ namespace xmloff { namespace token { TOKEN( "start-new-column", XML_START_NEW_COLUMN ), TOKEN( "reset-page-number", XML_RESET_PAGE_NUMBER ), TOKEN( "print-header-on-each-page", XML_PRINT_HEADER_ON_EACH_PAGE ), + TOKEN( "sort-expression", XML_SORT_EXPRESSION ), TOKEN( "group-expression", XML_GROUP_EXPRESSION ), TOKEN( "group-header", XML_GROUP_HEADER ), TOKEN( "group-footer", XML_GROUP_FOOTER ), |