Return-Path:
Readers are the components that send you a stream without the XML pr=
ocessing
--- that normally happens in a pipeline.=C2=A0 Cocoon already comes with so=
me readers out
+++ that normally happens in a pipeline. Cocoon already comes with some rea=
ders out
of the box such as your FileReader which serializes files from your web=
app
--- context.=C2=A0 What if you need something that doesn't come from the fi=
le system?=C2=A0
--- What if you need to create content on the fly but the XML processing ge=
ts in the
--- way?=C2=A0 That's where the Reader comes to play.=C2=A0 Even though the=
re is a
--- DatabaseReader in the Cocoon's SQL block, we are going to go through th=
e process
--- of creating a cacheable database reader here.Creating a Reader
=20
In the sitemap we use the reader we are going to develop like this:<= /p> =20 (3 equal lines skipped) =20
The sitemap snippet above matches anything in the attachment path fo= llowed by --- the ID for the attachment.=C2=A0 It then passes the ID into the src= --- attribute for our reader.=C2=A0 Why not include the nice neat little ex= tension for --- the file after the ID?=C2=A0 We actually have a very good reason: Micro= soft.=C2=A0 If you --- recall from the SitemapOutputComponent Contracts<= /a> page, --- Internet Explorer likes to pretend its smarter than you are.=C2=A0 If y= ou have a file --- extension on the URL that IE knows, it will ignore your mime-type setti= ngs that --- you provide.=C2=A0 However, if you don't provide any clues then IE has = to fall back --- to respecting the standard.
+++ the ID for the attachment. It then passes the ID into the src +++ attribute for our reader. Why not include the nice neat little extensio= n for the +++ file after the ID? We actually have a very good reason: Microsoft. If y= ou recall +++ from the SitemapOutputComponent Contracts pag= e, Internet +++ Explorer likes to pretend its smarter than you are. If you have a file = extension +++ on the URL that IE knows, it will ignore your mime-type settings that y= ou +++ provide. However, if you don't provide any clues then IE has to fall ba= ck to +++ respecting the standard. =20A Sitemap fills two of the core contracts with the Sitemap.=C2=A0 It=
is both a
--- SitemapModelComponent and a SitemapOutputComponent.=C2=A0 You can=
em> make it a
+++ A Sitemap fills two of the core contracts with the Sitemap. It is bo=
th a
+++ SitemapModelComponent and a SitemapOutputComponent. You can ma=
ke it a
CacheableProcessingComponent as well, which will help reduce the load o=
n your
--- database by avoiding the need to retrieve your attachments all the time=
.=C2=A0 In
+++ database by avoiding the need to retrieve your attachments all the time=
. In
fact, unless you have a good reason not to, you should always make your
--- components cacheable just for the flexibility in deployment later.=C2=
=A0 I recommend
+++ components cacheable just for the flexibility in deployment later. I re=
commend
you read the articles on the core contracts to understand where to find=
the
resources you need. A sitemap will fulfill all its core contracts first.=C2=A0 It will t=
hen query the
--- reader using the getLastModified() method.=C2=A0 The results o=
f that method
+++ A sitemap will fulfill all its core contracts first. It will then qu=
ery the
+++ reader using the getLastModified() method. The results of that=
method
will be added to the response header for browser caching purposes--alth=
ough it
--- is only done for the CachingPipeline.=C2=A0 Lastly, the sitemap will ca=
ll the
--- generate() method to create and send the results back to the c=
lient.=C2=A0
+++ is only done for the CachingPipeline. Lastly, the sitemap will call the
+++ generate() method to create and send the results back to the c=
lient.
It's a one stop shop, and because the Reader is both a SitemapModelComp=
onent and
a SitemapOutputComponent it is the beginning and the end of your pipeli=
ne. The ServiceableReader provides a good basis for building our databas=
e bound
--- AttachmentReader.=C2=A0 The ServiceableReader implements the Recyclable=
, LogEnabled
+++ AttachmentReader. The ServiceableReader implements the Recyclable, LogE=
nabled
and Serviceable interfaces and captures some of the information you wil=
l need
--- for you.=C2=A0 We will need these three interfaces to get a reference t=
o the
--- DataSourceComponent, our Logger, and to clean up our request based arti=
facts.=C2=A0
+++ for you. We will need these three interfaces to get a reference to the
+++ DataSourceComponent, our Logger, and to clean up our request based arti=
facts.
You might want to implement the Parameterizable or Configurable interfa=
ces if
you want to decide which particular database we will be hitting in your=
own
--- code.=C2=A0 For now, we are going to hard code the information.ServiceableReader: A Good Start
=20
If you'll notice we added the Disposable interface to the contract a= s well.=C2=A0 +++
If you'll notice we added the Disposable interface to the contract a= s well. This is so that we can be good citizens and release our components when= we are --- done with them.=C2=A0 Anything pooled needs to be released.=C2=A0 While= it's probably safe --- to treat your DataSourceComponent and your ServiceManager as singletons= in the --- system, we still want to be responsible.=C2=A0 First things first, let'= s get our --- DataSourceComponent and hold on to it as long as this Reader is around.= =C2=A0 To do --- this we will need to add two more class fields:
+++ done with them. Anything pooled needs to be released. =20 +++While it's probably safe to treat your DataSourceComponent and your +++ ServiceManager as singletons in the system, we still want to be respons= ible. +++ First things first, let's get our DataSourceComponent and hold on to it= as long +++ as this Reader is around. To do this we will need to add two more class= fields: +++
+++=20private DataSourceComponent datasource; private ServiceSelector dbselector;(6 equal lines skipped) Fields =3D=3D=3D=3D=3D=3D no changes Links =3D=3D=3D=3D=3D no changes Custom Fields =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D no changes Collections =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D no changes