/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * 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 .
*/
// 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()) returntrue;
// 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()) returnfalse;
// 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();
OUString aScheme; if (xId.is())
aScheme = xId->getContentProviderScheme();
/*-----------------------------------------------*/ bool MediaDescriptor::impl_addInputStream( bool bLockFile )
{ // check for an already existing stream item first
const_iterator pIt = find(MediaDescriptor::PROP_INPUTSTREAM); if (pIt != end()) returntrue;
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;
// b) ... or we must get it from the given URL
OUString sURL = getUnpackedValueOrDefault(MediaDescriptor::PROP_URL, OUString()); if (sURL.isEmpty()) throw css::uno::Exception(u"Found no URL."_ustr,
css::uno::Reference< css::uno::XInterface >());
rtl::Reference<comphelper::StillReadWriteInteraction> xInteraction = new comphelper::StillReadWriteInteraction(xOrgInteraction,xAuthenticationInteraction);
css::uno::Reference< css::ucb::XProgressHandler > xProgress;
rtl::Reference<::ucbhelper::CommandEnvironment> xCommandEnv = new ::ucbhelper::CommandEnvironment(xInteraction, xProgress);
// try to open the file in read/write mode // (if it's allowed to do so). // But handle errors in a "hidden mode". Because // we try it readonly later - if read/write is not an option.
css::uno::Reference< css::io::XStream > xStream;
css::uno::Reference< css::io::XInputStream > xInputStream;
if ( !bReadOnly && bLockFile )
{ try
{ // TODO: use "special" still interaction to suppress error messages
xStream = aContent.openWriteableStream(); if (xStream.is())
xInputStream = xStream->getInputStream();
} catch(const css::uno::RuntimeException&)
{ throw; } catch(const css::uno::Exception&)
{
css::uno::Any ex( cppu::getCaughtException() ); // ignore exception, if reason was problem reasoned on // open it in WRITABLE mode! Then we try it READONLY // later a second time. // All other errors must be handled as real error an // break this method. if (!xInteraction->wasWriteError() || bModeRequestedExplicitly)
{
SAL_WARN("unotools.misc","url: '" << sURL << "' " << exceptionToString(ex)); // If the protocol is webdav, then we need to treat the stream as readonly, even if the // operation was requested as read/write explicitly (the WebDAV UCB implementation is monodirectional // read or write not both at the same time). if ( !INetURLObject( sURL ).isAnyKnownWebDAVScheme() ) returnfalse;
}
xStream.clear();
xInputStream.clear();
}
}
// If opening of the stream in read/write mode was not allowed // or failed by an error - we must try it in readonly mode. if (!xInputStream.is())
{
OUString aScheme;
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 if( bLockFile && aScheme.equalsIgnoreAsciiCase("file") )
bReadOnly = true; else
{ bool bRequestReadOnly = bReadOnly;
aContent.getPropertyValue(u"IsReadOnly"_ustr) >>= bReadOnly; if ( bReadOnly && !bRequestReadOnly && bModeRequestedExplicitly ) returnfalse; // the document is explicitly requested with WRITABLE 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;
xInteraction->resetInterceptions();
xInteraction->resetErrorStates(); try
{ // all the contents except file-URLs should be opened as usual if ( bLockFile || !aScheme.equalsIgnoreAsciiCase("file") )
xInputStream = aContent.openStream(); else
xInputStream = aContent.openStreamNoLock();
} catch(const css::uno::RuntimeException&)
{ throw;
} catch(const css::uno::Exception&)
{
TOOLS_INFO_EXCEPTION("unotools.misc","url: '" << sURL << "'"); returnfalse;
}
}
// 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();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.