01: /*
02: * (c) Copyright 2003, 2004, Hewlett-Packard Development Company, LP
03: * All rights reserved.
04: * [See end of file]
05: * $Id: Tutorial07.java,v 1.4 2007/11/14 15:30:32 chris-dollin Exp $
06: */
07: package jena.examples.rdf;
08:
09: import com.hp.hpl.jena.rdf.model.*;
10: import com.hp.hpl.jena.util.FileManager;
11: import com.hp.hpl.jena.vocabulary.*;
12:
13: import java.io.*;
14:
15: /** Tutorial 7 - selecting the VCARD resources
16: *
17: * @author bwm - updated by kers/Daniel
18: * @version Release='$Name: $' Revision='$Revision: 1.4 $' Date='$Date: 2007/11/14 15:30:32 $'
19: */
20: public class Tutorial07 extends Object {
21:
22: static final String inputFileName = "vc-db-1.rdf";
23:
24: public static void main(String args[]) {
25: // create an empty model
26: Model model = ModelFactory.createDefaultModel();
27:
28: // use the FileManager to find the input file
29: InputStream in = FileManager.get().open(inputFileName);
30: if (in == null) {
31: throw new IllegalArgumentException("File: " + inputFileName
32: + " not found");
33: }
34:
35: // read the RDF/XML file
36: model.read(in, "");
37:
38: // select all the resources with a VCARD.FN property
39: ResIterator iter = model.listResourcesWithProperty(VCARD.FN);
40: if (iter.hasNext()) {
41: System.out.println("The database contains vcards for:");
42: while (iter.hasNext()) {
43: System.out.println(" "
44: + iter.nextResource().getRequiredProperty(
45: VCARD.FN).getString());
46: }
47: } else {
48: System.out.println("No vcards were found in the database");
49: }
50: }
51: }
52:
53: /*
54: * (c) Copyright 2003, 2004 Hewlett-Packard Development Company, LP
55: * All rights reserved.
56: *
57: * Redistribution and use in source and binary forms, with or without
58: * modification, are permitted provided that the following conditions
59: * are met:
60: * 1. Redistributions of source code must retain the above copyright
61: * notice, this list of conditions and the following disclaimer.
62: * 2. Redistributions in binary form must reproduce the above copyright
63: * notice, this list of conditions and the following disclaimer in the
64: * documentation and/or other materials provided with the distribution.
65: * 3. The name of the author may not be used to endorse or promote products
66: * derived from this software without specific prior written permission.
67: *
68: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
69: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
70: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
71: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
72: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
73: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
74: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
75: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
76: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
77: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
78: */
|