1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_desktop.hxx"
26 
27 #include "rtl/string.h"
28 #include "rtl/bootstrap.hxx"
29 #include "cppuhelper/exc_hlp.hxx"
30 #include "com/sun/star/uno/XComponentContext.hpp"
31 #include "com/sun/star/xml/dom/XDocumentBuilder.hpp"
32 #include "com/sun/star/xml/xpath/XXPathAPI.hpp"
33 #include "dp_misc.h"
34 
35 #include "dp_compbackenddb.hxx"
36 
37 
38 namespace css = ::com::sun::star;
39 using namespace ::com::sun::star::uno;
40 using ::rtl::OUString;
41 
42 #define EXTENSION_REG_NS "http://openoffice.org/extensionmanager/component-registry/2010"
43 #define NS_PREFIX "comp"
44 #define ROOT_ELEMENT_NAME "component-backend-db"
45 #define KEY_ELEMENT_NAME "component"
46 
47 namespace dp_registry {
48 namespace backend {
49 namespace component {
50 
ComponentBackendDb(Reference<XComponentContext> const & xContext,::rtl::OUString const & url)51 ComponentBackendDb::ComponentBackendDb(
52     Reference<XComponentContext> const &  xContext,
53     ::rtl::OUString const & url):BackendDb(xContext, url)
54 {
55 
56 }
57 
getDbNSName()58 OUString ComponentBackendDb::getDbNSName()
59 {
60     return OUSTR(EXTENSION_REG_NS);
61 }
62 
getNSPrefix()63 OUString ComponentBackendDb::getNSPrefix()
64 {
65     return OUSTR(NS_PREFIX);
66 }
67 
getRootElementName()68 OUString ComponentBackendDb::getRootElementName()
69 {
70     return OUSTR(ROOT_ELEMENT_NAME);
71 }
72 
getKeyElementName()73 OUString ComponentBackendDb::getKeyElementName()
74 {
75     return OUSTR(KEY_ELEMENT_NAME);
76 }
77 
addEntry(::rtl::OUString const & url,Data const & data)78 void ComponentBackendDb::addEntry(::rtl::OUString const & url, Data const & data)
79 {
80     try{
81         if (!activateEntry(url))
82         {
83             Reference<css::xml::dom::XNode> componentNode = writeKeyElement(url);
84             writeSimpleElement(OUSTR("java-type-library"),
85                                OUString::valueOf((sal_Bool) data.javaTypeLibrary),
86                                componentNode);
87 
88             writeSimpleList(
89                 data.implementationNames,
90                 OUSTR("implementation-names"),
91                 OUSTR("name"),
92                 componentNode);
93 
94             writeVectorOfPair(
95                 data.singletons,
96                 OUSTR("singletons"),
97                 OUSTR("item"),
98                 OUSTR("key"),
99                 OUSTR("value"),
100                 componentNode);
101 
102             save();
103         }
104     }
105     catch(css::uno::Exception &)
106     {
107         Any exc( ::cppu::getCaughtException() );
108         throw css::deployment::DeploymentException(
109             OUSTR("Extension Manager: failed to write data entry in backend db: ") +
110             m_urlDb, 0, exc);
111     }
112 }
113 
getEntry(::rtl::OUString const & url)114 ComponentBackendDb::Data ComponentBackendDb::getEntry(::rtl::OUString const & url)
115 {
116     try
117     {
118         ComponentBackendDb::Data retData;
119         Reference<css::xml::dom::XNode> aNode = getKeyElement(url);
120         if (aNode.is())
121         {
122             bool bJava = readSimpleElement(OUSTR("java-type-library"), aNode)
123                 .equals(OUSTR("true")) ? true : false;
124             retData.javaTypeLibrary = bJava;
125 
126             retData.implementationNames =
127                 readList(
128                     aNode,
129                     OUSTR("implementation-names"),
130                     OUSTR("name"));
131 
132             retData.singletons =
133                 readVectorOfPair(
134                     aNode,
135                     OUSTR("singletons"),
136                     OUSTR("item"),
137                     OUSTR("key"),
138                     OUSTR("value"));
139         }
140         return retData;
141     }
142     catch(css::uno::Exception &)
143     {
144         Any exc( ::cppu::getCaughtException() );
145         throw css::deployment::DeploymentException(
146             OUSTR("Extension Manager: failed to read data entry in backend db: ") +
147             m_urlDb, 0, exc);
148     }
149 }
150 
151 
152 } // namespace bundle
153 } // namespace backend
154 } // namespace dp_registry
155 
156