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