1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 5 * This Source Code Form is subject to the terms of the Mozilla Public 6 * License, v. 2.0. If a copy of the MPL was not distributed with this 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 11 * Licensed to the Apache Software Foundation (ASF) under one or more 12 * contributor license agreements. See the NOTICE file distributed 13 * with this work for additional information regarding copyright 14 * ownership. The ASF licenses this file to you under the Apache 15 * License, Version 2.0 (the "License"); you may not use this file 16 * except in compliance with the License. You may obtain a copy of 17 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 18 */ 19 20 #pragma once 21 22 #include <tools/urlobj.hxx> 23 #include <osl/conditn.hxx> 24 #include <osl/mutex.hxx> 25 #include <comphelper/processfactory.hxx> 26 #include <com/sun/star/uno/Reference.hxx> 27 #include <com/sun/star/uno/Any.hxx> 28 #include <com/sun/star/xml/dom/XDocumentFragment.hpp> 29 30 #include <com/sun/star/ucb/XCommandEnvironment.hpp> 31 #include <com/sun/star/ucb/XProgressHandler.hpp> 32 33 #include <com/sun/star/task/XInteractionHandler.hpp> 34 35 #include <com/sun/star/frame/XFrame.hpp> 36 37 #include <cppuhelper/implbase.hxx> 38 39 #include "serialization.hxx" 40 41 #include <memory> 42 43 class CSubmissionPut; 44 class CSubmissionPost; 45 class CSubmissionGet; 46 47 class CCommandEnvironmentHelper final : public cppu::WeakImplHelper< css::ucb::XCommandEnvironment > 48 { 49 friend class CSubmissionPut; 50 friend class CSubmissionPost; 51 friend class CSubmissionGet; 52 friend class CSubmission; 53 54 css::uno::Reference< css::task::XInteractionHandler > m_aInteractionHandler; 55 css::uno::Reference< css::ucb::XProgressHandler > m_aProgressHandler; 56 57 public: getInteractionHandler()58 virtual css::uno::Reference< css::task::XInteractionHandler > SAL_CALL getInteractionHandler() override 59 { 60 return m_aInteractionHandler; 61 } getProgressHandler()62 virtual css::uno::Reference< css::ucb::XProgressHandler > SAL_CALL getProgressHandler() override 63 { 64 return m_aProgressHandler; 65 } 66 }; 67 68 class CProgressHandlerHelper final : public cppu::WeakImplHelper< css::ucb::XProgressHandler > 69 { 70 friend class CSubmissionPut; 71 friend class CSubmissionPost; 72 friend class CSubmissionGet; 73 osl::Condition m_cFinished; 74 osl::Mutex m_mLock; 75 sal_Int32 m_count; 76 public: CProgressHandlerHelper()77 CProgressHandlerHelper() 78 : m_count(0) 79 {} push(const css::uno::Any &)80 virtual void SAL_CALL push( const css::uno::Any& /*aStatus*/) override 81 { 82 m_mLock.acquire(); 83 m_count++; 84 m_mLock.release(); 85 } update(const css::uno::Any &)86 virtual void SAL_CALL update(const css::uno::Any& /*aStatus*/) override 87 { 88 } pop()89 virtual void SAL_CALL pop() override 90 { 91 m_mLock.acquire(); 92 m_count--; 93 if (m_count == 0) 94 m_cFinished.set(); 95 m_mLock.release(); 96 } 97 }; 98 99 class CSubmission 100 { 101 102 protected: 103 INetURLObject m_aURLObj; 104 css::uno::Reference< css::xml::dom::XDocumentFragment > m_aFragment; 105 css::uno::Reference< css::io::XInputStream > m_aResultStream; 106 css::uno::Reference< css::uno::XComponentContext > m_xContext; 107 108 ::std::unique_ptr< CSerialization > createSerialization(const css::uno::Reference< css::task::XInteractionHandler >& aHandler 109 ,css::uno::Reference<css::ucb::XCommandEnvironment>& _rOutEnv); 110 111 public: 112 enum SubmissionResult { 113 SUCCESS, 114 UNKNOWN_ERROR 115 }; 116 CSubmission(const OUString & aURL,const css::uno::Reference<css::xml::dom::XDocumentFragment> & aFragment)117 CSubmission(const OUString& aURL, const css::uno::Reference< css::xml::dom::XDocumentFragment >& aFragment) 118 : m_aURLObj(aURL) 119 , m_aFragment(aFragment) 120 , m_xContext(::comphelper::getProcessComponentContext()) 121 {} 122 IsWebProtocol() const123 bool IsWebProtocol() const 124 { 125 INetProtocol eProtocol = m_aURLObj.GetProtocol(); 126 return eProtocol == INetProtocol::Http || eProtocol == INetProtocol::Https; 127 } 128 ~CSubmission()129 virtual ~CSubmission() {} 130 131 virtual SubmissionResult submit(const css::uno::Reference< css::task::XInteractionHandler >& ) = 0; 132 133 SubmissionResult replace(const OUString&, const css::uno::Reference< css::xml::dom::XDocument >&, const css::uno::Reference< css::frame::XFrame>&); 134 135 }; 136 137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 138