1*ecfe53c5SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ecfe53c5SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ecfe53c5SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ecfe53c5SAndrew Rist * distributed with this work for additional information 6*ecfe53c5SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ecfe53c5SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ecfe53c5SAndrew Rist * "License"); you may not use this file except in compliance 9*ecfe53c5SAndrew Rist * with the License. You may obtain a copy of the License at 10*ecfe53c5SAndrew Rist * 11*ecfe53c5SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ecfe53c5SAndrew Rist * 13*ecfe53c5SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ecfe53c5SAndrew Rist * software distributed under the License is distributed on an 15*ecfe53c5SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ecfe53c5SAndrew Rist * KIND, either express or implied. See the License for the 17*ecfe53c5SAndrew Rist * specific language governing permissions and limitations 18*ecfe53c5SAndrew Rist * under the License. 19*ecfe53c5SAndrew Rist * 20*ecfe53c5SAndrew Rist *************************************************************/ 21*ecfe53c5SAndrew Rist 22*ecfe53c5SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _XMLOFF_PROPERTYHANDLERFACTORY_HXX 25cdf0e10cSrcweir #define _XMLOFF_PROPERTYHANDLERFACTORY_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "sal/config.h" 28cdf0e10cSrcweir #include "xmloff/dllapi.h" 29cdf0e10cSrcweir #include "sal/types.h" 30cdf0e10cSrcweir 31cdf0e10cSrcweir #ifndef __SGI_STL_MAP 32cdf0e10cSrcweir #include <map> 33cdf0e10cSrcweir #endif 34cdf0e10cSrcweir #include <xmloff/uniref.hxx> 35cdf0e10cSrcweir #include <xmloff/xmlprhdl.hxx> 36cdf0e10cSrcweir 37cdf0e10cSrcweir /** 38cdf0e10cSrcweir This class is a base-class to create XMLPropertyHandler. 39cdf0e10cSrcweir It creates PropertyHandler for given XML-types and store 40cdf0e10cSrcweir them in an internal cache. They'll be deleted at destruction- 41cdf0e10cSrcweir time. 42cdf0e10cSrcweir For create your own PropertyHandler for specific XML-types 43cdf0e10cSrcweir you have to override the virtual method GetPropertyHandler 44cdf0e10cSrcweir ( see below ). 45cdf0e10cSrcweir */ 46cdf0e10cSrcweir class XMLOFF_DLLPUBLIC XMLPropertyHandlerFactory : public UniRefBase 47cdf0e10cSrcweir { 48cdf0e10cSrcweir public: 49cdf0e10cSrcweir virtual ~XMLPropertyHandlerFactory(); 50cdf0e10cSrcweir 51cdf0e10cSrcweir /** 52cdf0e10cSrcweir This method retrieves a PropertyHandler for the given XML-type. 53cdf0e10cSrcweir To extend this method for more XML-types override this method 54cdf0e10cSrcweir like the example below. If you call the method of the base-class 55cdf0e10cSrcweir you get propertyhandler for basic-XML-types ( e.g. for color, percent, ... ). 56cdf0e10cSrcweir Afetr that you could create your new XML-types. After creating a new type 57cdf0e10cSrcweir you have to put the pointer into the cache via the method 58cdf0e10cSrcweir PutHdlCache( sal_Int32 , XMLPropertyHandler* ). 59cdf0e10cSrcweir 60cdf0e10cSrcweir virtual const XMLPropertyHandler* GetPropertyHandler( sal_Int32 nType ) const 61cdf0e10cSrcweir { 62cdf0e10cSrcweir XMLPropertyHandler* pHdl = XMLPropertyHandlerFactory::GetPropertyHandler( nType ); 63cdf0e10cSrcweir 64cdf0e10cSrcweir if( !pHdl ) 65cdf0e10cSrcweir { 66cdf0e10cSrcweir switch( nType ) 67cdf0e10cSrcweir { 68cdf0e10cSrcweir case XML_TYPE_XYZ : 69cdf0e10cSrcweir pHdl = new XML_xyz_PropHdl; 70cdf0e10cSrcweir break; 71cdf0e10cSrcweir case ... 72cdf0e10cSrcweir : 73cdf0e10cSrcweir : 74cdf0e10cSrcweir } 75cdf0e10cSrcweir 76cdf0e10cSrcweir if( pHdl ) 77cdf0e10cSrcweir PutHdlCache( nType, pHdl ); 78cdf0e10cSrcweir } 79cdf0e10cSrcweir 80cdf0e10cSrcweir return pHdl; 81cdf0e10cSrcweir } 82cdf0e10cSrcweir */ 83cdf0e10cSrcweir virtual const XMLPropertyHandler* GetPropertyHandler( sal_Int32 nType ) const; 84cdf0e10cSrcweir 85cdf0e10cSrcweir /** helper method to statically create a property handler; this will not 86cdf0e10cSrcweir * use the handler cache. This method should only be called in special 87cdf0e10cSrcweir * circumstances; calling GetPropertyHandler is almost always 88cdf0e10cSrcweir * preferable. */ 89cdf0e10cSrcweir static const XMLPropertyHandler* CreatePropertyHandler( sal_Int32 nType ); 90cdf0e10cSrcweir 91cdf0e10cSrcweir protected: 92cdf0e10cSrcweir /** Retrieves a PropertyHandler from the internal cache */ 93cdf0e10cSrcweir XMLPropertyHandler* GetHdlCache( sal_Int32 nType ) const; 94cdf0e10cSrcweir /** Puts a PropertyHandler into the internal cache */ 95cdf0e10cSrcweir void PutHdlCache( sal_Int32 nType, const XMLPropertyHandler* pHdl ) const; 96cdf0e10cSrcweir 97cdf0e10cSrcweir private: 98cdf0e10cSrcweir /** Retrieves ( creates if necessary ) PropertyHandler for 99cdf0e10cSrcweir basic XML-types */ 100cdf0e10cSrcweir SAL_DLLPRIVATE const XMLPropertyHandler* GetBasicHandler( sal_Int32 nType ) 101cdf0e10cSrcweir const; 102cdf0e10cSrcweir 103cdf0e10cSrcweir typedef ::std::map< sal_Int32, XMLPropertyHandler* > CacheMap; 104cdf0e10cSrcweir CacheMap maHandlerCache; 105cdf0e10cSrcweir }; 106cdf0e10cSrcweir 107cdf0e10cSrcweir #endif // _XMLOFF_PROPERTYHANDLERFACTORY_HXX 108