/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package jena;

import static org.apache.jena.atlas.logging.LogCtl.setCmdLogging;

import java.net.URL;
import java.io.FileInputStream;

import org.apache.jena.rdf.model.* ;

/** A program which read two RDF models and determines if they are the same.
 *
 *  <p>This program will read two RDF models, in a variety of languages,
 *     and compare them.  Input can be read either from a URL or from a file.
 *     The program writes its results to the standard output stream and sets
 *     its exit code to 0 if the models are equal, to 1 if they are not and
 *     to -1 if it encounters an error.</p>
 *
 *  <p></p>
 *
 *  <pre>java jena.rdfcompare model1 model2 [lang1 [lang2]]
 *
 *       model1 and model2 can be file names or URL's
 *       lang1 and lang2 specify the language of the input and can be:
 *           RDF/XML
 *           N-TRIPLE
 *           N3
 *  </pre>
 */
public class rdfcompare extends java.lang.Object {

    static { setCmdLogging(); }

    /**
    * @param args the command line arguments
    */
    public static void main (String ... args) {
        if (args.length < 2 || args.length > 4) {
            usage();
            System.exit(-1);
        }
        
        String in1 = args[0];
        String in2 = args[1];
        String lang1 = "RDF/XML";
        if (args.length > 2) {
            lang1 = args[2];
        } 
        String lang2 = "N-TRIPLE";
        if (args.length == 4) {
            lang2 = args[3];
        }
        
        System.out.println(in1 + " " + in2 + " " + lang1 + " " + lang2);
        try {
            Model m1 = ModelFactory.createDefaultModel();
            Model m2 = ModelFactory.createDefaultModel();
        
            read(m1, in1, lang1);
            read(m2, in2, lang2);
        
            if (m1.isIsomorphicWith(m2)) {
                System.out.println("models are equal");
                System.out.println();
                System.exit(0);
            } else {
                System.out.println("models are unequal");
                System.out.println();
                System.exit(1);
            }
        } catch (Exception e) {
            System.err.println("Unhandled exception:");
            System.err.println("    " + e.toString());
            System.exit(-1);
        }
    }
    
    protected static void usage() {
        System.err.println("usage:");
        System.err.println(
            "    java jena.rdfcompare source1 source2 [lang1 [lang2]]");
        System.err.println();
        System.err.println("    source1 and source2 can be URL's or filenames");
        System.err.println("    lang1 and lang2 can take values:");
        System.err.println("      RDF/XML");
        System.err.println("      N-TRIPLE");
        System.err.println("      N3");
        System.err.println("    lang1 defaults to RDF/XML, lang2 to N-TRIPLE");
        System.err.println();
    }
    
    protected static void read(Model model, String in, String lang) 
      throws java.io.FileNotFoundException {
        try {
            URL url = new URL(in);
            model.read(in, lang);
        } catch (java.net.MalformedURLException e) {
            model.read(new FileInputStream(in), "", lang);
        }
    }
}

@@ -1920,17 +1920,17 @@
 ength %3E 
-4
+6
 ) %7B%0A    
@@ -2113,18 +2113,19 @@
 length %3E
- 2
+= 3
 ) %7B%0A    
@@ -2219,17 +2219,17 @@
 .length 
-=
+%3E
 = 4) %7B%0A 
@@ -2258,32 +2258,233 @@
 s%5B3%5D;%0A        %7D%0A
+        String base1 = null;%0A        if (args.length %3E= 5) %7B%0A            base1 = args%5B4%5D;%0A        %7D%0A        String base2 = base1;%0A        if (args.length %3E= 6) %7B%0A            base2 = args%5B5%5D;%0A        %7D%0A
         %0A       
@@ -2542,24 +2542,52 @@
  %22 %22 + lang2
+ + %22 %22 + base1 + %22 %22 + base2
 );%0A        t
@@ -2747,16 +2747,23 @@
 1, lang1
+, base1
 );%0A     
@@ -2788,16 +2788,23 @@
 2, lang2
+, base2
 );%0A     
@@ -3501,16 +3501,32 @@
 1 %5Blang2
+ %5Bbase1 %5Bbase2%5D%5D
 %5D%5D%22);%0A  
@@ -3905,32 +3905,338 @@
  to N-TRIPLE%22);%0A
+        System.err.println(%22    base1 and base2 are URIs%22);%0A        System.err.println(%22    base1 defaults to null%22);%0A        System.err.println(%22    base2 defaults to base1%22);%0A        System.err.println(%22    If no base URIs are specified Jena determines the base URI based on the input source%22);%0A        %0A
         System.e
@@ -4326,16 +4326,29 @@
 ing lang
+, String base
 ) %0A     
@@ -4462,16 +4462,22 @@
 read(in,
+ base,
  lang);%0A
@@ -4581,10 +4581,12 @@
 n), 
-%22%22
+base
 , la

Add support for specifying base URIs to rdfcompare