summaryrefslogtreecommitdiff
path: root/xmloff/source/script
diff options
context:
space:
mode:
Diffstat (limited to 'xmloff/source/script')
-rw-r--r--xmloff/source/script/XMLEventExport.cxx367
-rw-r--r--xmloff/source/script/XMLEventImportHelper.cxx179
-rw-r--r--xmloff/source/script/XMLEventsImportContext.cxx247
-rw-r--r--xmloff/source/script/XMLScriptContextFactory.cxx102
-rw-r--r--xmloff/source/script/XMLScriptExportHandler.cxx88
-rw-r--r--xmloff/source/script/XMLStarBasicContextFactory.cxx139
-rw-r--r--xmloff/source/script/XMLStarBasicExportHandler.cxx111
-rw-r--r--xmloff/source/script/xmlbasici.cxx197
-rw-r--r--xmloff/source/script/xmlbasici.hxx88
-rw-r--r--xmloff/source/script/xmlscripti.cxx188
10 files changed, 1706 insertions, 0 deletions
diff --git a/xmloff/source/script/XMLEventExport.cxx b/xmloff/source/script/XMLEventExport.cxx
new file mode 100644
index 000000000000..2675ecb4b98f
--- /dev/null
+++ b/xmloff/source/script/XMLEventExport.cxx
@@ -0,0 +1,367 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_xmloff.hxx"
+#include <xmloff/XMLEventExport.hxx>
+
+#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP
+#include <com/sun/star/beans/PropertyValue.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_DOCUMENT_XEVENTSSUPPLIER_HPP
+#include <com/sun/star/document/XEventsSupplier.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_CONTAINER_XNAMEREPLACE_HPP
+#include <com/sun/star/container/XNameReplace.hpp>
+#endif
+#include <tools/debug.hxx>
+#include <xmloff/xmlexp.hxx>
+#include <xmloff/xmltoken.hxx>
+#include "xmloff/xmlnmspe.hxx"
+#include <xmloff/nmspmap.hxx>
+
+
+using namespace ::com::sun::star::uno;
+
+using std::map;
+using ::rtl::OUString;
+using ::com::sun::star::beans::PropertyValue;
+using ::com::sun::star::document::XEventsSupplier;
+using ::com::sun::star::container::XNameReplace;
+using ::com::sun::star::container::XNameAccess;
+using ::xmloff::token::GetXMLToken;
+using ::xmloff::token::XML_EVENT_LISTENERS;
+
+
+XMLEventExport::XMLEventExport(SvXMLExport& rExp,
+ const XMLEventNameTranslation* pTranslationTable) :
+ sEventType(RTL_CONSTASCII_USTRINGPARAM("EventType")),
+ rExport(rExp),
+ bExtNamespace(false)
+{
+ AddTranslationTable(pTranslationTable);
+}
+
+XMLEventExport::~XMLEventExport()
+{
+ // delete all handlers
+ HandlerMap::iterator aEnd = aHandlerMap.end();
+ for( HandlerMap::iterator aIter =
+ aHandlerMap.begin();
+ aIter != aEnd;
+ aIter++ )
+ {
+ delete aIter->second;
+ }
+ aHandlerMap.clear();
+}
+
+void XMLEventExport::AddHandler( const OUString& rName,
+ XMLEventExportHandler* pHandler )
+{
+ DBG_ASSERT(pHandler != NULL, "Need EventExportHandler");
+ if (pHandler != NULL)
+ {
+ aHandlerMap[rName] = pHandler;
+ }
+}
+
+void XMLEventExport::AddTranslationTable(
+ const XMLEventNameTranslation* pTransTable )
+{
+ if (NULL != pTransTable)
+ {
+ // put translation table into map
+ for(const XMLEventNameTranslation* pTrans = pTransTable;
+ pTrans->sAPIName != NULL;
+ pTrans++)
+ {
+ aNameTranslationMap[OUString::createFromAscii(pTrans->sAPIName)] =
+ XMLEventName(pTrans->nPrefix, pTrans->sXMLName);
+ }
+ }
+ // else? ignore!
+}
+
+void XMLEventExport::Export( Reference<XEventsSupplier> & rSupplier,
+ sal_Bool bWhitespace)
+{
+ if (rSupplier.is())
+ {
+ Reference<XNameAccess> xAccess(rSupplier->getEvents(), UNO_QUERY);
+ Export(xAccess, bWhitespace);
+ }
+ // else: no supplier, no export -> ignore!
+}
+
+void XMLEventExport::Export( Reference<XNameReplace> & rReplace,
+ sal_Bool bWhitespace)
+{
+ Reference<XNameAccess> xAccess(rReplace, UNO_QUERY);
+ Export(xAccess, bWhitespace);
+}
+
+void XMLEventExport::Export( Reference<XNameAccess> & rAccess,
+ sal_Bool bWhitespace)
+{
+ // early out if we don't actually get any events
+ if (!rAccess.is())
+ {
+ return;
+ }
+
+ // have we already processed an element?
+ sal_Bool bStarted = sal_False;
+
+ // iterate over all event types
+ Sequence<OUString> aNames = rAccess->getElementNames();
+ sal_Int32 nCount = aNames.getLength();
+ for(sal_Int32 i = 0; i < nCount; i++)
+ {
+ // translate name
+ NameMap::iterator aIter = aNameTranslationMap.find(aNames[i]);
+ if (aIter != aNameTranslationMap.end())
+ {
+ const XMLEventName& rXmlName = aIter->second;
+
+ // get PropertyValues for this event
+ Any aAny = rAccess->getByName( aNames[i] );
+ Sequence<PropertyValue> aValues;
+ aAny >>= aValues;
+
+ // now export the current event
+ ExportEvent( aValues, rXmlName, bWhitespace, bStarted );
+ }
+#ifdef DBG_UTIL
+ else
+ {
+ // don't proceed further
+ ::rtl::OString aStr("Unknown event name:" );
+ aStr += ::rtl::OUStringToOString( aNames[i], RTL_TEXTENCODING_UTF8 );
+ DBG_ERROR( aStr.getStr() );
+ }
+#endif
+ }
+
+ // close <script:events> element (if it was opened before)
+ if (bStarted)
+ {
+ EndElement(bWhitespace);
+ }
+}
+
+void XMLEventExport::ExportExt( Reference<XNameAccess> & rAccess,
+ sal_Bool bWhitespace )
+{
+ // set bExtNamespace flag to use XML_NAMESPACE_OFFICE_EXT namespace
+ // for events element (not for child elements)
+ bExtNamespace = true;
+ Export(rAccess, bWhitespace);
+ bExtNamespace = false; // reset for future Export calls
+}
+
+/// export a singular event and wirte <office:events> container
+void XMLEventExport::ExportSingleEvent(
+ Sequence<PropertyValue>& rEventValues,
+ const OUString& rApiEventName,
+ sal_Bool bUseWhitespace )
+{
+ // translate the name
+ NameMap::iterator aIter = aNameTranslationMap.find(rApiEventName);
+ if (aIter != aNameTranslationMap.end())
+ {
+ const XMLEventName& rXmlName = aIter->second;
+
+ // export the event ...
+ sal_Bool bStarted = sal_False;
+ ExportEvent( rEventValues, rXmlName, bUseWhitespace, bStarted );
+
+ // ... and close the container element (if necessary)
+ if (bStarted)
+ {
+ EndElement(bUseWhitespace);
+ }
+ }
+#ifdef DBG_UTIL
+ else
+ {
+ // don't proceed further
+ ::rtl::OString aStr("Unknown event name:" );
+ aStr += ::rtl::OUStringToOString( rApiEventName, RTL_TEXTENCODING_UTF8 );
+ DBG_ERROR( aStr.getStr() );
+ }
+#endif
+}
+
+
+/// export a single event
+void XMLEventExport::ExportEvent(
+ Sequence<PropertyValue>& rEventValues,
+ const XMLEventName& rXmlEventName,
+ sal_Bool bUseWhitespace,
+ sal_Bool& rExported )
+{
+ // search for EventType value and then delegate to EventHandler
+ sal_Int32 nValues = rEventValues.getLength();
+ const PropertyValue* pValues = rEventValues.getConstArray();
+
+ for(sal_Int32 nVal = 0; nVal < nValues; nVal++)
+ {
+ if (sEventType.equals(pValues[nVal].Name))
+ {
+ // found! Now find handler and delegate
+ OUString sType;
+ pValues[nVal].Value >>= sType;
+
+ if (aHandlerMap.count(sType))
+ {
+ if (! rExported)
+ {
+ // OK, we have't yet exported the enclosing
+ // element. So we do that now.
+ rExported = sal_True;
+ StartElement(bUseWhitespace);
+ }
+
+ OUString aEventQName(
+ rExport.GetNamespaceMap().GetQNameByKey(
+ rXmlEventName.m_nPrefix, rXmlEventName.m_aName ) );
+
+ // delegate to proper ExportEventHandler
+ aHandlerMap[sType]->Export(rExport, aEventQName,
+ rEventValues, bUseWhitespace);
+ }
+ else
+ {
+ if (! sType.equalsAsciiL("None", sizeof("None")-1))
+ {
+ DBG_ERROR("unknown event type returned by API");
+ // unknown type -> error (ignore)
+ }
+ // else: we ignore None fields
+ }
+
+ // early out: we don't need to look for another type
+ break;
+ }
+ // else: we only care for EventType -> ignore
+ }
+}
+
+
+void XMLEventExport::StartElement(sal_Bool bWhitespace)
+{
+ if (bWhitespace)
+ {
+ rExport.IgnorableWhitespace();
+ }
+ sal_uInt16 nNamespace = bExtNamespace ? XML_NAMESPACE_OFFICE_EXT
+ : XML_NAMESPACE_OFFICE;
+ rExport.StartElement( nNamespace, XML_EVENT_LISTENERS,
+ bWhitespace);
+}
+
+void XMLEventExport::EndElement(sal_Bool bWhitespace)
+{
+ sal_uInt16 nNamespace = bExtNamespace ? XML_NAMESPACE_OFFICE_EXT
+ : XML_NAMESPACE_OFFICE;
+ rExport.EndElement(nNamespace, XML_EVENT_LISTENERS, bWhitespace);
+ if (bWhitespace)
+ {
+ rExport.IgnorableWhitespace();
+ }
+}
+
+
+// implement aStandardEventTable (defined in xmlevent.hxx)
+const XMLEventNameTranslation aStandardEventTable[] =
+{
+ { "OnSelect", XML_NAMESPACE_DOM, "select" }, // "on-select"
+ { "OnInsertStart", XML_NAMESPACE_OFFICE, "insert-start" }, // "on-insert-start"
+ { "OnInsertDone", XML_NAMESPACE_OFFICE, "insert-done" }, // "on-insert-done"
+ { "OnMailMerge", XML_NAMESPACE_OFFICE, "mail-merge" }, // "on-mail-merge"
+ { "OnAlphaCharInput", XML_NAMESPACE_OFFICE, "alpha-char-input" }, // "on-alpha-char-input"
+ { "OnNonAlphaCharInput", XML_NAMESPACE_OFFICE, "non-alpha-char-input" }, // "on-non-alpha-char-input"
+ { "OnResize", XML_NAMESPACE_DOM, "resize" }, // "on-resize"
+ { "OnMove", XML_NAMESPACE_OFFICE, "move" }, // "on-move"
+ { "OnPageCountChange", XML_NAMESPACE_OFFICE, "page-count-change" }, // "on-page-count-change"
+ { "OnMouseOver", XML_NAMESPACE_DOM, "mouseover" }, // "on-mouse-over"
+ { "OnClick", XML_NAMESPACE_DOM, "click" }, // "on-click"
+ { "OnMouseOut", XML_NAMESPACE_DOM, "mouseout" }, // "on-mouse-out"
+ { "OnLoadError", XML_NAMESPACE_OFFICE, "load-error" }, // "on-load-error"
+ { "OnLoadCancel", XML_NAMESPACE_OFFICE, "load-cancel" }, // "on-load-cancel"
+ { "OnLoadDone", XML_NAMESPACE_OFFICE, "load-done" }, // "on-load-done"
+ { "OnLoad", XML_NAMESPACE_DOM, "load" }, // "on-load"
+ { "OnUnload", XML_NAMESPACE_DOM, "unload" }, // "on-unload"
+ { "OnStartApp", XML_NAMESPACE_OFFICE, "start-app" }, // "on-start-app"
+ { "OnCloseApp", XML_NAMESPACE_OFFICE, "close-app" }, // "on-close-app"
+ { "OnNew", XML_NAMESPACE_OFFICE, "new" }, // "on-new"
+ { "OnSave", XML_NAMESPACE_OFFICE, "save" }, // "on-save"
+ { "OnSaveAs", XML_NAMESPACE_OFFICE, "save-as" }, // "on-save-as"
+ { "OnFocus", XML_NAMESPACE_DOM, "DOMFocusIn" }, // "on-focus"
+ { "OnUnfocus", XML_NAMESPACE_DOM, "DOMFocusOut" }, // "on-unfocus"
+ { "OnPrint", XML_NAMESPACE_OFFICE, "print" }, // "on-print"
+ { "OnError", XML_NAMESPACE_DOM, "error" }, // "on-error"
+ { "OnLoadFinished", XML_NAMESPACE_OFFICE, "load-finished" }, // "on-load-finished"
+ { "OnSaveFinished", XML_NAMESPACE_OFFICE, "save-finished" }, // "on-save-finished"
+ { "OnModifyChanged", XML_NAMESPACE_OFFICE, "modify-changed" }, // "on-modify-changed"
+ { "OnPrepareUnload", XML_NAMESPACE_OFFICE, "prepare-unload" }, // "on-prepare-unload"
+ { "OnNewMail", XML_NAMESPACE_OFFICE, "new-mail" }, // "on-new-mail"
+ { "OnToggleFullscreen", XML_NAMESPACE_OFFICE, "toggle-fullscreen" }, // "on-toggle-fullscreen"
+ { "OnSaveDone", XML_NAMESPACE_OFFICE, "save-done" }, // "on-save-done"
+ { "OnSaveAsDone", XML_NAMESPACE_OFFICE, "save-as-done" }, // "on-save-as-done"
+ { "OnCopyTo", XML_NAMESPACE_OFFICE, "copy-to" },
+ { "OnCopyToDone", XML_NAMESPACE_OFFICE, "copy-to-done" },
+ { "OnViewCreated", XML_NAMESPACE_OFFICE, "view-created" },
+ { "OnPrepareViewClosing", XML_NAMESPACE_OFFICE, "prepare-view-closing" },
+ { "OnViewClosed", XML_NAMESPACE_OFFICE, "view-close" },
+ { "OnVisAreaChanged", XML_NAMESPACE_OFFICE, "visarea-changed" }, // "on-visarea-changed"
+ { "OnCreate", XML_NAMESPACE_OFFICE, "create" },
+ { "OnSaveAsFailed", XML_NAMESPACE_OFFICE, "save-as-failed" },
+ { "OnSaveFailed", XML_NAMESPACE_OFFICE, "save-failed" },
+ { "OnCopyToFailed", XML_NAMESPACE_OFFICE, "copy-to-failed" },
+ { "OnTitleChanged", XML_NAMESPACE_OFFICE, "title-changed" },
+ { "OnModeChanged", XML_NAMESPACE_OFFICE, "mode-changed" },
+ { "OnSaveTo", XML_NAMESPACE_OFFICE, "save-to" },
+ { "OnSaveToDone", XML_NAMESPACE_OFFICE, "save-to-done" },
+ { "OnSaveToFailed", XML_NAMESPACE_OFFICE, "save-to-failed" },
+ { "OnSubComponentOpened", XML_NAMESPACE_OFFICE, "subcomponent-opened" },
+ { "OnSubComponentClosed", XML_NAMESPACE_OFFICE, "subcomponent-closed" },
+ { "OnStorageChanged", XML_NAMESPACE_OFFICE, "storage-changed" },
+ { "OnMailMergeFinished", XML_NAMESPACE_OFFICE, "mail-merge-finished" },
+ { "OnFieldMerge", XML_NAMESPACE_OFFICE, "field-merge" },
+ { "OnFieldMergeFinished", XML_NAMESPACE_OFFICE, "field-merge-finished" },
+ { "OnLayoutFinished", XML_NAMESPACE_OFFICE, "layout-finished" },
+ { "OnDoubleClick", XML_NAMESPACE_OFFICE, "dblclick" },
+ { "OnRightClick", XML_NAMESPACE_OFFICE, "contextmenu" },
+ { "OnChange", XML_NAMESPACE_OFFICE, "content-changed" },
+ { "OnCalculate", XML_NAMESPACE_OFFICE, "calculated" },
+
+ { NULL, 0, 0 }
+};
diff --git a/xmloff/source/script/XMLEventImportHelper.cxx b/xmloff/source/script/XMLEventImportHelper.cxx
new file mode 100644
index 000000000000..3dfbab60952f
--- /dev/null
+++ b/xmloff/source/script/XMLEventImportHelper.cxx
@@ -0,0 +1,179 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_xmloff.hxx"
+
+#ifndef _XMLOFF_XMLEVENTIMPORTHELPER_HXX
+#include "XMLEventImportHelper.hxx"
+#endif
+#include <tools/debug.hxx>
+#include <xmloff/xmlimp.hxx>
+#include <xmloff/nmspmap.hxx>
+#include "xmloff/xmlnmspe.hxx"
+#include "xmloff/xmlerror.hxx"
+
+using ::rtl::OUString;
+using ::com::sun::star::xml::sax::XAttributeList;
+using ::com::sun::star::uno::Reference;
+using ::com::sun::star::uno::Sequence;
+
+XMLEventImportHelper::XMLEventImportHelper() :
+ aFactoryMap(),
+ pEventNameMap(new NameMap()),
+ aEventNameMapList()
+{
+}
+
+
+XMLEventImportHelper::~XMLEventImportHelper()
+{
+ // delete factories
+ FactoryMap::iterator aEnd = aFactoryMap.end();
+ for(FactoryMap::iterator aIter = aFactoryMap.begin();
+ aIter != aEnd;
+ aIter++ )
+ {
+ delete aIter->second;
+ }
+ aFactoryMap.clear();
+
+ // delete name map
+ delete pEventNameMap;
+}
+
+void XMLEventImportHelper::RegisterFactory(
+ const OUString& rLanguage,
+ XMLEventContextFactory* pFactory )
+{
+ DBG_ASSERT(pFactory != NULL, "I need a factory.");
+ if (NULL != pFactory)
+ {
+ aFactoryMap[rLanguage] = pFactory;
+ }
+}
+
+void XMLEventImportHelper::AddTranslationTable(
+ const XMLEventNameTranslation* pTransTable )
+{
+ if (NULL != pTransTable)
+ {
+ // put translation table into map
+ for(const XMLEventNameTranslation* pTrans = pTransTable;
+ pTrans->sAPIName != NULL;
+ pTrans++)
+ {
+ XMLEventName aName( pTrans->nPrefix, pTrans->sXMLName );
+
+ // check for conflicting entries
+ DBG_ASSERT(pEventNameMap->find(aName) == pEventNameMap->end(),
+ "conflicting event translations");
+
+ // assign new translation
+ (*pEventNameMap)[aName] =
+ 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.empty() )
+ {
+ // delete current and install old map
+ delete pEventNameMap;
+ pEventNameMap = aEventNameMapList.back();
+ aEventNameMapList.pop_back();
+ }
+}
+
+
+SvXMLImportContext* XMLEventImportHelper::CreateContext(
+ SvXMLImport& rImport,
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
+ const Reference<XAttributeList> & xAttrList,
+ XMLEventsImportContext* rEvents,
+ const OUString& rXmlEventName,
+ const OUString& rLanguage)
+{
+ SvXMLImportContext* pContext = NULL;
+
+ // translate event name form xml to api
+ OUString sMacroName;
+ sal_uInt16 nMacroPrefix =
+ rImport.GetNamespaceMap().GetKeyByAttrName( rXmlEventName,
+ &sMacroName );
+ XMLEventName aEventName( nMacroPrefix, sMacroName );
+ NameMap::iterator aNameIter = pEventNameMap->find(aEventName);
+ if (aNameIter != pEventNameMap->end())
+ {
+ OUString aScriptLanguage;
+ sal_uInt16 nScriptPrefix = rImport.GetNamespaceMap().
+ GetKeyByAttrName( rLanguage, &aScriptLanguage );
+ if( XML_NAMESPACE_OOO != nScriptPrefix )
+ aScriptLanguage = rLanguage ;
+
+ // check for factory
+ FactoryMap::iterator aFactoryIterator =
+ aFactoryMap.find(aScriptLanguage);
+ if (aFactoryIterator != aFactoryMap.end())
+ {
+ // delegate to factory
+ pContext = aFactoryIterator->second->CreateContext(
+ rImport, nPrefix, rLocalName, xAttrList,
+ rEvents, aNameIter->second, aScriptLanguage);
+ }
+ }
+
+ // default context (if no context was created above)
+ if( NULL == pContext )
+ {
+ pContext = new SvXMLImportContext(rImport, nPrefix, rLocalName);
+
+ Sequence<OUString> aMsgParams(2);
+
+ aMsgParams[0] = rXmlEventName;
+ aMsgParams[1] = rLanguage;
+
+ rImport.SetError(XMLERROR_FLAG_ERROR | XMLERROR_ILLEGAL_EVENT,
+ aMsgParams);
+
+ }
+
+ return pContext;
+}
diff --git a/xmloff/source/script/XMLEventsImportContext.cxx b/xmloff/source/script/XMLEventsImportContext.cxx
new file mode 100644
index 000000000000..301bef53856d
--- /dev/null
+++ b/xmloff/source/script/XMLEventsImportContext.cxx
@@ -0,0 +1,247 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_xmloff.hxx"
+#include <xmloff/XMLEventsImportContext.hxx>
+
+#ifndef _XMLOFF_XMLEVENTIMPORTHELPER_HXX
+#include "XMLEventImportHelper.hxx"
+#endif
+
+#ifndef _COM_SUN_STAR_DOCUMENT_XEVENTSSUPPLIER_HPP
+#include <com/sun/star/document/XEventsSupplier.hpp>
+#endif
+#include <tools/debug.hxx>
+#include <xmloff/xmlimp.hxx>
+#include <xmloff/nmspmap.hxx>
+#include "xmloff/xmlnmspe.hxx"
+#include <xmloff/xmltoken.hxx>
+#include "xmloff/xmlerror.hxx"
+
+using namespace ::com::sun::star::uno;
+using namespace ::xmloff::token;
+
+using ::rtl::OUString;
+using ::com::sun::star::xml::sax::XAttributeList;
+using ::com::sun::star::beans::PropertyValue;
+using ::com::sun::star::container::XNameReplace;
+using ::com::sun::star::document::XEventsSupplier;
+using ::com::sun::star::lang::IllegalArgumentException;
+
+TYPEINIT1(XMLEventsImportContext, SvXMLImportContext);
+
+
+XMLEventsImportContext::XMLEventsImportContext(
+ SvXMLImport& rImport,
+ sal_uInt16 nPrfx,
+ const OUString& rLocalName) :
+ SvXMLImportContext(rImport, nPrfx, rLocalName)
+{
+}
+
+
+XMLEventsImportContext::XMLEventsImportContext(
+ SvXMLImport& rImport,
+ sal_uInt16 nPrfx,
+ const OUString& rLocalName,
+ const Reference<XEventsSupplier> & xEventsSupplier) :
+ SvXMLImportContext(rImport, nPrfx, rLocalName),
+ xEvents(xEventsSupplier->getEvents())
+{
+}
+
+
+XMLEventsImportContext::XMLEventsImportContext(
+ SvXMLImport& rImport,
+ sal_uInt16 nPrfx,
+ const OUString& rLocalName,
+ const Reference<XNameReplace> & xNameReplace) :
+ SvXMLImportContext(rImport, nPrfx, rLocalName),
+ xEvents(xNameReplace)
+{
+}
+
+XMLEventsImportContext::~XMLEventsImportContext()
+{
+// // if, for whatever reason, the object gets destroyed prematurely,
+// // we need to delete the collected events
+// EventsVector::iterator aEnd = aCollectEvents.end();
+// for(EventsVector::iterator aIter = aCollectEvents.begin();
+// aIter != aEnd;
+// aIter++)
+// {
+// EventNameValuesPair* pPair = &(*aIter);
+// delete pPair;
+// }
+// aCollectEvents.clear();
+}
+
+
+void XMLEventsImportContext::StartElement(
+ const Reference<XAttributeList> &)
+{
+ // nothing to be done
+}
+
+void XMLEventsImportContext::EndElement()
+{
+ // nothing to be done
+}
+
+SvXMLImportContext* XMLEventsImportContext::CreateChildContext(
+ sal_uInt16 p_nPrefix,
+ const OUString& rLocalName,
+ const Reference<XAttributeList> & xAttrList )
+{
+ // a) search for script:language and script:event-name attribute
+ // b) delegate to factory. The factory will:
+ // 1) translate XML event name into API event name
+ // 2) get proper event context factory from import
+ // 3) instantiate context
+
+ // a) search for script:language and script:event-name attribute
+ OUString sLanguage;
+ OUString sEventName;
+ sal_Int16 nCount = xAttrList->getLength();
+ for (sal_Int16 nAttr = 0; nAttr < nCount; nAttr++)
+ {
+ OUString sLocalName;
+ sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
+ GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), &sLocalName );
+
+ if (XML_NAMESPACE_SCRIPT == nPrefix)
+ {
+ if (IsXMLToken(sLocalName, XML_EVENT_NAME))
+ {
+ sEventName = xAttrList->getValueByIndex(nAttr);
+ }
+ else if (IsXMLToken(sLocalName, XML_LANGUAGE))
+ {
+ sLanguage = xAttrList->getValueByIndex(nAttr);
+ }
+ // else: ignore -> let child context handle this
+ }
+ // else: ignore -> let child context handle this
+ }
+
+ // b) delegate to factory
+ return GetImport().GetEventImport().CreateContext(
+ GetImport(), p_nPrefix, rLocalName, xAttrList,
+ this, sEventName, sLanguage);
+}
+
+void XMLEventsImportContext::SetEvents(
+ const Reference<XEventsSupplier> & xEventsSupplier)
+{
+ if (xEventsSupplier.is())
+ {
+ SetEvents(xEventsSupplier->getEvents());
+ }
+}
+
+void XMLEventsImportContext::SetEvents(
+ const Reference<XNameReplace> & xNameRepl)
+{
+ if (xNameRepl.is())
+ {
+ xEvents = xNameRepl;
+
+ // now iterate over vector and a) insert b) delete all elements
+ EventsVector::iterator aEnd = aCollectEvents.end();
+ for(EventsVector::iterator aIter = aCollectEvents.begin();
+ aIter != aEnd;
+ aIter++)
+ {
+ AddEventValues(aIter->first, aIter->second);
+// EventNameValuesPair* pPair = &(*aIter);
+// delete pPair;
+ }
+ aCollectEvents.clear();
+ }
+}
+
+sal_Bool XMLEventsImportContext::GetEventSequence(
+ const OUString& rName,
+ Sequence<PropertyValue> & rSequence )
+{
+ // search through the vector
+ // (This shouldn't take a lot of time, since this method should only get
+ // called if only one (or few) events are being expected)
+
+ // iterate over vector until end or rName is found;
+ EventsVector::iterator aIter = aCollectEvents.begin();
+ while( (aIter != aCollectEvents.end()) && (aIter->first != rName) )
+ {
+ aIter++;
+ }
+
+ // if we're not at the end, set the sequence
+ sal_Bool bRet = (aIter != aCollectEvents.end());
+ if (bRet)
+ rSequence = aIter->second;
+
+ return bRet;
+}
+
+void XMLEventsImportContext::AddEventValues(
+ const OUString& rEventName,
+ const Sequence<PropertyValue> & rValues )
+{
+ // if we already have the events, set them; else just collect
+ if (xEvents.is())
+ {
+ // set event (if name is known)
+ if (xEvents->hasByName(rEventName))
+ {
+ Any aAny;
+ aAny <<= rValues;
+
+ try
+ {
+ xEvents->replaceByName(rEventName, aAny);
+ } catch ( const IllegalArgumentException & rException )
+ {
+ Sequence<OUString> aMsgParams(1);
+
+ aMsgParams[0] = rEventName;
+
+ GetImport().SetError(XMLERROR_FLAG_ERROR |
+ XMLERROR_ILLEGAL_EVENT,
+ aMsgParams, rException.Message, 0);
+ }
+ }
+ }
+ else
+ {
+// EventNameValuesPair* aPair = new EventNameValuesPair(rEventName,
+// rValues);
+// aCollectEvents.push_back(*aPair);
+ EventNameValuesPair aPair(rEventName, rValues);
+ aCollectEvents.push_back(aPair);
+ }
+}
diff --git a/xmloff/source/script/XMLScriptContextFactory.cxx b/xmloff/source/script/XMLScriptContextFactory.cxx
new file mode 100644
index 000000000000..60e08a208f72
--- /dev/null
+++ b/xmloff/source/script/XMLScriptContextFactory.cxx
@@ -0,0 +1,102 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_xmloff.hxx"
+#include "XMLScriptContextFactory.hxx"
+#include <xmloff/XMLEventsImportContext.hxx>
+#include <tools/debug.hxx>
+#include <xmloff/xmlimp.hxx>
+#include <xmloff/nmspmap.hxx>
+#include "xmloff/xmlnmspe.hxx"
+#include <xmloff/xmltoken.hxx>
+
+
+using namespace ::xmloff::token;
+
+using ::rtl::OUString;
+using ::com::sun::star::xml::sax::XAttributeList;
+using ::com::sun::star::beans::PropertyValue;
+using ::com::sun::star::uno::Reference;
+using ::com::sun::star::uno::Sequence;
+using ::com::sun::star::uno::Any;
+
+XMLScriptContextFactory::XMLScriptContextFactory() :
+ sEventType(RTL_CONSTASCII_USTRINGPARAM("EventType")),
+ sScript(RTL_CONSTASCII_USTRINGPARAM("Script")),
+ sURL(RTL_CONSTASCII_USTRINGPARAM("Script"))
+{
+}
+
+XMLScriptContextFactory::~XMLScriptContextFactory()
+{
+}
+
+SvXMLImportContext * XMLScriptContextFactory::CreateContext
+(SvXMLImport & rImport,
+ sal_uInt16 p_nPrefix,
+ const OUString & rLocalName,
+ const Reference<XAttributeList> & xAttrList,
+ XMLEventsImportContext * rEvents,
+ const OUString & rApiEventName,
+ const OUString & /*rApiLanguage*/)
+{
+ OUString sURLVal;
+
+ sal_Int16 nCount = xAttrList->getLength();
+ for (sal_Int16 nAttr = 0; nAttr < nCount; nAttr++)
+ {
+ OUString sLocalName;
+ sal_uInt16 nPrefix = rImport.GetNamespaceMap().
+ GetKeyByAttrName(xAttrList->getNameByIndex(nAttr), &sLocalName);
+
+ if (XML_NAMESPACE_XLINK == nPrefix)
+ {
+ if (IsXMLToken(sLocalName, XML_HREF))
+ sURLVal = xAttrList->getValueByIndex(nAttr);
+ // else: ignore
+ }
+ // else ignore
+ }
+
+ Sequence<PropertyValue> aValues(2);
+
+ // EventType
+ aValues[0].Name = sEventType;
+ aValues[0].Value <<= sScript;
+
+ // URL
+ aValues[1].Name = sURL;
+ aValues[1].Value <<= sURLVal;
+
+ // add values for event now
+ rEvents->AddEventValues(rApiEventName, aValues);
+
+ // return dummy context
+ return new SvXMLImportContext(rImport, p_nPrefix, rLocalName);
+}
+
diff --git a/xmloff/source/script/XMLScriptExportHandler.cxx b/xmloff/source/script/XMLScriptExportHandler.cxx
new file mode 100644
index 000000000000..9cfc7211f3b9
--- /dev/null
+++ b/xmloff/source/script/XMLScriptExportHandler.cxx
@@ -0,0 +1,88 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_xmloff.hxx"
+#include "XMLScriptExportHandler.hxx"
+
+#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP
+#include <com/sun/star/beans/PropertyValue.hpp>
+#endif
+#include <tools/debug.hxx>
+#include <xmloff/xmlexp.hxx>
+#include <xmloff/xmltoken.hxx>
+#include <xmloff/nmspmap.hxx>
+#include "xmloff/xmlnmspe.hxx"
+
+
+using namespace ::com::sun::star::uno;
+using namespace ::xmloff::token;
+
+using ::rtl::OUString;
+using ::com::sun::star::beans::PropertyValue;
+
+
+XMLScriptExportHandler::XMLScriptExportHandler() :
+ sURL(RTL_CONSTASCII_USTRINGPARAM("Script"))
+{
+}
+
+XMLScriptExportHandler::~XMLScriptExportHandler()
+{
+}
+
+void XMLScriptExportHandler::Export(
+ SvXMLExport& rExport,
+ const OUString& rEventQName,
+ Sequence<PropertyValue> & rValues,
+ sal_Bool bUseWhitespace)
+{
+
+ rExport.AddAttribute(XML_NAMESPACE_SCRIPT, XML_LANGUAGE,
+ rExport.GetNamespaceMap().GetQNameByKey(
+ XML_NAMESPACE_OOO, GetXMLToken(XML_SCRIPT) ) );
+ rExport.AddAttribute(XML_NAMESPACE_SCRIPT, XML_EVENT_NAME, rEventQName);
+
+ sal_Int32 nCount = rValues.getLength();
+ for(sal_Int32 i = 0; i < nCount; i++)
+ {
+ if (sURL.equals(rValues[i].Name))
+ {
+ OUString sTmp;
+ rValues[i].Value >>= sTmp;
+ rExport.AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, sTmp);
+
+ // #i110911# xlink:type="simple" is required
+ rExport.AddAttribute(XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE);
+ }
+ // else: disregard
+ }
+
+ SvXMLElementExport aEventElemt(rExport, XML_NAMESPACE_SCRIPT,
+ XML_EVENT_LISTENER,
+ bUseWhitespace, sal_False);
+}
diff --git a/xmloff/source/script/XMLStarBasicContextFactory.cxx b/xmloff/source/script/XMLStarBasicContextFactory.cxx
new file mode 100644
index 000000000000..a957b4bd060f
--- /dev/null
+++ b/xmloff/source/script/XMLStarBasicContextFactory.cxx
@@ -0,0 +1,139 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_xmloff.hxx"
+#include "XMLStarBasicContextFactory.hxx"
+#include <xmloff/XMLEventsImportContext.hxx>
+#include <tools/debug.hxx>
+#include <xmloff/xmlimp.hxx>
+#include <xmloff/nmspmap.hxx>
+#include "xmloff/xmlnmspe.hxx"
+#include <xmloff/xmltoken.hxx>
+
+
+using namespace ::xmloff::token;
+
+using ::rtl::OUString;
+using ::com::sun::star::xml::sax::XAttributeList;
+using ::com::sun::star::beans::PropertyValue;
+using ::com::sun::star::uno::Reference;
+using ::com::sun::star::uno::Sequence;
+using ::com::sun::star::uno::Any;
+
+
+XMLStarBasicContextFactory::XMLStarBasicContextFactory() :
+ sEventType(RTL_CONSTASCII_USTRINGPARAM("EventType")),
+ sLibrary(RTL_CONSTASCII_USTRINGPARAM("Library")),
+ sMacroName(RTL_CONSTASCII_USTRINGPARAM("MacroName")),
+ sStarBasic(RTL_CONSTASCII_USTRINGPARAM("StarBasic"))
+{
+}
+
+XMLStarBasicContextFactory::~XMLStarBasicContextFactory()
+{
+}
+
+SvXMLImportContext* XMLStarBasicContextFactory::CreateContext(
+ SvXMLImport& rImport,
+ sal_uInt16 p_nPrefix,
+ const OUString& rLocalName,
+ const Reference<XAttributeList> & xAttrList,
+ XMLEventsImportContext* rEvents,
+ const OUString& rApiEventName,
+ const OUString& /*rApiLanguage*/)
+{
+ OUString sLibraryVal;
+ OUString sMacroNameVal;
+
+ sal_Int16 nCount = xAttrList->getLength();
+ for(sal_Int16 nAttr = 0; nAttr < nCount; nAttr++)
+ {
+ OUString sLocalName;
+ sal_uInt16 nPrefix = rImport.GetNamespaceMap().
+ GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), &sLocalName );
+
+ if (XML_NAMESPACE_SCRIPT == nPrefix)
+ {
+// if (IsXMLToken(sLocalName, XML_LIBRARY))
+// {
+// sLibraryVal = xAttrList->getValueByIndex(nAttr);
+// }
+// if (IsXMLToken(sLocalName, XML_LOCATION))
+// {
+// sLibraryVal = xAttrList->getValueByIndex(nAttr);
+// if ( IsXMLToken( sLibraryVal, XML_APPLICATION ) )
+// sLibraryVal =
+// OUString(RTL_CONSTASCII_USTRINGPARAM("StarOffice"));
+// }
+// else
+ if (IsXMLToken(sLocalName, XML_MACRO_NAME))
+ {
+ sMacroNameVal = xAttrList->getValueByIndex(nAttr);
+ }
+ // else: ingore
+ }
+ // else: ignore
+ }
+
+ const OUString& rApp = GetXMLToken( XML_APPLICATION );
+ const OUString& rDoc = GetXMLToken( XML_DOCUMENT );
+ if( sMacroNameVal.getLength() > rApp.getLength()+1 &&
+ sMacroNameVal.copy(0,rApp.getLength()).equalsIgnoreAsciiCase( rApp ) &&
+ ':' == sMacroNameVal[rApp.getLength()] )
+ {
+ sLibraryVal = OUString(RTL_CONSTASCII_USTRINGPARAM("StarOffice"));
+ sMacroNameVal = sMacroNameVal.copy( rApp.getLength()+1 );
+ }
+ else if( sMacroNameVal.getLength() > rDoc.getLength()+1 &&
+ sMacroNameVal.copy(0,rDoc.getLength()).equalsIgnoreAsciiCase( rDoc ) &&
+ ':' == sMacroNameVal[rDoc.getLength()] )
+ {
+ sLibraryVal = rDoc;
+ sMacroNameVal = sMacroNameVal.copy( rDoc.getLength()+1 );
+ }
+
+ Sequence<PropertyValue> aValues(3);
+
+ // EventType
+ aValues[0].Name = sEventType;
+ aValues[0].Value <<= sStarBasic;
+
+ // library name
+ aValues[1].Name = sLibrary;
+ aValues[1].Value <<= sLibraryVal;
+
+ // macro name
+ aValues[2].Name = sMacroName;
+ aValues[2].Value <<= sMacroNameVal;
+
+ // add values for event now
+ rEvents->AddEventValues(rApiEventName, aValues);
+
+ // return dummy context
+ return new SvXMLImportContext(rImport, p_nPrefix, rLocalName);
+}
diff --git a/xmloff/source/script/XMLStarBasicExportHandler.cxx b/xmloff/source/script/XMLStarBasicExportHandler.cxx
new file mode 100644
index 000000000000..13d6948ba98e
--- /dev/null
+++ b/xmloff/source/script/XMLStarBasicExportHandler.cxx
@@ -0,0 +1,111 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_xmloff.hxx"
+#include "XMLStarBasicExportHandler.hxx"
+
+#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP
+#include <com/sun/star/beans/PropertyValue.hpp>
+#endif
+#include <tools/debug.hxx>
+#include <xmloff/xmlexp.hxx>
+#include <xmloff/xmltoken.hxx>
+#include <xmloff/nmspmap.hxx>
+#include "xmloff/xmlnmspe.hxx"
+
+
+using namespace ::com::sun::star::uno;
+using namespace ::xmloff::token;
+
+using ::rtl::OUString;
+using ::rtl::OUStringBuffer;
+using ::com::sun::star::beans::PropertyValue;
+
+
+XMLStarBasicExportHandler::XMLStarBasicExportHandler() :
+ sStarBasic(RTL_CONSTASCII_USTRINGPARAM("StarBasic")),
+ sLibrary(RTL_CONSTASCII_USTRINGPARAM("Library")),
+ sMacroName(RTL_CONSTASCII_USTRINGPARAM("MacroName")),
+ sStarOffice(RTL_CONSTASCII_USTRINGPARAM("StarOffice")),
+ sApplication(RTL_CONSTASCII_USTRINGPARAM("application"))
+{
+}
+
+XMLStarBasicExportHandler::~XMLStarBasicExportHandler()
+{
+}
+
+void XMLStarBasicExportHandler::Export(
+ SvXMLExport& rExport,
+ const OUString& rEventQName,
+ Sequence<PropertyValue> & rValues,
+ sal_Bool bUseWhitespace)
+{
+ rExport.AddAttribute(XML_NAMESPACE_SCRIPT, XML_LANGUAGE,
+ rExport.GetNamespaceMap().GetQNameByKey(
+ XML_NAMESPACE_OOO, sStarBasic ) );
+ rExport.AddAttribute(XML_NAMESPACE_SCRIPT, XML_EVENT_NAME, rEventQName);
+
+ OUString sLocation, sName;
+ sal_Int32 nCount = rValues.getLength();
+ for(sal_Int32 i = 0; i < nCount; i++)
+ {
+ if (sLibrary.equals(rValues[i].Name))
+ {
+ OUString sTmp;
+ rValues[i].Value >>= sTmp;
+ sLocation = GetXMLToken(
+ (sTmp.equalsIgnoreAsciiCase(sApplication) ||
+ sTmp.equalsIgnoreAsciiCase(sStarOffice) ) ? XML_APPLICATION
+ : XML_DOCUMENT );
+ }
+ else if (sMacroName.equals(rValues[i].Name))
+ {
+ rValues[i].Value >>= sName;
+ }
+ // else: disregard
+ }
+
+ if( sLocation.getLength() )
+ {
+ OUStringBuffer sTmp( sLocation.getLength() + sName.getLength() + 1 );
+ sTmp = sLocation;
+ sTmp.append( sal_Unicode( ':' ) );
+ sTmp.append( sName );
+ rExport.AddAttribute(XML_NAMESPACE_SCRIPT, XML_MACRO_NAME,
+ sTmp.makeStringAndClear());
+ }
+ else
+ {
+ rExport.AddAttribute(XML_NAMESPACE_SCRIPT, XML_MACRO_NAME, sName );
+ }
+
+ SvXMLElementExport aEventElemt(rExport, XML_NAMESPACE_SCRIPT,
+ XML_EVENT_LISTENER,
+ bUseWhitespace, sal_False);
+}
diff --git a/xmloff/source/script/xmlbasici.cxx b/xmloff/source/script/xmlbasici.cxx
new file mode 100644
index 000000000000..c0d01a7b0264
--- /dev/null
+++ b/xmloff/source/script/xmlbasici.cxx
@@ -0,0 +1,197 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_xmloff.hxx"
+#include "xmlbasici.hxx"
+#include <xmloff/attrlist.hxx>
+#include <xmloff/nmspmap.hxx>
+#include <xmloff/xmlimp.hxx>
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+
+
+// =============================================================================
+// XMLBasicImportContext
+// =============================================================================
+
+XMLBasicImportContext::XMLBasicImportContext( SvXMLImport& rImport, USHORT nPrfx, const ::rtl::OUString& rLName,
+ const Reference< frame::XModel >& rxModel )
+ :SvXMLImportContext( rImport, nPrfx, rLName )
+ ,m_xModel( rxModel )
+{
+ Reference< lang::XMultiServiceFactory > xMSF = GetImport().getServiceFactory();
+ if ( xMSF.is() )
+ {
+ m_xHandler.set( xMSF->createInstance(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.XMLOasisBasicImporter" ) ) ),
+ UNO_QUERY );
+ }
+
+ if ( m_xHandler.is() )
+ {
+ Reference< document::XImporter > xImporter( m_xHandler, UNO_QUERY );
+ if ( xImporter.is() )
+ {
+ Reference< lang::XComponent > xComp( m_xModel, UNO_QUERY );
+ xImporter->setTargetDocument( xComp );
+ }
+ }
+}
+
+// -----------------------------------------------------------------------------
+
+XMLBasicImportContext::~XMLBasicImportContext()
+{
+}
+
+// -----------------------------------------------------------------------------
+
+SvXMLImportContext* XMLBasicImportContext::CreateChildContext(
+ USHORT nPrefix, const ::rtl::OUString& rLocalName,
+ const Reference< xml::sax::XAttributeList >& )
+{
+ SvXMLImportContext* pContext = 0;
+
+ if ( m_xHandler.is() )
+ pContext = new XMLBasicImportChildContext( GetImport(), nPrefix, rLocalName, m_xHandler );
+
+ if ( !pContext )
+ pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
+
+ return pContext;
+}
+
+// -----------------------------------------------------------------------------
+
+void XMLBasicImportContext::StartElement(
+ const Reference< xml::sax::XAttributeList >& rxAttrList )
+{
+ if ( m_xHandler.is() )
+ {
+ m_xHandler->startDocument();
+
+ // copy namespace declarations
+ SvXMLAttributeList* pAttrList = new SvXMLAttributeList( rxAttrList );
+ Reference< xml::sax::XAttributeList > xAttrList( pAttrList );
+ const SvXMLNamespaceMap& rNamespaceMap = GetImport().GetNamespaceMap();
+ sal_uInt16 nPos = rNamespaceMap.GetFirstKey();
+ while ( nPos != USHRT_MAX )
+ {
+ ::rtl::OUString aAttrName( rNamespaceMap.GetAttrNameByKey( nPos ) );
+ if ( xAttrList->getValueByName( aAttrName ).getLength() == 0 )
+ pAttrList->AddAttribute( aAttrName, rNamespaceMap.GetNameByKey( nPos ) );
+ nPos = rNamespaceMap.GetNextKey( nPos );
+ }
+
+ m_xHandler->startElement(
+ GetImport().GetNamespaceMap().GetQNameByKey( GetPrefix(), GetLocalName() ),
+ xAttrList );
+ }
+}
+
+// -----------------------------------------------------------------------------
+
+void XMLBasicImportContext::EndElement()
+{
+ if ( m_xHandler.is() )
+ {
+ m_xHandler->endElement(
+ GetImport().GetNamespaceMap().GetQNameByKey( GetPrefix(), GetLocalName() ) );
+ m_xHandler->endDocument();
+ }
+}
+
+// -----------------------------------------------------------------------------
+
+void XMLBasicImportContext::Characters( const ::rtl::OUString& rChars )
+{
+ if ( m_xHandler.is() )
+ m_xHandler->characters( rChars );
+}
+
+
+// =============================================================================
+// XMLBasicImportChildContext
+// =============================================================================
+
+XMLBasicImportChildContext::XMLBasicImportChildContext( SvXMLImport& rImport, USHORT nPrfx, const ::rtl::OUString& rLName,
+ const Reference< xml::sax::XDocumentHandler >& rxHandler )
+ :SvXMLImportContext( rImport, nPrfx, rLName )
+ ,m_xHandler( rxHandler )
+{
+}
+
+// -----------------------------------------------------------------------------
+
+XMLBasicImportChildContext::~XMLBasicImportChildContext()
+{
+}
+
+// -----------------------------------------------------------------------------
+
+SvXMLImportContext* XMLBasicImportChildContext::CreateChildContext(
+ USHORT nPrefix, const ::rtl::OUString& rLocalName,
+ const Reference< xml::sax::XAttributeList >& )
+{
+ return new XMLBasicImportChildContext( GetImport(), nPrefix, rLocalName, m_xHandler );
+}
+
+// -----------------------------------------------------------------------------
+
+void XMLBasicImportChildContext::StartElement(
+ const Reference< xml::sax::XAttributeList >& xAttrList )
+{
+ if ( m_xHandler.is() )
+ {
+ m_xHandler->startElement(
+ GetImport().GetNamespaceMap().GetQNameByKey( GetPrefix(), GetLocalName() ),
+ xAttrList );
+ }
+}
+
+// -----------------------------------------------------------------------------
+
+void XMLBasicImportChildContext::EndElement()
+{
+ if ( m_xHandler.is() )
+ {
+ m_xHandler->endElement(
+ GetImport().GetNamespaceMap().GetQNameByKey( GetPrefix(), GetLocalName() ) );
+ }
+}
+
+// -----------------------------------------------------------------------------
+
+void XMLBasicImportChildContext::Characters( const ::rtl::OUString& rChars )
+{
+ if ( m_xHandler.is() )
+ m_xHandler->characters( rChars );
+}
+
+// -----------------------------------------------------------------------------
diff --git a/xmloff/source/script/xmlbasici.hxx b/xmloff/source/script/xmlbasici.hxx
new file mode 100644
index 000000000000..b6f6e68d6ffd
--- /dev/null
+++ b/xmloff/source/script/xmlbasici.hxx
@@ -0,0 +1,88 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _XMLOFF_XMLBASICI_HXX
+#define _XMLOFF_XMLBASICI_HXX
+
+#include <com/sun/star/frame/XModel.hpp>
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#include <xmloff/xmlictxt.hxx>
+
+
+// =============================================================================
+// class XMLBasicImportContext
+// =============================================================================
+
+class XMLBasicImportContext : public SvXMLImportContext
+{
+private:
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > m_xModel;
+ ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > m_xHandler;
+
+public:
+ XMLBasicImportContext( SvXMLImport& rImport, USHORT nPrfx, const ::rtl::OUString& rLName,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& rxModel );
+
+ virtual ~XMLBasicImportContext();
+
+ virtual SvXMLImportContext* CreateChildContext( USHORT nPrefix, const ::rtl::OUString& rLocalName,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& rxAttrList );
+
+ virtual void StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& rxAttrList );
+
+ virtual void EndElement();
+
+ virtual void Characters( const ::rtl::OUString& rChars );
+};
+
+
+// =============================================================================
+// class XMLBasicImportChildContext
+// =============================================================================
+
+class XMLBasicImportChildContext : public SvXMLImportContext
+{
+private:
+ ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > m_xHandler;
+
+public:
+ XMLBasicImportChildContext( SvXMLImport& rImport, USHORT nPrfx, const ::rtl::OUString& rLName,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler >& rxHandler );
+
+ virtual ~XMLBasicImportChildContext();
+
+ virtual SvXMLImportContext* CreateChildContext( USHORT nPrefix, const ::rtl::OUString& rLocalName,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList );
+
+ virtual void StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList );
+
+ virtual void EndElement();
+
+ virtual void Characters( const ::rtl::OUString& rChars );
+};
+
+#endif // _XMLOFF_XMLBASICI_HXX
diff --git a/xmloff/source/script/xmlscripti.cxx b/xmloff/source/script/xmlscripti.cxx
new file mode 100644
index 000000000000..d64c872d3638
--- /dev/null
+++ b/xmloff/source/script/xmlscripti.cxx
@@ -0,0 +1,188 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_xmloff.hxx"
+
+#include <xmloff/xmlscripti.hxx>
+#include "xmloff/xmlnmspe.hxx"
+#include <xmloff/xmltoken.hxx>
+#include <xmloff/xmlimp.hxx>
+#include <xmloff/nmspmap.hxx>
+#include <xmloff/XMLEventsImportContext.hxx>
+#include "xmlbasici.hxx"
+
+#include <com/sun/star/document/XEventsSupplier.hpp>
+#include <com/sun/star/document/XEmbeddedScripts.hpp>
+
+using ::rtl::OUString;
+using namespace com::sun::star;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::lang;
+using namespace com::sun::star::frame;
+using namespace com::sun::star::document;
+using namespace com::sun::star::xml::sax;
+using namespace ::xmloff::token;
+
+
+// =============================================================================
+// XMLScriptChildContext: context for <office:script> element
+// =============================================================================
+
+class XMLScriptChildContext : public SvXMLImportContext
+{
+private:
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > m_xModel;
+ ::com::sun::star::uno::Reference< ::com::sun::star::document::XEmbeddedScripts > m_xDocumentScripts;
+ ::rtl::OUString m_aLanguage;
+
+public:
+ XMLScriptChildContext( SvXMLImport& rImport, USHORT nPrfx, const ::rtl::OUString& rLName,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel>& rxModel,
+ const ::rtl::OUString& rLanguage );
+ virtual ~XMLScriptChildContext();
+
+ virtual SvXMLImportContext* CreateChildContext( USHORT nPrefix, const ::rtl::OUString& rLocalName,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList );
+
+ virtual void EndElement();
+};
+
+// -----------------------------------------------------------------------------
+
+XMLScriptChildContext::XMLScriptChildContext( SvXMLImport& rImport, USHORT nPrfx, const ::rtl::OUString& rLName,
+ const Reference< frame::XModel >& rxModel, const ::rtl::OUString& rLanguage )
+ :SvXMLImportContext( rImport, nPrfx, rLName )
+ ,m_xModel( rxModel )
+ ,m_xDocumentScripts( rxModel, UNO_QUERY )
+ ,m_aLanguage( rLanguage )
+{
+}
+
+// -----------------------------------------------------------------------------
+
+XMLScriptChildContext::~XMLScriptChildContext()
+{
+}
+
+// -----------------------------------------------------------------------------
+
+SvXMLImportContext* XMLScriptChildContext::CreateChildContext(
+ USHORT nPrefix, const ::rtl::OUString& rLocalName,
+ const Reference< xml::sax::XAttributeList >& xAttrList )
+{
+ SvXMLImportContext* pContext = NULL;
+
+ if ( m_xDocumentScripts.is() )
+ { // document supports embedding scripts/macros
+ ::rtl::OUString aBasic( GetImport().GetNamespaceMap().GetPrefixByKey( XML_NAMESPACE_OOO ) );
+ aBasic += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ":Basic" ) );
+
+ if ( m_aLanguage == aBasic && nPrefix == XML_NAMESPACE_OOO && IsXMLToken( rLocalName, XML_LIBRARIES ) )
+ pContext = new XMLBasicImportContext( GetImport(), nPrefix, rLocalName, m_xModel );
+ }
+
+ if ( !pContext )
+ pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
+
+ return pContext;
+}
+
+// -----------------------------------------------------------------------------
+
+void XMLScriptChildContext::EndElement()
+{
+}
+
+// =============================================================================
+// XMLScriptContext: context for <office:scripts> element
+// =============================================================================
+
+XMLScriptContext::XMLScriptContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
+ const Reference<XModel>& rDocModel )
+ :SvXMLImportContext( rImport, nPrfx, rLName )
+ ,m_xModel( rDocModel )
+{
+}
+
+// -----------------------------------------------------------------------------
+
+XMLScriptContext::~XMLScriptContext()
+{
+}
+
+// -----------------------------------------------------------------------------
+
+SvXMLImportContext* XMLScriptContext::CreateChildContext(
+ sal_uInt16 nPrefix, const OUString& rLName,
+ const Reference<XAttributeList>& xAttrList )
+{
+ SvXMLImportContext* pContext = NULL;
+
+ if ( nPrefix == XML_NAMESPACE_OFFICE )
+ {
+ if ( IsXMLToken( rLName, XML_EVENT_LISTENERS ) )
+ {
+ Reference< XEventsSupplier> xSupplier( GetImport().GetModel(), UNO_QUERY );
+ pContext = new XMLEventsImportContext( GetImport(), nPrefix, rLName, xSupplier );
+ }
+ else if ( IsXMLToken( rLName, XML_SCRIPT ) )
+ {
+ ::rtl::OUString aAttrName( GetImport().GetNamespaceMap().GetPrefixByKey( XML_NAMESPACE_SCRIPT ) );
+ aAttrName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ":language" ) );
+ if ( xAttrList.is() )
+ {
+ ::rtl::OUString aLanguage = xAttrList->getValueByName( aAttrName );
+
+ if ( m_xModel.is() )
+ {
+ uno::Sequence< beans::PropertyValue > aMedDescr = m_xModel->getArgs();
+ sal_Int32 nNewLen = aMedDescr.getLength() + 1;
+ aMedDescr.realloc( nNewLen );
+ aMedDescr[nNewLen-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BreakMacroSignature" ) );
+ aMedDescr[nNewLen-1].Value <<= (sal_Bool)sal_True;
+ m_xModel->attachResource( m_xModel->getURL(), aMedDescr );
+
+ pContext = new XMLScriptChildContext( GetImport(), nPrefix, rLName, m_xModel, aLanguage );
+ }
+ }
+ }
+ }
+
+ if ( !pContext )
+ pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLName, xAttrList);
+
+ return pContext;
+}
+
+// -----------------------------------------------------------------------------
+
+void XMLScriptContext::EndElement()
+{
+}
+
+// -----------------------------------------------------------------------------