xref: /aoo42x/main/sfx2/source/bastyp/mieclip.cxx (revision 0f059bb0)
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_Int32 nStt = -1, nEnd = -1;
48 	sal_Int32 nStartFragment = 0, nEndFragment = 0;
49 	sal_uInt16 nIndex = 0;
50 
51 	rStream.Seek(STREAM_SEEK_TO_BEGIN);
52 	rStream.ResetError();
53 
54 	if( rStream.ReadLine( sLine ) &&
55 		sLine.GetToken( 0, ':', nIndex ) == "Version" )
56 	{
57 		sVersion = sLine.Copy( nIndex );
58 		while( rStream.ReadLine( sLine ) )
59 		{
60 			nIndex = 0;
61 			ByteString sTmp( sLine.GetToken( 0, ':', nIndex ) );
62 			if( sTmp == "StartHTML" )
63 				nStt = sLine.Erase( 0, nIndex ).ToInt32();
64 			else if( sTmp == "EndHTML" )
65 				nEnd = sLine.Erase( 0, nIndex ).ToInt32();
66 			else if( sTmp == "StartFragment" )
67 			{
68 				nStartFragment = sLine.Erase( 0, nIndex ).ToInt32();
69 				if( nStt == -1 )
70 					nStt = nStartFragment;
71 			}
72 			else if( sTmp == "EndFragment" )
73 			{
74 				nEndFragment = sLine.Erase( 0, nIndex ).ToInt32();
75 				if (nEnd == -1 )
76 					nEnd = nEndFragment;
77 			}
78 			else if( sTmp == "SourceURL" )
79 				sBaseURL = String( sLine.Erase( 0, nIndex ), RTL_TEXTENCODING_UTF8);
80 
81 			if( nEnd >= 0 && nStt >= 0 &&
82 				( sBaseURL.Len() || rStream.Tell() >= (sal_uInt32)nStt ))
83 			{
84 				bRet = sal_True;
85 				break;
86 			}
87 		}
88 	}
89 
90 	if( bRet )
91 	{
92 		rStream.Seek( nStt );
93 
94 		pStrm = new SvCacheStream( ( nEnd - nStt < 0x10000l
95 										? nEnd - nStt + 32
96 										: 0 ));
97 		*pStrm << rStream;
98 		pStrm->SetStreamSize( nEnd - nStt + 1L );
99 		pStrm->Seek( STREAM_SEEK_TO_BEGIN );
100 	}
101 
102 	return pStrm;
103 }
104 
105