Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2003-2011 eXo Platform SAS.
   *
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Affero General Public License
   * as published by the Free Software Foundation; either version 3
   * of the License, or (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, see<http://www.gnu.org/licenses/>.
  */
 package org.exoplatform.services.jcr.ext.backup;
 
 import java.net.URL;

Created by The eXo Platform SAS.
Date: 2011

Author(s):
Alex Reshetnyak
Version:
$Id$
 
 {
 
    {
    }

   
Will be returned relative path <name>/<name>.xml for all OS.

Parameters:
path String, path to
backupDirCanonicalPath String, path to backup dir
Returns:
String Will be returned relative path <name>/<name>.xml for all OS
Throws:
java.net.MalformedURLException
 
    public static String getRelativePath(String pathString backupDirCanonicalPaththrows MalformedURLException
    {
       URL urlPath = new URL(resolveFileURL("file:" + path));
       URL urlBackupDir = new URL(resolveFileURL("file:" + backupDirCanonicalPath));
 
       return urlPath.toString().replace(urlBackupDir.toString() + "/""");
    }

   
Will be returned absolute path.

Parameters:
relativePath String, relative path.
backupDirCanonicalPath String, path to backup dir
Returns:
String Will be returned absolute path.
Throws:
java.net.MalformedURLException
 
    public static String getPath(String relativePathString backupDirCanonicalPaththrows MalformedURLException
    {
       String path = "file:" + backupDirCanonicalPath + "/" + relativePath;
 
       URL urlPath = new URL(resolveFileURL(path));
 
       return urlPath.getFile();
    }
 
    private static String resolveFileURL(String url)
    {
       // we ensure that we don't have windows path separator in the url
       url = url.replace('\\''/');
       if (!url.startsWith("file:///"))
       {
          // The url is invalid, so we will fix it
          // it happens when we use a path of type file://${path}, under
          // linux or mac os the path will start with a '/' so the url
          // will be correct but under windows we will have something
          // like C:\ so the first '/' is missing
          if (url.startsWith("file://"))
          {
             // The url is of type file://, so one '/' is missing
             url = "file:///" + url.substring(7);
          }
          else if (url.startsWith("file:/"))
          {
             // The url is of type file:/, so two '/' are missing
             url = "file:///" + url.substring(6);
          }
          else
          {
            // The url is of type file:, so three '/' are missing
            url = "file:///" + url.substring(5);
         }
      }
      return url;
   }
New to GrepCode? Check out our FAQ X