1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "oox/ole/vbahelper.hxx" 29 #include <rtl/ustrbuf.hxx> 30 #include "oox/helper/binaryinputstream.hxx" 31 32 namespace oox { 33 namespace ole { 34 35 // ============================================================================ 36 37 using namespace ::com::sun::star::uno; 38 39 using ::rtl::OUString; 40 using ::rtl::OUStringBuffer; 41 42 // ============================================================================ 43 44 /*static*/ OUString VbaHelper::getBasicScriptUrl( 45 const OUString& rLibraryName, const OUString& rModuleName, const OUString& rMacroName ) 46 { 47 OSL_ENSURE( rLibraryName.getLength() > 0, "VbaHelper::getBasicScriptUrl - library name is empty" ); 48 OSL_ENSURE( rModuleName.getLength() > 0, "VbaHelper::getBasicScriptUrl - module name is empty" ); 49 OSL_ENSURE( rMacroName.getLength() > 0, "VbaHelper::getBasicScriptUrl - macro name is empty" ); 50 const sal_Unicode cDot = '.'; 51 return OUStringBuffer(). 52 appendAscii( RTL_CONSTASCII_STRINGPARAM( "vnd.sun.star.script:" ) ). 53 append( rLibraryName ).append( cDot ).append( rModuleName ).append( cDot ).append( rMacroName ). 54 appendAscii( RTL_CONSTASCII_STRINGPARAM( "?language=Basic&location=document" ) ). 55 makeStringAndClear(); 56 } 57 58 /*static*/ bool VbaHelper::readDirRecord( sal_uInt16& rnRecId, StreamDataSequence& rRecData, BinaryInputStream& rInStrm ) 59 { 60 // read the record header 61 sal_Int32 nRecSize; 62 rInStrm >> rnRecId >> nRecSize; 63 // for no obvious reason, PROJECTVERSION record contains size field of 4, but is 6 bytes long 64 if( rnRecId == VBA_ID_PROJECTVERSION ) 65 { 66 OSL_ENSURE( nRecSize == 4, "VbaHelper::readDirRecord - unexpected record size for PROJECTVERSION" ); 67 nRecSize = 6; 68 } 69 // read the record contents into the passed sequence 70 return !rInStrm.isEof() && (rInStrm.readData( rRecData, nRecSize ) == nRecSize); 71 } 72 73 /*static*/ bool VbaHelper::extractKeyValue( OUString& rKey, OUString& rValue, const OUString& rKeyValue ) 74 { 75 sal_Int32 nEqSignPos = rKeyValue.indexOf( '=' ); 76 if( nEqSignPos > 0 ) 77 { 78 rKey = rKeyValue.copy( 0, nEqSignPos ).trim(); 79 rValue = rKeyValue.copy( nEqSignPos + 1 ).trim(); 80 return (rKey.getLength() > 0) && (rValue.getLength() > 0); 81 } 82 return false; 83 } 84 85 // ============================================================================ 86 87 } // namespace ole 88 } // namespace oox 89