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 @@ ...@@ -26,6 +26,8 @@
#include <rtl/textenc.h> #include <rtl/textenc.h>
#include <sal/types.h> #include <sal/types.h>
class SvMemoryStream;
namespace com { namespace sun { namespace star { namespace util { namespace com { namespace sun { namespace star { namespace util {
class XStringWidth; class XStringWidth;
} } } } } } } }
...@@ -851,6 +853,9 @@ public: ...@@ -851,6 +853,9 @@ public:
OUString getFSysPath(FSysStyle eStyle, sal_Unicode * pDelimiter = 0) OUString getFSysPath(FSysStyle eStyle, sal_Unicode * pDelimiter = 0)
const; const;
// Data URLs:
SvMemoryStream* getData();
// POP3 and URLs: // POP3 and URLs:
OUString GetMsgId(DecodeMechanism eMechanism = DECODE_TO_IURI, OUString GetMsgId(DecodeMechanism eMechanism = DECODE_TO_IURI,
......
...@@ -67,8 +67,8 @@ ...@@ -67,8 +67,8 @@
#include <numrule.hxx> #include <numrule.hxx>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <sax/tools/converter.hxx>
#include <vcl/graphicfilter.hxx> #include <vcl/graphicfilter.hxx>
#include <tools/urlobj.hxx>
using namespace ::com::sun::star; using namespace ::com::sun::star;
...@@ -695,16 +695,18 @@ IMAGE_SETEVENT: ...@@ -695,16 +695,18 @@ IMAGE_SETEVENT:
aFrmSet.Put( aFrmSize ); aFrmSet.Put( aFrmSize );
Graphic aEmptyGrf; Graphic aEmptyGrf;
if( sGrfNm.startsWith("data:") ) INetURLObject aGraphicURL( sGrfNm );
if( aGraphicURL.GetProtocol() == INET_PROT_DATA )
{ {
// use embedded base64 encoded data SvMemoryStream* aStream = aGraphicURL.getData();
::com::sun::star::uno::Sequence< sal_Int8 > aPass; if( aStream )
OUString sBase64Data = sGrfNm.replaceAt(0,22,"");
::sax::Converter::decodeBase64(aPass, sBase64Data);
if( aPass.hasElements() )
{ {
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 else
......
...@@ -38,6 +38,7 @@ $(eval $(call gb_Library_use_libraries,tl,\ ...@@ -38,6 +38,7 @@ $(eval $(call gb_Library_use_libraries,tl,\
i18nlangtag \ i18nlangtag \
cppu \ cppu \
sal \ sal \
sax \
$(gb_UWINAPI) \ $(gb_UWINAPI) \
)) ))
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <tools/urlobj.hxx> #include <tools/urlobj.hxx>
#include <tools/debug.hxx> #include <tools/debug.hxx>
#include <tools/inetmime.hxx> #include <tools/inetmime.hxx>
#include <tools/stream.hxx>
#include <com/sun/star/uno/Reference.hxx> #include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/util/XStringWidth.hpp> #include <com/sun/star/util/XStringWidth.hpp>
#include <osl/diagnose.h> #include <osl/diagnose.h>
...@@ -37,6 +38,10 @@ ...@@ -37,6 +38,10 @@
#include <string.h> #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; namespace unnamed_tools_urlobj {} using namespace unnamed_tools_urlobj;
// unnamed namespaces don't work well yet... // unnamed namespaces don't work well yet...
...@@ -583,6 +588,44 @@ void INetURLObject::setInvalid() ...@@ -583,6 +588,44 @@ void INetURLObject::setInvalid()
m_aFragment.clear(); 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 { namespace unnamed_tools_urlobj {
INetURLObject::FSysStyle guessFSysStyleByCounting(sal_Unicode const * pBegin, 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