1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef INCLUDED_WW8_EVENT_HANDLER_HXX 25 #define INCLUDED_WW8_EVENT_HANDLER_HXX 26 27 #include <string> 28 #include <memory> 29 #include <boost/shared_ptr.hpp> 30 #include <sal/types.h> 31 #include <com/sun/star/drawing/XShape.hpp> 32 #include <com/sun/star/uno/Any.hxx> 33 #include <WriterFilterDllApi.hxx> 34 #include <resourcemodel/OutputWithDepth.hxx> 35 /** 36 @file WW8ResourceModel.hxx 37 38 The classes in this file define the interfaces for the resource 39 model of the DocTokenizer: 40 41 @image html doctok.png 42 43 A resource is a set of events that describe an object. A resource 44 is only an abstract concept. It is not instanciated to a class. 45 46 A reference to a resource represents the object that the resource 47 describes. The reference can be resolved thereby generating the 48 events of the resource. 49 50 A handler receives the events generated by resolving a 51 reference. There are several types of handlers each accepting their 52 specific set of events. 53 54 References always have a parameter determining the kind of handler 55 they send the events they generate to. The set of events generated 56 by resolving the reference is a subset of the events received by 57 the handler. 58 */ 59 60 61 typedef sal_uInt32 Id; 62 63 namespace writerfilter { 64 using namespace ::com::sun::star; 65 using namespace ::std; 66 67 /** 68 Reference to an resource that generates events and sends them to a 69 handler. 70 71 The reference can be resolved, i.e. the resource generates its 72 events. The events must be suitable for the handler type given by 73 the template parameter. 74 75 @attention The parameter of the template does not determine the 76 type of the reference's target. It determines the type of the handler! 77 78 Example: 79 80 A Word document can be represented as a stream of events. Event 81 types in a Word document are text, properties, tables, starts and 82 ends of groups. These can be handled by a stream handler (@see 83 Stream). Thus a reference to a Word document is resolved by 84 sending these events to a stream handler. 85 */ 86 87 template <class T> 88 class WRITERFILTER_DLLPUBLIC Reference 89 { 90 public: 91 /** 92 Pointer to reference 93 94 @attention The ownership of a reference is transferred when 95 the reference is passed. 96 */ 97 typedef boost::shared_ptr< Reference<T> > Pointer_t; 98 ~Reference()99 virtual ~Reference() {} 100 101 /** 102 Resolves the reference. 103 104 The events of the references target resource are generated and 105 send to a handler. 106 107 @param rHandler handler which receives the events 108 */ 109 virtual void resolve(T & rHandler) = 0; 110 111 /** 112 Returns the type of the reference aka the name of the access class. 113 */ 114 virtual string getType() const = 0; 115 }; 116 117 class Value; 118 class Sprm; 119 120 /** 121 Handler for properties. 122 */ 123 class WRITERFILTER_DLLPUBLIC Properties 124 { 125 public: 126 /** 127 Receives an attribute. 128 129 @param name name of the attribute 130 @param val value of the attribute 131 */ 132 virtual void attribute(Id name, Value & val) = 0; 133 134 /** 135 Receives a SPRM. 136 137 @param sprm the SPRM received 138 */ 139 virtual void sprm(Sprm & sprm) = 0; 140 ~Properties()141 virtual ~Properties(){} 142 }; 143 144 /** 145 Handler for tables. 146 */ 147 class WRITERFILTER_DLLPUBLIC Table 148 { 149 public: 150 typedef boost::shared_ptr<Table> Pointer_t; 151 /** 152 Receives an entry of the table. 153 154 @param pos position of the entry in the table 155 @param ref reference to properties of the entry 156 */ 157 virtual void entry(int pos, writerfilter::Reference<Properties>::Pointer_t ref) = 0; 158 ~Table()159 virtual ~Table() {} 160 }; 161 162 /** 163 Handler for binary objects. 164 */ 165 class WRITERFILTER_DLLPUBLIC BinaryObj 166 { 167 public: 168 /** 169 Receives binary data of the object. 170 171 @param buf pointer to buffer containing the data 172 @param len size of buffer 173 @param ref reference to properties of binary object 174 */ 175 virtual void data(const sal_uInt8* buf, size_t len, 176 writerfilter::Reference<Properties>::Pointer_t ref) = 0; 177 ~BinaryObj()178 virtual ~BinaryObj(){} 179 }; 180 181 /** 182 Handler for a stream. 183 */ 184 class WRITERFILTER_DLLPUBLIC Stream 185 { 186 public: 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 markLastParagraphInSection()212 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 /** 248 Receives properties of the current run of text. 249 250 @param ref reference to the properties 251 */ 252 virtual void props(writerfilter::Reference<Properties>::Pointer_t ref) = 0; 253 254 /** 255 Receives table. 256 257 @param name name of the table 258 @param ref referecne to the table 259 */ 260 virtual void table(Id name, 261 writerfilter::Reference<Table>::Pointer_t ref) = 0; 262 263 /** 264 Receives a substream. 265 266 @param name name of the substream 267 @param ref reference to the substream 268 */ 269 virtual void substream(Id name, 270 writerfilter::Reference<Stream>::Pointer_t ref) = 0; 271 272 273 /** 274 Debugging: Receives information about current point in stream. 275 276 @param info the information 277 */ 278 virtual void info(const string & info) = 0; 279 ~Stream()280 virtual ~Stream() {} 281 }; 282 283 /** 284 A value. 285 286 The methods of this class may throw exceptions if a certain aspect 287 makes no sense for a certain value, e.g. the integer value of a 288 string. 289 */ 290 class WRITERFILTER_DLLPUBLIC Value 291 { 292 public: 293 /** 294 Pointer to a value. 295 */ 296 typedef auto_ptr<Value> Pointer_t; 297 298 /** 299 Returns integer representation of the value. 300 */ 301 virtual sal_Int32 getInt() const = 0; 302 303 /** 304 Returns string representation of the value. 305 */ 306 virtual ::rtl::OUString getString() const = 0; 307 308 /** 309 Returns representation of the value as uno::Any. 310 */ 311 virtual uno::Any getAny() const = 0; 312 313 /** 314 Returns properties of this value. 315 */ 316 virtual writerfilter::Reference<Properties>::Pointer_t getProperties() = 0; 317 318 /** 319 Returns stream of this value. 320 */ 321 virtual writerfilter::Reference<Stream>::Pointer_t getStream() = 0; 322 323 /** 324 Returns binary object of this value. 325 */ 326 virtual writerfilter::Reference<BinaryObj>::Pointer_t getBinary() = 0; 327 328 /** 329 Returns string representation of this value. 330 */ 331 virtual string toString() const = 0; 332 ~Value()333 virtual ~Value() {} 334 }; 335 336 /** 337 An SPRM. 338 339 */ 340 class WRITERFILTER_DLLPUBLIC Sprm 341 { 342 public: 343 typedef auto_ptr<Sprm> Pointer_t; 344 enum Kind { UNKNOWN, CHARACTER, PARAGRAPH, TABLE }; 345 /** 346 Returns id of the SPRM. 347 */ 348 virtual sal_uInt32 getId() const = 0; 349 350 /** 351 Returns value of the SPRM. 352 */ 353 virtual Value::Pointer_t getValue() = 0; 354 355 /** 356 Returns reference to binary object contained in the SPRM. 357 */ 358 virtual writerfilter::Reference<BinaryObj>::Pointer_t getBinary() = 0; 359 360 /** 361 Returns reference to stream associated with the SPRM. 362 */ 363 virtual writerfilter::Reference<Stream>::Pointer_t getStream() = 0; 364 365 /** 366 Returns reference to properties contained in the SPRM. 367 368 */ 369 virtual writerfilter::Reference<Properties>::Pointer_t getProps() = 0; 370 371 /** 372 Returns the kind of this SPRM. 373 */ 374 virtual Kind getKind() = 0; 375 376 /** 377 Returns name of sprm. 378 */ 379 virtual string getName() const = 0; 380 381 /** 382 Returns string repesentation of sprm. 383 */ 384 virtual string toString() const = 0; 385 ~Sprm()386 virtual ~Sprm() {} 387 }; 388 389 /** 390 Creates handler for a stream. 391 */ 392 Stream::Pointer_t WRITERFILTER_DLLPUBLIC createStreamHandler(); 393 394 void WRITERFILTER_DLLPUBLIC analyzerIds(); 395 Stream::Pointer_t WRITERFILTER_DLLPUBLIC createAnalyzer(); 396 397 void WRITERFILTER_DLLPUBLIC logger(string prefix, string message); 398 399 void WRITERFILTER_DLLPUBLIC dump(OutputWithDepth<string> & o, const char * name, writerfilter::Reference<Properties>::Pointer_t props); 400 void WRITERFILTER_DLLPUBLIC dump(OutputWithDepth<string> & o, const char * name, sal_uInt32 n); 401 void WRITERFILTER_DLLPUBLIC dump(OutputWithDepth<string> & /*o*/, const char * /*name*/, 402 const rtl::OUString & /*str*/); 403 void WRITERFILTER_DLLPUBLIC dump(OutputWithDepth<string> & o, const char * name, writerfilter::Reference<BinaryObj>::Pointer_t binary); 404 405 class Token_t 406 { 407 sal_Int32 m_nId; 408 #ifdef DEBUG 409 ::std::string m_string; 410 #endif 411 412 void assign(sal_Int32 nId); 413 414 public: 415 Token_t(); 416 Token_t(sal_Int32 nId); 417 virtual ~Token_t(); 418 419 sal_Int32 getId() const; 420 operator sal_Int32() const; 421 Token_t & operator = (sal_Int32 n); 422 423 #ifdef DEBUG 424 ::std::string toString() const; 425 #endif 426 }; 427 428 struct TokenHash 429 { 430 size_t operator()(const Token_t & rToken) const; 431 }; 432 433 } 434 435 436 #endif // INCLUDED_WW8_EVENT_HANDLER_HXX 437