summaryrefslogtreecommitdiff
path: root/unotools
diff options
context:
space:
mode:
authorOliver Specht <os@openoffice.org>2001-01-23 15:30:25 +0000
committerOliver Specht <os@openoffice.org>2001-01-23 15:30:25 +0000
commit4285f3f51d7543bf4f4e1e055f6c79758a94010e (patch)
tree8339a747ff832c582395c883ab68fef893060bf1 /unotools
parent150e1132bdd6f1c25a818bfd9cc27b6475e1d72e (diff)
new: AddNode()
Diffstat (limited to 'unotools')
-rw-r--r--unotools/inc/unotools/configitem.hxx21
-rw-r--r--unotools/source/config/configitem.cxx134
2 files changed, 76 insertions, 79 deletions
diff --git a/unotools/inc/unotools/configitem.hxx b/unotools/inc/unotools/configitem.hxx
index 8e57341fd192..a6c334bacf9f 100644
--- a/unotools/inc/unotools/configitem.hxx
+++ b/unotools/inc/unotools/configitem.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: configitem.hxx,v $
*
- * $Revision: 1.7 $
+ * $Revision: 1.8 $
*
- * last change: $Author: os $ $Date: 2000-12-05 12:59:58 $
+ * last change: $Author: os $ $Date: 2001-01-23 16:29:51 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -105,15 +105,9 @@ namespace utl
xChangeLstnr;
utl::ConfigManager* pManager;
sal_Bool bIsModified : 1; //
-#if SUPD>615
-#else
- sal_Bool bInPutValues : 1; //prevent notification of own change actions
-#endif
sal_Bool bHasChangedProperties : 1; //call XChangesBatch::Commit() if any changes were notified
-#if SUPD>615
sal_Int16 nInValueChange;
-#endif
ConfigItem();//
void RemoveListener();
void CallNotify(
@@ -132,11 +126,7 @@ namespace utl
const com::sun::star::uno::Sequence< rtl::OUString >& rNames,
const com::sun::star::uno::Sequence< com::sun::star::uno::Any>& rValues);
-#if SUPD>615
sal_Bool EnableNotification(const com::sun::star::uno::Sequence< rtl::OUString >& rNames);
-#else
- sal_Bool EnableNotification(com::sun::star::uno::Sequence< rtl::OUString >& rNames);
-#endif
//returns all members of a node
com::sun::star::uno::Sequence< rtl::OUString >
@@ -150,6 +140,8 @@ namespace utl
sal_Bool SetSetProperties(const rtl::OUString& rNode, com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > rValues);
// remove, change or add members of a set
sal_Bool ReplaceSetProperties(const rtl::OUString& rNode, com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > rValues);
+ // add a new node without setting any properties
+ sal_Bool AddNode(const rtl::OUString& rNode, const rtl::OUString& rNewNode);
public:
virtual ~ConfigItem();
@@ -168,12 +160,7 @@ namespace utl
/** writes the changed values into the sub tree. Always called in the Dtor of the derived class. */
virtual void Commit();
-#if SUPD>615
sal_Bool IsInValueChange() const {return nInValueChange > 0;}
-#else
- void SetInValueChange(sal_Bool bSet) {bInPutValues = bSet;}
- sal_Bool IsInValueChange() const {return bInPutValues;}
-#endif
};
}//namespace utl
#endif //_UTL_CONFIGITEM_HXX_
diff --git a/unotools/source/config/configitem.cxx b/unotools/source/config/configitem.cxx
index 3a3bdd6924b0..62b7990fa4c7 100644
--- a/unotools/source/config/configitem.cxx
+++ b/unotools/source/config/configitem.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: configitem.cxx,v $
*
- * $Revision: 1.19 $
+ * $Revision: 1.20 $
*
- * last change: $Author: sb $ $Date: 2000-12-14 08:31:10 $
+ * last change: $Author: os $ $Date: 2001-01-23 16:30:25 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -143,7 +143,6 @@ namespace utl{
/* -----------------------------04.12.00 10:25--------------------------------
---------------------------------------------------------------------------*/
-#if SUPD>615
class ValueCounter_Impl
{
sal_Int16& rCnt;
@@ -157,33 +156,6 @@ public:
rCnt--;
}
};
-#else
-class ValueCounter_Impl
-{
- ConfigItem& rItem;
- sal_Bool bFlagChanged;
-public:
- ValueCounter_Impl(ConfigItem& rCfgItem);
- ~ValueCounter_Impl();
-};
-ValueCounter_Impl::ValueCounter_Impl(ConfigItem& rCfgItem):
- rItem(rCfgItem),
- bFlagChanged(sal_False)
-{
- if(!rItem.IsInValueChange())
- {
- rItem.SetInValueChange(sal_True);
- bFlagChanged = sal_True;
- }
-}
-
-ValueCounter_Impl::~ValueCounter_Impl()
-{
- if(bFlagChanged)
- rItem.SetInValueChange(sal_False);
-}
-
-#endif
/* -----------------------------29.08.00 16:34--------------------------------
---------------------------------------------------------------------------*/
@@ -259,11 +231,7 @@ ConfigItem::ConfigItem(const OUString rSubTree ) :
sSubTree(rSubTree),
bIsModified(sal_False),
bHasChangedProperties(sal_False),
-#if SUPD>615
nInValueChange(0)
-#else
- bInPutValues(sal_False)
-#endif
{
xHierarchyAccess = pManager->AddConfigItem(*this);
}
@@ -274,11 +242,7 @@ ConfigItem::ConfigItem(utl::ConfigManager& rManager, const rtl::OUString rSubTr
pManager(&rManager),
sSubTree(rSubTree),
bIsModified(sal_False),
-#if SUPD>615
nInValueChange(0),
-#else
- bInPutValues(sal_False),
-#endif
bHasChangedProperties(sal_False)
{
xHierarchyAccess = pManager->AddConfigItem(*this);
@@ -449,11 +413,7 @@ Sequence< Any > ConfigItem::GetProperties(const Sequence< OUString >& rNames)
sal_Bool ConfigItem::PutProperties( const Sequence< OUString >& rNames,
const Sequence< Any>& rValues)
{
-#if SUPD>615
ValueCounter_Impl aCounter(nInValueChange);
-#else
- ValueCounter_Impl aCounter(*this);
-#endif
Reference<XNameReplace> xTopNodeReplace(xHierarchyAccess, UNO_QUERY);
sal_Bool bRet = xHierarchyAccess.is() && xTopNodeReplace.is();
if(bRet)
@@ -523,11 +483,7 @@ sal_Bool ConfigItem::PutProperties( const Sequence< OUString >& rNames,
/* -----------------------------29.08.00 16:19--------------------------------
---------------------------------------------------------------------------*/
-#if SUPD>615
sal_Bool ConfigItem::EnableNotification(const Sequence< OUString >& rNames)
-#else
-sal_Bool ConfigItem::EnableNotification(Sequence< OUString >& rNames)
-#endif
{
Reference<XChangesNotifier> xChgNot(xHierarchyAccess, UNO_QUERY);
if(!xChgNot.is())
@@ -606,11 +562,7 @@ Sequence< OUString > ConfigItem::GetNodeNames(const OUString& rNode)
---------------------------------------------------------------------------*/
sal_Bool ConfigItem::ClearNodeSet(const OUString& rNode)
{
-#if SUPD>615
ValueCounter_Impl aCounter(nInValueChange);
-#else
- ValueCounter_Impl aCounter(*this);
-#endif
sal_Bool bRet;
if(xHierarchyAccess.is())
{
@@ -660,11 +612,7 @@ sal_Bool ConfigItem::ClearNodeSet(const OUString& rNode)
---------------------------------------------------------------------------*/
sal_Bool ConfigItem::ClearNodeElements(const OUString& rNode, Sequence< OUString >& rElements)
{
-#if SUPD>615
ValueCounter_Impl aCounter(nInValueChange);
-#else
- ValueCounter_Impl aCounter(*this);
-#endif
sal_Bool bRet;
if(xHierarchyAccess.is())
{
@@ -713,11 +661,7 @@ sal_Bool ConfigItem::ClearNodeElements(const OUString& rNode, Sequence< OUString
sal_Bool ConfigItem::SetSetProperties(
const OUString& rNode, Sequence< PropertyValue > rValues)
{
-#if SUPD>615
ValueCounter_Impl aCounter(nInValueChange);
-#else
- ValueCounter_Impl aCounter(*this);
-#endif
sal_Bool bRet;
if(xHierarchyAccess.is())
{
@@ -834,11 +778,7 @@ sal_Bool ConfigItem::SetSetProperties(
sal_Bool ConfigItem::ReplaceSetProperties(
const OUString& rNode, Sequence< PropertyValue > rValues)
{
-#if SUPD>615
ValueCounter_Impl aCounter(nInValueChange);
-#else
- ValueCounter_Impl aCounter(*this);
-#endif
sal_Bool bRet;
if(xHierarchyAccess.is())
{
@@ -989,6 +929,76 @@ sal_Bool ConfigItem::ReplaceSetProperties(
}
return bRet;
}
+/* -----------------------------23.01.01 12:49--------------------------------
+
+ ---------------------------------------------------------------------------*/
+sal_Bool ConfigItem::AddNode(const rtl::OUString& rNode, const rtl::OUString& rNewNode)
+{
+ ValueCounter_Impl aCounter(nInValueChange);
+ sal_Bool bRet;
+ if(xHierarchyAccess.is())
+ {
+ Reference<XChangesBatch> xBatch(xHierarchyAccess, UNO_QUERY);
+ try
+ {
+ Reference<XNameContainer> xCont;
+ if(rNode.getLength())
+ {
+ Any aNode = xHierarchyAccess->getByHierarchicalName(rNode);
+ aNode >>= xCont;
+ }
+ else
+ xCont = Reference<XNameContainer> (xHierarchyAccess, UNO_QUERY);
+ if(!xCont.is())
+ return sal_False;
+ Reference<XSingleServiceFactory> xFac(xCont, UNO_QUERY);
+ sal_Int32 nNodeLength = rNode.getLength() + 1;
+ if(xFac.is())
+ {
+ if(!xCont->hasByName(rNewNode))
+ {
+ Reference<XInterface> xInst = xFac->createInstance();
+ Any aVal; aVal <<= xInst;
+ xCont->insertByName(rNewNode, aVal);
+ }
+ try
+ {
+ xBatch->commitChanges();
+ }
+ catch(Exception& rEx)
+ {
+#ifdef DBG_UTIL
+ lcl_CFG_DBG_EXCEPTION("Exception from commitChanges(): ", rEx);
+#endif
+ }
+ }
+ else
+ {
+ //if no factory is available then the node contains basic data elements
+ try
+ {
+ if(!xCont->hasByName(rNewNode))
+ xCont->insertByName(rNewNode, Any());
+ }
+ catch(Exception& rEx)
+ {
+#ifdef DBG_UTIL
+ lcl_CFG_DBG_EXCEPTION("Exception from AddNode(): ", rEx);
+#endif
+ }
+ }
+ xBatch->commitChanges();
+ }
+ catch(Exception& rEx)
+ {
+#ifdef DBG_UTIL
+ lcl_CFG_DBG_EXCEPTION("Exception from AddNode(): ", rEx);
+#endif
+ bRet = sal_False;
+ }
+ }
+ return bRet;
+}