deprecated/buildtools/buildsystemtools/lib/XML/XQL/DirXQL.pm
author lorewang
Wed, 01 Dec 2010 16:05:36 +0800
changeset 715 e0739b8406dd
parent 655 3f65fd25dfd4
permissions -rw-r--r--
Specify extenal tool with path
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
655
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     1
# Attibute Definitions:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     2
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     3
#  name: Text - name of file, dir, ...
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     4
#  ext: Text - file extension
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     5
#  no_ext: Text - name without ext
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     6
#  full: Text - full path name
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     7
#  abs: Text - absolute path name
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     8
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     9
#  M,age: Number - Age of file (in days)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    10
#                   [since script started says man(perlfunc)??]
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    11
#  cre,create: Date (see age)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    12
#  A,acc_in_days: Number - Last access time in days
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    13
#  acc,access: Date (see A)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    14
#    set with utime()
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    15
#  f,is_file: Boolean
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    16
#  d,is_dir: Boolean
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    17
#  l,is_link: Boolean
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    18
#  p,is_pipe: Boolean
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    19
#  e,exists: Boolean
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    20
#  z,is_zero: Boolean - whether size equals zero bytes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    21
#  r,readable: Boolean
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    22
#  w,writable: Boolean
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    23
#  x,executable: Boolean
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    24
#  o,owned: Boolean - whether it is owned (by effective uid)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    25
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    26
#---------------------------------------------------------------------------
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    27
# Todo: 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    28
# - implement abs(): absolute filepath
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    29
# - support links: use lstat(), @link 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    30
# - flags: -R,-W,-X,-O (by real uid/gid instead of effective uid,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    31
#          -S (is_socket), -b (block special file), -c (char. special file),
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    32
#          -t  Filehandle is opened to a tty.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    33
#          -u  File has setuid bit set.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    34
#          -g  File has setgid bit set.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    35
#          -k  File has sticky bit set.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    36
#          -T  File is a text file.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    37
#          -B  File is a binary file (opposite of -T).
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    38
#          -C  inode change time in days.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    39
#              set with utime() ??
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    40
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    41
# stat() fields:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    42
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    43
#         0 dev      device number of filesystem
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    44
#         1 ino      inode number
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    45
#         2 mode     file mode  (type and permissions)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    46
#	    add mode_str ??: "rwxr-xr--"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    47
#         3 nlink    number of (hard) links to the file
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    48
#         4 uid      numeric user ID of file's owner
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    49
#           add uname
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    50
#         5 gid      numeric group ID of file's owner
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    51
#           add gname
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    52
#         6 rdev     the device identifier (special files only)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    53
# x       7 size     total size of file, in bytes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    54
# -       8 atime    last access time since the epoch
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    55
# -       9 mtime    last modify time since the epoch
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    56
# -      10 ctime    inode change time (NOT creation time!) since the epoch
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    57
#        11 blksize  preferred block size for file system I/O
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    58
#        12 blocks   actual number of blocks allocated
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    59
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    60
package XML::XQL::DirXQL;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    61
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    62
use strict;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    63
use XML::XQL;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    64
use XML::XQL::Date;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    65
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    66
sub dirxql
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    67
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    68
    my ($context, $list, $filepath) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    69
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    70
    $filepath = XML::XQL::toList ($filepath->solve ($context, $list));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    71
    my @result;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    72
    for my $file (@$filepath)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    73
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    74
	push @result, XML::XQL::DirDoc->new (Root => $file->xql_toString)->root;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    75
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    76
    \@result;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    77
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    78
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    79
XML::XQL::defineFunction ("dirxql", \&XML::XQL::DirXQL::dirxql, 1, 1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    80
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    81
package XML::XQL::DirNode;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    82
# extended by: DirDoc, DirAttr, DirElem (File, Dir), FileContents
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    83
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    84
use vars qw{ @ISA $SEP };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    85
@ISA = qw{ XML::XQL::Node };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    86
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    87
# Directory path separator (default: Unix)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    88
$SEP = "/";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    89
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    90
if ((defined $^O and
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    91
     $^O =~ /MSWin32/i ||
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    92
     $^O =~ /Windows_95/i ||
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    93
     $^O =~ /Windows_NT/i) ||
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    94
    (defined $ENV{OS} and
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    95
     $ENV{OS} =~ /MSWin32/i ||
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    96
     $ENV{OS} =~ /Windows_95/i ||
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    97
     $ENV{OS} =~ /Windows_NT/i))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    98
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    99
    $SEP = "\\";	# Win32
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   100
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   101
elsif  ((defined $^O and $^O =~ /MacOS/i) ||
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   102
	(defined $ENV{OS} and $ENV{OS} =~ /MacOS/i))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   103
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   104
    $SEP = ":";		# Mac
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   105
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   106
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   107
sub isElementNode { 0 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   108
sub isTextNode    { 0 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   109
sub xql_parent    { $_[0]->{Parent} }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   110
#sub xql_document { $_[0]->{Doc} }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   111
sub xml_xqlString { $_[0]->toString }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   112
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   113
sub xql
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   114
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   115
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   116
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   117
    # Odd number of args, assume first is XQL expression without 'Expr' key
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   118
    unshift @_, 'Expr' if (@_ % 2 == 1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   119
    my $query = new XML::XQL::Query (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   120
    $query->solve ($self);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   121
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   122
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   123
sub xql_sortKey
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   124
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   125
    my $key = $_[0]->{SortKey};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   126
    return $key if defined $key;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   127
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   128
    $key = XML::XQL::createSortKey ($_[0]->{Parent}->xql_sortKey, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   129
				    $_[0]->xql_childIndex, 1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   130
#print "xql_sortKey $_[0] ind=" . $_[0]->xql_childIndex . " key=$key str=" . XML::XQL::keyStr($key) . "\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   131
    $_[0]->{SortKey} = $key;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   132
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   133
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   134
sub xql_node
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   135
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   136
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   137
    $self->build unless $self->{Built};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   138
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   139
    $self->{C};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   140
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   141
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   142
sub getChildIndex
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   143
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   144
    my ($self, $kid) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   145
    my $i = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   146
    for (@{ $self->xql_node })
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   147
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   148
	return $i if $kid == $_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   149
	$i++;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   150
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   151
    return -1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   152
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   153
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   154
sub xql_childIndex
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   155
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   156
    $_[0]->{Parent}->getChildIndex ($_[0]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   157
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   158
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   159
# As it appears in the XML document
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   160
sub xql_xmlString
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   161
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   162
    $_[0]->toString;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   163
#?? impl.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   164
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   165
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   166
sub create_date_from_days
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   167
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   168
    my ($days, $srcNode) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   169
    my $secs = int (0.5 + $days * 24 * 3600 );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   170
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   171
    my $internal = Date::Manip::DateCalc ("today", "- $secs seconds");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   172
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   173
    new XML::XQL::Date (SourceNode => $srcNode,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   174
			Internal => $internal,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   175
			String => $internal );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   176
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   177
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   178
#------ WHITESPACE STUFF (DELETE??)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   179
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   180
# Find previous sibling that is not a text node with ignorable whitespace
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   181
sub xql_prevNonWS
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   182
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   183
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   184
    my $parent = $self->{Parent};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   185
    return unless $parent;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   186
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   187
    for (my $i = $parent->getChildIndex ($self) - 1; $i >= 0; $i--)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   188
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   189
	my $node = $parent->getChildAtIndex ($i);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   190
	return $node unless $node->xql_isIgnorableWS;	# skip whitespace
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   191
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   192
    undef;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   193
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   194
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   195
# True if it's a Text node with just whitespace and xml::space != "preserve"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   196
sub xql_isIgnorableWS
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   197
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   198
    0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   199
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   200
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   201
# Whether the node should preserve whitespace
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   202
# It should if it has attribute xml:space="preserve"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   203
sub xql_preserveSpace
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   204
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   205
    $_[0]->{Parent}->xql_preserveSpace;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   206
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   207
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   208
#---------------------------------------------------------------------------
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   209
package XML::XQL::DirDoc;		# The Document
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   210
use vars qw{ @ISA };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   211
@ISA = qw{ XML::XQL::DirNode };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   212
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   213
sub new
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   214
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   215
    my ($type, %hash) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   216
    my $self = bless \%hash, $type;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   217
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   218
    $self->{Root} = "." unless exists $self->{Root};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   219
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   220
    my $dirname;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   221
    if ($self->{Root} =~ /^(.+)\Q${XML::XQL::DirNode::SEP}\E(.+)$/)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   222
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   223
	$self->{Prefix} = $1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   224
	$dirname = $2;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   225
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   226
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   227
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   228
	$self->{Prefix} = "";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   229
	$dirname = $self->{Root};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   230
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   231
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   232
    $self->{Dir} = new XML::XQL::Dir (TagName => $dirname, Parent => $self);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   233
    $self->{Built} = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   234
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   235
    return $self;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   236
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   237
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   238
sub xql
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   239
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   240
    shift->root->xql (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   241
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   242
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   243
sub root           { $_[0]->{Dir} }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   244
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   245
sub isElementNode  { 0 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   246
sub xql_nodeType   { 9 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   247
sub xql_childCount { 1 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   248
sub fullname       { $_[0]->{Prefix} }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   249
sub xql_sortKey    { "" }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   250
sub xql_parent     { undef }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   251
sub xql_nodeName   { "#document" }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   252
sub depth          { 0 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   253
sub xql_node       { [ $_[0]->{Dir} ] }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   254
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   255
sub xql_element
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   256
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   257
    my ($self, $elem) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   258
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   259
    my $dir = $self->{Dir};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   260
    if (defined $elem)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   261
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   262
	return [ $dir ] if $dir->{TagName} eq $elem;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   263
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   264
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   265
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   266
	return [ $dir ];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   267
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   268
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   269
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   270
# By default the elements in a document don't preserve whitespace
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   271
sub xql_preserveSpace
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   272
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   273
    0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   274
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   275
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   276
sub toString
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   277
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   278
    $_[0]->root->toString;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   279
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   280
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   281
#----------------------------------------------------------------------------
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   282
package XML::XQL::DirAttrDef;	# Definitions for DirAttr nodes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   283
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   284
sub new
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   285
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   286
    my ($type, %hash) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   287
    bless \%hash, $type;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   288
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   289
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   290
sub dump
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   291
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   292
    print $_[0]->toString . "\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   293
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   294
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   295
sub toString
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   296
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   297
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   298
    print "DirAttrDef $self\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   299
    my $i = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   300
    for my $attrName ($self->in_order)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   301
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   302
	my $a = $self->{$attrName};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   303
	print "[$i] name=$attrName"; $i++;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   304
	print " order=" . $a->{Order};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   305
	print " get=" . $a->{Get} if defined $a->{Get};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   306
	print " set=" . $a->{Set} if defined $a->{Set};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   307
	if (defined $a->{Alias})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   308
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   309
	    print " alias=" . join (",", @{ $a->{Alias} });
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   310
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   311
	print "\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   312
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   313
    if (defined $self->{'@ALIAS'})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   314
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   315
	print "Alias: ";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   316
	my $alias = $self->{'@ALIAS'};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   317
	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   318
	print join (",", map { "$_=" . $alias->{$_} } keys %$alias);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   319
	print "\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   320
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   321
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   322
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   323
sub clone
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   324
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   325
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   326
    my $n = new XML::XQL::DirAttrDef;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   327
    $n->{'@IN_ORDER'} = [ @{ $self->{'@IN_ORDER'} } ];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   328
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   329
    for my $a (@{ $self->{'@IN_ORDER'} })
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   330
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   331
	$n->{$a} = { %{ $self->{$a} } };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   332
	$n->{$a}->{Alias} = [ @{ $self->{$a}->{Alias} } ]
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   333
	    if defined $self->{$a}->{Alias};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   334
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   335
    $n->{'@ALIAS'} = { %{ $self->{'@ALIAS'} } }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   336
	    if defined $self->{'@ALIAS'};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   337
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   338
    return $n;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   339
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   340
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   341
sub in_order { defined $_[0]->{'@IN_ORDER'} ? @{ $_[0]->{'@IN_ORDER'} } : () }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   342
sub alias    { $_[0]->{'@ALIAS'}->{$_[1]} }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   343
sub order    { $_[0]->{$_[1]}->{Order} }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   344
sub get      { $_[0]->{$_[1]}->{Get} }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   345
sub set      { $_[0]->{$_[1]}->{Set} }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   346
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   347
sub remove_attr
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   348
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   349
    my ($self, $name) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   350
    next unless defined $self->{$name};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   351
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   352
    my $order = $self->{$name}->{Order};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   353
    my @in_order = $self->in_order;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   354
    splice @in_order, $order, 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   355
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   356
    # Reassign Order numbers
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   357
    for (my $i = 0; $i < @in_order; $i++)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   358
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   359
	$self->{$name}->{Order} = $i;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   360
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   361
    $self->{'@IN_ORDER'} = \@in_order;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   362
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   363
    delete $self->{$name};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   364
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   365
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   366
sub define_attr
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   367
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   368
    my ($self, %hash) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   369
    my $name = $hash{Name};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   370
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   371
    if (defined $self->{$name})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   372
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   373
	$hash{Order} = $self->{$name}->{Order} unless defined $hash{Order};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   374
	$self->remove_attr ($name);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   375
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   376
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   377
    my @in_order = $self->in_order;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   378
    $hash{Order} = -1
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   379
	if $hash{Order} >= @in_order;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   380
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   381
    if ($hash{Order} == -1)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   382
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   383
	push @in_order, $name;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   384
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   385
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   386
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   387
	splice @in_order, $hash{Order}, 0, $name;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   388
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   389
    $self->{$name} = \%hash;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   390
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   391
    # Reassign Order numbers
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   392
    for (my $i = 0; $i < @in_order; $i++)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   393
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   394
	$self->{$name}->{Order} = $i;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   395
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   396
    $self->{'@IN_ORDER'} = \@in_order;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   397
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   398
    my @alias = defined $hash{Alias} ? @{ $hash{Alias} } : ();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   399
    for (@alias)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   400
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   401
	$self->{'@ALIAS'}->{$_} = $name;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   402
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   403
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   404
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   405
#----------------------------------------------------------------------------
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   406
package XML::XQL::DirAttr;	# Attr node
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   407
use vars qw{ @ISA %GET_ATTR_FUNC %SET_ATTR_FUNC };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   408
@ISA = qw{ XML::XQL::DirNode };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   409
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   410
sub new
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   411
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   412
    my ($type, %hash) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   413
    my $self = bless \%hash, $type;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   414
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   415
    $self->{xql_value} = $self->{Parent}->{AttrDef}->get ($hash{Name});
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   416
    $self->{xql_setValue} = $self->{Parent}->{AttrDef}->set ($hash{Name});
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   417
    $self;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   418
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   419
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   420
sub isElementNode  { 0 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   421
sub xql_nodeType   { 2 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   422
sub xql_nodeName   { $_[0]->{Name} }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   423
sub xql_childIndex { $_[0]->{Parent}->attrIndex ($_[0]->{Name}) }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   424
sub xql_childCount { 0 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   425
sub xql_node       { [] }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   426
sub is_defined     { exists $_[0]->{Value} }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   427
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   428
sub create	{ XML::XQL::DirNode::create_date_from_days ($_[0]->{Parent}->age, $_[0]) }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   429
sub age		{ new XML::XQL::Number ($_[0]->{Parent}->age, $_[0]) }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   430
sub size	{ new XML::XQL::Text ($_[0]->{Parent}->size, $_[0]) }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   431
sub ext		{ new XML::XQL::Text ($_[0]->{Parent}->ext, $_[0]) }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   432
sub no_ext	{ new XML::XQL::Text ($_[0]->{Parent}->no_ext, $_[0]) }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   433
sub name	{ new XML::XQL::Text ($_[0]->{Parent}->name, $_[0]) }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   434
sub full	{ new XML::XQL::Text ($_[0]->{Parent}->full, $_[0]) }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   435
sub abs 	{ new XML::XQL::Text ($_[0]->{Parent}->abs, $_[0]) }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   436
sub is_file	{ new XML::XQL::Boolean ($_[0]->{Parent}->is_file, $_[0]) }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   437
sub is_dir	{ new XML::XQL::Boolean ($_[0]->{Parent}->is_dir, $_[0]) }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   438
sub is_link	{ new XML::XQL::Boolean ($_[0]->{Parent}->is_link, $_[0]) }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   439
sub is_pipe	{ new XML::XQL::Boolean ($_[0]->{Parent}->is_pipe, $_[0]) }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   440
sub it_exists	{ new XML::XQL::Boolean ($_[0]->{Parent}->it_exists, $_[0]) }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   441
sub is_zero	{ new XML::XQL::Boolean ($_[0]->{Parent}->is_zero, $_[0]) }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   442
sub readable	{ new XML::XQL::Boolean ($_[0]->{Parent}->readable, $_[0]) }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   443
sub writable	{ new XML::XQL::Boolean ($_[0]->{Parent}->writable, $_[0]) }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   444
sub executable	{ new XML::XQL::Boolean ($_[0]->{Parent}->executable, $_[0]) }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   445
sub owned	{ new XML::XQL::Boolean ($_[0]->{Parent}->owned, $_[0]) }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   446
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   447
sub last_access_in_days
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   448
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   449
    new XML::XQL::Number ($_[0]->{Parent}->last_access_in_days, $_[0]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   450
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   451
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   452
sub last_access
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   453
{ 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   454
  XML::XQL::DirNode::create_date_from_days ($_[0]->{Parent}->last_access_in_days, $_[0]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   455
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   456
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   457
sub toString       
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   458
{ 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   459
    my $old = ""; #$_[0]->is_defined ? "" : " (undef)";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   460
    my $val = $_[0]->xql_value->xql_toString; #exists $_[0]->{Value} ? $_[0]->{Value}->xql_toString : "(undef)";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   461
    $_[0]->{Name} . "=\"$val$old\""
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   462
#?? encodeAttrValue
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   463
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   464
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   465
sub xql_value
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   466
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   467
    $_[0]->{Value} ||= &{ $_[0]->{xql_value} } (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   468
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   469
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   470
sub xql_setValue
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   471
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   472
    my ($self, $text) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   473
    my $set = $_[0]->{xql_setValue};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   474
    if (defined $set)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   475
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   476
	&$set ($self, $text);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   477
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   478
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   479
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   480
	warn "xql_setValue not defined for DirAttr name=" . $self->{TagName};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   481
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   482
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   483
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   484
sub set_name
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   485
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   486
    my ($attr, $text) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   487
    $attr->{Parent}->set_name ($text);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   488
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   489
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   490
sub set_ext
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   491
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   492
    my ($attr, $text) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   493
    $attr->{Parent}->set_ext ($text);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   494
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   495
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   496
sub set_no_ext
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   497
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   498
    my ($attr, $text) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   499
    $attr->{Parent}->set_no_ext ($text);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   500
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   501
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   502
#----------------------------------------------------------------------------
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   503
package XML::XQL::DirElem;	# File or Dir
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   504
use vars qw{ @ISA $ATTRDEF };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   505
@ISA = qw( XML::XQL::DirNode );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   506
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   507
$ATTRDEF = new XML::XQL::DirAttrDef;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   508
$ATTRDEF->define_attr (Name => 'name', Get => \&XML::XQL::DirAttr::name, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   509
		       Set => \&XML::XQL::DirAttr::set_name);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   510
$ATTRDEF->define_attr (Name => 'full', Get => \&XML::XQL::DirAttr::full);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   511
$ATTRDEF->define_attr (Name => 'abs', Get => \&XML::XQL::DirAttr::abs);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   512
$ATTRDEF->define_attr (Name => 'no_ext', Get => \&XML::XQL::DirAttr::no_ext, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   513
		       Set => \&XML::XQL::DirAttr::set_no_ext);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   514
$ATTRDEF->define_attr (Name => 'ext', Get => \&XML::XQL::DirAttr::ext, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   515
		       Set => \&XML::XQL::DirAttr::set_ext);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   516
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   517
$ATTRDEF->define_attr (Name => 'age', Get => \&XML::XQL::DirAttr::age, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   518
		       Alias => [ 'M' ] );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   519
$ATTRDEF->define_attr (Name => 'create', Get => \&XML::XQL::DirAttr::create, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   520
		       Alias => [ 'cre' ] );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   521
$ATTRDEF->define_attr (Name => 'A', Get => \&XML::XQL::DirAttr::last_access_in_days,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   522
		       Alias => [ 'acc_in_days' ] );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   523
$ATTRDEF->define_attr (Name => 'access', Get => \&XML::XQL::DirAttr::last_access, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   524
		       Alias => [ 'acc' ] );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   525
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   526
# These should only be implemented for Link and Pipe resp. !!
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   527
$ATTRDEF->define_attr (Name => 'l', Get => \&XML::XQL::DirAttr::is_link, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   528
		       Alias => [ 'is_link' ] );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   529
$ATTRDEF->define_attr (Name => 'p', Get => \&XML::XQL::DirAttr::is_pipe, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   530
		       Alias => [ 'is_pipe' ] );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   531
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   532
$ATTRDEF->define_attr (Name => 'e', Get => \&XML::XQL::DirAttr::it_exists, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   533
		       Alias => [ 'exists' ] );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   534
$ATTRDEF->define_attr (Name => 'z', Get => \&XML::XQL::DirAttr::is_zero, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   535
		       Alias => [ 'is_zero' ] );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   536
$ATTRDEF->define_attr (Name => 'r', Get => \&XML::XQL::DirAttr::readable, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   537
		       Alias => [ 'readable' ] );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   538
$ATTRDEF->define_attr (Name => 'w', Get => \&XML::XQL::DirAttr::writable, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   539
		       Alias => [ 'writable' ] );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   540
$ATTRDEF->define_attr (Name => 'x', Get => \&XML::XQL::DirAttr::executable, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   541
		       Alias => [ 'is_zero' ] );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   542
$ATTRDEF->define_attr (Name => 'o', Get => \&XML::XQL::DirAttr::owned, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   543
		       Alias => [ 'owned' ] );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   544
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   545
#dump_attr_def();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   546
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   547
# mod => 0,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   548
# create => 1,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   549
# prot => 2,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   550
# protn => 3,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   551
# name => 4,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   552
# path => 5,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   553
# dir => 6,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   554
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   555
sub isElementNode   { 1 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   556
sub xql_nodeType    { 1 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   557
sub xql_nodeName    { $_[0]->{TagName} }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   558
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   559
sub dump_attr_def   { $ATTRDEF->dump; }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   560
sub attrNames       { @{ $_[0]->{AttrDef}->{'@IN_ORDER'} } }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   561
sub hasAttr         { exists $_[0]->{AttrDef}->{$_[1]} }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   562
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   563
# Attributes set/get
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   564
sub full  		{ $_[0]->fullname }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   565
sub abs      		{ $_[0]->abs }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   566
sub no_ext		{ $_[0]->{TagName} }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   567
sub set_no_ext		{ shift->set_name (@_) }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   568
sub size		{ -s $_[0]->fullname }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   569
sub age			{ -M $_[0]->fullname }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   570
sub last_access_in_days	{ -A $_[0]->fullname }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   571
sub is_file             { -f $_[0]->fullname }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   572
sub is_dir              { -d $_[0]->fullname }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   573
sub is_link             { -l $_[0]->fullname }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   574
sub is_pipe             { -p $_[0]->fullname }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   575
sub it_exists           { -e $_[0]->fullname }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   576
sub is_zero             { -z $_[0]->fullname }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   577
sub readable            { -r $_[0]->fullname }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   578
sub writable            { -w $_[0]->fullname }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   579
sub executable          { -x $_[0]->fullname }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   580
sub owned               { -o $_[0]->fullname }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   581
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   582
sub attr_alias    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   583
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   584
    return undef unless defined $_[1];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   585
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   586
    my $alias = $_[0]->{AttrDef}->alias ($_[1]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   587
    defined $alias ? $alias : $_[1];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   588
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   589
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   590
sub create_path	# static
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   591
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   592
    my ($dir, $file) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   593
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   594
    if ($dir =~ /\Q${XML::XQL::DirNode::SEP}\E$/)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   595
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   596
	return "$dir$file";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   597
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   598
    elsif ($dir eq "")	# e.g. when file is root directory '/'
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   599
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   600
	return $file;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   601
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   602
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   603
    { 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   604
	return "$dir${XML::XQL::DirNode::SEP}$file";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   605
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   606
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   607
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   608
sub fullname
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   609
{ 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   610
    my $pa = $_[0]->{Parent}->fullname;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   611
    my $name = $_[0]->{TagName};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   612
    create_path ($pa, $name);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   613
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   614
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   615
#?? same as full name - for now
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   616
sub abs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   617
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   618
    shift->fullname (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   619
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   620
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   621
sub parent_dir
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   622
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   623
    $_[0]->{Parent}->fullname;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   624
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   625
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   626
# With 3 params, sets the specified attribute with $attrName to $attrValue.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   627
# With 2 params, reinitializes the specified attribute with $attrName if
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   628
# it currently has a value.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   629
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   630
sub update_attr
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   631
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   632
    my ($self, $attrName, $attrValue) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   633
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   634
    if (@_ == 3)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   635
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   636
	my $attr = $self->getAttributeNode ($attrName);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   637
	if (defined $attr && defined $attr->{Value})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   638
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   639
	    $attr->{Value} = $attrValue;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   640
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   641
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   642
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   643
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   644
	return unless exists $self->{A}->{$attrName};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   645
	my $a = $self->{A}->{$attrName};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   646
	if (exists $a->{Value})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   647
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   648
	    delete $a->{Value};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   649
	    $a->xql_value;	# reinitialize value
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   650
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   651
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   652
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   653
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   654
sub set_name
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   655
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   656
    my ($self, $text) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   657
    my $fullName = $self->fullname;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   658
    my $newName = create_path ($self->parent_dir, $text);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   659
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   660
    if (rename ($fullName, $newName))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   661
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   662
	$self->{TagName} = $text;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   663
	$self->update_attr ('name', $text);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   664
	$self->update_attr ('ext');
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   665
	$self->update_attr ('no_ext');
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   666
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   667
	return 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   668
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   669
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   670
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   671
	warn "set_name: could not rename $fullName to $newName";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   672
	return 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   673
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   674
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   675
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   676
sub ext
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   677
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   678
    my $name = $_[0]->{TagName};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   679
    $name =~ /\.([^.]+)$/;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   680
#    print "ext name=$name ext=$1\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   681
    return $1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   682
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   683
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   684
sub set_ext
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   685
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   686
    my ($self, $text) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   687
#    print "set_ext $text\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   688
    my $no_ext = $self->no_ext;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   689
    $self->set_name (length ($text) ? "$no_ext.$text" : $no_ext);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   690
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   691
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   692
sub no_ext
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   693
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   694
    my $name = $_[0]->{TagName};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   695
    $name =~ /^(.+)\.([^.]+)$/;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   696
#    print "no_ext name=$name no_ext=$1\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   697
    return $1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   698
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   699
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   700
sub set_no_ext
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   701
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   702
    my ($self, $text) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   703
#    print "set_no_ext $text\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   704
    my $ext = $self->ext;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   705
    $self->set_name (length ($ext) ? "$text.$ext" : $text);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   706
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   707
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   708
sub xql_attribute
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   709
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   710
    my ($node, $attrName) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   711
    if (defined $attrName)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   712
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   713
	my $attr = $node->getAttributeNode ($attrName);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   714
	defined ($attr) ? [ $attr ] : [];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   715
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   716
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   717
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   718
	my @attr;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   719
	for my $name ($node->attrNames)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   720
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   721
	    push @attr, $node->getAttributeNode ($name);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   722
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   723
	\@attr;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   724
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   725
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   726
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   727
sub getAttributeNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   728
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   729
    my ($self, $attrName) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   730
    $attrName = $self->attr_alias ($attrName);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   731
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   732
    return undef unless $self->hasAttr ($attrName);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   733
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   734
    my $attr = $_[0]->{A}->{$attrName} ||= 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   735
	new XML::XQL::DirAttr (Parent => $self, Name => $attrName);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   736
    $attr;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   737
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   738
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   739
sub attrIndex
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   740
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   741
    $_[0]->{AttrDef}->order ($_[1]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   742
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   743
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   744
sub toString       
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   745
{ 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   746
    my ($self, $depth) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   747
    my $indent = "  " x $depth;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   748
    my $str = $indent;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   749
    my $tagName = $self->{TagName};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   750
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   751
    my $tfp = $self->tag_for_print;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   752
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   753
    $str .= "<$tfp name=\"$tagName\"";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   754
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   755
    for my $attrName ($self->attrNames)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   756
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   757
	next unless exists $self->{A}->{$attrName};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   758
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   759
#?? don't print un-retrieved attributes - for now	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   760
	my $attr = $self->{A}->{$attrName};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   761
	next unless $attr->is_defined;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   762
	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   763
	$str .= " " . $attr->toString;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   764
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   765
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   766
    my $kids = $self->print_kids ? $self->xql_node : [];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   767
    if (@$kids)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   768
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   769
	$str .= ">\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   770
	for (@$kids)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   771
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   772
	    $str .= $_->toString ($depth + 1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   773
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   774
	$str .= $indent . "</dir>\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   775
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   776
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   777
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   778
	$str .= "/>\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   779
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   780
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   781
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   782
#----------------------------------------------------------------------------
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   783
package XML::XQL::Dir;	# Element node
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   784
use vars qw{ @ISA $ATTRDEF };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   785
@ISA = qw( XML::XQL::DirElem );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   786
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   787
$ATTRDEF = $XML::XQL::DirElem::ATTRDEF->clone;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   788
$ATTRDEF->define_attr (Name => 'd', Get => \&XML::XQL::DirAttr::is_dir, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   789
		       Alias => [ 'is_dir' ] );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   790
#dump_attr_def();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   791
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   792
sub tag_for_print { "dir" }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   793
sub print_kids    { 1 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   794
sub dump_attr_def { $ATTRDEF->dump }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   795
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   796
sub new
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   797
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   798
    my ($type, %hash) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   799
    $hash{AttrDef} = $ATTRDEF;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   800
    bless \%hash, $type;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   801
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   802
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   803
sub build
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   804
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   805
    my ($self) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   806
    my $dirname = $self->fullname;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   807
#    print "dirname=$dirname\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   808
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   809
    if (opendir (DIR, $dirname))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   810
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   811
	my @kids;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   812
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   813
	my @f = readdir (DIR);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   814
	closedir DIR;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   815
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   816
	for my $f (@f)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   817
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   818
	    next if $f =~ /^..?$/;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   819
#	    print "dirname=$dirname f=$f\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   820
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   821
	    my $full = defined $dirname ? "$dirname${XML::XQL::DirNode::SEP}$f" : $f;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   822
#	    print "dirname=$dirname full=$full\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   823
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   824
	    if (-f $full)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   825
	    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   826
		push @kids, XML::XQL::File->new (Parent => $self, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   827
						 TagName => $f
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   828
						);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   829
	    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   830
	    elsif (-d _)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   831
	    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   832
		push @kids, XML::XQL::Dir->new (Parent => $self, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   833
						TagName => $f
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   834
					       );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   835
	    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   836
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   837
	$self->{C} = \@kids;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   838
	$self->{Built} = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   839
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   840
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   841
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   842
	print "can't opendir $dirname: $!";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   843
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   844
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   845
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   846
sub xql_childCount
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   847
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   848
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   849
    $self->build unless $self->{Built};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   850
    my $ch = $self->{C};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   851
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   852
    defined $ch ? scalar(@$ch) : 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   853
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   854
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   855
#----------------------------------------------------------------------------
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   856
package XML::XQL::File;	# Element node
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   857
use vars qw{ @ISA $ATTRDEF };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   858
@ISA = qw( XML::XQL::DirElem );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   859
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   860
$ATTRDEF = $XML::XQL::DirElem::ATTRDEF->clone;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   861
$ATTRDEF->define_attr (Name => 'f', Get => \&XML::XQL::DirAttr::is_file, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   862
		       Alias => [ 'is_file' ] );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   863
$ATTRDEF->define_attr (Name => 'size', Get => \&XML::XQL::DirAttr::size, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   864
		       Alias => [ 's' ]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   865
#dump_attr_def();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   866
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   867
sub new
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   868
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   869
    my ($type, %hash) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   870
    $hash{AttrDef} = $ATTRDEF;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   871
    bless \%hash, $type;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   872
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   873
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   874
sub getChildIndex  { 0 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   875
sub xql_childCount { 1 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   876
sub contents       { $_[0]->build unless $_[0]->{Built}; $_[0]->{C}->[0] }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   877
sub xql_text       { $_[0]->contents->xql_text }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   878
sub xql_rawText    { $_[0]->contents->xql_text }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   879
sub tag_for_print  { "file" }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   880
sub print_kids     { 0 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   881
sub dump_attr_def  { $ATTRDEF->dump }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   882
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   883
sub xql_rawTextBlocks
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   884
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   885
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   886
    ( [ 0, 0, $self->xql_text ])
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   887
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   888
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   889
sub xql_setValue
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   890
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   891
    my ($self, $text) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   892
    $self->contents->xql_setValue ($text);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   893
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   894
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   895
sub xql_replaceBlockWithText
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   896
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   897
    my ($self, $start, $end, $text) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   898
    if ($start == 0 && $end == 0)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   899
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   900
	$self->xql_setValue ($text);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   901
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   902
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   903
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   904
	warn "xql_setText bad index start=$start end=$end";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   905
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   906
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   907
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   908
sub build
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   909
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   910
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   911
    push @{ $self->{C} }, XML::XQL::FileContents->new (Parent => $self);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   912
    $self->{Built} = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   913
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   914
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   915
#----------------------------------------------------------------------------
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   916
package XML::XQL::FileContents;	# Text node
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   917
use vars qw{ @ISA };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   918
@ISA = qw{ XML::XQL::DirNode };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   919
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   920
sub new
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   921
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   922
    my ($type, %hash) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   923
    bless \%hash, $type;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   924
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   925
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   926
sub isTextNode     { 1 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   927
sub xql_nodeType   { 3 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   928
sub xql_nodeName   { "#contents" }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   929
sub getChildIndex  { 0 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   930
sub xql_childCount { 0 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   931
sub xql_rawText    { $_[0]->xql_text }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   932
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   933
sub xql_text
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   934
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   935
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   936
    unless ($self->{Built})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   937
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   938
	local *FILE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   939
	local $/;	# slurp mode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   940
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   941
	if (open (FILE, $self->{Parent}->fullname))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   942
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   943
	    $self->{Data} = <FILE>;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   944
	    close FILE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   945
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   946
	else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   947
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   948
#?? warning
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   949
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   950
	$self->{Built} = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   951
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   952
    $self->{Data};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   953
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   954
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   955
sub xql_setValue
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   956
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   957
    my ($self, $text) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   958
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   959
    my $filename = $self->{Parent}->fullname;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   960
    local *FILE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   961
    if (open (FILE, ">$filename"))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   962
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   963
	print FILE $text;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   964
	$self->{Data} = $text;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   965
	$self->{Built} = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   966
	close FILE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   967
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   968
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   969
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   970
	warn "xql_setValue could not open $filename for writing";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   971
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   972
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   973
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   974
return 1;