/****************************************************************************/
/*  File:       Paths.java                                                  */
/*  Author:     F. Georges                                                  */
/*  Company:    H2O Consulting                                              */
/*  Date:       2015-01-13                                                  */
/*  Tags:                                                                   */
/*      Copyright (c) 2015 Florent Georges (see end of file.)               */
/* ------------------------------------------------------------------------ */


package org.expath.file;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

/**
 * Facade for EXPath File module functions in the section "Paths".
 * 
 * @author Florent Georges
 * @date   2015-01-13
 * @see http://expath.org/spec/file#paths
 * @see http://expath.org/spec/file/20131203#paths
 */
public class Paths
{
    // file:name($path as xs:string) as xs:string
    public String name(String path)
    {
        File f = new File(path);
        return f.getName();
    }

    // file:parent($path as xs:string) as xs:string?
    public String parent(String path)
    {
        File f = new File(path);
        File abs = f.getAbsoluteFile();
        return abs.getParent();
    }

    // file:path-to-native($path as xs:string) as xs:string
    // [file:io-error] is raised if an error occurs while trying to obtain the native path.
    public String pathToNative(String path)
            throws FileException
    {
        try {
            File f = new File(path);
            return f.getCanonicalPath();
        }
        catch ( IOException ex ) {
            throw FileException.ioError("Error getting the native path", ex);
        }
    }

    // file:path-to-uri($path as xs:string) as xs:anyURI
    public URI pathToUri(String path)
            throws FileException
    {
        File f = new File(path);
        File abs = f.getAbsoluteFile();
        return abs.toURI();
    }

    // file:resolve-path($path as xs:string) as xs:string
    public String resolvePath(String path)
    {
        File f = new File(path);
        return f.getAbsolutePath();
    }
}


/* ------------------------------------------------------------------------ */
/*  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS COMMENT.               */
/*                                                                          */
/*  The contents of this file are subject to the Mozilla Public License     */
/*  Version 1.0 (the "License"); you may not use this file except in        */
/*  compliance with the License. You may obtain a copy of the License at    */
/*  http://www.mozilla.org/MPL/.                                            */
/*                                                                          */
/*  Software distributed under the License is distributed on an "AS IS"     */
/*  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See    */
/*  the License for the specific language governing rights and limitations  */
/*  under the License.                                                      */
/*                                                                          */
/*  The Original Code is: all this file.                                    */
/*                                                                          */
/*  The Initial Developer of the Original Code is Florent Georges.          */
/*                                                                          */
/*  Contributor(s): none.                                                   */
/* ------------------------------------------------------------------------ */

@@ -726,44 +726,8 @@
 URI;
-%0Aimport java.net.URISyntaxException;
 %0A%0A/*
@@ -1050,32 +1050,129 @@
 ing path)%0A    %7B%0A
+        if ( File.separator.equals(path) ) %7B%0A            return %22%22;%0A        %7D%0A        else %7B%0A    
         File f =
@@ -1188,32 +1188,36 @@
 (path);%0A        
+ 
+   
 return f.getName
@@ -1216,24 +1216,34 @@
 .getName();%0A
+        %7D%0A
     %7D%0A%0A    /
@@ -1341,32 +1341,34 @@
 %0A        File f 
+  
 = new File(path)
@@ -1413,30 +1413,34 @@
 ();%0A        
-return
+File p   =
  abs.getPare
@@ -1441,17 +1441,74 @@
 etParent
-(
+File();%0A        return null == p ? null : Util.stringify(p
 );%0A    %7D
@@ -1810,24 +1810,39 @@
      return 
+Util.stringify(
 f.getCanonic
@@ -1843,21 +1843,22 @@
 anonical
-Path(
+File()
 );%0A     
@@ -2385,24 +2385,39 @@
      return 
+Util.stringify(
 f.getAbsolut
@@ -2417,21 +2417,22 @@
 Absolute
-Path(
+File()
 );%0A    %7D

Make sure name() on "/" returns the empty string. Return the empty sequence when there is no parent(). Return proper string ending with / when path points to a directory.