You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Sascha Kulawik <sa...@kulawik.de> on 2002/07/28 12:08:17 UTC

RE: Return BLOB Value / redesigned DatabaseReader / a NO thank-you to Cocoon-developers

Thank you very much, but it didn't work out.
I've now taken the DatabaseReaser.java and changed it in a little way
for my needs - now it works.
I think, te DatabaseReader that comes with Cocoon will never work in
that case. I haven't found the solution, to give the reader the
informations which "id" or something else I'm searching for.
It was REALLY messy to get this working - I'm a Java Developer of
course, also I'm a Cocoon User - but not a Cocoon Developer. So I've
tried to get this reader working, without any good documentation. Hey
Cocoon guys, it's really hard to understand components with a Javadoc
Information, that doesn't fit to the sourcecode of this component ! 
A little example for the DatabaseReader:
At first I have to give the reader the Information, which Datasouce from
my Sitemap I want to use.
Nothing found in Javadoc, in the Source I've found, that there must be
an Parameter "use-connection" for giving the Name of the Database
Connection.
But - as I said, I'm not a Cocoon-Dev or Avalon Expert, so: is this a
Value of a XML Parameter ? Is this a Attribute ? Where do I have to use
the Attribute ?
After 2 hours trial & error I've found, that this is a Element (not
map:parameter) in the map:reader section. Also I've found, that this
component doesn't like my Entrys in the cocoon.xconf like:
<jdbc name="myconn">
(like any other components), so that there MUST be also a given class
like:
<jdbc name="MyConnectionName"
class="org.apache.avalon.util.datasource.JdbcDataSource">
But: how should I know that ? Why does all the other components work
without this class ? (Thats an Avalon Issue, I don't know how the
selektors work...)
Afer all that work and a lot of Time there was the last two issues for
getting this Reader working:
How can I give the component the part of the SQL, where I'm looking for
?
(Like: SELECT * FROM table WHERE id = ?, the "?" Part was never filled.)
After that and a new Parameter for that in the Sorce (there was a
varaible, that was never been initialized and used for that (also in the
parent-class), don't know hw this should work) I've got
NullPointerExceptions that I can't resolve.
(Hey, I'm not a Cocoon Expert ! :-)
So I've found, that I also need to give the reader the mime-type like
any redirect to an Image, so that there will be a correct output.
This Issue was fast to resolve, because in the procedure getMimeType()
was an entry like super.getMimeType() and the super.getMimeType() will
ever give NULL.
So I've taken the Mimetsype from the Database for supporting
DOc/PDF/GIF/JPG ... and so on.
My Sitemap looks like this right now:
<map:match pattern="BLOB">
    <map:act type="request">
     <map:parameter name="parameters" value="true"/>
     <map:read type="db">
      <parameter name="table" value="teasermessage_blob"/>
      <parameter name="image" value="data"/>
      <parameter name="key" value="id"/>
      <parameter name="find" value="{id}"/>
      <parameter name="filename" value="filename"/>
      <parameter name="mime" value="mimetype"/>
     </map:read>
    </map:act>
   </map:match>
 
So, If anybody is interested in my source, I can give it to you, but
what I want to say is, that this was REALLY messy to get a reader
working, and a lot of the soruce in Cocoon isn't right documented - so
If you aren't a cocoon-source-expert you have to look and invest a lot
of time to get thinks working.
Especially all of the Actions / Readers / Generators that aren't in any
HowTo are not easy to understand and there is a documentation, that
won't give any correct answer to that question. 
Also there was been saved with examples and so on. Sometimes it isn't
clear, if there will be a Sitemap entry at the component or where do you
use this component.
 
Ok,
thats enough for today,
greetings,
Sascha

-----Original Message-----
From: Jeroen ter Voorde [mailto:j.tervoorde@home.nl] 
Sent: Saturday, July 27, 2002 3:25 PM
To: cocoon-users@xml.apache.org
Subject: Re: Return BLOB Value
Importance: High


You can use a Reader to implement this (That's what i did).
 
(Stripped) Example:
 
public class Reader extends AbstractReader implements Poolable,
Composable {
 
 Request request = null;
 Response response = null;
 Context context = null;
 ComponentManager manager = null;
 
 public void setup(SourceResolver resolver, Map objectModel, String src,
Parameters par) throws ProcessingException, SAXException, IOException {
  super.setup(resolver, objectModel, src, par);
  context = ObjectModelHelper.getContext(objectModel);
  request = ObjectModelHelper.getRequest(objectModel);
  response = ObjectModelHelper.getResponse(objectModel);
 }
 
  public void generate() throws IOException, SAXException,
ProcessingException {
    
  try {
    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0);
 
   // out is the outputstream to write your blob data to.
 
    ((OutputStream)out).write('The blob data');

   }
  } catch (Exception e) {   
   throw new ProcessingException("Error in reader: "+e);
  }
 }
 
 public String getMimeType() {
  return context.getMimeType(source.substring(source.lastIndexOf("/") +
1));
 }
}
 
----- Original Message ----- 

From: Sascha  <ma...@kulawik.de> Kulawik 
To: cocoon-users@xml.apache.org <ma...@xml.apache.org>  
Sent: Friday, July 26, 2002 10:07 PM
Subject: Return BLOB Value



Hello, 

I'm trying to implement a File-Upload / Download for a small Forum
written in Cocoon XSP. 
Currently Ive no idea how to implement the FileDownload. The easiest way
for that would be to write the data to a mySQL Ressouce and read the
data because of Userpermissions and so on.

Is it possible, to returm plain BLOB Data from a Database to the User
for a Download ? 
Is there a better way to implement that in Cocoon ? 

Thank you very much, 

Greetings, 
Sascha 


RE: Return BLOB Value / redesigned DatabaseReader / a NO thank-you to Cocoon-developers

Posted by Vadim Gritsenko <va...@verizon.net>.
Sascha,

Do you want to submit a patch to DatabaseReader documentation?


Vadim


-----Original Message-----
From: Sascha Kulawik [mailto:sascha@kulawik.de] 
Sent: Sunday, July 28, 2002 6:08 AM
To: cocoon-users@xml.apache.org
Subject: RE: Return BLOB Value / redesigned DatabaseReader / a NO
thank-you to Cocoon-developers

Thank you very much, but it didn't work out.
I've now taken the DatabaseReaser.java and changed it in a little way
for my needs - now it works.
I think, te DatabaseReader that comes with Cocoon will never work in
that case. I haven't found the solution, to give the reader the
informations which "id" or something else I'm searching for.
It was REALLY messy to get this working - I'm a Java Developer of
course, also I'm a Cocoon User - but not a Cocoon Developer. So I've
tried to get this reader working, without any good documentation. Hey
Cocoon guys, it's really hard to understand components with a Javadoc
Information, that doesn't fit to the sourcecode of this component ! 
A little example for the DatabaseReader:
At first I have to give the reader the Information, which Datasouce from
my Sitemap I want to use.
Nothing found in Javadoc, in the Source I've found, that there must be
an Parameter "use-connection" for giving the Name of the Database
Connection.
But - as I said, I'm not a Cocoon-Dev or Avalon Expert, so: is this a
Value of a XML Parameter ? Is this a Attribute ? Where do I have to use
the Attribute ?
After 2 hours trial & error I've found, that this is a Element (not
map:parameter) in the map:reader section. Also I've found, that this
component doesn't like my Entrys in the cocoon.xconf like:
<jdbc name="myconn">
(like any other components), so that there MUST be also a given class
like:
<jdbc name="MyConnectionName"
class="org.apache.avalon.util.datasource.JdbcDataSource">
But: how should I know that ? Why does all the other components work
without this class ? (Thats an Avalon Issue, I don't know how the
selektors work...)
Afer all that work and a lot of Time there was the last two issues for
getting this Reader working:
How can I give the component the part of the SQL, where I'm looking for
?
(Like: SELECT * FROM table WHERE id = ?, the "?" Part was never filled.)
After that and a new Parameter for that in the Sorce (there was a
varaible, that was never been initialized and used for that (also in the
parent-class), don't know hw this should work) I've got
NullPointerExceptions that I can't resolve.
(Hey, I'm not a Cocoon Expert ! :-)
So I've found, that I also need to give the reader the mime-type like
any redirect to an Image, so that there will be a correct output.
This Issue was fast to resolve, because in the procedure getMimeType()
was an entry like super.getMimeType() and the super.getMimeType() will
ever give NULL.
So I've taken the Mimetsype from the Database for supporting
DOc/PDF/GIF/JPG ... and so on.
My Sitemap looks like this right now:
<map:match pattern="BLOB">
    <map:act type="request">
     <map:parameter name="parameters" value="true"/>
     <map:read type="db">
      <parameter name="table" value="teasermessage_blob"/>
      <parameter name="image" value="data"/>
      <parameter name="key" value="id"/>
      <parameter name="find" value="{id}"/>
      <parameter name="filename" value="filename"/>
      <parameter name="mime" value="mimetype"/>
     </map:read>
    </map:act>
   </map:match>
 
So, If anybody is interested in my source, I can give it to you, but
what I want to say is, that this was REALLY messy to get a reader
working, and a lot of the soruce in Cocoon isn't right documented - so
If you aren't a cocoon-source-expert you have to look and invest a lot
of time to get thinks working.
Especially all of the Actions / Readers / Generators that aren't in any
HowTo are not easy to understand and there is a documentation, that
won't give any correct answer to that question. 
Also there was been saved with examples and so on. Sometimes it isn't
clear, if there will be a Sitemap entry at the component or where do you
use this component.
 
Ok,
thats enough for today,
greetings,
Sascha
-----Original Message-----
From: Jeroen ter Voorde [mailto:j.tervoorde@home.nl] 
Sent: Saturday, July 27, 2002 3:25 PM
To: cocoon-users@xml.apache.org
Subject: Re: Return BLOB Value
Importance: High
You can use a Reader to implement this (That's what i did).
 
(Stripped) Example:
 
public class Reader extends AbstractReader implements Poolable,
Composable {
 
 Request request = null;
 Response response = null;
 Context context = null;
 ComponentManager manager = null;
 
 public void setup(SourceResolver resolver, Map objectModel, String src,
Parameters par) throws ProcessingException, SAXException, IOException {
  super.setup(resolver, objectModel, src, par);
  context = ObjectModelHelper.getContext(objectModel);
  request = ObjectModelHelper.getRequest(objectModel);
  response = ObjectModelHelper.getResponse(objectModel);
 }
 
  public void generate() throws IOException, SAXException,
ProcessingException {
    
  try {
    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0);
 
   // out is the outputstream to write your blob data to.
 
    ((OutputStream)out).write('The blob data');

   }
  } catch (Exception e) {   
   throw new ProcessingException("Error in reader: "+e);
  }
 }
 
 public String getMimeType() {
  return context.getMimeType(source.substring(source.lastIndexOf("/") +
1));
 }
}
 
----- Original Message ----- 
From: Sascha Kulawik 
To: cocoon-users@xml.apache.org 
Sent: Friday, July 26, 2002 10:07 PM
Subject: Return BLOB Value

Hello, 
I'm trying to implement a File-Upload / Download for a small Forum
written in Cocoon XSP. 
Currently Ive no idea how to implement the FileDownload. The easiest way
for that would be to write the data to a mySQL Ressouce and read the
data because of Userpermissions and so on.
Is it possible, to returm plain BLOB Data from a Database to the User
for a Download ? 
Is there a better way to implement that in Cocoon ? 
Thank you very much, 
Greetings, 
Sascha 


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>