1*c7cc89feSAndrew Rist /**************************************************************
2*c7cc89feSAndrew Rist  *
3*c7cc89feSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*c7cc89feSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*c7cc89feSAndrew Rist  * distributed with this work for additional information
6*c7cc89feSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*c7cc89feSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*c7cc89feSAndrew Rist  * "License"); you may not use this file except in compliance
9*c7cc89feSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*c7cc89feSAndrew Rist  *
11*c7cc89feSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*c7cc89feSAndrew Rist  *
13*c7cc89feSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*c7cc89feSAndrew Rist  * software distributed under the License is distributed on an
15*c7cc89feSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*c7cc89feSAndrew Rist  * KIND, either express or implied.  See the License for the
17*c7cc89feSAndrew Rist  * specific language governing permissions and limitations
18*c7cc89feSAndrew Rist  * under the License.
19*c7cc89feSAndrew Rist  *
20*c7cc89feSAndrew Rist  *************************************************************/
21*c7cc89feSAndrew Rist 
22*c7cc89feSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package complex.memCheck;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import java.io.File;
27cdf0e10cSrcweir 
28cdf0e10cSrcweir /**
29cdf0e10cSrcweir  *
30cdf0e10cSrcweir  * @author ll93751
31cdf0e10cSrcweir  */
32cdf0e10cSrcweir public class FileHelper
33cdf0e10cSrcweir {
appendPath(String _sPath, String _sRelativePathToAdd)34cdf0e10cSrcweir     public static String appendPath(String _sPath, String _sRelativePathToAdd)
35cdf0e10cSrcweir         {
36cdf0e10cSrcweir             String sNewPath = _sPath;
37cdf0e10cSrcweir             String fs = System.getProperty("file.separator");
38cdf0e10cSrcweir             if (_sPath.startsWith("file:"))
39cdf0e10cSrcweir             {
40cdf0e10cSrcweir                 fs = "/";                                  // we use a file URL so only '/' is allowed.
41cdf0e10cSrcweir             }
42cdf0e10cSrcweir             if (! (sNewPath.endsWith("/") || sNewPath.endsWith("\\") ) )
43cdf0e10cSrcweir             {
44cdf0e10cSrcweir                 sNewPath += fs;
45cdf0e10cSrcweir             }
46cdf0e10cSrcweir             sNewPath += _sRelativePathToAdd;
47cdf0e10cSrcweir             return sNewPath;
48cdf0e10cSrcweir         }
getJavaCompatibleFilename(String _sFilename)49cdf0e10cSrcweir     public static String getJavaCompatibleFilename(String _sFilename)
50cdf0e10cSrcweir     {
51cdf0e10cSrcweir         // It is a little bit stupid that office urls not compatible to java file urls
52cdf0e10cSrcweir         // System.out.println("java.io.File can't access Office file urls.");
53cdf0e10cSrcweir         if(_sFilename.startsWith("path:"))
54cdf0e10cSrcweir         {
55cdf0e10cSrcweir             final String sPath = _sFilename.substring(5);
56cdf0e10cSrcweir             return sPath;
57cdf0e10cSrcweir         }
58cdf0e10cSrcweir 
59cdf0e10cSrcweir         String sSystemPath = graphical.FileHelper.getSystemPathFromFileURL(_sFilename);
60cdf0e10cSrcweir         if (sSystemPath == null)
61cdf0e10cSrcweir         {
62cdf0e10cSrcweir             sSystemPath = _sFilename;
63cdf0e10cSrcweir         }
64cdf0e10cSrcweir         return sSystemPath;
65cdf0e10cSrcweir     }
66cdf0e10cSrcweir 
getBasename(String _sFilename)67cdf0e10cSrcweir public static String getBasename(String _sFilename)
68cdf0e10cSrcweir         {
69cdf0e10cSrcweir             if (_sFilename == null)
70cdf0e10cSrcweir             {
71cdf0e10cSrcweir                 return "";
72cdf0e10cSrcweir             }
73cdf0e10cSrcweir             // String fs = System.getProperty("file.separator");
74cdf0e10cSrcweir 
75cdf0e10cSrcweir             int nIdx = _sFilename.lastIndexOf("\\");
76cdf0e10cSrcweir             if (nIdx == -1)
77cdf0e10cSrcweir             {
78cdf0e10cSrcweir                 nIdx = _sFilename.lastIndexOf("/");
79cdf0e10cSrcweir             }
80cdf0e10cSrcweir             if (nIdx > 0)
81cdf0e10cSrcweir             {
82cdf0e10cSrcweir                 return _sFilename.substring(nIdx + 1);
83cdf0e10cSrcweir             }
84cdf0e10cSrcweir             return _sFilename;
85cdf0e10cSrcweir         }
86cdf0e10cSrcweir }
87