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 :
21 : #include <ctype.h>
22 : #include <stdio.h>
23 :
24 : #include <tools/debug.hxx>
25 :
26 : #include <basobj.hxx>
27 : #include <module.hxx>
28 : #include <globals.hxx>
29 : #include <database.hxx>
30 :
31 0 : SV_IMPL_META_FACTORY1( SvMetaObject, SvRttiBase )
32 0 : SvMetaObject::SvMetaObject()
33 : {
34 0 : }
35 :
36 0 : void SvMetaObject::Load( SvPersistStream & )
37 : {
38 0 : }
39 :
40 0 : void SvMetaObject::Save( SvPersistStream & )
41 : {
42 0 : }
43 :
44 0 : void SvMetaObject::WriteTab( SvStream & rOutStm, sal_uInt16 nTab )
45 : {
46 0 : while( nTab-- )
47 0 : rOutStm.WriteCharPtr( " " );
48 0 : }
49 :
50 0 : void SvMetaObject::WriteStars( SvStream & rOutStm )
51 : {
52 0 : rOutStm.WriteChar( '/' );
53 0 : for( int i = 6; i > 0; i-- )
54 0 : rOutStm.WriteCharPtr( "**********" );
55 0 : rOutStm.WriteChar( '/' ) << endl;
56 0 : }
57 :
58 0 : sal_Bool SvMetaObject::TestAndSeekSpaceOnly( SvStream & rOutStm, sal_uLong nBegPos )
59 : {
60 : // write no empty brackets
61 0 : sal_uLong nPos = rOutStm.Tell();
62 0 : rOutStm.Seek( nBegPos );
63 0 : sal_Bool bOnlySpace = sal_True;
64 0 : while( bOnlySpace && rOutStm.Tell() < nPos )
65 : {
66 : char c;
67 0 : rOutStm.ReadChar( c );
68 0 : if( !isspace( c ) )
69 0 : bOnlySpace = sal_False;
70 : }
71 0 : if( bOnlySpace )
72 : // nothing written
73 0 : rOutStm.Seek( nBegPos );
74 : else
75 0 : rOutStm.Seek( nPos );
76 0 : return bOnlySpace;
77 : }
78 :
79 0 : void SvMetaObject::Back2Delemitter( SvStream & rOutStm )
80 : {
81 : // write no empty brackets
82 0 : sal_uLong nPos = rOutStm.Tell();
83 0 : rOutStm.SeekRel( -1 );
84 0 : char c = 0;
85 0 : rOutStm.ReadChar( c );
86 :
87 0 : while( isspace( c ) && rOutStm.Tell() != 1 )
88 : {
89 0 : rOutStm.SeekRel( -2 );
90 0 : rOutStm.ReadChar( c );
91 : }
92 :
93 0 : if( c == ';' || c == ',' )
94 0 : rOutStm.SeekRel( -1 );
95 : else
96 0 : rOutStm.Seek( nPos );
97 0 : }
98 :
99 0 : sal_Bool SvMetaObject::ReadSvIdl( SvIdlDataBase &, SvTokenStream & )
100 : {
101 0 : return sal_False;
102 : }
103 :
104 0 : void SvMetaObject::WriteSvIdl( SvIdlDataBase &, SvStream &, sal_uInt16 /*nTab */ )
105 : {
106 0 : }
107 :
108 0 : void SvMetaObject::Write( SvIdlDataBase &, SvStream &, sal_uInt16 /*nTab */,
109 : WriteType, WriteAttribute )
110 : {
111 0 : }
112 :
113 0 : SV_IMPL_META_FACTORY1( SvMetaName, SvMetaObject );
114 0 : SvMetaName::SvMetaName()
115 : {
116 0 : }
117 :
118 0 : void SvMetaName::Load( SvPersistStream & rStm )
119 : {
120 0 : SvMetaObject::Load( rStm );
121 : sal_uInt8 nMask;
122 0 : rStm.ReadUChar( nMask );
123 :
124 0 : if( nMask >= 0x20 )
125 : {
126 0 : rStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
127 : OSL_FAIL( "wrong format" );
128 0 : return;
129 : }
130 0 : if( nMask & 0x01 ) rStm >> aName;
131 0 : if( nMask & 0x02 ) rStm >> aHelpContext;
132 0 : if( nMask & 0x04 ) rStm >> aHelpText;
133 0 : if( nMask & 0x08 ) rStm >> aConfigName;
134 0 : if( nMask & 0x10 ) rStm >> aDescription;
135 : }
136 :
137 0 : void SvMetaName::Save( SvPersistStream & rStm )
138 : {
139 0 : SvMetaObject::Save( rStm );
140 0 : sal_uInt8 nMask = 0;
141 0 : if( aName.IsSet() ) nMask |= 0x01;
142 0 : if( aHelpContext.IsSet() ) nMask |= 0x02;
143 0 : if( aHelpText.IsSet() ) nMask |= 0x04;
144 0 : if( aConfigName.IsSet() ) nMask |= 0x08;
145 0 : if( aDescription.IsSet() ) nMask |= 0x10;
146 :
147 0 : rStm.WriteUChar( nMask );
148 0 : if( nMask & 0x01 ) WriteSvString( rStm, aName );
149 0 : if( nMask & 0x02 ) WriteSvNumberIdentifier( rStm, aHelpContext );
150 0 : if( nMask & 0x04 ) WriteSvString( rStm, aHelpText );
151 0 : if( nMask & 0x08 ) WriteSvString( rStm, aConfigName );
152 0 : if( nMask & 0x10 ) WriteSvString( rStm, aDescription );
153 0 : }
154 :
155 0 : sal_Bool SvMetaName::SetName( const OString& rName, SvIdlDataBase * )
156 : {
157 0 : aName.setString(rName);
158 0 : return sal_True;
159 : }
160 :
161 0 : sal_Bool SvMetaName::ReadNameSvIdl( SvIdlDataBase & rBase,
162 : SvTokenStream & rInStm )
163 : {
164 0 : sal_uInt32 nTokPos = rInStm.Tell();
165 0 : SvToken * pTok = rInStm.GetToken_Next();
166 :
167 : // read module name
168 0 : if( pTok->IsIdentifier() )
169 0 : if( SetName( pTok->GetString(), &rBase ) )
170 0 : return sal_True;
171 :
172 0 : rInStm.Seek( nTokPos );
173 0 : return sal_False;
174 : }
175 :
176 0 : void SvMetaName::ReadAttributesSvIdl( SvIdlDataBase & rBase,
177 : SvTokenStream & rInStm )
178 : {
179 0 : sal_uInt32 nTokPos = rInStm.Tell();
180 0 : if( aName.ReadSvIdl( SvHash_Name(), rInStm ) )
181 : {
182 0 : if( !SetName( aName.getString(), &rBase ) )
183 0 : rInStm.Seek( nTokPos );
184 : }
185 :
186 0 : aHelpContext.ReadSvIdl( rBase, SvHash_HelpContext(), rInStm );
187 0 : aHelpText.ReadSvIdl( rBase, rInStm );
188 0 : aConfigName.ReadSvIdl( SvHash_ConfigName(), rInStm );
189 0 : aDescription.ReadSvIdl( SvHash_Description(), rInStm );
190 0 : }
191 :
192 0 : void SvMetaName::DoReadContextSvIdl( SvIdlDataBase & rBase,
193 : SvTokenStream & rInStm, char cDel )
194 : {
195 0 : sal_uInt32 nBeginPos = 0; // can not happen with Tell
196 0 : while( nBeginPos != rInStm.Tell() )
197 : {
198 0 : nBeginPos = rInStm.Tell();
199 0 : ReadContextSvIdl( rBase, rInStm );
200 0 : if( cDel == '\0' )
201 0 : rInStm.ReadDelemiter();
202 : else
203 0 : rInStm.Read( cDel );
204 : }
205 0 : }
206 :
207 0 : void SvMetaName::ReadContextSvIdl( SvIdlDataBase &, SvTokenStream & )
208 : {
209 0 : }
210 :
211 0 : sal_Bool SvMetaName::Test( SvIdlDataBase &, SvTokenStream & )
212 : {
213 0 : return sal_True;
214 : }
215 :
216 0 : void SvMetaName::WriteContextSvIdl( SvIdlDataBase &, SvStream &, sal_uInt16 )
217 : {
218 0 : }
219 :
220 0 : void SvMetaName::WriteDescription( SvStream & rOutStm )
221 : {
222 0 : rOutStm.WriteCharPtr( "<DESCRIPTION>" ) << endl;
223 :
224 0 : OString aDesc( GetDescription().getString() );
225 0 : sal_Int32 nPos = aDesc.indexOf('\n');
226 0 : while ( nPos != -1 )
227 : {
228 0 : rOutStm.WriteCharPtr( aDesc.copy( 0, nPos ).getStr() ) << endl;
229 0 : aDesc = aDesc.copy(nPos+1);
230 0 : nPos = aDesc.indexOf('\n');
231 : }
232 :
233 0 : rOutStm.WriteCharPtr( aDesc.getStr() ) << endl;
234 0 : rOutStm.WriteCharPtr( "</DESCRIPTION>" ) << endl;
235 0 : }
236 :
237 0 : void SvMetaName::WriteAttributesSvIdl( SvIdlDataBase & rBase,
238 : SvStream & rOutStm,
239 : sal_uInt16 nTab )
240 : {
241 0 : if( aHelpContext.IsSet() || aHelpText.IsSet() || aConfigName.IsSet() )
242 : {
243 0 : WriteTab( rOutStm, nTab );
244 0 : rOutStm.WriteCharPtr( "// class SvMetaName" ) << endl;
245 : }
246 0 : if( aHelpContext.IsSet() )
247 : {
248 0 : WriteTab( rOutStm, nTab );
249 0 : aHelpContext.WriteSvIdl( SvHash_HelpContext(), rOutStm, nTab );
250 0 : rOutStm.WriteChar( ';' ) << endl;
251 : }
252 0 : if( aHelpText.IsSet() )
253 : {
254 0 : WriteTab( rOutStm, nTab );
255 0 : aHelpText.WriteSvIdl( rBase, rOutStm, nTab );
256 0 : rOutStm.WriteChar( ';' ) << endl;
257 : }
258 0 : if( aConfigName.IsSet() )
259 : {
260 0 : WriteTab( rOutStm, nTab );
261 0 : aConfigName.WriteSvIdl( SvHash_ConfigName(), rOutStm, nTab );
262 0 : rOutStm.WriteChar( ';' ) << endl;
263 : }
264 0 : }
265 :
266 0 : sal_Bool SvMetaName::ReadSvIdl( SvIdlDataBase & rBase, SvTokenStream & rInStm )
267 : {
268 0 : sal_uInt32 nTokPos = rInStm.Tell();
269 0 : sal_Bool bOk = sal_True;
270 0 : if( rInStm.Read( '[' ) )
271 : {
272 0 : sal_uInt32 nBeginPos = 0; // can not happen with Tell
273 0 : while( nBeginPos != rInStm.Tell() )
274 : {
275 0 : nBeginPos = rInStm.Tell();
276 0 : ReadAttributesSvIdl( rBase, rInStm );
277 0 : rInStm.ReadDelemiter();
278 : }
279 0 : bOk = rInStm.Read( ']' );
280 : }
281 :
282 0 : if( bOk )
283 : {
284 0 : if( rInStm.Read( '{' ) )
285 : {
286 0 : DoReadContextSvIdl( rBase, rInStm );
287 0 : bOk = rInStm.Read( '}' );
288 : }
289 : }
290 :
291 0 : if( !bOk )
292 0 : rInStm.Seek( nTokPos );
293 0 : return bOk;
294 : }
295 :
296 0 : void SvMetaName::WriteSvIdl( SvIdlDataBase & rBase, SvStream & rOutStm,
297 : sal_uInt16 nTab )
298 : {
299 0 : sal_uLong nBeginPos = rOutStm.Tell();
300 0 : WriteTab( rOutStm, nTab );
301 0 : rOutStm.WriteChar( '[' ) << endl;
302 0 : sal_uLong nOldPos = rOutStm.Tell();
303 0 : WriteAttributesSvIdl( rBase, rOutStm, nTab +1 );
304 :
305 : // write no empty brackets
306 0 : if( TestAndSeekSpaceOnly( rOutStm, nOldPos ) )
307 : // nothing written
308 0 : rOutStm.Seek( nBeginPos );
309 : else
310 : {
311 0 : WriteTab( rOutStm, nTab );
312 0 : rOutStm.WriteChar( ']' );
313 0 : nBeginPos = rOutStm.Tell();
314 0 : rOutStm << endl;
315 : }
316 :
317 0 : WriteTab( rOutStm, nTab );
318 0 : rOutStm.WriteChar( '{' ) << endl;
319 0 : nOldPos = rOutStm.Tell();
320 0 : WriteContextSvIdl( rBase, rOutStm, nTab +1 );
321 :
322 : // write no empty brackets
323 0 : if( TestAndSeekSpaceOnly( rOutStm, nOldPos ) )
324 : // nothing written
325 0 : rOutStm.Seek( nBeginPos );
326 : else
327 : {
328 0 : WriteTab( rOutStm, nTab );
329 0 : rOutStm.WriteChar( '}' );
330 : }
331 0 : }
332 :
333 0 : void SvMetaName::Write( SvIdlDataBase & rBase, SvStream & rOutStm,
334 : sal_uInt16 nTab,
335 : WriteType nT, WriteAttribute nA )
336 : {
337 0 : sal_uLong nBeginPos = rOutStm.Tell();
338 0 : WriteTab( rOutStm, nTab );
339 0 : rOutStm.WriteChar( '[' ) << endl;
340 0 : sal_uLong nOldPos = rOutStm.Tell();
341 0 : WriteAttributes( rBase, rOutStm, nTab +1, nT, nA );
342 :
343 : // write no empty brackets
344 0 : sal_uLong nPos = rOutStm.Tell();
345 0 : rOutStm.Seek( nOldPos );
346 0 : sal_Bool bOnlySpace = sal_True;
347 0 : while( bOnlySpace && rOutStm.Tell() < nPos )
348 : {
349 : char c;
350 0 : rOutStm.ReadChar( c );
351 0 : if( !isspace( c ) )
352 0 : bOnlySpace = sal_False;
353 : }
354 0 : if( bOnlySpace )
355 : // nothing written
356 0 : rOutStm.Seek( nBeginPos );
357 : else
358 : {
359 0 : rOutStm.Seek( nPos );
360 0 : WriteTab( rOutStm, nTab );
361 0 : rOutStm.WriteChar( ']' ) << endl;
362 : }
363 0 : }
364 :
365 0 : void SvMetaName::WriteAttributes( SvIdlDataBase &, SvStream & rOutStm,
366 : sal_uInt16 nTab,
367 : WriteType, WriteAttribute )
368 : {
369 0 : if( GetHelpText().IsSet() || GetHelpContext().IsSet() )
370 : {
371 0 : WriteTab( rOutStm, nTab );
372 0 : rOutStm.WriteCharPtr( "// class SvMetaName" ) << endl;
373 : }
374 0 : if( GetHelpText().IsSet() )
375 : {
376 0 : WriteTab( rOutStm, nTab );
377 0 : rOutStm.WriteCharPtr( "helpstring(\"" ).WriteCharPtr( GetHelpText().getString().getStr() ).WriteCharPtr( "\")," ) << endl;
378 : }
379 0 : if( GetHelpContext().IsSet() )
380 : {
381 0 : WriteTab( rOutStm, nTab );
382 0 : rOutStm.WriteCharPtr( "helpcontext(" )
383 0 : .WriteCharPtr( OString::number(GetHelpContext().GetValue()).getStr() )
384 0 : .WriteCharPtr( ")," ) << endl;
385 : }
386 0 : }
387 :
388 0 : void SvMetaName::WriteContext( SvIdlDataBase &, SvStream &,
389 : sal_uInt16,
390 : WriteType, WriteAttribute )
391 : {
392 0 : }
393 :
394 0 : SV_IMPL_META_FACTORY1( SvMetaReference, SvMetaName );
395 :
396 0 : SvMetaReference::SvMetaReference()
397 : {
398 0 : }
399 :
400 0 : void SvMetaReference::Load( SvPersistStream & rStm )
401 : {
402 0 : SvMetaName::Load( rStm );
403 :
404 : sal_uInt8 nMask;
405 0 : rStm.ReadUChar( nMask );
406 0 : if( nMask >= 0x2 )
407 : {
408 0 : rStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
409 : OSL_FAIL( "wrong format" );
410 0 : return;
411 : }
412 0 : if( nMask & 0x01 )
413 : {
414 : SvMetaReference * pRef;
415 0 : rStm >> pRef;
416 0 : aRef = pRef;
417 : }
418 : }
419 :
420 0 : void SvMetaReference::Save( SvPersistStream & rStm )
421 : {
422 0 : SvMetaName::Save( rStm );
423 :
424 : // create mask
425 0 : sal_uInt8 nMask = 0;
426 0 : if( aRef.Is() )
427 0 : nMask |= 0x01;
428 :
429 : // write data
430 0 : rStm.WriteUChar( nMask );
431 0 : if( nMask & 0x01 ) WriteSvPersistBase( rStm, aRef );
432 0 : }
433 :
434 0 : SV_IMPL_META_FACTORY1( SvMetaExtern, SvMetaReference );
435 :
436 0 : SvMetaExtern::SvMetaExtern()
437 : : pModule( NULL )
438 : , bReadUUId( sal_False )
439 0 : , bReadVersion( sal_False )
440 : {
441 0 : }
442 :
443 0 : void SvMetaExtern::Load( SvPersistStream & rStm )
444 : {
445 0 : SvMetaReference::Load( rStm );
446 :
447 : sal_uInt8 nMask;
448 0 : rStm.ReadUChar( nMask );
449 0 : if( nMask >= 0x20 )
450 : {
451 0 : rStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
452 : OSL_FAIL( "wrong format" );
453 0 : return;
454 : }
455 0 : if( nMask & 0x01 ) rStm >> pModule;
456 0 : if( nMask & 0x02 ) rStm >> aUUId;
457 0 : if( nMask & 0x04 ) rStm >> aVersion;
458 0 : if( nMask & 0x08 ) bReadUUId = sal_True;
459 0 : if( nMask & 0x10 ) bReadVersion = sal_True;
460 : }
461 :
462 0 : void SvMetaExtern::Save( SvPersistStream & rStm )
463 : {
464 0 : SvMetaReference::Save( rStm );
465 :
466 : // create mask
467 0 : sal_uInt8 nMask = 0;
468 0 : if( pModule ) nMask |= 0x01;
469 0 : if( aUUId != SvGlobalName() ) nMask |= 0x02;
470 0 : if( aVersion != SvVersion() ) nMask |= 0x04;
471 0 : if( bReadUUId ) nMask |= 0x08;
472 0 : if( bReadVersion ) nMask |= 0x10;
473 :
474 : // write data
475 0 : rStm.WriteUChar( nMask );
476 0 : if( nMask & 0x01 ) WriteSvPersistBase( rStm, pModule );
477 0 : if( nMask & 0x02 ) WriteSvGlobalName( rStm, aUUId );
478 0 : if( nMask & 0x04 ) WriteSvVersion( rStm, aVersion );
479 0 : }
480 :
481 0 : SvMetaModule * SvMetaExtern::GetModule() const
482 : {
483 : DBG_ASSERT( pModule != NULL, "module not set" );
484 0 : return pModule;
485 : }
486 :
487 0 : const SvGlobalName & SvMetaExtern::GetUUId() const
488 : {
489 0 : if( aUUId == SvGlobalName() )
490 0 : GetModule()->FillNextName( &((SvMetaExtern *)this)->aUUId );
491 0 : return aUUId;
492 : }
493 :
494 0 : void SvMetaExtern::SetModule( SvIdlDataBase & rBase )
495 : {
496 0 : pModule = (SvMetaModule *)rBase.GetStack().Get( TYPE( SvMetaModule ) );
497 0 : }
498 :
499 0 : void SvMetaExtern::ReadAttributesSvIdl( SvIdlDataBase & rBase,
500 : SvTokenStream & rInStm )
501 : {
502 0 : SvMetaReference::ReadAttributesSvIdl( rBase, rInStm );
503 0 : if( aUUId.ReadSvIdl( rBase, rInStm ) )
504 0 : bReadUUId = sal_True;
505 0 : if( aVersion.ReadSvIdl( rInStm ) )
506 0 : bReadVersion = sal_True;
507 0 : }
508 :
509 0 : void SvMetaExtern::WriteAttributesSvIdl( SvIdlDataBase & rBase,
510 : SvStream & rOutStm, sal_uInt16 nTab )
511 : {
512 0 : SvMetaReference::WriteAttributesSvIdl( rBase, rOutStm, nTab );
513 0 : if( bReadUUId || bReadVersion )
514 : {
515 0 : WriteTab( rOutStm, nTab );
516 0 : rOutStm.WriteCharPtr( "// class SvMetaExtern" ) << endl;
517 :
518 0 : if( bReadUUId )
519 : {
520 0 : WriteTab( rOutStm, nTab );
521 0 : aUUId.WriteSvIdl( rOutStm );
522 0 : rOutStm.WriteChar( ';' ) << endl;
523 : }
524 0 : if( bReadVersion )
525 : {
526 0 : WriteTab( rOutStm, nTab );
527 0 : aVersion.WriteSvIdl( rOutStm );
528 0 : rOutStm.WriteChar( ';' ) << endl;
529 : }
530 : }
531 0 : }
532 :
533 0 : sal_Bool SvMetaExtern::ReadSvIdl( SvIdlDataBase & rBase, SvTokenStream & rInStm )
534 : {
535 0 : SetModule( rBase );
536 0 : GetUUId(); // id gets created
537 0 : return SvMetaReference::ReadSvIdl( rBase, rInStm );
538 : }
539 :
540 0 : void SvMetaExtern::WriteSvIdl( SvIdlDataBase & rBase, SvStream & rOutStm,
541 : sal_uInt16 nTab )
542 : {
543 0 : SvMetaReference::WriteSvIdl( rBase, rOutStm, nTab );
544 0 : }
545 :
546 0 : void SvMetaExtern::Write( SvIdlDataBase & rBase, SvStream & rOutStm,
547 : sal_uInt16 nTab,
548 : WriteType nT, WriteAttribute nA )
549 : {
550 0 : SvMetaReference::Write( rBase, rOutStm, nTab, nT, nA );
551 0 : }
552 :
553 0 : void SvMetaExtern::WriteAttributes( SvIdlDataBase & rBase, SvStream & rOutStm,
554 : sal_uInt16 nTab,
555 : WriteType nT, WriteAttribute nA )
556 : {
557 0 : SvMetaReference::WriteAttributes( rBase, rOutStm, nTab, nT, nA );
558 :
559 0 : WriteTab( rOutStm, nTab );
560 0 : rOutStm.WriteCharPtr( "// class SvMetaExtern" ) << endl;
561 0 : WriteTab( rOutStm, nTab );
562 0 : rOutStm.WriteCharPtr( "uuid(" ).WriteCharPtr( OUStringToOString(GetUUId().GetHexName(), RTL_TEXTENCODING_UTF8).getStr() ).WriteCharPtr( ")," ) << endl;
563 0 : WriteTab( rOutStm, nTab );
564 0 : rOutStm.WriteCharPtr( "version(" )
565 0 : .WriteCharPtr( OString::number(aVersion.GetMajorVersion()).getStr() )
566 0 : .WriteChar( '.' )
567 0 : .WriteCharPtr( OString::number(aVersion.GetMinorVersion()).getStr() )
568 0 : .WriteCharPtr( ")," ) << endl;
569 0 : }
570 :
571 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|