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 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_desktop.hxx"
30 
31 #include "rtl/string.h"
32 #include "rtl/bootstrap.hxx"
33 #include "cppuhelper/exc_hlp.hxx"
34 #include "com/sun/star/uno/XComponentContext.hpp"
35 #include "com/sun/star/xml/dom/XDocumentBuilder.hpp"
36 #include "com/sun/star/xml/xpath/XXPathAPI.hpp"
37 #include "dp_misc.h"
38 
39 #include "dp_extbackenddb.hxx"
40 
41 
42 namespace css = ::com::sun::star;
43 using namespace ::com::sun::star::uno;
44 using ::rtl::OUString;
45 
46 #define EXTENSION_REG_NS "http://openoffice.org/extensionmanager/extension-registry/2010"
47 #define NS_PREFIX "ext"
48 #define ROOT_ELEMENT_NAME "extension-backend-db"
49 #define KEY_ELEMENT_NAME "extension"
50 
51 namespace dp_registry {
52 namespace backend {
53 namespace bundle {
54 
55 ExtensionBackendDb::ExtensionBackendDb(
56     Reference<XComponentContext> const &  xContext,
57     ::rtl::OUString const & url):BackendDb(xContext, url)
58 {
59 
60 }
61 
62 OUString ExtensionBackendDb::getDbNSName()
63 {
64     return OUSTR(EXTENSION_REG_NS);
65 }
66 
67 OUString ExtensionBackendDb::getNSPrefix()
68 {
69     return OUSTR(NS_PREFIX);
70 }
71 
72 OUString ExtensionBackendDb::getRootElementName()
73 {
74     return OUSTR(ROOT_ELEMENT_NAME);
75 }
76 
77 OUString ExtensionBackendDb::getKeyElementName()
78 {
79     return OUSTR(KEY_ELEMENT_NAME);
80 }
81 
82 void ExtensionBackendDb::addEntry(::rtl::OUString const & url, Data const & data)
83 {
84     try{
85         //reactive revoked entry if possible.
86         if (!activateEntry(url))
87         {
88             Reference<css::xml::dom::XNode> extensionNodeNode = writeKeyElement(url);
89             writeVectorOfPair(
90                 data.items,
91                 OUSTR("extension-items"),
92                 OUSTR("item"),
93                 OUSTR("url"),
94                 OUSTR("media-type"),
95                 extensionNodeNode);
96             save();
97         }
98     }
99     catch(css::uno::Exception &)
100     {
101         Any exc( ::cppu::getCaughtException() );
102         throw css::deployment::DeploymentException(
103             OUSTR("Extension Manager: failed to write data entry in backend db: ") +
104             m_urlDb, 0, exc);
105     }
106 }
107 
108 ExtensionBackendDb::Data ExtensionBackendDb::getEntry(::rtl::OUString const & url)
109 {
110     try
111     {
112         ExtensionBackendDb::Data retData;
113         Reference<css::xml::dom::XNode> aNode = getKeyElement(url);
114 
115         if (aNode.is())
116         {
117             retData.items =
118                 readVectorOfPair(
119                     aNode,
120                     OUSTR("extension-items"),
121                     OUSTR("item"),
122                     OUSTR("url"),
123                     OUSTR("media-type"));
124         }
125         return retData;
126     }
127     catch(css::uno::Exception &)
128     {
129         Any exc( ::cppu::getCaughtException() );
130         throw css::deployment::DeploymentException(
131             OUSTR("Extension Manager: failed to read data entry in backend db: ") +
132             m_urlDb, 0, exc);
133     }
134 }
135 
136 } // namespace bundle
137 } // namespace backend
138 } // namespace dp_registry
139 
140