Kaydet (Commit) 8b46d5c8 authored tarafından Chr. Rossmanith's avatar Chr. Rossmanith Kaydeden (comit) Stephan Bergmann

new method INetURLObject::getData() for data urls

Signed-off-by: 's avatarStephan Bergmann <sbergman@redhat.com>

Conflicts:
	tools/source/fsys/urlobj.cxx

Change-Id: I59b5b95cf9b65920ec04922fdb25e4228fd22995
üst 44f42204
......@@ -26,6 +26,8 @@
#include <rtl/textenc.h>
#include <sal/types.h>
class SvMemoryStream;
namespace com { namespace sun { namespace star { namespace util {
class XStringWidth;
} } } }
......@@ -851,6 +853,9 @@ public:
OUString getFSysPath(FSysStyle eStyle, sal_Unicode * pDelimiter = 0)
const;
// Data URLs:
SvMemoryStream* getData();
// POP3 and URLs:
OUString GetMsgId(DecodeMechanism eMechanism = DECODE_TO_IURI,
......
......@@ -67,8 +67,8 @@
#include <numrule.hxx>
#include <boost/shared_ptr.hpp>
#include <sax/tools/converter.hxx>
#include <vcl/graphicfilter.hxx>
#include <tools/urlobj.hxx>
using namespace ::com::sun::star;
......@@ -695,16 +695,18 @@ IMAGE_SETEVENT:
aFrmSet.Put( aFrmSize );
Graphic aEmptyGrf;
if( sGrfNm.startsWith("data:") )
INetURLObject aGraphicURL( sGrfNm );
if( aGraphicURL.GetProtocol() == INET_PROT_DATA )
{
// use embedded base64 encoded data
::com::sun::star::uno::Sequence< sal_Int8 > aPass;
OUString sBase64Data = sGrfNm.replaceAt(0,22,"");
::sax::Converter::decodeBase64(aPass, sBase64Data);
if( aPass.hasElements() )
SvMemoryStream* aStream = aGraphicURL.getData();
if( aStream )
{
SvMemoryStream aStream(aPass.getArray(), aPass.getLength(), STREAM_READ);
GraphicFilter::GetGraphicFilter().ImportGraphic( aEmptyGrf, OUString(), aStream );
GraphicFilter::GetGraphicFilter().ImportGraphic( aEmptyGrf, OUString(), *aStream );
free( aStream );
}
else
{
aEmptyGrf.SetDefaultType();
}
}
else
......
......@@ -38,6 +38,7 @@ $(eval $(call gb_Library_use_libraries,tl,\
i18nlangtag \
cppu \
sal \
sax \
$(gb_UWINAPI) \
))
......
......@@ -20,6 +20,7 @@
#include <tools/urlobj.hxx>
#include <tools/debug.hxx>
#include <tools/inetmime.hxx>
#include <tools/stream.hxx>
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/util/XStringWidth.hpp>
#include <osl/diagnose.h>
......@@ -37,6 +38,10 @@
#include <string.h>
#include <com/sun/star/uno/Sequence.hxx>
#include <sax/tools/converter.hxx>
#include <rtl/uri.hxx>
namespace unnamed_tools_urlobj {} using namespace unnamed_tools_urlobj;
// unnamed namespaces don't work well yet...
......@@ -583,6 +588,44 @@ void INetURLObject::setInvalid()
m_aFragment.clear();
}
SvMemoryStream* INetURLObject::getData()
{
if( GetProtocol() != INET_PROT_DATA )
{
return NULL;
}
OUString sURLPath = GetURLPath( DECODE_WITH_CHARSET, RTL_TEXTENCODING_ISO_8859_1 );
OUString sType, sSubType;
OUString sBase64Enc(";base64,");
INetContentTypeParameterList params;
sal_Unicode const * pSkippedMediatype = INetMIME::scanContentType( sURLPath.getStr(), sURLPath.getStr() + sURLPath.getLength(), &sType, &sSubType, &params );
sal_Int32 nCharactersSkipped = pSkippedMediatype-sURLPath.getStr();
sal_Int32 nCommaIndex = sURLPath.indexOf( ",", nCharactersSkipped );
sal_Int32 nBase64Index = sURLPath.indexOf( sBase64Enc, nCharactersSkipped );
SvMemoryStream* aStream=NULL;
if( nBase64Index >= 0 && nBase64Index < nCommaIndex )
{
// base64 decoding
OUString sBase64Data = sURLPath.copy( nBase64Index + sBase64Enc.getLength() );
css::uno::Sequence< sal_Int8 > aDecodedData;
::sax::Converter::decodeBase64( aDecodedData, sBase64Data );
if( aDecodedData.hasElements() )
{
aStream = new SvMemoryStream( aDecodedData.getArray(), aDecodedData.getLength(), STREAM_READ );
}
}
else
{
// URL decoding
OUString sURLEncodedData = sURLPath.copy( nCommaIndex+1 );
aStream = new SvMemoryStream( const_cast< sal_Char * >(OUStringToOString(sURLEncodedData, RTL_TEXTENCODING_UTF8).getStr()), sURLEncodedData.getLength(), STREAM_READ);
}
return aStream;
}
namespace unnamed_tools_urlobj {
INetURLObject::FSysStyle guessFSysStyleByCounting(sal_Unicode const * pBegin,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment