com.hp.hpl.mesa.rdf.jena.common.prettywriter
Class PrettyWriter

java.lang.Object
  |
  +--com.hp.hpl.mesa.rdf.jena.common.prettywriter.PrettyWriter
All Implemented Interfaces:
RDFErrorHandler, RDFWriter

public class PrettyWriter
extends java.lang.Object
implements RDFWriter, RDFErrorHandler

Writes out RDF in the abbreviated syntax, for human consumption not only machine readable. It is not normal to call the constructor directly, but to use the method RDFWriterF.getWriter("RDF/XML-ABBREV"). Does not support the NSPREFIXPROPBASE system properties. Use setNsPrefix. For best results it is necessary to set the property "prettyTypes". See setProperty for information.

Version:
Release='$Name: $' Revision='$Revision: 1.6 $' Date='$Date: 2002/08/03 05:43:03 $'
Author:
jjc
See Also:
RDFWriterF.getWriter()

Field Summary
 
Fields inherited from interface com.hp.hpl.mesa.rdf.jena.model.RDFWriter
NSPREFIXPROPBASE
 
Constructor Summary
PrettyWriter()
           
 
Method Summary
 void error(java.lang.Exception e)
          report an error
 void fatalError(java.lang.Exception e)
          report a catastrophic error.
static void main(java.lang.String[] args)
           
 RDFErrorHandler setErrorHandler(RDFErrorHandler errHandler)
          Set an error handler.
 void setNsPrefix(java.lang.String prefix, java.lang.String ns)
          Set the the namespace prefix to be used for a particular namespace.
 java.lang.Object setProperty(java.lang.String propName, java.lang.Object propValue)
          Sets properties on this writer.
 void warning(java.lang.Exception e)
          report a warning
 void write(Model model, java.io.OutputStream out, java.lang.String base)
           
 void write(Model model, java.io.Writer out, java.lang.String base)
          Serialize Model model to Writer out.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PrettyWriter

public PrettyWriter()
Method Detail

setErrorHandler

public RDFErrorHandler setErrorHandler(RDFErrorHandler errHandler)
Set an error handler.

Specified by:
setErrorHandler in interface RDFWriter
Parameters:
errHandler - The new error handler to be used.
Returns:
the old error handler

setNsPrefix

public void setNsPrefix(java.lang.String prefix,
                        java.lang.String ns)
Set the the namespace prefix to be used for a particular namespace.

Specified by:
setNsPrefix in interface RDFWriter
Parameters:
prefix - the prefix to be used
ns - the namespace

setProperty

public java.lang.Object setProperty(java.lang.String propName,
                                    java.lang.Object propValue)
                             throws RDFException
Sets properties on this writer. Current properties are:
xmlbase
Allows the specification of the value for xml:base in the file, as a string.
showXmlDeclaration
can be true, false or "default" (null) If true, an XML Declaration is included in the output, if false no XML declaration is included. The default behaviour only gives an XML Declaration when asked to write to an OutputStreamWriter that uses some encoding other than UTF-8. In this case the encoding is shown in the XML declaration.
prettyTypes
the types of the principal objects in the model. PrettyWriter will tend to create RDF/XML with resources of these types at the top level.
Example usage showing the default value:
 prettyWriter.setProperty("prettyTypes",new Resource[]{
               DAML.Ontology,
               DAML.Class,
               DAML.Datatype,
               DAML.Property,
               DAML.ObjectProperty,
               DAML.DatatypeProperty,
               DAML.TransitiveProperty,
               DAML.UnambigousProperty,
               DAML.UniqueProperty,
               });
      

Specified by:
setProperty in interface RDFWriter
Parameters:
propName - Must be one of "xmlbase", "showXmlDeclaration", "prettyTypes"
propValue - Appropriate value for the property. i.e. For
xmlbase
A string, representing a URI.
showXmlDeclaration
A Boolean, null, or the strings "true", "false", or "default"
prettyTypes
An array of Resource's being types of objects to show at the top level.
Returns:
the old value for this property, or null if no value was set.
Throws:
RDFException - Throws a generic RDF exception

write

public void write(Model model,
                  java.io.Writer out,
                  java.lang.String base)
           throws RDFException
Serialize Model model to Writer out.

Specified by:
write in interface RDFWriter
Parameters:
out - The Writer to which the serialization should be sent.
model - The model to be written.
base - the base URI for relative URI calculations. null means use only absolute URI's.
Throws:
RDFException - Generic RDF exception.

write

public void write(Model model,
                  java.io.OutputStream out,
                  java.lang.String base)
           throws RDFException
RDFException

error

public void error(java.lang.Exception e)
Description copied from interface: RDFErrorHandler
report an error

Specified by:
error in interface RDFErrorHandler
Parameters:
e - an exception representing the error

warning

public void warning(java.lang.Exception e)
Description copied from interface: RDFErrorHandler
report a warning

Specified by:
warning in interface RDFErrorHandler
Parameters:
e - an exception representing the error

fatalError

public void fatalError(java.lang.Exception e)
Description copied from interface: RDFErrorHandler
report a catastrophic error. Must not return.

Specified by:
fatalError in interface RDFErrorHandler
Parameters:
e - an exception representing the error

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
java.lang.Exception


Copyright © 2001 Hewlett-Packard. All Rights Reserved.