Line data Source code
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>
22 : #include <xmloff/xmlnmspe.hxx>
23 : #include <xmloff/nmspmap.hxx>
24 : #include "xmlEnums.hxx"
25 : #include "xmlReportElement.hxx"
26 : #include <tools/debug.hxx>
27 : #include <com/sun/star/report/XShape.hpp>
28 : #include "xmlCell.hxx"
29 : #include "xmlstrings.hrc"
30 : #include <com/sun/star/report/XShape.hpp>
31 : #include <com/sun/star/report/XFormattedField.hpp>
32 : #include <com/sun/star/report/XFixedText.hpp>
33 : #include <com/sun/star/text/ControlCharacter.hpp>
34 : #include "xmlTable.hxx"
35 : #include <xmloff/XMLCharContext.hxx>
36 :
37 : namespace rptxml
38 : {
39 : using namespace ::com::sun::star;
40 :
41 0 : class OXMLCharContent : public XMLCharContext
42 : {
43 : OXMLFixedContent* m_pFixedContent;
44 : OXMLCharContent(const OXMLCharContent&);
45 : OXMLCharContent operator =(const OXMLCharContent&);
46 : public:
47 : OXMLCharContent(
48 : SvXMLImport& rImport,
49 : OXMLFixedContent* _pFixedContent,
50 : sal_uInt16 nPrfx,
51 : const ::rtl::OUString& rLName,
52 : const uno::Reference< xml::sax::XAttributeList > & xAttrList,
53 : sal_Unicode c,
54 : sal_Bool bCount );
55 : OXMLCharContent(
56 : SvXMLImport& rImport,
57 : OXMLFixedContent* _pFixedContent,
58 : sal_uInt16 nPrfx,
59 : const ::rtl::OUString& rLName,
60 : const uno::Reference< xml::sax::XAttributeList > & xAttrList,
61 : sal_Int16 nControl );
62 :
63 : virtual void InsertControlCharacter(sal_Int16 _nControl);
64 : virtual void InsertString(const ::rtl::OUString& _sString);
65 : };
66 0 : OXMLCharContent::OXMLCharContent(
67 : SvXMLImport& rImport,
68 : OXMLFixedContent* _pFixedContent,
69 : sal_uInt16 nPrfx,
70 : const ::rtl::OUString& rLName,
71 : const uno::Reference< xml::sax::XAttributeList > & xAttrList,
72 : sal_Unicode c,
73 : sal_Bool bCount )
74 : : XMLCharContext(rImport,nPrfx,rLName,xAttrList,c,bCount)
75 0 : ,m_pFixedContent(_pFixedContent)
76 : {
77 0 : }
78 : // -----------------------------------------------------------------------------
79 0 : OXMLCharContent::OXMLCharContent(
80 : SvXMLImport& rImport,
81 : OXMLFixedContent* _pFixedContent,
82 : sal_uInt16 nPrfx,
83 : const ::rtl::OUString& rLName,
84 : const uno::Reference< xml::sax::XAttributeList > & xAttrList,
85 : sal_Int16 nControl )
86 : : XMLCharContext(rImport,nPrfx,rLName,xAttrList,nControl)
87 0 : ,m_pFixedContent(_pFixedContent)
88 : {
89 0 : }
90 : // -----------------------------------------------------------------------------
91 0 : void OXMLCharContent::InsertControlCharacter(sal_Int16 _nControl)
92 : {
93 0 : switch( _nControl )
94 : {
95 : case ControlCharacter::LINE_BREAK:
96 0 : m_pFixedContent->Characters(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\n")));
97 0 : break;
98 : default:
99 : OSL_FAIL("Not supported control character");
100 0 : break;
101 : }
102 0 : }
103 : // -----------------------------------------------------------------------------
104 0 : void OXMLCharContent::InsertString(const ::rtl::OUString& _sString)
105 : {
106 0 : m_pFixedContent->Characters(_sString);
107 0 : }
108 : // -----------------------------------------------------------------------------
109 :
110 : DBG_NAME( rpt_OXMLFixedContent )
111 :
112 0 : OXMLFixedContent::OXMLFixedContent( ORptFilter& rImport,
113 : sal_uInt16 nPrfx, const ::rtl::OUString& rLName
114 : ,OXMLCell& _rCell
115 : ,OXMLTable* _pContainer
116 : ,OXMLFixedContent* _pInP) :
117 : OXMLReportElementBase( rImport, nPrfx, rLName,NULL,_pContainer)
118 : ,m_rCell(_rCell)
119 : ,m_pInP(_pInP)
120 0 : ,m_bFormattedField(false)
121 : {
122 : DBG_CTOR( rpt_OXMLFixedContent,NULL);
123 0 : }
124 : // -----------------------------------------------------------------------------
125 :
126 0 : OXMLFixedContent::~OXMLFixedContent()
127 : {
128 :
129 : DBG_DTOR( rpt_OXMLFixedContent,NULL);
130 0 : }
131 : // -----------------------------------------------------------------------------
132 : // -----------------------------------------------------------------------------
133 0 : SvXMLImportContext* OXMLFixedContent::_CreateChildContext(
134 : sal_uInt16 nPrefix,
135 : const ::rtl::OUString& rLocalName,
136 : const Reference< XAttributeList > & xAttrList )
137 : {
138 0 : SvXMLImportContext *pContext = OXMLReportElementBase::_CreateChildContext(nPrefix,rLocalName,xAttrList);
139 0 : if ( pContext )
140 0 : return pContext;
141 :
142 0 : static const ::rtl::OUString s_sStringConcat(RTL_CONSTASCII_USTRINGPARAM(" & "));
143 0 : const SvXMLTokenMap& rTokenMap = m_rImport.GetCellElemTokenMap();
144 0 : Reference<XMultiServiceFactory> xFactor = m_rImport.getServiceFactory();
145 :
146 0 : m_rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
147 0 : const sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName );
148 0 : switch( nToken )
149 : {
150 : case XML_TOK_P:
151 0 : pContext = new OXMLFixedContent(m_rImport,nPrefix, rLocalName,m_rCell,m_pContainer,this);
152 0 : break;
153 : case XML_TOK_TEXT_TAB_STOP:
154 : pContext = new OXMLCharContent( m_rImport, this,nPrefix,
155 : rLocalName, xAttrList,
156 0 : 0x0009, sal_False );
157 0 : break;
158 :
159 : case XML_TOK_TEXT_LINE_BREAK:
160 : pContext = new OXMLCharContent( m_rImport, this,nPrefix,
161 : rLocalName, xAttrList,
162 0 : ControlCharacter::LINE_BREAK );
163 0 : break;
164 :
165 : case XML_TOK_TEXT_S:
166 : pContext = new OXMLCharContent( m_rImport, this,nPrefix,
167 : rLocalName, xAttrList,
168 0 : 0x0020, sal_True );
169 0 : break;
170 : case XML_TOK_PAGE_NUMBER:
171 0 : m_sPageText += s_sStringConcat + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" PageNumber()"));
172 0 : m_bFormattedField = true;
173 0 : break;
174 : case XML_TOK_PAGE_COUNT:
175 0 : m_sPageText += s_sStringConcat + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" PageCount()"));
176 0 : m_bFormattedField = true;
177 0 : break;
178 : default:
179 : ;
180 : }
181 0 : return pContext;
182 : }
183 : // -----------------------------------------------------------------------------
184 0 : void OXMLFixedContent::EndElement()
185 : {
186 0 : if ( m_pInP )
187 : {
188 0 : const Reference<XMultiServiceFactory> xFactor(m_rImport.GetModel(),uno::UNO_QUERY);
189 0 : if ( m_bFormattedField )
190 : {
191 0 : uno::Reference< uno::XInterface> xInt = xFactor->createInstance(SERVICE_FORMATTEDFIELD);
192 0 : Reference< report::XFormattedField > xControl(xInt,uno::UNO_QUERY);
193 0 : xControl->setDataField(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:")) + m_sPageText);
194 : OSL_ENSURE(xControl.is(),"Could not create FormattedField!");
195 0 : m_pInP->m_xComponent = xControl.get();
196 0 : m_xComponent = xControl.get();
197 : }
198 : else
199 : {
200 0 : Reference< XFixedText > xControl(xFactor->createInstance(SERVICE_FIXEDTEXT),uno::UNO_QUERY);
201 : OSL_ENSURE(xControl.is(),"Could not create FixedContent!");
202 0 : m_pInP->m_xComponent = xControl.get();
203 0 : m_xComponent = xControl.get();
204 0 : xControl->setLabel(m_sLabel);
205 : }
206 :
207 0 : m_pContainer->addCell(m_xComponent);
208 0 : m_rCell.setComponent(m_xComponent);
209 :
210 0 : OXMLReportElementBase::EndElement();
211 : }
212 0 : }
213 : // -----------------------------------------------------------------------------
214 0 : void OXMLFixedContent::Characters( const ::rtl::OUString& rChars )
215 : {
216 0 : m_sLabel += rChars;
217 0 : if ( !rChars.isEmpty() )
218 : {
219 0 : static const ::rtl::OUString s_Quote(RTL_CONSTASCII_USTRINGPARAM("\""));
220 0 : if ( !m_sPageText.isEmpty() )
221 : {
222 0 : static const ::rtl::OUString s_sStringConcat(RTL_CONSTASCII_USTRINGPARAM(" & "));
223 0 : m_sPageText += s_sStringConcat;
224 : }
225 :
226 0 : m_sPageText += s_Quote + rChars + s_Quote;
227 : }
228 0 : }
229 :
230 : //----------------------------------------------------------------------------
231 : } // namespace rptxml
232 : // -----------------------------------------------------------------------------
233 :
234 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|