Java Path Normalize normalizeURI(String prefix, String relativePath)

Here you can find the source of normalizeURI(String prefix, String relativePath)

Description

Returns the (smart) concatenation of the prefix and the relativePath.

License

Open Source License

Parameter

Parameter Description
prefix a parameter
relativePath a parameter

Return

A normalized URI or null

Declaration

public static String normalizeURI(String prefix, String relativePath) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2012 Olivier Moises//from   www.  ja v  a 2  s.  co  m
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Olivier Moises- initial API and implementation
 *******************************************************************************/

public class Main {
    /**
     * Returns the (smart) concatenation of the prefix and the relativePath.
     * 
     * @param prefix
     * @param relativePath
     * @return A normalized URI or null
     */
    public static String normalizeURI(String prefix, String relativePath) {
        if (prefix == null)
            return relativePath;
        if (relativePath == null)
            return prefix;
        if (relativePath.startsWith(prefix)) //$NON-NLS-1$
            return relativePath;
        if (!relativePath.startsWith("//")) {
            if (relativePath.startsWith("/")) //$NON-NLS-1$
                relativePath = relativePath.substring(1);
            if (prefix.endsWith("/")) //$NON-NLS-1$
                return prefix + relativePath;
            else if (prefix.startsWith("urn:")) //$NON-NLS-1$
                return prefix + relativePath;
            else
                return prefix + '/' + relativePath;
        }
        return null;
    }
}

Related

  1. normalizeResourcesPath(final String path)
  2. normalizeRootPath(String rootPath)
  3. normalizeSlashes(final String path)
  4. normalizeSlashes(String path)
  5. normalizeToDir(CharSequence path)
  6. normalizeUriPath(String path)
  7. normalizeUrlPath(String name)
  8. normalizeUrlPath(String protocol, String host, int portNumber, String basePath)
  9. normalizeZKPath(String basePath, String child)