update dev300-m58
[ooovba.git] / configmgr / source / treemgr / configdefaultprovider.cxx
blobc36d5ded160a848fe783e5a4552eae400be3a776
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: configdefaultprovider.cxx,v $
10 * $Revision: 1.10 $
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_configmgr.hxx"
34 #include "configdefaultprovider.hxx"
35 #include "defaultproviderproxy.hxx"
36 #include "noderef.hxx"
37 #include "valuenode.hxx"
38 #include "tree.hxx"
39 #include "options.hxx"
41 namespace configmgr
43 //-----------------------------------------------------------------------------
44 namespace configuration
46 //-----------------------------------------------------------------------------
47 // class DefaultProvider
48 //-----------------------------------------------------------------------------
50 // standard c/d-tors to make compiler barrier
51 DefaultProvider DefaultProvider::createEmpty()
53 return DefaultProvider(NULL);
55 //-----------------------------------------------------------------------------
57 DefaultProvider DefaultProvider::create(rtl::Reference< Tree > const& _aRootTree, RequestOptions const& _aOptions,
58 rtl::Reference< TreeManager > const & _xDefaultProvider,
59 IDefaultableTreeManager* _pDefaultableTree)
61 OSL_PRECOND( !isEmpty(_aRootTree.get()), "ERROR: Cannot create DefaultProvider for NULL tree");
63 rtl::Reference< DefaultProviderProxy > xNewProxy;
65 if (!isEmpty(_aRootTree.get()))
67 xNewProxy = new DefaultProviderProxy(_xDefaultProvider,_pDefaultableTree,
68 _aRootTree->getRootPath(), _aOptions );
71 return DefaultProvider( xNewProxy );
73 //-----------------------------------------------------------------------------
75 DefaultProvider::DefaultProvider(DefaultProvider const& _aOther)
76 : m_aProxy(_aOther.m_aProxy)
79 //-----------------------------------------------------------------------------
81 DefaultProvider& DefaultProvider::operator=(DefaultProvider const& _aOther)
83 m_aProxy = _aOther.m_aProxy;
84 return *this;
86 //-----------------------------------------------------------------------------
88 DefaultProvider::~DefaultProvider()
91 //-----------------------------------------------------------------------------
93 DefaultProvider::DefaultProvider(rtl::Reference< DefaultProviderProxy > const& _xProviderProxy)
94 : m_aProxy(_xProviderProxy)
97 //-----------------------------------------------------------------------------
99 /// tries to load a default instance of the specified node
100 std::auto_ptr<ISubtree> DefaultProvider::getDefaultTree(
101 rtl::Reference< Tree > const& _aTree, NodeRef const& _aNode
102 ) const SAL_THROW((com::sun::star::uno::Exception))
104 std::auto_ptr<ISubtree> aRet;
106 node::Attributes aAttributes = _aTree->getAttributes(_aNode);
108 // if (aAttributes.bDefaulted)
109 // clone the ISubtree (no interface for that) :-(
111 if (m_aProxy.is() && aAttributes.existsInDefault())
112 aRet = m_aProxy->getDefaultTree(_aTree->getAbsolutePath(_aNode));
114 return aRet;
117 //-----------------------------------------------------------------------------
118 /// tries to load default data into the specified tree
119 static bool shouldFetchDefaultData(rtl::Reference< Tree > const& _aTreeRef, bool & _rbHasDefaults)
121 bool bShouldFetch = false;
123 node::Attributes aAttributes = _aTreeRef->getAttributes(_aTreeRef->getRootNode());
125 if (aAttributes.isDefault())
126 _rbHasDefaults = true;
128 // in replaced/added parts, defaults are considered non-existing
129 else if (!aAttributes.isReplacedForUser())
130 _rbHasDefaults = false;
132 else
133 bShouldFetch = true;
135 return bShouldFetch;
138 //-----------------------------------------------------------------------------
139 /// tries to load default data into the specified tree
140 bool DefaultProvider::fetchDefaultData(rtl::Reference< Tree > const& _aTreeRef) const SAL_THROW((com::sun::star::uno::Exception))
142 bool bHasDefaults = false;
144 if (shouldFetchDefaultData(_aTreeRef,bHasDefaults) && m_aProxy.is() )
145 bHasDefaults = m_aProxy->fetchDefaultData();
147 return bHasDefaults;
150 //-----------------------------------------------------------------------------