Branch data 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 _XMLOFF_PROPERTYHANDLERFACTORY_HXX
21 : : #define _XMLOFF_PROPERTYHANDLERFACTORY_HXX
22 : :
23 : : #include "sal/config.h"
24 : : #include "xmloff/dllapi.h"
25 : : #include "sal/types.h"
26 : :
27 : : #include <map>
28 : : #include <xmloff/uniref.hxx>
29 : : #include <xmloff/xmlprhdl.hxx>
30 : :
31 : : /**
32 : : This class is a base-class to create XMLPropertyHandler.
33 : : It creates PropertyHandler for given XML-types and store
34 : : them in an internal cache. They'll be deleted at destruction-
35 : : time.
36 : : For create your own PropertyHandler for specific XML-types
37 : : you have to override the virtual method GetPropertyHandler
38 : : ( see below ).
39 : : */
40 [ + - ]: 400 : class XMLOFF_DLLPUBLIC XMLPropertyHandlerFactory : public UniRefBase
41 : : {
42 : : public:
43 : : virtual ~XMLPropertyHandlerFactory();
44 : :
45 : : /**
46 : : This method retrieves a PropertyHandler for the given XML-type.
47 : : To extend this method for more XML-types override this method
48 : : like the example below. If you call the method of the base-class
49 : : you get propertyhandler for basic-XML-types ( e.g. for color, percent, ... ).
50 : : Afetr that you could create your new XML-types. After creating a new type
51 : : you have to put the pointer into the cache via the method
52 : : PutHdlCache( sal_Int32 , XMLPropertyHandler* ).
53 : :
54 : : virtual const XMLPropertyHandler* GetPropertyHandler( sal_Int32 nType ) const
55 : : {
56 : : XMLPropertyHandler* pHdl = XMLPropertyHandlerFactory::GetPropertyHandler( nType );
57 : :
58 : : if( !pHdl )
59 : : {
60 : : switch( nType )
61 : : {
62 : : case XML_TYPE_XYZ :
63 : : pHdl = new XML_xyz_PropHdl;
64 : : break;
65 : : case ...
66 : : :
67 : : :
68 : : }
69 : :
70 : : if( pHdl )
71 : : PutHdlCache( nType, pHdl );
72 : : }
73 : :
74 : : return pHdl;
75 : : }
76 : : */
77 : : virtual const XMLPropertyHandler* GetPropertyHandler( sal_Int32 nType ) const;
78 : :
79 : : /** helper method to statically create a property handler; this will not
80 : : * use the handler cache. This method should only be called in special
81 : : * circumstances; calling GetPropertyHandler is almost always
82 : : * preferable. */
83 : : static const XMLPropertyHandler* CreatePropertyHandler( sal_Int32 nType );
84 : :
85 : : protected:
86 : : /** Retrieves a PropertyHandler from the internal cache */
87 : : XMLPropertyHandler* GetHdlCache( sal_Int32 nType ) const;
88 : : /** Puts a PropertyHandler into the internal cache */
89 : : void PutHdlCache( sal_Int32 nType, const XMLPropertyHandler* pHdl ) const;
90 : :
91 : : private:
92 : : /** Retrieves ( creates if necessary ) PropertyHandler for
93 : : basic XML-types */
94 : : SAL_DLLPRIVATE const XMLPropertyHandler* GetBasicHandler( sal_Int32 nType )
95 : : const;
96 : :
97 : : typedef ::std::map< sal_Int32, XMLPropertyHandler* > CacheMap;
98 : : CacheMap maHandlerCache;
99 : : };
100 : :
101 : : #endif // _XMLOFF_PROPERTYHANDLERFACTORY_HXX
102 : :
103 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|