Get Parent URI : URI « Network Protocol « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JavaFX
25.JDK 6
26.JDK 7
27.JNDI LDAP
28.JPA
29.JSP
30.JSTL
31.Language Basics
32.Network Protocol
33.PDF RTF
34.Reflection
35.Regular Expressions
36.Scripting
37.Security
38.Servlets
39.Spring
40.Swing Components
41.Swing JFC
42.SWT JFace Eclipse
43.Threads
44.Tiny Application
45.Velocity
46.Web Services SOA
47.XML
Java » Network Protocol » URI 




Get Parent URI
     
/*
  Milyn - Copyright (C) 2006

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License (version 2.1) as published by the Free Software
  Foundation.

  This library 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 Lesser General Public License for more details:
  http://www.gnu.org/licenses/lgpl.txt
*/

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

/**
 {@link java.net.URI} utility methods.
 
 @author <a href="mailto:[email protected]">[email protected]</a>
 */
public abstract class URIUtil {

    /**
     * Get the parent URI of the supplied URI
     @param uri The input URI for which the parent URI is being requrested.
     @return The parent URI.  Returns a URI instance equivalent to "../" if
     * the supplied URI path has no parent.
     @throws URISyntaxException Failed to reconstruct the parent URI.
     */
    public static URI getParent(URI urithrows URISyntaxException {


        String parentPath = new File(uri.getPath()).getParent();

        if(parentPath == null) {
            return new URI("../");
        }

        return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), parentPath.replace('\\''/'), uri.getQuery(), uri.getFragment());
    }
}

   
    
    
    
    
  














Related examples in the same category
1.Encode a URI path
2.Add two URI path segments
3.Remove parameters from a uri.
4.Remove any authorisation details from a URI
5.A class to represent a Uniform Resource Identifier (URI).
6.Utility to convert File to URL.
7.Return True if the uri has a scheme
8.Normalize a uri containing ../ and ./ paths.
9.URI Support
10.URI utilities
11.Create and resolve URI
12.Add parameters stored in the Map to the uri string.
13.Make a URL from the given string
14.Is Equal URI
15.Resolves the specified URI, and returns the file represented by the URI.
16.Returns the filename for the specified URI.
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.