2010-10-14 08:27:31 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-29 14:02:24 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2010-06-18 13:43:12 +02:00
|
|
|
|
|
|
|
#include <comphelper/mediadescriptor.hxx>
|
2010-08-30 14:34:00 +02:00
|
|
|
#include <comphelper/namedvaluecollection.hxx>
|
2010-06-18 13:43:12 +02:00
|
|
|
#include <comphelper/stillreadwriteinteraction.hxx>
|
|
|
|
|
|
|
|
#include <com/sun/star/ucb/XContent.hpp>
|
|
|
|
#include <com/sun/star/ucb/XCommandEnvironment.hpp>
|
|
|
|
#include <com/sun/star/task/XInteractionHandler.hpp>
|
|
|
|
#include <com/sun/star/io/XStream.hpp>
|
|
|
|
#include <com/sun/star/io/XActiveDataSink.hpp>
|
|
|
|
#include <com/sun/star/io/XSeekable.hpp>
|
|
|
|
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
|
|
|
#include <com/sun/star/lang/IllegalArgumentException.hpp>
|
|
|
|
#include <com/sun/star/util/XURLTransformer.hpp>
|
|
|
|
#include <com/sun/star/ucb/InteractiveIOException.hpp>
|
|
|
|
#include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
|
|
|
|
#include <com/sun/star/ucb/CommandFailedException.hpp>
|
|
|
|
#include <com/sun/star/task/XInteractionAbort.hpp>
|
2012-10-12 08:57:24 +02:00
|
|
|
#include <com/sun/star/uri/UriReferenceFactory.hpp>
|
2010-06-18 13:43:12 +02:00
|
|
|
#include <com/sun/star/uri/XUriReference.hpp>
|
|
|
|
#include <com/sun/star/ucb/PostCommandArgument2.hpp>
|
|
|
|
#include <com/sun/star/container/XNameAccess.hpp>
|
2012-02-13 22:15:02 +01:00
|
|
|
#include <officecfg/Office/Common.hxx>
|
2010-06-18 13:43:12 +02:00
|
|
|
#include <ucbhelper/interceptedinteraction.hxx>
|
|
|
|
#include <ucbhelper/content.hxx>
|
|
|
|
#include <ucbhelper/commandenvironment.hxx>
|
|
|
|
#include <ucbhelper/activedatasink.hxx>
|
|
|
|
#include <comphelper/processfactory.hxx>
|
|
|
|
|
|
|
|
#include <rtl/ustrbuf.hxx>
|
|
|
|
|
|
|
|
|
|
|
|
namespace comphelper{
|
|
|
|
|
|
|
|
const ::rtl::OUString& MediaDescriptor::PROP_ABORTED()
|
|
|
|
{
|
2013-01-28 10:16:20 +01:00
|
|
|
static const ::rtl::OUString sProp("Aborted");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ::rtl::OUString& MediaDescriptor::PROP_ASTEMPLATE()
|
|
|
|
{
|
2013-01-28 10:16:20 +01:00
|
|
|
static const ::rtl::OUString sProp("AsTemplate");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ::rtl::OUString& MediaDescriptor::PROP_COMPONENTDATA()
|
|
|
|
{
|
2013-01-28 10:16:20 +01:00
|
|
|
static const ::rtl::OUString sProp("ComponentData");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ::rtl::OUString& MediaDescriptor::PROP_DOCUMENTSERVICE()
|
|
|
|
{
|
2013-01-28 10:16:20 +01:00
|
|
|
static const ::rtl::OUString sProp("DocumentService");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
2010-11-04 17:56:39 +01:00
|
|
|
const ::rtl::OUString& MediaDescriptor::PROP_ENCRYPTIONDATA()
|
|
|
|
{
|
2013-01-28 10:16:20 +01:00
|
|
|
static const ::rtl::OUString sProp("EncryptionData");
|
2010-11-04 17:56:39 +01:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
2010-06-18 13:43:12 +02:00
|
|
|
const ::rtl::OUString& MediaDescriptor::PROP_FILENAME()
|
|
|
|
{
|
2013-01-28 10:16:20 +01:00
|
|
|
static const ::rtl::OUString sProp("FileName");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ::rtl::OUString& MediaDescriptor::PROP_FILTERNAME()
|
|
|
|
{
|
2013-01-28 10:16:20 +01:00
|
|
|
static const ::rtl::OUString sProp("FilterName");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
2012-07-27 22:14:39 -04:00
|
|
|
const OUString& MediaDescriptor::PROP_FILTERPROVIDER()
|
|
|
|
{
|
|
|
|
static const OUString aProp("FilterProvider");
|
|
|
|
return aProp;
|
|
|
|
}
|
|
|
|
|
2010-06-18 13:43:12 +02:00
|
|
|
const ::rtl::OUString& MediaDescriptor::PROP_FILTEROPTIONS()
|
|
|
|
{
|
2013-01-28 10:16:20 +01:00
|
|
|
static const ::rtl::OUString sProp("FilterOptions");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ::rtl::OUString& MediaDescriptor::PROP_FRAME()
|
|
|
|
{
|
2013-01-28 10:16:20 +01:00
|
|
|
static const ::rtl::OUString sProp("Frame");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ::rtl::OUString& MediaDescriptor::PROP_FRAMENAME()
|
|
|
|
{
|
2013-01-28 10:16:20 +01:00
|
|
|
static const ::rtl::OUString sProp("FrameName");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ::rtl::OUString& MediaDescriptor::PROP_HIDDEN()
|
|
|
|
{
|
2013-01-28 10:16:20 +01:00
|
|
|
static const ::rtl::OUString sProp("Hidden");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ::rtl::OUString& MediaDescriptor::PROP_INPUTSTREAM()
|
|
|
|
{
|
2013-01-28 10:16:20 +01:00
|
|
|
static const ::rtl::OUString sProp("InputStream");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ::rtl::OUString& MediaDescriptor::PROP_INTERACTIONHANDLER()
|
|
|
|
{
|
2013-01-28 10:16:20 +01:00
|
|
|
static const ::rtl::OUString sProp("InteractionHandler");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ::rtl::OUString& MediaDescriptor::PROP_JUMPMARK()
|
|
|
|
{
|
2013-01-28 10:16:20 +01:00
|
|
|
static const ::rtl::OUString sProp("JumpMark");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ::rtl::OUString& MediaDescriptor::PROP_MACROEXECUTIONMODE()
|
|
|
|
{
|
2013-01-28 10:16:20 +01:00
|
|
|
static const ::rtl::OUString sProp("MacroExecutionMode");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ::rtl::OUString& MediaDescriptor::PROP_MEDIATYPE()
|
|
|
|
{
|
2013-01-28 10:16:20 +01:00
|
|
|
static const ::rtl::OUString sProp("MediaType");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
2013-01-29 21:41:06 +01:00
|
|
|
const OUString& MediaDescriptor::PROP_MINIMIZED()
|
2010-06-18 13:43:12 +02:00
|
|
|
{
|
2013-01-29 21:41:06 +01:00
|
|
|
static const OUString sProp("Minimized");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
2013-01-29 21:41:06 +01:00
|
|
|
const OUString& MediaDescriptor::PROP_NOAUTOSAVE()
|
2010-06-18 13:43:12 +02:00
|
|
|
{
|
2013-01-29 21:41:06 +01:00
|
|
|
static const OUString sProp("NoAutoSave");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
2013-01-29 21:41:06 +01:00
|
|
|
const OUString& MediaDescriptor::PROP_OPENNEWVIEW()
|
2010-06-18 13:43:12 +02:00
|
|
|
{
|
2013-01-29 21:41:06 +01:00
|
|
|
static const OUString sProp("OpenNewView");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
2013-01-29 21:41:06 +01:00
|
|
|
const OUString& MediaDescriptor::PROP_OUTPUTSTREAM()
|
2010-06-18 13:43:12 +02:00
|
|
|
{
|
2013-01-29 21:41:06 +01:00
|
|
|
static const OUString sProp("OutputStream");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
2013-01-29 21:41:06 +01:00
|
|
|
const OUString& MediaDescriptor::PROP_POSTDATA()
|
2010-06-18 13:43:12 +02:00
|
|
|
{
|
2013-01-29 21:41:06 +01:00
|
|
|
static const OUString sProp("PostData");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
2013-01-29 21:41:06 +01:00
|
|
|
const OUString& MediaDescriptor::PROP_PREVIEW()
|
2010-06-18 13:43:12 +02:00
|
|
|
{
|
2013-01-29 21:41:06 +01:00
|
|
|
static const OUString sProp("Preview");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
2013-01-29 21:41:06 +01:00
|
|
|
const OUString& MediaDescriptor::PROP_READONLY()
|
2010-06-18 13:43:12 +02:00
|
|
|
{
|
2013-01-29 21:41:06 +01:00
|
|
|
static const OUString sProp("ReadOnly");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
2013-01-29 21:41:06 +01:00
|
|
|
const OUString& MediaDescriptor::PROP_REFERRER()
|
2010-06-18 13:43:12 +02:00
|
|
|
{
|
2013-01-29 21:41:06 +01:00
|
|
|
static const OUString sProp("Referer");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
2013-01-29 21:41:06 +01:00
|
|
|
const OUString& MediaDescriptor::PROP_STATUSINDICATOR()
|
2010-06-18 13:43:12 +02:00
|
|
|
{
|
2013-01-29 21:41:06 +01:00
|
|
|
static const OUString sProp("StatusIndicator");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
2013-01-29 21:41:06 +01:00
|
|
|
const OUString& MediaDescriptor::PROP_STREAM()
|
2010-06-18 13:43:12 +02:00
|
|
|
{
|
2013-01-29 21:41:06 +01:00
|
|
|
static const OUString sProp("Stream");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
2013-01-29 21:41:06 +01:00
|
|
|
const OUString& MediaDescriptor::PROP_STREAMFOROUTPUT()
|
2010-06-18 13:43:12 +02:00
|
|
|
{
|
2013-01-29 21:41:06 +01:00
|
|
|
static const OUString sProp("StreamForOutput");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
2013-01-29 21:41:06 +01:00
|
|
|
const OUString& MediaDescriptor::PROP_TEMPLATENAME()
|
2010-06-18 13:43:12 +02:00
|
|
|
{
|
2013-01-29 21:41:06 +01:00
|
|
|
static const OUString sProp("TemplateName");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
2013-01-29 21:41:06 +01:00
|
|
|
const OUString& MediaDescriptor::PROP_TYPENAME()
|
2010-06-18 13:43:12 +02:00
|
|
|
{
|
2013-01-29 21:41:06 +01:00
|
|
|
static const OUString sProp("TypeName");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
2013-01-29 21:41:06 +01:00
|
|
|
const OUString& MediaDescriptor::PROP_UCBCONTENT()
|
2010-06-18 13:43:12 +02:00
|
|
|
{
|
2013-01-29 21:41:06 +01:00
|
|
|
static const OUString sProp("UCBContent");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
2013-01-29 21:41:06 +01:00
|
|
|
const OUString& MediaDescriptor::PROP_UPDATEDOCMODE()
|
2010-06-18 13:43:12 +02:00
|
|
|
{
|
2013-01-29 21:41:06 +01:00
|
|
|
static const OUString sProp("UpdateDocMode");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
2013-01-29 21:41:06 +01:00
|
|
|
const OUString& MediaDescriptor::PROP_URL()
|
2010-06-18 13:43:12 +02:00
|
|
|
{
|
2013-01-29 21:41:06 +01:00
|
|
|
static const OUString sProp("URL");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
2013-01-29 21:41:06 +01:00
|
|
|
const OUString& MediaDescriptor::PROP_VERSION()
|
2010-06-18 13:43:12 +02:00
|
|
|
{
|
2013-01-29 21:41:06 +01:00
|
|
|
static const OUString sProp("Version");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
2013-01-29 21:41:06 +01:00
|
|
|
const OUString& MediaDescriptor::PROP_DOCUMENTTITLE()
|
2010-06-18 13:43:12 +02:00
|
|
|
{
|
2013-01-29 21:41:06 +01:00
|
|
|
static const OUString sProp("DocumentTitle");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
2013-01-29 21:41:06 +01:00
|
|
|
const OUString& MediaDescriptor::PROP_MODEL()
|
2010-06-18 13:43:12 +02:00
|
|
|
{
|
2013-01-29 21:41:06 +01:00
|
|
|
static const OUString sProp("Model");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
2013-01-29 21:41:06 +01:00
|
|
|
const OUString& MediaDescriptor::PROP_PASSWORD()
|
2010-06-18 13:43:12 +02:00
|
|
|
{
|
2013-01-29 21:41:06 +01:00
|
|
|
static const OUString sProp("Password");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
2013-01-29 21:41:06 +01:00
|
|
|
const OUString& MediaDescriptor::PROP_TITLE()
|
2010-06-18 13:43:12 +02:00
|
|
|
{
|
2013-01-29 21:41:06 +01:00
|
|
|
static const OUString sProp("Title");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
2013-01-29 21:41:06 +01:00
|
|
|
const OUString& MediaDescriptor::PROP_SALVAGEDFILE()
|
2010-06-18 13:43:12 +02:00
|
|
|
{
|
2013-01-29 21:41:06 +01:00
|
|
|
static const OUString sProp("SalvagedFile");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
2013-01-29 21:41:06 +01:00
|
|
|
const OUString& MediaDescriptor::PROP_VIEWONLY()
|
2010-06-18 13:43:12 +02:00
|
|
|
{
|
2013-01-29 21:41:06 +01:00
|
|
|
static const OUString sProp("ViewOnly");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
2013-01-29 21:41:06 +01:00
|
|
|
const OUString& MediaDescriptor::PROP_DOCUMENTBASEURL()
|
2010-06-18 13:43:12 +02:00
|
|
|
{
|
2013-01-29 21:41:06 +01:00
|
|
|
static const OUString sProp("DocumentBaseURL");
|
2010-06-18 13:43:12 +02:00
|
|
|
return sProp;
|
|
|
|
}
|
|
|
|
|
2013-02-04 14:14:15 -05:00
|
|
|
const OUString& MediaDescriptor::PROP_DEEPDETECTION()
|
|
|
|
{
|
|
|
|
static const OUString aProp("DeepDetection");
|
|
|
|
return aProp;
|
|
|
|
}
|
|
|
|
|
2010-06-18 13:43:12 +02:00
|
|
|
MediaDescriptor::MediaDescriptor()
|
|
|
|
: SequenceAsHashMap()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaDescriptor::MediaDescriptor(const css::uno::Sequence< css::beans::PropertyValue >& lSource)
|
|
|
|
: SequenceAsHashMap(lSource)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool MediaDescriptor::isStreamReadOnly() const
|
|
|
|
{
|
2013-01-29 21:41:06 +01:00
|
|
|
static OUString CONTENTSCHEME_FILE( "file" );
|
|
|
|
static OUString CONTENTPROP_ISREADONLY( "IsReadOnly" );
|
|
|
|
static sal_Bool READONLY_FALLBACK = sal_False;
|
2010-06-18 13:43:12 +02:00
|
|
|
|
|
|
|
sal_Bool bReadOnly = READONLY_FALLBACK;
|
|
|
|
|
|
|
|
// check for explicit readonly state
|
|
|
|
const_iterator pIt = find(MediaDescriptor::PROP_READONLY());
|
|
|
|
if (pIt != end())
|
|
|
|
{
|
|
|
|
pIt->second >>= bReadOnly;
|
|
|
|
return bReadOnly;
|
|
|
|
}
|
|
|
|
|
|
|
|
// streams based on post data are readonly by definition
|
|
|
|
pIt = find(MediaDescriptor::PROP_POSTDATA());
|
|
|
|
if (pIt != end())
|
|
|
|
return sal_True;
|
|
|
|
|
|
|
|
// A XStream capsulate XInputStream and XOutputStream ...
|
|
|
|
// If it exists - the file must be open in read/write mode!
|
|
|
|
pIt = find(MediaDescriptor::PROP_STREAM());
|
|
|
|
if (pIt != end())
|
|
|
|
return sal_False;
|
|
|
|
|
|
|
|
// Only file system content provider is able to provide XStream
|
|
|
|
// so for this content impossibility to create XStream triggers
|
|
|
|
// switch to readonly mode.
|
|
|
|
try
|
|
|
|
{
|
|
|
|
css::uno::Reference< css::ucb::XContent > xContent = getUnpackedValueOrDefault(MediaDescriptor::PROP_UCBCONTENT(), css::uno::Reference< css::ucb::XContent >());
|
|
|
|
if (xContent.is())
|
|
|
|
{
|
|
|
|
css::uno::Reference< css::ucb::XContentIdentifier > xId(xContent->getIdentifier(), css::uno::UNO_QUERY);
|
|
|
|
::rtl::OUString aScheme;
|
|
|
|
if (xId.is())
|
|
|
|
aScheme = xId->getContentProviderScheme();
|
|
|
|
|
|
|
|
if (aScheme.equalsIgnoreAsciiCase(CONTENTSCHEME_FILE))
|
|
|
|
bReadOnly = sal_True;
|
|
|
|
else
|
|
|
|
{
|
2012-09-14 18:08:57 +02:00
|
|
|
::ucbhelper::Content aContent(xContent, css::uno::Reference< css::ucb::XCommandEnvironment >(), getProcessComponentContext());
|
2010-06-18 13:43:12 +02:00
|
|
|
aContent.getPropertyValue(CONTENTPROP_ISREADONLY) >>= bReadOnly;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-05 10:49:59 +01:00
|
|
|
catch(const css::uno::RuntimeException& )
|
|
|
|
{ throw; }
|
2010-06-18 13:43:12 +02:00
|
|
|
catch(const css::uno::Exception&)
|
|
|
|
{}
|
|
|
|
|
|
|
|
return bReadOnly;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
css::uno::Any MediaDescriptor::getComponentDataEntry( const ::rtl::OUString& rName ) const
|
|
|
|
{
|
2010-08-30 14:34:00 +02:00
|
|
|
css::uno::Any aEntry;
|
|
|
|
SequenceAsHashMap::const_iterator aPropertyIter = find( PROP_COMPONENTDATA() );
|
|
|
|
if( aPropertyIter != end() )
|
|
|
|
return NamedValueCollection( aPropertyIter->second ).get( rName );
|
|
|
|
return css::uno::Any();
|
2010-06-18 13:43:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MediaDescriptor::setComponentDataEntry( const ::rtl::OUString& rName, const css::uno::Any& rValue )
|
|
|
|
{
|
|
|
|
if( rValue.hasValue() )
|
|
|
|
{
|
2010-08-30 14:34:00 +02:00
|
|
|
// get or create the 'ComponentData' property entry
|
2010-06-18 13:43:12 +02:00
|
|
|
css::uno::Any& rCompDataAny = operator[]( PROP_COMPONENTDATA() );
|
2010-08-30 14:34:00 +02:00
|
|
|
// insert the value (retain sequence type, create NamedValue elements by default)
|
|
|
|
bool bHasNamedValues = !rCompDataAny.hasValue() || rCompDataAny.has< css::uno::Sequence< css::beans::NamedValue > >();
|
|
|
|
bool bHasPropValues = rCompDataAny.has< css::uno::Sequence< css::beans::PropertyValue > >();
|
|
|
|
OSL_ENSURE( bHasNamedValues || bHasPropValues, "MediaDescriptor::setComponentDataEntry - incompatible 'ComponentData' property in media descriptor" );
|
|
|
|
if( bHasNamedValues || bHasPropValues )
|
2010-06-18 13:43:12 +02:00
|
|
|
{
|
|
|
|
// insert or overwrite the passed value
|
|
|
|
SequenceAsHashMap aCompDataMap( rCompDataAny );
|
|
|
|
aCompDataMap[ rName ] = rValue;
|
2010-08-30 14:34:00 +02:00
|
|
|
// write back the sequence (restore sequence with correct element type)
|
|
|
|
rCompDataAny = aCompDataMap.getAsConstAny( bHasPropValues );
|
2010-06-18 13:43:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// if an empty Any is passed, clear the entry
|
|
|
|
clearComponentDataEntry( rName );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaDescriptor::clearComponentDataEntry( const ::rtl::OUString& rName )
|
|
|
|
{
|
|
|
|
SequenceAsHashMap::iterator aPropertyIter = find( PROP_COMPONENTDATA() );
|
|
|
|
if( aPropertyIter != end() )
|
|
|
|
{
|
2010-08-30 14:34:00 +02:00
|
|
|
css::uno::Any& rCompDataAny = aPropertyIter->second;
|
|
|
|
bool bHasNamedValues = rCompDataAny.has< css::uno::Sequence< css::beans::NamedValue > >();
|
|
|
|
bool bHasPropValues = rCompDataAny.has< css::uno::Sequence< css::beans::PropertyValue > >();
|
|
|
|
OSL_ENSURE( bHasNamedValues || bHasPropValues, "MediaDescriptor::clearComponentDataEntry - incompatible 'ComponentData' property in media descriptor" );
|
|
|
|
if( bHasNamedValues || bHasPropValues )
|
2010-06-18 13:43:12 +02:00
|
|
|
{
|
|
|
|
// remove the value with the passed name
|
2010-08-30 14:34:00 +02:00
|
|
|
SequenceAsHashMap aCompDataMap( rCompDataAny );
|
2010-06-18 13:43:12 +02:00
|
|
|
aCompDataMap.erase( rName );
|
|
|
|
// write back the sequence, or remove it completely if it is empty
|
|
|
|
if( aCompDataMap.empty() )
|
|
|
|
erase( aPropertyIter );
|
|
|
|
else
|
2010-08-30 14:34:00 +02:00
|
|
|
rCompDataAny = aCompDataMap.getAsConstAny( bHasPropValues );
|
2010-06-18 13:43:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool MediaDescriptor::addInputStream()
|
|
|
|
{
|
|
|
|
return impl_addInputStream( sal_True );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-----------------------------------------------*/
|
|
|
|
sal_Bool MediaDescriptor::addInputStreamOwnLock()
|
|
|
|
{
|
2012-02-13 22:15:02 +01:00
|
|
|
return impl_addInputStream(
|
|
|
|
officecfg::Office::Common::Misc::UseDocumentSystemFileLocking::get());
|
2010-06-18 13:43:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-----------------------------------------------*/
|
|
|
|
sal_Bool MediaDescriptor::impl_addInputStream( sal_Bool bLockFile )
|
|
|
|
{
|
|
|
|
// check for an already existing stream item first
|
|
|
|
const_iterator pIt = find(MediaDescriptor::PROP_INPUTSTREAM());
|
|
|
|
if (pIt != end())
|
|
|
|
return sal_True;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// No stream available - create a new one
|
|
|
|
// a) data comes as PostData ...
|
|
|
|
pIt = find(MediaDescriptor::PROP_POSTDATA());
|
|
|
|
if (pIt != end())
|
|
|
|
{
|
|
|
|
const css::uno::Any& rPostData = pIt->second;
|
|
|
|
css::uno::Reference< css::io::XInputStream > xPostData;
|
|
|
|
rPostData >>= xPostData;
|
|
|
|
|
|
|
|
return impl_openStreamWithPostData( xPostData );
|
|
|
|
}
|
|
|
|
|
|
|
|
// b) ... or we must get it from the given URL
|
|
|
|
::rtl::OUString sURL = getUnpackedValueOrDefault(MediaDescriptor::PROP_URL(), ::rtl::OUString());
|
2011-12-12 23:01:55 -02:00
|
|
|
if (sURL.isEmpty())
|
2013-01-29 21:41:06 +01:00
|
|
|
throw css::uno::Exception( OUString( "Found no URL." ),
|
2010-06-18 13:43:12 +02:00
|
|
|
css::uno::Reference< css::uno::XInterface >());
|
|
|
|
|
|
|
|
// Parse URL! Only the main part has to be used further. E.g. a jumpmark can make trouble
|
|
|
|
::rtl::OUString sNormalizedURL = impl_normalizeURL( sURL );
|
|
|
|
return impl_openStreamWithURL( sNormalizedURL, bLockFile );
|
|
|
|
}
|
2011-02-06 13:17:10 +01:00
|
|
|
#if OSL_DEBUG_LEVEL > 0
|
2010-06-18 13:43:12 +02:00
|
|
|
catch(const css::uno::Exception& ex)
|
|
|
|
{
|
|
|
|
::rtl::OUStringBuffer sMsg(256);
|
|
|
|
sMsg.appendAscii("Invalid MediaDescriptor detected:\n");
|
|
|
|
sMsg.append (ex.Message );
|
2011-03-19 14:11:09 +01:00
|
|
|
OSL_FAIL(::rtl::OUStringToOString(sMsg.makeStringAndClear(), RTL_TEXTENCODING_UTF8).getStr());
|
2010-06-18 13:43:12 +02:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
catch(const css::uno::Exception&)
|
|
|
|
{}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return sal_False;
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool MediaDescriptor::impl_openStreamWithPostData( const css::uno::Reference< css::io::XInputStream >& _rxPostData )
|
|
|
|
throw(::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
if ( !_rxPostData.is() )
|
2013-01-29 21:41:06 +01:00
|
|
|
throw css::lang::IllegalArgumentException( OUString( "Found invalid PostData." ),
|
2010-06-18 13:43:12 +02:00
|
|
|
css::uno::Reference< css::uno::XInterface >(), 1);
|
|
|
|
|
|
|
|
// PostData can't be used in read/write mode!
|
|
|
|
(*this)[MediaDescriptor::PROP_READONLY()] <<= sal_True;
|
|
|
|
|
|
|
|
// prepare the environment
|
|
|
|
css::uno::Reference< css::task::XInteractionHandler > xInteraction = getUnpackedValueOrDefault(
|
|
|
|
MediaDescriptor::PROP_INTERACTIONHANDLER(),
|
|
|
|
css::uno::Reference< css::task::XInteractionHandler >());
|
|
|
|
css::uno::Reference< css::ucb::XProgressHandler > xProgress;
|
|
|
|
::ucbhelper::CommandEnvironment* pCommandEnv = new ::ucbhelper::CommandEnvironment(xInteraction, xProgress);
|
|
|
|
css::uno::Reference< css::ucb::XCommandEnvironment > xCommandEnv(static_cast< css::ucb::XCommandEnvironment* >(pCommandEnv), css::uno::UNO_QUERY);
|
|
|
|
|
|
|
|
// media type
|
|
|
|
::rtl::OUString sMediaType = getUnpackedValueOrDefault(MediaDescriptor::PROP_MEDIATYPE(), ::rtl::OUString());
|
2011-12-12 23:01:55 -02:00
|
|
|
if (sMediaType.isEmpty())
|
2010-06-18 13:43:12 +02:00
|
|
|
{
|
2013-01-29 21:41:06 +01:00
|
|
|
sMediaType = "application/x-www-form-urlencoded";
|
2010-06-18 13:43:12 +02:00
|
|
|
(*this)[MediaDescriptor::PROP_MEDIATYPE()] <<= sMediaType;
|
|
|
|
}
|
|
|
|
|
|
|
|
// url
|
2013-01-29 21:41:06 +01:00
|
|
|
OUString sURL( getUnpackedValueOrDefault( PROP_URL(), OUString() ) );
|
2010-06-18 13:43:12 +02:00
|
|
|
|
|
|
|
css::uno::Reference< css::io::XInputStream > xResultStream;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// seek PostData stream to the beginning
|
|
|
|
css::uno::Reference< css::io::XSeekable > xSeek( _rxPostData, css::uno::UNO_QUERY );
|
|
|
|
if ( xSeek.is() )
|
|
|
|
xSeek->seek( 0 );
|
|
|
|
|
|
|
|
// a content for the URL
|
2012-09-14 18:08:57 +02:00
|
|
|
::ucbhelper::Content aContent( sURL, xCommandEnv, getProcessComponentContext() );
|
2010-06-18 13:43:12 +02:00
|
|
|
|
|
|
|
// use post command
|
|
|
|
css::ucb::PostCommandArgument2 aPostArgument;
|
|
|
|
aPostArgument.Source = _rxPostData;
|
|
|
|
css::uno::Reference< css::io::XActiveDataSink > xSink( new ucbhelper::ActiveDataSink );
|
|
|
|
aPostArgument.Sink = xSink;
|
|
|
|
aPostArgument.MediaType = sMediaType;
|
|
|
|
aPostArgument.Referer = getUnpackedValueOrDefault( PROP_REFERRER(), ::rtl::OUString() );
|
|
|
|
|
2013-01-29 21:41:06 +01:00
|
|
|
OUString sCommandName( "post" );
|
2010-06-18 13:43:12 +02:00
|
|
|
aContent.executeCommand( sCommandName, css::uno::makeAny( aPostArgument ) );
|
|
|
|
|
|
|
|
// get result
|
|
|
|
xResultStream = xSink->getInputStream();
|
|
|
|
}
|
|
|
|
catch( const css::uno::Exception& )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// success?
|
|
|
|
if ( !xResultStream.is() )
|
|
|
|
{
|
2011-03-12 11:47:36 +01:00
|
|
|
OSL_FAIL( "no valid reply to the HTTP-Post" );
|
2010-06-18 13:43:12 +02:00
|
|
|
return sal_False;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*this)[MediaDescriptor::PROP_INPUTSTREAM()] <<= xResultStream;
|
|
|
|
return sal_True;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-----------------------------------------------*/
|
2013-01-29 21:41:06 +01:00
|
|
|
sal_Bool MediaDescriptor::impl_openStreamWithURL( const OUString& sURL, sal_Bool bLockFile )
|
2010-06-18 13:43:12 +02:00
|
|
|
throw(::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
// prepare the environment
|
|
|
|
css::uno::Reference< css::task::XInteractionHandler > xOrgInteraction = getUnpackedValueOrDefault(
|
|
|
|
MediaDescriptor::PROP_INTERACTIONHANDLER(),
|
|
|
|
css::uno::Reference< css::task::XInteractionHandler >());
|
|
|
|
|
|
|
|
StillReadWriteInteraction* pInteraction = new StillReadWriteInteraction(xOrgInteraction);
|
|
|
|
css::uno::Reference< css::task::XInteractionHandler > xInteraction(static_cast< css::task::XInteractionHandler* >(pInteraction), css::uno::UNO_QUERY);
|
|
|
|
|
|
|
|
css::uno::Reference< css::ucb::XProgressHandler > xProgress;
|
|
|
|
::ucbhelper::CommandEnvironment* pCommandEnv = new ::ucbhelper::CommandEnvironment(xInteraction, xProgress);
|
|
|
|
css::uno::Reference< css::ucb::XCommandEnvironment > xCommandEnv(static_cast< css::ucb::XCommandEnvironment* >(pCommandEnv), css::uno::UNO_QUERY);
|
|
|
|
|
|
|
|
// try to create the content
|
|
|
|
// no content -> no stream => return immediatly with FALSE
|
|
|
|
::ucbhelper::Content aContent;
|
|
|
|
css::uno::Reference< css::ucb::XContent > xContent;
|
|
|
|
try
|
|
|
|
{
|
2012-09-14 18:08:57 +02:00
|
|
|
aContent = ::ucbhelper::Content(sURL, xCommandEnv, getProcessComponentContext());
|
2010-06-18 13:43:12 +02:00
|
|
|
xContent = aContent.get();
|
|
|
|
}
|
|
|
|
catch(const css::uno::RuntimeException&)
|
|
|
|
{ throw; }
|
|
|
|
catch(const css::ucb::ContentCreationException&)
|
|
|
|
{ return sal_False; } // TODO error handling
|
|
|
|
catch(const css::uno::Exception&)
|
|
|
|
{ return sal_False; } // TODO error handling
|
|
|
|
|
|
|
|
// try to open the file in read/write mode
|
|
|
|
// (if its allowed to do so).
|
|
|
|
// But handle errors in a "hidden mode". Because
|
|
|
|
// we try it readonly later - if read/write isnt an option.
|
|
|
|
css::uno::Reference< css::io::XStream > xStream ;
|
|
|
|
css::uno::Reference< css::io::XInputStream > xInputStream;
|
|
|
|
|
|
|
|
sal_Bool bReadOnly = sal_False;
|
|
|
|
sal_Bool bModeRequestedExplicitly = sal_False;
|
|
|
|
const_iterator pIt = find(MediaDescriptor::PROP_READONLY());
|
|
|
|
if (pIt != end())
|
|
|
|
{
|
|
|
|
pIt->second >>= bReadOnly;
|
|
|
|
bModeRequestedExplicitly = sal_True;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !bReadOnly && bLockFile )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// TODO: use "special" still interaction to supress error messages
|
|
|
|
xStream = aContent.openWriteableStream();
|
|
|
|
if (xStream.is())
|
|
|
|
xInputStream = xStream->getInputStream();
|
|
|
|
}
|
|
|
|
catch(const css::uno::RuntimeException&)
|
|
|
|
{ throw; }
|
|
|
|
catch(const css::uno::Exception&)
|
|
|
|
{
|
|
|
|
// ignore exception, if reason was problem reasoned on
|
|
|
|
// open it in WRITEABLE mode! Then we try it READONLY
|
|
|
|
// later a second time.
|
|
|
|
// All other errors must be handled as real error an
|
|
|
|
// break this method.
|
|
|
|
if (!pInteraction->wasWriteError() || bModeRequestedExplicitly)
|
|
|
|
return sal_False;
|
|
|
|
xStream.clear();
|
|
|
|
xInputStream.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If opening of the stream in read/write mode wasnt allowed
|
|
|
|
// or failed by an error - we must try it in readonly mode.
|
|
|
|
if (!xInputStream.is())
|
|
|
|
{
|
2013-01-29 21:41:06 +01:00
|
|
|
OUString aScheme;
|
2010-06-18 13:43:12 +02:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
css::uno::Reference< css::ucb::XContentIdentifier > xContId(
|
|
|
|
aContent.get().is() ? aContent.get()->getIdentifier() : 0 );
|
|
|
|
|
|
|
|
if ( xContId.is() )
|
|
|
|
aScheme = xContId->getContentProviderScheme();
|
|
|
|
|
|
|
|
// Only file system content provider is able to provide XStream
|
|
|
|
// so for this content impossibility to create XStream triggers
|
|
|
|
// switch to readonly mode in case of opening with locking on
|
2013-01-29 21:41:06 +01:00
|
|
|
if( bLockFile && aScheme.equalsIgnoreAsciiCase("file") )
|
2010-06-18 13:43:12 +02:00
|
|
|
bReadOnly = sal_True;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sal_Bool bRequestReadOnly = bReadOnly;
|
2013-01-29 21:41:06 +01:00
|
|
|
aContent.getPropertyValue( OUString( "IsReadOnly" ) ) >>= bReadOnly;
|
2010-06-18 13:43:12 +02:00
|
|
|
if ( bReadOnly && !bRequestReadOnly && bModeRequestedExplicitly )
|
|
|
|
return sal_False; // the document is explicitly requested with WRITEABLE mode
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(const css::uno::RuntimeException&)
|
|
|
|
{ throw; }
|
|
|
|
catch(const css::uno::Exception&)
|
|
|
|
{ /* no error handling if IsReadOnly property does not exist for UCP */ }
|
|
|
|
|
|
|
|
if ( bReadOnly )
|
|
|
|
(*this)[MediaDescriptor::PROP_READONLY()] <<= bReadOnly;
|
|
|
|
|
|
|
|
pInteraction->resetInterceptions();
|
|
|
|
pInteraction->resetErrorStates();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// all the contents except file-URLs should be opened as usual
|
2013-01-29 21:41:06 +01:00
|
|
|
if ( bLockFile || !aScheme.equalsIgnoreAsciiCase("file") )
|
2010-06-18 13:43:12 +02:00
|
|
|
xInputStream = aContent.openStream();
|
|
|
|
else
|
|
|
|
xInputStream = aContent.openStreamNoLock();
|
|
|
|
}
|
|
|
|
catch(const css::uno::RuntimeException&)
|
|
|
|
{ throw; }
|
|
|
|
catch(const css::uno::Exception&)
|
|
|
|
{ return sal_False; }
|
|
|
|
}
|
|
|
|
|
|
|
|
// add streams to the descriptor
|
|
|
|
if (xContent.is())
|
|
|
|
(*this)[MediaDescriptor::PROP_UCBCONTENT()] <<= xContent;
|
|
|
|
if (xStream.is())
|
|
|
|
(*this)[MediaDescriptor::PROP_STREAM()] <<= xStream;
|
|
|
|
if (xInputStream.is())
|
|
|
|
(*this)[MediaDescriptor::PROP_INPUTSTREAM()] <<= xInputStream;
|
|
|
|
|
|
|
|
// At least we need an input stream. The r/w stream is optional ...
|
|
|
|
return xInputStream.is();
|
|
|
|
}
|
|
|
|
|
|
|
|
::rtl::OUString MediaDescriptor::impl_normalizeURL(const ::rtl::OUString& sURL)
|
|
|
|
{
|
|
|
|
/* Remove Jumpmarks (fragments) of an URL only here.
|
|
|
|
They are not part of any URL and as a result may be
|
|
|
|
no ucb content can be created then.
|
|
|
|
On the other side arguments must exists ... because
|
|
|
|
they are part of an URL.
|
|
|
|
|
|
|
|
Do not use the URLTransformer service here. Because
|
|
|
|
it parses the URL in another way. It's main part isnt enough
|
|
|
|
and it's complete part contains the jumpmark (fragment) parameter ...
|
|
|
|
*/
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2012-10-12 08:57:24 +02:00
|
|
|
css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
|
|
|
|
css::uno::Reference< css::uri::XUriReferenceFactory > xUriFactory = css::uri::UriReferenceFactory::create(xContext);;
|
|
|
|
css::uno::Reference< css::uri::XUriReference > xUriRef = xUriFactory->parse(sURL);
|
2010-06-18 13:43:12 +02:00
|
|
|
if (xUriRef.is())
|
|
|
|
{
|
|
|
|
xUriRef->clearFragment();
|
|
|
|
return xUriRef->getUriReference();
|
|
|
|
}
|
|
|
|
}
|
2012-02-05 10:49:59 +01:00
|
|
|
catch(const css::uno::RuntimeException&)
|
|
|
|
{ throw; }
|
2010-06-18 13:43:12 +02:00
|
|
|
catch(const css::uno::Exception&)
|
|
|
|
{}
|
|
|
|
|
|
|
|
// If an error ocurred ... return the original URL.
|
|
|
|
// It's a try .-)
|
|
|
|
return sURL;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace comphelper
|
|
|
|
|
2010-10-14 08:27:31 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|