RDF::Redland::Serializer - Redland RDF Serializing to Syntax Class


Redland documentation Contained in the Redland distribution.

Index


Code Index:

NAME

Top

RDF::Redland::Serializer - Redland RDF Serializing to Syntax Class

SYNOPSIS

Top

  use RDF::Redland;

  ...
  my $serializer=new RDF::Redland::Serializer("ntriples");

  $serializer->serialize_model_to_file("foo.rdf", $base_uri, $model);

DESCRIPTION

Top

This class represents serializers that turn RDF graphs into various syntaxes. from an RDF::Redland::Model object.

CONSTRUCTORS

Top

new [NAME [MIME_TYPE [URI]]]

Create a new RDF::Redland::Serializer object for a syntax serializer named NAME, with MIME Type MIME_TYPE and/or URI URI. Any field can be undef or omitted; if all are omitted, the default serializer is used, currently 'ntriples'.

METHODS

Top

serialize_model_to_file FILENAME BASE_URI MODEL

Serialize the RDF Graph MODEL as syntax with the base RDF::Redland::URI BASE_URI to file FILENAME.

serialize_model_to_string BASE-URI MODEL

Serialize the RDF Graph MODEL to a syntax. If no serializer name is given, the default serializer RDF/XML is used.

set_namespace PREFIX URI

Define a namespace URI with the supplied PREFIX for use in serializing an RDF Graph.

feature URI [VALUE]

Get/set a serializer feature. The feature is named via RDF::Redland::URI URI and the value is a string. If VALUE is given, the feature is set to that value, otherwise the current value is returned.

SEE ALSO

Top

RDF::Redland::Parser, RDF::Redland::URI

AUTHOR

Top

Dave Beckett - http://purl.org/net/dajobe/


Redland documentation Contained in the Redland distribution.
# -*- Mode: Perl -*-
#
# Serializer.pm - Redland Perl RDF Serializer module
#
# $Id: Serializer.pm 10593 2006-03-05 08:30:38Z dajobe $
#
# Copyright (C) 2002-2005 David Beckett - http://purl.org/net/dajobe/
# Copyright (C) 2002-2005 University of Bristol - http://www.bristol.ac.uk/
# 
# This package is Free Software or Open Source available under the
# following licenses (these are alternatives):
#   1. GNU Lesser General Public License (LGPL)
#   2. GNU General Public License (GPL)
#   3. Mozilla Public License (MPL)
# 
# See LICENSE.html or LICENSE.txt at the top of this package for the
# full license terms.
# 
# 
#

package RDF::Redland::Serializer;

use strict;

use RDF::Redland::Stream;

######################################################################

# CONSTRUCTOR
# (main)
sub new ($;$$$) {
  my($proto,$name,$mime_type,$uri)=@_;
  my $class = ref($proto) || $proto;
  my $self  = {};

  if(defined $uri) {
    $uri=$uri->{URI};
  }

  $self->{SERIALIZER}=&RDF::Redland::CORE::librdf_new_serializer($RDF::Redland::World->{WORLD},$name,$mime_type,$uri);
  return undef if !$self->{SERIALIZER};

  bless ($self, $class);
  return $self;
}

sub DESTROY ($) {
  warn "RDF::Redland::Serializer DESTROY\n" if $RDF::Redland::Debug;
  &RDF::Redland::CORE::librdf_free_serializer(shift->{SERIALIZER});
}

sub serialize_model_to_file ($$$$) {
  my($self,$name,$base_uri,$model)=@_;
  return &RDF::Redland::CORE::librdf_serializer_serialize_model_to_file($self->{SERIALIZER},$name, $base_uri->{URI},$model->{MODEL});
}

sub serialize_model_to_string($$$) {
  my($self,$uri,$model)=@_;

  return &RDF::Redland::CORE::librdf_serializer_serialize_model_to_string($self->{SERIALIZER}, $uri->{URI}, $model->{MODEL});
}


sub set_namespace ($$$) {
  my($self,$prefix, $uri)=@_;

  warn "RDF::Redland::Serializer->namespace('$prefix', '$uri')\n" if $RDF::Redland::Debug;
  $uri=RDF::Redland::URI->new($uri)
    unless ref $uri;

  return &RDF::Redland::CORE::librdf_serializer_set_namespace($self->{SERIALIZER},$uri->{URI}, $prefix);
}


sub feature ($$;$) {
  my($self,$uri,$value)=@_;

  warn "RDF::Redland::Serializer->feature('$uri', '$value')\n" if $RDF::Redland::Debug;
  $uri=RDF::Redland::URI->new($uri)
    unless ref $uri;

  return &RDF::Redland::CORE::librdf_serializer_get_feature($self->{SERIALIZER},$uri->{URI})
    unless $value;

  return &RDF::Redland::CORE::librdf_serializer_set_feature($self->{SERIALIZER},$uri->{URI},$value);
}


1;