1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_shell.hxx" 26 27 #include "cmdmailmsg.hxx" 28 29 using com::sun::star::lang::IllegalArgumentException; 30 using com::sun::star::lang::WrappedTargetException; 31 using com::sun::star::container::NoSuchElementException; 32 using com::sun::star::container::XNameAccess; 33 using rtl::OUString; 34 using osl::MutexGuard; 35 36 using namespace cppu; 37 using namespace com::sun::star::uno; 38 39 40 void SAL_CALL CmdMailMsg::setBody( const OUString& aBody ) 41 throw (RuntimeException) 42 { 43 MutexGuard aGuard( m_aMutex ); 44 m_aBody = aBody; 45 } 46 47 OUString SAL_CALL CmdMailMsg::getBody( ) 48 throw (RuntimeException) 49 { 50 MutexGuard aGuard( m_aMutex ); 51 return m_aBody; 52 } 53 54 void SAL_CALL CmdMailMsg::setRecipient( const OUString& aRecipient ) 55 throw (RuntimeException) 56 { 57 MutexGuard aGuard( m_aMutex ); 58 m_aRecipient = aRecipient; 59 } 60 61 OUString SAL_CALL CmdMailMsg::getRecipient( ) 62 throw (RuntimeException) 63 { 64 MutexGuard aGuard( m_aMutex ); 65 return m_aRecipient; 66 } 67 68 void SAL_CALL CmdMailMsg::setCcRecipient( const Sequence< OUString >& aCcRecipient ) 69 throw (RuntimeException) 70 { 71 MutexGuard aGuard( m_aMutex ); 72 m_CcRecipients = aCcRecipient; 73 } 74 75 Sequence< OUString > SAL_CALL CmdMailMsg::getCcRecipient( ) 76 throw (RuntimeException) 77 { 78 MutexGuard aGuard( m_aMutex ); 79 return m_CcRecipients; 80 } 81 82 void SAL_CALL CmdMailMsg::setBccRecipient( const Sequence< OUString >& aBccRecipient ) 83 throw (RuntimeException) 84 { 85 MutexGuard aGuard( m_aMutex ); 86 m_BccRecipients = aBccRecipient; 87 } 88 89 Sequence< OUString > SAL_CALL CmdMailMsg::getBccRecipient( ) 90 throw (RuntimeException) 91 { 92 MutexGuard aGuard( m_aMutex ); 93 return m_BccRecipients; 94 } 95 96 void SAL_CALL CmdMailMsg::setOriginator( const OUString& aOriginator ) 97 throw (RuntimeException) 98 { 99 MutexGuard aGuard( m_aMutex ); 100 m_aOriginator = aOriginator; 101 } 102 103 OUString SAL_CALL CmdMailMsg::getOriginator( ) 104 throw (RuntimeException) 105 { 106 MutexGuard aGuard( m_aMutex ); 107 return m_aOriginator; 108 } 109 110 void SAL_CALL CmdMailMsg::setSubject( const OUString& aSubject ) 111 throw (RuntimeException) 112 { 113 MutexGuard aGuard( m_aMutex ); 114 m_aSubject = aSubject; 115 } 116 117 OUString SAL_CALL CmdMailMsg::getSubject( ) 118 throw (RuntimeException) 119 { 120 MutexGuard aGuard( m_aMutex ); 121 return m_aSubject; 122 } 123 124 void SAL_CALL CmdMailMsg::setAttachement( const Sequence< OUString >& aAttachment ) 125 throw (IllegalArgumentException, RuntimeException) 126 { 127 MutexGuard aGuard( m_aMutex ); 128 m_Attachments = aAttachment; 129 } 130 131 Sequence< OUString > SAL_CALL CmdMailMsg::getAttachement( ) 132 throw (RuntimeException) 133 { 134 MutexGuard aGuard( m_aMutex ); 135 return m_Attachments; 136 } 137 138 Any SAL_CALL CmdMailMsg::getByName( const OUString& aName ) 139 throw (NoSuchElementException, WrappedTargetException, RuntimeException) 140 { 141 MutexGuard aGuard( m_aMutex ); 142 143 if( 0 == aName.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "body" )) && m_aBody.getLength() ) 144 return makeAny( m_aBody ); 145 146 if( 0 == aName.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "from" )) && m_aOriginator.getLength() ) 147 return makeAny( m_aOriginator ); 148 149 else if( 0 == aName.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "to" )) && m_aRecipient.getLength() ) 150 return makeAny( m_aRecipient ); 151 152 else if( 0 == aName.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "cc" )) && m_CcRecipients.getLength() ) 153 return makeAny( m_CcRecipients ); 154 155 else if( 0 == aName.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "bcc" )) && m_BccRecipients.getLength() ) 156 return makeAny( m_BccRecipients ); 157 158 else if( 0 == aName.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "subject" )) && m_aSubject.getLength() ) 159 return makeAny( m_aSubject ); 160 161 else if( 0 == aName.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "attachment" )) && m_Attachments.getLength() ) 162 return makeAny( m_Attachments ); 163 164 throw NoSuchElementException( OUString(RTL_CONSTASCII_USTRINGPARAM( "key not found: ")) + aName, 165 static_cast < XNameAccess * > (this) ); 166 } 167 168 Sequence< OUString > SAL_CALL CmdMailMsg::getElementNames( ) 169 throw (::com::sun::star::uno::RuntimeException) 170 { 171 MutexGuard aGuard( m_aMutex ); 172 173 sal_Int32 nItems = 0; 174 Sequence< OUString > aRet( 7 ); 175 176 if( m_aBody.getLength() ) 177 aRet[nItems++] = OUString(RTL_CONSTASCII_USTRINGPARAM( "body" )); 178 179 if( m_aOriginator.getLength() ) 180 aRet[nItems++] = OUString(RTL_CONSTASCII_USTRINGPARAM( "from" )); 181 182 if( m_aRecipient.getLength() ) 183 aRet[nItems++] = OUString(RTL_CONSTASCII_USTRINGPARAM( "to" )); 184 185 if( m_CcRecipients.getLength() ) 186 aRet[nItems++] = OUString(RTL_CONSTASCII_USTRINGPARAM( "cc" )); 187 188 if( m_BccRecipients.getLength() ) 189 aRet[nItems++] = OUString(RTL_CONSTASCII_USTRINGPARAM( "bcc" )); 190 191 if( m_aSubject.getLength() ) 192 aRet[nItems++] = OUString(RTL_CONSTASCII_USTRINGPARAM( "subject" )); 193 194 if( m_Attachments.getLength() ) 195 aRet[nItems++] = OUString(RTL_CONSTASCII_USTRINGPARAM( "attachment" )); 196 197 aRet.realloc( nItems ); 198 return aRet; 199 } 200 201 sal_Bool SAL_CALL CmdMailMsg::hasByName( const OUString& aName ) 202 throw (RuntimeException) 203 { 204 MutexGuard aGuard( m_aMutex ); 205 206 if( 0 == aName.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "body" )) && m_aBody.getLength() ) 207 return sal_True; 208 209 if( 0 == aName.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "from" )) && m_aOriginator.getLength() ) 210 return sal_True; 211 212 else if( 0 == aName.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "to" )) && m_aRecipient.getLength() ) 213 return sal_True; 214 215 else if( 0 == aName.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "cc" )) && m_CcRecipients.getLength() ) 216 return sal_True; 217 218 else if( 0 == aName.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "bcc" )) && m_BccRecipients.getLength() ) 219 return sal_True; 220 221 else if( 0 == aName.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "subject" )) && m_aSubject.getLength() ) 222 return sal_True; 223 224 else if( 0 == aName.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "attachment" )) && m_Attachments.getLength() ) 225 return sal_True; 226 227 return sal_False; 228 } 229 230 Type SAL_CALL CmdMailMsg::getElementType( ) 231 throw (RuntimeException) 232 { 233 // returning void for multi type container 234 return Type(); 235 } 236 237 sal_Bool SAL_CALL CmdMailMsg::hasElements( ) 238 throw (RuntimeException) 239 { 240 return 0 != getElementNames().getLength(); 241 } 242