KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdf > model > impl > RDFWriterFImpl


1 /*
2  * (c) Copyright 2000, 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * $Id: RDFWriterFImpl.java,v 1.12 2005/02/21 12:14:50 andy_seaborne Exp $
28  */

29
30 package com.hp.hpl.jena.rdf.model.impl;
31
32 import com.hp.hpl.jena.*;
33 import com.hp.hpl.jena.rdf.model.*;
34
35 import java.util.Properties JavaDoc;
36 import com.hp.hpl.jena.shared.*;
37 import com.hp.hpl.jena.n3.N3JenaWriter;
38 import com.hp.hpl.jena.JenaRuntime ;
39
40
41 /**
42  *
43  * @author bwm
44  * @version $Revision: 1.12 $ $Date: 2005/02/21 12:14:50 $
45  */

46 public class RDFWriterFImpl extends Object JavaDoc implements RDFWriterF {
47
48     protected static Properties JavaDoc langToClassName = null;
49
50     // predefined languages - these should probably go in a properties file
51

52     protected static final String JavaDoc LANGS[] =
53         { "RDF/XML",
54           "RDF/XML-ABBREV",
55           "N-TRIPLE",
56           "N-TRIPLES",
57           "N3",
58           N3JenaWriter.n3WriterPrettyPrinter,
59           N3JenaWriter.n3WriterPlain,
60           N3JenaWriter.n3WriterTriples,
61           N3JenaWriter.n3WriterTriplesAlt,
62           N3JenaWriter.turtleWriter
63         };
64     // default readers for each language
65

66     protected static final String JavaDoc DEFAULTWRITERS[] =
67         {
68             Jena.PATH + ".xmloutput.impl.Basic",
69             Jena.PATH + ".xmloutput.impl.Abbreviated",
70             Jena.PATH + ".rdf.model.impl.NTripleWriter",
71             Jena.PATH + ".rdf.model.impl.NTripleWriter",
72             Jena.PATH + ".n3.N3JenaWriter",
73             Jena.PATH + ".n3.N3JenaWriterPP",
74             Jena.PATH + ".n3.N3JenaWriterPlain",
75             Jena.PATH + ".n3.N3JenaWriterTriples",
76             Jena.PATH + ".n3.N3JenaWriterTriples", // Same writer, different writer name
77
Jena.PATH + ".n3.TurtleJenaWriter",
78              };
79
80     protected static final String JavaDoc DEFAULTLANG = LANGS[0];
81
82     protected static final String JavaDoc PROPNAMEBASE = Jena.PATH + ".writer.";
83
84     static { // static initializer - set default readers
85
langToClassName = new Properties JavaDoc();
86         for (int i = 0; i < LANGS.length; i++) {
87             langToClassName.setProperty(
88                 LANGS[i],
89                 JenaRuntime.getSystemProperty(PROPNAMEBASE + LANGS[i], DEFAULTWRITERS[i]));
90         }
91     }
92
93     /** Creates new RDFReaderFImpl */
94     public RDFWriterFImpl() {
95     }
96
97     public RDFWriter getWriter() {
98         return getWriter(DEFAULTLANG);
99     }
100
101     public RDFWriter getWriter(String JavaDoc lang) {
102
103         // setup default language
104
if (lang == null || lang.equals("")) {
105             lang = LANGS[0];
106         }
107
108         String JavaDoc className = langToClassName.getProperty(lang);
109         if (className == null || className.equals("")) {
110             throw new NoWriterForLangException( lang );
111         }
112         try {
113             return (RDFWriter) Class.forName(className).newInstance();
114         } catch (Exception JavaDoc e) {
115             throw new JenaException(e);
116         }
117     }
118
119     public String JavaDoc setWriterClassName(String JavaDoc lang, String JavaDoc className) {
120         String JavaDoc oldClassName = langToClassName.getProperty(lang);
121         langToClassName.setProperty(lang, className);
122         return oldClassName;
123     }
124 }
125
Popular Tags