summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xmloff/inc/XMLEventImportHelper.hxx36
-rw-r--r--xmloff/source/script/XMLEventImportHelper.cxx51
2 files changed, 73 insertions, 14 deletions
diff --git a/xmloff/inc/XMLEventImportHelper.hxx b/xmloff/inc/XMLEventImportHelper.hxx
index 981d7fa40062..addfb5a6cd41 100644
--- a/xmloff/inc/XMLEventImportHelper.hxx
+++ b/xmloff/inc/XMLEventImportHelper.hxx
@@ -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,
diff --git a/xmloff/source/script/XMLEventImportHelper.cxx b/xmloff/source/script/XMLEventImportHelper.cxx
index ff6601ca6399..75097a37055e 100644
--- a/xmloff/source/script/XMLEventImportHelper.cxx
+++ b/xmloff/source/script/XMLEventImportHelper.cxx
@@ -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);
}
}