1*96de5490SAndrew Rist /**************************************************************
2*96de5490SAndrew Rist  *
3*96de5490SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*96de5490SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*96de5490SAndrew Rist  * distributed with this work for additional information
6*96de5490SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*96de5490SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*96de5490SAndrew Rist  * "License"); you may not use this file except in compliance
9*96de5490SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*96de5490SAndrew Rist  *
11*96de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*96de5490SAndrew Rist  *
13*96de5490SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*96de5490SAndrew Rist  * software distributed under the License is distributed on an
15*96de5490SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*96de5490SAndrew Rist  * KIND, either express or implied.  See the License for the
17*96de5490SAndrew Rist  * specific language governing permissions and limitations
18*96de5490SAndrew Rist  * under the License.
19*96de5490SAndrew Rist  *
20*96de5490SAndrew Rist  *************************************************************/
21*96de5490SAndrew Rist 
22*96de5490SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "storagetextstream.hxx"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir /** === begin UNO includes === **/
29cdf0e10cSrcweir #include <com/sun/star/io/XTextOutputStream.hpp>
30cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSource.hpp>
31cdf0e10cSrcweir /** === end UNO includes === **/
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <comphelper/componentcontext.hxx>
34cdf0e10cSrcweir #include <tools/diagnose_ex.h>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir //......................................................................................................................
37cdf0e10cSrcweir namespace dbaccess
38cdf0e10cSrcweir {
39cdf0e10cSrcweir //......................................................................................................................
40cdf0e10cSrcweir 
41cdf0e10cSrcweir 	/** === begin UNO using === **/
42cdf0e10cSrcweir 	using ::com::sun::star::uno::Reference;
43cdf0e10cSrcweir 	using ::com::sun::star::uno::XInterface;
44cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_QUERY;
45cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_QUERY_THROW;
46cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_SET_THROW;
47cdf0e10cSrcweir 	using ::com::sun::star::uno::Exception;
48cdf0e10cSrcweir 	using ::com::sun::star::uno::RuntimeException;
49cdf0e10cSrcweir 	using ::com::sun::star::uno::Any;
50cdf0e10cSrcweir 	using ::com::sun::star::uno::makeAny;
51cdf0e10cSrcweir 	using ::com::sun::star::uno::Sequence;
52cdf0e10cSrcweir 	using ::com::sun::star::uno::Type;
53cdf0e10cSrcweir     using ::com::sun::star::embed::XStorage;
54cdf0e10cSrcweir     using ::com::sun::star::io::XTextOutputStream;
55cdf0e10cSrcweir     using ::com::sun::star::io::XActiveDataSource;
56cdf0e10cSrcweir 	/** === end UNO using === **/
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 	//==================================================================================================================
59cdf0e10cSrcweir 	//= StorageTextOutputStream_Data
60cdf0e10cSrcweir 	//==================================================================================================================
61cdf0e10cSrcweir     struct StorageTextOutputStream_Data
62cdf0e10cSrcweir     {
63cdf0e10cSrcweir         Reference< XTextOutputStream >  xTextOutput;
64cdf0e10cSrcweir     };
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 	//==================================================================================================================
67cdf0e10cSrcweir 	//= helper
68cdf0e10cSrcweir 	//==================================================================================================================
69cdf0e10cSrcweir     namespace
70cdf0e10cSrcweir     {
71cdf0e10cSrcweir 	    //--------------------------------------------------------------------------------------------------------------
lcl_getTextStreamEncodingName()72cdf0e10cSrcweir         static const ::rtl::OUString& lcl_getTextStreamEncodingName()
73cdf0e10cSrcweir         {
74cdf0e10cSrcweir             static const ::rtl::OUString s_sMapStreamEncodingName( RTL_CONSTASCII_USTRINGPARAM( "UTF-8" ) );
75cdf0e10cSrcweir             return s_sMapStreamEncodingName;
76cdf0e10cSrcweir         }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir         //--------------------------------------------------------------------------------------------------------------
lcl_getLineFeed()79cdf0e10cSrcweir         static const ::rtl::OUString& lcl_getLineFeed()
80cdf0e10cSrcweir         {
81cdf0e10cSrcweir             static const ::rtl::OUString s_sLineFeed( sal_Unicode( '\n' ) );
82cdf0e10cSrcweir             return s_sLineFeed;
83cdf0e10cSrcweir         }
84cdf0e10cSrcweir     }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 	//==================================================================================================================
87cdf0e10cSrcweir 	//= StorageTextOutputStream
88cdf0e10cSrcweir 	//==================================================================================================================
89cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
StorageTextOutputStream(const::comphelper::ComponentContext & i_rContext,const Reference<XStorage> & i_rParentStorage,const::rtl::OUString & i_rStreamName)90cdf0e10cSrcweir     StorageTextOutputStream::StorageTextOutputStream(   const ::comphelper::ComponentContext& i_rContext,
91cdf0e10cSrcweir                                                         const Reference< XStorage >& i_rParentStorage,
92cdf0e10cSrcweir                                                         const ::rtl::OUString& i_rStreamName
93cdf0e10cSrcweir                                                     )
94cdf0e10cSrcweir         :StorageOutputStream( i_rContext, i_rParentStorage, i_rStreamName )
95cdf0e10cSrcweir         ,m_pData( new StorageTextOutputStream_Data )
96cdf0e10cSrcweir     {
97cdf0e10cSrcweir         m_pData->xTextOutput.set( i_rContext.createComponent( "com.sun.star.io.TextOutputStream" ), UNO_QUERY_THROW );
98cdf0e10cSrcweir         m_pData->xTextOutput->setEncoding( lcl_getTextStreamEncodingName() );
99cdf0e10cSrcweir 
100cdf0e10cSrcweir         Reference< XActiveDataSource > xDataSource( m_pData->xTextOutput, UNO_QUERY_THROW );
101cdf0e10cSrcweir         xDataSource->setOutputStream( getOutputStream() );
102cdf0e10cSrcweir     }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
~StorageTextOutputStream()105cdf0e10cSrcweir     StorageTextOutputStream::~StorageTextOutputStream()
106cdf0e10cSrcweir     {
107cdf0e10cSrcweir     }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
writeLine(const::rtl::OUString & i_rLine)110cdf0e10cSrcweir     void StorageTextOutputStream::writeLine( const ::rtl::OUString& i_rLine )
111cdf0e10cSrcweir     {
112cdf0e10cSrcweir         ENSURE_OR_RETURN_VOID( m_pData->xTextOutput.is(), "no text output" );
113cdf0e10cSrcweir 
114cdf0e10cSrcweir         m_pData->xTextOutput->writeString( i_rLine );
115cdf0e10cSrcweir         m_pData->xTextOutput->writeString( lcl_getLineFeed() );
116cdf0e10cSrcweir     }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
writeLine()119cdf0e10cSrcweir     void StorageTextOutputStream::writeLine()
120cdf0e10cSrcweir     {
121cdf0e10cSrcweir         ENSURE_OR_RETURN_VOID( m_pData->xTextOutput.is(), "no text output" );
122cdf0e10cSrcweir 
123cdf0e10cSrcweir         m_pData->xTextOutput->writeString( lcl_getLineFeed() );
124cdf0e10cSrcweir     }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir //......................................................................................................................
127cdf0e10cSrcweir } // namespace dbaccess
128cdf0e10cSrcweir //......................................................................................................................
129