2 # ============================================================================
3 # Zebra perl API header
4 # =============================================================================
7 # =============================================================================
8 package IDZebra::Data1;
12 # -----------------------------------------------------------------------------
13 # Class constructors and destructor
14 # -----------------------------------------------------------------------------
16 my ($proto, $handle, $mem) = @_;
17 my $class = ref($proto) || $proto;
21 $self->{dh} = $handle;
23 # data1_destroy is not going to be called, when object is released
30 my ($proto, $mem, $flag) = @_;
31 my $class = ref($proto) || $proto;
36 unless ($self->{dh} = IDZebra::data1_createx($flag)) {
37 croak ("Cannot create data1 handle");
40 # data1_destroy going to be called, when object is released
43 unless ($self->{mem} = $mem) {
44 croak ("Missing NMEM handle");
53 if ($self->{dflag}) { IDZebra::data1_destroy($self->{dh}) }
58 # -----------------------------------------------------------------------------
60 # -----------------------------------------------------------------------------
63 my ($self, $file, $mode) = @_;
64 return (IDZebra::data1_path_fopen ($self->{dh}, $file, $mode));
68 my ($self, $path) = @_;
69 if (defined($path)) { IDZebra::data1_set_tabpath($self->{dh}, $path); }
70 return (IDZebra::data1_get_tabpath($self->{dh}));
74 my ($self, $path) = @_;
75 if (defined($path)) { IDZebra::data1_set_tabroot($self->{dh}, $path); }
76 return (IDZebra::data1_get_tabroot($self->{dh}));
79 # -----------------------------------------------------------------------------
80 # D1 Structure manipulation
81 # -----------------------------------------------------------------------------
83 my ($self, $name) = @_;
84 return (IDZebra::data1_mk_root($self->{dh}, $self->{mem}, $name));
88 my ($self, $node, $name) = @_;
89 IDZebra::data1_set_root($self->{dh}, $node, $self->{mem}, $name);
93 my ($self, $parent, $tag, @attributes) = @_;
94 return (IDZebra::data1_mk_tag($self->{dh}, $self->{mem},
95 $tag, \@attributes, $parent));
99 my ($self, $node, @attributes) = @_;
100 IDZebra::data1_tag_add_attr ($self->{dh}, $self->{mem},
101 $node, \@attributes);
105 my ($self, $parent, $text) = @_;
106 $text = "" unless ($text);
107 return (IDZebra::data1_mk_text($self->{dh}, $self->{mem},
112 my ($self, $parent, $text) = @_;
113 return (IDZebra::data1_mk_comment($self->{dh}, $self->{mem},
118 my ($self, $parent, $target, @attributes) = @_;
119 return (IDZebra::data1_mk_preprocess($self->{dh}, $self->{mem},
120 $target, \@attributes, $parent));
125 my ($self, $node) = @_;
126 IDZebra::data1_print_tree($self->{dh}, $node);
130 my ($self, $node) = @_;
131 IDZebra::data1_free_tree($self->{dh}, $node);
134 # =============================================================================
140 IDZebra::Data1 - OO Aproach interface for data1 structures
146 my $m = IDZebra::nmem_create();
147 my $d1=IDZebra::Data1->new($m,$IDZebra::DATA1_FLAG_XML);
148 my $root = $d1->mk_root('ostriches');
149 my $tag = $d1->mk_tag($root,'emu',('speed' => 120,
155 I never managed to understand data1 entirely. Probably Adam, or someone else from IndexData could write a more deep introduction here. However here are some ideas:
157 Data1 structures are used in zebra to represent structured data. You can map an xml structure, a marc record, or anything in D1. These structures are built by different filters - this is called "extraction" in zebra's code.
159 When zebra asks a filter to extract a file, it provides a data1 handle, which can be used to
161 - reach profile information, provided in zebra.cfg, and other refered
162 configuration files, (like tab path).
164 - build data1 structures
166 In one word, a data1 handle is a kind of context in the d1 API. This handle is represented here as a IDZebra::Data1 object. When you implement a filter, you'll get this object ready for use, otherwise, you'll have to prepare an NMEM handle, and call the constructor:
168 my $m = IDZebra::nmem_create();
169 my $dh = IDZebra::Data1->new($m,$IDZebra::DATA1_FLAG_XML);
171 What is FLAG_XML? I don't know exactly. You don't have to worry about it, it's already set, if you implement a filter.
173 =head1 PROFILE INFORMATION
175 =item $d1->tabpath([$path])
177 Set and/or get the tab path. This is a colon separated list of directories, where different configuration files can be found.
179 =item $d1->tabroot([$path])
181 Set and/or get the tab root.
183 =head1 BUILDING DATA STRUCTURES
185 It's obvious, that first of all you have to create a root node:
187 my $r1 = $d1->mk_root('pod');
189 This is going to initialize the abstract syntax "pod" (trying to open and parse pod.abs). I don't know why exactly, but then, you'll have to create a root tag as well, under the same name.
191 my $root=$d1->mk_tag($r1,'pod');
193 Then just continue, to add child nodes, as tags, text nodes... to your structure.
195 =item $d1->mk_root($name)
197 Create a root node, with the given name. (name is type in d1 terminology?)
199 =item $d1->set_root($node, $name)
201 Makes an existing node into root node, under the given name
203 =item $d1->mk_tag($parent, $name, [@attributes])
205 Add a tag to the parent node, with the given name and attributes. For example:
207 my $tag = $d1->mk_tag($root,'emu',('speed' => 120,
210 =item $d1->tag_add_attr($node, @attributes)
212 Add attributes to an existing node
214 =item $d1->mk_text($parent, $text)
216 Add a text node to the given parent
218 =item $d1->mk_comment($parent, $text)
220 Add a comment node to the given parent
222 =item $d1->mk_preprocess($parent, $target, $attributes)
226 =item $d1->pr_tree($node)
228 Prints data1 tree on STDOUT;
230 =item $d1->free_tree($node)
232 Destroys a data1 node structure;
240 Peter Popovics, pop@technomat.hu
244 IDZebra, Zebra documentation