1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _XMLOFF_PROPERTYHANDLERFACTORY_HXX 29 #define _XMLOFF_PROPERTYHANDLERFACTORY_HXX 30 31 #include "sal/config.h" 32 #include "xmloff/dllapi.h" 33 #include "sal/types.h" 34 35 #ifndef __SGI_STL_MAP 36 #include <map> 37 #endif 38 #include <xmloff/uniref.hxx> 39 #include <xmloff/xmlprhdl.hxx> 40 41 /** 42 This class is a base-class to create XMLPropertyHandler. 43 It creates PropertyHandler for given XML-types and store 44 them in an internal cache. They'll be deleted at destruction- 45 time. 46 For create your own PropertyHandler for specific XML-types 47 you have to override the virtual method GetPropertyHandler 48 ( see below ). 49 */ 50 class XMLOFF_DLLPUBLIC XMLPropertyHandlerFactory : public UniRefBase 51 { 52 public: 53 virtual ~XMLPropertyHandlerFactory(); 54 55 /** 56 This method retrieves a PropertyHandler for the given XML-type. 57 To extend this method for more XML-types override this method 58 like the example below. If you call the method of the base-class 59 you get propertyhandler for basic-XML-types ( e.g. for color, percent, ... ). 60 Afetr that you could create your new XML-types. After creating a new type 61 you have to put the pointer into the cache via the method 62 PutHdlCache( sal_Int32 , XMLPropertyHandler* ). 63 64 virtual const XMLPropertyHandler* GetPropertyHandler( sal_Int32 nType ) const 65 { 66 XMLPropertyHandler* pHdl = XMLPropertyHandlerFactory::GetPropertyHandler( nType ); 67 68 if( !pHdl ) 69 { 70 switch( nType ) 71 { 72 case XML_TYPE_XYZ : 73 pHdl = new XML_xyz_PropHdl; 74 break; 75 case ... 76 : 77 : 78 } 79 80 if( pHdl ) 81 PutHdlCache( nType, pHdl ); 82 } 83 84 return pHdl; 85 } 86 */ 87 virtual const XMLPropertyHandler* GetPropertyHandler( sal_Int32 nType ) const; 88 89 /** helper method to statically create a property handler; this will not 90 * use the handler cache. This method should only be called in special 91 * circumstances; calling GetPropertyHandler is almost always 92 * preferable. */ 93 static const XMLPropertyHandler* CreatePropertyHandler( sal_Int32 nType ); 94 95 protected: 96 /** Retrieves a PropertyHandler from the internal cache */ 97 XMLPropertyHandler* GetHdlCache( sal_Int32 nType ) const; 98 /** Puts a PropertyHandler into the internal cache */ 99 void PutHdlCache( sal_Int32 nType, const XMLPropertyHandler* pHdl ) const; 100 101 private: 102 /** Retrieves ( creates if necessary ) PropertyHandler for 103 basic XML-types */ 104 SAL_DLLPRIVATE const XMLPropertyHandler* GetBasicHandler( sal_Int32 nType ) 105 const; 106 107 typedef ::std::map< sal_Int32, XMLPropertyHandler* > CacheMap; 108 CacheMap maHandlerCache; 109 }; 110 111 #endif // _XMLOFF_PROPERTYHANDLERFACTORY_HXX 112