Update git submodules
[LibreOffice.git] / dbaccess / source / core / recovery / storagexmlstream.cxx
blobe828ac73d38d1026db16e24a9baddb4a58d304a6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "storagexmlstream.hxx"
22 #include <com/sun/star/embed/ElementModes.hpp>
23 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
24 #include <com/sun/star/xml/sax/Parser.hpp>
25 #include <com/sun/star/xml/sax/Writer.hpp>
27 #include <rtl/ref.hxx>
28 #include <comphelper/diagnose_ex.hxx>
30 namespace dbaccess
33 using ::com::sun::star::uno::Reference;
34 using ::com::sun::star::uno::UNO_QUERY_THROW;
35 using ::com::sun::star::uno::XComponentContext;
36 using ::com::sun::star::embed::XStorage;
37 using ::com::sun::star::xml::sax::XDocumentHandler;
38 using ::com::sun::star::xml::sax::XWriter;
39 using ::com::sun::star::xml::sax::Writer;
40 using ::com::sun::star::xml::sax::Parser;
41 using ::com::sun::star::xml::sax::InputSource;
43 // StorageXMLOutputStream
44 StorageXMLOutputStream::StorageXMLOutputStream( const Reference<XComponentContext>& i_rContext,
45 const Reference< XStorage >& i_rParentStorage,
46 const OUString& i_rStreamName )
47 :StorageOutputStream( i_rParentStorage, i_rStreamName )
49 const Reference< XWriter > xSaxWriter = Writer::create( i_rContext );
50 xSaxWriter->setOutputStream( getOutputStream() );
52 mxHandler.set( xSaxWriter, UNO_QUERY_THROW );
53 mxHandler->startDocument();
55 mxAttributes = new comphelper::AttributeList;
58 StorageXMLOutputStream::~StorageXMLOutputStream()
62 void StorageXMLOutputStream::close()
64 ENSURE_OR_RETURN_VOID( mxHandler.is(), "illegal document handler" );
65 mxHandler->endDocument();
66 // do not call the base class, it would call closeOutput on the output stream, which is already done by
67 // endDocument
70 void StorageXMLOutputStream::addAttribute( const OUString& i_rName, const OUString& i_rValue ) const
72 mxAttributes->AddAttribute( i_rName, i_rValue );
75 void StorageXMLOutputStream::startElement( const OUString& i_rElementName )
77 ENSURE_OR_RETURN_VOID( mxHandler.is(), "no document handler" );
79 mxHandler->startElement( i_rElementName, mxAttributes );
80 mxAttributes = new comphelper::AttributeList;
81 maElements.push( i_rElementName );
84 void StorageXMLOutputStream::endElement()
86 ENSURE_OR_RETURN_VOID( mxHandler.is(), "no document handler" );
87 ENSURE_OR_RETURN_VOID( !maElements.empty(), "no element on the stack" );
89 const OUString sElementName( maElements.top() );
90 mxHandler->endElement( sElementName );
91 maElements.pop();
94 void StorageXMLOutputStream::ignorableWhitespace( const OUString& i_rWhitespace ) const
96 ENSURE_OR_RETURN_VOID( mxHandler.is(), "no document handler" );
98 mxHandler->ignorableWhitespace( i_rWhitespace );
101 void StorageXMLOutputStream::characters( const OUString& i_rCharacters ) const
103 ENSURE_OR_RETURN_VOID( mxHandler.is(), "no document handler" );
105 mxHandler->characters( i_rCharacters );
108 // StorageXMLInputStream
109 StorageXMLInputStream::StorageXMLInputStream( const Reference<XComponentContext>& i_rContext,
110 const Reference< XStorage >& i_rParentStorage,
111 const OUString& i_rStreamName )
113 ENSURE_OR_THROW( i_rParentStorage.is(), "illegal stream" );
115 const Reference< css::io::XStream > xStream(
116 i_rParentStorage->openStreamElement( i_rStreamName, css::embed::ElementModes::READ ), css::uno::UNO_SET_THROW );
117 m_xInputStream.set( xStream->getInputStream(), css::uno::UNO_SET_THROW );
119 m_xParser.set( Parser::create(i_rContext) );
122 void StorageXMLInputStream::import( const Reference< XDocumentHandler >& i_rHandler )
124 ENSURE_OR_THROW( i_rHandler.is(), "illegal document handler (NULL)" );
126 InputSource aInputSource;
127 aInputSource.aInputStream = m_xInputStream;
129 m_xParser->setDocumentHandler( i_rHandler );
130 m_xParser->parseStream( aInputSource );
133 StorageXMLInputStream::~StorageXMLInputStream()
137 } // namespace dbaccess
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */