1*2722ceddSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*2722ceddSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*2722ceddSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*2722ceddSAndrew Rist * distributed with this work for additional information 6*2722ceddSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*2722ceddSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*2722ceddSAndrew Rist * "License"); you may not use this file except in compliance 9*2722ceddSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*2722ceddSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*2722ceddSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*2722ceddSAndrew Rist * software distributed under the License is distributed on an 15*2722ceddSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*2722ceddSAndrew Rist * KIND, either express or implied. See the License for the 17*2722ceddSAndrew Rist * specific language governing permissions and limitations 18*2722ceddSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*2722ceddSAndrew Rist *************************************************************/ 21*2722ceddSAndrew Rist 22*2722ceddSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_desktop.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "rtl/string.h" 28cdf0e10cSrcweir #include "rtl/bootstrap.hxx" 29cdf0e10cSrcweir #include "cppuhelper/exc_hlp.hxx" 30cdf0e10cSrcweir #include "com/sun/star/uno/XComponentContext.hpp" 31cdf0e10cSrcweir #include "com/sun/star/xml/dom/XDocumentBuilder.hpp" 32cdf0e10cSrcweir #include "com/sun/star/xml/xpath/XXPathAPI.hpp" 33cdf0e10cSrcweir #include "dp_misc.h" 34cdf0e10cSrcweir 35cdf0e10cSrcweir #include "dp_configurationbackenddb.hxx" 36cdf0e10cSrcweir 37cdf0e10cSrcweir 38cdf0e10cSrcweir namespace css = ::com::sun::star; 39cdf0e10cSrcweir using namespace ::com::sun::star::uno; 40cdf0e10cSrcweir using ::rtl::OUString; 41cdf0e10cSrcweir 42cdf0e10cSrcweir #define EXTENSION_REG_NS "http://openoffice.org/extensionmanager/configuration-registry/2010" 43cdf0e10cSrcweir #define NS_PREFIX "conf" 44cdf0e10cSrcweir #define ROOT_ELEMENT_NAME "configuration-backend-db" 45cdf0e10cSrcweir #define KEY_ELEMENT_NAME "configuration" 46cdf0e10cSrcweir 47cdf0e10cSrcweir namespace dp_registry { 48cdf0e10cSrcweir namespace backend { 49cdf0e10cSrcweir namespace configuration { 50cdf0e10cSrcweir 51cdf0e10cSrcweir ConfigurationBackendDb::ConfigurationBackendDb( 52cdf0e10cSrcweir Reference<XComponentContext> const & xContext, 53cdf0e10cSrcweir ::rtl::OUString const & url):BackendDb(xContext, url) 54cdf0e10cSrcweir { 55cdf0e10cSrcweir 56cdf0e10cSrcweir } 57cdf0e10cSrcweir 58cdf0e10cSrcweir OUString ConfigurationBackendDb::getDbNSName() 59cdf0e10cSrcweir { 60cdf0e10cSrcweir return OUSTR(EXTENSION_REG_NS); 61cdf0e10cSrcweir } 62cdf0e10cSrcweir 63cdf0e10cSrcweir OUString ConfigurationBackendDb::getNSPrefix() 64cdf0e10cSrcweir { 65cdf0e10cSrcweir return OUSTR(NS_PREFIX); 66cdf0e10cSrcweir } 67cdf0e10cSrcweir 68cdf0e10cSrcweir OUString ConfigurationBackendDb::getRootElementName() 69cdf0e10cSrcweir { 70cdf0e10cSrcweir return OUSTR(ROOT_ELEMENT_NAME); 71cdf0e10cSrcweir } 72cdf0e10cSrcweir 73cdf0e10cSrcweir OUString ConfigurationBackendDb::getKeyElementName() 74cdf0e10cSrcweir { 75cdf0e10cSrcweir return OUSTR(KEY_ELEMENT_NAME); 76cdf0e10cSrcweir } 77cdf0e10cSrcweir 78cdf0e10cSrcweir 79cdf0e10cSrcweir void ConfigurationBackendDb::addEntry(::rtl::OUString const & url, Data const & data) 80cdf0e10cSrcweir { 81cdf0e10cSrcweir try{ 82cdf0e10cSrcweir if (!activateEntry(url)) 83cdf0e10cSrcweir { 84cdf0e10cSrcweir Reference<css::xml::dom::XNode> helpNode 85cdf0e10cSrcweir = writeKeyElement(url); 86cdf0e10cSrcweir 87cdf0e10cSrcweir writeSimpleElement(OUSTR("data-url"), data.dataUrl, helpNode); 88cdf0e10cSrcweir writeSimpleElement(OUSTR("ini-entry"), data.iniEntry, helpNode); 89cdf0e10cSrcweir save(); 90cdf0e10cSrcweir } 91cdf0e10cSrcweir } 92cdf0e10cSrcweir catch (css::deployment::DeploymentException& ) 93cdf0e10cSrcweir { 94cdf0e10cSrcweir throw; 95cdf0e10cSrcweir } 96cdf0e10cSrcweir catch(css::uno::Exception &) 97cdf0e10cSrcweir { 98cdf0e10cSrcweir Any exc( ::cppu::getCaughtException() ); 99cdf0e10cSrcweir throw css::deployment::DeploymentException( 100cdf0e10cSrcweir OUSTR("Extension Manager: failed to write data entry in configuration backend db: ") + 101cdf0e10cSrcweir m_urlDb, 0, exc); 102cdf0e10cSrcweir } 103cdf0e10cSrcweir } 104cdf0e10cSrcweir 105cdf0e10cSrcweir 106cdf0e10cSrcweir ::boost::optional<ConfigurationBackendDb::Data> 107cdf0e10cSrcweir ConfigurationBackendDb::getEntry(::rtl::OUString const & url) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir try 110cdf0e10cSrcweir { 111cdf0e10cSrcweir ConfigurationBackendDb::Data retData; 112cdf0e10cSrcweir Reference<css::xml::dom::XNode> aNode = getKeyElement(url); 113cdf0e10cSrcweir if (aNode.is()) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir retData.dataUrl = readSimpleElement(OUSTR("data-url"), aNode); 116cdf0e10cSrcweir retData.iniEntry = readSimpleElement(OUSTR("ini-entry"), aNode); 117cdf0e10cSrcweir } 118cdf0e10cSrcweir else 119cdf0e10cSrcweir { 120cdf0e10cSrcweir return ::boost::optional<Data>(); 121cdf0e10cSrcweir } 122cdf0e10cSrcweir return ::boost::optional<Data>(retData); 123cdf0e10cSrcweir } 124cdf0e10cSrcweir catch (css::deployment::DeploymentException& ) 125cdf0e10cSrcweir { 126cdf0e10cSrcweir throw; 127cdf0e10cSrcweir } 128cdf0e10cSrcweir catch(css::uno::Exception &) 129cdf0e10cSrcweir { 130cdf0e10cSrcweir Any exc( ::cppu::getCaughtException() ); 131cdf0e10cSrcweir throw css::deployment::DeploymentException( 132cdf0e10cSrcweir OUSTR("Extension Manager: failed to read data entry in configuration backend db: ") + 133cdf0e10cSrcweir m_urlDb, 0, exc); 134cdf0e10cSrcweir } 135cdf0e10cSrcweir } 136cdf0e10cSrcweir 137cdf0e10cSrcweir ::std::list<OUString> ConfigurationBackendDb::getAllDataUrls() 138cdf0e10cSrcweir { 139cdf0e10cSrcweir try 140cdf0e10cSrcweir { 141cdf0e10cSrcweir ::std::list<OUString> listRet; 142cdf0e10cSrcweir Reference<css::xml::dom::XDocument> doc = getDocument(); 143cdf0e10cSrcweir Reference<css::xml::dom::XNode> root = doc->getFirstChild(); 144cdf0e10cSrcweir 145cdf0e10cSrcweir Reference<css::xml::xpath::XXPathAPI> xpathApi = getXPathAPI(); 146cdf0e10cSrcweir const OUString sPrefix = getNSPrefix(); 147cdf0e10cSrcweir OUString sExpression( 148cdf0e10cSrcweir sPrefix + OUSTR(":configuration/") + sPrefix + OUSTR(":data-url/text()")); 149cdf0e10cSrcweir Reference<css::xml::dom::XNodeList> nodes = 150cdf0e10cSrcweir xpathApi->selectNodeList(root, sExpression); 151cdf0e10cSrcweir if (nodes.is()) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir sal_Int32 length = nodes->getLength(); 154cdf0e10cSrcweir for (sal_Int32 i = 0; i < length; i++) 155cdf0e10cSrcweir listRet.push_back(nodes->item(i)->getNodeValue()); 156cdf0e10cSrcweir } 157cdf0e10cSrcweir return listRet; 158cdf0e10cSrcweir } 159cdf0e10cSrcweir catch (css::deployment::DeploymentException& ) 160cdf0e10cSrcweir { 161cdf0e10cSrcweir throw; 162cdf0e10cSrcweir } 163cdf0e10cSrcweir catch(css::uno::Exception &) 164cdf0e10cSrcweir { 165cdf0e10cSrcweir Any exc( ::cppu::getCaughtException() ); 166cdf0e10cSrcweir throw css::deployment::DeploymentException( 167cdf0e10cSrcweir OUSTR("Extension Manager: failed to read data entry in configuration backend db: ") + 168cdf0e10cSrcweir m_urlDb, 0, exc); 169cdf0e10cSrcweir } 170cdf0e10cSrcweir } 171cdf0e10cSrcweir 172cdf0e10cSrcweir ::std::list<OUString> ConfigurationBackendDb::getAllIniEntries() 173cdf0e10cSrcweir { 174cdf0e10cSrcweir return getOneChildFromAllEntries(OUSTR("ini-entry")); 175cdf0e10cSrcweir } 176cdf0e10cSrcweir 177cdf0e10cSrcweir 178cdf0e10cSrcweir 179cdf0e10cSrcweir } // namespace configuration 180cdf0e10cSrcweir } // namespace backend 181cdf0e10cSrcweir } // namespace dp_registry 182cdf0e10cSrcweir 183