xref: /aoo41x/main/sfx2/source/bastyp/mieclip.cxx (revision 24c56ab9)
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;
47cdf0e10cSrcweir 	sal_uIntPtr nStt = 0, nEnd = 0;
48cdf0e10cSrcweir 	sal_uInt16 nIndex = 0;
49cdf0e10cSrcweir 
50cdf0e10cSrcweir 	rStream.Seek(STREAM_SEEK_TO_BEGIN);
51cdf0e10cSrcweir 	rStream.ResetError();
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 	if( rStream.ReadLine( sLine ) &&
54cdf0e10cSrcweir 		sLine.GetToken( 0, ':', nIndex ) == "Version" )
55cdf0e10cSrcweir 	{
56cdf0e10cSrcweir 		sVersion = sLine.Copy( nIndex );
57cdf0e10cSrcweir 		while( rStream.ReadLine( sLine ) )
58cdf0e10cSrcweir 		{
59cdf0e10cSrcweir 			nIndex = 0;
60cdf0e10cSrcweir 			ByteString sTmp( sLine.GetToken( 0, ':', nIndex ) );
61cdf0e10cSrcweir 			if( sTmp == "StartHTML" )
62cdf0e10cSrcweir 				nStt = (sal_uIntPtr)(sLine.Erase( 0, nIndex ).ToInt32());
63cdf0e10cSrcweir 			else if( sTmp == "EndHTML" )
64cdf0e10cSrcweir 				nEnd = (sal_uIntPtr)(sLine.Erase( 0, nIndex ).ToInt32());
65cdf0e10cSrcweir 			else if( sTmp == "SourceURL" )
66*24c56ab9SHerbert Dürr 				sBaseURL = String( sLine.Erase( 0, nIndex ), RTL_TEXTENCODING_UTF8);
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 			if( nEnd && nStt &&
69cdf0e10cSrcweir 				( sBaseURL.Len() || rStream.Tell() >= nStt ))
70cdf0e10cSrcweir 			{
71cdf0e10cSrcweir 				bRet = sal_True;
72cdf0e10cSrcweir 				break;
73cdf0e10cSrcweir 			}
74cdf0e10cSrcweir 		}
75cdf0e10cSrcweir 	}
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 	if( bRet )
78cdf0e10cSrcweir 	{
79cdf0e10cSrcweir 		rStream.Seek( nStt );
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 		pStrm = new SvCacheStream( ( nEnd - nStt < 0x10000l
82cdf0e10cSrcweir 										? nEnd - nStt + 32
83cdf0e10cSrcweir 										: 0 ));
84cdf0e10cSrcweir 		*pStrm << rStream;
85cdf0e10cSrcweir 		pStrm->SetStreamSize( nEnd - nStt + 1L );
86cdf0e10cSrcweir 		pStrm->Seek( STREAM_SEEK_TO_BEGIN );
87cdf0e10cSrcweir 	}
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 	return pStrm;
90cdf0e10cSrcweir }
91cdf0e10cSrcweir 
92