1323de322SAndrew Rist/************************************************************** 2cdf0e10cSrcweir * 3323de322SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4323de322SAndrew Rist * or more contributor license agreements. See the NOTICE file 5323de322SAndrew Rist * distributed with this work for additional information 6323de322SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7323de322SAndrew Rist * to you under the Apache License, Version 2.0 (the 8323de322SAndrew Rist * "License"); you may not use this file except in compliance 9323de322SAndrew Rist * with the License. You may obtain a copy of the License at 10323de322SAndrew Rist * 11323de322SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12323de322SAndrew Rist * 13323de322SAndrew Rist * Unless required by applicable law or agreed to in writing, 14323de322SAndrew Rist * software distributed under the License is distributed on an 15323de322SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16323de322SAndrew Rist * KIND, either express or implied. See the License for the 17323de322SAndrew Rist * specific language governing permissions and limitations 18323de322SAndrew Rist * under the License. 19323de322SAndrew Rist * 20323de322SAndrew Rist *************************************************************/ 21323de322SAndrew Rist 22323de322SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir#ifndef _NSSTRING_OOOADDITIONS_HXX_ 25cdf0e10cSrcweir#include "NSString_OOoAdditions.hxx" 26cdf0e10cSrcweir#endif 27cdf0e10cSrcweir 28cdf0e10cSrcweir#include "NSURL_OOoAdditions.hxx" 29cdf0e10cSrcweir 30cdf0e10cSrcweir@implementation NSURL (OOoAdditions) 31cdf0e10cSrcweir- (rtl::OUString) OUStringForInfo:(InfoType)info 32cdf0e10cSrcweir{ 33cdf0e10cSrcweir NSAutoreleasePool *pool = [NSAutoreleasePool new]; 34cdf0e10cSrcweir 35cdf0e10cSrcweir NSString *sURLString = nil; 36cdf0e10cSrcweir 37cdf0e10cSrcweir switch(info) { 38cdf0e10cSrcweir case FULLPATH: 39cdf0e10cSrcweir OSL_TRACE("Extracting the full path of an item"); 40cdf0e10cSrcweir sURLString = [self absoluteString]; 41cdf0e10cSrcweir [sURLString retain]; 42cdf0e10cSrcweir break; 43*d192718aSHerbert Dürr case FILENAME: { 44cdf0e10cSrcweir OSL_TRACE("Extracting the file name of an item"); 45*d192718aSHerbert Dürr NSString* path = [self path]; 46cdf0e10cSrcweir if (path == nil) { 47cdf0e10cSrcweir sURLString = @""; 48cdf0e10cSrcweir } 49cdf0e10cSrcweir else { 50cdf0e10cSrcweir sURLString = [path lastPathComponent]; 51cdf0e10cSrcweir } 52cdf0e10cSrcweir [sURLString retain]; 53*d192718aSHerbert Dürr } break; 54*d192718aSHerbert Dürr case PATHWITHOUTLASTCOMPONENT: { 55cdf0e10cSrcweir OSL_TRACE("Extracting the last but one component of an item's path"); 56*d192718aSHerbert Dürr NSString* path = [self absoluteString]; 57cdf0e10cSrcweir if (path == nil) { 58cdf0e10cSrcweir sURLString = @""; 59cdf0e10cSrcweir } 60cdf0e10cSrcweir else { 61cdf0e10cSrcweir NSString* lastComponent = [path lastPathComponent]; 62cdf0e10cSrcweir unsigned int lastLength = [lastComponent length]; 63cdf0e10cSrcweir sURLString = [path substringToIndex:([path length] - lastLength)]; 64cdf0e10cSrcweir } 65cdf0e10cSrcweir [sURLString retain]; 66*d192718aSHerbert Dürr } break; 67cdf0e10cSrcweir default: 68cdf0e10cSrcweir break; 69cdf0e10cSrcweir } 70cdf0e10cSrcweir 71cdf0e10cSrcweir rtl::OUString sResult = [sURLString OUString]; 72cdf0e10cSrcweir [sURLString release]; 73cdf0e10cSrcweir 74cdf0e10cSrcweir [pool release]; 75cdf0e10cSrcweir 76cdf0e10cSrcweir return sResult; 77cdf0e10cSrcweir} 78cdf0e10cSrcweir@end 79cdf0e10cSrcweir 80cdf0e10cSrcweirNSString* resolveAlias( NSString* i_pSystemPath ) 81cdf0e10cSrcweir{ 82cdf0e10cSrcweir NSString* pResolvedPath = nil; 83cdf0e10cSrcweir CFURLRef rUrl = CFURLCreateWithFileSystemPath( kCFAllocatorDefault, 84cdf0e10cSrcweir (CFStringRef)i_pSystemPath, 85cdf0e10cSrcweir kCFURLPOSIXPathStyle, false); 86cdf0e10cSrcweir if( rUrl != NULL ) 87cdf0e10cSrcweir { 88cdf0e10cSrcweir FSRef rFS; 89cdf0e10cSrcweir if( CFURLGetFSRef( rUrl, &rFS ) ) 90cdf0e10cSrcweir { 91cdf0e10cSrcweir Boolean bIsFolder = false; 92cdf0e10cSrcweir Boolean bAlias = false; 93cdf0e10cSrcweir OSErr err = FSResolveAliasFile( &rFS, true, &bIsFolder, &bAlias); 94cdf0e10cSrcweir if( (err == noErr) && bAlias ) 95cdf0e10cSrcweir { 96cdf0e10cSrcweir CFURLRef rResolvedUrl = CFURLCreateFromFSRef( kCFAllocatorDefault, &rFS ); 97cdf0e10cSrcweir if( rResolvedUrl != NULL ) 98cdf0e10cSrcweir { 99cdf0e10cSrcweir pResolvedPath = (NSString*)CFURLCopyFileSystemPath( rResolvedUrl, kCFURLPOSIXPathStyle ); 100cdf0e10cSrcweir CFRelease( rResolvedUrl ); 101cdf0e10cSrcweir } 102cdf0e10cSrcweir } 103cdf0e10cSrcweir } 104cdf0e10cSrcweir CFRelease( rUrl ); 105cdf0e10cSrcweir } 106cdf0e10cSrcweir 107cdf0e10cSrcweir return pResolvedPath; 108cdf0e10cSrcweir} 109