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