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 :
20 : #ifndef INCLUDED_WW8RESOURCEMODEL_HXX
21 : #define INCLUDED_WW8RESOURCEMODEL_HXX
22 :
23 : #include <string>
24 : #include <memory>
25 : #include <boost/shared_ptr.hpp>
26 : #include <sal/types.h>
27 : #include <com/sun/star/drawing/XShape.hpp>
28 : #include <com/sun/star/uno/Any.hxx>
29 : #include <WriterFilterDllApi.hxx>
30 : /**
31 : @file WW8ResourceModel.hxx
32 :
33 : The classes in this file define the interfaces for the resource
34 : model of the DocTokenizer:
35 :
36 : @image html doctok.png
37 :
38 : A resource is a set of events that describe an object. A resource
39 : is only an abstract concept. It is not instanciated to a class.
40 :
41 : A reference to a resource represents the object that the resource
42 : describes. The reference can be resolved thereby generating the
43 : events of the resource.
44 :
45 : A handler receives the events generated by resolving a
46 : reference. There are several types of handlers each accepting their
47 : specific set of events.
48 :
49 : References always have a parameter determining the kind of handler
50 : they send the events they generate to. The set of events generated
51 : by resolving the reference is a subset of the events received by
52 : the handler.
53 : */
54 :
55 :
56 : typedef sal_uInt32 Id;
57 :
58 : namespace writerfilter {
59 : using namespace ::com::sun::star;
60 : using namespace ::std;
61 :
62 : /**
63 : Reference to an resource that generates events and sends them to a
64 : handler.
65 :
66 : The reference can be resolved, i.e. the resource generates its
67 : events. The events must be suitable for the handler type given by
68 : the template parameter.
69 :
70 : @attention The parameter of the template does not determine the
71 : type of the reference's target. It determines the type of the handler!
72 :
73 : Example:
74 :
75 : A Word document can be represented as a stream of events. Event
76 : types in a Word document are text, properties, tables, starts and
77 : ends of groups. These can be handled by a stream handler (@see
78 : Stream). Thus a reference to a Word document is resolved by
79 : sending these events to a stream handler.
80 : */
81 :
82 : template <class T>
83 1356015 : class SAL_DLLPUBLIC_TEMPLATE Reference
84 : {
85 : public:
86 : /**
87 : Pointer to reference
88 :
89 : @attention The ownership of a reference is transfered when
90 : the reference is passed.
91 : */
92 : typedef boost::shared_ptr< Reference<T> > Pointer_t;
93 :
94 : /**
95 : Resolves the reference.
96 :
97 : The events of the references target resource are generated and
98 : send to a handler.
99 :
100 : @param rHandler handler which receives the events
101 : */
102 : virtual void resolve(T & rHandler) = 0;
103 :
104 : /**
105 : Returns the type of the reference aka the name of the access class.
106 : */
107 : virtual string getType() const = 0;
108 :
109 : protected:
110 1356015 : ~Reference() {}
111 : };
112 :
113 : class Value;
114 : class Sprm;
115 :
116 : /**
117 : Handler for properties.
118 : */
119 195742 : class Properties
120 : {
121 : public:
122 : /**
123 : Receives an attribute.
124 :
125 : @param name name of the attribute
126 : @param val value of the attribute
127 : */
128 : virtual void attribute(Id name, Value & val) = 0;
129 :
130 : /**
131 : Receives a SPRM.
132 :
133 : @param sprm the SPRM received
134 : */
135 : virtual void sprm(Sprm & sprm) = 0;
136 :
137 : protected:
138 195742 : ~Properties() {}
139 : };
140 :
141 : /**
142 : Handler for tables.
143 : */
144 6458 : class Table
145 : {
146 : public:
147 : typedef boost::shared_ptr<Table> Pointer_t;
148 :
149 : /**
150 : Receives an entry of the table.
151 :
152 : @param pos position of the entry in the table
153 : @param ref reference to properties of the entry
154 : */
155 : virtual void entry(int pos, writerfilter::Reference<Properties>::Pointer_t ref) = 0;
156 :
157 : protected:
158 6458 : ~Table() {}
159 : };
160 :
161 : /**
162 : Handler for binary objects.
163 : */
164 2090 : class BinaryObj
165 : {
166 : public:
167 : /**
168 : Receives binary data of the object.
169 :
170 : @param buf pointer to buffer containing the data
171 : @param len size of buffer
172 : @param ref reference to properties of binary object
173 : */
174 : virtual void data(const sal_uInt8* buf, size_t len,
175 : writerfilter::Reference<Properties>::Pointer_t ref) = 0;
176 :
177 : protected:
178 2090 : ~BinaryObj() {}
179 : };
180 :
181 : /**
182 : Handler for a stream.
183 : */
184 3108 : class Stream
185 : {
186 : public:
187 :
188 : /**
189 : Pointer to this stream.
190 : */
191 : typedef boost::shared_ptr<Stream> Pointer_t;
192 :
193 : /**
194 : Receives start mark for group with the same section properties.
195 : */
196 : virtual void startSectionGroup() = 0;
197 :
198 : /**
199 : Receives end mark for group with the same section properties.
200 : */
201 : virtual void endSectionGroup() = 0;
202 :
203 : /**
204 : Receives start mark for group with the same paragraph properties.
205 : */
206 : virtual void startParagraphGroup() = 0;
207 :
208 : /**
209 : Receives end mark for group with the same paragraph properties.
210 : */
211 : virtual void endParagraphGroup() = 0;
212 :
213 0 : virtual void markLastParagraphInSection( ) { };
214 :
215 : /**
216 : Receives start mark for group with the same character properties.
217 : */
218 : virtual void startCharacterGroup() = 0;
219 :
220 : /**
221 : Receives end mark for group with the same character properties.
222 : */
223 : virtual void endCharacterGroup() = 0;
224 :
225 : /**
226 : Receives a shape.
227 : */
228 : virtual void startShape( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape ) = 0;
229 :
230 : virtual void endShape( ) = 0;
231 :
232 : /**
233 : Receives 8-bit per character text.
234 :
235 : @param data buffer containing the text
236 : @param len number of characters in the text
237 : */
238 : virtual void text(const sal_uInt8 * data, size_t len) = 0;
239 :
240 : /**
241 : Receives 16-bit per character text.
242 :
243 : @param data buffer containing the text
244 : @param len number of characters in the text.
245 : */
246 : virtual void utext(const sal_uInt8 * data, size_t len) = 0;
247 :
248 : virtual void positivePercentage(const OUString& rText) = 0;
249 :
250 : /**
251 : Receives properties of the current run of text.
252 :
253 : @param ref reference to the properties
254 : */
255 : virtual void props(writerfilter::Reference<Properties>::Pointer_t ref) = 0;
256 :
257 : /**
258 : Receives table.
259 :
260 : @param name name of the table
261 : @param ref referecne to the table
262 : */
263 : virtual void table(Id name,
264 : writerfilter::Reference<Table>::Pointer_t ref) = 0;
265 :
266 : /**
267 : Receives a substream.
268 :
269 : @param name name of the substream
270 : @param ref reference to the substream
271 : */
272 : virtual void substream(Id name,
273 : writerfilter::Reference<Stream>::Pointer_t ref) = 0;
274 :
275 :
276 : /**
277 : Debugging: Receives information about current point in stream.
278 :
279 : @param info the information
280 : */
281 : virtual void info(const string & info) = 0;
282 :
283 : protected:
284 3108 : ~Stream() {}
285 : };
286 :
287 : /**
288 : A value.
289 :
290 : The methods of this class may throw exceptions if a certain aspect
291 : makes no sense for a certain value, e.g. the integer value of a
292 : string.
293 : */
294 6297186 : class Value
295 : {
296 : public:
297 : /**
298 : Pointer to a value.
299 : */
300 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
301 : typedef auto_ptr<Value> Pointer_t;
302 : SAL_WNODEPRECATED_DECLARATIONS_POP
303 :
304 6297186 : virtual ~Value() {}
305 :
306 : /**
307 : Returns integer representation of the value.
308 : */
309 : virtual int getInt() const = 0;
310 :
311 : /**
312 : Returns string representation of the value.
313 : */
314 : virtual OUString getString() const = 0;
315 :
316 : /**
317 : Returns representation of the value as uno::Any.
318 : */
319 : virtual uno::Any getAny() const = 0;
320 :
321 : /**
322 : Returns properties of this value.
323 : */
324 : virtual writerfilter::Reference<Properties>::Pointer_t getProperties() = 0;
325 :
326 : /**
327 : Returns stream of this value.
328 : */
329 : virtual writerfilter::Reference<Stream>::Pointer_t getStream() = 0;
330 :
331 : /**
332 : Returns binary object of this value.
333 : */
334 : virtual writerfilter::Reference<BinaryObj>::Pointer_t getBinary() = 0;
335 :
336 : /**
337 : Returns string representation of this value.
338 : */
339 : virtual string toString() const = 0;
340 : };
341 :
342 : /**
343 : An SPRM.
344 :
345 : */
346 2136331 : class Sprm
347 : {
348 : public:
349 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
350 : typedef auto_ptr<Sprm> Pointer_t;
351 : SAL_WNODEPRECATED_DECLARATIONS_POP
352 : enum Kind { UNKNOWN, CHARACTER, PARAGRAPH, TABLE };
353 :
354 : /**
355 : Returns id of the SPRM.
356 : */
357 : virtual sal_uInt32 getId() const = 0;
358 :
359 : /**
360 : Returns value of the SPRM.
361 : */
362 : virtual Value::Pointer_t getValue() = 0;
363 :
364 : /**
365 : Returns reference to binary object contained in the SPRM.
366 : */
367 : virtual writerfilter::Reference<BinaryObj>::Pointer_t getBinary() = 0;
368 :
369 : /**
370 : Returns reference to stream associated with the SPRM.
371 : */
372 : virtual writerfilter::Reference<Stream>::Pointer_t getStream() = 0;
373 :
374 : /**
375 : Returns reference to properties contained in the SPRM.
376 :
377 : */
378 : virtual writerfilter::Reference<Properties>::Pointer_t getProps() = 0;
379 :
380 : /**
381 : Returns the kind of this SPRM.
382 : */
383 : virtual Kind getKind() = 0;
384 :
385 : /**
386 : Returns name of sprm.
387 : */
388 : virtual string getName() const = 0;
389 :
390 : /**
391 : Returns string repesentation of sprm.
392 : */
393 : virtual string toString() const = 0;
394 :
395 : protected:
396 2136331 : ~Sprm() {}
397 : };
398 :
399 : }
400 :
401 : #endif // INCLUDED_WW8RESOURCEMODEL_HXX
402 :
403 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|