001 /*
002 * (c) Copyright 2009 University of Bristol
003 * All rights reserved.
004 * [See end of file]
005 */
006
007 package rdfa;
008
009 import com.hp.hpl.jena.rdf.model.Model;
010 import com.hp.hpl.jena.rdf.model.ModelFactory;
011 import com.hp.hpl.jena.util.FileManager;
012 import java.io.InputStream;
013 import java.util.LinkedList;
014 import java.util.List;
015 import net.rootdev.javardfa.Version;
016
017 /**
018 * Simple command line tool. Uses Jena, and doesn't stream, so output
019 * is much nicer than simpleparse.
020 *
021 * @author pldms
022 */
023 public class parse {
024
025 public static void main(String... args) throws ClassNotFoundException {
026 if (args.length == 0) usage();
027 if ("--version".equals(args[0]) || "-v".equals(args[0])) version();
028
029 // Ensure hooks run
030 Class.forName("net.rootdev.javardfa.RDFaReader");
031
032 String format = "XHTML";
033 boolean getFormat = false;
034
035 List<String> uris = new LinkedList<String>();
036
037 for (String arg: args) {
038 if (getFormat) { format = arg; getFormat = false; }
039 else if ("--help".equalsIgnoreCase(arg)) usage();
040 else if ("--format".equalsIgnoreCase(arg)) getFormat = true;
041 else uris.add(arg);
042 }
043
044 if (getFormat) usage();
045
046 Model m = ModelFactory.createDefaultModel();
047 FileManager fm = FileManager.get();
048 for (String uri: uris) {
049 InputStream in = fm.open(uri);
050 m.read(in, uri, format);
051 }
052 m.write(System.out, "TTL");
053 }
054
055 private static void usage() {
056 System.err.println("rdfa.parse [--version] [--format XHTML|HTML] <url> [...]");
057 System.exit(0);
058 }
059
060 private static void version() {
061 System.err.println(Version.get());
062 System.exit(0);
063 }
064
065 }
066
067 /*
068 * (c) Copyright 2009 University of Bristol
069 * All rights reserved.
070 *
071 * Redistribution and use in source and binary forms, with or without
072 * modification, are permitted provided that the following conditions
073 * are met:
074 * 1. Redistributions of source code must retain the above copyright
075 * notice, this list of conditions and the following disclaimer.
076 * 2. Redistributions in binary form must reproduce the above copyright
077 * notice, this list of conditions and the following disclaimer in the
078 * documentation and/or other materials provided with the distribution.
079 * 3. The name of the author may not be used to endorse or promote products
080 * derived from this software without specific prior written permission.
081 *
082 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
083 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
084 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
085 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
086 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
087 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
088 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
089 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
090 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
091 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
092 */