24#include <com/sun/star/frame/XModel.hpp>
25#include <com/sun/star/uri/UriReferenceFactory.hpp>
26#include <com/sun/star/util/MeasureUnit.hpp>
27#include <com/sun/star/util/XNumberFormatsSupplier.hpp>
28#include <com/sun/star/packages/WrongPasswordException.hpp>
29#include <com/sun/star/packages/zip/ZipIOException.hpp>
30#include <com/sun/star/embed/ElementModes.hpp>
31#include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
39#include <com/sun/star/xml/sax/InputSource.hpp>
40#include <com/sun/star/xml/sax/SAXParseException.hpp>
43#include <com/sun/star/io/XInputStream.hpp>
51#include <com/sun/star/util/XModifiable.hpp>
52#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
55#include <osl/diagnose.h>
65extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
67 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const&)
69 return cppu::acquire(new ::dbaxml::ODBFilter(context));
78 const uno::Reference<XInputStream>& xInputStream,
79 const uno::Reference<XComponent>& xModelComponent,
80 const uno::Reference<XComponentContext> & rxContext,
83 OSL_ENSURE(xInputStream.is(),
"input stream missing");
84 OSL_ENSURE(xModelComponent.is(),
"document missing");
85 OSL_ENSURE(rxContext.is(),
"factory missing");
88 InputSource aParserInput;
89 aParserInput.aInputStream = xInputStream;
92 _rFilter.setTargetDocument( xModelComponent );
97 _rFilter.parseStream( aParserInput );
99 catch (
const SAXParseException&)
101#if OSL_DEBUG_LEVEL > 0
106 catch (
const SAXException&)
110 catch (
const packages::zip::ZipIOException&)
126 const uno::Reference< embed::XStorage >& xStorage,
127 const uno::Reference<XComponent>& xModelComponent,
128 const char* pStreamName,
129 const uno::Reference<XComponentContext> & rxContext,
132 OSL_ENSURE( xStorage.is(),
"Need storage!");
133 OSL_ENSURE(
nullptr != pStreamName,
"Please, please, give me a name!");
139 uno::Reference< io::XStream > xDocStream;
144 OUString sStreamName = OUString::createFromAscii(pStreamName);
145 if ( !xStorage->hasByName( sStreamName ) || !xStorage->isStreamElement( sStreamName ) )
152 xDocStream = xStorage->openStreamElement( sStreamName, embed::ElementModes::READ );
154 catch (
const packages::WrongPasswordException&)
158 catch (
const uno::Exception&)
163 uno::Reference< XInputStream > xInputStream = xDocStream->getInputStream();
173 : SvXMLImport(_rxContext, getImplementationName_Static())
174 , m_bNewFormat(false)
177 GetMM100UnitConverter().SetCoreMeasureUnit(util::MeasureUnit::MM_10TH);
178 GetMM100UnitConverter().SetXMLMeasureUnit(util::MeasureUnit::CM);
179 GetNamespaceMap().Add(
"_db",
183 GetNamespaceMap().Add(
"__db",
197 return "com.sun.star.comp.sdb.DBFilter";
202class FocusWindowWaitGuard
205 FocusWindowWaitGuard()
212 ~FocusWindowWaitGuard()
227 FocusWindowWaitGuard aWindowFocusGuard;
230 if ( GetModel().is() )
242 uno::Reference<embed::XStorage> xStorage = GetSourceStorage();
247 if (aMediaDescriptor.
has(
"URL"))
248 sFileName = aMediaDescriptor.
getOrDefault(
"URL", OUString());
249 if (sFileName.isEmpty() && aMediaDescriptor.
has(
"FileName"))
250 sFileName = aMediaDescriptor.
getOrDefault(
"FileName", sFileName);
252 OSL_ENSURE(!sFileName.isEmpty(),
"ODBFilter::implImport: no URL given!");
253 bRet = !sFileName.isEmpty();
262 OUString sStreamRelPath;
263 if (sFileName.startsWithIgnoreAsciiCase(
"vnd.sun.star.pkg:"))
266 auto const uri = css::uri::UriReferenceFactory::create(GetComponentContext())
268 if (uri.is() && uri->isAbsolute()
269 && uri->hasAuthority() && !uri->hasQuery() && !uri->hasFragment())
271 auto const auth = uri->getAuthority();
272 auto const decAuth = rtl::Uri::decode(
273 auth, rtl_UriDecodeStrict, RTL_TEXTENCODING_UTF8);
274 auto path = uri->getPath();
275 if (!path.isEmpty()) {
276 assert(path[0] ==
'/');
279 auto const decPath = rtl::Uri::decode(
280 path, rtl_UriDecodeStrict, RTL_TEXTENCODING_UTF8);
282 if (auth.isEmpty() == decAuth.isEmpty() && path.isEmpty() == decPath.isEmpty())
286 sStreamRelPath = decPath;
290 "<" << sFileName <<
"> cannot be parse as vnd.sun.star.pkg URL");
295 "<" << sFileName <<
"> cannot be parse as vnd.sun.star.pkg URL");
299 pMedium =
new SfxMedium(sFileName, (StreamMode::READ | StreamMode::NOCREATE));
302 xStorage.set(pMedium->GetStorage(
false), UNO_SET_THROW);
304 if (!sStreamRelPath.isEmpty())
305 xStorage = xStorage->openStorageElement(sStreamRelPath, embed::ElementModes::READ);
313 Any aError = ::cppu::getCaughtException();
314 throw lang::WrappedTargetRuntimeException(OUString(), *
this, aError);
318 uno::Reference<sdb::XOfficeDatabaseDocument> xOfficeDoc(GetModel(),UNO_QUERY_THROW);
319 m_xDataSource.set(xOfficeDoc->getDataSource(),UNO_QUERY_THROW);
321 SetNumberFormatsSupplier(xNum);
323 uno::Reference<XComponent>
xModel(GetModel());
327 ,GetComponentContext()
335 ,GetComponentContext()
343 uno::Reference< XModifiable > xModi(GetModel(),UNO_QUERY);
345 xModi->setModified(
false);
369 DBXMLDocumentSettingsContext(SvXMLImport & rImport)
374 virtual uno::Reference< xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
375 sal_Int32 nElement,
const uno::Reference< xml::sax::XFastAttributeList >& )
override
388 DBXMLDocumentStylesContext(SvXMLImport & rImport)
393 virtual uno::Reference< xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
394 sal_Int32 nElement,
const uno::Reference< xml::sax::XFastAttributeList >& )
override
396 ODBFilter & rImport(
static_cast<ODBFilter&
>(GetImport()));
402 return rImport.CreateStylesContext(
false);
406 return rImport.CreateStylesContext(
true);
415 DBXMLDocumentBodyContext(SvXMLImport & rImport)
420 virtual uno::Reference< xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
421 sal_Int32 nElement,
const uno::Reference< xml::sax::XFastAttributeList >& )
override
423 ODBFilter & rImport(
static_cast<ODBFilter&
>(GetImport()));
429 return new OXMLDatabase(rImport);
439 DBXMLDocumentContentContext(SvXMLImport & rImport)
444 virtual uno::Reference< xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
445 sal_Int32 nElement,
const uno::Reference< xml::sax::XFastAttributeList >& )
override
447 ODBFilter & rImport(
static_cast<ODBFilter&
>(GetImport()));
452 return new DBXMLDocumentBodyContext(rImport);
458 return rImport.CreateStylesContext(
true);
468 const ::css::uno::Reference< ::css::xml::sax::XFastAttributeList >& )
477 pContext =
new DBXMLDocumentSettingsContext(*
this);
481 pContext =
new DBXMLDocumentStylesContext(*
this);
485 pContext =
new DBXMLDocumentContentContext(*
this);
495 const PropertyValue *pIter = aViewProps.getConstArray();
496 const PropertyValue *pEnd = pIter + aViewProps.getLength();
497 for (; pIter != pEnd; ++pIter)
499 if ( pIter->Name ==
"Queries" )
503 else if ( pIter->Name ==
"Tables" )
513 const PropertyValue *pIter = aConfigProps.getConstArray();
514 const PropertyValue *pEnd = pIter + aConfigProps.getLength();
515 for (; pIter != pEnd; ++pIter)
517 if ( pIter->Name ==
"layout-settings" )
519 Sequence<PropertyValue> aWindows;
520 pIter->Value >>= aWindows;
531 Sequence<PropertyValue> aWindows;
532 _rValue >>= aWindows;
533 const PropertyValue *pIter = aWindows.getConstArray();
534 const PropertyValue *pEnd = pIter + aWindows.getLength();
535 for (; pIter != pEnd; ++pIter)
537 Sequence<PropertyValue> aValue;
538 pIter->Value >>= aValue;
539 _rMap.emplace( pIter->Name,aValue );
589 if ( !xDataSource.is() )
593 const OUString sURL = ::comphelper::getString(xDataSource->getPropertyValue(
PROPERTY_URL));
596 Sequence<PropertyValue> aInfo;
601 aDataSourceSettings >>= aInfo;
602 if ( aInfo.hasElements() )
static vcl::Window * GetFocusWindow()
static DialogMask HandleError(ErrCode nId, weld::Window *pParent=nullptr, DialogMask nMask=DialogMask::MAX)
void set(reference_type *pBody)
bool has(const OUString &_rValueName) const
NamedValueCollection & merge(const NamedValueCollection &_rAdditionalValues, bool _bOverwriteExisting)
VALUE_TYPE getOrDefault(const OUString &_rValueName, const VALUE_TYPE &_rDefault) const
const ::comphelper::NamedValueCollection & getProperties(std::u16string_view _sURL) const
virtual void SetConfigurationSettings(const css::uno::Sequence< css::beans::PropertyValue > &aConfigProps) override
Reference< XPropertySet > m_xDataSource
virtual SvXMLImportContext * CreateFastContext(sal_Int32 Element, const ::css::uno::Reference< ::css::xml::sax::XFastAttributeList > &xAttrList) override
virtual sal_Bool SAL_CALL filter(const Sequence< PropertyValue > &rDescriptor) override
rtl::Reference< XMLPropertySetMapper > const & GetColumnStylesPropertySetMapper() const
TPropertyNameMap m_aTablesSettings
bool implImport(const Sequence< PropertyValue > &rDescriptor)
rtl::Reference< XMLPropertySetMapper > m_xTableStylesPropertySetMapper
rtl::Reference< XMLPropertySetMapper > const & GetCellStylesPropertySetMapper() const
virtual void SetViewSettings(const css::uno::Sequence< css::beans::PropertyValue > &aViewProps) override
static void fillPropertyMap(const Any &_rValue, TPropertyNameMap &_rMap)
fills the map with the Properties
rtl::Reference< XMLPropertySetMapper > m_xCellStylesPropertySetMapper
std::vector< css::beans::PropertyValue > m_aInfoSequence
SvXMLImportContext * CreateStylesContext(bool bIsAutoStyle)
static OUString getImplementationName_Static()
TPropertyNameMap m_aQuerySettings
rtl::Reference< XMLPropertySetMapper > const & GetTableStylesPropertySetMapper() const
ODBFilter(const Reference< XComponentContext > &_rxContext)
rtl::Reference< XMLPropertySetMapper > m_xColumnStylesPropertySetMapper
std::map< OUString, Sequence< PropertyValue > > TPropertyNameMap
const Reference< XPropertySet > & getDataSource() const
virtual ~ODBFilter() noexcept override
static rtl::Reference< XMLPropertySetMapper > GetCellStylesPropertySetMapper(bool bForExport)
static rtl::Reference< XMLPropertySetMapper > GetColumnStylesPropertySetMapper(bool bForExport)
static rtl::Reference< XMLPropertySetMapper > GetTableStylesPropertySetMapper(bool bForExport)
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
#define ERRCODE_IO_BROKENPACKAGE
#define SAL_WARN(area, stream)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
static ErrCode ReadThroughComponent(const uno::Reference< XInputStream > &xInputStream, const uno::Reference< XComponent > &xModelComponent, const uno::Reference< XComponentContext > &rxContext, ODBFilter &_rFilter)
read a component (file + filter version)
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
#define ERRCODE_SFX_WRONGPASSWORD
constexpr OUStringLiteral PROPERTY_URL(u"URL")
constexpr OUStringLiteral PROPERTY_INFO(u"Info")
constexpr OUStringLiteral PROPERTY_NUMBERFORMATSSUPPLIER(u"NumberFormatsSupplier")
constexpr OUStringLiteral PROPERTY_LAYOUTINFORMATION(u"LayoutInformation")
Reference< XModel > xModel
the model of the sub component. Might be <NULL>
#define PROGRESS_BAR_STEP
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_sdb_DBFilter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
VclPtr< vcl::Window > mpWindow
#define XML_ELEMENT(prefix, name)
constexpr sal_uInt16 XML_NAMESPACE_DB