/[wait]/cvs-head/lib/WAIT/Document/Ora.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /cvs-head/lib/WAIT/Document/Ora.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 69 - (show annotations)
Fri Jan 25 07:27:30 2002 UTC (22 years, 4 months ago) by laperla
File size: 2974 byte(s)
- Produced the first index that worked with 5.7.2@14354

1 # -*- Mode: Cperl -*-
2 # Nroff.pm --
3 # ITIID : $ITI$ $Header $__Header$
4 # Author : Ulrich Pfeifer
5 # Created On : Mon Sep 16 19:04:37 1996
6 # Last Modified By: Ulrich Pfeifer
7 # Last Modified On: Fri Jan 4 15:56:11 2002
8 # Language : CPerl
9 # Update Count : 86
10 # Status : Unknown, Use with caution!
11 #
12 # Copyright (c) 1996-1997, Ulrich Pfeifer
13 #
14
15 package WAIT::Document::Ora;
16 @ISA = qw(WAIT::Document::Base);
17 use WAIT::Document::Base;
18
19 use IO::File;
20 use Encode;
21 use strict;
22 use Carp;
23
24 sub TIEHASH {
25 my $type = shift;
26 my $dir = shift;
27 my @files;
28
29 opendir(DIR, $dir) or croak "Could not open '$dir': $!";
30 DIRENT: for my $entry (readdir DIR) {
31 if (-f "$dir/$entry/desc.html") {
32 my $index = "$dir/$entry/index.html";
33 open F, $index or Carp::confess("Could not open $index: $!");
34 local $/;
35 my $content = <F>;
36 next DIRENT unless $content =~ m|<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\s+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\s+<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">\s+<head>\s+<!-- product id:|s;
37 push @files, $entry;
38 }
39 }
40 closedir DIR;
41 my $self = {
42 Dir => $dir,
43 Files => \@files
44 };
45 bless $self, ref($type) || $type;
46 }
47
48 sub FETCH {
49 my $self = shift;
50 my $file = shift;
51
52 local($/) = undef;
53
54 my $fh = IO::File->new(join('/',$self->{Dir},$file,'desc.html'));
55 my $desc = conv_getline($fh);
56 $fh = IO::File->new(join('/',$self->{Dir},$file,'author.html'));
57 my $author = conv_getline($fh) if $fh;
58 $fh = IO::File->new(join('/',$self->{Dir},$file,'index.html'));
59 my $index = conv_getline($fh) if $fh;
60 $fh = IO::File->new(join('/',$self->{Dir},$file,'colophon.html'));
61 my $colophon = conv_getline($fh) if $fh;
62 return {
63 desc => $desc,
64 author => $author,
65 index => $index,
66 colophon => $colophon,
67 };
68 }
69
70 # WAIT::Document::Ora::conv_getline
71 sub conv_getline ($) {
72 my($fh) = shift;
73 local $/ = "\n";
74 my $firstline = <$fh>;
75 my $src_enc;
76 # \042 is double quote, \047 is single quote. I avoid single quotes
77 # here just for easier copy and paste to the terminal (I need to
78 # debug here frequently)
79 if ($firstline =~ /<\?xml[^>]+encoding\s*=([\042\047])([\w\-]+)\1/) {
80 $src_enc = $2;
81 } else {
82 $src_enc = "ISO-8859-1";
83 }
84 seek $fh, 0, 0;
85 undef $/;
86 my $content = <$fh>;
87 $content =~ s/\s+/ /gs; # eliminate TABs and CRs for easier debugging
88 my $dcontent = Encode::decode($src_enc,$content);
89 $dcontent;
90 }
91
92 sub FIRSTKEY {
93 my $self = shift;
94 $self->{fno} = 0;
95 $self->NEXTKEY;
96 }
97
98 sub NEXTKEY {
99 my $self = shift;
100 return undef if ($self->{fno}++ > @{$self->{Files}});
101 $self->{Files}->[$self->{fno}-1];
102 }
103
104 sub close {
105 my $self = shift;
106
107 delete $self->{fno};
108 delete $self->{Files}; # no need at query time
109 }
110
111 1;

Properties

Name Value
cvs2svn:cvs-rev 1.5

  ViewVC Help
Powered by ViewVC 1.1.26