1*dde7d3faSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*dde7d3faSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*dde7d3faSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*dde7d3faSAndrew Rist * distributed with this work for additional information 6*dde7d3faSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*dde7d3faSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*dde7d3faSAndrew Rist * "License"); you may not use this file except in compliance 9*dde7d3faSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*dde7d3faSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*dde7d3faSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*dde7d3faSAndrew Rist * software distributed under the License is distributed on an 15*dde7d3faSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*dde7d3faSAndrew Rist * KIND, either express or implied. See the License for the 17*dde7d3faSAndrew Rist * specific language governing permissions and limitations 18*dde7d3faSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*dde7d3faSAndrew Rist *************************************************************/ 21*dde7d3faSAndrew Rist 22*dde7d3faSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_comphelper.hxx" 26cdf0e10cSrcweir #include <comphelper/mediadescriptor.hxx> 27cdf0e10cSrcweir #include <comphelper/namedvaluecollection.hxx> 28cdf0e10cSrcweir #include <comphelper/stillreadwriteinteraction.hxx> 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <com/sun/star/ucb/XContent.hpp> 31cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandEnvironment.hpp> 32cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp> 33cdf0e10cSrcweir #include <com/sun/star/io/XStream.hpp> 34cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSink.hpp> 35cdf0e10cSrcweir #include <com/sun/star/io/XSeekable.hpp> 36cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 37cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp> 38cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp> 39cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveIOException.hpp> 40cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp> 41cdf0e10cSrcweir #include <com/sun/star/ucb/CommandFailedException.hpp> 42cdf0e10cSrcweir #include <com/sun/star/task/XInteractionAbort.hpp> 43cdf0e10cSrcweir #include <com/sun/star/uri/XUriReferenceFactory.hpp> 44cdf0e10cSrcweir #include <com/sun/star/uri/XUriReference.hpp> 45cdf0e10cSrcweir #include <com/sun/star/ucb/PostCommandArgument2.hpp> 46cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 47cdf0e10cSrcweir 48cdf0e10cSrcweir #include <ucbhelper/interceptedinteraction.hxx> 49cdf0e10cSrcweir #include <ucbhelper/content.hxx> 50cdf0e10cSrcweir #include <ucbhelper/commandenvironment.hxx> 51cdf0e10cSrcweir #include <ucbhelper/activedatasink.hxx> 52cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 53cdf0e10cSrcweir #include <comphelper/configurationhelper.hxx> 54cdf0e10cSrcweir 55cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 56cdf0e10cSrcweir 57cdf0e10cSrcweir //_______________________________________________ 58cdf0e10cSrcweir // namespace 59cdf0e10cSrcweir 60cdf0e10cSrcweir namespace comphelper{ 61cdf0e10cSrcweir 62cdf0e10cSrcweir namespace css = ::com::sun::star; 63cdf0e10cSrcweir 64cdf0e10cSrcweir //_______________________________________________ 65cdf0e10cSrcweir // definitions 66cdf0e10cSrcweir 67cdf0e10cSrcweir /*----------------------------------------------- 68cdf0e10cSrcweir 10.03.2004 07:35 69cdf0e10cSrcweir -----------------------------------------------*/ 70cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_ABORTED() 71cdf0e10cSrcweir { 72cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Aborted")); 73cdf0e10cSrcweir return sProp; 74cdf0e10cSrcweir } 75cdf0e10cSrcweir 76cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_ASTEMPLATE() 77cdf0e10cSrcweir { 78cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("AsTemplate")); 79cdf0e10cSrcweir return sProp; 80cdf0e10cSrcweir } 81cdf0e10cSrcweir 82cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_CHARACTERSET() 83cdf0e10cSrcweir { 84cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("CharacterSet")); 85cdf0e10cSrcweir return sProp; 86cdf0e10cSrcweir } 87cdf0e10cSrcweir 88cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_COMPONENTDATA() 89cdf0e10cSrcweir { 90cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("ComponentData")); 91cdf0e10cSrcweir return sProp; 92cdf0e10cSrcweir } 93cdf0e10cSrcweir 94cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_DEEPDETECTION() 95cdf0e10cSrcweir { 96cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("DeepDetection")); 97cdf0e10cSrcweir return sProp; 98cdf0e10cSrcweir } 99cdf0e10cSrcweir 100cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_DETECTSERVICE() 101cdf0e10cSrcweir { 102cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("DetectService")); 103cdf0e10cSrcweir return sProp; 104cdf0e10cSrcweir } 105cdf0e10cSrcweir 106cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_DOCUMENTSERVICE() 107cdf0e10cSrcweir { 108cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("DocumentService")); 109cdf0e10cSrcweir return sProp; 110cdf0e10cSrcweir } 111cdf0e10cSrcweir 112cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_ENCRYPTIONDATA() 113cdf0e10cSrcweir { 114cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("EncryptionData")); 115cdf0e10cSrcweir return sProp; 116cdf0e10cSrcweir } 117cdf0e10cSrcweir 118cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_EXTENSION() 119cdf0e10cSrcweir { 120cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Extension")); 121cdf0e10cSrcweir return sProp; 122cdf0e10cSrcweir } 123cdf0e10cSrcweir 124cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_FILENAME() 125cdf0e10cSrcweir { 126cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("FileName")); 127cdf0e10cSrcweir return sProp; 128cdf0e10cSrcweir } 129cdf0e10cSrcweir 130cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_FILTERNAME() 131cdf0e10cSrcweir { 132cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("FilterName")); 133cdf0e10cSrcweir return sProp; 134cdf0e10cSrcweir } 135cdf0e10cSrcweir 136cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_FILTEROPTIONS() 137cdf0e10cSrcweir { 138cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("FilterOptions")); 139cdf0e10cSrcweir return sProp; 140cdf0e10cSrcweir } 141cdf0e10cSrcweir 142cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_FORMAT() 143cdf0e10cSrcweir { 144cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Format")); 145cdf0e10cSrcweir return sProp; 146cdf0e10cSrcweir } 147cdf0e10cSrcweir 148cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_FRAME() 149cdf0e10cSrcweir { 150cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Frame")); 151cdf0e10cSrcweir return sProp; 152cdf0e10cSrcweir } 153cdf0e10cSrcweir 154cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_FRAMENAME() 155cdf0e10cSrcweir { 156cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("FrameName")); 157cdf0e10cSrcweir return sProp; 158cdf0e10cSrcweir } 159cdf0e10cSrcweir 160cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_HIDDEN() 161cdf0e10cSrcweir { 162cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Hidden")); 163cdf0e10cSrcweir return sProp; 164cdf0e10cSrcweir } 165cdf0e10cSrcweir 166cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_INPUTSTREAM() 167cdf0e10cSrcweir { 168cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("InputStream")); 169cdf0e10cSrcweir return sProp; 170cdf0e10cSrcweir } 171cdf0e10cSrcweir 172cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_INTERACTIONHANDLER() 173cdf0e10cSrcweir { 174cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("InteractionHandler")); 175cdf0e10cSrcweir return sProp; 176cdf0e10cSrcweir } 177cdf0e10cSrcweir 178cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_JUMPMARK() 179cdf0e10cSrcweir { 180cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("JumpMark")); 181cdf0e10cSrcweir return sProp; 182cdf0e10cSrcweir } 183cdf0e10cSrcweir 184cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_MACROEXECUTIONMODE() 185cdf0e10cSrcweir { 186cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("MacroExecutionMode")); 187cdf0e10cSrcweir return sProp; 188cdf0e10cSrcweir } 189cdf0e10cSrcweir 190cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_MEDIATYPE() 191cdf0e10cSrcweir { 192cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("MediaType")); 193cdf0e10cSrcweir return sProp; 194cdf0e10cSrcweir } 195cdf0e10cSrcweir 196cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_MINIMIZED() 197cdf0e10cSrcweir { 198cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Minimized")); 199cdf0e10cSrcweir return sProp; 200cdf0e10cSrcweir } 201cdf0e10cSrcweir 202cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_NOAUTOSAVE() 203cdf0e10cSrcweir { 204cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("NoAutoSave")); 205cdf0e10cSrcweir return sProp; 206cdf0e10cSrcweir } 207cdf0e10cSrcweir 208cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_OPENNEWVIEW() 209cdf0e10cSrcweir { 210cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("OpenNewView")); 211cdf0e10cSrcweir return sProp; 212cdf0e10cSrcweir } 213cdf0e10cSrcweir 214cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_OUTPUTSTREAM() 215cdf0e10cSrcweir { 216cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("OutputStream")); 217cdf0e10cSrcweir return sProp; 218cdf0e10cSrcweir } 219cdf0e10cSrcweir 220cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_PATTERN() 221cdf0e10cSrcweir { 222cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Pattern")); 223cdf0e10cSrcweir return sProp; 224cdf0e10cSrcweir } 225cdf0e10cSrcweir 226cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_POSSIZE() 227cdf0e10cSrcweir { 228cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("PosSize")); 229cdf0e10cSrcweir return sProp; 230cdf0e10cSrcweir } 231cdf0e10cSrcweir 232cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_POSTDATA() 233cdf0e10cSrcweir { 234cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("PostData")); 235cdf0e10cSrcweir return sProp; 236cdf0e10cSrcweir } 237cdf0e10cSrcweir 238cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_POSTSTRING() 239cdf0e10cSrcweir { 240cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("PostString")); 241cdf0e10cSrcweir return sProp; 242cdf0e10cSrcweir } 243cdf0e10cSrcweir 244cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_PREVIEW() 245cdf0e10cSrcweir { 246cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Preview")); 247cdf0e10cSrcweir return sProp; 248cdf0e10cSrcweir } 249cdf0e10cSrcweir 250cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_READONLY() 251cdf0e10cSrcweir { 252cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("ReadOnly")); 253cdf0e10cSrcweir return sProp; 254cdf0e10cSrcweir } 255cdf0e10cSrcweir 256cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_REFERRER() 257cdf0e10cSrcweir { 258cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Referer")); 259cdf0e10cSrcweir return sProp; 260cdf0e10cSrcweir } 261cdf0e10cSrcweir 262cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_SILENT() 263cdf0e10cSrcweir { 264cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Silent")); 265cdf0e10cSrcweir return sProp; 266cdf0e10cSrcweir } 267cdf0e10cSrcweir 268cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_STATUSINDICATOR() 269cdf0e10cSrcweir { 270cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("StatusIndicator")); 271cdf0e10cSrcweir return sProp; 272cdf0e10cSrcweir } 273cdf0e10cSrcweir 274cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_STREAM() 275cdf0e10cSrcweir { 276cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Stream")); 277cdf0e10cSrcweir return sProp; 278cdf0e10cSrcweir } 279cdf0e10cSrcweir 280cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_STREAMFOROUTPUT() 281cdf0e10cSrcweir { 282cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("StreamForOutput")); 283cdf0e10cSrcweir return sProp; 284cdf0e10cSrcweir } 285cdf0e10cSrcweir 286cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_TEMPLATENAME() 287cdf0e10cSrcweir { 288cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("TemplateName")); 289cdf0e10cSrcweir return sProp; 290cdf0e10cSrcweir } 291cdf0e10cSrcweir 292cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_TEMPLATEREGIONNAME() 293cdf0e10cSrcweir { 294cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("TemplateRegionName")); 295cdf0e10cSrcweir return sProp; 296cdf0e10cSrcweir } 297cdf0e10cSrcweir 298cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_TYPENAME() 299cdf0e10cSrcweir { 300cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("TypeName")); 301cdf0e10cSrcweir return sProp; 302cdf0e10cSrcweir } 303cdf0e10cSrcweir 304cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_UCBCONTENT() 305cdf0e10cSrcweir { 306cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("UCBContent")); 307cdf0e10cSrcweir return sProp; 308cdf0e10cSrcweir } 309cdf0e10cSrcweir 310cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_UPDATEDOCMODE() 311cdf0e10cSrcweir { 312cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("UpdateDocMode")); 313cdf0e10cSrcweir return sProp; 314cdf0e10cSrcweir } 315cdf0e10cSrcweir 316cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_URL() 317cdf0e10cSrcweir { 318cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("URL")); 319cdf0e10cSrcweir return sProp; 320cdf0e10cSrcweir } 321cdf0e10cSrcweir 322cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_VERSION() 323cdf0e10cSrcweir { 324cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Version")); 325cdf0e10cSrcweir return sProp; 326cdf0e10cSrcweir } 327cdf0e10cSrcweir 328cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_VIEWID() 329cdf0e10cSrcweir { 330cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("ViewId")); 331cdf0e10cSrcweir return sProp; 332cdf0e10cSrcweir } 333cdf0e10cSrcweir 334cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_REPAIRPACKAGE() 335cdf0e10cSrcweir { 336cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("RepairPackage")); 337cdf0e10cSrcweir return sProp; 338cdf0e10cSrcweir } 339cdf0e10cSrcweir 340cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_DOCUMENTTITLE() 341cdf0e10cSrcweir { 342cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("DocumentTitle")); 343cdf0e10cSrcweir return sProp; 344cdf0e10cSrcweir } 345cdf0e10cSrcweir 346cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_MODEL() 347cdf0e10cSrcweir { 348cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Model")); 349cdf0e10cSrcweir return sProp; 350cdf0e10cSrcweir } 351cdf0e10cSrcweir 352cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_PASSWORD() 353cdf0e10cSrcweir { 354cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Password")); 355cdf0e10cSrcweir return sProp; 356cdf0e10cSrcweir } 357cdf0e10cSrcweir 358cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_TITLE() 359cdf0e10cSrcweir { 360cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Title")); 361cdf0e10cSrcweir return sProp; 362cdf0e10cSrcweir } 363cdf0e10cSrcweir 364cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_SALVAGEDFILE() 365cdf0e10cSrcweir { 366cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("SalvagedFile")); 367cdf0e10cSrcweir return sProp; 368cdf0e10cSrcweir } 369cdf0e10cSrcweir 370cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_VIEWONLY() 371cdf0e10cSrcweir { 372cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("ViewOnly")); 373cdf0e10cSrcweir return sProp; 374cdf0e10cSrcweir } 375cdf0e10cSrcweir 376cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_DOCUMENTBASEURL() 377cdf0e10cSrcweir { 378cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("DocumentBaseURL")); 379cdf0e10cSrcweir return sProp; 380cdf0e10cSrcweir } 381cdf0e10cSrcweir 382cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_VIEWCONTROLLERNAME() 383cdf0e10cSrcweir { 384cdf0e10cSrcweir static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("ViewControllerName")); 385cdf0e10cSrcweir return sProp; 386cdf0e10cSrcweir } 387cdf0e10cSrcweir /*----------------------------------------------- 388cdf0e10cSrcweir 10.03.2004 08:09 389cdf0e10cSrcweir -----------------------------------------------*/ 390cdf0e10cSrcweir MediaDescriptor::MediaDescriptor() 391cdf0e10cSrcweir : SequenceAsHashMap() 392cdf0e10cSrcweir { 393cdf0e10cSrcweir } 394cdf0e10cSrcweir 395cdf0e10cSrcweir /*----------------------------------------------- 396cdf0e10cSrcweir 10.03.2004 08:09 397cdf0e10cSrcweir -----------------------------------------------*/ 398cdf0e10cSrcweir MediaDescriptor::MediaDescriptor(const css::uno::Any& aSource) 399cdf0e10cSrcweir : SequenceAsHashMap(aSource) 400cdf0e10cSrcweir { 401cdf0e10cSrcweir } 402cdf0e10cSrcweir 403cdf0e10cSrcweir /*----------------------------------------------- 404cdf0e10cSrcweir 10.03.2004 08:09 405cdf0e10cSrcweir -----------------------------------------------*/ 406cdf0e10cSrcweir MediaDescriptor::MediaDescriptor(const css::uno::Sequence< css::beans::PropertyValue >& lSource) 407cdf0e10cSrcweir : SequenceAsHashMap(lSource) 408cdf0e10cSrcweir { 409cdf0e10cSrcweir } 410cdf0e10cSrcweir 411cdf0e10cSrcweir /*----------------------------------------------- 412cdf0e10cSrcweir 10.03.2004 08:09 413cdf0e10cSrcweir -----------------------------------------------*/ 414cdf0e10cSrcweir MediaDescriptor::MediaDescriptor(const css::uno::Sequence< css::beans::NamedValue >& lSource) 415cdf0e10cSrcweir : SequenceAsHashMap(lSource) 416cdf0e10cSrcweir { 417cdf0e10cSrcweir } 418cdf0e10cSrcweir 419cdf0e10cSrcweir /*----------------------------------------------- 420cdf0e10cSrcweir 18.11.2004 13:37 421cdf0e10cSrcweir -----------------------------------------------*/ 422cdf0e10cSrcweir sal_Bool MediaDescriptor::isStreamReadOnly() const 423cdf0e10cSrcweir { 424cdf0e10cSrcweir static ::rtl::OUString CONTENTSCHEME_FILE = ::rtl::OUString::createFromAscii("file"); 425cdf0e10cSrcweir static ::rtl::OUString CONTENTPROP_ISREADONLY = ::rtl::OUString::createFromAscii("IsReadOnly"); 426cdf0e10cSrcweir static sal_Bool READONLY_FALLBACK = sal_False; 427cdf0e10cSrcweir 428cdf0e10cSrcweir sal_Bool bReadOnly = READONLY_FALLBACK; 429cdf0e10cSrcweir 430cdf0e10cSrcweir // check for explicit readonly state 431cdf0e10cSrcweir const_iterator pIt = find(MediaDescriptor::PROP_READONLY()); 432cdf0e10cSrcweir if (pIt != end()) 433cdf0e10cSrcweir { 434cdf0e10cSrcweir pIt->second >>= bReadOnly; 435cdf0e10cSrcweir return bReadOnly; 436cdf0e10cSrcweir } 437cdf0e10cSrcweir 438cdf0e10cSrcweir // streams based on post data are readonly by definition 439cdf0e10cSrcweir pIt = find(MediaDescriptor::PROP_POSTDATA()); 440cdf0e10cSrcweir if (pIt != end()) 441cdf0e10cSrcweir return sal_True; 442cdf0e10cSrcweir 443cdf0e10cSrcweir // A XStream capsulate XInputStream and XOutputStream ... 444cdf0e10cSrcweir // If it exists - the file must be open in read/write mode! 445cdf0e10cSrcweir pIt = find(MediaDescriptor::PROP_STREAM()); 446cdf0e10cSrcweir if (pIt != end()) 447cdf0e10cSrcweir return sal_False; 448cdf0e10cSrcweir 449cdf0e10cSrcweir // Only file system content provider is able to provide XStream 450cdf0e10cSrcweir // so for this content impossibility to create XStream triggers 451cdf0e10cSrcweir // switch to readonly mode. 452cdf0e10cSrcweir try 453cdf0e10cSrcweir { 454cdf0e10cSrcweir css::uno::Reference< css::ucb::XContent > xContent = getUnpackedValueOrDefault(MediaDescriptor::PROP_UCBCONTENT(), css::uno::Reference< css::ucb::XContent >()); 455cdf0e10cSrcweir if (xContent.is()) 456cdf0e10cSrcweir { 457cdf0e10cSrcweir css::uno::Reference< css::ucb::XContentIdentifier > xId(xContent->getIdentifier(), css::uno::UNO_QUERY); 458cdf0e10cSrcweir ::rtl::OUString aScheme; 459cdf0e10cSrcweir if (xId.is()) 460cdf0e10cSrcweir aScheme = xId->getContentProviderScheme(); 461cdf0e10cSrcweir 462cdf0e10cSrcweir if (aScheme.equalsIgnoreAsciiCase(CONTENTSCHEME_FILE)) 463cdf0e10cSrcweir bReadOnly = sal_True; 464cdf0e10cSrcweir else 465cdf0e10cSrcweir { 466cdf0e10cSrcweir ::ucbhelper::Content aContent(xContent, css::uno::Reference< css::ucb::XCommandEnvironment >()); 467cdf0e10cSrcweir aContent.getPropertyValue(CONTENTPROP_ISREADONLY) >>= bReadOnly; 468cdf0e10cSrcweir } 469cdf0e10cSrcweir } 470cdf0e10cSrcweir } 471cdf0e10cSrcweir catch(const css::uno::RuntimeException& exRun) 472cdf0e10cSrcweir { throw exRun; } 473cdf0e10cSrcweir catch(const css::uno::Exception&) 474cdf0e10cSrcweir {} 475cdf0e10cSrcweir 476cdf0e10cSrcweir return bReadOnly; 477cdf0e10cSrcweir } 478cdf0e10cSrcweir 479cdf0e10cSrcweir // ---------------------------------------------------------------------------- 480cdf0e10cSrcweir 481cdf0e10cSrcweir css::uno::Any MediaDescriptor::getComponentDataEntry( const ::rtl::OUString& rName ) const 482cdf0e10cSrcweir { 483cdf0e10cSrcweir css::uno::Any aEntry; 484cdf0e10cSrcweir SequenceAsHashMap::const_iterator aPropertyIter = find( PROP_COMPONENTDATA() ); 485cdf0e10cSrcweir if( aPropertyIter != end() ) 486cdf0e10cSrcweir return NamedValueCollection( aPropertyIter->second ).get( rName ); 487cdf0e10cSrcweir return css::uno::Any(); 488cdf0e10cSrcweir } 489cdf0e10cSrcweir 490cdf0e10cSrcweir void MediaDescriptor::setComponentDataEntry( const ::rtl::OUString& rName, const css::uno::Any& rValue ) 491cdf0e10cSrcweir { 492cdf0e10cSrcweir if( rValue.hasValue() ) 493cdf0e10cSrcweir { 494cdf0e10cSrcweir // get or create the 'ComponentData' property entry 495cdf0e10cSrcweir css::uno::Any& rCompDataAny = operator[]( PROP_COMPONENTDATA() ); 496cdf0e10cSrcweir // insert the value (retain sequence type, create NamedValue elements by default) 497cdf0e10cSrcweir bool bHasNamedValues = !rCompDataAny.hasValue() || rCompDataAny.has< css::uno::Sequence< css::beans::NamedValue > >(); 498cdf0e10cSrcweir bool bHasPropValues = rCompDataAny.has< css::uno::Sequence< css::beans::PropertyValue > >(); 499cdf0e10cSrcweir OSL_ENSURE( bHasNamedValues || bHasPropValues, "MediaDescriptor::setComponentDataEntry - incompatible 'ComponentData' property in media descriptor" ); 500cdf0e10cSrcweir if( bHasNamedValues || bHasPropValues ) 501cdf0e10cSrcweir { 502cdf0e10cSrcweir // insert or overwrite the passed value 503cdf0e10cSrcweir SequenceAsHashMap aCompDataMap( rCompDataAny ); 504cdf0e10cSrcweir aCompDataMap[ rName ] = rValue; 505cdf0e10cSrcweir // write back the sequence (restore sequence with correct element type) 506cdf0e10cSrcweir rCompDataAny = aCompDataMap.getAsConstAny( bHasPropValues ); 507cdf0e10cSrcweir } 508cdf0e10cSrcweir } 509cdf0e10cSrcweir else 510cdf0e10cSrcweir { 511cdf0e10cSrcweir // if an empty Any is passed, clear the entry 512cdf0e10cSrcweir clearComponentDataEntry( rName ); 513cdf0e10cSrcweir } 514cdf0e10cSrcweir } 515cdf0e10cSrcweir 516cdf0e10cSrcweir void MediaDescriptor::clearComponentDataEntry( const ::rtl::OUString& rName ) 517cdf0e10cSrcweir { 518cdf0e10cSrcweir SequenceAsHashMap::iterator aPropertyIter = find( PROP_COMPONENTDATA() ); 519cdf0e10cSrcweir if( aPropertyIter != end() ) 520cdf0e10cSrcweir { 521cdf0e10cSrcweir css::uno::Any& rCompDataAny = aPropertyIter->second; 522cdf0e10cSrcweir bool bHasNamedValues = rCompDataAny.has< css::uno::Sequence< css::beans::NamedValue > >(); 523cdf0e10cSrcweir bool bHasPropValues = rCompDataAny.has< css::uno::Sequence< css::beans::PropertyValue > >(); 524cdf0e10cSrcweir OSL_ENSURE( bHasNamedValues || bHasPropValues, "MediaDescriptor::clearComponentDataEntry - incompatible 'ComponentData' property in media descriptor" ); 525cdf0e10cSrcweir if( bHasNamedValues || bHasPropValues ) 526cdf0e10cSrcweir { 527cdf0e10cSrcweir // remove the value with the passed name 528cdf0e10cSrcweir SequenceAsHashMap aCompDataMap( rCompDataAny ); 529cdf0e10cSrcweir aCompDataMap.erase( rName ); 530cdf0e10cSrcweir // write back the sequence, or remove it completely if it is empty 531cdf0e10cSrcweir if( aCompDataMap.empty() ) 532cdf0e10cSrcweir erase( aPropertyIter ); 533cdf0e10cSrcweir else 534cdf0e10cSrcweir rCompDataAny = aCompDataMap.getAsConstAny( bHasPropValues ); 535cdf0e10cSrcweir } 536cdf0e10cSrcweir } 537cdf0e10cSrcweir } 538cdf0e10cSrcweir 539cdf0e10cSrcweir /*----------------------------------------------- 540cdf0e10cSrcweir 10.03.2004 09:02 541cdf0e10cSrcweir -----------------------------------------------*/ 542cdf0e10cSrcweir sal_Bool MediaDescriptor::addInputStream() 543cdf0e10cSrcweir { 544cdf0e10cSrcweir return impl_addInputStream( sal_True ); 545cdf0e10cSrcweir } 546cdf0e10cSrcweir 547cdf0e10cSrcweir /*-----------------------------------------------*/ 548cdf0e10cSrcweir sal_Bool MediaDescriptor::addInputStreamOwnLock() 549cdf0e10cSrcweir { 550cdf0e10cSrcweir // Own lock file implementation 551cdf0e10cSrcweir 552cdf0e10cSrcweir sal_Bool bUseLock = sal_True; // the system file locking is used per default 553cdf0e10cSrcweir try 554cdf0e10cSrcweir { 555cdf0e10cSrcweir 556cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > xCommonConfig = ::comphelper::ConfigurationHelper::openConfig( 557cdf0e10cSrcweir ::comphelper::getProcessServiceFactory(), 558cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common" ) ), 559cdf0e10cSrcweir ::comphelper::ConfigurationHelper::E_STANDARD ); 560cdf0e10cSrcweir if ( !xCommonConfig.is() ) 561cdf0e10cSrcweir throw css::uno::RuntimeException(); 562cdf0e10cSrcweir 563cdf0e10cSrcweir ::comphelper::ConfigurationHelper::readRelativeKey( 564cdf0e10cSrcweir xCommonConfig, 565cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Misc/" ) ), 566cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseDocumentSystemFileLocking" ) ) ) >>= bUseLock; 567cdf0e10cSrcweir } 568cdf0e10cSrcweir catch( const css::uno::Exception& ) 569cdf0e10cSrcweir { 570cdf0e10cSrcweir } 571cdf0e10cSrcweir 572cdf0e10cSrcweir return impl_addInputStream( bUseLock ); 573cdf0e10cSrcweir } 574cdf0e10cSrcweir 575cdf0e10cSrcweir /*-----------------------------------------------*/ 576cdf0e10cSrcweir sal_Bool MediaDescriptor::impl_addInputStream( sal_Bool bLockFile ) 577cdf0e10cSrcweir { 578cdf0e10cSrcweir // check for an already existing stream item first 579cdf0e10cSrcweir const_iterator pIt = find(MediaDescriptor::PROP_INPUTSTREAM()); 580cdf0e10cSrcweir if (pIt != end()) 581cdf0e10cSrcweir return sal_True; 582cdf0e10cSrcweir 583cdf0e10cSrcweir try 584cdf0e10cSrcweir { 585cdf0e10cSrcweir // No stream available - create a new one 586cdf0e10cSrcweir // a) data comes as PostData ... 587cdf0e10cSrcweir pIt = find(MediaDescriptor::PROP_POSTDATA()); 588cdf0e10cSrcweir if (pIt != end()) 589cdf0e10cSrcweir { 590cdf0e10cSrcweir const css::uno::Any& rPostData = pIt->second; 591cdf0e10cSrcweir css::uno::Reference< css::io::XInputStream > xPostData; 592cdf0e10cSrcweir rPostData >>= xPostData; 593cdf0e10cSrcweir 594cdf0e10cSrcweir return impl_openStreamWithPostData( xPostData ); 595cdf0e10cSrcweir } 596cdf0e10cSrcweir 597cdf0e10cSrcweir // b) ... or we must get it from the given URL 598cdf0e10cSrcweir ::rtl::OUString sURL = getUnpackedValueOrDefault(MediaDescriptor::PROP_URL(), ::rtl::OUString()); 599cdf0e10cSrcweir if (!sURL.getLength()) 600cdf0e10cSrcweir throw css::uno::Exception( 601cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Found no URL."), 602cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface >()); 603cdf0e10cSrcweir 604cdf0e10cSrcweir // Parse URL! Only the main part has to be used further. E.g. a jumpmark can make trouble 605cdf0e10cSrcweir ::rtl::OUString sNormalizedURL = impl_normalizeURL( sURL ); 606cdf0e10cSrcweir return impl_openStreamWithURL( sNormalizedURL, bLockFile ); 607cdf0e10cSrcweir } 608cdf0e10cSrcweir #if OSL_DEBUG_LEVEL>0 609cdf0e10cSrcweir catch(const css::uno::Exception& ex) 610cdf0e10cSrcweir { 611cdf0e10cSrcweir ::rtl::OUStringBuffer sMsg(256); 612cdf0e10cSrcweir sMsg.appendAscii("Invalid MediaDescriptor detected:\n"); 613cdf0e10cSrcweir sMsg.append (ex.Message ); 614cdf0e10cSrcweir OSL_ENSURE(sal_False, ::rtl::OUStringToOString(sMsg.makeStringAndClear(), RTL_TEXTENCODING_UTF8).getStr()); 615cdf0e10cSrcweir } 616cdf0e10cSrcweir #else 617cdf0e10cSrcweir catch(const css::uno::Exception&) 618cdf0e10cSrcweir {} 619cdf0e10cSrcweir #endif 620cdf0e10cSrcweir 621cdf0e10cSrcweir return sal_False; 622cdf0e10cSrcweir } 623cdf0e10cSrcweir 624cdf0e10cSrcweir /*----------------------------------------------- 625cdf0e10cSrcweir 25.03.2004 12:38 626cdf0e10cSrcweir -----------------------------------------------*/ 627cdf0e10cSrcweir sal_Bool MediaDescriptor::impl_openStreamWithPostData( const css::uno::Reference< css::io::XInputStream >& _rxPostData ) 628cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 629cdf0e10cSrcweir { 630cdf0e10cSrcweir if ( !_rxPostData.is() ) 631cdf0e10cSrcweir throw css::lang::IllegalArgumentException( 632cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Found invalid PostData."), 633cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface >(), 1); 634cdf0e10cSrcweir 635cdf0e10cSrcweir // PostData can't be used in read/write mode! 636cdf0e10cSrcweir (*this)[MediaDescriptor::PROP_READONLY()] <<= sal_True; 637cdf0e10cSrcweir 638cdf0e10cSrcweir // prepare the environment 639cdf0e10cSrcweir css::uno::Reference< css::task::XInteractionHandler > xInteraction = getUnpackedValueOrDefault( 640cdf0e10cSrcweir MediaDescriptor::PROP_INTERACTIONHANDLER(), 641cdf0e10cSrcweir css::uno::Reference< css::task::XInteractionHandler >()); 642cdf0e10cSrcweir css::uno::Reference< css::ucb::XProgressHandler > xProgress; 643cdf0e10cSrcweir ::ucbhelper::CommandEnvironment* pCommandEnv = new ::ucbhelper::CommandEnvironment(xInteraction, xProgress); 644cdf0e10cSrcweir css::uno::Reference< css::ucb::XCommandEnvironment > xCommandEnv(static_cast< css::ucb::XCommandEnvironment* >(pCommandEnv), css::uno::UNO_QUERY); 645cdf0e10cSrcweir 646cdf0e10cSrcweir // media type 647cdf0e10cSrcweir ::rtl::OUString sMediaType = getUnpackedValueOrDefault(MediaDescriptor::PROP_MEDIATYPE(), ::rtl::OUString()); 648cdf0e10cSrcweir if (!sMediaType.getLength()) 649cdf0e10cSrcweir { 650cdf0e10cSrcweir sMediaType = ::rtl::OUString::createFromAscii("application/x-www-form-urlencoded"); 651cdf0e10cSrcweir (*this)[MediaDescriptor::PROP_MEDIATYPE()] <<= sMediaType; 652cdf0e10cSrcweir } 653cdf0e10cSrcweir 654cdf0e10cSrcweir // url 655cdf0e10cSrcweir ::rtl::OUString sURL( getUnpackedValueOrDefault( PROP_URL(), ::rtl::OUString() ) ); 656cdf0e10cSrcweir 657cdf0e10cSrcweir css::uno::Reference< css::io::XInputStream > xResultStream; 658cdf0e10cSrcweir try 659cdf0e10cSrcweir { 660cdf0e10cSrcweir // seek PostData stream to the beginning 661cdf0e10cSrcweir css::uno::Reference< css::io::XSeekable > xSeek( _rxPostData, css::uno::UNO_QUERY ); 662cdf0e10cSrcweir if ( xSeek.is() ) 663cdf0e10cSrcweir xSeek->seek( 0 ); 664cdf0e10cSrcweir 665cdf0e10cSrcweir // a content for the URL 666cdf0e10cSrcweir ::ucbhelper::Content aContent( sURL, xCommandEnv ); 667cdf0e10cSrcweir 668cdf0e10cSrcweir // use post command 669cdf0e10cSrcweir css::ucb::PostCommandArgument2 aPostArgument; 670cdf0e10cSrcweir aPostArgument.Source = _rxPostData; 671cdf0e10cSrcweir css::uno::Reference< css::io::XActiveDataSink > xSink( new ucbhelper::ActiveDataSink ); 672cdf0e10cSrcweir aPostArgument.Sink = xSink; 673cdf0e10cSrcweir aPostArgument.MediaType = sMediaType; 674cdf0e10cSrcweir aPostArgument.Referer = getUnpackedValueOrDefault( PROP_REFERRER(), ::rtl::OUString() ); 675cdf0e10cSrcweir 676cdf0e10cSrcweir ::rtl::OUString sCommandName( RTL_CONSTASCII_USTRINGPARAM( "post" ) ); 677cdf0e10cSrcweir aContent.executeCommand( sCommandName, css::uno::makeAny( aPostArgument ) ); 678cdf0e10cSrcweir 679cdf0e10cSrcweir // get result 680cdf0e10cSrcweir xResultStream = xSink->getInputStream(); 681cdf0e10cSrcweir } 682cdf0e10cSrcweir catch( const css::uno::Exception& ) 683cdf0e10cSrcweir { 684cdf0e10cSrcweir } 685cdf0e10cSrcweir 686cdf0e10cSrcweir // success? 687cdf0e10cSrcweir if ( !xResultStream.is() ) 688cdf0e10cSrcweir { 689cdf0e10cSrcweir OSL_ENSURE( false, "no valid reply to the HTTP-Post" ); 690cdf0e10cSrcweir return sal_False; 691cdf0e10cSrcweir } 692cdf0e10cSrcweir 693cdf0e10cSrcweir (*this)[MediaDescriptor::PROP_INPUTSTREAM()] <<= xResultStream; 694cdf0e10cSrcweir return sal_True; 695cdf0e10cSrcweir } 696cdf0e10cSrcweir 697cdf0e10cSrcweir /*-----------------------------------------------*/ 698cdf0e10cSrcweir 699cdf0e10cSrcweir /*----------------------------------------------- 700cdf0e10cSrcweir 25.03.2004 12:29 701cdf0e10cSrcweir -----------------------------------------------*/ 702cdf0e10cSrcweir sal_Bool MediaDescriptor::impl_openStreamWithURL( const ::rtl::OUString& sURL, sal_Bool bLockFile ) 703cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 704cdf0e10cSrcweir { 705cdf0e10cSrcweir // prepare the environment 706cdf0e10cSrcweir css::uno::Reference< css::task::XInteractionHandler > xOrgInteraction = getUnpackedValueOrDefault( 707cdf0e10cSrcweir MediaDescriptor::PROP_INTERACTIONHANDLER(), 708cdf0e10cSrcweir css::uno::Reference< css::task::XInteractionHandler >()); 709cdf0e10cSrcweir 710cdf0e10cSrcweir StillReadWriteInteraction* pInteraction = new StillReadWriteInteraction(xOrgInteraction); 711cdf0e10cSrcweir css::uno::Reference< css::task::XInteractionHandler > xInteraction(static_cast< css::task::XInteractionHandler* >(pInteraction), css::uno::UNO_QUERY); 712cdf0e10cSrcweir 713cdf0e10cSrcweir css::uno::Reference< css::ucb::XProgressHandler > xProgress; 714cdf0e10cSrcweir ::ucbhelper::CommandEnvironment* pCommandEnv = new ::ucbhelper::CommandEnvironment(xInteraction, xProgress); 715cdf0e10cSrcweir css::uno::Reference< css::ucb::XCommandEnvironment > xCommandEnv(static_cast< css::ucb::XCommandEnvironment* >(pCommandEnv), css::uno::UNO_QUERY); 716cdf0e10cSrcweir 717cdf0e10cSrcweir // try to create the content 718cdf0e10cSrcweir // no content -> no stream => return immediatly with FALSE 719cdf0e10cSrcweir ::ucbhelper::Content aContent; 720cdf0e10cSrcweir css::uno::Reference< css::ucb::XContent > xContent; 721cdf0e10cSrcweir try 722cdf0e10cSrcweir { 723cdf0e10cSrcweir aContent = ::ucbhelper::Content(sURL, xCommandEnv); 724cdf0e10cSrcweir xContent = aContent.get(); 725cdf0e10cSrcweir } 726cdf0e10cSrcweir catch(const css::uno::RuntimeException&) 727cdf0e10cSrcweir { throw; } 728cdf0e10cSrcweir catch(const css::ucb::ContentCreationException&) 729cdf0e10cSrcweir { return sal_False; } // TODO error handling 730cdf0e10cSrcweir catch(const css::uno::Exception&) 731cdf0e10cSrcweir { return sal_False; } // TODO error handling 732cdf0e10cSrcweir 733cdf0e10cSrcweir // try to open the file in read/write mode 734cdf0e10cSrcweir // (if its allowed to do so). 735cdf0e10cSrcweir // But handle errors in a "hidden mode". Because 736cdf0e10cSrcweir // we try it readonly later - if read/write isnt an option. 737cdf0e10cSrcweir css::uno::Reference< css::io::XStream > xStream ; 738cdf0e10cSrcweir css::uno::Reference< css::io::XInputStream > xInputStream; 739cdf0e10cSrcweir 740cdf0e10cSrcweir sal_Bool bReadOnly = sal_False; 741cdf0e10cSrcweir sal_Bool bModeRequestedExplicitly = sal_False; 742cdf0e10cSrcweir const_iterator pIt = find(MediaDescriptor::PROP_READONLY()); 743cdf0e10cSrcweir if (pIt != end()) 744cdf0e10cSrcweir { 745cdf0e10cSrcweir pIt->second >>= bReadOnly; 746cdf0e10cSrcweir bModeRequestedExplicitly = sal_True; 747cdf0e10cSrcweir } 748cdf0e10cSrcweir 749cdf0e10cSrcweir if ( !bReadOnly && bLockFile ) 750cdf0e10cSrcweir { 751cdf0e10cSrcweir try 752cdf0e10cSrcweir { 753cdf0e10cSrcweir // TODO: use "special" still interaction to supress error messages 754cdf0e10cSrcweir xStream = aContent.openWriteableStream(); 755cdf0e10cSrcweir if (xStream.is()) 756cdf0e10cSrcweir xInputStream = xStream->getInputStream(); 757cdf0e10cSrcweir } 758cdf0e10cSrcweir catch(const css::uno::RuntimeException&) 759cdf0e10cSrcweir { throw; } 760cdf0e10cSrcweir catch(const css::uno::Exception&) 761cdf0e10cSrcweir { 762cdf0e10cSrcweir // ignore exception, if reason was problem reasoned on 763cdf0e10cSrcweir // open it in WRITEABLE mode! Then we try it READONLY 764cdf0e10cSrcweir // later a second time. 765cdf0e10cSrcweir // All other errors must be handled as real error an 766cdf0e10cSrcweir // break this method. 767cdf0e10cSrcweir if (!pInteraction->wasWriteError() || bModeRequestedExplicitly) 768cdf0e10cSrcweir return sal_False; 769cdf0e10cSrcweir xStream.clear(); 770cdf0e10cSrcweir xInputStream.clear(); 771cdf0e10cSrcweir } 772cdf0e10cSrcweir } 773cdf0e10cSrcweir 774cdf0e10cSrcweir // If opening of the stream in read/write mode wasnt allowed 775cdf0e10cSrcweir // or failed by an error - we must try it in readonly mode. 776cdf0e10cSrcweir if (!xInputStream.is()) 777cdf0e10cSrcweir { 778cdf0e10cSrcweir rtl::OUString aScheme; 779cdf0e10cSrcweir 780cdf0e10cSrcweir try 781cdf0e10cSrcweir { 782cdf0e10cSrcweir css::uno::Reference< css::ucb::XContentIdentifier > xContId( 783cdf0e10cSrcweir aContent.get().is() ? aContent.get()->getIdentifier() : 0 ); 784cdf0e10cSrcweir 785cdf0e10cSrcweir if ( xContId.is() ) 786cdf0e10cSrcweir aScheme = xContId->getContentProviderScheme(); 787cdf0e10cSrcweir 788cdf0e10cSrcweir // Only file system content provider is able to provide XStream 789cdf0e10cSrcweir // so for this content impossibility to create XStream triggers 790cdf0e10cSrcweir // switch to readonly mode in case of opening with locking on 791cdf0e10cSrcweir if( bLockFile && aScheme.equalsIgnoreAsciiCaseAscii( "file" ) ) 792cdf0e10cSrcweir bReadOnly = sal_True; 793cdf0e10cSrcweir else 794cdf0e10cSrcweir { 795cdf0e10cSrcweir sal_Bool bRequestReadOnly = bReadOnly; 796cdf0e10cSrcweir aContent.getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsReadOnly" ) ) ) >>= bReadOnly; 797cdf0e10cSrcweir if ( bReadOnly && !bRequestReadOnly && bModeRequestedExplicitly ) 798cdf0e10cSrcweir return sal_False; // the document is explicitly requested with WRITEABLE mode 799cdf0e10cSrcweir } 800cdf0e10cSrcweir } 801cdf0e10cSrcweir catch(const css::uno::RuntimeException&) 802cdf0e10cSrcweir { throw; } 803cdf0e10cSrcweir catch(const css::uno::Exception&) 804cdf0e10cSrcweir { /* no error handling if IsReadOnly property does not exist for UCP */ } 805cdf0e10cSrcweir 806cdf0e10cSrcweir if ( bReadOnly ) 807cdf0e10cSrcweir (*this)[MediaDescriptor::PROP_READONLY()] <<= bReadOnly; 808cdf0e10cSrcweir 809cdf0e10cSrcweir pInteraction->resetInterceptions(); 810cdf0e10cSrcweir pInteraction->resetErrorStates(); 811cdf0e10cSrcweir try 812cdf0e10cSrcweir { 813cdf0e10cSrcweir // all the contents except file-URLs should be opened as usual 814cdf0e10cSrcweir if ( bLockFile || !aScheme.equalsIgnoreAsciiCaseAscii( "file" ) ) 815cdf0e10cSrcweir xInputStream = aContent.openStream(); 816cdf0e10cSrcweir else 817cdf0e10cSrcweir xInputStream = aContent.openStreamNoLock(); 818cdf0e10cSrcweir } 819cdf0e10cSrcweir catch(const css::uno::RuntimeException&) 820cdf0e10cSrcweir { throw; } 821cdf0e10cSrcweir catch(const css::uno::Exception&) 822cdf0e10cSrcweir { return sal_False; } 823cdf0e10cSrcweir } 824cdf0e10cSrcweir 825cdf0e10cSrcweir // add streams to the descriptor 826cdf0e10cSrcweir if (xContent.is()) 827cdf0e10cSrcweir (*this)[MediaDescriptor::PROP_UCBCONTENT()] <<= xContent; 828cdf0e10cSrcweir if (xStream.is()) 829cdf0e10cSrcweir (*this)[MediaDescriptor::PROP_STREAM()] <<= xStream; 830cdf0e10cSrcweir if (xInputStream.is()) 831cdf0e10cSrcweir (*this)[MediaDescriptor::PROP_INPUTSTREAM()] <<= xInputStream; 832cdf0e10cSrcweir 833cdf0e10cSrcweir // At least we need an input stream. The r/w stream is optional ... 834cdf0e10cSrcweir return xInputStream.is(); 835cdf0e10cSrcweir } 836cdf0e10cSrcweir 837cdf0e10cSrcweir /*----------------------------------------------- 838cdf0e10cSrcweir 10.09.2004 10:51 839cdf0e10cSrcweir -----------------------------------------------*/ 840cdf0e10cSrcweir ::rtl::OUString MediaDescriptor::impl_normalizeURL(const ::rtl::OUString& sURL) 841cdf0e10cSrcweir { 842cdf0e10cSrcweir /* Remove Jumpmarks (fragments) of an URL only here. 843cdf0e10cSrcweir They are not part of any URL and as a result may be 844cdf0e10cSrcweir no ucb content can be created then. 845cdf0e10cSrcweir On the other side arguments must exists ... because 846cdf0e10cSrcweir they are part of an URL. 847cdf0e10cSrcweir 848cdf0e10cSrcweir Do not use the URLTransformer service here. Because 849cdf0e10cSrcweir it parses the URL in another way. It's main part isnt enough 850cdf0e10cSrcweir and it's complete part contains the jumpmark (fragment) parameter ... 851cdf0e10cSrcweir */ 852cdf0e10cSrcweir static ::rtl::OUString SERVICENAME_URIREFERENCEFACTORY = ::rtl::OUString::createFromAscii("com.sun.star.uri.UriReferenceFactory"); 853cdf0e10cSrcweir 854cdf0e10cSrcweir try 855cdf0e10cSrcweir { 856cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory(); 857cdf0e10cSrcweir css::uno::Reference< css::uri::XUriReferenceFactory > xUriFactory(xSMGR->createInstance(SERVICENAME_URIREFERENCEFACTORY), css::uno::UNO_QUERY_THROW); 858cdf0e10cSrcweir css::uno::Reference< css::uri::XUriReference > xUriRef = xUriFactory->parse(sURL); 859cdf0e10cSrcweir if (xUriRef.is()) 860cdf0e10cSrcweir { 861cdf0e10cSrcweir xUriRef->clearFragment(); 862cdf0e10cSrcweir return xUriRef->getUriReference(); 863cdf0e10cSrcweir } 864cdf0e10cSrcweir } 865cdf0e10cSrcweir catch(const css::uno::RuntimeException& exRun) 866cdf0e10cSrcweir { throw exRun; } 867cdf0e10cSrcweir catch(const css::uno::Exception&) 868cdf0e10cSrcweir {} 869cdf0e10cSrcweir 870cdf0e10cSrcweir // If an error ocurred ... return the original URL. 871cdf0e10cSrcweir // It's a try .-) 872cdf0e10cSrcweir return sURL; 873cdf0e10cSrcweir } 874cdf0e10cSrcweir 875cdf0e10cSrcweir } // namespace comphelper 876cdf0e10cSrcweir 877