improve Metadata module to build hashref for Manager structure

This commit is contained in:
Thomas CHEMINEAU 2010-01-28 17:58:49 +00:00
parent cb71f77f4d
commit 5b576643ee
3 changed files with 70 additions and 3 deletions

View File

@ -111,13 +111,72 @@ sub toXML
sub toConf
{
my $self = shift;
my $fields;
local $Data::Dumper::Indent = 0;
local $Data::Dumper::Varname = "data";
my $data = Dumper($self);
$data =~ s/\A\$VAR\d+\s*=\s*//;
$data =~ s/^\s*(.*?)\s*$/$1/;
$data =~ s/'/'/g;
return $data;
}
## @method public hashref toStruct ()
# Return this object to be display into the Manager.
# @return hashref
sub toStruct
{
my $self = shift;
my $struct = ();
foreach (keys %$self)
{
$struct->{$_} = $self->{$_};
}
return $self->_toStruct('', $struct);
}
## @method private hashref _toStruct (Hashref node)
# Return a preformated structure to be stored into Manager structure.
# @param $path The path of the node.
# @param $node The current node into the hashref tree.
# @return Hashref A structure to be inserted into Manager structure.
sub _toStruct
{
my $self = shift;
my $path = shift;
my ($node) = @_;
if (ref $node)
{
my $struct = {
_nodes => [],
_help => 'default'
};
my @nodes = ();
foreach (keys %$node)
{
if ($_ =~ /^xmlns/)
{
next;
}
my $key = $path . ' ' . $_;
$key =~ s/^ +//g;
my $data = $self->_toStruct($key, $node->{$_});
if ($data)
{
$struct->{$key} = $data;
push @nodes, 'n:' . $key;
}
else
{
$struct->{$key} = 'text:/' . $_;
push @nodes, $key;
}
}
$struct->{_nodes} = \@nodes;
return $struct;
}
return 0;
}
## @method public static boolean load(Array files)
# Return an array of Metadata object.
# @param $files Array of filenames

View File

@ -43,7 +43,7 @@ sub unserialize {
while ( my ( $k, $v ) = each(%$fields) ) {
$v =~ s/^'(.*)'$/$1/s;
if ( $k =~
/^(?:exportedVars|locationRules|groups|exportedHeaders|macros|globalStorageOptions|notificationStorageOptions)$/
/^(?:exportedVars|locationRules|groups|exportedHeaders|macros|globalStorageOptions|notificationStorageOptions|samlServiceMetaData)$/
and $v ||= {}
and not ref($v) )
{

View File

@ -6,6 +6,8 @@
package Lemonldap::NG::Manager::_Struct;
use strict;
use Lemonldap::NG::Common::Conf::SAML::Metadata;
our $VERSION = '0.1';
## @method protected hashref cstruct(hashref h,string k)
@ -42,7 +44,7 @@ sub cstruct {
sub struct {
my $self = shift;
return {
_nodes => [qw(n:generalParameters n:variables n:virtualHosts)],
_nodes => [qw(n:generalParameters n:variables n:virtualHosts n:samlServiceMetadata)],
_help => 'default',
######################
@ -237,6 +239,12 @@ sub struct {
_help => 'default',
_call => '$(\'#bnewvh\').show();',
},
#################
# SAML METADATA #
#################
samlServiceMetadata => $self->conf->{samlServiceMetaData}->toStruct(),
};
}