Kaydet (Commit) bdd39ed7 authored tarafından Daniel Vogelheim's avatar Daniel Vogelheim

- added: translation tables are now kept in a stack

- fixed: now use STL iterators to find elements (rather than a count(), operator[] sequence)
- fixed: header is now commented
üst 1d9f7d2c
......@@ -2,9 +2,9 @@
*
* $RCSfile: XMLEventImportHelper.hxx,v $
*
* $Revision: 1.1 $
* $Revision: 1.2 $
*
* last change: $Author: dvo $ $Date: 2000-12-19 18:56:47 $
* last change: $Author: dvo $ $Date: 2001-01-23 13:20:03 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
......@@ -71,6 +71,7 @@
#endif
#include <map>
#include <list>
namespace com { namespace sun { namespace star {
......@@ -83,23 +84,52 @@ struct XMLEventNameTranslation;
typedef ::std::map< ::rtl::OUString, XMLEventContextFactory* > FactoryMap;
typedef ::std::map< ::rtl::OUString, ::rtl::OUString > NameMap;
typedef ::std::list< NameMap* > NameMapList;
/**
* Helps the XMLEventsImportContext.
*
* This class stores
* a) the translation from XML event names to API event names, and
* b) a mapping from script language names to XMLEventContextFactory objects
* (that handle particular languages).
*
* Event name translation tables may be added, i.e. they will be joined
* together. If different translations are needed (i.e., if the same XML name
* needs to be translated to different API names in different contexts), then
* translation tables may be saved on a translation table stack.
*/
class XMLEventImportHelper
{
/// map of XMLEventContextFactory objects
FactoryMap aFactoryMap;
NameMap aEventNameMap;
/// map from XML to API names
NameMap* pEventNameMap;
/// stack of previous aEventNameMap
NameMapList aEventNameMapList;
public:
XMLEventImportHelper();
~XMLEventImportHelper();
/// register a handler for a particular language type
void RegisterFactory( const ::rtl::OUString& rLanguage,
XMLEventContextFactory* aFactory );
/// add event name translation to the internal table
void AddTranslationTable( const XMLEventNameTranslation* pTransTable );
/// save the old translation table on a stack and install an empty table
void PushTranslationTable();
/// recover the top-most previously saved translation table
void PopTranslationTable();
/// create an appropriate import context for a particular event
SvXMLImportContext* CreateContext(
SvXMLImport& rImport,
sal_uInt16 nPrefix,
......
......@@ -2,9 +2,9 @@
*
* $RCSfile: XMLEventImportHelper.cxx,v $
*
* $Revision: 1.3 $
* $Revision: 1.4 $
*
* last change: $Author: dvo $ $Date: 2001-01-22 19:50:20 $
* last change: $Author: dvo $ $Date: 2001-01-23 13:20:04 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
......@@ -88,10 +88,14 @@ using ::rtl::OUString;
using ::com::sun::star::xml::sax::XAttributeList;
using ::com::sun::star::uno::Reference;
XMLEventImportHelper::XMLEventImportHelper()
XMLEventImportHelper::XMLEventImportHelper() :
aFactoryMap(),
pEventNameMap(new NameMap()),
aEventNameMapList()
{
}
XMLEventImportHelper::~XMLEventImportHelper()
{
// delete factories
......@@ -103,6 +107,9 @@ XMLEventImportHelper::~XMLEventImportHelper()
delete aIter->second;
}
aFactoryMap.clear();
// delete name map
delete pEventNameMap;
}
void XMLEventImportHelper::RegisterFactory(
......@@ -129,16 +136,38 @@ void XMLEventImportHelper::AddTranslationTable(
OUString rName(OUString::createFromAscii(pTrans->sXMLName));
// check for conflicting entries
DBG_ASSERT(aEventNameMap.find(rName) == aEventNameMap.end(),
DBG_ASSERT(pEventNameMap->find(rName) == pEventNameMap->end(),
"conflicting event translations");
// assign new translation
aEventNameMap[rName] = OUString::createFromAscii(pTrans->sAPIName);
(*pEventNameMap)[rName] =
OUString::createFromAscii(pTrans->sAPIName);
}
}
// else? ignore!
}
void XMLEventImportHelper::PushTranslationTable()
{
// save old map and install new one
aEventNameMapList.push_back(pEventNameMap);
pEventNameMap = new NameMap();
}
void XMLEventImportHelper::PopTranslationTable()
{
DBG_ASSERT(aEventNameMapList.size() > 0,
"no translation tables left to pop");
if (aEventNameMapList.size() > 0)
{
// delete current and install old map
delete pEventNameMap;
pEventNameMap = aEventNameMapList.back();
aEventNameMapList.pop_back();
}
}
SvXMLImportContext* XMLEventImportHelper::CreateContext(
SvXMLImport& rImport,
sal_uInt16 nPrefix,
......@@ -151,17 +180,17 @@ SvXMLImportContext* XMLEventImportHelper::CreateContext(
SvXMLImportContext* pContext = NULL;
// translate event name form xml to api
if (aEventNameMap.count(rXmlEventName))
NameMap::iterator aNameIter = pEventNameMap->find(rXmlEventName);
if (aNameIter != pEventNameMap->end())
{
OUString& rApiEventName = aEventNameMap[rXmlEventName];
// check for factory
if (aFactoryMap.count(rLanguage))
FactoryMap::iterator aFactoryIterator = aFactoryMap.find(rLanguage);
if (aFactoryIterator != aFactoryMap.end())
{
// delegate to factory
pContext = aFactoryMap[rLanguage]->CreateContext(
pContext = aFactoryIterator->second->CreateContext(
rImport, nPrefix, rLocalName, xAttrList,
rEvents, rApiEventName, rLanguage);
rEvents, aNameIter->second, rLanguage);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment