/src/libreoffice/xmloff/source/chart/SchXMLParagraphContext.cxx
Line | Count | Source |
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 | | |
20 | | |
21 | | #include "SchXMLParagraphContext.hxx" |
22 | | |
23 | | #include <sal/log.hxx> |
24 | | #include <xmloff/xmlimp.hxx> |
25 | | #include <xmloff/xmlnamespace.hxx> |
26 | | #include <xmloff/xmltoken.hxx> |
27 | | |
28 | | using namespace com::sun::star; |
29 | | using namespace ::xmloff::token; |
30 | | |
31 | | SchXMLParagraphContext::SchXMLParagraphContext( SvXMLImport& rImport, |
32 | | OUString& rText, |
33 | | OUString * pOutId /* = 0 */ ) : |
34 | 0 | SvXMLImportContext( rImport ), |
35 | 0 | mrText( rText ), |
36 | 0 | mpId( pOutId ) |
37 | 0 | { |
38 | 0 | } |
39 | | |
40 | | SchXMLParagraphContext::~SchXMLParagraphContext() |
41 | 0 | {} |
42 | | |
43 | | void SchXMLParagraphContext::startFastElement( |
44 | | sal_Int32 /*nElement*/, |
45 | | const uno::Reference< xml::sax::XFastAttributeList >& xAttrList ) |
46 | 0 | { |
47 | | // remember the id. It is used for storing the original cell range string in |
48 | | // a local table (cached data) |
49 | 0 | if( !mpId ) |
50 | 0 | return; |
51 | | |
52 | 0 | bool bHaveXmlId( false ); |
53 | |
|
54 | 0 | for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) ) |
55 | 0 | { |
56 | 0 | switch(aIter.getToken()) |
57 | 0 | { |
58 | 0 | case XML_ELEMENT(XML, XML_ID): |
59 | 0 | (*mpId) = aIter.toString(); |
60 | 0 | bHaveXmlId = true; |
61 | 0 | break; |
62 | 0 | case XML_ELEMENT(TEXT, XML_ID): |
63 | 0 | { // text:id shall be ignored if xml:id exists |
64 | 0 | if (!bHaveXmlId) |
65 | 0 | { |
66 | 0 | (*mpId) = aIter.toString(); |
67 | 0 | } |
68 | 0 | break; |
69 | 0 | } |
70 | 0 | default: |
71 | 0 | XMLOFF_WARN_UNKNOWN("xmloff", aIter); |
72 | 0 | } |
73 | 0 | } |
74 | 0 | } |
75 | | |
76 | | void SchXMLParagraphContext::endFastElement(sal_Int32 ) |
77 | 0 | { |
78 | 0 | mrText = maBuffer.makeStringAndClear(); |
79 | 0 | } |
80 | | |
81 | | css::uno::Reference< css::xml::sax::XFastContextHandler > SchXMLParagraphContext::createFastChildContext( |
82 | | sal_Int32 nElement, |
83 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) |
84 | 0 | { |
85 | 0 | if( nElement == XML_ELEMENT(TEXT, XML_TAB_STOP) ) |
86 | 0 | { |
87 | 0 | maBuffer.append( u'\x0009'); // tabulator |
88 | 0 | } |
89 | 0 | else if( nElement == XML_ELEMENT(TEXT, XML_LINE_BREAK) ) |
90 | 0 | { |
91 | 0 | maBuffer.append( u'\x000A'); // linefeed |
92 | 0 | } |
93 | 0 | else |
94 | 0 | XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement); |
95 | |
|
96 | 0 | return nullptr; |
97 | 0 | } |
98 | | |
99 | | void SchXMLParagraphContext::characters( const OUString& rChars ) |
100 | 0 | { |
101 | 0 | maBuffer.append( rChars ); |
102 | 0 | } |
103 | | |
104 | | SchXMLTitleParaContext::SchXMLTitleParaContext( SvXMLImport& rImport, |
105 | | std::vector<std::pair<OUString, OUString>>& rParaText) : |
106 | 0 | SvXMLImportContext( rImport ), |
107 | 0 | mrParaText( rParaText ) |
108 | 0 | { |
109 | 0 | } |
110 | | |
111 | | SchXMLTitleParaContext::~SchXMLTitleParaContext() |
112 | 0 | {} |
113 | | |
114 | | void SchXMLTitleParaContext::endFastElement(sal_Int32 ) |
115 | 0 | { |
116 | 0 | if (!maBuffer.isEmpty()) |
117 | 0 | mrParaText.push_back(std::make_pair(maStyleName, maBuffer.makeStringAndClear())); |
118 | 0 | } |
119 | | |
120 | | void SchXMLTitleParaContext::characters(const OUString& rChars) |
121 | 0 | { |
122 | 0 | maBuffer.append(rChars); |
123 | 0 | } |
124 | | |
125 | | css::uno::Reference< css::xml::sax::XFastContextHandler > SchXMLTitleParaContext::createFastChildContext( |
126 | | sal_Int32 nElement, |
127 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList) |
128 | 0 | { |
129 | 0 | if( nElement == XML_ELEMENT(TEXT, XML_SPAN) ) |
130 | 0 | { |
131 | 0 | if (!maBuffer.isEmpty()) |
132 | 0 | mrParaText.push_back(std::make_pair(maStyleName, maBuffer.makeStringAndClear())); |
133 | |
|
134 | 0 | return new SchXMLTitleSpanContext(GetImport(), mrParaText, xAttrList); |
135 | 0 | } |
136 | 0 | else if( nElement == XML_ELEMENT(TEXT, XML_TAB_STOP) ) |
137 | 0 | { |
138 | 0 | maBuffer.append( u'\x0009'); // tabulator |
139 | 0 | } |
140 | 0 | else if( nElement == XML_ELEMENT(TEXT, XML_LINE_BREAK) ) |
141 | 0 | { |
142 | 0 | maBuffer.append( u'\x000A'); // linefeed |
143 | 0 | } |
144 | 0 | else |
145 | 0 | XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement); |
146 | |
|
147 | 0 | return nullptr; |
148 | 0 | } |
149 | | |
150 | | SchXMLTitleSpanContext::SchXMLTitleSpanContext(SvXMLImport& rImport, std::vector<std::pair<OUString, OUString>>& rSpanTexts, |
151 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList) : |
152 | 0 | SvXMLImportContext(rImport), |
153 | 0 | mrSpanTexts(rSpanTexts) |
154 | 0 | { |
155 | 0 | for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) ) |
156 | 0 | { |
157 | 0 | if( aIter.getToken() == XML_ELEMENT(TEXT, XML_STYLE_NAME) ) |
158 | 0 | { |
159 | 0 | maStyleName = aIter.toString(); |
160 | 0 | break; |
161 | 0 | } |
162 | 0 | } |
163 | 0 | } |
164 | | |
165 | | SchXMLTitleSpanContext::~SchXMLTitleSpanContext() |
166 | 0 | {} |
167 | | |
168 | | void SchXMLTitleSpanContext::characters(const OUString& rChars) |
169 | 0 | { |
170 | 0 | maCharBuffer.append(rChars); |
171 | 0 | } |
172 | | |
173 | | css::uno::Reference< css::xml::sax::XFastContextHandler > SchXMLTitleSpanContext::createFastChildContext( |
174 | | sal_Int32 nElement, |
175 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/) |
176 | 0 | { |
177 | 0 | if( nElement == XML_ELEMENT(TEXT, XML_TAB_STOP) ) |
178 | 0 | { |
179 | 0 | maCharBuffer.append( u'\x0009'); // tabulator |
180 | 0 | } |
181 | 0 | else if( nElement == XML_ELEMENT(TEXT, XML_LINE_BREAK) ) |
182 | 0 | { |
183 | 0 | maCharBuffer.append( u'\x000A'); // linefeed |
184 | 0 | } |
185 | 0 | else |
186 | 0 | XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement); |
187 | |
|
188 | 0 | return nullptr; |
189 | 0 | } |
190 | | |
191 | | void SchXMLTitleSpanContext::endFastElement(sal_Int32) |
192 | 0 | { |
193 | 0 | if (!maCharBuffer.isEmpty()) |
194 | 0 | mrSpanTexts.push_back(std::make_pair(maStyleName, maCharBuffer.makeStringAndClear())); |
195 | 0 | } |
196 | | |
197 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |