diff options
author | Frank Schönheit <fs@openoffice.org> | 2001-10-16 14:46:51 +0000 |
---|---|---|
committer | Frank Schönheit <fs@openoffice.org> | 2001-10-16 14:46:51 +0000 |
commit | 6f00fdc785bac27d3ee8105f7c0a5c64adaf6bc0 (patch) | |
tree | 6ff02e9b4d589da91df3e07c735db4bddf57dee1 /svx | |
parent | b0baf9900f199d753f8aba423e1d608be098e3e2 (diff) |
#92922# getDefaultForm: be more tolerant against exceptions
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/form/fmpgeimp.cxx | 129 |
1 files changed, 69 insertions, 60 deletions
diff --git a/svx/source/form/fmpgeimp.cxx b/svx/source/form/fmpgeimp.cxx index d7f9aa45cd19..c6c6c1690b67 100644 --- a/svx/source/form/fmpgeimp.cxx +++ b/svx/source/form/fmpgeimp.cxx @@ -2,9 +2,9 @@ * * $RCSfile: fmpgeimp.cxx,v $ * - * $Revision: 1.11 $ + * $Revision: 1.12 $ * - * last change: $Author: fs $ $Date: 2001-07-25 13:43:36 $ + * last change: $Author: fs $ $Date: 2001-10-16 15:46:51 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -276,80 +276,89 @@ Reference< ::com::sun::star::form::XForm > FmFormPageImpl::getDefaultForm() { Reference< ::com::sun::star::form::XForm > xForm; - // wenn noch kein TargetForm gefunden, dann aktuelle oder Default - if (!xCurrentForm.is()) + try { - if (xForms->hasElements()) + // wenn noch kein TargetForm gefunden, dann aktuelle oder Default + if (!xCurrentForm.is()) { - // suche die Standardform - ::rtl::OUString ustrStdFormName = ::rtl::OUString(SVX_RES(RID_STR_STDFORMNAME)); - - if (xForms->hasByName(ustrStdFormName)) + if (xForms->hasElements()) { - try - { - xForms->getByName(ustrStdFormName) >>= xForm; - } - catch(::com::sun::star::container::NoSuchElementException &) + // suche die Standardform + ::rtl::OUString ustrStdFormName = ::rtl::OUString(SVX_RES(RID_STR_STDFORMNAME)); + + if (xForms->hasByName(ustrStdFormName)) { - DBG_ERROR("NoSuchElementException occured!"); + try + { + xForms->getByName(ustrStdFormName) >>= xForm; + } + catch(::com::sun::star::container::NoSuchElementException &) + { + DBG_ERROR("NoSuchElementException occured!"); + } + catch(::com::sun::star::lang::WrappedTargetException &) + { + DBG_ERROR("WrappedTargetException occured!"); + } + } - catch(::com::sun::star::lang::WrappedTargetException &) + + // gibt es denn ueberhaupt eine + if (!xForm.is()) { - DBG_ERROR("WrappedTargetException occured!"); + Reference< ::com::sun::star::container::XIndexAccess > xGetFirst(xForms, UNO_QUERY); + DBG_ASSERT(xGetFirst.is(), "FmFormPageImpl::getDefaultForm : no IndexAccess on my form container !"); + // wenn das anspringt, muesste man sich die Namen des NameContainers geben lassen und dann das Objekt fuer den + // ersten Namen erfragen ... aber normalerweise sollte die FOrms-Sammlung auch einen IndexAccess haben + xGetFirst->getByIndex(0) >>= xForm; } - - } - - // gibt es denn ueberhaupt eine - if (!xForm.is()) - { - Reference< ::com::sun::star::container::XIndexAccess > xGetFirst(xForms, UNO_QUERY); - DBG_ASSERT(xGetFirst.is(), "FmFormPageImpl::getDefaultForm : no IndexAccess on my form container !"); - // wenn das anspringt, muesste man sich die Namen des NameContainers geben lassen und dann das Objekt fuer den - // ersten Namen erfragen ... aber normalerweise sollte die FOrms-Sammlung auch einen IndexAccess haben - xGetFirst->getByIndex(0) >>= xForm; } } - } - else - xForm = xCurrentForm; + else + xForm = xCurrentForm; - // keine gefunden dann standard erzeugen - if (!xForm.is()) - { + // keine gefunden dann standard erzeugen + if (!xForm.is()) + { - SdrModel* pModel = pPage->GetModel(); - XubString aStr(SVX_RES(RID_STR_FORM)); - XubString aUndoStr(SVX_RES(RID_STR_UNDO_CONTAINER_INSERT)); - aUndoStr.SearchAndReplace('#', aStr); - pModel->BegUndo(aUndoStr); + SdrModel* pModel = pPage->GetModel(); + XubString aStr(SVX_RES(RID_STR_FORM)); + XubString aUndoStr(SVX_RES(RID_STR_UNDO_CONTAINER_INSERT)); + aUndoStr.SearchAndReplace('#', aStr); + pModel->BegUndo(aUndoStr); - xForm = Reference< ::com::sun::star::form::XForm >(::comphelper::getProcessServiceFactory()->createInstance(FM_SUN_COMPONENT_FORM), UNO_QUERY); - // a form should always have the command type table as default - Reference< ::com::sun::star::beans::XPropertySet > xSet(xForm, UNO_QUERY); - try - { - xSet->setPropertyValue(FM_PROP_COMMANDTYPE, makeAny(sal_Int32(CommandType::TABLE))); - } - catch(Exception&) - { - } + xForm = Reference< ::com::sun::star::form::XForm >(::comphelper::getProcessServiceFactory()->createInstance(FM_SUN_COMPONENT_FORM), UNO_QUERY); + // a form should always have the command type table as default + Reference< ::com::sun::star::beans::XPropertySet > xSet(xForm, UNO_QUERY); + try + { + xSet->setPropertyValue(FM_PROP_COMMANDTYPE, makeAny(sal_Int32(CommandType::TABLE))); + } + catch(Exception&) + { + } - ::rtl::OUString aName = ::rtl::OUString(SVX_RES(RID_STR_STDFORMNAME)); - xSet->setPropertyValue(FM_PROP_NAME, makeAny(aName)); + ::rtl::OUString aName = ::rtl::OUString(SVX_RES(RID_STR_STDFORMNAME)); + xSet->setPropertyValue(FM_PROP_NAME, makeAny(aName)); - Reference< ::com::sun::star::container::XIndexContainer > xContainer(xForms, UNO_QUERY); - pModel->AddUndo(new FmUndoContainerAction(*(FmFormModel*)pModel, - FmUndoContainerAction::Inserted, - xContainer, - xForm, - xContainer->getCount())); - xForms->insertByName(aName, makeAny(xForm)); - xCurrentForm = xForm; - pModel->EndUndo(); + Reference< ::com::sun::star::container::XIndexContainer > xContainer(xForms, UNO_QUERY); + pModel->AddUndo(new FmUndoContainerAction(*(FmFormModel*)pModel, + FmUndoContainerAction::Inserted, + xContainer, + xForm, + xContainer->getCount())); + xForms->insertByName(aName, makeAny(xForm)); + xCurrentForm = xForm; + pModel->EndUndo(); + } } + catch( const Exception& ) + { + DBG_ERROR( "FmFormPageImpl::getDefaultForm: caught an exception!" ); + xForm.clear(); + } + return xForm; } |