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 :
22 : #include <sot/storage.hxx>
23 : #include <sot/formats.hxx>
24 :
25 : #include <sfx2/mieclip.hxx>
26 : #include <sfx2/sfxuno.hxx>
27 :
28 0 : MSE40HTMLClipFormatObj::~MSE40HTMLClipFormatObj()
29 : {
30 0 : delete pStrm;
31 0 : }
32 :
33 0 : SvStream* MSE40HTMLClipFormatObj::IsValid( SvStream& rStream )
34 : {
35 0 : bool bRet = false;
36 0 : if( pStrm )
37 0 : delete pStrm, pStrm = 0;
38 :
39 0 : OString sLine, sVersion;
40 0 : sal_Int32 nStt = -1, nEnd = -1, nFragStart = -1, nFragEnd = -1;
41 0 : sal_Int32 nIndex = 0;
42 :
43 0 : rStream.Seek(STREAM_SEEK_TO_BEGIN);
44 0 : rStream.ResetError();
45 :
46 0 : if( rStream.ReadLine( sLine ) &&
47 0 : sLine.getToken( 0, ':', nIndex ) == "Version" )
48 : {
49 0 : sVersion = sLine.copy( nIndex );
50 0 : while( rStream.ReadLine( sLine ) )
51 : {
52 0 : nIndex = 0;
53 0 : OString sTmp(sLine.getToken(0, ':', nIndex));
54 0 : if (sTmp == "StartHTML")
55 0 : nStt = sLine.copy(nIndex).toInt32();
56 0 : else if (sTmp == "EndHTML")
57 0 : nEnd = sLine.copy(nIndex).toInt32();
58 0 : else if (sTmp == "StartFragment")
59 0 : nFragStart = sLine.copy(nIndex).toInt32();
60 0 : else if (sTmp == "EndFragment")
61 0 : nFragEnd = sLine.copy(nIndex).toInt32();
62 0 : else if (sTmp == "SourceURL")
63 0 : sBaseURL = OStringToOUString( sLine.copy(nIndex), RTL_TEXTENCODING_UTF8 );
64 :
65 0 : if (nEnd >= 0 && nStt >= 0 &&
66 0 : (!sBaseURL.isEmpty() || rStream.Tell() >= static_cast<sal_Size>(nStt)))
67 : {
68 0 : bRet = true;
69 0 : break;
70 : }
71 0 : }
72 : }
73 :
74 0 : if( bRet )
75 : {
76 0 : rStream.Seek( nStt );
77 :
78 0 : pStrm = new SvMemoryStream( ( nEnd - nStt < 0x10000l
79 0 : ? nEnd - nStt + 32
80 0 : : 0 ));
81 0 : pStrm->WriteStream( rStream );
82 0 : pStrm->SetStreamSize( nEnd - nStt + 1L );
83 0 : pStrm->Seek( STREAM_SEEK_TO_BEGIN );
84 0 : return pStrm;
85 : }
86 :
87 0 : if (nFragStart > 0 && nFragEnd > 0 && nFragEnd > nFragStart)
88 : {
89 0 : sal_uIntPtr nSize = static_cast<sal_uIntPtr>(nFragEnd - nFragStart + 1);
90 0 : if (nSize < 0x10000L)
91 : {
92 0 : rStream.Seek(nFragStart);
93 0 : pStrm = new SvMemoryStream(nSize);
94 0 : pStrm->WriteStream( rStream );
95 0 : pStrm->SetStreamSize(nSize);
96 0 : pStrm->Seek(STREAM_SEEK_TO_BEGIN);
97 0 : return pStrm;
98 : }
99 : }
100 :
101 0 : return NULL;
102 : }
103 :
104 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|