1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: WW8ResourceModel.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef INCLUDED_WW8_EVENT_HANDLER_HXX
32 #define INCLUDED_WW8_EVENT_HANDLER_HXX
36 #include <boost/shared_ptr.hpp>
37 #include <sal/types.h>
38 #include <com/sun/star/drawing/XShape.hpp>
39 #include <com/sun/star/uno/Any.hxx>
40 #include <WriterFilterDllApi.hxx>
41 #include <resourcemodel/OutputWithDepth.hxx>
43 @file WW8ResourceModel.hxx
45 The classes in this file define the interfaces for the resource
46 model of the DocTokenizer:
48 @image html doctok.png
50 A resource is a set of events that describe an object. A resource
51 is only an abstract concept. It is not instanciated to a class.
53 A reference to a resource represents the object that the resource
54 describes. The reference can be resolved thereby generating the
55 events of the resource.
57 A handler receives the events generated by resolving a
58 reference. There are several types of handlers each accepting their
59 specific set of events.
61 References always have a parameter determining the kind of handler
62 they send the events they generate to. The set of events generated
63 by resolving the reference is a subset of the events received by
68 typedef sal_uInt32 Id
;
70 namespace writerfilter
{
71 using namespace ::com::sun::star
;
72 using namespace ::std
;
75 Reference to an resource that generates events and sends them to a
78 The reference can be resolved, i.e. the resource generates its
79 events. The events must be suitable for the handler type given by
80 the template parameter.
82 @attention The parameter of the template does not determine the
83 type of the reference's target. It determines the type of the handler!
87 A Word document can be represented as a stream of events. Event
88 types in a Word document are text, properties, tables, starts and
89 ends of groups. These can be handled by a stream handler (@see
90 Stream). Thus a reference to a Word document is resolved by
91 sending these events to a stream handler.
95 class WRITERFILTER_DLLPUBLIC Reference
101 @attention The ownership of a reference is transfered when
102 the reference is passed.
104 typedef boost::shared_ptr
< Reference
<T
> > Pointer_t
;
106 virtual ~Reference() {}
109 Resolves the reference.
111 The events of the references target resource are generated and
114 @param rHandler handler which receives the events
116 virtual void resolve(T
& rHandler
) = 0;
119 Returns the type of the reference aka the name of the access class.
121 virtual string
getType() const = 0;
128 Handler for properties.
130 class WRITERFILTER_DLLPUBLIC Properties
134 Receives an attribute.
136 @param name name of the attribute
137 @param val value of the attribute
139 virtual void attribute(Id name
, Value
& val
) = 0;
144 @param sprm the SPRM received
146 virtual void sprm(Sprm
& sprm
) = 0;
153 class WRITERFILTER_DLLPUBLIC Table
157 Receives an entry of the table.
159 @param pos position of the entry in the table
160 @param ref reference to properties of the entry
162 virtual void entry(int pos
, writerfilter::Reference
<Properties
>::Pointer_t ref
) = 0;
166 Handler for binary objects.
168 class WRITERFILTER_DLLPUBLIC BinaryObj
172 Receives binary data of the object.
174 @param buf pointer to buffer containing the data
175 @param len size of buffer
176 @param ref reference to properties of binary object
178 virtual void data(const sal_uInt8
* buf
, size_t len
,
179 writerfilter::Reference
<Properties
>::Pointer_t ref
) = 0;
183 Handler for a stream.
185 class WRITERFILTER_DLLPUBLIC Stream
189 Pointer to this stream.
191 typedef boost::shared_ptr
<Stream
> Pointer_t
;
194 Receives start mark for group with the same section properties.
196 virtual void startSectionGroup() = 0;
199 Receives end mark for group with the same section properties.
201 virtual void endSectionGroup() = 0;
204 Receives start mark for group with the same paragraph properties.
206 virtual void startParagraphGroup() = 0;
209 Receives end mark for group with the same paragraph properties.
211 virtual void endParagraphGroup() = 0;
213 virtual void markLastParagraphInSection( ) { };
216 Receives start mark for group with the same character properties.
218 virtual void startCharacterGroup() = 0;
221 Receives end mark for group with the same character properties.
223 virtual void endCharacterGroup() = 0;
228 virtual void startShape( ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShape
> xShape
) = 0;
230 virtual void endShape( ) = 0;
233 Receives 8-bit per character text.
235 @param data buffer containing the text
236 @param len number of characters in the text
238 virtual void text(const sal_uInt8
* data
, size_t len
) = 0;
241 Receives 16-bit per character text.
243 @param data buffer containing the text
244 @param len number of characters in the text.
246 virtual void utext(const sal_uInt8
* data
, size_t len
) = 0;
249 Receives properties of the current run of text.
251 @param ref reference to the properties
253 virtual void props(writerfilter::Reference
<Properties
>::Pointer_t ref
) = 0;
258 @param name name of the table
259 @param ref referecne to the table
261 virtual void table(Id name
,
262 writerfilter::Reference
<Table
>::Pointer_t ref
) = 0;
265 Receives a substream.
267 @param name name of the substream
268 @param ref reference to the substream
270 virtual void substream(Id name
,
271 writerfilter::Reference
<Stream
>::Pointer_t ref
) = 0;
275 Debugging: Receives information about current point in stream.
277 @param info the information
279 virtual void info(const string
& info
) = 0;
285 The methods of this class may throw exceptions if a certain aspect
286 makes no sense for a certain value, e.g. the integer value of a
289 class WRITERFILTER_DLLPUBLIC Value
295 typedef auto_ptr
<Value
> Pointer_t
;
298 Returns integer representation of the value.
300 virtual int getInt() const = 0;
303 Returns string representation of the value.
305 virtual ::rtl::OUString
getString() const = 0;
308 Returns representation of the value as uno::Any.
310 virtual uno::Any
getAny() const = 0;
313 Returns properties of this value.
315 virtual writerfilter::Reference
<Properties
>::Pointer_t
getProperties() = 0;
318 Returns stream of this value.
320 virtual writerfilter::Reference
<Stream
>::Pointer_t
getStream() = 0;
323 Returns binary object of this value.
325 virtual writerfilter::Reference
<BinaryObj
>::Pointer_t
getBinary() = 0;
328 Returns string representation of this value.
330 virtual string
toString() const = 0;
337 class WRITERFILTER_DLLPUBLIC Sprm
340 typedef auto_ptr
<Sprm
> Pointer_t
;
341 enum Kind
{ UNKNOWN
, CHARACTER
, PARAGRAPH
, TABLE
};
343 Returns id of the SPRM.
345 virtual sal_uInt32
getId() const = 0;
348 Returns value of the SPRM.
350 virtual Value::Pointer_t
getValue() = 0;
353 Returns reference to binary object contained in the SPRM.
355 virtual writerfilter::Reference
<BinaryObj
>::Pointer_t
getBinary() = 0;
358 Returns reference to stream associated with the SPRM.
360 virtual writerfilter::Reference
<Stream
>::Pointer_t
getStream() = 0;
363 Returns reference to properties contained in the SPRM.
366 virtual writerfilter::Reference
<Properties
>::Pointer_t
getProps() = 0;
369 Returns the kind of this SPRM.
371 virtual Kind
getKind() = 0;
374 Returns name of sprm.
376 virtual string
getName() const = 0;
379 Returns string repesentation of sprm.
381 virtual string
toString() const = 0;
385 Creates handler for a stream.
387 Stream::Pointer_t WRITERFILTER_DLLPUBLIC
createStreamHandler();
389 void WRITERFILTER_DLLPUBLIC
analyzerIds();
390 Stream::Pointer_t WRITERFILTER_DLLPUBLIC
createAnalyzer();
392 void WRITERFILTER_DLLPUBLIC
logger(string prefix
, string message
);
394 void WRITERFILTER_DLLPUBLIC
dump(OutputWithDepth
<string
> & o
, const char * name
, writerfilter::Reference
<Properties
>::Pointer_t props
);
395 void WRITERFILTER_DLLPUBLIC
dump(OutputWithDepth
<string
> & o
, const char * name
, sal_uInt32 n
);
396 void WRITERFILTER_DLLPUBLIC
dump(OutputWithDepth
<string
> & /*o*/, const char * /*name*/,
397 const rtl::OUString
& /*str*/);
398 void WRITERFILTER_DLLPUBLIC
dump(OutputWithDepth
<string
> & o
, const char * name
, writerfilter::Reference
<BinaryObj
>::Pointer_t binary
);
403 #endif // INCLUDED_WW8_EVENT_HANDLER_HXX