merge the formfield patch from ooo-build
[ooovba.git] / desktop / source / deployment / registry / package / dp_description.cxx
blob48a8633f98c821ef2a3514070784c70514976285
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dp_description.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_desktop.hxx"
34 #include "dp_description.hxx"
36 #include "cppuhelper/exc_hlp.hxx"
37 #include "ucbhelper/content.hxx"
38 #include "com/sun/star/deployment/DeploymentException.hpp"
39 #include "com/sun/star/xml/dom/XDocumentBuilder.hpp"
40 #include "com/sun/star/uno/XComponentContext.hpp"
41 #include "com/sun/star/ucb/CommandFailedException.hpp"
42 #include "com/sun/star/ucb/InteractiveAugmentedIOException.hpp"
43 #include "com/sun/star/ucb/IOErrorCode.hpp"
45 #include "com/sun/star/beans/PropertyValue.hpp"
48 #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
50 namespace css = com::sun::star;
51 namespace cssu = com::sun::star::uno;
53 namespace dp_registry {
54 namespace backend {
55 namespace bundle {
57 ExtensionDescription::ExtensionDescription(
58 const cssu::Reference<cssu::XComponentContext>& xContext,
59 const ::rtl::OUString& installDir,
60 const cssu::Reference< css::ucb::XCommandEnvironment >& xCmdEnv)
62 try {
63 m_sExtensionRootUrl = installDir;
64 //may throw ::com::sun::star::ucb::ContentCreationException
65 //If there is no description.xml then ucb will start an interaction which
66 //brings up a dialog.We want to prevent this. Therefore we wrap the xCmdEnv
67 //and filter the respective exception out.
68 ::rtl::OUString sDescriptionUri(installDir + OUSTR("/description.xml"));
69 cssu::Reference<css::ucb::XCommandEnvironment> xFilter =
70 static_cast<css::ucb::XCommandEnvironment*>(
71 new FileDoesNotExistFilter(xCmdEnv));
72 ::ucbhelper::Content descContent(sDescriptionUri, xFilter);
74 //throws an com::sun::star::uno::Exception if the file is not available
75 cssu::Reference<css::io::XInputStream> xIn;
76 try
77 { //throws com.sun.star.ucb.InteractiveAugmentedIOException
78 xIn = descContent.openStream();
80 catch (cssu::Exception& )
82 if ( ! static_cast<FileDoesNotExistFilter*>(xFilter.get())->exist())
83 throw NoDescriptionException();
84 throw;
86 if (!xIn.is())
88 throw cssu::Exception(
89 OUSTR("Could not get XInputStream for description.xml of extension ") +
90 sDescriptionUri, 0);
93 //get root node of description.xml
94 cssu::Reference<css::xml::dom::XDocumentBuilder> xDocBuilder(
95 xContext->getServiceManager()->createInstanceWithContext(
96 OUSTR("com.sun.star.xml.dom.DocumentBuilder"),
97 xContext ), cssu::UNO_QUERY);
98 if (!xDocBuilder.is())
99 throw css::uno::Exception(OUSTR(" Could not create service com.sun.star.xml.dom.DocumentBuilder"), 0);
101 if (xDocBuilder->isNamespaceAware() == sal_False)
103 throw cssu::Exception(
104 OUSTR("Service com.sun.star.xml.dom.DocumentBuilder is not namespace aware."), 0);
107 cssu::Reference<css::xml::dom::XDocument> xDoc = xDocBuilder->parse(xIn);
108 if (!xDoc.is())
110 throw cssu::Exception(sDescriptionUri + OUSTR(" contains data which cannot be parsed. "), 0);
113 //check for proper root element and namespace
114 cssu::Reference<css::xml::dom::XElement> xRoot = xDoc->getDocumentElement();
115 if (!xRoot.is())
117 throw cssu::Exception(
118 sDescriptionUri + OUSTR(" contains no root element."), 0);
121 if ( ! xRoot->getTagName().equals(OUSTR("description")))
123 throw cssu::Exception(
124 sDescriptionUri + OUSTR(" does not contain the root element <description>."), 0);
127 m_xRoot = cssu::Reference<css::xml::dom::XNode>(
128 xRoot, cssu::UNO_QUERY_THROW);
129 ::rtl::OUString nsDescription = xRoot->getNamespaceURI();
131 //check if this namespace is supported
132 if ( ! nsDescription.equals(OUSTR("http://openoffice.org/extensions/description/2006")))
134 throw cssu::Exception(sDescriptionUri + OUSTR(" contains a root element with an unsupported namespace. "), 0);
136 } catch (css::uno::RuntimeException &) {
137 throw;
138 } catch (css::deployment::DeploymentException &) {
139 throw;
140 } catch (css::uno::Exception & e) {
141 css::uno::Any a(cppu::getCaughtException());
142 throw css::deployment::DeploymentException(
143 e.Message, css::uno::Reference< css::uno::XInterface >(), a);
147 ExtensionDescription::~ExtensionDescription()
151 //======================================================================
152 FileDoesNotExistFilter::FileDoesNotExistFilter(
153 const css::uno::Reference< css::ucb::XCommandEnvironment >& xCmdEnv):
154 m_bExist(true), m_xCommandEnv(xCmdEnv)
157 FileDoesNotExistFilter::~FileDoesNotExistFilter()
161 bool FileDoesNotExistFilter::exist()
163 return m_bExist;
165 // XCommandEnvironment
166 cssu::Reference<css::task::XInteractionHandler >
167 FileDoesNotExistFilter::getInteractionHandler() throw (css::uno::RuntimeException)
169 return static_cast<css::task::XInteractionHandler*>(this);
172 cssu::Reference<css::ucb::XProgressHandler >
173 FileDoesNotExistFilter::getProgressHandler() throw (css::uno::RuntimeException)
175 return m_xCommandEnv.is()
176 ? m_xCommandEnv->getProgressHandler()
177 : cssu::Reference<css::ucb::XProgressHandler>();
180 // XInteractionHandler
181 //If the interaction was caused by a non-existing file which is specified in the ctor
182 //of FileDoesNotExistFilter, then we do nothing
183 void FileDoesNotExistFilter::handle(
184 cssu::Reference<css::task::XInteractionRequest > const & xRequest )
185 throw (css::uno::RuntimeException)
187 cssu::Any request( xRequest->getRequest() );
189 css::ucb::InteractiveAugmentedIOException ioexc;
190 if ((request>>= ioexc) && ioexc.Code == css::ucb::IOErrorCode_NOT_EXISTING )
192 m_bExist = false;
193 return;
195 css::uno::Reference<css::task::XInteractionHandler> xInteraction;
196 if (m_xCommandEnv.is()) {
197 xInteraction = m_xCommandEnv->getInteractionHandler();
199 if (xInteraction.is()) {
200 xInteraction->handle(xRequest);
205 } // namespace bundle
206 } // namespace backend
207 } // namespace dp_registry