Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <tools/stream.hxx>
21 : #include <tools/cachestr.hxx>
22 :
23 : #include <sot/storage.hxx>
24 : #include <sot/formats.hxx>
25 :
26 : #include <sfx2/mieclip.hxx>
27 : #include <sfx2/sfxuno.hxx>
28 :
29 0 : MSE40HTMLClipFormatObj::~MSE40HTMLClipFormatObj()
30 : {
31 0 : delete pStrm;
32 0 : }
33 :
34 0 : SvStream* MSE40HTMLClipFormatObj::IsValid( SvStream& rStream )
35 : {
36 0 : bool bRet = false;
37 0 : if( pStrm )
38 0 : delete pStrm, pStrm = 0;
39 :
40 0 : rtl::OString sLine, sVersion;
41 0 : sal_Int32 nStt = -1, nEnd = -1, nFragStart = -1, nFragEnd = -1;
42 0 : sal_Int32 nIndex = 0;
43 :
44 0 : rStream.Seek(STREAM_SEEK_TO_BEGIN);
45 0 : rStream.ResetError();
46 :
47 0 : if( rStream.ReadLine( sLine ) &&
48 0 : sLine.getToken( 0, ':', nIndex ) == "Version" )
49 : {
50 0 : sVersion = sLine.copy( nIndex );
51 0 : while( rStream.ReadLine( sLine ) )
52 : {
53 0 : nIndex = 0;
54 0 : rtl::OString sTmp(sLine.getToken(0, ':', nIndex));
55 0 : if (sTmp.equalsL(RTL_CONSTASCII_STRINGPARAM("StartHTML")))
56 0 : nStt = sLine.copy(nIndex).toInt32();
57 0 : else if (sTmp.equalsL(RTL_CONSTASCII_STRINGPARAM("EndHTML")))
58 0 : nEnd = sLine.copy(nIndex).toInt32();
59 0 : else if (sTmp.equalsL(RTL_CONSTASCII_STRINGPARAM("StartFragment")))
60 0 : nFragStart = sLine.copy(nIndex).toInt32();
61 0 : else if (sTmp.equalsL(RTL_CONSTASCII_STRINGPARAM("EndFragment")))
62 0 : nFragEnd = sLine.copy(nIndex).toInt32();
63 0 : else if (sTmp.equalsL(RTL_CONSTASCII_STRINGPARAM("SourceURL")))
64 0 : sBaseURL = S2U(sLine.copy(nIndex));
65 :
66 0 : if (nEnd >= 0 && nStt >= 0 &&
67 0 : (sBaseURL.Len() || rStream.Tell() >= static_cast<sal_Size>(nStt)))
68 : {
69 0 : bRet = true;
70 : break;
71 : }
72 0 : }
73 : }
74 :
75 0 : if( bRet )
76 : {
77 0 : rStream.Seek( nStt );
78 :
79 : pStrm = new SvCacheStream( ( nEnd - nStt < 0x10000l
80 : ? nEnd - nStt + 32
81 0 : : 0 ));
82 0 : *pStrm << rStream;
83 0 : pStrm->SetStreamSize( nEnd - nStt + 1L );
84 0 : pStrm->Seek( STREAM_SEEK_TO_BEGIN );
85 0 : return pStrm;
86 : }
87 :
88 0 : if (nFragStart > 0 && nFragEnd > 0 && nFragEnd > nFragStart)
89 : {
90 0 : sal_uIntPtr nSize = static_cast<sal_uIntPtr>(nFragEnd - nFragStart + 1);
91 0 : if (nSize < 0x10000L)
92 : {
93 0 : rStream.Seek(nFragStart);
94 0 : pStrm = new SvCacheStream(nSize);
95 0 : *pStrm << rStream;
96 0 : pStrm->SetStreamSize(nSize);
97 0 : pStrm->Seek(STREAM_SEEK_TO_BEGIN);
98 0 : return pStrm;
99 : }
100 : }
101 :
102 0 : return NULL;
103 : }
104 :
105 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|