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 package complex.memCheck;
25 
26 import java.io.File;
27 
28 /**
29  *
30  * @author ll93751
31  */
32 public class FileHelper
33 {
appendPath(String _sPath, String _sRelativePathToAdd)34     public static String appendPath(String _sPath, String _sRelativePathToAdd)
35         {
36             String sNewPath = _sPath;
37             String fs = System.getProperty("file.separator");
38             if (_sPath.startsWith("file:"))
39             {
40                 fs = "/";                                  // we use a file URL so only '/' is allowed.
41             }
42             if (! (sNewPath.endsWith("/") || sNewPath.endsWith("\\") ) )
43             {
44                 sNewPath += fs;
45             }
46             sNewPath += _sRelativePathToAdd;
47             return sNewPath;
48         }
getJavaCompatibleFilename(String _sFilename)49     public static String getJavaCompatibleFilename(String _sFilename)
50     {
51         // It is a little bit stupid that office urls not compatible to java file urls
52         // System.out.println("java.io.File can't access Office file urls.");
53         if(_sFilename.startsWith("path:"))
54         {
55             final String sPath = _sFilename.substring(5);
56             return sPath;
57         }
58 
59         String sSystemPath = graphical.FileHelper.getSystemPathFromFileURL(_sFilename);
60         if (sSystemPath == null)
61         {
62             sSystemPath = _sFilename;
63         }
64         return sSystemPath;
65     }
66 
getBasename(String _sFilename)67 public static String getBasename(String _sFilename)
68         {
69             if (_sFilename == null)
70             {
71                 return "";
72             }
73             // String fs = System.getProperty("file.separator");
74 
75             int nIdx = _sFilename.lastIndexOf("\\");
76             if (nIdx == -1)
77             {
78                 nIdx = _sFilename.lastIndexOf("/");
79             }
80             if (nIdx > 0)
81             {
82                 return _sFilename.substring(nIdx + 1);
83             }
84             return _sFilename;
85         }
86 }
87