LibreOffice Module reportdesign (master) 1
xmlFixedContent.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19#include "xmlFixedContent.hxx"
20#include "xmlfilter.hxx"
21#include <xmloff/xmltoken.hxx>
24#include "xmlEnums.hxx"
25#include "xmlCell.hxx"
26#include <strings.hxx>
27#include <com/sun/star/lang/XMultiServiceFactory.hpp>
28#include <com/sun/star/report/XFormattedField.hpp>
29#include <com/sun/star/report/XFixedText.hpp>
30#include <com/sun/star/text/ControlCharacter.hpp>
31#include "xmlTable.hxx"
33#include <osl/diagnose.h>
34
35namespace rptxml
36{
37 using namespace ::com::sun::star;
38
39namespace {
40
41class OXMLCharContent: public XMLCharContext
42{
43 OXMLFixedContent* m_pFixedContent;
44
45public:
46 OXMLCharContent(
47 SvXMLImport& rImport,
48 OXMLFixedContent* _pFixedContent,
49 const uno::Reference< xml::sax::XFastAttributeList > & xAttrList,
51 bool bCount );
52 OXMLCharContent(
53 SvXMLImport& rImport,
54 OXMLFixedContent* _pFixedContent,
55 sal_Int16 nControl );
56 OXMLCharContent(const OXMLCharContent&) = delete;
57 OXMLCharContent& operator=(const OXMLCharContent&) = delete;
58
59 virtual void InsertControlCharacter(sal_Int16 _nControl) override;
60 virtual void InsertString(const OUString& _sString) override;
61};
62
63}
64
65OXMLCharContent::OXMLCharContent(
66 SvXMLImport& rImport,
67 OXMLFixedContent* _pFixedContent,
68 const uno::Reference< xml::sax::XFastAttributeList > & xAttrList,
70 bool bCount )
71 : XMLCharContext(rImport,xAttrList,c,bCount)
72 ,m_pFixedContent(_pFixedContent)
73{
74}
75
76OXMLCharContent::OXMLCharContent(
77 SvXMLImport& rImport,
78 OXMLFixedContent* _pFixedContent,
79 sal_Int16 nControl )
80 : XMLCharContext(rImport,nControl)
81 ,m_pFixedContent(_pFixedContent)
82{
83}
84
85void OXMLCharContent::InsertControlCharacter(sal_Int16 _nControl)
86{
87 switch( _nControl )
88 {
89 case ControlCharacter::LINE_BREAK:
90 m_pFixedContent->characters("\n");
91 break;
92 default:
93 OSL_FAIL("Not supported control character");
94 break;
95 }
96}
97
98void OXMLCharContent::InsertString(const OUString& _sString)
99{
100 m_pFixedContent->characters(_sString);
101}
102
103
104OXMLFixedContent::OXMLFixedContent( ORptFilter& rImport
105 ,OXMLCell& _rCell
106 ,OXMLTable* _pContainer
107 ,OXMLFixedContent* _pInP) :
108 OXMLReportElementBase( rImport,nullptr,_pContainer)
109,m_rCell(_rCell)
110,m_pInP(_pInP)
111,m_bFormattedField(false)
112{
113}
114
115
117{
118
119}
120
121
122css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLFixedContent::createFastChildContext(
123 sal_Int32 nElement,
124 const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList )
125{
126 css::uno::Reference< css::xml::sax::XFastContextHandler > xContext = OXMLReportElementBase::createFastChildContext(nElement,xAttrList);
127 if (xContext)
128 return xContext;
129
130 static constexpr char16_t s_sStringConcat[] = u" & ";
131
132 m_rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
133 switch( nElement )
134 {
135 case XML_ELEMENT(TEXT, XML_P):
136 xContext = new OXMLFixedContent(m_rImport,m_rCell,m_pContainer,this);
137 break;
138 case XML_ELEMENT(TEXT, XML_TAB):
139 xContext = new OXMLCharContent( m_rImport, this, xAttrList,
140 0x0009, false );
141 break;
142
144 xContext = new OXMLCharContent( m_rImport, this,
145 ControlCharacter::LINE_BREAK );
146 break;
147
148 case XML_ELEMENT(TEXT, XML_S):
149 xContext = new OXMLCharContent( m_rImport, this, xAttrList,
150 0x0020, true );
151 break;
153 m_sPageText += OUString::Concat(s_sStringConcat) + " PageNumber()";
154 m_bFormattedField = true;
155 break;
157 m_sPageText += OUString::Concat(s_sStringConcat) + " PageCount()";
158 m_bFormattedField = true;
159 break;
160 default:
161 ;
162 }
163 return xContext;
164}
165
166void OXMLFixedContent::endFastElement(sal_Int32 nElement)
167{
168 if ( !m_pInP )
169 return;
170
171 const Reference<XMultiServiceFactory> xFactor(m_rImport.GetModel(),uno::UNO_QUERY);
172 if ( m_bFormattedField )
173 {
174 uno::Reference< uno::XInterface> xInt = xFactor->createInstance(SERVICE_FORMATTEDFIELD);
175 Reference< report::XFormattedField > xControl(xInt,uno::UNO_QUERY);
176 xControl->setDataField("rpt:" + m_sPageText);
177 OSL_ENSURE(xControl.is(),"Could not create FormattedField!");
178 m_pInP->m_xReportComponent = xControl.get();
179 m_xReportComponent = xControl.get();
180 }
181 else
182 {
183 Reference< XFixedText > xControl(xFactor->createInstance(SERVICE_FIXEDTEXT),uno::UNO_QUERY);
184 OSL_ENSURE(xControl.is(),"Could not create FixedContent!");
185 m_pInP->m_xReportComponent = xControl.get();
186 m_xReportComponent = xControl.get();
187 xControl->setLabel(m_sLabel);
188 }
189
192
194}
195
196void OXMLFixedContent::characters( const OUString& rChars )
197{
198 m_sLabel += rChars;
199 if ( !rChars.isEmpty() )
200 {
201 static const char s_Quote[] = "\"";
202 if ( !m_sPageText.isEmpty() )
203 {
204 m_sPageText += " & ";
205 }
206
207 m_sPageText += s_Quote + rChars + s_Quote;
208 }
209}
210
211
212} // namespace rptxml
213
214
215/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void setComponent(const css::uno::Reference< css::report::XReportComponent > &_xComponent)
Definition: xmlCell.cxx:233
OXMLFixedContent * m_pInP
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
virtual void SAL_CALL characters(const OUString &rChars) override
virtual ~OXMLFixedContent() override
OXMLFixedContent(const OXMLFixedContent &)=delete
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
css::uno::Reference< css::report::XReportComponent > m_xReportComponent
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
void addCell(const css::uno::Reference< css::report::XReportComponent > &_xElement)
Definition: xmlTable.cxx:256
float u
XML_LINE_BREAK
XML_S
XML_PAGE_COUNT
XML_PAGE_NUMBER
XML_TAB
XML_P
constexpr OUStringLiteral SERVICE_FIXEDTEXT
Definition: strings.hxx:22
constexpr OUStringLiteral SERVICE_FORMATTEDFIELD
Definition: strings.hxx:23
TEXT
sal_uInt16 sal_Unicode
#define PROGRESS_BAR_STEP
Definition: xmlEnums.hxx:22
OXMLFixedContent * m_pFixedContent
#define XML_ELEMENT(prefix, name)