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 #ifndef __SUBMISSION_HXX
25 #define __SUBMISSION_HXX
26 
27 #include <tools/urlobj.hxx>
28 #include <rtl/ustring.h>
29 #include <osl/conditn.hxx>
30 #include <osl/mutex.hxx>
31 #include <unotools/processfactory.hxx>
32 #include <com/sun/star/uno/Reference.hxx>
33 #include <com/sun/star/uno/Any.hxx>
34 #include <com/sun/star/uno/Exception.hpp>
35 #include <com/sun/star/uno/RuntimeException.hpp>
36 #include <com/sun/star/xml/xpath/XXPathObject.hpp>
37 #include <com/sun/star/xml/dom/XDocumentFragment.hpp>
38 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39 
40 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
41 #include <com/sun/star/ucb/XProgressHandler.hpp>
42 
43 #include <com/sun/star/task/XInteractionHandler.hpp>
44 
45 #include <com/sun/star/frame/XFrame.hpp>
46 
47 #include <cppuhelper/implbase1.hxx>
48 #include <cppuhelper/implbase2.hxx>
49 #include <cppuhelper/implbase3.hxx>
50 
51 #include "serialization.hxx"
52 
53 namespace CSS = com::sun::star;
54 
55 class CSubmissionPut;
56 class CSubmissionPost;
57 class CSubmissionGet;
58 
59 class CCommandEnvironmentHelper : public cppu::WeakImplHelper1< CSS::ucb::XCommandEnvironment >
60 {
61     friend class CSubmissionPut;
62     friend class CSubmissionPost;
63     friend class CSubmissionGet;
64     friend class CSubmission;
65 
66 protected:
67     CSS::uno::Reference< CSS::task::XInteractionHandler >   m_aInteractionHandler;
68     CSS::uno::Reference< CSS::ucb::XProgressHandler >       m_aProgressHandler;
69 
70 public:
getInteractionHandler()71     virtual CSS::uno::Reference< CSS::task::XInteractionHandler > SAL_CALL getInteractionHandler() throw (CSS::uno::RuntimeException)
72     {
73         return m_aInteractionHandler;
74     }
getProgressHandler()75     virtual CSS::uno::Reference< CSS::ucb::XProgressHandler > SAL_CALL getProgressHandler() throw (CSS::uno::RuntimeException)
76     {
77         return m_aProgressHandler;
78     }
79 };
80 
81 class CProgressHandlerHelper : public cppu::WeakImplHelper1< CSS::ucb::XProgressHandler >
82 {
83     friend class CSubmissionPut;
84     friend class CSubmissionPost;
85     friend class CSubmissionGet;
86 protected:
87     osl::Condition m_cFinished;
88     osl::Mutex m_mLock;
89     sal_Int32 m_count;
90 public:
CProgressHandlerHelper()91     CProgressHandlerHelper()
92         : m_count(0)
93     {}
push(const com::sun::star::uno::Any &)94     virtual void SAL_CALL push( const com::sun::star::uno::Any& /*aStatus*/) throw(com::sun::star::uno::RuntimeException)
95     {
96         m_mLock.acquire();
97         m_count++;
98         m_mLock.release();
99     }
update(const com::sun::star::uno::Any &)100     virtual void SAL_CALL update(const com::sun::star::uno::Any& /*aStatus*/) throw(com::sun::star::uno::RuntimeException)
101     {
102     }
pop()103     virtual void SAL_CALL pop() throw(com::sun::star::uno::RuntimeException)
104     {
105         m_mLock.acquire();
106         m_count--;
107         if (m_count == 0)
108             m_cFinished.set();
109         m_mLock.release();
110     }
111 };
112 
113 class CSubmission
114 {
115 
116 protected:
117     INetURLObject m_aURLObj;
118     CSS::uno::Reference< CSS::xml::xpath::XXPathObject >    m_aXPathObject;
119     CSS::uno::Reference< CSS::xml::dom::XDocumentFragment > m_aFragment;
120     CSS::uno::Reference< CSS::io::XInputStream >            m_aResultStream;
121     CSS::uno::Reference< CSS::lang::XMultiServiceFactory >  m_aFactory;
122     rtl::OUString m_aEncoding;
123 
124     ::std::auto_ptr< CSerialization > createSerialization(const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& aHandler
125                                                   ,com::sun::star::uno::Reference<com::sun::star::ucb::XCommandEnvironment>& _rOutEnv);
126 
127 public:
128     enum SubmissionResult {
129         SUCCESS,
130         INVALID_METHOD,
131         INVALID_URL,
132         INVALID_ENCODING,
133         E_TRANSMISSION,
134         UNKNOWN_ERROR
135     };
136 
CSubmission(const rtl::OUString & aURL,const CSS::uno::Reference<CSS::xml::dom::XDocumentFragment> & aFragment)137     CSubmission(const rtl::OUString& aURL, const CSS::uno::Reference< CSS::xml::dom::XDocumentFragment >& aFragment)
138         : m_aURLObj(aURL)
139         , m_aFragment(aFragment)
140         , m_aFactory(::utl::getProcessServiceFactory())
141     {}
142 
~CSubmission()143     virtual ~CSubmission() {}
144 
145     //    virtual CSS::uno::Sequence< rtl::OUString > getSupportedEncodings() = 0;
setEncoding(const rtl::OUString & aEncoding)146     virtual void setEncoding(const rtl::OUString& aEncoding)
147     {
148         m_aEncoding = aEncoding;
149     }
150     virtual SubmissionResult submit(const CSS::uno::Reference< CSS::task::XInteractionHandler >& ) = 0;
151 
152     virtual SubmissionResult replace(const rtl::OUString&, const CSS::uno::Reference< CSS::xml::dom::XDocument >&, const CSS::uno::Reference< CSS::frame::XFrame>&);
153 
154 };
155 
156 #endif
157