001/*
002 * (c) Copyright 2009 University of Bristol
003 * All rights reserved.
004 * [See end of file]
005 */
006
007package net.rootdev.javardfa.uri;
008
009import java.net.URI;
010import java.net.URISyntaxException;
011import net.rootdev.javardfa.Resolver;
012
013/**
014 * Resolver that uses java's URI library.
015 * The IRI resolver is strongly recommended over this.
016 *
017 * @author pldms
018 */
019public class URIResolver implements Resolver {
020
021    public URIResolver() { }
022
023    public String resolve(String first, String second) {
024        try {
025            URI uri = new URI(first);
026            return uri.resolve(second).toString();
027        } catch (URISyntaxException ex) {
028            // TODO Is this a good idea???
029            return null;
030        } catch (IllegalArgumentException ex) {
031            // See above
032            return null;
033        }
034    }
035
036}
037
038/*
039 * (c) Copyright 2009 University of Bristol
040 * All rights reserved.
041 *
042 * Redistribution and use in source and binary forms, with or without
043 * modification, are permitted provided that the following conditions
044 * are met:
045 * 1. Redistributions of source code must retain the above copyright
046 *    notice, this list of conditions and the following disclaimer.
047 * 2. Redistributions in binary form must reproduce the above copyright
048 *    notice, this list of conditions and the following disclaimer in the
049 *    documentation and/or other materials provided with the distribution.
050 * 3. The name of the author may not be used to endorse or promote products
051 *    derived from this software without specific prior written permission.
052 *
053 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
054 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
055 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
056 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
057 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
058 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
059 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
060 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
061 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
062 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
063 */