1d119d52dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3d119d52dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4d119d52dSAndrew Rist * or more contributor license agreements. See the NOTICE file
5d119d52dSAndrew Rist * distributed with this work for additional information
6d119d52dSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7d119d52dSAndrew Rist * to you under the Apache License, Version 2.0 (the
8d119d52dSAndrew Rist * "License"); you may not use this file except in compliance
9d119d52dSAndrew Rist * with the License. You may obtain a copy of the License at
10d119d52dSAndrew Rist *
11d119d52dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12d119d52dSAndrew Rist *
13d119d52dSAndrew Rist * Unless required by applicable law or agreed to in writing,
14d119d52dSAndrew Rist * software distributed under the License is distributed on an
15d119d52dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16d119d52dSAndrew Rist * KIND, either express or implied. See the License for the
17d119d52dSAndrew Rist * specific language governing permissions and limitations
18d119d52dSAndrew Rist * under the License.
19d119d52dSAndrew Rist *
20d119d52dSAndrew Rist *************************************************************/
21d119d52dSAndrew Rist
22d119d52dSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
26cdf0e10cSrcweir #include <tools/stream.hxx>
27cdf0e10cSrcweir #include <tools/cachestr.hxx>
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include <sot/storage.hxx>
30cdf0e10cSrcweir #include <sot/formats.hxx>
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include <sfx2/mieclip.hxx>
33cdf0e10cSrcweir #include <sfx2/sfxuno.hxx>
34cdf0e10cSrcweir
~MSE40HTMLClipFormatObj()35cdf0e10cSrcweir MSE40HTMLClipFormatObj::~MSE40HTMLClipFormatObj()
36cdf0e10cSrcweir {
37cdf0e10cSrcweir delete pStrm;
38cdf0e10cSrcweir }
39cdf0e10cSrcweir
IsValid(SvStream & rStream)40cdf0e10cSrcweir SvStream* MSE40HTMLClipFormatObj::IsValid( SvStream& rStream )
41cdf0e10cSrcweir {
42cdf0e10cSrcweir sal_Bool bRet = sal_False;
43cdf0e10cSrcweir if( pStrm )
44cdf0e10cSrcweir delete pStrm, pStrm = 0;
45cdf0e10cSrcweir
46cdf0e10cSrcweir ByteString sLine, sVersion;
47*0f059bb0Sdamjan sal_Int32 nStt = -1, nEnd = -1;
48*0f059bb0Sdamjan sal_Int32 nStartFragment = 0, nEndFragment = 0;
49cdf0e10cSrcweir sal_uInt16 nIndex = 0;
50cdf0e10cSrcweir
51cdf0e10cSrcweir rStream.Seek(STREAM_SEEK_TO_BEGIN);
52cdf0e10cSrcweir rStream.ResetError();
53cdf0e10cSrcweir
54cdf0e10cSrcweir if( rStream.ReadLine( sLine ) &&
55cdf0e10cSrcweir sLine.GetToken( 0, ':', nIndex ) == "Version" )
56cdf0e10cSrcweir {
57cdf0e10cSrcweir sVersion = sLine.Copy( nIndex );
58cdf0e10cSrcweir while( rStream.ReadLine( sLine ) )
59cdf0e10cSrcweir {
60cdf0e10cSrcweir nIndex = 0;
61cdf0e10cSrcweir ByteString sTmp( sLine.GetToken( 0, ':', nIndex ) );
62cdf0e10cSrcweir if( sTmp == "StartHTML" )
63*0f059bb0Sdamjan nStt = sLine.Erase( 0, nIndex ).ToInt32();
64cdf0e10cSrcweir else if( sTmp == "EndHTML" )
65*0f059bb0Sdamjan nEnd = sLine.Erase( 0, nIndex ).ToInt32();
66*0f059bb0Sdamjan else if( sTmp == "StartFragment" )
67*0f059bb0Sdamjan {
68*0f059bb0Sdamjan nStartFragment = sLine.Erase( 0, nIndex ).ToInt32();
69*0f059bb0Sdamjan if( nStt == -1 )
70*0f059bb0Sdamjan nStt = nStartFragment;
71*0f059bb0Sdamjan }
72*0f059bb0Sdamjan else if( sTmp == "EndFragment" )
73*0f059bb0Sdamjan {
74*0f059bb0Sdamjan nEndFragment = sLine.Erase( 0, nIndex ).ToInt32();
75*0f059bb0Sdamjan if (nEnd == -1 )
76*0f059bb0Sdamjan nEnd = nEndFragment;
77*0f059bb0Sdamjan }
78cdf0e10cSrcweir else if( sTmp == "SourceURL" )
7924c56ab9SHerbert Dürr sBaseURL = String( sLine.Erase( 0, nIndex ), RTL_TEXTENCODING_UTF8);
80cdf0e10cSrcweir
81*0f059bb0Sdamjan if( nEnd >= 0 && nStt >= 0 &&
82*0f059bb0Sdamjan ( sBaseURL.Len() || rStream.Tell() >= (sal_uInt32)nStt ))
83cdf0e10cSrcweir {
84cdf0e10cSrcweir bRet = sal_True;
85cdf0e10cSrcweir break;
86cdf0e10cSrcweir }
87cdf0e10cSrcweir }
88cdf0e10cSrcweir }
89cdf0e10cSrcweir
90cdf0e10cSrcweir if( bRet )
91cdf0e10cSrcweir {
92cdf0e10cSrcweir rStream.Seek( nStt );
93cdf0e10cSrcweir
94cdf0e10cSrcweir pStrm = new SvCacheStream( ( nEnd - nStt < 0x10000l
95cdf0e10cSrcweir ? nEnd - nStt + 32
96cdf0e10cSrcweir : 0 ));
97cdf0e10cSrcweir *pStrm << rStream;
98cdf0e10cSrcweir pStrm->SetStreamSize( nEnd - nStt + 1L );
99cdf0e10cSrcweir pStrm->Seek( STREAM_SEEK_TO_BEGIN );
100cdf0e10cSrcweir }
101cdf0e10cSrcweir
102cdf0e10cSrcweir return pStrm;
103cdf0e10cSrcweir }
104cdf0e10cSrcweir
105