1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include "storagetextstream.hxx"
23 #include <com/sun/star/io/XTextOutputStream.hpp>
24 #include <com/sun/star/io/XActiveDataSource.hpp>
26 #include <comphelper/componentcontext.hxx>
27 #include <tools/diagnose_ex.h>
29 //......................................................................................................................
32 //......................................................................................................................
34 /** === begin UNO using === **/
35 using ::com::sun::star::uno::Reference
;
36 using ::com::sun::star::uno::XInterface
;
37 using ::com::sun::star::uno::UNO_QUERY
;
38 using ::com::sun::star::uno::UNO_QUERY_THROW
;
39 using ::com::sun::star::uno::UNO_SET_THROW
;
40 using ::com::sun::star::uno::Exception
;
41 using ::com::sun::star::uno::RuntimeException
;
42 using ::com::sun::star::uno::Any
;
43 using ::com::sun::star::uno::makeAny
;
44 using ::com::sun::star::uno::Sequence
;
45 using ::com::sun::star::uno::Type
;
46 using ::com::sun::star::embed::XStorage
;
47 using ::com::sun::star::io::XTextOutputStream
;
48 using ::com::sun::star::io::XActiveDataSource
;
49 /** === end UNO using === **/
51 //==================================================================================================================
52 //= StorageTextOutputStream_Data
53 //==================================================================================================================
54 struct StorageTextOutputStream_Data
56 Reference
< XTextOutputStream
> xTextOutput
;
59 //==================================================================================================================
61 //==================================================================================================================
64 //--------------------------------------------------------------------------------------------------------------
65 static const ::rtl::OUString
& lcl_getTextStreamEncodingName()
67 static const ::rtl::OUString
s_sMapStreamEncodingName( RTL_CONSTASCII_USTRINGPARAM( "UTF-8" ) );
68 return s_sMapStreamEncodingName
;
71 //--------------------------------------------------------------------------------------------------------------
72 static const ::rtl::OUString
& lcl_getLineFeed()
74 static const ::rtl::OUString
s_sLineFeed( sal_Unicode( '\n' ) );
79 //==================================================================================================================
80 //= StorageTextOutputStream
81 //==================================================================================================================
82 //------------------------------------------------------------------------------------------------------------------
83 StorageTextOutputStream::StorageTextOutputStream( const ::comphelper::ComponentContext
& i_rContext
,
84 const Reference
< XStorage
>& i_rParentStorage
,
85 const ::rtl::OUString
& i_rStreamName
87 :StorageOutputStream( i_rContext
, i_rParentStorage
, i_rStreamName
)
88 ,m_pData( new StorageTextOutputStream_Data
)
90 m_pData
->xTextOutput
.set( i_rContext
.createComponent( "com.sun.star.io.TextOutputStream" ), UNO_QUERY_THROW
);
91 m_pData
->xTextOutput
->setEncoding( lcl_getTextStreamEncodingName() );
93 Reference
< XActiveDataSource
> xDataSource( m_pData
->xTextOutput
, UNO_QUERY_THROW
);
94 xDataSource
->setOutputStream( getOutputStream() );
97 //------------------------------------------------------------------------------------------------------------------
98 StorageTextOutputStream::~StorageTextOutputStream()
102 //------------------------------------------------------------------------------------------------------------------
103 void StorageTextOutputStream::writeLine( const ::rtl::OUString
& i_rLine
)
105 ENSURE_OR_RETURN_VOID( m_pData
->xTextOutput
.is(), "no text output" );
107 m_pData
->xTextOutput
->writeString( i_rLine
);
108 m_pData
->xTextOutput
->writeString( lcl_getLineFeed() );
111 //------------------------------------------------------------------------------------------------------------------
112 void StorageTextOutputStream::writeLine()
114 ENSURE_OR_RETURN_VOID( m_pData
->xTextOutput
.is(), "no text output" );
116 m_pData
->xTextOutput
->writeString( lcl_getLineFeed() );
119 //......................................................................................................................
120 } // namespace dbaccess
121 //......................................................................................................................
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */