merge the formfield patch from ooo-build
[ooovba.git] / starmath / source / mathmlimport.cxx
blob1f7336db6d3cfcbacf80c616a51281c5537ae76b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: x $
10 * $Revision: 1.00 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_starmath.hxx"
34 /*todo: Change characters and tcharacters to accumulate the characters together
35 into one string, xml parser hands them to us line by line rather than all in
36 one go*/
38 #include <com/sun/star/xml/sax/XErrorHandler.hpp>
39 #include <com/sun/star/xml/sax/XEntityResolver.hpp>
40 #include <com/sun/star/xml/sax/InputSource.hpp>
41 #include <com/sun/star/xml/sax/XDTDHandler.hpp>
42 #include <com/sun/star/xml/sax/XParser.hpp>
43 #include <com/sun/star/io/XActiveDataSource.hpp>
44 #include <com/sun/star/io/XActiveDataControl.hpp>
45 #include <com/sun/star/document/XDocumentProperties.hpp>
46 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
47 #include <com/sun/star/packages/zip/ZipIOException.hpp>
48 #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
49 #include <com/sun/star/beans/PropertyAttribute.hpp>
50 #include <com/sun/star/container/XNameAccess.hpp>
51 #include <com/sun/star/embed/ElementModes.hpp>
52 #include <com/sun/star/uno/Any.h>
54 #include <rtl/math.hxx>
55 #include <sfx2/frame.hxx>
56 #include <sfx2/docfile.hxx>
57 #include <tools/debug.hxx>
58 #include <tools/urlobj.hxx>
59 #include <svtools/sfxecode.hxx>
60 #include <svtools/saveopt.hxx>
61 #include <svtools/stritem.hxx>
62 #include <svtools/itemprop.hxx>
63 #include <unotools/processfactory.hxx>
64 #include <unotools/streamwrap.hxx>
65 #include <xmloff/xmlnmspe.hxx>
66 #include <xmloff/xmltoken.hxx>
67 #include <xmloff/nmspmap.hxx>
68 #include <xmloff/attrlist.hxx>
69 #include <xmloff/xmluconv.hxx>
70 #include <xmloff/xmlmetai.hxx>
71 #include <osl/mutex.hxx>
72 #include <comphelper/genericpropertyset.hxx>
74 #include <memory>
76 #include "mathmlimport.hxx"
77 #include "mathtype.hxx"
78 #include <starmath.hrc>
79 #include <unomodel.hxx>
80 #include <document.hxx>
81 #include <utility.hxx>
83 using namespace ::com::sun::star::beans;
84 using namespace ::com::sun::star::container;
85 using namespace ::com::sun::star::document;
86 using namespace ::com::sun::star::lang;
87 using namespace ::com::sun::star::uno;
88 using namespace ::com::sun::star;
89 using namespace ::xmloff::token;
91 using ::rtl::OUString;
92 using ::rtl::OUStringBuffer;
94 #define IMPORT_SVC_NAME RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.XMLImportFilter")
96 #undef WANTEXCEPT
98 ////////////////////////////////////////////////////////////
100 ULONG SmXMLImportWrapper::Import(SfxMedium &rMedium)
102 ULONG nError = ERRCODE_SFX_DOLOADFAILED;
104 uno::Reference<lang::XMultiServiceFactory> xServiceFactory(
105 utl::getProcessServiceFactory());
106 DBG_ASSERT(xServiceFactory.is(), "XMLReader::Read: got no service manager");
107 if ( !xServiceFactory.is() )
108 return nError;
110 //Make a model component from our SmModel
111 uno::Reference< lang::XComponent > xModelComp( xModel, uno::UNO_QUERY );
112 DBG_ASSERT( xModelComp.is(), "XMLReader::Read: got no model" );
114 // try to get an XStatusIndicator from the Medium
115 uno::Reference<task::XStatusIndicator> xStatusIndicator;
117 sal_Bool bEmbedded = sal_False;
118 uno::Reference <lang::XUnoTunnel> xTunnel;
119 xTunnel = uno::Reference <lang::XUnoTunnel> (xModel,uno::UNO_QUERY);
120 SmModel *pModel = reinterpret_cast<SmModel *>
121 (xTunnel->getSomething(SmModel::getUnoTunnelId()));
123 SmDocShell *pDocShell = pModel ?
124 static_cast<SmDocShell*>(pModel->GetObjectShell()) : 0;
125 if (pDocShell)
127 // if (pDocShell->GetMedium())
129 DBG_ASSERT( pDocShell->GetMedium() == &rMedium,
130 "different SfxMedium found" );
132 SfxItemSet* pSet = rMedium.GetItemSet();
133 if (pSet)
135 const SfxUnoAnyItem* pItem = static_cast<const SfxUnoAnyItem*>(
136 pSet->GetItem(SID_PROGRESS_STATUSBAR_CONTROL) );
137 if (pItem)
138 pItem->GetValue() >>= xStatusIndicator;
142 if ( SFX_CREATE_MODE_EMBEDDED == pDocShell->GetCreateMode() )
143 bEmbedded = sal_True;
146 comphelper::PropertyMapEntry aInfoMap[] =
148 { "PrivateData", sizeof("PrivateData")-1, 0,
149 &::getCppuType( (Reference<XInterface> *)0 ),
150 beans::PropertyAttribute::MAYBEVOID, 0 },
151 { "BaseURI", sizeof("BaseURI")-1, 0,
152 &::getCppuType( (OUString *)0 ),
153 beans::PropertyAttribute::MAYBEVOID, 0 },
154 { "StreamRelPath", sizeof("StreamRelPath")-1, 0,
155 &::getCppuType( (OUString *)0 ),
156 beans::PropertyAttribute::MAYBEVOID, 0 },
157 { "StreamName", sizeof("StreamName")-1, 0,
158 &::getCppuType( (OUString *)0 ),
159 beans::PropertyAttribute::MAYBEVOID, 0 },
160 { NULL, 0, 0, NULL, 0, 0 }
162 uno::Reference< beans::XPropertySet > xInfoSet(
163 comphelper::GenericPropertySet_CreateInstance(
164 new comphelper::PropertySetInfo( aInfoMap ) ) );
166 // Set base URI
167 OUString sPropName( RTL_CONSTASCII_USTRINGPARAM("BaseURI") );
168 xInfoSet->setPropertyValue( sPropName, makeAny( rMedium.GetBaseURL() ) );
170 sal_Int32 nSteps=3;
171 if ( !(rMedium.IsStorage()))
172 nSteps = 1;
174 sal_Int32 nProgressRange(nSteps);
175 if (xStatusIndicator.is())
177 xStatusIndicator->start(String(SmResId(STR_STATSTR_READING)),
178 nProgressRange);
181 nSteps=0;
182 if (xStatusIndicator.is())
183 xStatusIndicator->setValue(nSteps++);
185 if ( rMedium.IsStorage())
187 // TODO/LATER: handle the case of embedded links gracefully
188 if ( bEmbedded ) // && !rMedium.GetStorage()->IsRoot() )
190 OUString aName( RTL_CONSTASCII_USTRINGPARAM( "dummyObjName" ) );
191 if ( rMedium.GetItemSet() )
193 const SfxStringItem* pDocHierarchItem = static_cast<const SfxStringItem*>(
194 rMedium.GetItemSet()->GetItem(SID_DOC_HIERARCHICALNAME) );
195 if ( pDocHierarchItem )
196 aName = pDocHierarchItem->GetValue();
199 if ( aName.getLength() )
201 sPropName = OUString(RTL_CONSTASCII_USTRINGPARAM("StreamRelPath"));
202 xInfoSet->setPropertyValue( sPropName, makeAny( aName ) );
206 sal_Bool bOASIS = ( SotStorage::GetVersion( rMedium.GetStorage() ) > SOFFICE_FILEFORMAT_60 );
207 if (xStatusIndicator.is())
208 xStatusIndicator->setValue(nSteps++);
210 ULONG nWarn = ReadThroughComponent(
211 rMedium.GetStorage(), xModelComp, "meta.xml", "Meta.xml",
212 xServiceFactory, xInfoSet,
213 (bOASIS ? "com.sun.star.comp.Math.XMLOasisMetaImporter"
214 : "com.sun.star.comp.Math.XMLMetaImporter") );
216 if ( nWarn != ERRCODE_IO_BROKENPACKAGE )
218 if (xStatusIndicator.is())
219 xStatusIndicator->setValue(nSteps++);
221 nWarn = ReadThroughComponent(
222 rMedium.GetStorage(), xModelComp, "settings.xml", 0,
223 xServiceFactory, xInfoSet,
224 (bOASIS ? "com.sun.star.comp.Math.XMLOasisSettingsImporter"
225 : "com.sun.star.comp.Math.XMLSettingsImporter" ) );
227 if ( nWarn != ERRCODE_IO_BROKENPACKAGE )
229 if (xStatusIndicator.is())
230 xStatusIndicator->setValue(nSteps++);
232 nError = ReadThroughComponent(
233 rMedium.GetStorage(), xModelComp, "content.xml", "Content.xml",
234 xServiceFactory, xInfoSet, "com.sun.star.comp.Math.XMLImporter" );
236 else
237 nError = ERRCODE_IO_BROKENPACKAGE;
239 else
240 nError = ERRCODE_IO_BROKENPACKAGE;
242 else
244 Reference<io::XInputStream> xInputStream =
245 new utl::OInputStreamWrapper(rMedium.GetInStream());
247 if (xStatusIndicator.is())
248 xStatusIndicator->setValue(nSteps++);
250 nError = ReadThroughComponent( xInputStream, xModelComp,
251 xServiceFactory, xInfoSet, "com.sun.star.comp.Math.XMLImporter", FALSE );
254 if (xStatusIndicator.is())
255 xStatusIndicator->end();
256 return nError;
260 /// read a component (file + filter version)
261 ULONG SmXMLImportWrapper::ReadThroughComponent(
262 Reference<io::XInputStream> xInputStream,
263 Reference<XComponent> xModelComponent,
264 Reference<lang::XMultiServiceFactory> & rFactory,
265 Reference<beans::XPropertySet> & rPropSet,
266 const sal_Char* pFilterName,
267 sal_Bool bEncrypted )
269 ULONG nError = ERRCODE_SFX_DOLOADFAILED;
270 DBG_ASSERT(xInputStream.is(), "input stream missing");
271 DBG_ASSERT(xModelComponent.is(), "document missing");
272 DBG_ASSERT(rFactory.is(), "factory missing");
273 DBG_ASSERT(NULL != pFilterName,"I need a service name for the component!");
275 // prepare ParserInputSrouce
276 xml::sax::InputSource aParserInput;
277 aParserInput.aInputStream = xInputStream;
279 // get parser
280 Reference< xml::sax::XParser > xParser(
281 rFactory->createInstance(
282 OUString::createFromAscii("com.sun.star.xml.sax.Parser") ),
283 UNO_QUERY );
284 DBG_ASSERT( xParser.is(), "Can't create parser" );
285 if ( !xParser.is() )
286 return nError;
288 Sequence<Any> aArgs( 1 );
289 aArgs[0] <<= rPropSet;
291 // get filter
292 Reference< xml::sax::XDocumentHandler > xFilter(
293 rFactory->createInstanceWithArguments(
294 OUString::createFromAscii(pFilterName), aArgs ),
295 UNO_QUERY );
296 DBG_ASSERT( xFilter.is(), "Can't instantiate filter component." );
297 if ( !xFilter.is() )
298 return nError;
300 // connect parser and filter
301 xParser->setDocumentHandler( xFilter );
303 // connect model and filter
304 Reference < XImporter > xImporter( xFilter, UNO_QUERY );
305 xImporter->setTargetDocument( xModelComponent );
307 // finally, parser the stream
310 xParser->parseStream( aParserInput );
312 uno::Reference<lang::XUnoTunnel> xFilterTunnel;
313 xFilterTunnel = uno::Reference<lang::XUnoTunnel>
314 ( xFilter, uno::UNO_QUERY );
315 SmXMLImport *pFilter = reinterpret_cast< SmXMLImport * >(
316 sal::static_int_cast< sal_uIntPtr >(
317 xFilterTunnel->getSomething( SmXMLImport::getUnoTunnelId() )));
318 if ( pFilter && pFilter->GetSuccess() )
319 nError = 0;
321 catch( xml::sax::SAXParseException& r )
323 // sax parser sends wrapped exceptions,
324 // try to find the original one
325 xml::sax::SAXException aSaxEx = *(xml::sax::SAXException*)(&r);
326 sal_Bool bTryChild = sal_True;
328 while( bTryChild )
330 xml::sax::SAXException aTmp;
331 if ( aSaxEx.WrappedException >>= aTmp )
332 aSaxEx = aTmp;
333 else
334 bTryChild = sal_False;
337 packages::zip::ZipIOException aBrokenPackage;
338 if ( aSaxEx.WrappedException >>= aBrokenPackage )
339 return ERRCODE_IO_BROKENPACKAGE;
341 if ( bEncrypted )
342 nError = ERRCODE_SFX_WRONGPASSWORD;
344 catch( xml::sax::SAXException& r )
346 packages::zip::ZipIOException aBrokenPackage;
347 if ( r.WrappedException >>= aBrokenPackage )
348 return ERRCODE_IO_BROKENPACKAGE;
350 if ( bEncrypted )
351 nError = ERRCODE_SFX_WRONGPASSWORD;
353 catch( packages::zip::ZipIOException& )
355 nError = ERRCODE_IO_BROKENPACKAGE;
357 catch( io::IOException& )
361 return nError;
365 ULONG SmXMLImportWrapper::ReadThroughComponent(
366 const uno::Reference< embed::XStorage >& xStorage,
367 Reference<XComponent> xModelComponent,
368 const sal_Char* pStreamName,
369 const sal_Char* pCompatibilityStreamName,
370 Reference<lang::XMultiServiceFactory> & rFactory,
371 Reference<beans::XPropertySet> & rPropSet,
372 const sal_Char* pFilterName )
374 DBG_ASSERT(xStorage.is(), "Need storage!");
375 DBG_ASSERT(NULL != pStreamName, "Please, please, give me a name!");
377 // open stream (and set parser input)
378 OUString sStreamName = OUString::createFromAscii(pStreamName);
379 uno::Reference < container::XNameAccess > xAccess( xStorage, uno::UNO_QUERY );
380 if ( !xAccess->hasByName(sStreamName) || !xStorage->isStreamElement(sStreamName) )
382 // stream name not found! Then try the compatibility name.
383 // do we even have an alternative name?
384 if ( pCompatibilityStreamName )
385 sStreamName = OUString::createFromAscii(pCompatibilityStreamName);
388 // get input stream
391 uno::Reference < io::XStream > xEventsStream = xStorage->openStreamElement( sStreamName, embed::ElementModes::READ );
393 // determine if stream is encrypted or not
394 uno::Reference < beans::XPropertySet > xProps( xEventsStream, uno::UNO_QUERY );
395 Any aAny = xProps->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Encrypted") ) );
396 sal_Bool bEncrypted = sal_False;
397 if ( aAny.getValueType() == ::getBooleanCppuType() )
398 aAny >>= bEncrypted;
400 // set Base URL
401 if ( rPropSet.is() )
403 OUString sPropName( RTL_CONSTASCII_USTRINGPARAM("StreamName") );
404 rPropSet->setPropertyValue( sPropName, makeAny( sStreamName ) );
408 Reference < io::XInputStream > xStream = xEventsStream->getInputStream();
409 return ReadThroughComponent( xStream, xModelComponent, rFactory, rPropSet, pFilterName, bEncrypted );
411 catch ( packages::WrongPasswordException& )
413 return ERRCODE_SFX_WRONGPASSWORD;
415 catch( packages::zip::ZipIOException& )
417 return ERRCODE_IO_BROKENPACKAGE;
419 catch ( uno::Exception& )
423 return ERRCODE_SFX_DOLOADFAILED;
426 ////////////////////////////////////////////////////////////
428 SmXMLImport::SmXMLImport(
429 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceFactory,
430 sal_uInt16 nImportFlags)
431 : SvXMLImport( xServiceFactory, nImportFlags ),
432 pPresLayoutElemTokenMap(0),
433 pPresLayoutAttrTokenMap(0),
434 pFencedAttrTokenMap(0),
435 pOperatorAttrTokenMap(0),
436 pAnnotationAttrTokenMap(0),
437 pPresElemTokenMap(0),
438 pPresScriptEmptyElemTokenMap(0),
439 pPresTableElemTokenMap(0),
440 pColorTokenMap(0),
441 bSuccess(sal_False)
445 const uno::Sequence< sal_Int8 > & SmXMLImport::getUnoTunnelId() throw()
447 static uno::Sequence< sal_Int8 > * pSeq = 0;
448 if ( !pSeq )
450 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
451 if ( !pSeq )
453 static uno::Sequence< sal_Int8 > aSeq( 16 );
454 rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
455 pSeq = &aSeq;
458 return *pSeq;
461 OUString SAL_CALL SmXMLImport_getImplementationName() throw()
463 return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Math.XMLImporter" ) );
466 uno::Sequence< OUString > SAL_CALL SmXMLImport_getSupportedServiceNames()
467 throw()
469 const OUString aServiceName( IMPORT_SVC_NAME );
470 const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
471 return aSeq;
474 uno::Reference< uno::XInterface > SAL_CALL SmXMLImport_createInstance(
475 const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
476 throw( uno::Exception )
478 // #110680#
479 // return (cppu::OWeakObject*)new SmXMLImport(IMPORT_ALL);
480 return (cppu::OWeakObject*)new SmXMLImport(rSMgr, IMPORT_ALL);
483 ////////////////////////////////////////////////////////////
485 OUString SAL_CALL SmXMLImportMeta_getImplementationName() throw()
487 return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Math.XMLOasisMetaImporter" ) );
490 uno::Sequence< OUString > SAL_CALL SmXMLImportMeta_getSupportedServiceNames()
491 throw()
493 const OUString aServiceName( IMPORT_SVC_NAME );
494 const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
495 return aSeq;
498 uno::Reference< uno::XInterface > SAL_CALL SmXMLImportMeta_createInstance(
499 const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
500 throw( uno::Exception )
502 // #110680#
503 // return (cppu::OWeakObject*)new SmXMLImport( IMPORT_META );
504 return (cppu::OWeakObject*)new SmXMLImport( rSMgr, IMPORT_META );
507 ////////////////////////////////////////////////////////////
509 OUString SAL_CALL SmXMLImportSettings_getImplementationName() throw()
511 return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Math.XMLOasisSettingsImporter" ) );
514 uno::Sequence< OUString > SAL_CALL SmXMLImportSettings_getSupportedServiceNames()
515 throw()
517 const OUString aServiceName( IMPORT_SVC_NAME );
518 const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
519 return aSeq;
522 uno::Reference< uno::XInterface > SAL_CALL SmXMLImportSettings_createInstance(
523 const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
524 throw( uno::Exception )
526 // #110680#
527 // return (cppu::OWeakObject*)new SmXMLImport( IMPORT_SETTINGS );
528 return (cppu::OWeakObject*)new SmXMLImport( rSMgr, IMPORT_SETTINGS );
531 ////////////////////////////////////////////////////////////
533 // XServiceInfo
534 // override empty method from parent class
535 rtl::OUString SAL_CALL SmXMLImport::getImplementationName()
536 throw(uno::RuntimeException)
538 OUString aTxt;
539 switch( getImportFlags() )
541 case IMPORT_META:
542 aTxt = SmXMLImportMeta_getImplementationName();
543 break;
544 case IMPORT_SETTINGS:
545 aTxt = SmXMLImportSettings_getImplementationName();
546 break;
547 case IMPORT_ALL:
548 default:
549 aTxt = SmXMLImport_getImplementationName();
550 break;
552 return aTxt;
556 sal_Int64 SAL_CALL SmXMLImport::getSomething(
557 const uno::Sequence< sal_Int8 >&rId )
558 throw(uno::RuntimeException)
560 if ( rId.getLength() == 16 &&
561 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
562 rId.getConstArray(), 16 ) )
563 return sal::static_int_cast< sal_Int64 >(reinterpret_cast< sal_uIntPtr >(this));
565 return SvXMLImport::getSomething( rId );
568 void SmXMLImport::endDocument(void)
569 throw(xml::sax::SAXException, uno::RuntimeException)
571 //Set the resulted tree into the SmDocShell where it belongs
572 SmNode *pTree;
573 if (NULL != (pTree = GetTree()))
575 uno::Reference <frame::XModel> xModel = GetModel();
576 uno::Reference <lang::XUnoTunnel> xTunnel;
577 xTunnel = uno::Reference <lang::XUnoTunnel> (xModel,uno::UNO_QUERY);
578 SmModel *pModel = reinterpret_cast<SmModel *>
579 (xTunnel->getSomething(SmModel::getUnoTunnelId()));
581 if (pModel)
583 SmDocShell *pDocShell =
584 static_cast<SmDocShell*>(pModel->GetObjectShell());
585 pDocShell->SetFormulaTree(pTree);
586 if (0 == aText.Len()) //If we picked up no annotation text
588 //Make up some editable text
589 aText = pDocShell->GetText();
590 pTree->CreateTextFromNode(aText);
591 aText.EraseTrailingChars();
592 if ((aText.GetChar(0) == '{') &&
593 (aText.GetChar(aText.Len()-1) == '}'))
595 aText.Erase(0,1);
596 aText.Erase(aText.Len()-1,1);
599 pDocShell->SetText( String() );
601 // Convert symbol names
602 SmParser &rParser = pDocShell->GetParser();
603 BOOL bVal = rParser.IsImportSymbolNames();
604 rParser.SetImportSymbolNames( TRUE );
605 SmNode *pTmpTree = rParser.Parse( aText );
606 aText = rParser.GetText();
607 delete pTmpTree;
608 rParser.SetImportSymbolNames( bVal );
610 pDocShell->SetText( aText );
612 DBG_ASSERT(pModel,"So there *was* a uno problem after all");
614 bSuccess = sal_True;
617 SvXMLImport::endDocument();
620 ////////////////////////////////////////////////////////////
622 class SmXMLImportContext: public SvXMLImportContext
624 public:
625 SmXMLImportContext( SmXMLImport &rImport, sal_uInt16 nPrfx,
626 const OUString& rLName)
627 : SvXMLImportContext(rImport, nPrfx, rLName) {}
629 const SmXMLImport& GetSmImport() const
631 return (const SmXMLImport&)GetImport();
634 SmXMLImport& GetSmImport()
636 return (SmXMLImport&)GetImport();
639 virtual void TCharacters(const OUString & /*rChars*/);
640 virtual void Characters(const OUString &rChars);
641 virtual SvXMLImportContext *CreateChildContext(sal_uInt16 /*nPrefix*/, const OUString& /*rLocalName*/, const uno::Reference< xml::sax::XAttributeList > & /*xAttrList*/);
644 void SmXMLImportContext::TCharacters(const OUString & /*rChars*/)
648 void SmXMLImportContext::Characters(const OUString &rChars)
651 Whitespace occurring within the content of token elements is "trimmed"
652 from the ends (i.e. all whitespace at the beginning and end of the
653 content is removed), and "collapsed" internally (i.e. each sequence of
654 1 or more whitespace characters is replaced with one blank character).
656 //collapsing not done yet!
657 const OUString &rChars2 = rChars.trim();
658 if (rChars2.getLength())
659 TCharacters(rChars2/*.collapse()*/);
662 SvXMLImportContext * SmXMLImportContext::CreateChildContext(sal_uInt16 /*nPrefix*/,
663 const OUString& /*rLocalName*/,
664 const uno::Reference< xml::sax::XAttributeList > & /*xAttrList*/)
666 return 0;
669 ////////////////////////////////////////////////////////////
671 struct SmXMLContext_Helper
673 sal_Int8 nIsBold;
674 sal_Int8 nIsItalic;
675 double nFontSize;
676 sal_Bool bFontNodeNeeded;
677 OUString sFontFamily;
678 OUString sColor;
680 SmXMLImportContext rContext;
682 SmXMLContext_Helper(SmXMLImportContext &rImport) :
683 nIsBold(-1), nIsItalic(-1), nFontSize(0.0), rContext(rImport) {}
685 void RetrieveAttrs(const uno::Reference< xml::sax::XAttributeList > &xAttrList );
686 void ApplyAttrs();
689 void SmXMLContext_Helper::RetrieveAttrs(const uno::Reference<
690 xml::sax::XAttributeList > & xAttrList )
692 sal_Int8 nOldIsBold=nIsBold;
693 sal_Int8 nOldIsItalic=nIsItalic;
694 double nOldFontSize=nFontSize;
695 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
696 OUString sOldFontFamily = sFontFamily;
697 for (sal_Int16 i=0;i<nAttrCount;i++)
699 OUString sAttrName = xAttrList->getNameByIndex(i);
700 OUString aLocalName;
701 sal_uInt16 nPrefix = rContext.GetSmImport().GetNamespaceMap().
702 GetKeyByAttrName(sAttrName,&aLocalName);
703 OUString sValue = xAttrList->getValueByIndex(i);
704 const SvXMLTokenMap &rAttrTokenMap =
705 rContext.GetSmImport().GetPresLayoutAttrTokenMap();
706 switch(rAttrTokenMap.Get(nPrefix,aLocalName))
708 case XML_TOK_FONTWEIGHT:
709 nIsBold = sValue.equals(GetXMLToken(XML_BOLD));
710 break;
711 case XML_TOK_FONTSTYLE:
712 nIsItalic = sValue.equals(GetXMLToken(XML_ITALIC));
713 break;
714 case XML_TOK_FONTSIZE:
715 SvXMLUnitConverter::convertDouble(nFontSize,sValue);
716 rContext.GetSmImport().GetMM100UnitConverter().
717 setXMLMeasureUnit(MAP_POINT);
718 if (-1 == sValue.indexOf(GetXMLToken(XML_UNIT_PT)))
720 if (-1 == sValue.indexOf('%'))
721 nFontSize=0.0;
722 else
724 rContext.GetSmImport().GetMM100UnitConverter().
725 setXMLMeasureUnit(MAP_RELATIVE);
728 break;
729 case XML_TOK_FONTFAMILY:
730 sFontFamily = sValue;
731 break;
732 case XML_TOK_COLOR:
733 sColor = sValue;
734 break;
735 default:
736 break;
740 if ((nOldIsBold!=nIsBold) || (nOldIsItalic!=nIsItalic) ||
741 (nOldFontSize!=nFontSize) || (sOldFontFamily!=sFontFamily)
742 || sColor.getLength())
743 bFontNodeNeeded=sal_True;
744 else
745 bFontNodeNeeded=sal_False;
748 void SmXMLContext_Helper::ApplyAttrs()
750 SmNodeStack &rNodeStack = rContext.GetSmImport().GetNodeStack();
752 if (bFontNodeNeeded)
754 SmToken aToken;
755 aToken.cMathChar = '\0';
756 aToken.nGroup = 0;
757 aToken.nLevel = 5;
759 if (nIsBold != -1)
761 if (nIsBold)
762 aToken.eType = TBOLD;
763 else
764 aToken.eType = TNBOLD;
765 SmStructureNode *pFontNode = static_cast<SmStructureNode *>
766 (new SmFontNode(aToken));
767 pFontNode->SetSubNodes(0,rNodeStack.Pop());
768 rNodeStack.Push(pFontNode);
770 if (nIsItalic != -1)
772 if (nIsItalic)
773 aToken.eType = TITALIC;
774 else
775 aToken.eType = TNITALIC;
776 SmStructureNode *pFontNode = static_cast<SmStructureNode *>
777 (new SmFontNode(aToken));
778 pFontNode->SetSubNodes(0,rNodeStack.Pop());
779 rNodeStack.Push(pFontNode);
781 if (nFontSize != 0.0)
783 aToken.eType = TSIZE;
784 SmFontNode *pFontNode = new SmFontNode(aToken);
786 if (MAP_RELATIVE == rContext.GetSmImport().GetMM100UnitConverter().
787 getXMLMeasureUnit())
789 if (nFontSize < 100.00)
790 pFontNode->SetSizeParameter(Fraction(100.00/nFontSize),
791 FNTSIZ_DIVIDE);
792 else
793 pFontNode->SetSizeParameter(Fraction(nFontSize/100.00),
794 FNTSIZ_MULTIPLY);
796 else
797 pFontNode->SetSizeParameter(Fraction(nFontSize),FNTSIZ_ABSOLUT);
799 pFontNode->SetSubNodes(0,rNodeStack.Pop());
800 rNodeStack.Push(pFontNode);
802 if (sFontFamily.getLength())
804 if (sFontFamily.equalsIgnoreAsciiCase(GetXMLToken(XML_FIXED)))
805 aToken.eType = TFIXED;
806 else if (sFontFamily.equalsIgnoreAsciiCase(OUString(
807 RTL_CONSTASCII_USTRINGPARAM("sans"))))
808 aToken.eType = TSANS;
809 else if (sFontFamily.equalsIgnoreAsciiCase(OUString(
810 RTL_CONSTASCII_USTRINGPARAM("serif"))))
811 aToken.eType = TSERIF;
812 else //Just give up, we need to extend our font mechanism to be
813 //more general
814 return;
816 aToken.aText = sFontFamily;
817 SmFontNode *pFontNode = new SmFontNode(aToken);
818 pFontNode->SetSubNodes(0,rNodeStack.Pop());
819 rNodeStack.Push(pFontNode);
821 if (sColor.getLength())
823 //Again we can only handle a small set of colours in
824 //StarMath for now.
825 const SvXMLTokenMap& rTokenMap =
826 rContext.GetSmImport().GetColorTokenMap();
827 aToken.eType = static_cast<SmTokenType>(rTokenMap.Get(
828 XML_NAMESPACE_MATH, sColor));
829 if (aToken.eType != -1)
831 SmFontNode *pFontNode = new SmFontNode(aToken);
832 pFontNode->SetSubNodes(0,rNodeStack.Pop());
833 rNodeStack.Push(pFontNode);
840 ////////////////////////////////////////////////////////////
842 class SmXMLDocContext_Impl : public SmXMLImportContext
844 public:
845 SmXMLDocContext_Impl( SmXMLImport &rImport, sal_uInt16 nPrfx,
846 const OUString& rLName)
847 : SmXMLImportContext(rImport,nPrfx,rLName) {}
849 virtual SvXMLImportContext *CreateChildContext(sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< xml::sax::XAttributeList > &xAttrList);
851 void EndElement();
854 ////////////////////////////////////////////////////////////
856 /*avert thy gaze from the proginator*/
857 class SmXMLRowContext_Impl : public SmXMLDocContext_Impl
859 protected:
860 ULONG nElementCount;
862 public:
863 SmXMLRowContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
864 const OUString& rLName)
865 : SmXMLDocContext_Impl(rImport,nPrefix,rLName)
866 { nElementCount = GetSmImport().GetNodeStack().Count(); }
868 virtual SvXMLImportContext *CreateChildContext(sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< xml::sax::XAttributeList > &xAttrList);
870 SvXMLImportContext *StrictCreateChildContext(sal_uInt16 nPrefix,
871 const OUString& rLocalName,
872 const uno::Reference< xml::sax::XAttributeList > &xAttrList);
874 void EndElement();
877 ////////////////////////////////////////////////////////////
879 class SmXMLFracContext_Impl : public SmXMLRowContext_Impl
881 public:
882 SmXMLFracContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
883 const OUString& rLName)
884 : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {}
886 void EndElement();
889 ////////////////////////////////////////////////////////////
891 class SmXMLSqrtContext_Impl : public SmXMLRowContext_Impl
893 public:
894 SmXMLSqrtContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
895 const OUString& rLName)
896 : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {}
898 void EndElement();
901 ////////////////////////////////////////////////////////////
903 class SmXMLRootContext_Impl : public SmXMLRowContext_Impl
905 public:
906 SmXMLRootContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
907 const OUString& rLName)
908 : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {}
910 void EndElement();
913 ////////////////////////////////////////////////////////////
915 class SmXMLStyleContext_Impl : public SmXMLRowContext_Impl
917 protected:
918 SmXMLContext_Helper aStyleHelper;
920 public:
921 /*Right now the style tag is completely ignored*/
922 SmXMLStyleContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
923 const OUString& rLName) : SmXMLRowContext_Impl(rImport,nPrefix,rLName),
924 aStyleHelper(*this) {}
926 void EndElement();
927 void StartElement(const uno::Reference< xml::sax::XAttributeList > &xAttrList );
930 void SmXMLStyleContext_Impl::StartElement(const uno::Reference<
931 xml::sax::XAttributeList > & xAttrList )
933 #if 1
934 aStyleHelper.RetrieveAttrs(xAttrList);
935 #else
936 sal_Int8 nOldIsBold=nIsBold;
937 sal_Int8 nOldIsItalic=nIsItalic;
938 double nOldFontSize=nFontSize;
939 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
940 OUString sOldFontFamily = sFontFamily;
941 for (sal_Int16 i=0;i<nAttrCount;i++)
943 OUString sAttrName = xAttrList->getNameByIndex(i);
944 OUString aLocalName;
945 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
946 GetKeyByAttrName(sAttrName,&aLocalName);
947 OUString sValue = xAttrList->getValueByIndex(i);
948 const SvXMLTokenMap &rAttrTokenMap =
949 GetSmImport().GetPresLayoutAttrTokenMap();
950 switch(rAttrTokenMap.Get(nPrefix,aLocalName))
952 case XML_TOK_FONTWEIGHT:
953 nIsBold = sValue.equals(GetXMLToken(XML_BOLD));
954 break;
955 case XML_TOK_FONTSTYLE:
956 nIsItalic = sValue.equals(GetXMLToken(XML_ITALIC));
957 break;
958 case XML_TOK_FONTSIZE:
959 SvXMLUnitConverter::convertDouble(nFontSize,sValue);
960 GetSmImport().GetMM100UnitConverter().
961 setXMLMeasureUnit(MAP_POINT);
962 if (-1 == sValue.indexOf(GetXMLToken(XML_UNIT_PT)))
963 if (-1 == sValue.indexOf('%'))
964 nFontSize=0.0;
965 else
967 GetSmImport().GetMM100UnitConverter().
968 setXMLMeasureUnit(MAP_RELATIVE);
970 break;
971 case XML_TOK_FONTFAMILY:
972 sFontFamily = sValue;
973 break;
974 case XML_TOK_COLOR:
975 sColor = sValue;
976 break;
977 default:
978 break;
982 if ((nOldIsBold!=nIsBold) || (nOldIsItalic!=nIsItalic) ||
983 (nOldFontSize!=nFontSize) || (sOldFontFamily!=sFontFamily)
984 || sColor.getLength())
985 bFontNodeNeeded=sal_True;
986 else
987 bFontNodeNeeded=sal_False;
988 #endif
992 void SmXMLStyleContext_Impl::EndElement()
995 <mstyle> accepts any number of arguments; if this number is not 1, its
996 contents are treated as a single "inferred <mrow>" containing its
997 arguments
999 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
1000 if (rNodeStack.Count() - nElementCount > 1)
1001 SmXMLRowContext_Impl::EndElement();
1002 #if 1
1003 aStyleHelper.ApplyAttrs();
1004 #else
1005 if (bFontNodeNeeded)
1007 SmToken aToken;
1008 aToken.cMathChar = '\0';
1009 aToken.nGroup = 0;
1010 aToken.nLevel = 5;
1012 if (nIsBold != -1)
1014 if (nIsBold)
1015 aToken.eType = TBOLD;
1016 else
1017 aToken.eType = TNBOLD;
1018 SmStructureNode *pFontNode = static_cast<SmStructureNode *>
1019 (new SmFontNode(aToken));
1020 pFontNode->SetSubNodes(0,rNodeStack.Pop());
1021 rNodeStack.Push(pFontNode);
1023 if (nIsItalic != -1)
1025 if (nIsItalic)
1026 aToken.eType = TITALIC;
1027 else
1028 aToken.eType = TNITALIC;
1029 SmStructureNode *pFontNode = static_cast<SmStructureNode *>
1030 (new SmFontNode(aToken));
1031 pFontNode->SetSubNodes(0,rNodeStack.Pop());
1032 rNodeStack.Push(pFontNode);
1034 if (nFontSize != 0.0)
1036 aToken.eType = TSIZE;
1037 SmFontNode *pFontNode = new SmFontNode(aToken);
1039 if (MAP_RELATIVE == GetSmImport().GetMM100UnitConverter().
1040 getXMLMeasureUnit())
1042 if (nFontSize < 100.00)
1043 pFontNode->SetSizeParameter(Fraction(100.00/nFontSize),
1044 FNTSIZ_DIVIDE);
1045 else
1046 pFontNode->SetSizeParameter(Fraction(nFontSize/100.00),
1047 FNTSIZ_MULTIPLY);
1049 else
1050 pFontNode->SetSizeParameter(Fraction(nFontSize),FNTSIZ_ABSOLUT);
1052 pFontNode->SetSubNodes(0,rNodeStack.Pop());
1053 rNodeStack.Push(pFontNode);
1055 if (sFontFamily.getLength())
1057 if (sFontFamily.equalsIgnoreCase(GetXMLToken(XML_FIXED)))
1058 aToken.eType = TFIXED;
1059 else if (sFontFamily.equalsIgnoreCase(OUString(
1060 RTL_CONSTASCII_USTRINGPARAM("sans"))))
1061 aToken.eType = TSANS;
1062 else if (sFontFamily.equalsIgnoreCase(OUString(
1063 RTL_CONSTASCII_USTRINGPARAM("serif"))))
1064 aToken.eType = TSERIF;
1065 else //Just give up, we need to extend our font mechanism to be
1066 //more general
1067 return;
1069 aToken.aText = sFontFamily;
1070 SmFontNode *pFontNode = new SmFontNode(aToken);
1071 pFontNode->SetSubNodes(0,rNodeStack.Pop());
1072 rNodeStack.Push(pFontNode);
1074 if (sColor.getLength())
1076 //Again we can only handle a small set of colours in
1077 //StarMath for now.
1078 const SvXMLTokenMap& rTokenMap =
1079 GetSmImport().GetColorTokenMap();
1080 aToken.eType = static_cast<SmTokenType>(rTokenMap.Get(
1081 XML_NAMESPACE_MATH, sColor));
1082 if (aToken.eType != -1)
1084 SmFontNode *pFontNode = new SmFontNode(aToken);
1085 pFontNode->SetSubNodes(0,rNodeStack.Pop());
1086 rNodeStack.Push(pFontNode);
1091 #endif
1094 ////////////////////////////////////////////////////////////
1096 class SmXMLPaddedContext_Impl : public SmXMLRowContext_Impl
1098 public:
1099 /*Right now the style tag is completely ignored*/
1100 SmXMLPaddedContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1101 const OUString& rLName)
1102 : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {}
1104 void EndElement();
1107 void SmXMLPaddedContext_Impl::EndElement()
1110 <mpadded> accepts any number of arguments; if this number is not 1, its
1111 contents are treated as a single "inferred <mrow>" containing its
1112 arguments
1114 if (GetSmImport().GetNodeStack().Count() - nElementCount > 1)
1115 SmXMLRowContext_Impl::EndElement();
1118 ////////////////////////////////////////////////////////////
1120 class SmXMLPhantomContext_Impl : public SmXMLRowContext_Impl
1122 public:
1123 /*Right now the style tag is completely ignored*/
1124 SmXMLPhantomContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1125 const OUString& rLName)
1126 : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {}
1128 void EndElement();
1131 void SmXMLPhantomContext_Impl::EndElement()
1134 <mphantom> accepts any number of arguments; if this number is not 1, its
1135 contents are treated as a single "inferred <mrow>" containing its
1136 arguments
1138 if (GetSmImport().GetNodeStack().Count() - nElementCount > 1)
1139 SmXMLRowContext_Impl::EndElement();
1141 SmToken aToken;
1142 aToken.cMathChar = '\0';
1143 aToken.nGroup = 0;
1144 aToken.nLevel = 5;
1145 aToken.eType = TPHANTOM;
1147 SmStructureNode *pPhantom = static_cast<SmStructureNode *>
1148 (new SmFontNode(aToken));
1149 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
1150 pPhantom->SetSubNodes(0,rNodeStack.Pop());
1151 rNodeStack.Push(pPhantom);
1154 ////////////////////////////////////////////////////////////
1156 class SmXMLFencedContext_Impl : public SmXMLRowContext_Impl
1158 protected:
1159 sal_Unicode cBegin;
1160 sal_Unicode cEnd;
1162 public:
1163 SmXMLFencedContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1164 const OUString& rLName)
1165 : SmXMLRowContext_Impl(rImport,nPrefix,rLName),
1166 cBegin('('), cEnd(')') {}
1168 void StartElement(const uno::Reference< xml::sax::XAttributeList > & xAttrList );
1169 void EndElement();
1173 void SmXMLFencedContext_Impl::StartElement(const uno::Reference<
1174 xml::sax::XAttributeList > & xAttrList )
1176 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1177 for (sal_Int16 i=0;i<nAttrCount;i++)
1179 OUString sAttrName = xAttrList->getNameByIndex(i);
1180 OUString aLocalName;
1181 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
1182 GetKeyByAttrName(sAttrName,&aLocalName);
1183 OUString sValue = xAttrList->getValueByIndex(i);
1184 const SvXMLTokenMap &rAttrTokenMap =
1185 GetSmImport().GetFencedAttrTokenMap();
1186 switch(rAttrTokenMap.Get(nPrefix,aLocalName))
1188 //temp, starmath cannot handle multichar brackets (I think)
1189 case XML_TOK_OPEN:
1190 cBegin = sValue[0];
1191 break;
1192 case XML_TOK_CLOSE:
1193 cEnd = sValue[0];
1194 break;
1195 default:
1196 /*Go to superclass*/
1197 break;
1203 void SmXMLFencedContext_Impl::EndElement()
1205 SmToken aToken;
1206 aToken.cMathChar = '\0';
1207 aToken.nGroup = 0;
1208 aToken.aText = ',';
1209 aToken.eType = TLEFT;
1210 aToken.nLevel = 5;
1212 aToken.eType = TLPARENT;
1213 aToken.cMathChar = cBegin;
1214 SmStructureNode *pSNode = new SmBraceNode(aToken);
1215 SmNode *pLeft = new SmMathSymbolNode(aToken);
1217 aToken.cMathChar = cEnd;
1218 aToken.eType = TRPARENT;
1219 SmNode *pRight = new SmMathSymbolNode(aToken);
1221 SmNodeArray aRelationArray;
1222 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
1224 aToken.cMathChar = '\0';
1225 aToken.aText = ',';
1226 aToken.eType = TIDENT;
1228 ULONG i = rNodeStack.Count() - nElementCount;
1229 if (rNodeStack.Count() - nElementCount > 1)
1230 i += rNodeStack.Count() - 1 - nElementCount;
1231 aRelationArray.resize(i);
1232 while (rNodeStack.Count() > nElementCount)
1234 aRelationArray[--i] = rNodeStack.Pop();
1235 if (i > 1 && rNodeStack.Count() > 1)
1236 aRelationArray[--i] = new SmGlyphSpecialNode(aToken);
1239 SmToken aDummy;
1240 SmStructureNode *pBody = new SmExpressionNode(aDummy);
1241 pBody->SetSubNodes(aRelationArray);
1244 pSNode->SetSubNodes(pLeft,pBody,pRight);
1245 pSNode->SetScaleMode(SCALE_HEIGHT);
1246 GetSmImport().GetNodeStack().Push(pSNode);
1250 ////////////////////////////////////////////////////////////
1252 class SmXMLErrorContext_Impl : public SmXMLRowContext_Impl
1254 public:
1255 SmXMLErrorContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1256 const OUString& rLName)
1257 : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {}
1259 void EndElement();
1262 void SmXMLErrorContext_Impl::EndElement()
1264 /*Right now the error tag is completely ignored, what
1265 can I do with it in starmath, ?, maybe we need a
1266 report window ourselves, do a test for validity of
1267 the xml input, use merrors, and then generate
1268 the markup inside the merror with a big red colour
1269 of something. For now just throw them all away.
1271 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
1272 while (rNodeStack.Count() > nElementCount)
1274 SmNode *pNode = rNodeStack.Pop();
1275 delete pNode;
1279 ////////////////////////////////////////////////////////////
1281 class SmXMLNumberContext_Impl : public SmXMLImportContext
1283 protected:
1284 SmToken aToken;
1286 public:
1287 SmXMLNumberContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1288 const OUString& rLName)
1289 : SmXMLImportContext(rImport,nPrefix,rLName)
1291 aToken.cMathChar = '\0';
1292 aToken.nGroup = 0;
1293 aToken.nLevel = 5;
1294 aToken.eType = TNUMBER;
1297 virtual void TCharacters(const OUString &rChars);
1299 void EndElement();
1302 void SmXMLNumberContext_Impl::TCharacters(const OUString &rChars)
1304 aToken.aText = rChars;
1307 void SmXMLNumberContext_Impl::EndElement()
1309 GetSmImport().GetNodeStack().Push(new SmTextNode(aToken,FNT_NUMBER));
1312 ////////////////////////////////////////////////////////////
1314 class SmXMLAnnotationContext_Impl : public SmXMLImportContext
1316 sal_Bool bIsStarMath;
1318 public:
1319 SmXMLAnnotationContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1320 const OUString& rLName)
1321 : SmXMLImportContext(rImport,nPrefix,rLName), bIsStarMath(sal_False) {}
1323 virtual void Characters(const OUString &rChars);
1325 void StartElement(const uno::Reference<xml::sax::XAttributeList > & xAttrList );
1328 void SmXMLAnnotationContext_Impl::StartElement(const uno::Reference<
1329 xml::sax::XAttributeList > & xAttrList )
1331 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1332 for (sal_Int16 i=0;i<nAttrCount;i++)
1334 OUString sAttrName = xAttrList->getNameByIndex(i);
1335 OUString aLocalName;
1336 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
1337 GetKeyByAttrName(sAttrName,&aLocalName);
1339 OUString sValue = xAttrList->getValueByIndex(i);
1340 const SvXMLTokenMap &rAttrTokenMap =
1341 GetSmImport().GetAnnotationAttrTokenMap();
1342 switch(rAttrTokenMap.Get(nPrefix,aLocalName))
1344 case XML_TOK_ENCODING:
1345 bIsStarMath= sValue.equals(
1346 OUString(RTL_CONSTASCII_USTRINGPARAM("StarMath 5.0")));
1347 break;
1348 default:
1349 break;
1354 void SmXMLAnnotationContext_Impl::Characters(const OUString &rChars)
1356 if (bIsStarMath)
1357 GetSmImport().GetText().Append(String(rChars));
1360 ////////////////////////////////////////////////////////////
1362 class SmXMLTextContext_Impl : public SmXMLImportContext
1364 protected:
1365 SmToken aToken;
1367 public:
1368 SmXMLTextContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1369 const OUString& rLName)
1370 : SmXMLImportContext(rImport,nPrefix,rLName)
1372 aToken.cMathChar = '\0';
1373 aToken.nGroup = 0;
1374 aToken.nLevel = 5;
1375 aToken.eType = TTEXT;
1378 virtual void TCharacters(const OUString &rChars);
1380 void EndElement();
1383 void SmXMLTextContext_Impl::TCharacters(const OUString &rChars)
1385 aToken.aText = rChars;
1388 void SmXMLTextContext_Impl::EndElement()
1390 GetSmImport().GetNodeStack().Push(new SmTextNode(aToken,FNT_TEXT));
1393 ////////////////////////////////////////////////////////////
1395 class SmXMLStringContext_Impl : public SmXMLImportContext
1397 protected:
1398 SmToken aToken;
1400 public:
1401 SmXMLStringContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1402 const OUString& rLName)
1403 : SmXMLImportContext(rImport,nPrefix,rLName)
1405 aToken.cMathChar = '\0';
1406 aToken.nGroup = 0;
1407 aToken.nLevel = 5;
1408 aToken.eType = TTEXT;
1411 virtual void TCharacters(const OUString &rChars);
1413 void EndElement();
1416 void SmXMLStringContext_Impl::TCharacters(const OUString &rChars)
1419 The content of <ms> elements should be rendered with visible "escaping" of
1420 certain characters in the content, including at least "double quote"
1421 itself, and preferably whitespace other than individual blanks. The intent
1422 is for the viewer to see that the expression is a string literal, and to
1423 see exactly which characters form its content. For example, <ms>double
1424 quote is "</ms> might be rendered as "double quote is \"".
1426 Obviously this isn't fully done here.
1428 aToken.aText.Erase();
1429 aToken.aText += '\"';
1430 aToken.aText += String(rChars);
1431 aToken.aText += '\"';
1434 void SmXMLStringContext_Impl::EndElement()
1436 GetSmImport().GetNodeStack().Push(new SmTextNode(aToken,FNT_FIXED));
1439 ////////////////////////////////////////////////////////////
1441 class SmXMLIdentifierContext_Impl : public SmXMLImportContext
1443 protected:
1444 SmXMLContext_Helper aStyleHelper;
1445 SmToken aToken;
1447 public:
1448 SmXMLIdentifierContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1449 const OUString& rLName)
1450 : SmXMLImportContext(rImport,nPrefix,rLName),aStyleHelper(*this)
1452 aToken.cMathChar = '\0';
1453 aToken.nGroup = 0;
1454 aToken.nLevel = 5;
1455 aToken.eType = TIDENT;
1458 void TCharacters(const OUString &rChars);
1459 void StartElement(const uno::Reference< xml::sax::XAttributeList > & xAttrList )
1461 aStyleHelper.RetrieveAttrs(xAttrList);
1463 void EndElement();
1466 void SmXMLIdentifierContext_Impl::EndElement()
1468 SmTextNode *pNode = 0;
1469 //we will handle identifier italic/normal here instead of with a standalone
1470 //font node
1471 if (((aStyleHelper.nIsItalic == -1) && (aToken.aText.Len() > 1))
1472 || ((aStyleHelper.nIsItalic == 0) && (aToken.aText.Len() == 1)))
1474 pNode = new SmTextNode(aToken,FNT_FUNCTION);
1475 pNode->GetFont().SetItalic(ITALIC_NONE);
1476 aStyleHelper.nIsItalic = -1;
1478 else
1479 pNode = new SmTextNode(aToken,FNT_VARIABLE);
1480 if (aStyleHelper.bFontNodeNeeded && aStyleHelper.nIsItalic != -1)
1482 if (aStyleHelper.nIsItalic)
1483 pNode->GetFont().SetItalic(ITALIC_NORMAL);
1484 else
1485 pNode->GetFont().SetItalic(ITALIC_NONE);
1488 if ((-1!=aStyleHelper.nIsBold) || (0.0!=aStyleHelper.nFontSize) ||
1489 (aStyleHelper.sFontFamily.getLength()) ||
1490 aStyleHelper.sColor.getLength())
1491 aStyleHelper.bFontNodeNeeded=sal_True;
1492 else
1493 aStyleHelper.bFontNodeNeeded=sal_False;
1494 if (aStyleHelper.bFontNodeNeeded)
1495 aStyleHelper.ApplyAttrs();
1496 GetSmImport().GetNodeStack().Push(pNode);
1499 void SmXMLIdentifierContext_Impl::TCharacters(const OUString &rChars)
1501 aToken.aText = rChars;
1504 ////////////////////////////////////////////////////////////
1506 class SmXMLOperatorContext_Impl : public SmXMLImportContext
1508 sal_Bool bIsStretchy;
1510 protected:
1511 SmToken aToken;
1513 public:
1514 SmXMLOperatorContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1515 const OUString& rLName)
1516 : SmXMLImportContext(rImport,nPrefix,rLName), bIsStretchy(sal_False)
1518 aToken.nGroup = 0;
1519 aToken.eType = TSPECIAL;
1520 aToken.nLevel = 5;
1523 void TCharacters(const OUString &rChars);
1524 void StartElement(const uno::Reference< xml::sax::XAttributeList > &xAttrList );
1525 void EndElement();
1528 void SmXMLOperatorContext_Impl::TCharacters(const OUString &rChars)
1530 aToken.cMathChar = rChars[0];
1533 void SmXMLOperatorContext_Impl::EndElement()
1535 SmMathSymbolNode *pNode = new SmMathSymbolNode(aToken);
1536 //For stretchy scaling the scaling must be retrieved from this node
1537 //and applied to the expression itself so as to get the expression
1538 //to scale the operator to the height of the expression itself
1539 if (bIsStretchy)
1540 pNode->SetScaleMode(SCALE_HEIGHT);
1541 GetSmImport().GetNodeStack().Push(pNode);
1546 void SmXMLOperatorContext_Impl::StartElement(const uno::Reference<
1547 xml::sax::XAttributeList > & xAttrList )
1549 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1550 for (sal_Int16 i=0;i<nAttrCount;i++)
1552 OUString sAttrName = xAttrList->getNameByIndex(i);
1553 OUString aLocalName;
1554 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
1555 GetKeyByAttrName(sAttrName,&aLocalName);
1557 OUString sValue = xAttrList->getValueByIndex(i);
1558 const SvXMLTokenMap &rAttrTokenMap =
1559 GetSmImport().GetOperatorAttrTokenMap();
1560 switch(rAttrTokenMap.Get(nPrefix,aLocalName))
1562 case XML_TOK_STRETCHY:
1563 bIsStretchy = sValue.equals(
1564 GetXMLToken(XML_TRUE));
1565 break;
1566 default:
1567 break;
1573 ////////////////////////////////////////////////////////////
1575 class SmXMLSpaceContext_Impl : public SmXMLImportContext
1577 public:
1578 SmXMLSpaceContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1579 const OUString& rLName)
1580 : SmXMLImportContext(rImport,nPrefix,rLName) {}
1582 void StartElement(const uno::Reference< xml::sax::XAttributeList >& xAttrList );
1585 void SmXMLSpaceContext_Impl::StartElement(
1586 const uno::Reference<xml::sax::XAttributeList > & /*xAttrList*/ )
1588 SmToken aToken;
1589 aToken.cMathChar = '\0';
1590 aToken.nGroup = 0;
1591 aToken.eType = TBLANK;
1592 aToken.nLevel = 5;
1593 SmBlankNode *pBlank = new SmBlankNode(aToken);
1594 pBlank->IncreaseBy(aToken);
1595 GetSmImport().GetNodeStack().Push(pBlank);
1598 ////////////////////////////////////////////////////////////
1600 class SmXMLSubContext_Impl : public SmXMLRowContext_Impl
1602 protected:
1603 void GenericEndElement(SmTokenType eType,SmSubSup aSubSup);
1605 public:
1606 SmXMLSubContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1607 const OUString& rLName)
1608 : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {}
1610 void EndElement()
1612 GenericEndElement(TRSUB,RSUB);
1617 void SmXMLSubContext_Impl::GenericEndElement(SmTokenType eType, SmSubSup eSubSup)
1619 /*The <msub> element requires exactly 2 arguments.*/
1620 DBG_ASSERT(GetSmImport().GetNodeStack().Count() - nElementCount == 2,
1621 "Sub has not two arguments");
1622 SmToken aToken;
1623 aToken.cMathChar = '\0';
1624 aToken.nGroup = 0;
1625 aToken.nLevel = 0;
1626 aToken.eType = eType;
1627 SmSubSupNode *pNode = new SmSubSupNode(aToken);
1628 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
1630 // initialize subnodes array
1631 SmNodeArray aSubNodes;
1632 aSubNodes.resize(1 + SUBSUP_NUM_ENTRIES);
1633 for (ULONG i = 1; i < aSubNodes.size(); i++)
1634 aSubNodes[i] = NULL;
1636 aSubNodes[eSubSup+1] = rNodeStack.Pop();
1637 aSubNodes[0] = rNodeStack.Pop();
1638 pNode->SetSubNodes(aSubNodes);
1639 rNodeStack.Push(pNode);
1642 ////////////////////////////////////////////////////////////
1644 class SmXMLSupContext_Impl : public SmXMLSubContext_Impl
1646 public:
1647 SmXMLSupContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1648 const OUString& rLName)
1649 : SmXMLSubContext_Impl(rImport,nPrefix,rLName) {}
1651 void EndElement()
1653 GenericEndElement(TRSUP,RSUP);
1657 ////////////////////////////////////////////////////////////
1659 class SmXMLSubSupContext_Impl : public SmXMLRowContext_Impl
1661 protected:
1662 void GenericEndElement(SmTokenType eType, SmSubSup aSub,SmSubSup aSup);
1664 public:
1665 SmXMLSubSupContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1666 const OUString& rLName)
1667 : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {}
1669 void EndElement()
1671 GenericEndElement(TRSUB,RSUB,RSUP);
1675 void SmXMLSubSupContext_Impl::GenericEndElement(SmTokenType eType,
1676 SmSubSup aSub,SmSubSup aSup)
1678 /*The <msub> element requires exactly 3 arguments.*/
1679 DBG_ASSERT(GetSmImport().GetNodeStack().Count() - nElementCount == 3,
1680 "SubSup has not three arguments");
1682 SmToken aToken;
1683 aToken.cMathChar = '\0';
1684 aToken.nGroup = 0;
1685 aToken.nLevel = 0;
1686 aToken.eType = eType;
1687 SmSubSupNode *pNode = new SmSubSupNode(aToken);
1688 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
1690 // initialize subnodes array
1691 SmNodeArray aSubNodes;
1692 aSubNodes.resize(1 + SUBSUP_NUM_ENTRIES);
1693 for (ULONG i = 1; i < aSubNodes.size(); i++)
1694 aSubNodes[i] = NULL;
1696 aSubNodes[aSup+1] = rNodeStack.Pop();
1697 aSubNodes[aSub+1] = rNodeStack.Pop();
1698 aSubNodes[0] = rNodeStack.Pop();
1699 pNode->SetSubNodes(aSubNodes);
1700 rNodeStack.Push(pNode);
1703 ////////////////////////////////////////////////////////////
1705 class SmXMLUnderContext_Impl : public SmXMLSubContext_Impl
1707 protected:
1708 sal_Int16 nAttrCount;
1710 public:
1711 SmXMLUnderContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1712 const OUString& rLName)
1713 : SmXMLSubContext_Impl(rImport,nPrefix,rLName) {}
1715 void StartElement(const uno::Reference< xml::sax::XAttributeList > &xAttrList );
1716 void EndElement();
1717 void HandleAccent();
1720 void SmXMLUnderContext_Impl::StartElement(const uno::Reference<
1721 xml::sax::XAttributeList > & xAttrList )
1723 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1726 void SmXMLUnderContext_Impl::HandleAccent()
1728 DBG_ASSERT(GetSmImport().GetNodeStack().Count() - nElementCount == 2,
1729 "Sub has not two arguments");
1731 /*Just one special case for the underline thing*/
1732 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
1733 SmNode *pTest = rNodeStack.Pop();
1734 SmToken aToken;
1735 aToken.cMathChar = '\0';
1736 aToken.nGroup = 0;
1737 aToken.nLevel = 0;
1738 aToken.eType = TUNDERLINE;
1741 SmNodeArray aSubNodes;
1742 aSubNodes.resize(2);
1744 SmStructureNode *pNode = new SmAttributNode(aToken);
1745 if ((pTest->GetToken().cMathChar & 0x0FFF) == 0x0332)
1747 aSubNodes[0] = new SmRectangleNode(aToken);
1748 delete pTest;
1750 else
1751 aSubNodes[0] = pTest;
1753 aSubNodes[1] = rNodeStack.Pop();
1754 pNode->SetSubNodes(aSubNodes);
1755 pNode->SetScaleMode(SCALE_WIDTH);
1756 rNodeStack.Push(pNode);
1760 void SmXMLUnderContext_Impl::EndElement()
1762 if (!nAttrCount)
1763 GenericEndElement(TCSUB,CSUB);
1764 else
1765 HandleAccent();
1766 #if 0
1767 //UnderBrace trick
1768 SmStructureNode *pNode = rNodeStack.Pop();
1769 if (pNode->GetSubNode(1)->GetToken().cMathChar == (0x0332|0xf000))
1770 if (pNode->GetSubNode(0)->GetToken().cMathChar == (0x0332|0xf000))
1771 #endif
1774 ////////////////////////////////////////////////////////////
1776 class SmXMLOverContext_Impl : public SmXMLSubContext_Impl
1778 protected:
1779 sal_Int16 nAttrCount;
1781 public:
1782 SmXMLOverContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1783 const OUString& rLName)
1784 : SmXMLSubContext_Impl(rImport,nPrefix,rLName), nAttrCount(0) {}
1786 void EndElement();
1787 void StartElement(const uno::Reference< xml::sax::XAttributeList > &xAttrList );
1788 void HandleAccent();
1792 void SmXMLOverContext_Impl::StartElement(const uno::Reference<
1793 xml::sax::XAttributeList > & xAttrList )
1795 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1799 void SmXMLOverContext_Impl::EndElement()
1801 if (!nAttrCount)
1802 GenericEndElement(TCSUP,CSUP);
1803 else
1804 HandleAccent();
1808 void SmXMLOverContext_Impl::HandleAccent()
1810 DBG_ASSERT(GetSmImport().GetNodeStack().Count() - nElementCount == 2,
1811 "Sub has not two arguments");
1812 SmToken aToken;
1813 aToken.cMathChar = '\0';
1814 aToken.nGroup = 0;
1815 aToken.nLevel = 0;
1816 aToken.eType = TACUTE;
1818 SmAttributNode *pNode = new SmAttributNode(aToken);
1819 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
1821 SmNodeArray aSubNodes;
1822 aSubNodes.resize(2);
1823 aSubNodes[0] = rNodeStack.Pop();
1824 aSubNodes[1] = rNodeStack.Pop();
1825 pNode->SetSubNodes(aSubNodes);
1826 pNode->SetScaleMode(SCALE_WIDTH);
1827 rNodeStack.Push(pNode);
1831 ////////////////////////////////////////////////////////////
1833 class SmXMLUnderOverContext_Impl : public SmXMLSubSupContext_Impl
1835 public:
1836 SmXMLUnderOverContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1837 const OUString& rLName)
1838 : SmXMLSubSupContext_Impl(rImport,nPrefix,rLName) {}
1840 void EndElement()
1842 GenericEndElement(TCSUB,CSUB,CSUP);
1846 ////////////////////////////////////////////////////////////
1848 class SmXMLMultiScriptsContext_Impl : public SmXMLSubSupContext_Impl
1850 sal_Bool bHasPrescripts;
1852 public:
1853 SmXMLMultiScriptsContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1854 const OUString& rLName) :
1855 SmXMLSubSupContext_Impl(rImport,nPrefix,rLName),
1856 bHasPrescripts(FALSE) {}
1858 void EndElement();
1859 void MiddleElement();
1860 SvXMLImportContext *CreateChildContext(sal_uInt16 nPrefix,
1861 const OUString& rLocalName,
1862 const uno::Reference< xml::sax::XAttributeList > &xAttrList);
1865 ////////////////////////////////////////////////////////////
1867 class SmXMLNoneContext_Impl : public SmXMLImportContext
1869 public:
1870 SmXMLNoneContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1871 const OUString& rLName)
1872 : SmXMLImportContext(rImport,nPrefix,rLName) {}
1874 void EndElement();
1878 void SmXMLNoneContext_Impl::EndElement(void)
1880 SmToken aToken;
1881 aToken.cMathChar = '\0';
1882 aToken.nGroup = 0;
1883 aToken.aText.Erase();
1884 aToken.nLevel = 5;
1885 aToken.eType = TIDENT;
1886 GetSmImport().GetNodeStack().Push(
1887 new SmTextNode(aToken,FNT_VARIABLE));
1890 ////////////////////////////////////////////////////////////
1892 class SmXMLPrescriptsContext_Impl : public SmXMLImportContext
1894 public:
1895 SmXMLPrescriptsContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1896 const OUString& rLName)
1897 : SmXMLImportContext(rImport,nPrefix,rLName) {}
1900 ////////////////////////////////////////////////////////////
1902 class SmXMLTableRowContext_Impl : public SmXMLRowContext_Impl
1904 public:
1905 SmXMLTableRowContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1906 const OUString& rLName) :
1907 SmXMLRowContext_Impl(rImport,nPrefix,rLName)
1910 SvXMLImportContext *CreateChildContext(sal_uInt16 nPrefix,
1911 const OUString& rLocalName,
1912 const uno::Reference< xml::sax::XAttributeList > &xAttrList);
1916 ////////////////////////////////////////////////////////////
1918 class SmXMLTableContext_Impl : public SmXMLTableRowContext_Impl
1920 public:
1921 SmXMLTableContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1922 const OUString& rLName) :
1923 SmXMLTableRowContext_Impl(rImport,nPrefix,rLName)
1926 void EndElement();
1927 SvXMLImportContext *CreateChildContext(sal_uInt16 nPrefix,
1928 const OUString& rLocalName,
1929 const uno::Reference< xml::sax::XAttributeList > &xAttrList);
1933 ////////////////////////////////////////////////////////////
1935 class SmXMLTableCellContext_Impl : public SmXMLRowContext_Impl
1937 public:
1938 SmXMLTableCellContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1939 const OUString& rLName) :
1940 SmXMLRowContext_Impl(rImport,nPrefix,rLName)
1944 ////////////////////////////////////////////////////////////
1946 class SmXMLAlignGroupContext_Impl : public SmXMLRowContext_Impl
1948 public:
1949 SmXMLAlignGroupContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1950 const OUString& rLName) :
1951 SmXMLRowContext_Impl(rImport,nPrefix,rLName)
1954 /*Don't do anything with alignment for now*/
1955 void EndElement()
1960 ////////////////////////////////////////////////////////////
1962 class SmXMLActionContext_Impl : public SmXMLRowContext_Impl
1964 public:
1965 SmXMLActionContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1966 const OUString& rLName) :
1967 SmXMLRowContext_Impl(rImport,nPrefix,rLName)
1970 void EndElement();
1973 ////////////////////////////////////////////////////////////
1975 // NB: virtually inherit so we can multiply inherit properly
1976 // in SmXMLFlatDocContext_Impl
1977 class SmXMLOfficeContext_Impl : public virtual SvXMLImportContext
1979 public:
1980 SmXMLOfficeContext_Impl( SmXMLImport &rImport, sal_uInt16 nPrfx,
1981 const OUString& rLName)
1982 : SvXMLImportContext(rImport,nPrfx,rLName) {}
1984 virtual SvXMLImportContext *CreateChildContext(sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< xml::sax::XAttributeList > &xAttrList);
1987 SvXMLImportContext *SmXMLOfficeContext_Impl::CreateChildContext(sal_uInt16 nPrefix,
1988 const OUString& rLocalName,
1989 const uno::Reference< xml::sax::XAttributeList > &xAttrList)
1991 SvXMLImportContext *pContext = 0;
1992 if ( XML_NAMESPACE_OFFICE == nPrefix &&
1993 rLocalName == GetXMLToken(XML_META) )
1995 DBG_WARNING("XML_TOK_DOC_META: should not have come here, maybe document is invalid?");
1997 else if ( XML_NAMESPACE_OFFICE == nPrefix &&
1998 rLocalName == GetXMLToken(XML_SETTINGS) )
2000 pContext = new XMLDocumentSettingsContext( GetImport(),
2001 XML_NAMESPACE_OFFICE, rLocalName,
2002 xAttrList );
2004 else
2005 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
2007 return pContext;
2010 ////////////////////////////////////////////////////////////
2012 // context for flat file xml format
2013 class SmXMLFlatDocContext_Impl
2014 : public SmXMLOfficeContext_Impl, public SvXMLMetaDocumentContext
2016 public:
2017 SmXMLFlatDocContext_Impl( SmXMLImport& i_rImport,
2018 USHORT i_nPrefix, const OUString & i_rLName,
2019 const uno::Reference<document::XDocumentProperties>& i_xDocProps,
2020 const uno::Reference<xml::sax::XDocumentHandler>& i_xDocBuilder);
2022 virtual ~SmXMLFlatDocContext_Impl();
2024 virtual SvXMLImportContext *CreateChildContext(USHORT i_nPrefix, const OUString& i_rLocalName, const uno::Reference<xml::sax::XAttributeList>& i_xAttrList);
2027 SmXMLFlatDocContext_Impl::SmXMLFlatDocContext_Impl( SmXMLImport& i_rImport,
2028 USHORT i_nPrefix, const OUString & i_rLName,
2029 const uno::Reference<document::XDocumentProperties>& i_xDocProps,
2030 const uno::Reference<xml::sax::XDocumentHandler>& i_xDocBuilder) :
2031 SvXMLImportContext(i_rImport, i_nPrefix, i_rLName),
2032 SmXMLOfficeContext_Impl(i_rImport, i_nPrefix, i_rLName),
2033 SvXMLMetaDocumentContext(i_rImport, i_nPrefix, i_rLName,
2034 i_xDocProps, i_xDocBuilder)
2038 SmXMLFlatDocContext_Impl::~SmXMLFlatDocContext_Impl()
2042 SvXMLImportContext *SmXMLFlatDocContext_Impl::CreateChildContext(
2043 USHORT i_nPrefix, const OUString& i_rLocalName,
2044 const uno::Reference<xml::sax::XAttributeList>& i_xAttrList)
2046 // behave like meta base class iff we encounter office:meta
2047 if ( XML_NAMESPACE_OFFICE == i_nPrefix &&
2048 i_rLocalName == GetXMLToken(XML_META) )
2050 return SvXMLMetaDocumentContext::CreateChildContext(
2051 i_nPrefix, i_rLocalName, i_xAttrList );
2053 else
2055 return SmXMLOfficeContext_Impl::CreateChildContext(
2056 i_nPrefix, i_rLocalName, i_xAttrList );
2060 ////////////////////////////////////////////////////////////
2062 static __FAR_DATA SvXMLTokenMapEntry aPresLayoutElemTokenMap[] =
2064 { XML_NAMESPACE_MATH, XML_SEMANTICS, XML_TOK_SEMANTICS },
2065 { XML_NAMESPACE_MATH, XML_MATH, XML_TOK_MATH },
2066 { XML_NAMESPACE_MATH, XML_MSTYLE, XML_TOK_MSTYLE },
2067 { XML_NAMESPACE_MATH, XML_MERROR, XML_TOK_MERROR },
2068 { XML_NAMESPACE_MATH, XML_MPHANTOM, XML_TOK_MPHANTOM },
2069 { XML_NAMESPACE_MATH, XML_MROW, XML_TOK_MROW },
2070 { XML_NAMESPACE_MATH, XML_MFRAC, XML_TOK_MFRAC },
2071 { XML_NAMESPACE_MATH, XML_MSQRT, XML_TOK_MSQRT },
2072 { XML_NAMESPACE_MATH, XML_MROOT, XML_TOK_MROOT },
2073 { XML_NAMESPACE_MATH, XML_MSUB, XML_TOK_MSUB },
2074 { XML_NAMESPACE_MATH, XML_MSUP, XML_TOK_MSUP },
2075 { XML_NAMESPACE_MATH, XML_MSUBSUP, XML_TOK_MSUBSUP },
2076 { XML_NAMESPACE_MATH, XML_MUNDER, XML_TOK_MUNDER },
2077 { XML_NAMESPACE_MATH, XML_MOVER, XML_TOK_MOVER },
2078 { XML_NAMESPACE_MATH, XML_MUNDEROVER, XML_TOK_MUNDEROVER },
2079 { XML_NAMESPACE_MATH, XML_MMULTISCRIPTS, XML_TOK_MMULTISCRIPTS },
2080 { XML_NAMESPACE_MATH, XML_MTABLE, XML_TOK_MTABLE },
2081 { XML_NAMESPACE_MATH, XML_MACTION, XML_TOK_MACTION },
2082 { XML_NAMESPACE_MATH, XML_MFENCED, XML_TOK_MFENCED },
2083 { XML_NAMESPACE_MATH, XML_MPADDED, XML_TOK_MPADDED },
2084 XML_TOKEN_MAP_END
2087 static __FAR_DATA SvXMLTokenMapEntry aPresLayoutAttrTokenMap[] =
2089 { XML_NAMESPACE_MATH, XML_FONTWEIGHT, XML_TOK_FONTWEIGHT },
2090 { XML_NAMESPACE_MATH, XML_FONTSTYLE, XML_TOK_FONTSTYLE },
2091 { XML_NAMESPACE_MATH, XML_FONTSIZE, XML_TOK_FONTSIZE },
2092 { XML_NAMESPACE_MATH, XML_FONTFAMILY, XML_TOK_FONTFAMILY },
2093 { XML_NAMESPACE_MATH, XML_COLOR, XML_TOK_COLOR },
2094 XML_TOKEN_MAP_END
2097 static __FAR_DATA SvXMLTokenMapEntry aFencedAttrTokenMap[] =
2099 { XML_NAMESPACE_MATH, XML_OPEN, XML_TOK_OPEN },
2100 { XML_NAMESPACE_MATH, XML_CLOSE, XML_TOK_CLOSE },
2101 XML_TOKEN_MAP_END
2104 static __FAR_DATA SvXMLTokenMapEntry aOperatorAttrTokenMap[] =
2106 { XML_NAMESPACE_MATH, XML_STRETCHY, XML_TOK_STRETCHY },
2107 XML_TOKEN_MAP_END
2110 static __FAR_DATA SvXMLTokenMapEntry aAnnotationAttrTokenMap[] =
2112 { XML_NAMESPACE_MATH, XML_ENCODING, XML_TOK_ENCODING },
2113 XML_TOKEN_MAP_END
2117 static __FAR_DATA SvXMLTokenMapEntry aPresElemTokenMap[] =
2119 { XML_NAMESPACE_MATH, XML_ANNOTATION, XML_TOK_ANNOTATION },
2120 { XML_NAMESPACE_MATH, XML_MI, XML_TOK_MI },
2121 { XML_NAMESPACE_MATH, XML_MN, XML_TOK_MN },
2122 { XML_NAMESPACE_MATH, XML_MO, XML_TOK_MO },
2123 { XML_NAMESPACE_MATH, XML_MTEXT, XML_TOK_MTEXT },
2124 { XML_NAMESPACE_MATH, XML_MSPACE,XML_TOK_MSPACE },
2125 { XML_NAMESPACE_MATH, XML_MS, XML_TOK_MS },
2126 { XML_NAMESPACE_MATH, XML_MALIGNGROUP, XML_TOK_MALIGNGROUP },
2127 XML_TOKEN_MAP_END
2130 static __FAR_DATA SvXMLTokenMapEntry aPresScriptEmptyElemTokenMap[] =
2132 { XML_NAMESPACE_MATH, XML_MPRESCRIPTS, XML_TOK_MPRESCRIPTS },
2133 { XML_NAMESPACE_MATH, XML_NONE, XML_TOK_NONE },
2134 XML_TOKEN_MAP_END
2137 static __FAR_DATA SvXMLTokenMapEntry aPresTableElemTokenMap[] =
2139 { XML_NAMESPACE_MATH, XML_MTR, XML_TOK_MTR },
2140 { XML_NAMESPACE_MATH, XML_MTD, XML_TOK_MTD },
2141 XML_TOKEN_MAP_END
2144 static __FAR_DATA SvXMLTokenMapEntry aColorTokenMap[] =
2146 { XML_NAMESPACE_MATH, XML_BLACK, TBLACK},
2147 { XML_NAMESPACE_MATH, XML_WHITE, TWHITE},
2148 { XML_NAMESPACE_MATH, XML_RED, TRED},
2149 { XML_NAMESPACE_MATH, XML_GREEN, TGREEN},
2150 { XML_NAMESPACE_MATH, XML_BLUE, TBLUE},
2151 { XML_NAMESPACE_MATH, XML_AQUA, TCYAN},
2152 { XML_NAMESPACE_MATH, XML_FUCHSIA, TMAGENTA},
2153 { XML_NAMESPACE_MATH, XML_YELLOW, TYELLOW},
2154 XML_TOKEN_MAP_END
2158 ////////////////////////////////////////////////////////////
2160 const SvXMLTokenMap& SmXMLImport::GetPresLayoutElemTokenMap()
2162 if (!pPresLayoutElemTokenMap)
2163 pPresLayoutElemTokenMap = new SvXMLTokenMap(aPresLayoutElemTokenMap);
2164 return *pPresLayoutElemTokenMap;
2167 const SvXMLTokenMap& SmXMLImport::GetPresLayoutAttrTokenMap()
2169 if (!pPresLayoutAttrTokenMap)
2170 pPresLayoutAttrTokenMap = new SvXMLTokenMap(aPresLayoutAttrTokenMap);
2171 return *pPresLayoutAttrTokenMap;
2175 const SvXMLTokenMap& SmXMLImport::GetFencedAttrTokenMap()
2177 if (!pFencedAttrTokenMap)
2178 pFencedAttrTokenMap = new SvXMLTokenMap(aFencedAttrTokenMap);
2179 return *pFencedAttrTokenMap;
2182 const SvXMLTokenMap& SmXMLImport::GetOperatorAttrTokenMap()
2184 if (!pOperatorAttrTokenMap)
2185 pOperatorAttrTokenMap = new SvXMLTokenMap(aOperatorAttrTokenMap);
2186 return *pOperatorAttrTokenMap;
2189 const SvXMLTokenMap& SmXMLImport::GetAnnotationAttrTokenMap()
2191 if (!pAnnotationAttrTokenMap)
2192 pAnnotationAttrTokenMap = new SvXMLTokenMap(aAnnotationAttrTokenMap);
2193 return *pAnnotationAttrTokenMap;
2196 const SvXMLTokenMap& SmXMLImport::GetPresElemTokenMap()
2198 if (!pPresElemTokenMap)
2199 pPresElemTokenMap = new SvXMLTokenMap(aPresElemTokenMap);
2200 return *pPresElemTokenMap;
2203 const SvXMLTokenMap& SmXMLImport::GetPresScriptEmptyElemTokenMap()
2205 if (!pPresScriptEmptyElemTokenMap)
2206 pPresScriptEmptyElemTokenMap = new
2207 SvXMLTokenMap(aPresScriptEmptyElemTokenMap);
2208 return *pPresScriptEmptyElemTokenMap;
2211 const SvXMLTokenMap& SmXMLImport::GetPresTableElemTokenMap()
2213 if (!pPresTableElemTokenMap)
2214 pPresTableElemTokenMap = new SvXMLTokenMap(aPresTableElemTokenMap);
2215 return *pPresTableElemTokenMap;
2218 const SvXMLTokenMap& SmXMLImport::GetColorTokenMap()
2220 if (!pColorTokenMap)
2221 pColorTokenMap = new SvXMLTokenMap(aColorTokenMap);
2222 return *pColorTokenMap;
2225 ////////////////////////////////////////////////////////////
2227 SvXMLImportContext *SmXMLDocContext_Impl::CreateChildContext(
2228 sal_uInt16 nPrefix,
2229 const OUString& rLocalName,
2230 const uno::Reference<xml::sax::XAttributeList>& xAttrList)
2232 SvXMLImportContext* pContext = 0L;
2234 const SvXMLTokenMap& rTokenMap = GetSmImport().GetPresLayoutElemTokenMap();
2236 //UINT32 nTest = rTokenMap.Get(nPrefix, rLocalName);
2238 switch(rTokenMap.Get(nPrefix, rLocalName))
2240 //Consider semantics a dummy except for any starmath annotations
2241 case XML_TOK_SEMANTICS:
2242 pContext = GetSmImport().CreateRowContext(nPrefix,rLocalName,
2243 xAttrList);
2244 break;
2245 /*General Layout Schemata*/
2246 case XML_TOK_MROW:
2247 pContext = GetSmImport().CreateRowContext(nPrefix,rLocalName,
2248 xAttrList);
2249 break;
2250 case XML_TOK_MFRAC:
2251 pContext = GetSmImport().CreateFracContext(nPrefix,rLocalName,
2252 xAttrList);
2253 break;
2254 case XML_TOK_MSQRT:
2255 pContext = GetSmImport().CreateSqrtContext(nPrefix,rLocalName,
2256 xAttrList);
2257 break;
2258 case XML_TOK_MROOT:
2259 pContext = GetSmImport().CreateRootContext(nPrefix,rLocalName,
2260 xAttrList);
2261 break;
2262 case XML_TOK_MSTYLE:
2263 pContext = GetSmImport().CreateStyleContext(nPrefix,rLocalName,
2264 xAttrList);
2265 break;
2266 case XML_TOK_MERROR:
2267 pContext = GetSmImport().CreateErrorContext(nPrefix,rLocalName,
2268 xAttrList);
2269 break;
2270 case XML_TOK_MPADDED:
2271 pContext = GetSmImport().CreatePaddedContext(nPrefix,rLocalName,
2272 xAttrList);
2273 break;
2274 case XML_TOK_MPHANTOM:
2275 pContext = GetSmImport().CreatePhantomContext(nPrefix,rLocalName,
2276 xAttrList);
2277 break;
2278 case XML_TOK_MFENCED:
2279 pContext = GetSmImport().CreateFencedContext(nPrefix,rLocalName,
2280 xAttrList);
2281 break;
2282 /*Script and Limit Schemata*/
2283 case XML_TOK_MSUB:
2284 pContext = GetSmImport().CreateSubContext(nPrefix,rLocalName,
2285 xAttrList);
2286 break;
2287 case XML_TOK_MSUP:
2288 pContext = GetSmImport().CreateSupContext(nPrefix,rLocalName,
2289 xAttrList);
2290 break;
2291 case XML_TOK_MSUBSUP:
2292 pContext = GetSmImport().CreateSubSupContext(nPrefix,rLocalName,
2293 xAttrList);
2294 break;
2295 case XML_TOK_MUNDER:
2296 pContext = GetSmImport().CreateUnderContext(nPrefix,rLocalName,
2297 xAttrList);
2298 break;
2299 case XML_TOK_MOVER:
2300 pContext = GetSmImport().CreateOverContext(nPrefix,rLocalName,
2301 xAttrList);
2302 break;
2303 case XML_TOK_MUNDEROVER:
2304 pContext = GetSmImport().CreateUnderOverContext(nPrefix,rLocalName,
2305 xAttrList);
2306 break;
2307 case XML_TOK_MMULTISCRIPTS:
2308 pContext = GetSmImport().CreateMultiScriptsContext(nPrefix,
2309 rLocalName, xAttrList);
2310 break;
2311 case XML_TOK_MTABLE:
2312 pContext = GetSmImport().CreateTableContext(nPrefix,
2313 rLocalName, xAttrList);
2314 break;
2315 case XML_TOK_MACTION:
2316 pContext = GetSmImport().CreateActionContext(nPrefix,
2317 rLocalName, xAttrList);
2318 break;
2319 default:
2320 /*Basically theres an implicit mrow around certain bare
2321 *elements, use a RowContext to see if this is one of
2322 *those ones*/
2323 SmXMLRowContext_Impl aTempContext(GetSmImport(),nPrefix,
2324 GetXMLToken(XML_MROW));
2326 pContext = aTempContext.StrictCreateChildContext(nPrefix,
2327 rLocalName, xAttrList);
2328 break;
2330 return pContext;
2333 void SmXMLDocContext_Impl::EndElement()
2335 SmNodeArray ContextArray;
2336 ContextArray.resize(1);
2337 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
2339 for (ULONG i=0;i< 1;i++)
2340 ContextArray[i] = rNodeStack.Pop();
2342 SmToken aDummy;
2343 SmStructureNode *pSNode = new SmLineNode(aDummy);
2344 pSNode->SetSubNodes(ContextArray);
2345 rNodeStack.Push(pSNode);
2347 SmNodeArray LineArray;
2348 ULONG n = rNodeStack.Count();
2349 LineArray.resize(n);
2350 for (ULONG j = 0; j < n; j++)
2351 LineArray[n - (j + 1)] = rNodeStack.Pop();
2352 SmStructureNode *pSNode2 = new SmTableNode(aDummy);
2353 pSNode2->SetSubNodes(LineArray);
2354 rNodeStack.Push(pSNode2);
2357 void SmXMLFracContext_Impl::EndElement()
2359 SmToken aToken;
2360 aToken.cMathChar = '\0';
2361 aToken.nGroup = 0;
2362 aToken.nLevel = 0;
2363 aToken.eType = TOVER;
2364 SmStructureNode *pSNode = new SmBinVerNode(aToken);
2365 SmNode *pOper = new SmRectangleNode(aToken);
2366 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
2367 DBG_ASSERT(rNodeStack.Count() - nElementCount == 2,
2368 "Fraction (mfrac) tag is missing component");
2369 if (rNodeStack.Count() - nElementCount == 2)
2371 SmNode *pSecond = rNodeStack.Pop();
2372 SmNode *pFirst = rNodeStack.Pop();
2373 pSNode->SetSubNodes(pFirst,pOper,pSecond);
2374 rNodeStack.Push(pSNode);
2378 void SmXMLRootContext_Impl::EndElement()
2380 /*The <mroot> element requires exactly 2 arguments.*/
2381 DBG_ASSERT(GetSmImport().GetNodeStack().Count() - nElementCount == 2,
2382 "Root tag is missing component");
2384 SmToken aToken;
2385 aToken.cMathChar = MS_SQRT; //Temporary: alert, based on StarSymbol font
2386 aToken.nGroup = 0;
2387 aToken.nLevel = 0;
2388 aToken.eType = TNROOT;
2389 SmStructureNode *pSNode = new SmRootNode(aToken);
2390 SmNode *pOper = new SmRootSymbolNode(aToken);
2391 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
2392 SmNode *pIndex = rNodeStack.Pop();
2393 SmNode *pBase = rNodeStack.Pop();
2394 pSNode->SetSubNodes(pIndex,pOper,pBase);
2395 rNodeStack.Push(pSNode);
2398 void SmXMLSqrtContext_Impl::EndElement()
2401 <msqrt> accepts any number of arguments; if this number is not 1, its
2402 contents are treated as a single "inferred <mrow>" containing its
2403 arguments
2405 if (GetSmImport().GetNodeStack().Count() - nElementCount > 1)
2406 SmXMLRowContext_Impl::EndElement();
2408 SmToken aToken;
2409 aToken.cMathChar = MS_SQRT; //Temporary: alert, based on StarSymbol font
2410 aToken.nGroup = 0;
2411 aToken.nLevel = 0;
2412 aToken.eType = TSQRT;
2413 SmStructureNode *pSNode = new SmRootNode(aToken);
2414 SmNode *pOper = new SmRootSymbolNode(aToken);
2415 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
2416 pSNode->SetSubNodes(0,pOper,rNodeStack.Pop());
2417 rNodeStack.Push(pSNode);
2420 void SmXMLRowContext_Impl::EndElement()
2422 SmNodeArray aRelationArray;
2423 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
2424 ULONG nSize = rNodeStack.Count()-nElementCount;
2426 if (nSize > 0)
2428 aRelationArray.resize(nSize);
2429 for (ULONG j=rNodeStack.Count()-nElementCount;j > 0;j--)
2430 aRelationArray[j-1] = rNodeStack.Pop();
2433 //If the first or last element is an operator with stretchyness
2434 //set then we must create a brace node here from those elements,
2435 //removing the stretchness from the operators and applying it to
2436 //ourselves, and creating the appropiate dummy StarMath none bracket
2437 //to balance the arrangement
2438 if (((aRelationArray[0]->GetScaleMode() == SCALE_HEIGHT)
2439 && (aRelationArray[0]->GetType() == NMATH))
2440 || ((aRelationArray[nSize-1]->GetScaleMode() == SCALE_HEIGHT)
2441 && (aRelationArray[nSize-1]->GetType() == NMATH)))
2443 SmToken aToken;
2444 aToken.cMathChar = '\0';
2445 aToken.nGroup = 0;
2446 aToken.nLevel = 5;
2448 int nLeft=0,nRight=0;
2449 if ((aRelationArray[0]->GetScaleMode() == SCALE_HEIGHT)
2450 && (aRelationArray[0]->GetType() == NMATH))
2452 aToken = aRelationArray[0]->GetToken();
2453 nLeft=1;
2455 else
2456 aToken.cMathChar = '\0';
2458 aToken.eType = TLPARENT;
2459 SmNode *pLeft = new SmMathSymbolNode(aToken);
2461 if ((aRelationArray[nSize-1]->GetScaleMode() == SCALE_HEIGHT)
2462 && (aRelationArray[nSize-1]->GetType() == NMATH))
2464 aToken = aRelationArray[nSize-1]->GetToken();
2465 nRight=1;
2467 else
2468 aToken.cMathChar = '\0';
2470 aToken.eType = TRPARENT;
2471 SmNode *pRight = new SmMathSymbolNode(aToken);
2473 SmNodeArray aRelationArray2;
2475 //!! nSize-nLeft-nRight may be < 0 !!
2476 int nRelArrSize = nSize-nLeft-nRight;
2477 if (nRelArrSize > 0)
2479 aRelationArray2.resize(nRelArrSize);
2480 for (int i=0;i < nRelArrSize;i++)
2481 aRelationArray2[i] = aRelationArray[i+nLeft];
2484 SmToken aDummy;
2485 SmStructureNode *pSNode = new SmBraceNode(aToken);
2486 SmStructureNode *pBody = new SmExpressionNode(aDummy);
2487 pBody->SetSubNodes(aRelationArray2);
2489 pSNode->SetSubNodes(pLeft,pBody,pRight);
2490 pSNode->SetScaleMode(SCALE_HEIGHT);
2491 rNodeStack.Push(pSNode);
2492 return;
2495 else //Multiple newlines result in empty row elements
2497 aRelationArray.resize(1);
2498 SmToken aToken;
2499 aToken.cMathChar = '\0';
2500 aToken.nGroup = 0;
2501 aToken.nLevel = 5;
2502 aToken.eType = TNEWLINE;
2503 aRelationArray[0] = new SmLineNode(aToken);
2506 SmToken aDummy;
2507 SmStructureNode *pSNode = new SmExpressionNode(aDummy);
2508 pSNode->SetSubNodes(aRelationArray);
2509 rNodeStack.Push(pSNode);
2513 SvXMLImportContext *SmXMLRowContext_Impl::StrictCreateChildContext(
2514 sal_uInt16 nPrefix,
2515 const OUString& rLocalName,
2516 const uno::Reference<xml::sax::XAttributeList>& xAttrList)
2518 SvXMLImportContext* pContext = 0L;
2520 const SvXMLTokenMap& rTokenMap = GetSmImport().GetPresElemTokenMap();
2521 switch(rTokenMap.Get(nPrefix, rLocalName))
2523 /*Note that these should accept malignmark subelements, but do not*/
2524 case XML_TOK_MN:
2525 pContext = GetSmImport().CreateNumberContext(nPrefix,rLocalName,
2526 xAttrList);
2527 break;
2528 case XML_TOK_MI:
2529 pContext = GetSmImport().CreateIdentifierContext(nPrefix,rLocalName,
2530 xAttrList);
2531 break;
2532 case XML_TOK_MO:
2533 pContext = GetSmImport().CreateOperatorContext(nPrefix,rLocalName,
2534 xAttrList);
2535 break;
2536 case XML_TOK_MTEXT:
2537 pContext = GetSmImport().CreateTextContext(nPrefix,rLocalName,
2538 xAttrList);
2539 break;
2540 case XML_TOK_MSPACE:
2541 pContext = GetSmImport().CreateSpaceContext(nPrefix,rLocalName,
2542 xAttrList);
2543 break;
2544 case XML_TOK_MS:
2545 pContext = GetSmImport().CreateStringContext(nPrefix,rLocalName,
2546 xAttrList);
2547 break;
2549 /*Note: The maligngroup should only be seen when the row
2550 * (or decendants) are in a table*/
2551 case XML_TOK_MALIGNGROUP:
2552 pContext = GetSmImport().CreateAlignGroupContext(nPrefix,rLocalName,
2553 xAttrList);
2554 break;
2556 case XML_TOK_ANNOTATION:
2557 pContext = GetSmImport().CreateAnnotationContext(nPrefix,rLocalName,
2558 xAttrList);
2559 break;
2561 default:
2562 break;
2564 return pContext;
2568 SvXMLImportContext *SmXMLRowContext_Impl::CreateChildContext(
2569 sal_uInt16 nPrefix,
2570 const OUString& rLocalName,
2571 const uno::Reference<xml::sax::XAttributeList>& xAttrList)
2573 SvXMLImportContext* pContext = StrictCreateChildContext(nPrefix,
2574 rLocalName, xAttrList);
2576 if (!pContext)
2578 //Hmm, unrecognized for this level, check to see if its
2579 //an element that can have an implicit schema around it
2580 pContext = SmXMLDocContext_Impl::CreateChildContext(nPrefix,
2581 rLocalName,xAttrList);
2583 return pContext;
2587 SvXMLImportContext *SmXMLMultiScriptsContext_Impl::CreateChildContext(
2588 sal_uInt16 nPrefix,
2589 const OUString& rLocalName,
2590 const uno::Reference<xml::sax::XAttributeList>& xAttrList)
2592 SvXMLImportContext* pContext = 0L;
2594 const SvXMLTokenMap& rTokenMap = GetSmImport().
2595 GetPresScriptEmptyElemTokenMap();
2596 switch(rTokenMap.Get(nPrefix, rLocalName))
2598 case XML_TOK_MPRESCRIPTS:
2599 MiddleElement();
2600 pContext = GetSmImport().CreatePrescriptsContext(nPrefix,
2601 rLocalName, xAttrList);
2602 break;
2603 case XML_TOK_NONE:
2604 pContext = GetSmImport().CreateNoneContext(nPrefix,rLocalName,
2605 xAttrList);
2606 break;
2607 default:
2608 pContext = SmXMLRowContext_Impl::CreateChildContext(nPrefix,
2609 rLocalName,xAttrList);
2610 break;
2612 return pContext;
2615 void SmXMLMultiScriptsContext_Impl::MiddleElement()
2617 bHasPrescripts=sal_True;
2619 DBG_ASSERT(GetSmImport().GetNodeStack().Count() - nElementCount > 0,
2620 "Sub has no arguments");
2621 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
2622 if (rNodeStack.Count()-nElementCount > 1)
2624 SmToken aToken;
2625 aToken.cMathChar = '\0';
2626 aToken.nGroup = 0;
2627 aToken.nLevel = 0;
2628 aToken.eType = TRSUB;
2629 ULONG nFinalCount = rNodeStack.Count()-nElementCount-1;
2631 SmNodeStack aReverseStack;
2632 while (rNodeStack.Count()-nElementCount)
2634 SmNode *pThing = rNodeStack.Pop();
2635 aReverseStack.Push(pThing);
2638 for (ULONG nCount=0;nCount < nFinalCount;nCount+=2)
2640 SmSubSupNode *pNode = new SmSubSupNode(aToken);
2642 // initialize subnodes array
2643 SmNodeArray aSubNodes;
2644 aSubNodes.resize(1 + SUBSUP_NUM_ENTRIES);
2645 for (ULONG i = 1; i < aSubNodes.size(); i++)
2646 aSubNodes[i] = NULL;
2648 /*On each loop the base and its sub sup pair becomes the
2649 base for the next loop to which the next sub sup pair is
2650 attached, i.e. wheels within wheels*/
2651 //if (nCount == 0)
2652 aSubNodes[0] = aReverseStack.Pop();
2654 SmNode *pScriptNode = aReverseStack.Pop();
2656 if (pScriptNode && ((pScriptNode->GetToken().eType != TIDENT) ||
2657 (pScriptNode->GetToken().aText.Len())))
2658 aSubNodes[RSUB+1] = pScriptNode;
2659 pScriptNode = aReverseStack.Pop();
2660 if (pScriptNode && ((pScriptNode->GetToken().eType != TIDENT) ||
2661 (pScriptNode->GetToken().aText.Len())))
2662 aSubNodes[RSUP+1] = pScriptNode;
2664 pNode->SetSubNodes(aSubNodes);
2665 aReverseStack.Push(pNode);
2667 rNodeStack.Push(aReverseStack.Pop());
2672 void SmXMLTableContext_Impl::EndElement()
2674 SmNodeArray aExpressionArray;
2675 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
2676 SmNodeStack aReverseStack;
2677 aExpressionArray.resize(rNodeStack.Count()-nElementCount);
2679 ULONG nRows = rNodeStack.Count()-nElementCount;
2680 USHORT nCols = 0;
2682 SmStructureNode *pArray;
2683 for (ULONG i=rNodeStack.Count()-nElementCount;i > 0;i--)
2685 pArray = (SmStructureNode *)rNodeStack.Pop();
2686 if (pArray->GetNumSubNodes() == 0)
2688 //This is a little tricky, it is possible that there was
2689 //be elements that were not inside a <mtd> pair, in which
2690 //case they will not be in a row, i.e. they will not have
2691 //SubNodes, so we have to wait until here before we can
2692 //resolve the situation. Implicitsurrounding tags are
2693 //surprisingly difficult to get right within this
2694 //architecture
2696 SmNodeArray aRelationArray;
2697 aRelationArray.resize(1);
2698 aRelationArray[0] = pArray;
2699 SmToken aDummy;
2700 pArray = new SmExpressionNode(aDummy);
2701 pArray->SetSubNodes(aRelationArray);
2704 if (pArray->GetNumSubNodes() > nCols)
2705 nCols = pArray->GetNumSubNodes();
2706 aReverseStack.Push(pArray);
2708 aExpressionArray.resize(nCols*nRows);
2709 ULONG j=0;
2710 while (aReverseStack.Count())
2712 pArray = (SmStructureNode *)aReverseStack.Pop();
2713 for (USHORT i=0;i<pArray->GetNumSubNodes();i++)
2714 aExpressionArray[j++] = pArray->GetSubNode(i);
2717 SmToken aToken;
2718 aToken.cMathChar = '\0';
2719 aToken.nGroup = TRGROUP;
2720 aToken.nLevel = 0;
2721 aToken.eType = TMATRIX;
2722 SmMatrixNode *pSNode = new SmMatrixNode(aToken);
2723 pSNode->SetSubNodes(aExpressionArray);
2724 pSNode->SetRowCol(static_cast<USHORT>(nRows),nCols);
2725 rNodeStack.Push(pSNode);
2728 SvXMLImportContext *SmXMLTableRowContext_Impl::CreateChildContext(
2729 sal_uInt16 nPrefix,
2730 const OUString& rLocalName,
2731 const uno::Reference<xml::sax::XAttributeList>& xAttrList)
2733 SvXMLImportContext* pContext = 0L;
2735 const SvXMLTokenMap& rTokenMap = GetSmImport().
2736 GetPresTableElemTokenMap();
2737 switch(rTokenMap.Get(nPrefix, rLocalName))
2739 case XML_TOK_MTD:
2740 pContext = GetSmImport().CreateTableCellContext(nPrefix,
2741 rLocalName, xAttrList);
2742 break;
2743 default:
2744 pContext = SmXMLRowContext_Impl::CreateChildContext(nPrefix,
2745 rLocalName,xAttrList);
2746 break;
2748 return pContext;
2751 SvXMLImportContext *SmXMLTableContext_Impl::CreateChildContext(
2752 sal_uInt16 nPrefix,
2753 const OUString& rLocalName,
2754 const uno::Reference<xml::sax::XAttributeList>& xAttrList)
2756 SvXMLImportContext* pContext = 0L;
2758 const SvXMLTokenMap& rTokenMap = GetSmImport().
2759 GetPresTableElemTokenMap();
2760 switch(rTokenMap.Get(nPrefix, rLocalName))
2762 case XML_TOK_MTR:
2763 pContext = GetSmImport().CreateTableRowContext(nPrefix,rLocalName,
2764 xAttrList);
2765 break;
2766 default:
2767 pContext = SmXMLTableRowContext_Impl::CreateChildContext(nPrefix,
2768 rLocalName,xAttrList);
2769 break;
2771 return pContext;
2774 void SmXMLMultiScriptsContext_Impl::EndElement()
2776 if (!bHasPrescripts)
2777 MiddleElement();
2779 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
2780 if (rNodeStack.Count()-nElementCount > 1)
2782 SmToken aToken;
2783 aToken.cMathChar = '\0';
2784 aToken.nGroup = 0;
2785 aToken.nLevel = 0;
2786 aToken.eType = TLSUB;
2787 ULONG nFinalCount = rNodeStack.Count()-nElementCount-1;
2789 SmNodeStack aReverseStack;
2790 while (rNodeStack.Count()-nElementCount)
2791 aReverseStack.Push(rNodeStack.Pop());
2792 for (ULONG nCount=0;nCount < nFinalCount;nCount+=2)
2794 SmSubSupNode *pNode = new SmSubSupNode(aToken);
2796 // initialize subnodes array
2797 SmNodeArray aSubNodes;
2798 aSubNodes.resize(1 + SUBSUP_NUM_ENTRIES);
2799 for (ULONG i = 1; i < aSubNodes.size(); i++)
2800 aSubNodes[i] = NULL;
2802 /*On each loop the base and its sub sup pair becomes the
2803 base for the next loop to which the next sub sup pair is
2804 attached, i.e. wheels within wheels*/
2805 //if (nCount == 0)
2806 aSubNodes[0] = aReverseStack.Pop();
2808 SmNode *pScriptNode = aReverseStack.Pop();
2809 if (pScriptNode->GetToken().aText.Len())
2810 aSubNodes[LSUB+1] = pScriptNode;
2811 pScriptNode = aReverseStack.Pop();
2812 if (pScriptNode->GetToken().aText.Len())
2813 aSubNodes[LSUP+1] = pScriptNode;
2815 pNode->SetSubNodes(aSubNodes);
2816 aReverseStack.Push(pNode);
2818 rNodeStack.Push(aReverseStack.Pop());
2822 void SmXMLActionContext_Impl::EndElement()
2824 /*For now we will just assume that the
2825 selected attribute is one, and then just display
2826 that expression alone, i.e. remove all expect the
2827 first pushed one*/
2829 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
2830 for (ULONG i=rNodeStack.Count()-nElementCount;i > 1;i--)
2832 delete rNodeStack.Pop();
2836 SvXMLImportContext *SmXMLImport::CreateContext(sal_uInt16 nPrefix,
2837 const OUString &rLocalName,
2838 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2840 if ( XML_NAMESPACE_OFFICE == nPrefix )
2842 if ( (IsXMLToken(rLocalName, XML_DOCUMENT) ||
2843 IsXMLToken(rLocalName, XML_DOCUMENT_META)))
2845 uno::Reference<xml::sax::XDocumentHandler> xDocBuilder(
2846 mxServiceFactory->createInstance(
2847 ::rtl::OUString::createFromAscii(
2848 "com.sun.star.xml.dom.SAXDocumentBuilder")),
2849 uno::UNO_QUERY_THROW);
2850 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
2851 GetModel(), uno::UNO_QUERY_THROW);
2852 return IsXMLToken(rLocalName, XML_DOCUMENT_META)
2853 ? new SvXMLMetaDocumentContext(*this,
2854 XML_NAMESPACE_OFFICE, rLocalName,
2855 xDPS->getDocumentProperties(), xDocBuilder)
2856 // flat OpenDocument file format -- this has not been tested...
2857 : new SmXMLFlatDocContext_Impl( *this, nPrefix, rLocalName,
2858 xDPS->getDocumentProperties(), xDocBuilder);
2860 else
2862 return new SmXMLOfficeContext_Impl( *this,nPrefix,rLocalName);
2865 else
2866 return new SmXMLDocContext_Impl(*this,nPrefix,rLocalName);
2869 SvXMLImportContext *SmXMLImport::CreateRowContext(sal_uInt16 nPrefix,
2870 const OUString &rLocalName,
2871 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2873 return new SmXMLRowContext_Impl(*this,nPrefix,rLocalName);
2876 SvXMLImportContext *SmXMLImport::CreateTextContext(sal_uInt16 nPrefix,
2877 const OUString &rLocalName,
2878 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2880 return new SmXMLTextContext_Impl(*this,nPrefix,rLocalName);
2883 SvXMLImportContext *SmXMLImport::CreateAnnotationContext(sal_uInt16 nPrefix,
2884 const OUString &rLocalName,
2885 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2887 return new SmXMLAnnotationContext_Impl(*this,nPrefix,rLocalName);
2890 SvXMLImportContext *SmXMLImport::CreateStringContext(sal_uInt16 nPrefix,
2891 const OUString &rLocalName,
2892 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2894 return new SmXMLStringContext_Impl(*this,nPrefix,rLocalName);
2897 SvXMLImportContext *SmXMLImport::CreateNumberContext(sal_uInt16 nPrefix,
2898 const OUString &rLocalName,
2899 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2901 return new SmXMLNumberContext_Impl(*this,nPrefix,rLocalName);
2904 SvXMLImportContext *SmXMLImport::CreateIdentifierContext(sal_uInt16 nPrefix,
2905 const OUString &rLocalName,
2906 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2908 return new SmXMLIdentifierContext_Impl(*this,nPrefix,rLocalName);
2911 SvXMLImportContext *SmXMLImport::CreateOperatorContext(sal_uInt16 nPrefix,
2912 const OUString &rLocalName,
2913 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2915 return new SmXMLOperatorContext_Impl(*this,nPrefix,rLocalName);
2918 SvXMLImportContext *SmXMLImport::CreateSpaceContext(sal_uInt16 nPrefix,
2919 const OUString &rLocalName,
2920 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2922 return new SmXMLSpaceContext_Impl(*this,nPrefix,rLocalName);
2926 SvXMLImportContext *SmXMLImport::CreateFracContext(sal_uInt16 nPrefix,
2927 const OUString &rLocalName,
2928 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2930 return new SmXMLFracContext_Impl(*this,nPrefix,rLocalName);
2933 SvXMLImportContext *SmXMLImport::CreateSqrtContext(sal_uInt16 nPrefix,
2934 const OUString &rLocalName,
2935 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2937 return new SmXMLSqrtContext_Impl(*this,nPrefix,rLocalName);
2940 SvXMLImportContext *SmXMLImport::CreateRootContext(sal_uInt16 nPrefix,
2941 const OUString &rLocalName,
2942 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2944 return new SmXMLRootContext_Impl(*this,nPrefix,rLocalName);
2947 SvXMLImportContext *SmXMLImport::CreateStyleContext(sal_uInt16 nPrefix,
2948 const OUString &rLocalName,
2949 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2951 return new SmXMLStyleContext_Impl(*this,nPrefix,rLocalName);
2954 SvXMLImportContext *SmXMLImport::CreatePaddedContext(sal_uInt16 nPrefix,
2955 const OUString &rLocalName,
2956 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2958 return new SmXMLPaddedContext_Impl(*this,nPrefix,rLocalName);
2961 SvXMLImportContext *SmXMLImport::CreatePhantomContext(sal_uInt16 nPrefix,
2962 const OUString &rLocalName,
2963 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2965 return new SmXMLPhantomContext_Impl(*this,nPrefix,rLocalName);
2968 SvXMLImportContext *SmXMLImport::CreateFencedContext(sal_uInt16 nPrefix,
2969 const OUString &rLocalName,
2970 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2972 return new SmXMLFencedContext_Impl(*this,nPrefix,rLocalName);
2975 SvXMLImportContext *SmXMLImport::CreateErrorContext(sal_uInt16 nPrefix,
2976 const OUString &rLocalName,
2977 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2979 return new SmXMLErrorContext_Impl(*this,nPrefix,rLocalName);
2982 SvXMLImportContext *SmXMLImport::CreateSubContext(sal_uInt16 nPrefix,
2983 const OUString &rLocalName,
2984 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2986 return new SmXMLSubContext_Impl(*this,nPrefix,rLocalName);
2989 SvXMLImportContext *SmXMLImport::CreateSubSupContext(sal_uInt16 nPrefix,
2990 const OUString &rLocalName,
2991 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2993 return new SmXMLSubSupContext_Impl(*this,nPrefix,rLocalName);
2996 SvXMLImportContext *SmXMLImport::CreateSupContext(sal_uInt16 nPrefix,
2997 const OUString &rLocalName,
2998 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
3000 return new SmXMLSupContext_Impl(*this,nPrefix,rLocalName);
3003 SvXMLImportContext *SmXMLImport::CreateUnderContext(sal_uInt16 nPrefix,
3004 const OUString &rLocalName,
3005 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
3007 return new SmXMLUnderContext_Impl(*this,nPrefix,rLocalName);
3010 SvXMLImportContext *SmXMLImport::CreateOverContext(sal_uInt16 nPrefix,
3011 const OUString &rLocalName,
3012 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
3014 return new SmXMLOverContext_Impl(*this,nPrefix,rLocalName);
3017 SvXMLImportContext *SmXMLImport::CreateUnderOverContext(sal_uInt16 nPrefix,
3018 const OUString &rLocalName,
3019 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
3021 return new SmXMLUnderOverContext_Impl(*this,nPrefix,rLocalName);
3024 SvXMLImportContext *SmXMLImport::CreateMultiScriptsContext(sal_uInt16 nPrefix,
3025 const OUString &rLocalName,
3026 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
3028 return new SmXMLMultiScriptsContext_Impl(*this,nPrefix,rLocalName);
3031 SvXMLImportContext *SmXMLImport::CreateTableContext(sal_uInt16 nPrefix,
3032 const OUString &rLocalName,
3033 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
3035 return new SmXMLTableContext_Impl(*this,nPrefix,rLocalName);
3037 SvXMLImportContext *SmXMLImport::CreateTableRowContext(sal_uInt16 nPrefix,
3038 const OUString &rLocalName,
3039 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
3041 return new SmXMLTableRowContext_Impl(*this,nPrefix,rLocalName);
3043 SvXMLImportContext *SmXMLImport::CreateTableCellContext(sal_uInt16 nPrefix,
3044 const OUString &rLocalName,
3045 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
3047 return new SmXMLTableCellContext_Impl(*this,nPrefix,rLocalName);
3050 SvXMLImportContext *SmXMLImport::CreateNoneContext(sal_uInt16 nPrefix,
3051 const OUString &rLocalName,
3052 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
3054 return new SmXMLNoneContext_Impl(*this,nPrefix,rLocalName);
3057 SvXMLImportContext *SmXMLImport::CreatePrescriptsContext(sal_uInt16 nPrefix,
3058 const OUString &rLocalName,
3059 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
3061 return new SmXMLPrescriptsContext_Impl(*this,nPrefix,rLocalName);
3064 SvXMLImportContext *SmXMLImport::CreateAlignGroupContext(sal_uInt16 nPrefix,
3065 const OUString &rLocalName,
3066 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
3068 return new SmXMLAlignGroupContext_Impl(*this,nPrefix,rLocalName);
3071 SvXMLImportContext *SmXMLImport::CreateActionContext(sal_uInt16 nPrefix,
3072 const OUString &rLocalName,
3073 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
3075 return new SmXMLActionContext_Impl(*this,nPrefix,rLocalName);
3078 SmXMLImport::~SmXMLImport() throw ()
3080 delete pPresLayoutElemTokenMap;
3081 delete pPresElemTokenMap;
3082 delete pPresScriptEmptyElemTokenMap;
3083 delete pPresTableElemTokenMap;
3084 delete pPresLayoutAttrTokenMap;
3085 delete pFencedAttrTokenMap;
3086 delete pColorTokenMap;
3087 delete pOperatorAttrTokenMap;
3088 delete pAnnotationAttrTokenMap;
3091 void SmXMLImport::SetViewSettings(const Sequence<PropertyValue>& aViewProps)
3093 uno::Reference <frame::XModel> xModel = GetModel();
3094 if ( !xModel.is() )
3095 return;
3097 uno::Reference <lang::XUnoTunnel> xTunnel;
3098 xTunnel = uno::Reference <lang::XUnoTunnel> (xModel,uno::UNO_QUERY);
3099 SmModel *pModel = reinterpret_cast<SmModel *>
3100 (xTunnel->getSomething(SmModel::getUnoTunnelId()));
3102 if ( !pModel )
3103 return;
3105 SmDocShell *pDocShell =
3106 static_cast<SmDocShell*>(pModel->GetObjectShell());
3107 if ( !pDocShell )
3108 return;
3110 Rectangle aRect( pDocShell->GetVisArea() );
3112 sal_Int32 nCount = aViewProps.getLength();
3113 const PropertyValue *pValue = aViewProps.getConstArray();
3115 long nTmp = 0;
3116 //sal_Bool bShowDeletes = sal_False, bShowInserts = sal_False, bShowFooter = sal_False, bShowHeader = sal_False;
3118 for (sal_Int32 i = 0; i < nCount ; i++)
3120 if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ViewAreaTop" ) ) )
3122 pValue->Value >>= nTmp;
3123 aRect.setY( nTmp );
3125 else if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ViewAreaLeft" ) ) )
3127 pValue->Value >>= nTmp;
3128 aRect.setX( nTmp );
3130 else if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ViewAreaWidth" ) ) )
3132 pValue->Value >>= nTmp;
3133 Size aSize( aRect.GetSize() );
3134 aSize.Width() = nTmp;
3135 aRect.SetSize( aSize );
3137 else if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ViewAreaHeight" ) ) )
3139 pValue->Value >>= nTmp;
3140 Size aSize( aRect.GetSize() );
3141 aSize.Height() = nTmp;
3142 aRect.SetSize( aSize );
3144 pValue++;
3147 pDocShell->SetVisArea ( aRect );
3150 void SmXMLImport::SetConfigurationSettings(const Sequence<PropertyValue>& aConfProps)
3152 uno::Reference < XPropertySet > xProps ( GetModel(), UNO_QUERY );
3153 if ( xProps.is() )
3155 Reference < XPropertySetInfo > xInfo ( xProps->getPropertySetInfo() );
3156 if (xInfo.is() )
3158 sal_Int32 nCount = aConfProps.getLength();
3159 const PropertyValue* pValues = aConfProps.getConstArray();
3161 const OUString sFormula ( RTL_CONSTASCII_USTRINGPARAM ( "Formula" ) );
3162 const OUString sBasicLibraries ( RTL_CONSTASCII_USTRINGPARAM ( "BasicLibraries" ) );
3163 const OUString sDialogLibraries ( RTL_CONSTASCII_USTRINGPARAM ( "DialogLibraries" ) );
3164 while ( nCount-- )
3166 if (pValues->Name != sFormula &&
3167 pValues->Name != sBasicLibraries &&
3168 pValues->Name != sDialogLibraries)
3172 if ( xInfo->hasPropertyByName( pValues->Name ) )
3173 xProps->setPropertyValue( pValues->Name, pValues->Value );
3175 catch( Exception& )
3177 DBG_ERROR( "SmXMLImport::SetConfigurationSettings: Exception!" );
3181 pValues++;
3188 ////////////////////////////////////////////////////////////