/*
 * Copyright (C) 2008 TranceCode Software
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 * 
 * 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.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
 *
 * $Id$
 */
package org.trancecode.io;

import java.net.URI;
import java.net.URISyntaxException;

import org.trancecode.annotation.Nullable;
import org.trancecode.annotation.ReturnsNullable;

/**
 * Utility methods related to {@link URI}.
 * 
 * @author Herve Quiroz
 */
public final class Uris
{
    private Uris()
    {
        // To prevent instantiation
    }

    @ReturnsNullable
    public static URI createUri(@Nullable final String uri)
    {
        if (uri == null || uri.length() == 0)
        {
            return null;
        }

        return URI.create(uri);
    }

    @ReturnsNullable
    public static URI resolve(@Nullable final String href, @Nullable final String base)
    {
        return resolve(createUri(href), createUri(base));
    }

    @ReturnsNullable
    public static URI resolve(@Nullable final URI href, @Nullable final URI base)
    {
        if (base == null)
        {
            return href;
        }

        if (href == null)
        {
            return base;
        }

        return base.resolve(href);
    }

    public static boolean isValidUri(final String string)
    {
        try
        {
            new URI(string);
            return true;
        }
        catch (final URISyntaxException e)
        {
            return false;
        }
    }
}

@@ -820,16 +820,62 @@
 de.io;%0A%0A
+import com.google.common.base.Preconditions;%0A%0A
 import j
@@ -2128,11 +2128,952 @@
  %7D%0A    %7D
+%0A%0A    public static URI setPath(final URI uri, final String path)%0A    %7B%0A        Preconditions.checkNotNull(uri);%0A        Preconditions.checkArgument(!uri.isOpaque(), %22URI must be hierarchical: %25s%22, uri);%0A        Preconditions.checkArgument(uri.isAbsolute(), %22URI must be absolute: %25s%22, uri);%0A        try%0A        %7B%0A            return new URI(uri.getScheme(), uri.getAuthority(), path, uri.getQuery(), uri.getFragment());%0A        %7D%0A        catch (final URISyntaxException e)%0A        %7B%0A            throw new IllegalStateException(String.format(%22uri = %25s ; path = %25s%22, uri, path), e);%0A        %7D%0A    %7D%0A%0A    public static URI asDirectory(final URI uri)%0A    %7B%0A        Preconditions.checkNotNull(uri);%0A        Preconditions.checkArgument(!uri.isOpaque(), %22URI must be hierarchical: %25s%22, uri);%0A        Preconditions.checkArgument(uri.isAbsolute(), %22URI must be absolute: %25s%22, uri);%0A        return setPath(uri, Paths.asDirectory(uri.getPath()));%0A    %7D
 %0A%7D%0A

Add Uris.setPath() and Uris.asDirectory()