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_desktop.hxx" 26 27 #include "sal/config.h" 28 29 #include "boost/optional.hpp" 30 #include "com/sun/star/beans/Optional.hpp" 31 #include "com/sun/star/deployment/XPackage.hpp" 32 #include "com/sun/star/uno/Reference.hxx" 33 #include "osl/diagnose.h" 34 #include "rtl/string.h" 35 #include "rtl/ustrbuf.hxx" 36 #include "rtl/ustring.hxx" 37 38 #include "dp_identifier.hxx" 39 40 namespace { 41 namespace css = ::com::sun::star; 42 } 43 44 namespace dp_misc { 45 generateIdentifier(::boost::optional<::rtl::OUString> const & optional,::rtl::OUString const & fileName)46::rtl::OUString generateIdentifier( 47 ::boost::optional< ::rtl::OUString > const & optional, 48 ::rtl::OUString const & fileName) 49 { 50 return optional ? *optional : generateLegacyIdentifier(fileName); 51 } 52 getIdentifier(css::uno::Reference<css::deployment::XPackage> const & package)53::rtl::OUString getIdentifier( 54 css::uno::Reference< css::deployment::XPackage > const & package) 55 { 56 OSL_ASSERT(package.is()); 57 css::beans::Optional< ::rtl::OUString > id(package->getIdentifier()); 58 return id.IsPresent 59 ? id.Value : generateLegacyIdentifier(package->getName()); 60 } 61 generateLegacyIdentifier(::rtl::OUString const & fileName)62::rtl::OUString generateLegacyIdentifier(::rtl::OUString const & fileName) { 63 rtl::OUStringBuffer b; 64 b.appendAscii(RTL_CONSTASCII_STRINGPARAM("org.openoffice.legacy.")); 65 b.append(fileName); 66 return b.makeStringAndClear(); 67 } 68 69 } 70