1*0a1e2f0eSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*0a1e2f0eSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*0a1e2f0eSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*0a1e2f0eSAndrew Rist * distributed with this work for additional information 6*0a1e2f0eSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*0a1e2f0eSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*0a1e2f0eSAndrew Rist * "License"); you may not use this file except in compliance 9*0a1e2f0eSAndrew Rist * with the License. You may obtain a copy of the License at 10*0a1e2f0eSAndrew Rist * 11*0a1e2f0eSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*0a1e2f0eSAndrew Rist * 13*0a1e2f0eSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*0a1e2f0eSAndrew Rist * software distributed under the License is distributed on an 15*0a1e2f0eSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*0a1e2f0eSAndrew Rist * KIND, either express or implied. See the License for the 17*0a1e2f0eSAndrew Rist * specific language governing permissions and limitations 18*0a1e2f0eSAndrew Rist * under the License. 19*0a1e2f0eSAndrew Rist * 20*0a1e2f0eSAndrew Rist *************************************************************/ 21*0a1e2f0eSAndrew Rist 22*0a1e2f0eSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #if ! defined INCLUDED_DP_BACKENDDB_HXX 25cdf0e10cSrcweir #define INCLUDED_DP_BACKENDDB_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "rtl/ustring.hxx" 28cdf0e10cSrcweir #include <list> 29cdf0e10cSrcweir #include <vector> 30cdf0e10cSrcweir 31cdf0e10cSrcweir namespace css = ::com::sun::star; 32cdf0e10cSrcweir 33cdf0e10cSrcweir namespace com { namespace sun { namespace star { 34cdf0e10cSrcweir namespace uno { 35cdf0e10cSrcweir class XComponentContext; 36cdf0e10cSrcweir } 37cdf0e10cSrcweir namespace xml { namespace dom { 38cdf0e10cSrcweir class XDocument; 39cdf0e10cSrcweir class XNode; 40cdf0e10cSrcweir }} 41cdf0e10cSrcweir namespace xml { namespace xpath { 42cdf0e10cSrcweir class XXPathAPI; 43cdf0e10cSrcweir }} 44cdf0e10cSrcweir }}} 45cdf0e10cSrcweir 46cdf0e10cSrcweir namespace dp_registry { 47cdf0e10cSrcweir namespace backend { 48cdf0e10cSrcweir 49cdf0e10cSrcweir class BackendDb 50cdf0e10cSrcweir { 51cdf0e10cSrcweir private: 52cdf0e10cSrcweir 53cdf0e10cSrcweir css::uno::Reference<css::xml::dom::XDocument> m_doc; 54cdf0e10cSrcweir css::uno::Reference<css::xml::xpath::XXPathAPI> m_xpathApi; 55cdf0e10cSrcweir 56cdf0e10cSrcweir BackendDb(BackendDb const &); 57cdf0e10cSrcweir BackendDb & operator = (BackendDb const &); 58cdf0e10cSrcweir 59cdf0e10cSrcweir protected: 60cdf0e10cSrcweir const css::uno::Reference<css::uno::XComponentContext> m_xContext; 61cdf0e10cSrcweir ::rtl::OUString m_urlDb; 62cdf0e10cSrcweir 63cdf0e10cSrcweir protected: 64cdf0e10cSrcweir 65cdf0e10cSrcweir /* caller must make sure that only one thread accesses the function 66cdf0e10cSrcweir */ 67cdf0e10cSrcweir css::uno::Reference<css::xml::dom::XDocument> getDocument(); 68cdf0e10cSrcweir 69cdf0e10cSrcweir /* the namespace prefix is "reg" (without quotes) 70cdf0e10cSrcweir */ 71cdf0e10cSrcweir css::uno::Reference<css::xml::xpath::XXPathAPI> getXPathAPI(); 72cdf0e10cSrcweir void save(); 73cdf0e10cSrcweir void removeElement(::rtl::OUString const & sXPathExpression); 74cdf0e10cSrcweir 75cdf0e10cSrcweir css::uno::Reference<css::xml::dom::XNode> getKeyElement( 76cdf0e10cSrcweir ::rtl::OUString const & url); 77cdf0e10cSrcweir 78cdf0e10cSrcweir void writeSimpleList( 79cdf0e10cSrcweir ::std::list< ::rtl::OUString> const & list, 80cdf0e10cSrcweir ::rtl::OUString const & sListTagName, 81cdf0e10cSrcweir ::rtl::OUString const & sMemberTagName, 82cdf0e10cSrcweir css::uno::Reference<css::xml::dom::XNode> const & xParent); 83cdf0e10cSrcweir 84cdf0e10cSrcweir void writeVectorOfPair( 85cdf0e10cSrcweir ::std::vector< ::std::pair< ::rtl::OUString, ::rtl::OUString > > const & vecPairs, 86cdf0e10cSrcweir ::rtl::OUString const & sVectorTagName, 87cdf0e10cSrcweir ::rtl::OUString const & sPairTagName, 88cdf0e10cSrcweir ::rtl::OUString const & sFirstTagName, 89cdf0e10cSrcweir ::rtl::OUString const & sSecondTagName, 90cdf0e10cSrcweir css::uno::Reference<css::xml::dom::XNode> const & xParent); 91cdf0e10cSrcweir 92cdf0e10cSrcweir void writeSimpleElement( 93cdf0e10cSrcweir ::rtl::OUString const & sElementName, ::rtl::OUString const & value, 94cdf0e10cSrcweir css::uno::Reference<css::xml::dom::XNode> const & xParent); 95cdf0e10cSrcweir 96cdf0e10cSrcweir css::uno::Reference<css::xml::dom::XNode> writeKeyElement( 97cdf0e10cSrcweir ::rtl::OUString const & url); 98cdf0e10cSrcweir 99cdf0e10cSrcweir ::rtl::OUString readSimpleElement( 100cdf0e10cSrcweir ::rtl::OUString const & sElementName, 101cdf0e10cSrcweir css::uno::Reference<css::xml::dom::XNode> const & xParent); 102cdf0e10cSrcweir 103cdf0e10cSrcweir ::std::vector< ::std::pair< ::rtl::OUString, ::rtl::OUString > > 104cdf0e10cSrcweir readVectorOfPair( 105cdf0e10cSrcweir css::uno::Reference<css::xml::dom::XNode> const & parent, 106cdf0e10cSrcweir ::rtl::OUString const & sListTagName, 107cdf0e10cSrcweir ::rtl::OUString const & sPairTagName, 108cdf0e10cSrcweir ::rtl::OUString const & sFirstTagName, 109cdf0e10cSrcweir ::rtl::OUString const & sSecondTagName); 110cdf0e10cSrcweir 111cdf0e10cSrcweir ::std::list< ::rtl::OUString> readList( 112cdf0e10cSrcweir css::uno::Reference<css::xml::dom::XNode> const & parent, 113cdf0e10cSrcweir ::rtl::OUString const & sListTagName, 114cdf0e10cSrcweir ::rtl::OUString const & sMemberTagName); 115cdf0e10cSrcweir 116cdf0e10cSrcweir /* returns the values of one particulary child element of all key elements. 117cdf0e10cSrcweir */ 118cdf0e10cSrcweir ::std::list< ::rtl::OUString> getOneChildFromAllEntries( 119cdf0e10cSrcweir ::rtl::OUString const & sElementName); 120cdf0e10cSrcweir 121cdf0e10cSrcweir 122cdf0e10cSrcweir /* returns the namespace which is to be written as xmlns attribute 123cdf0e10cSrcweir into the root element. 124cdf0e10cSrcweir */ 125cdf0e10cSrcweir virtual ::rtl::OUString getDbNSName()=0; 126cdf0e10cSrcweir /* return the namespace prefix which is to be registered with the XPath API. 127cdf0e10cSrcweir 128cdf0e10cSrcweir The prefix can then be used in XPath expressions. 129cdf0e10cSrcweir */ 130cdf0e10cSrcweir virtual ::rtl::OUString getNSPrefix()=0; 131cdf0e10cSrcweir /* returns the name of the root element without any namespace prefix. 132cdf0e10cSrcweir */ 133cdf0e10cSrcweir virtual ::rtl::OUString getRootElementName()=0; 134cdf0e10cSrcweir /* returns the name of xml element for each entry 135cdf0e10cSrcweir */ 136cdf0e10cSrcweir virtual ::rtl::OUString getKeyElementName()=0; 137cdf0e10cSrcweir 138cdf0e10cSrcweir 139cdf0e10cSrcweir 140cdf0e10cSrcweir public: 141cdf0e10cSrcweir BackendDb(css::uno::Reference<css::uno::XComponentContext> const & xContext, 142cdf0e10cSrcweir ::rtl::OUString const & url); 143cdf0e10cSrcweir virtual ~BackendDb() {}; 144cdf0e10cSrcweir 145cdf0e10cSrcweir void removeEntry(::rtl::OUString const & url); 146cdf0e10cSrcweir 147cdf0e10cSrcweir /* This is called to write the "revoked" attribute to the entry. 148cdf0e10cSrcweir This is done when XPackage::revokePackage is called. 149cdf0e10cSrcweir */ 150cdf0e10cSrcweir void revokeEntry(::rtl::OUString const & url); 151cdf0e10cSrcweir 152cdf0e10cSrcweir /* returns false if the entry does not exist yet. 153cdf0e10cSrcweir */ 154cdf0e10cSrcweir bool activateEntry(::rtl::OUString const & url); 155cdf0e10cSrcweir 156cdf0e10cSrcweir bool hasActiveEntry(::rtl::OUString const & url); 157cdf0e10cSrcweir 158cdf0e10cSrcweir }; 159cdf0e10cSrcweir 160cdf0e10cSrcweir class RegisteredDb: public BackendDb 161cdf0e10cSrcweir { 162cdf0e10cSrcweir 163cdf0e10cSrcweir public: 164cdf0e10cSrcweir RegisteredDb( css::uno::Reference<css::uno::XComponentContext> const & xContext, 165cdf0e10cSrcweir ::rtl::OUString const & url); 166cdf0e10cSrcweir virtual ~RegisteredDb() {}; 167cdf0e10cSrcweir 168cdf0e10cSrcweir 169cdf0e10cSrcweir virtual void addEntry(::rtl::OUString const & url); 170cdf0e10cSrcweir virtual bool getEntry(::rtl::OUString const & url); 171cdf0e10cSrcweir 172cdf0e10cSrcweir }; 173cdf0e10cSrcweir 174cdf0e10cSrcweir 175cdf0e10cSrcweir } 176cdf0e10cSrcweir } 177cdf0e10cSrcweir #endif 178cdf0e10cSrcweir 179