Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / sfx2 / source / bastyp / mieclip.cxx
blob01edabde114aeddd82792f90ce6ed666d611650e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <tools/stream.hxx>
30 #include <tools/cachestr.hxx>
32 #include <sot/storage.hxx>
33 #include <sot/formats.hxx>
35 #include <sfx2/mieclip.hxx>
36 #include <sfx2/sfxuno.hxx>
38 MSE40HTMLClipFormatObj::~MSE40HTMLClipFormatObj()
40 delete pStrm;
43 SvStream* MSE40HTMLClipFormatObj::IsValid( SvStream& rStream )
45 bool bRet = false;
46 if( pStrm )
47 delete pStrm, pStrm = 0;
49 rtl::OString sLine, sVersion;
50 sal_Int32 nStt = -1, nEnd = -1, nFragStart = -1, nFragEnd = -1;
51 sal_Int32 nIndex = 0;
53 rStream.Seek(STREAM_SEEK_TO_BEGIN);
54 rStream.ResetError();
56 if( rStream.ReadLine( sLine ) &&
57 sLine.getToken( 0, ':', nIndex ) == "Version" )
59 sVersion = sLine.copy( nIndex );
60 while( rStream.ReadLine( sLine ) )
62 nIndex = 0;
63 rtl::OString sTmp(sLine.getToken(0, ':', nIndex));
64 if (sTmp.equalsL(RTL_CONSTASCII_STRINGPARAM("StartHTML")))
65 nStt = sLine.copy(nIndex).toInt32();
66 else if (sTmp.equalsL(RTL_CONSTASCII_STRINGPARAM("EndHTML")))
67 nEnd = sLine.copy(nIndex).toInt32();
68 else if (sTmp.equalsL(RTL_CONSTASCII_STRINGPARAM("StartFragment")))
69 nFragStart = sLine.copy(nIndex).toInt32();
70 else if (sTmp.equalsL(RTL_CONSTASCII_STRINGPARAM("EndFragment")))
71 nFragEnd = sLine.copy(nIndex).toInt32();
72 else if (sTmp.equalsL(RTL_CONSTASCII_STRINGPARAM("SourceURL")))
73 sBaseURL = S2U(sLine.copy(nIndex));
75 if (nEnd >= 0 && nStt >= 0 &&
76 (sBaseURL.Len() || rStream.Tell() >= static_cast<sal_Size>(nStt)))
78 bRet = true;
79 break;
84 if( bRet )
86 rStream.Seek( nStt );
88 pStrm = new SvCacheStream( ( nEnd - nStt < 0x10000l
89 ? nEnd - nStt + 32
90 : 0 ));
91 *pStrm << rStream;
92 pStrm->SetStreamSize( nEnd - nStt + 1L );
93 pStrm->Seek( STREAM_SEEK_TO_BEGIN );
94 return pStrm;
97 if (nFragStart > 0 && nFragEnd > 0 && nFragEnd > nFragStart)
99 sal_uIntPtr nSize = static_cast<sal_uIntPtr>(nFragEnd - nFragStart + 1);
100 if (nSize < 0x10000L)
102 rStream.Seek(nFragStart);
103 pStrm = new SvCacheStream(nSize);
104 *pStrm << rStream;
105 pStrm->SetStreamSize(nSize);
106 pStrm->Seek(STREAM_SEEK_TO_BEGIN);
107 return pStrm;
111 return NULL;
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */