1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #if ! defined INCLUDED_DP_BACKENDDB_HXX 29 #define INCLUDED_DP_BACKENDDB_HXX 30 31 #include "rtl/ustring.hxx" 32 #include <list> 33 #include <vector> 34 35 namespace css = ::com::sun::star; 36 37 namespace com { namespace sun { namespace star { 38 namespace uno { 39 class XComponentContext; 40 } 41 namespace xml { namespace dom { 42 class XDocument; 43 class XNode; 44 }} 45 namespace xml { namespace xpath { 46 class XXPathAPI; 47 }} 48 }}} 49 50 namespace dp_registry { 51 namespace backend { 52 53 class BackendDb 54 { 55 private: 56 57 css::uno::Reference<css::xml::dom::XDocument> m_doc; 58 css::uno::Reference<css::xml::xpath::XXPathAPI> m_xpathApi; 59 60 BackendDb(BackendDb const &); 61 BackendDb & operator = (BackendDb const &); 62 63 protected: 64 const css::uno::Reference<css::uno::XComponentContext> m_xContext; 65 ::rtl::OUString m_urlDb; 66 67 protected: 68 69 /* caller must make sure that only one thread accesses the function 70 */ 71 css::uno::Reference<css::xml::dom::XDocument> getDocument(); 72 73 /* the namespace prefix is "reg" (without quotes) 74 */ 75 css::uno::Reference<css::xml::xpath::XXPathAPI> getXPathAPI(); 76 void save(); 77 void removeElement(::rtl::OUString const & sXPathExpression); 78 79 css::uno::Reference<css::xml::dom::XNode> getKeyElement( 80 ::rtl::OUString const & url); 81 82 void writeSimpleList( 83 ::std::list< ::rtl::OUString> const & list, 84 ::rtl::OUString const & sListTagName, 85 ::rtl::OUString const & sMemberTagName, 86 css::uno::Reference<css::xml::dom::XNode> const & xParent); 87 88 void writeVectorOfPair( 89 ::std::vector< ::std::pair< ::rtl::OUString, ::rtl::OUString > > const & vecPairs, 90 ::rtl::OUString const & sVectorTagName, 91 ::rtl::OUString const & sPairTagName, 92 ::rtl::OUString const & sFirstTagName, 93 ::rtl::OUString const & sSecondTagName, 94 css::uno::Reference<css::xml::dom::XNode> const & xParent); 95 96 void writeSimpleElement( 97 ::rtl::OUString const & sElementName, ::rtl::OUString const & value, 98 css::uno::Reference<css::xml::dom::XNode> const & xParent); 99 100 css::uno::Reference<css::xml::dom::XNode> writeKeyElement( 101 ::rtl::OUString const & url); 102 103 ::rtl::OUString readSimpleElement( 104 ::rtl::OUString const & sElementName, 105 css::uno::Reference<css::xml::dom::XNode> const & xParent); 106 107 ::std::vector< ::std::pair< ::rtl::OUString, ::rtl::OUString > > 108 readVectorOfPair( 109 css::uno::Reference<css::xml::dom::XNode> const & parent, 110 ::rtl::OUString const & sListTagName, 111 ::rtl::OUString const & sPairTagName, 112 ::rtl::OUString const & sFirstTagName, 113 ::rtl::OUString const & sSecondTagName); 114 115 ::std::list< ::rtl::OUString> readList( 116 css::uno::Reference<css::xml::dom::XNode> const & parent, 117 ::rtl::OUString const & sListTagName, 118 ::rtl::OUString const & sMemberTagName); 119 120 /* returns the values of one particulary child element of all key elements. 121 */ 122 ::std::list< ::rtl::OUString> getOneChildFromAllEntries( 123 ::rtl::OUString const & sElementName); 124 125 126 /* returns the namespace which is to be written as xmlns attribute 127 into the root element. 128 */ 129 virtual ::rtl::OUString getDbNSName()=0; 130 /* return the namespace prefix which is to be registered with the XPath API. 131 132 The prefix can then be used in XPath expressions. 133 */ 134 virtual ::rtl::OUString getNSPrefix()=0; 135 /* returns the name of the root element without any namespace prefix. 136 */ 137 virtual ::rtl::OUString getRootElementName()=0; 138 /* returns the name of xml element for each entry 139 */ 140 virtual ::rtl::OUString getKeyElementName()=0; 141 142 143 144 public: 145 BackendDb(css::uno::Reference<css::uno::XComponentContext> const & xContext, 146 ::rtl::OUString const & url); 147 virtual ~BackendDb() {}; 148 149 void removeEntry(::rtl::OUString const & url); 150 151 /* This is called to write the "revoked" attribute to the entry. 152 This is done when XPackage::revokePackage is called. 153 */ 154 void revokeEntry(::rtl::OUString const & url); 155 156 /* returns false if the entry does not exist yet. 157 */ 158 bool activateEntry(::rtl::OUString const & url); 159 160 bool hasActiveEntry(::rtl::OUString const & url); 161 162 }; 163 164 class RegisteredDb: public BackendDb 165 { 166 167 public: 168 RegisteredDb( css::uno::Reference<css::uno::XComponentContext> const & xContext, 169 ::rtl::OUString const & url); 170 virtual ~RegisteredDb() {}; 171 172 173 virtual void addEntry(::rtl::OUString const & url); 174 virtual bool getEntry(::rtl::OUString const & url); 175 176 }; 177 178 179 } 180 } 181 #endif 182 183