1*ca5ec200SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ca5ec200SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ca5ec200SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ca5ec200SAndrew Rist * distributed with this work for additional information 6*ca5ec200SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ca5ec200SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ca5ec200SAndrew Rist * "License"); you may not use this file except in compliance 9*ca5ec200SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*ca5ec200SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*ca5ec200SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ca5ec200SAndrew Rist * software distributed under the License is distributed on an 15*ca5ec200SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ca5ec200SAndrew Rist * KIND, either express or implied. See the License for the 17*ca5ec200SAndrew Rist * specific language governing permissions and limitations 18*ca5ec200SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*ca5ec200SAndrew Rist *************************************************************/ 21*ca5ec200SAndrew Rist 22*ca5ec200SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include "oox/ole/vbahelper.hxx" 25cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 26cdf0e10cSrcweir #include "oox/helper/binaryinputstream.hxx" 27cdf0e10cSrcweir 28cdf0e10cSrcweir namespace oox { 29cdf0e10cSrcweir namespace ole { 30cdf0e10cSrcweir 31cdf0e10cSrcweir // ============================================================================ 32cdf0e10cSrcweir 33cdf0e10cSrcweir using namespace ::com::sun::star::uno; 34cdf0e10cSrcweir 35cdf0e10cSrcweir using ::rtl::OUString; 36cdf0e10cSrcweir using ::rtl::OUStringBuffer; 37cdf0e10cSrcweir 38cdf0e10cSrcweir // ============================================================================ 39cdf0e10cSrcweir 40cdf0e10cSrcweir /*static*/ OUString VbaHelper::getBasicScriptUrl( 41cdf0e10cSrcweir const OUString& rLibraryName, const OUString& rModuleName, const OUString& rMacroName ) 42cdf0e10cSrcweir { 43cdf0e10cSrcweir OSL_ENSURE( rLibraryName.getLength() > 0, "VbaHelper::getBasicScriptUrl - library name is empty" ); 44cdf0e10cSrcweir OSL_ENSURE( rModuleName.getLength() > 0, "VbaHelper::getBasicScriptUrl - module name is empty" ); 45cdf0e10cSrcweir OSL_ENSURE( rMacroName.getLength() > 0, "VbaHelper::getBasicScriptUrl - macro name is empty" ); 46cdf0e10cSrcweir const sal_Unicode cDot = '.'; 47cdf0e10cSrcweir return OUStringBuffer(). 48cdf0e10cSrcweir appendAscii( RTL_CONSTASCII_STRINGPARAM( "vnd.sun.star.script:" ) ). 49cdf0e10cSrcweir append( rLibraryName ).append( cDot ).append( rModuleName ).append( cDot ).append( rMacroName ). 50cdf0e10cSrcweir appendAscii( RTL_CONSTASCII_STRINGPARAM( "?language=Basic&location=document" ) ). 51cdf0e10cSrcweir makeStringAndClear(); 52cdf0e10cSrcweir } 53cdf0e10cSrcweir 54cdf0e10cSrcweir /*static*/ bool VbaHelper::readDirRecord( sal_uInt16& rnRecId, StreamDataSequence& rRecData, BinaryInputStream& rInStrm ) 55cdf0e10cSrcweir { 56cdf0e10cSrcweir // read the record header 57cdf0e10cSrcweir sal_Int32 nRecSize; 58cdf0e10cSrcweir rInStrm >> rnRecId >> nRecSize; 59cdf0e10cSrcweir // for no obvious reason, PROJECTVERSION record contains size field of 4, but is 6 bytes long 60cdf0e10cSrcweir if( rnRecId == VBA_ID_PROJECTVERSION ) 61cdf0e10cSrcweir { 62cdf0e10cSrcweir OSL_ENSURE( nRecSize == 4, "VbaHelper::readDirRecord - unexpected record size for PROJECTVERSION" ); 63cdf0e10cSrcweir nRecSize = 6; 64cdf0e10cSrcweir } 65cdf0e10cSrcweir // read the record contents into the passed sequence 66cdf0e10cSrcweir return !rInStrm.isEof() && (rInStrm.readData( rRecData, nRecSize ) == nRecSize); 67cdf0e10cSrcweir } 68cdf0e10cSrcweir 69cdf0e10cSrcweir /*static*/ bool VbaHelper::extractKeyValue( OUString& rKey, OUString& rValue, const OUString& rKeyValue ) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir sal_Int32 nEqSignPos = rKeyValue.indexOf( '=' ); 72cdf0e10cSrcweir if( nEqSignPos > 0 ) 73cdf0e10cSrcweir { 74cdf0e10cSrcweir rKey = rKeyValue.copy( 0, nEqSignPos ).trim(); 75cdf0e10cSrcweir rValue = rKeyValue.copy( nEqSignPos + 1 ).trim(); 76cdf0e10cSrcweir return (rKey.getLength() > 0) && (rValue.getLength() > 0); 77cdf0e10cSrcweir } 78cdf0e10cSrcweir return false; 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir // ============================================================================ 82cdf0e10cSrcweir 83cdf0e10cSrcweir } // namespace ole 84cdf0e10cSrcweir } // namespace oox 85