Source Code Cross Referenced for Rio.java in  » RSS-RDF » sesame » org » openrdf » rio » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » RSS RDF » sesame » org.openrdf.rio 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2007.
003:         *
004:         * Licensed under the Aduna BSD-style license.
005:         */
006:        package org.openrdf.rio;
007:
008:        import java.io.FileInputStream;
009:        import java.io.FileOutputStream;
010:        import java.io.IOException;
011:        import java.io.OutputStream;
012:        import java.io.Writer;
013:
014:        import org.openrdf.model.ValueFactory;
015:
016:        /**
017:         * Factory class providing static methods for creating RDF parsers and -writers
018:         * for various RDF file formats.
019:         * 
020:         * @author Arjohn Kampman
021:         */
022:        public class Rio {
023:
024:            /**
025:             * Tries to match a MIME type against the list of RDF formats that can be
026:             * parsed.
027:             * 
028:             * @param mimeType
029:             *        A MIME type, e.g. "application/rdf+xml".
030:             * @return An RDFFormat object if a match was found, or <tt>null</tt>
031:             *         otherwise.
032:             * @see #getParserFormatForMIMEType(String, RDFFormat)
033:             */
034:            public static RDFFormat getParserFormatForMIMEType(String mimeType) {
035:                return getParserFormatForMIMEType(mimeType, null);
036:            }
037:
038:            /**
039:             * Tries to match a MIME type against the list of RDF formats that can be
040:             * parsed. This method calls
041:             * {@link RDFFormat#matchMIMEType(String, Iterable)} with the specified MIME
042:             * type, the keys of {@link RDFParserRegistry#getInstance()} and the fallback
043:             * format as parameters.
044:             * 
045:             * @param mimeType
046:             *        A MIME type, e.g. "application/rdf+xml".
047:             * @param fallback
048:             *        The format that will be returned if no match was found.
049:             * @return The matching RDFFormat, or <tt>fallback</tt> if no match was
050:             *         found.
051:             */
052:            public static RDFFormat getParserFormatForMIMEType(String mimeType,
053:                    RDFFormat fallback) {
054:                return RDFFormat.matchMIMEType(mimeType, RDFParserRegistry
055:                        .getInstance().getKeys(), fallback);
056:            }
057:
058:            /**
059:             * Tries to match the extension of a file name against the list of RDF
060:             * formats that can be parsed.
061:             * 
062:             * @param fileName
063:             *        A file name.
064:             * @return An RDFFormat object if a match was found, or <tt>null</tt>
065:             *         otherwise.
066:             * @see #getParserFormatForFileName(String, RDFFormat)
067:             */
068:            public static RDFFormat getParserFormatForFileName(String fileName) {
069:                return getParserFormatForFileName(fileName, null);
070:            }
071:
072:            /**
073:             * Tries to match the extension of a file name against the list of RDF
074:             * formats that can be parsed. This method calls
075:             * {@link RDFFormat#matchFileName(String, Iterable, info.aduna.lang.FileFormat)}
076:             * with the specified MIME type, the keys of
077:             * {@link RDFParserRegistry#getInstance()} and the fallback format as
078:             * parameters.
079:             * 
080:             * @param fileName
081:             *        A file name.
082:             * @param fallback
083:             *        The format that will be returned if no match was found.
084:             * @return The matching RDFFormat, or <tt>fallback</tt> if no match was
085:             *         found.
086:             */
087:            public static RDFFormat getParserFormatForFileName(String fileName,
088:                    RDFFormat fallback) {
089:                return RDFFormat.matchFileName(fileName, RDFParserRegistry
090:                        .getInstance().getKeys(), fallback);
091:            }
092:
093:            /**
094:             * Tries to match a MIME type against the list of RDF formats that can be
095:             * written.
096:             * 
097:             * @param mimeType
098:             *        A MIME type, e.g. "application/rdf+xml".
099:             * @return An RDFFormat object if a match was found, or <tt>null</tt>
100:             *         otherwise.
101:             * @see #getWriterFormatForMIMEType(String, RDFFormat)
102:             */
103:            public static RDFFormat getWriterFormatForMIMEType(String mimeType) {
104:                return getWriterFormatForMIMEType(mimeType, null);
105:            }
106:
107:            /**
108:             * Tries to match a MIME type against the list of RDF formats that can be
109:             * written. This method calls
110:             * {@link RDFFormat#matchMIMEType(String, Iterable, info.aduna.lang.FileFormat)}
111:             * with the specified MIME type, the keys of
112:             * {@link RDFWriterRegistry#getInstance()} and the fallback format as
113:             * parameters.
114:             * 
115:             * @param mimeType
116:             *        A MIME type, e.g. "application/rdf+xml".
117:             * @param fallback
118:             *        The format that will be returned if no match was found.
119:             * @return The matching RDFFormat, or <tt>fallback</tt> if no match was
120:             *         found.
121:             */
122:            public static RDFFormat getWriterFormatForMIMEType(String mimeType,
123:                    RDFFormat fallback) {
124:                return RDFFormat.matchMIMEType(mimeType, RDFWriterRegistry
125:                        .getInstance().getKeys(), fallback);
126:            }
127:
128:            /**
129:             * Tries to match the extension of a file name against the list of RDF
130:             * formats that can be written.
131:             * 
132:             * @param fileName
133:             *        A file name.
134:             * @return An RDFFormat object if a match was found, or <tt>null</tt>
135:             *         otherwise.
136:             * @see #getWriterFormatForFileName(String, RDFFormat)
137:             */
138:            public static RDFFormat getWriterFormatForFileName(String fileName) {
139:                return getWriterFormatForFileName(fileName, null);
140:            }
141:
142:            /**
143:             * Tries to match the extension of a file name against the list of RDF
144:             * formats that can be written. This method calls
145:             * {@link RDFFormat#matchFileName(String, Iterable, info.aduna.lang.FileFormat)}
146:             * with the specified MIME type, the keys of
147:             * {@link RDFWriterRegistry#getInstance()} and the fallback format as
148:             * parameters.
149:             * 
150:             * @param fileName
151:             *        A file name.
152:             * @param fallback
153:             *        The format that will be returned if no match was found.
154:             * @return The matching RDFFormat, or <tt>fallback</tt> if no match was
155:             *         found.
156:             */
157:            public static RDFFormat getWriterFormatForFileName(String fileName,
158:                    RDFFormat fallback) {
159:                return RDFFormat.matchFileName(fileName, RDFWriterRegistry
160:                        .getInstance().getKeys(), fallback);
161:            }
162:
163:            /**
164:             * Convenience methods for creating RDFParser objects. This method uses the
165:             * registry returned by {@link RDFParserRegistry#getInstance()} to get a
166:             * factory for the specified format and uses this factory to create the
167:             * appropriate parser.
168:             * 
169:             * @throws UnsupportedRDFormatException
170:             *         If no parser is available for the specified RDF format.
171:             */
172:            public static RDFParser createParser(RDFFormat format)
173:                    throws UnsupportedRDFormatException {
174:                RDFParserFactory factory = RDFParserRegistry.getInstance().get(
175:                        format);
176:
177:                if (factory != null) {
178:                    return factory.getParser();
179:                }
180:
181:                throw new UnsupportedRDFormatException(
182:                        "No parser factory available for RDF format " + format);
183:            }
184:
185:            /**
186:             * Convenience methods for creating RDFParser objects that use the specified
187:             * ValueFactory to create RDF model objects.
188:             * 
189:             * @throws UnsupportedRDFormatException
190:             *         If no parser is available for the specified RDF format.
191:             * @see #createParser(RDFFormat)
192:             * @see RDFParser#setValueFactory(ValueFactory)
193:             */
194:            public static RDFParser createParser(RDFFormat format,
195:                    ValueFactory valueFactory)
196:                    throws UnsupportedRDFormatException {
197:                RDFParser rdfParser = createParser(format);
198:                rdfParser.setValueFactory(valueFactory);
199:                return rdfParser;
200:            }
201:
202:            /**
203:             * Convenience methods for creating RDFWriter objects. This method uses the
204:             * registry returned by {@link RDFWriterRegistry#getInstance()} to get a
205:             * factory for the specified format and uses this factory to create the
206:             * appropriate writer.
207:             * 
208:             * @throws UnsupportedRDFormatException
209:             *         If no writer is available for the specified RDF format.
210:             */
211:            public static RDFWriter createWriter(RDFFormat format,
212:                    OutputStream out) throws UnsupportedRDFormatException {
213:                RDFWriterFactory factory = RDFWriterRegistry.getInstance().get(
214:                        format);
215:
216:                if (factory != null) {
217:                    return factory.getWriter(out);
218:                }
219:
220:                throw new UnsupportedRDFormatException(
221:                        "No writer factory available for RDF format " + format);
222:            }
223:
224:            /**
225:             * Convenience methods for creating RDFWriter objects. This method uses the
226:             * registry returned by {@link RDFWriterRegistry#getInstance()} to get a
227:             * factory for the specified format and uses this factory to create the
228:             * appropriate writer.
229:             * 
230:             * @throws UnsupportedRDFormatException
231:             *         If no writer is available for the specified RDF format.
232:             */
233:            public static RDFWriter createWriter(RDFFormat format, Writer writer)
234:                    throws UnsupportedRDFormatException {
235:                RDFWriterFactory factory = RDFWriterRegistry.getInstance().get(
236:                        format);
237:
238:                if (factory != null) {
239:                    return factory.getWriter(writer);
240:                }
241:
242:                throw new UnsupportedRDFormatException(
243:                        "No writer factory available for RDF format " + format);
244:            }
245:
246:            public static void main(String[] args) throws IOException,
247:                    RDFParseException, RDFHandlerException,
248:                    UnsupportedRDFormatException {
249:                if (args.length < 2) {
250:                    System.out
251:                            .println("Usage: java org.openrdf.rio.Rio <inputFile> <outputFile>");
252:                    return;
253:                }
254:
255:                // Create parser for input file
256:                String inputFile = args[0];
257:                FileInputStream inStream = new FileInputStream(inputFile);
258:                RDFFormat inputFormat = getParserFormatForFileName(inputFile,
259:                        RDFFormat.RDFXML);
260:                RDFParser rdfParser = createParser(inputFormat);
261:
262:                // Create writer for output file
263:                String outputFile = args[1];
264:                FileOutputStream outStream = new FileOutputStream(outputFile);
265:                RDFFormat outputFormat = getWriterFormatForFileName(outputFile,
266:                        RDFFormat.RDFXML);
267:                RDFWriter rdfWriter = createWriter(outputFormat, outStream);
268:
269:                rdfParser.setRDFHandler(rdfWriter);
270:                rdfParser.parse(inStream, "file:" + inputFile);
271:
272:                inStream.close();
273:                outStream.close();
274:            }
275:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.