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_extbackenddb.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/extension-registry/2010"
43 #define NS_PREFIX "ext"
44 #define ROOT_ELEMENT_NAME "extension-backend-db"
45 #define KEY_ELEMENT_NAME "extension"
46 
47 namespace dp_registry {
48 namespace backend {
49 namespace bundle {
50 
ExtensionBackendDb(Reference<XComponentContext> const & xContext,::rtl::OUString const & url)51 ExtensionBackendDb::ExtensionBackendDb(
52     Reference<XComponentContext> const &  xContext,
53     ::rtl::OUString const & url):BackendDb(xContext, url)
54 {
55 
56 }
57 
getDbNSName()58 OUString ExtensionBackendDb::getDbNSName()
59 {
60     return OUSTR(EXTENSION_REG_NS);
61 }
62 
getNSPrefix()63 OUString ExtensionBackendDb::getNSPrefix()
64 {
65     return OUSTR(NS_PREFIX);
66 }
67 
getRootElementName()68 OUString ExtensionBackendDb::getRootElementName()
69 {
70     return OUSTR(ROOT_ELEMENT_NAME);
71 }
72 
getKeyElementName()73 OUString ExtensionBackendDb::getKeyElementName()
74 {
75     return OUSTR(KEY_ELEMENT_NAME);
76 }
77 
addEntry(::rtl::OUString const & url,Data const & data)78 void ExtensionBackendDb::addEntry(::rtl::OUString const & url, Data const & data)
79 {
80     try{
81         //reactive revoked entry if possible.
82         if (!activateEntry(url))
83         {
84             Reference<css::xml::dom::XNode> extensionNodeNode = writeKeyElement(url);
85             writeVectorOfPair(
86                 data.items,
87                 OUSTR("extension-items"),
88                 OUSTR("item"),
89                 OUSTR("url"),
90                 OUSTR("media-type"),
91                 extensionNodeNode);
92             save();
93         }
94     }
95     catch(css::uno::Exception &)
96     {
97         Any exc( ::cppu::getCaughtException() );
98         throw css::deployment::DeploymentException(
99             OUSTR("Extension Manager: failed to write data entry in backend db: ") +
100             m_urlDb, 0, exc);
101     }
102 }
103 
getEntry(::rtl::OUString const & url)104 ExtensionBackendDb::Data ExtensionBackendDb::getEntry(::rtl::OUString const & url)
105 {
106     try
107     {
108         ExtensionBackendDb::Data retData;
109         Reference<css::xml::dom::XNode> aNode = getKeyElement(url);
110 
111         if (aNode.is())
112         {
113             retData.items =
114                 readVectorOfPair(
115                     aNode,
116                     OUSTR("extension-items"),
117                     OUSTR("item"),
118                     OUSTR("url"),
119                     OUSTR("media-type"));
120         }
121         return retData;
122     }
123     catch(css::uno::Exception &)
124     {
125         Any exc( ::cppu::getCaughtException() );
126         throw css::deployment::DeploymentException(
127             OUSTR("Extension Manager: failed to read data entry in backend db: ") +
128             m_urlDb, 0, exc);
129     }
130 }
131 
132 } // namespace bundle
133 } // namespace backend
134 } // namespace dp_registry
135 
136