xref: /AOO41X/main/dbaccess/source/core/recovery/storagetextstream.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3 *
4 * Copyright 2009 by Sun Microsystems, Inc.
5 *
6 * OpenOffice.org - a multi-platform office productivity suite
7 *
8 * This file is part of OpenOffice.org.
9 *
10 * OpenOffice.org is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License version 3
12 * only, as published by the Free Software Foundation.
13 *
14 * OpenOffice.org is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU Lesser General Public License version 3 for more details
18 * (a copy is included in the LICENSE file that accompanied this code).
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * version 3 along with OpenOffice.org.  If not, see
22 * <http://www.openoffice.org/license.html>
23 * for a copy of the LGPLv3 License.
24 ************************************************************************/
25 
26 #include "precompiled_dbaccess.hxx"
27 
28 #include "storagetextstream.hxx"
29 
30 /** === begin UNO includes === **/
31 #include <com/sun/star/io/XTextOutputStream.hpp>
32 #include <com/sun/star/io/XActiveDataSource.hpp>
33 /** === end UNO includes === **/
34 
35 #include <comphelper/componentcontext.hxx>
36 #include <tools/diagnose_ex.h>
37 
38 //......................................................................................................................
39 namespace dbaccess
40 {
41 //......................................................................................................................
42 
43 	/** === begin UNO using === **/
44 	using ::com::sun::star::uno::Reference;
45 	using ::com::sun::star::uno::XInterface;
46 	using ::com::sun::star::uno::UNO_QUERY;
47 	using ::com::sun::star::uno::UNO_QUERY_THROW;
48 	using ::com::sun::star::uno::UNO_SET_THROW;
49 	using ::com::sun::star::uno::Exception;
50 	using ::com::sun::star::uno::RuntimeException;
51 	using ::com::sun::star::uno::Any;
52 	using ::com::sun::star::uno::makeAny;
53 	using ::com::sun::star::uno::Sequence;
54 	using ::com::sun::star::uno::Type;
55     using ::com::sun::star::embed::XStorage;
56     using ::com::sun::star::io::XTextOutputStream;
57     using ::com::sun::star::io::XActiveDataSource;
58 	/** === end UNO using === **/
59 
60 	//==================================================================================================================
61 	//= StorageTextOutputStream_Data
62 	//==================================================================================================================
63     struct StorageTextOutputStream_Data
64     {
65         Reference< XTextOutputStream >  xTextOutput;
66     };
67 
68 	//==================================================================================================================
69 	//= helper
70 	//==================================================================================================================
71     namespace
72     {
73 	    //--------------------------------------------------------------------------------------------------------------
74         static const ::rtl::OUString& lcl_getTextStreamEncodingName()
75         {
76             static const ::rtl::OUString s_sMapStreamEncodingName( RTL_CONSTASCII_USTRINGPARAM( "UTF-8" ) );
77             return s_sMapStreamEncodingName;
78         }
79 
80         //--------------------------------------------------------------------------------------------------------------
81         static const ::rtl::OUString& lcl_getLineFeed()
82         {
83             static const ::rtl::OUString s_sLineFeed( sal_Unicode( '\n' ) );
84             return s_sLineFeed;
85         }
86     }
87 
88 	//==================================================================================================================
89 	//= StorageTextOutputStream
90 	//==================================================================================================================
91 	//------------------------------------------------------------------------------------------------------------------
92     StorageTextOutputStream::StorageTextOutputStream(   const ::comphelper::ComponentContext& i_rContext,
93                                                         const Reference< XStorage >& i_rParentStorage,
94                                                         const ::rtl::OUString& i_rStreamName
95                                                     )
96         :StorageOutputStream( i_rContext, i_rParentStorage, i_rStreamName )
97         ,m_pData( new StorageTextOutputStream_Data )
98     {
99         m_pData->xTextOutput.set( i_rContext.createComponent( "com.sun.star.io.TextOutputStream" ), UNO_QUERY_THROW );
100         m_pData->xTextOutput->setEncoding( lcl_getTextStreamEncodingName() );
101 
102         Reference< XActiveDataSource > xDataSource( m_pData->xTextOutput, UNO_QUERY_THROW );
103         xDataSource->setOutputStream( getOutputStream() );
104     }
105 
106     //------------------------------------------------------------------------------------------------------------------
107     StorageTextOutputStream::~StorageTextOutputStream()
108     {
109     }
110 
111     //------------------------------------------------------------------------------------------------------------------
112     void StorageTextOutputStream::writeLine( const ::rtl::OUString& i_rLine )
113     {
114         ENSURE_OR_RETURN_VOID( m_pData->xTextOutput.is(), "no text output" );
115 
116         m_pData->xTextOutput->writeString( i_rLine );
117         m_pData->xTextOutput->writeString( lcl_getLineFeed() );
118     }
119 
120     //------------------------------------------------------------------------------------------------------------------
121     void StorageTextOutputStream::writeLine()
122     {
123         ENSURE_OR_RETURN_VOID( m_pData->xTextOutput.is(), "no text output" );
124 
125         m_pData->xTextOutput->writeString( lcl_getLineFeed() );
126     }
127 
128 //......................................................................................................................
129 } // namespace dbaccess
130 //......................................................................................................................
131