KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > joseki > rdffetch


1 /*
2  * (c) Copyright 2003, 2004 Hewlett-Packard Development Company, LP
3  * [See end of file]
4  */

5
6 package joseki;
7
8 import jena.cmdline.*;
9 import com.hp.hpl.jena.joseki.* ;
10 import com.hp.hpl.jena.rdf.model.* ;
11
12 /** Command line application to issue queries against a remote model.
13  *
14  * @author Andy Seaborne
15  * @version $Id: rdffetch.java,v 1.3 2004/04/30 14:13:14 andy_seaborne Exp $
16  */

17
18
19 public class rdffetch
20 {
21     public static final String JavaDoc defaultURL = "http://localhost:2020/rdfserver/rdf" ;
22     
23     public static boolean VERBOSE = false ;
24     public static boolean DEBUG = false ;
25     
26     public static void main (String JavaDoc args[])
27     {
28         try {
29             String JavaDoc usageMessage = rdffetch.class.getName()+
30                                     " [--verbose] [--format fmt] "+
31                                     "--model modelURL --resource URI";
32
33             CommandLine cmd = new CommandLine() ;
34             cmd.setUsage(usageMessage) ;
35
36             ArgDecl verboseDecl = new ArgDecl(false, "-v", "--verbose") ;
37             ArgDecl modelDecl = new ArgDecl(true, "model", "url") ;
38             ArgDecl resDecl = new ArgDecl(true, "resource", "r") ;
39             
40             cmd.add(verboseDecl) ;
41             cmd.add(modelDecl) ;
42             cmd.add(resDecl) ;
43             
44             cmd.add("--format", true) ;
45             cmd.add("--debug", false) ;
46
47             // Addition argument, after the flags, is a query
48
cmd.process(args) ;
49
50             if ( cmd.contains("--debug") )
51                 DEBUG = true ;
52
53             if ( cmd.contains("--help") )
54             {
55                 System.err.println(usageMessage) ;
56                 System.exit(0) ;
57             }
58
59             if ( cmd.contains(verboseDecl) )
60                 VERBOSE = true ;
61             
62                 
63             if ( ! cmd.contains(modelDecl) )
64             {
65                 System.err.println(usageMessage) ;
66                 System.err.println("Required argument: --model") ;
67                 System.exit(8) ;
68             }
69
70             if ( ! cmd.contains(resDecl) )
71             {
72                 System.err.println(usageMessage) ;
73                 System.err.println("Required argument: --resource") ;
74                 System.exit(8) ;
75             }
76             
77             String JavaDoc format = "N3" ;
78             String JavaDoc modelStr = cmd.getArg(modelDecl).getValue() ;
79             String JavaDoc resource = cmd.getArg(resDecl).getValue() ;
80             
81             if ( cmd.contains("format") )
82                 format = cmd.getArg("format").getValue() ;
83             
84             HttpFetch fetch = new HttpFetch(modelStr, resource) ;
85             Model obj = fetch.exec() ;
86             
87             obj.write(System.out, format) ;
88             
89         }
90         catch (Exception JavaDoc e)
91         {
92             e.printStackTrace(System.err) ;
93             System.exit(9) ;
94         }
95     }
96 }
97
98 /*
99  * (c) Copyright 2003, 2004 Hewlett-Packard Development Company, LP
100  * All rights reserved.
101  *
102  * Redistribution and use in source and binary forms, with or without
103  * modification, are permitted provided that the following conditions
104  * are met:
105  * 1. Redistributions of source code must retain the above copyright
106  * notice, this list of conditions and the following disclaimer.
107  * 2. Redistributions in binary form must reproduce the above copyright
108  * notice, this list of conditions and the following disclaimer in the
109  * documentation and/or other materials provided with the distribution.
110  * 3. The name of the author may not be used to endorse or promote products
111  * derived from this software without specific prior written permission.
112  *
113  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
114  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
115  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
116  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
117  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
118  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
119  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
120  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
121  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
122  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
123  */

124
Popular Tags