xref: /aoo41x/main/oox/source/ole/vbahelper.cxx (revision ca5ec200)
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 #include "oox/ole/vbahelper.hxx"
25 #include <rtl/ustrbuf.hxx>
26 #include "oox/helper/binaryinputstream.hxx"
27 
28 namespace oox {
29 namespace ole {
30 
31 // ============================================================================
32 
33 using namespace ::com::sun::star::uno;
34 
35 using ::rtl::OUString;
36 using ::rtl::OUStringBuffer;
37 
38 // ============================================================================
39 
getBasicScriptUrl(const OUString & rLibraryName,const OUString & rModuleName,const OUString & rMacroName)40 /*static*/ OUString VbaHelper::getBasicScriptUrl(
41         const OUString& rLibraryName, const OUString& rModuleName, const OUString& rMacroName )
42 {
43     OSL_ENSURE( rLibraryName.getLength() > 0, "VbaHelper::getBasicScriptUrl - library name is empty" );
44     OSL_ENSURE( rModuleName.getLength() > 0, "VbaHelper::getBasicScriptUrl - module name is empty" );
45     OSL_ENSURE( rMacroName.getLength() > 0, "VbaHelper::getBasicScriptUrl - macro name is empty" );
46     const sal_Unicode cDot = '.';
47     return OUStringBuffer().
48         appendAscii( RTL_CONSTASCII_STRINGPARAM( "vnd.sun.star.script:" ) ).
49         append( rLibraryName ).append( cDot ).append( rModuleName ).append( cDot ).append( rMacroName ).
50         appendAscii( RTL_CONSTASCII_STRINGPARAM( "?language=Basic&location=document" ) ).
51         makeStringAndClear();
52 }
53 
readDirRecord(sal_uInt16 & rnRecId,StreamDataSequence & rRecData,BinaryInputStream & rInStrm)54 /*static*/ bool VbaHelper::readDirRecord( sal_uInt16& rnRecId, StreamDataSequence& rRecData, BinaryInputStream& rInStrm )
55 {
56     // read the record header
57     sal_Int32 nRecSize;
58     rInStrm >> rnRecId >> nRecSize;
59     // for no obvious reason, PROJECTVERSION record contains size field of 4, but is 6 bytes long
60     if( rnRecId == VBA_ID_PROJECTVERSION )
61     {
62         OSL_ENSURE( nRecSize == 4, "VbaHelper::readDirRecord - unexpected record size for PROJECTVERSION" );
63         nRecSize = 6;
64     }
65     // read the record contents into the passed sequence
66     return !rInStrm.isEof() && (rInStrm.readData( rRecData, nRecSize ) == nRecSize);
67 }
68 
extractKeyValue(OUString & rKey,OUString & rValue,const OUString & rKeyValue)69 /*static*/ bool VbaHelper::extractKeyValue( OUString& rKey, OUString& rValue, const OUString& rKeyValue )
70 {
71     sal_Int32 nEqSignPos = rKeyValue.indexOf( '=' );
72     if( nEqSignPos > 0 )
73     {
74         rKey = rKeyValue.copy( 0, nEqSignPos ).trim();
75         rValue = rKeyValue.copy( nEqSignPos + 1 ).trim();
76         return (rKey.getLength() > 0) && (rValue.getLength() > 0);
77     }
78     return false;
79 }
80 
81 // ============================================================================
82 
83 } // namespace ole
84 } // namespace oox
85