1 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 ; 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 46 public class RDFWriterFImpl extends Object implements RDFWriterF { 47 48 protected static Properties langToClassName = null; 49 50 52 protected static final String 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 66 protected static final String 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", Jena.PATH + ".n3.TurtleJenaWriter", 78 }; 79 80 protected static final String DEFAULTLANG = LANGS[0]; 81 82 protected static final String PROPNAMEBASE = Jena.PATH + ".writer."; 83 84 static { langToClassName = new Properties (); 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 94 public RDFWriterFImpl() { 95 } 96 97 public RDFWriter getWriter() { 98 return getWriter(DEFAULTLANG); 99 } 100 101 public RDFWriter getWriter(String lang) { 102 103 if (lang == null || lang.equals("")) { 105 lang = LANGS[0]; 106 } 107 108 String 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 e) { 115 throw new JenaException(e); 116 } 117 } 118 119 public String setWriterClassName(String lang, String className) { 120 String oldClassName = langToClassName.getProperty(lang); 121 langToClassName.setProperty(lang, className); 122 return oldClassName; 123 } 124 } 125 | Popular Tags |