1*ae15d43aSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ae15d43aSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ae15d43aSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ae15d43aSAndrew Rist * distributed with this work for additional information 6*ae15d43aSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ae15d43aSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ae15d43aSAndrew Rist * "License"); you may not use this file except in compliance 9*ae15d43aSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*ae15d43aSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*ae15d43aSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ae15d43aSAndrew Rist * software distributed under the License is distributed on an 15*ae15d43aSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ae15d43aSAndrew Rist * KIND, either express or implied. See the License for the 17*ae15d43aSAndrew Rist * specific language governing permissions and limitations 18*ae15d43aSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*ae15d43aSAndrew Rist *************************************************************/ 21*ae15d43aSAndrew Rist 22*ae15d43aSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir import java.io.File; 25cdf0e10cSrcweir import java.net.MalformedURLException; 26cdf0e10cSrcweir 27cdf0e10cSrcweir public class URLHelper 28cdf0e10cSrcweir { 29cdf0e10cSrcweir /** 30cdf0e10cSrcweir * Because the office need URLs for loading/saving documents 31cdf0e10cSrcweir * we must convert used system pathes. 32cdf0e10cSrcweir * And java use another notation for file URLs ... correct it. 33cdf0e10cSrcweir * 34cdf0e10cSrcweir * @param aSystemPath 35cdf0e10cSrcweir * represent the file in system notation 36cdf0e10cSrcweir * 37cdf0e10cSrcweir * @return [String] 38cdf0e10cSrcweir * a file url which represent the given system path 39cdf0e10cSrcweir */ 40cdf0e10cSrcweir @SuppressWarnings("deprecation") getFileURLFromSystemPath( File aSystemPath )41cdf0e10cSrcweir public static String getFileURLFromSystemPath( File aSystemPath ) 42cdf0e10cSrcweir { 43cdf0e10cSrcweir String sFileURL = null; 44cdf0e10cSrcweir try 45cdf0e10cSrcweir { 46cdf0e10cSrcweir sFileURL = aSystemPath.toURL().toString(); 47cdf0e10cSrcweir } 48cdf0e10cSrcweir catch( MalformedURLException exWrong ) 49cdf0e10cSrcweir { 50cdf0e10cSrcweir sFileURL = null; 51cdf0e10cSrcweir } 52cdf0e10cSrcweir 53cdf0e10cSrcweir // problem of java: file URL's are coded with 1 slash instead of 2 or 3 ones! 54cdf0e10cSrcweir // => correct this problem first, otherwise office can't use these URL's 55cdf0e10cSrcweir if( 56cdf0e10cSrcweir (sFileURL != null ) && 57cdf0e10cSrcweir (sFileURL.startsWith("file:/") == true ) && 58cdf0e10cSrcweir (sFileURL.startsWith("file://") == false) 59cdf0e10cSrcweir ) 60cdf0e10cSrcweir { 61cdf0e10cSrcweir StringBuffer sWorkBuffer = new StringBuffer(sFileURL); 62cdf0e10cSrcweir sWorkBuffer.insert(6,"//"); 63cdf0e10cSrcweir sFileURL = sWorkBuffer.toString(); 64cdf0e10cSrcweir } 65cdf0e10cSrcweir 66cdf0e10cSrcweir return sFileURL; 67cdf0e10cSrcweir } 68cdf0e10cSrcweir } 69