1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef __SUBMISSION_HXX
29 #define __SUBMISSION_HXX
30 
31 #include <tools/urlobj.hxx>
32 #include <rtl/ustring.h>
33 #include <osl/conditn.hxx>
34 #include <osl/mutex.hxx>
35 #include <unotools/processfactory.hxx>
36 #include <com/sun/star/uno/Reference.hxx>
37 #include <com/sun/star/uno/Any.hxx>
38 #include <com/sun/star/uno/Exception.hpp>
39 #include <com/sun/star/uno/RuntimeException.hpp>
40 #include <com/sun/star/xml/xpath/XXPathObject.hpp>
41 #include <com/sun/star/xml/dom/XDocumentFragment.hpp>
42 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
43 
44 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
45 #include <com/sun/star/ucb/XProgressHandler.hpp>
46 
47 #include <com/sun/star/task/XInteractionHandler.hpp>
48 
49 #include <com/sun/star/frame/XFrame.hpp>
50 
51 #include <cppuhelper/implbase1.hxx>
52 #include <cppuhelper/implbase2.hxx>
53 #include <cppuhelper/implbase3.hxx>
54 
55 #include "serialization.hxx"
56 
57 namespace CSS = com::sun::star;
58 
59 class CSubmissionPut;
60 class CSubmissionPost;
61 class CSubmissionGet;
62 
63 class CCommandEnvironmentHelper : public cppu::WeakImplHelper1< CSS::ucb::XCommandEnvironment >
64 {
65     friend class CSubmissionPut;
66     friend class CSubmissionPost;
67     friend class CSubmissionGet;
68     friend class CSubmission;
69 
70 protected:
71     CSS::uno::Reference< CSS::task::XInteractionHandler >   m_aInteractionHandler;
72     CSS::uno::Reference< CSS::ucb::XProgressHandler >       m_aProgressHandler;
73 
74 public:
75     virtual CSS::uno::Reference< CSS::task::XInteractionHandler > SAL_CALL getInteractionHandler() throw (CSS::uno::RuntimeException)
76     {
77         return m_aInteractionHandler;
78     }
79     virtual CSS::uno::Reference< CSS::ucb::XProgressHandler > SAL_CALL getProgressHandler() throw (CSS::uno::RuntimeException)
80     {
81         return m_aProgressHandler;
82     }
83 };
84 
85 class CProgressHandlerHelper : public cppu::WeakImplHelper1< CSS::ucb::XProgressHandler >
86 {
87     friend class CSubmissionPut;
88     friend class CSubmissionPost;
89     friend class CSubmissionGet;
90 protected:
91     osl::Condition m_cFinished;
92     osl::Mutex m_mLock;
93     sal_Int32 m_count;
94 public:
95     CProgressHandlerHelper()
96         : m_count(0)
97     {}
98     virtual void SAL_CALL push( const com::sun::star::uno::Any& /*aStatus*/) throw(com::sun::star::uno::RuntimeException)
99     {
100         m_mLock.acquire();
101         m_count++;
102         m_mLock.release();
103     }
104     virtual void SAL_CALL update(const com::sun::star::uno::Any& /*aStatus*/) throw(com::sun::star::uno::RuntimeException)
105     {
106     }
107     virtual void SAL_CALL pop() throw(com::sun::star::uno::RuntimeException)
108     {
109         m_mLock.acquire();
110         m_count--;
111         if (m_count == 0)
112             m_cFinished.set();
113         m_mLock.release();
114     }
115 };
116 
117 class CSubmission
118 {
119 
120 protected:
121     INetURLObject m_aURLObj;
122     CSS::uno::Reference< CSS::xml::xpath::XXPathObject >    m_aXPathObject;
123     CSS::uno::Reference< CSS::xml::dom::XDocumentFragment > m_aFragment;
124     CSS::uno::Reference< CSS::io::XInputStream >            m_aResultStream;
125     CSS::uno::Reference< CSS::lang::XMultiServiceFactory >  m_aFactory;
126     rtl::OUString m_aEncoding;
127 
128     ::std::auto_ptr< CSerialization > createSerialization(const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& aHandler
129                                                   ,com::sun::star::uno::Reference<com::sun::star::ucb::XCommandEnvironment>& _rOutEnv);
130 
131 public:
132     enum SubmissionResult {
133         SUCCESS,
134         INVALID_METHOD,
135         INVALID_URL,
136         INVALID_ENCODING,
137         E_TRANSMISSION,
138         UNKNOWN_ERROR
139     };
140 
141     CSubmission(const rtl::OUString& aURL, const CSS::uno::Reference< CSS::xml::dom::XDocumentFragment >& aFragment)
142         : m_aURLObj(aURL)
143         , m_aFragment(aFragment)
144         , m_aFactory(::utl::getProcessServiceFactory())
145     {}
146 
147     virtual ~CSubmission() {}
148 
149     //    virtual CSS::uno::Sequence< rtl::OUString > getSupportedEncodings() = 0;
150     virtual void setEncoding(const rtl::OUString& aEncoding)
151     {
152         m_aEncoding = aEncoding;
153     }
154     virtual SubmissionResult submit(const CSS::uno::Reference< CSS::task::XInteractionHandler >& ) = 0;
155 
156     virtual SubmissionResult replace(const rtl::OUString&, const CSS::uno::Reference< CSS::xml::dom::XDocument >&, const CSS::uno::Reference< CSS::frame::XFrame>&);
157 
158 };
159 
160 #endif
161