XRI::Descriptor - Utilities for XRI Descriptor XML doc management


XRI documentation Contained in the XRI distribution.

Index


Code Index:

NAME

Top

XRI::Descriptor - Utilities for XRI Descriptor XML doc management

SYNOPSIS

Top

    use XRI:Descriptor;
    my $XRID = XRI->new($xml_descriptor);

    $resolved = $XRID->getResolved;
    $AuthRef  = $XRID->getXRIAuthorityURIs;
    @uris     = $XRID->getLocalAccess($service, $type);
    $mapRef   = $XRID->getMappings;

ABSTRACT

Top

Utilities for XRI Descriptor XML doc management

DESCRIPTION

Top

This module provides utilities to pull element values from an XRI Descriptor XML file. Example XRI Descriptor XML file:

    <?xml version="1.0" encoding="iso-8859-1"?>
    <XRIDescriptor xmlns="xri:$r*s/XRIDescriptor">
      <Resolved>*user</Resolved>
      <XRIAuthority>
        <URI>http://community.broker.com/</URI>
      </XRIAuthority>
      <LocalAccess>
        <Service>xri:$r*a/XRIDB</Service>
        <URI>http://broker.com/xridb</URI>
      </LocalAccess>
      <Mapping>xri:@*:1002*(:1000:1000)</Mapping>
    </XRIDescriptor>

TODO

Top

SEE ALSO

Top

xri(3)

AUTHOR

Top

Fen Labalme, <fen@idcommons.net>

COPYRIGHT AND LICENSE

Top


XRI documentation Contained in the XRI distribution.

# Copyright (C) 2004 Identity Commons.  All Rights Reserved.
# See LICENSE for licensing details

# Authors:
#       Fen Labalme <fen@idcommons.net>
#       Eugene Eric Kim <eekim@blueoxen.org>

package XRI::Descriptor;

our $VERSION = 0.1;

use XRI::Descriptor::LocalAccess;
use XML::Smart;

sub new {
    my $self = shift;
    my $xml = shift;
    my $doc = XML::Smart->new( $xml );
    $doc = $doc->{XRIDescriptor};

    bless { doc=>$doc }, $self;
}

sub getResolved {
    my $self = shift;

    return $self->{doc}{Resolved};
}

# returns a reference to a list of URIs
#
sub getXRIAuthorityURIs {
    my $self = shift;

    return \@{$self->{doc}{XRIAuthority}{URI}};
}

sub getLocalAccess {
    my $self = shift;
    my ($service, $type) = @_;

    my @localAccessObjects;
    my @localAccessElements = @{$self->{doc}->{LocalAccess}};

    foreach my $element (@localAccessElements) {
        my $object = XRI::Descriptor::LocalAccess->new;
        $object->service($element->{Service}) if ($element->{Service});
        if (!$service || $object->service eq $service) {
            if ($element->{URI}) {
                # this conditional should be unnecessary if XML is valid.
                # according to the schema, there should always be at least
                # one URI per LocalAccess object.
                $object->uris($element->{URI});
            }
            $object->types($element->{Type}) if $element->{Type};
            if (!$type || grep(/^$type$/, $object->types)) {
                push @localAccessObjects, $object;
            }
        }
    }
    return @localAccessObjects;
}

sub getMappings {
    my $self = shift;

    return \@{$self->{doc}{Mapping}};
}

1;
__END__