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 org.apache.jena.iri.IRI;
010import org.apache.jena.iri.IRIFactory;
011import net.rootdev.javardfa.Resolver;
012
013/**
014 * Resolver that uses the IRI library.
015 * This is the recommended resolver.
016 *
017 * @author pldms
018 */
019public class IRIResolver implements Resolver {
020    private final IRIFactory iriFactory;
021
022    /**
023     * Create a semantic web version
024     */
025    public IRIResolver() {
026        this(IRIFactory.semanticWebImplementation());
027    }
028
029    public IRIResolver(IRIFactory iriFactory) {
030        this.iriFactory = iriFactory;
031    }
032
033    public String resolve(String first, String second) {
034        if (first == null) throw new RuntimeException("Base is null.");
035        IRI iri = iriFactory.construct(first);
036        IRI resolved = iri.resolve(second);
037        return resolved.toString();
038    }
039
040}
041
042/*
043 * (c) Copyright 2009 University of Bristol
044 * All rights reserved.
045 *
046 * Redistribution and use in source and binary forms, with or without
047 * modification, are permitted provided that the following conditions
048 * are met:
049 * 1. Redistributions of source code must retain the above copyright
050 *    notice, this list of conditions and the following disclaimer.
051 * 2. Redistributions in binary form must reproduce the above copyright
052 *    notice, this list of conditions and the following disclaimer in the
053 *    documentation and/or other materials provided with the distribution.
054 * 3. The name of the author may not be used to endorse or promote products
055 *    derived from this software without specific prior written permission.
056 *
057 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
058 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
059 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
060 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
061 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
062 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
063 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
064 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
065 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
066 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
067 */