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