1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cmdmailmsg.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_shell.hxx"
34 //------------------------------------------------------------------------
36 //------------------------------------------------------------------------
37 #include <osl/diagnose.h>
38 #include "cmdmailmsg.hxx"
39 #include <com/sun/star/uri/XExternalUriReferenceTranslator.hpp>
40 #include <com/sun/star/uri/ExternalUriReferenceTranslator.hpp>
41 #include <com/sun/star/uno/Reference.hxx>
42 #include <com/sun/star/uno/RuntimeException.hpp>
44 //------------------------------------------------------------------------
45 // namespace directives
46 //------------------------------------------------------------------------
48 using com::sun::star::lang::IllegalArgumentException
;
49 using com::sun::star::lang::WrappedTargetException
;
50 using com::sun::star::container::NoSuchElementException
;
51 using com::sun::star::container::XNameAccess
;
53 using osl::MutexGuard
;
56 using namespace com::sun::star::uno
;
59 //------------------------------------------------
61 //------------------------------------------------
63 void SAL_CALL
CmdMailMsg::setRecipient( const ::rtl::OUString
& aRecipient
)
64 throw (RuntimeException
)
66 MutexGuard
aGuard( m_aMutex
);
67 m_aRecipient
= aRecipient
;
70 //------------------------------------------------
72 //------------------------------------------------
74 ::rtl::OUString SAL_CALL
CmdMailMsg::getRecipient( )
75 throw (RuntimeException
)
77 MutexGuard
aGuard( m_aMutex
);
81 //------------------------------------------------
83 //------------------------------------------------
85 void SAL_CALL
CmdMailMsg::setCcRecipient( const Sequence
< OUString
>& aCcRecipient
)
86 throw (RuntimeException
)
88 MutexGuard
aGuard( m_aMutex
);
89 m_CcRecipients
= aCcRecipient
;
92 //------------------------------------------------
94 //------------------------------------------------
96 Sequence
< OUString
> SAL_CALL
CmdMailMsg::getCcRecipient( )
97 throw (RuntimeException
)
99 MutexGuard
aGuard( m_aMutex
);
100 return m_CcRecipients
;
103 //------------------------------------------------
105 //------------------------------------------------
107 void SAL_CALL
CmdMailMsg::setBccRecipient( const Sequence
< OUString
>& aBccRecipient
)
108 throw (RuntimeException
)
110 MutexGuard
aGuard( m_aMutex
);
111 m_BccRecipients
= aBccRecipient
;
114 //------------------------------------------------
116 //------------------------------------------------
118 Sequence
< OUString
> SAL_CALL
CmdMailMsg::getBccRecipient( )
119 throw (RuntimeException
)
121 MutexGuard
aGuard( m_aMutex
);
122 return m_BccRecipients
;
125 //------------------------------------------------
127 //------------------------------------------------
129 void SAL_CALL
CmdMailMsg::setOriginator( const OUString
& aOriginator
)
130 throw (RuntimeException
)
132 MutexGuard
aGuard( m_aMutex
);
133 m_aOriginator
= aOriginator
;
136 //------------------------------------------------
138 //------------------------------------------------
140 OUString SAL_CALL
CmdMailMsg::getOriginator( )
141 throw (RuntimeException
)
143 MutexGuard
aGuard( m_aMutex
);
144 return m_aOriginator
;
147 //------------------------------------------------
149 //------------------------------------------------
151 void SAL_CALL
CmdMailMsg::setSubject( const OUString
& aSubject
)
152 throw (RuntimeException
)
154 MutexGuard
aGuard( m_aMutex
);
155 m_aSubject
= aSubject
;
158 //------------------------------------------------
160 //------------------------------------------------
162 OUString SAL_CALL
CmdMailMsg::getSubject( )
163 throw (RuntimeException
)
165 MutexGuard
aGuard( m_aMutex
);
169 //------------------------------------------------
171 //------------------------------------------------
173 void SAL_CALL
CmdMailMsg::setAttachement( const Sequence
< ::rtl::OUString
>& aAttachment
)
174 throw (IllegalArgumentException
, RuntimeException
)
176 MutexGuard
aGuard( m_aMutex
);
177 m_Attachments
= aAttachment
;
180 //------------------------------------------------
182 //------------------------------------------------
184 Sequence
< OUString
> SAL_CALL
CmdMailMsg::getAttachement( )
185 throw (RuntimeException
)
187 MutexGuard
aGuard( m_aMutex
);
188 return m_Attachments
;
191 //------------------------------------------------
193 //------------------------------------------------
195 Any SAL_CALL
CmdMailMsg::getByName( const OUString
& aName
)
196 throw (NoSuchElementException
, WrappedTargetException
, RuntimeException
)
198 MutexGuard
aGuard( m_aMutex
);
200 if( 0 == aName
.compareToAscii( "from" ) && m_aOriginator
.getLength() )
201 return makeAny( m_aOriginator
);
203 else if( 0 == aName
.compareToAscii( "to" ) && m_aRecipient
.getLength() )
204 return makeAny( m_aRecipient
);
206 else if( 0 == aName
.compareToAscii( "cc" ) && m_CcRecipients
.getLength() )
207 return makeAny( m_CcRecipients
);
209 else if( 0 == aName
.compareToAscii( "bcc" ) && m_BccRecipients
.getLength() )
210 return makeAny( m_BccRecipients
);
212 else if( 0 == aName
.compareToAscii( "subject" ) && m_aSubject
.getLength() )
213 return makeAny( m_aSubject
);
215 else if( 0 == aName
.compareToAscii( "attachment" ) && m_Attachments
.getLength() )
216 return makeAny( m_Attachments
);
218 throw NoSuchElementException( OUString::createFromAscii( "key not found: ") + aName
,
219 static_cast < XNameAccess
* > (this) );
222 //------------------------------------------------
224 //------------------------------------------------
226 Sequence
< OUString
> SAL_CALL
CmdMailMsg::getElementNames( )
227 throw (::com::sun::star::uno::RuntimeException
)
229 MutexGuard
aGuard( m_aMutex
);
231 sal_Int32 nItems
= 0;
232 Sequence
< OUString
> aRet( 6 );
234 if( m_aOriginator
.getLength() )
235 aRet
[nItems
++] = OUString::createFromAscii( "from" );
237 if( m_aRecipient
.getLength() )
238 aRet
[nItems
++] = OUString::createFromAscii( "to" );
240 if( m_CcRecipients
.getLength() )
241 aRet
[nItems
++] = OUString::createFromAscii( "cc" );
243 if( m_BccRecipients
.getLength() )
244 aRet
[nItems
++] = OUString::createFromAscii( "bcc" );
246 if( m_aSubject
.getLength() )
247 aRet
[nItems
++] = OUString::createFromAscii( "subject" );
249 if( m_Attachments
.getLength() )
250 aRet
[nItems
++] = OUString::createFromAscii( "attachment" );
252 aRet
.realloc( nItems
);
256 //------------------------------------------------
258 //------------------------------------------------
260 sal_Bool SAL_CALL
CmdMailMsg::hasByName( const ::rtl::OUString
& aName
)
261 throw (RuntimeException
)
263 MutexGuard
aGuard( m_aMutex
);
265 if( 0 == aName
.compareToAscii( "from" ) && m_aOriginator
.getLength() )
268 else if( 0 == aName
.compareToAscii( "to" ) && m_aRecipient
.getLength() )
271 else if( 0 == aName
.compareToAscii( "cc" ) && m_CcRecipients
.getLength() )
274 else if( 0 == aName
.compareToAscii( "bcc" ) && m_BccRecipients
.getLength() )
277 else if( 0 == aName
.compareToAscii( "subject" ) && m_aSubject
.getLength() )
280 else if( 0 == aName
.compareToAscii( "attachment" ) && m_Attachments
.getLength() )
286 //------------------------------------------------
288 //------------------------------------------------
290 Type SAL_CALL
CmdMailMsg::getElementType( )
291 throw (RuntimeException
)
293 // returning void for multi type container
297 //------------------------------------------------
299 //------------------------------------------------
301 sal_Bool SAL_CALL
CmdMailMsg::hasElements( )
302 throw (RuntimeException
)
304 return 0 != getElementNames().getLength();