/
Id.pm
160 lines (106 loc) · 3.62 KB
/
Id.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
######################################################################
#
# EPrints::MetaField::Id;
#
######################################################################
#
#
######################################################################
=pod
=head1 NAME
B<EPrints::MetaField::Id> - an identifier string
=head1 DESCRIPTION
Use Id fields whenever you are storing textual data that needs to be matched exactly (e.g. filenames).
Characters that are not valid XML 1.0 code-points will be replaced with the Unicode replacement character.
=over 4
=cut
package EPrints::MetaField::Id;
use EPrints::MetaField;
@ISA = qw( EPrints::MetaField );
use strict;
######################################################################
=pod
=item $val = $field->value_from_sql_row( $session, $row )
Shift and return the utf8 value of this field from the database input $row.
=cut
######################################################################
sub value_from_sql_row
{
my( $self, $session, $row ) = @_;
return undef unless defined $row->[0];
if( $session->{database}->{dbh}->{Driver}->{Name} eq "mysql" )
{
utf8::decode( $row->[0] );
}
return shift @$row;
}
=item @row = $field->sql_row_from_value( $session, $value )
Returns the value as an appropriate value for the database.
Replaces invalid XML 1.0 code points with the Unicode substitution character (0xfffd), see http://www.w3.org/International/questions/qa-controls
Values are truncated if they are longer than maxlength.
=cut
sub sql_row_from_value
{
my( $self, $session, $value ) = @_;
return( undef ) if !defined $value;
$value =~ s/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\x9f]/\x{fffd}/g;
$value =~ s/^\s+//;
$value =~ s/\s+$//;
$value = substr( $value, 0, $self->{ "maxlength" } );
return( $value );
}
sub get_property_defaults
{
my( $self ) = @_;
return(
$self->SUPER::get_property_defaults,
match => "EX",
merge => "ALL",
);
}
# id fields are searched whole, whether against the main table or in the index
sub get_index_codes_basic
{
my( $self, $session, $value ) = @_;
return( [], [], [] ) if !EPrints::Utils::is_set( $value );
return( [ $value ], [], [] );
}
sub get_xml_schema_type
{
my( $self ) = @_;
if ($self->property("maxlength") != $self->{field_defaults}->{maxlength}) {
return $self->get_xml_schema_field_type;
}
else {
return $self->{type};
}
}
sub render_xml_schema_type
{
my( $self, $session ) = @_;
my $type = $session->make_element( "xs:simpleType", name => $self->get_xml_schema_type );
my $restriction = $session->make_element( "xs:restriction", base => "xs:string" );
$type->appendChild( $restriction );
my $length = $session->make_element( "xs:maxLength", value => $self->get_max_input_size );
$restriction->appendChild( $length );
return $type;
}
######################################################################
1;
=head1 COPYRIGHT
=for COPYRIGHT BEGIN
Copyright 2000-2011 University of Southampton.
=for COPYRIGHT END
=for LICENSE BEGIN
This file is part of EPrints L<http://www.eprints.org/>.
EPrints is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
EPrints is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
License along with EPrints. If not, see L<http://www.gnu.org/licenses/>.
=for LICENSE END