xref: /trunk/main/ucb/source/ucp/file/filinsreq.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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_file.hxx"
26 #include "filinsreq.hxx"
27 #include "shell.hxx"
28 #include "filglob.hxx"
29 #include <com/sun/star/ucb/IOErrorCode.hpp>
30 #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
31 #include <com/sun/star/ucb/NameClashException.hpp>
32 #include <com/sun/star/beans/PropertyValue.hpp>
33 
34 
35 
36 using namespace cppu;
37 using namespace com::sun::star;
38 using namespace com::sun::star::uno;
39 using namespace com::sun::star::lang;
40 using namespace com::sun::star::task;
41 using namespace com::sun::star::ucb;
42 using namespace com::sun::star::beans;
43 using namespace fileaccess;
44 
45 
46 
47 void SAL_CALL
acquire(void)48 XInteractionSupplyNameImpl::acquire( void )
49     throw()
50 {
51     OWeakObject::acquire();
52 }
53 
54 
55 
56 void SAL_CALL
release(void)57 XInteractionSupplyNameImpl::release( void )
58     throw()
59 {
60     OWeakObject::release();
61 }
62 
63 
64 
65 Any SAL_CALL
queryInterface(const Type & rType)66 XInteractionSupplyNameImpl::queryInterface( const Type& rType )
67 {
68     Any aRet = cppu::queryInterface( rType,
69                                      SAL_STATIC_CAST( lang::XTypeProvider*, this ),
70                                      SAL_STATIC_CAST( XInteractionSupplyName*,this) );
71     return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
72 }
73 
74 
75 //////////////////////////////////////////////////////////////////////////////////////////
76 //  XTypeProvider
77 //////////////////////////////////////////////////////////////////////////////////////////
78 
XTYPEPROVIDER_IMPL_2(XInteractionSupplyNameImpl,XTypeProvider,XInteractionSupplyName)79 XTYPEPROVIDER_IMPL_2( XInteractionSupplyNameImpl,
80                       XTypeProvider,
81                       XInteractionSupplyName )
82 
83 
84 
85 void SAL_CALL
86 XInteractionAbortImpl::acquire( void )
87     throw()
88 {
89     OWeakObject::acquire();
90 }
91 
92 
93 
94 void SAL_CALL
release(void)95 XInteractionAbortImpl::release( void )
96     throw()
97 {
98     OWeakObject::release();
99 }
100 
101 
102 
103 Any SAL_CALL
queryInterface(const Type & rType)104 XInteractionAbortImpl::queryInterface( const Type& rType )
105 {
106     Any aRet = cppu::queryInterface( rType,
107                                      SAL_STATIC_CAST( lang::XTypeProvider*, this ),
108                                      SAL_STATIC_CAST( XInteractionAbort*,this) );
109     return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
110 }
111 
112 
113 //////////////////////////////////////////////////////////////////////////////////////////
114 //  XTypeProvider
115 //////////////////////////////////////////////////////////////////////////////////////////
116 
XTYPEPROVIDER_IMPL_2(XInteractionAbortImpl,XTypeProvider,XInteractionAbort)117 XTYPEPROVIDER_IMPL_2( XInteractionAbortImpl,
118                       XTypeProvider,
119                       XInteractionAbort )
120 
121 
122 
123 XInteractionRequestImpl::XInteractionRequestImpl(
124     const rtl::OUString& aClashingName,
125     const Reference<XInterface>& xOrigin,
126     shell *pShell,sal_Int32 CommandId)
127     : p1( new XInteractionSupplyNameImpl ),
128       p2( new XInteractionAbortImpl ),
129       m_nErrorCode(0),
130       m_nMinorError(0),
131       m_aSeq( 2 ),
132       m_aClashingName(aClashingName),
133       m_xOrigin(xOrigin)
134 {
135     if( pShell )
136         pShell->retrieveError(CommandId,m_nErrorCode,m_nMinorError);
137     m_aSeq[0] = Reference<XInteractionContinuation>(p1);
138     m_aSeq[1] = Reference<XInteractionContinuation>(p2);
139 }
140 
141 
142 void SAL_CALL
acquire(void)143 XInteractionRequestImpl::acquire( void )
144     throw()
145 {
146     OWeakObject::acquire();
147 }
148 
149 
150 
151 void SAL_CALL
release(void)152 XInteractionRequestImpl::release( void )
153     throw()
154 {
155     OWeakObject::release();
156 }
157 
158 
159 
160 Any SAL_CALL
queryInterface(const Type & rType)161 XInteractionRequestImpl::queryInterface( const Type& rType )
162 {
163     Any aRet =
164         cppu::queryInterface(
165             rType,
166             SAL_STATIC_CAST( lang::XTypeProvider*, this ),
167             SAL_STATIC_CAST( XInteractionRequest*,this) );
168     return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
169 }
170 
171 
172 //////////////////////////////////////////////////////////////////////////////////////////
173 //  XTypeProvider
174 //////////////////////////////////////////////////////////////////////////////////////////
175 
XTYPEPROVIDER_IMPL_2(XInteractionRequestImpl,XTypeProvider,XInteractionRequest)176 XTYPEPROVIDER_IMPL_2( XInteractionRequestImpl,
177                       XTypeProvider,
178                       XInteractionRequest )
179 
180 
181 Any SAL_CALL
182 XInteractionRequestImpl::getRequest()
183 {
184     Any aAny;
185     if(m_nErrorCode == TASKHANDLING_FOLDER_EXISTS_MKDIR)
186     {
187         NameClashException excep;
188         excep.Name = m_aClashingName;
189         excep.Classification = InteractionClassification_ERROR;
190         excep.Context = m_xOrigin;
191         excep.Message = rtl::OUString(
192             RTL_CONSTASCII_USTRINGPARAM(
193                 "folder exists and overwritte forbidden"));
194         aAny <<= excep;
195     }
196     else if(m_nErrorCode == TASKHANDLING_INVALID_NAME_MKDIR)
197     {
198         InteractiveAugmentedIOException excep;
199         excep.Code = IOErrorCode_INVALID_CHARACTER;
200         PropertyValue prop;
201         prop.Name = rtl::OUString::createFromAscii("ResourceName");
202         prop.Handle = -1;
203         prop.Value <<= m_aClashingName;
204         Sequence<Any> seq(1);
205         seq[0] <<= prop;
206         excep.Arguments = seq;
207         excep.Classification = InteractionClassification_ERROR;
208         excep.Context = m_xOrigin;
209         excep.Message = rtl::OUString(
210             RTL_CONSTASCII_USTRINGPARAM(
211                 "the name contained invalid characters"));
212         aAny <<= excep;
213 
214     }
215     return aAny;
216 }
217