001: /*
002: * (c) Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: * 1. Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: * 2. Redistributions in binary form must reproduce the above copyright
011: * notice, this list of conditions and the following disclaimer in the
012: * documentation and/or other materials provided with the distribution.
013: * 3. The name of the author may not be used to endorse or promote products
014: * derived from this software without specific prior written permission.
015:
016: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
017: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
018: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
019: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
020: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
021: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
022: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
023: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
024: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
025: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
026: *
027: * $Id: RDFWriterFImpl.java,v 1.17 2008/01/02 12:05:01 andy_seaborne Exp $
028: */
029:
030: package com.hp.hpl.jena.rdf.model.impl;
031:
032: import com.hp.hpl.jena.*;
033: import com.hp.hpl.jena.rdf.model.*;
034:
035: import java.util.Properties;
036: import com.hp.hpl.jena.shared.*;
037: import com.hp.hpl.jena.n3.N3JenaWriter;
038: import com.hp.hpl.jena.JenaRuntime;
039:
040: /**
041: *
042: * @author bwm
043: * @version $Revision: 1.17 $ $Date: 2008/01/02 12:05:01 $
044: */
045: public class RDFWriterFImpl extends Object implements RDFWriterF {
046:
047: protected static Properties langToClassName = null;
048:
049: // predefined languages - these should probably go in a properties file
050:
051: protected static final String LANGS[] = { "RDF/XML",
052: "RDF/XML-ABBREV", "N-TRIPLE", "N-TRIPLES", "N3",
053: N3JenaWriter.n3WriterPrettyPrinter,
054: N3JenaWriter.n3WriterPlain, N3JenaWriter.n3WriterTriples,
055: N3JenaWriter.n3WriterTriplesAlt, N3JenaWriter.turtleWriter,
056: N3JenaWriter.turtleWriterAlt1,
057: N3JenaWriter.turtleWriterAlt2 };
058: // default readers for each language
059:
060: protected static final String DEFAULTWRITERS[] = {
061: Jena.PATH + ".xmloutput.impl.Basic",
062: Jena.PATH + ".xmloutput.impl.Abbreviated",
063: Jena.PATH + ".rdf.model.impl.NTripleWriter",
064: Jena.PATH + ".rdf.model.impl.NTripleWriter",
065: Jena.PATH + ".n3.N3JenaWriter",
066: Jena.PATH + ".n3.N3JenaWriterPP",
067: Jena.PATH + ".n3.N3JenaWriterPlain",
068: Jena.PATH + ".n3.N3JenaWriterTriples",
069: Jena.PATH + ".n3.N3JenaWriterTriples", // Same writer, different writer name
070: Jena.PATH + ".n3.N3TurtleJenaWriter", // Alternative names for Turtle
071: Jena.PATH + ".n3.N3TurtleJenaWriter",
072: Jena.PATH + ".n3.N3TurtleJenaWriter", };
073:
074: protected static final String DEFAULTLANG = LANGS[0];
075:
076: protected static final String PROPNAMEBASE = Jena.PATH + ".writer.";
077:
078: static { // static initializer - set default readers
079: langToClassName = new Properties();
080: for (int i = 0; i < LANGS.length; i++) {
081: langToClassName.setProperty(LANGS[i], JenaRuntime
082: .getSystemProperty(PROPNAMEBASE + LANGS[i],
083: DEFAULTWRITERS[i]));
084: }
085: }
086:
087: /** Creates new RDFReaderFImpl */
088: public RDFWriterFImpl() {
089: }
090:
091: public RDFWriter getWriter() {
092: return getWriter(DEFAULTLANG);
093: }
094:
095: public RDFWriter getWriter(String lang) {
096:
097: // setup default language
098: if (lang == null || lang.equals("")) {
099: lang = LANGS[0];
100: }
101:
102: String className = langToClassName.getProperty(lang);
103: if (className == null || className.equals("")) {
104: throw new NoWriterForLangException(lang);
105: }
106: try {
107: return (RDFWriter) Class.forName(className).newInstance();
108: } catch (Exception e) {
109: throw new JenaException(e);
110: }
111: }
112:
113: public String setWriterClassName(String lang, String className) {
114: String oldClassName = langToClassName.getProperty(lang);
115: langToClassName.setProperty(lang, className);
116: return oldClassName;
117: }
118: }
|