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
10*2722ceddSAndrew Rist  *
11*2722ceddSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2722ceddSAndrew Rist  *
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.
19*2722ceddSAndrew Rist  *
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_compbackenddb.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/component-registry/2010"
43cdf0e10cSrcweir #define NS_PREFIX "comp"
44cdf0e10cSrcweir #define ROOT_ELEMENT_NAME "component-backend-db"
45cdf0e10cSrcweir #define KEY_ELEMENT_NAME "component"
46cdf0e10cSrcweir 
47cdf0e10cSrcweir namespace dp_registry {
48cdf0e10cSrcweir namespace backend {
49cdf0e10cSrcweir namespace component {
50cdf0e10cSrcweir 
ComponentBackendDb(Reference<XComponentContext> const & xContext,::rtl::OUString const & url)51cdf0e10cSrcweir ComponentBackendDb::ComponentBackendDb(
52cdf0e10cSrcweir     Reference<XComponentContext> const &  xContext,
53cdf0e10cSrcweir     ::rtl::OUString const & url):BackendDb(xContext, url)
54cdf0e10cSrcweir {
55cdf0e10cSrcweir 
56cdf0e10cSrcweir }
57cdf0e10cSrcweir 
getDbNSName()58cdf0e10cSrcweir OUString ComponentBackendDb::getDbNSName()
59cdf0e10cSrcweir {
60cdf0e10cSrcweir     return OUSTR(EXTENSION_REG_NS);
61cdf0e10cSrcweir }
62cdf0e10cSrcweir 
getNSPrefix()63cdf0e10cSrcweir OUString ComponentBackendDb::getNSPrefix()
64cdf0e10cSrcweir {
65cdf0e10cSrcweir     return OUSTR(NS_PREFIX);
66cdf0e10cSrcweir }
67cdf0e10cSrcweir 
getRootElementName()68cdf0e10cSrcweir OUString ComponentBackendDb::getRootElementName()
69cdf0e10cSrcweir {
70cdf0e10cSrcweir     return OUSTR(ROOT_ELEMENT_NAME);
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
getKeyElementName()73cdf0e10cSrcweir OUString ComponentBackendDb::getKeyElementName()
74cdf0e10cSrcweir {
75cdf0e10cSrcweir     return OUSTR(KEY_ELEMENT_NAME);
76cdf0e10cSrcweir }
77cdf0e10cSrcweir 
addEntry(::rtl::OUString const & url,Data const & data)78cdf0e10cSrcweir void ComponentBackendDb::addEntry(::rtl::OUString const & url, Data const & data)
79cdf0e10cSrcweir {
80cdf0e10cSrcweir     try{
81cdf0e10cSrcweir         if (!activateEntry(url))
82cdf0e10cSrcweir         {
83cdf0e10cSrcweir             Reference<css::xml::dom::XNode> componentNode = writeKeyElement(url);
84cdf0e10cSrcweir             writeSimpleElement(OUSTR("java-type-library"),
85cdf0e10cSrcweir                                OUString::valueOf((sal_Bool) data.javaTypeLibrary),
86cdf0e10cSrcweir                                componentNode);
87cdf0e10cSrcweir 
88cdf0e10cSrcweir             writeSimpleList(
89cdf0e10cSrcweir                 data.implementationNames,
90cdf0e10cSrcweir                 OUSTR("implementation-names"),
91cdf0e10cSrcweir                 OUSTR("name"),
92cdf0e10cSrcweir                 componentNode);
93cdf0e10cSrcweir 
94cdf0e10cSrcweir             writeVectorOfPair(
95cdf0e10cSrcweir                 data.singletons,
96cdf0e10cSrcweir                 OUSTR("singletons"),
97cdf0e10cSrcweir                 OUSTR("item"),
98cdf0e10cSrcweir                 OUSTR("key"),
99cdf0e10cSrcweir                 OUSTR("value"),
100cdf0e10cSrcweir                 componentNode);
101cdf0e10cSrcweir 
102cdf0e10cSrcweir             save();
103cdf0e10cSrcweir         }
104cdf0e10cSrcweir     }
105cdf0e10cSrcweir     catch(css::uno::Exception &)
106cdf0e10cSrcweir     {
107cdf0e10cSrcweir         Any exc( ::cppu::getCaughtException() );
108cdf0e10cSrcweir         throw css::deployment::DeploymentException(
109cdf0e10cSrcweir             OUSTR("Extension Manager: failed to write data entry in backend db: ") +
110cdf0e10cSrcweir             m_urlDb, 0, exc);
111cdf0e10cSrcweir     }
112cdf0e10cSrcweir }
113cdf0e10cSrcweir 
getEntry(::rtl::OUString const & url)114cdf0e10cSrcweir ComponentBackendDb::Data ComponentBackendDb::getEntry(::rtl::OUString const & url)
115cdf0e10cSrcweir {
116cdf0e10cSrcweir     try
117cdf0e10cSrcweir     {
118cdf0e10cSrcweir         ComponentBackendDb::Data retData;
119cdf0e10cSrcweir         Reference<css::xml::dom::XNode> aNode = getKeyElement(url);
120cdf0e10cSrcweir         if (aNode.is())
121cdf0e10cSrcweir         {
122cdf0e10cSrcweir             bool bJava = readSimpleElement(OUSTR("java-type-library"), aNode)
123cdf0e10cSrcweir                 .equals(OUSTR("true")) ? true : false;
124cdf0e10cSrcweir             retData.javaTypeLibrary = bJava;
125cdf0e10cSrcweir 
126cdf0e10cSrcweir             retData.implementationNames =
127cdf0e10cSrcweir                 readList(
128cdf0e10cSrcweir                     aNode,
129cdf0e10cSrcweir                     OUSTR("implementation-names"),
130cdf0e10cSrcweir                     OUSTR("name"));
131cdf0e10cSrcweir 
132cdf0e10cSrcweir             retData.singletons =
133cdf0e10cSrcweir                 readVectorOfPair(
134cdf0e10cSrcweir                     aNode,
135cdf0e10cSrcweir                     OUSTR("singletons"),
136cdf0e10cSrcweir                     OUSTR("item"),
137cdf0e10cSrcweir                     OUSTR("key"),
138cdf0e10cSrcweir                     OUSTR("value"));
139cdf0e10cSrcweir         }
140cdf0e10cSrcweir         return retData;
141cdf0e10cSrcweir     }
142cdf0e10cSrcweir     catch(css::uno::Exception &)
143cdf0e10cSrcweir     {
144cdf0e10cSrcweir         Any exc( ::cppu::getCaughtException() );
145cdf0e10cSrcweir         throw css::deployment::DeploymentException(
146cdf0e10cSrcweir             OUSTR("Extension Manager: failed to read data entry in backend db: ") +
147cdf0e10cSrcweir             m_urlDb, 0, exc);
148cdf0e10cSrcweir     }
149cdf0e10cSrcweir }
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 
152cdf0e10cSrcweir } // namespace bundle
153cdf0e10cSrcweir } // namespace backend
154cdf0e10cSrcweir } // namespace dp_registry
155cdf0e10cSrcweir 
156