You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by BMur <br...@hotmail.com> on 2007/01/11 22:18:26 UTC

Create New File

Hello, I'm using Cocoon version 2.1.7:

I have an instance of Lenya, which uses Cocoon, and I beleive this question
is related to Cocoon more than Lenya.

I would like to create a new file within the filesystem on-the-fly.  If
possible I would like to do this in an xmap file (usecase.xmap).  I'd like
to pass the xmap file some variables, and create a new xml file based on
those variables.  For instance:
<source:write create="true"
xmlns:source="http://apache.org/cocoon/source/1.0">
<source:source>MyTestfileName.xml</source:source>
<source:fragment>"Value of passed variable"</source:fragment>
</source:write>

I've tried various methods of creating the file using source:write in the
xmap, however nothing has worked thus far.  I'd paste my errors here,
however I receive different errors depending on the different attempts I've
made.

Can anyone help, or provide an alternative for creating files on the fly?
-- 
View this message in context: http://www.nabble.com/Create-New-File-tf2961773.html#a8286480
Sent from the Cocoon - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Create New File

Posted by BMur <br...@hotmail.com>.

Joerg Heinicke wrote:
> 
>> <source:write create="true"
>> xmlns:source="http://apache.org/cocoon/source/1.0">
>> <source:source>MyTestfileName.xml</source:source>
>> <source:fragment>"Value of passed variable"</source:fragment>
>> </source:write>
>> 
> 
> The above code looks at least like a code snippet for the 
> SourceWritingTransformer, which is a possible choice. But we can't help 
> if you don't provide at least the pipeline code from your sitemap, which 
> seem to be named usecase.xmap in your case.
> 
> Jörg
> 

Thank you for the reply Jörg!  Is there anything in particular that you'd be
looking for in the xmap code?  Unfortunately Lenya loads a number of xmap
files, and the one I referenced is almost 900 lines of code.  The pipeline
which I would like to do this in is about 700 of those 900 lines.  Due to
this I don't think you'd want me to send it (let me know if I'm wrong).  
The end result is to use the variables I originally mentioned to create an
rss file, however for the time being I'd be happy with simply creating a
file with "hello world" in it, then I can worry about it's content
afterward.
-- 
View this message in context: http://www.nabble.com/Create-New-File-tf2961773.html#a8299146
Sent from the Cocoon - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Create New File

Posted by Joerg Heinicke <jo...@gmx.de>.
On 11.01.2007 22:18, BMur wrote:

> I would like to create a new file within the filesystem on-the-fly.  If
> possible I would like to do this in an xmap file (usecase.xmap).  I'd like
> to pass the xmap file some variables, and create a new xml file based on
> those variables.  For instance:
> <source:write create="true"
> xmlns:source="http://apache.org/cocoon/source/1.0">
> <source:source>MyTestfileName.xml</source:source>
> <source:fragment>"Value of passed variable"</source:fragment>
> </source:write>
> 
> I've tried various methods of creating the file using source:write in the
> xmap, however nothing has worked thus far.  I'd paste my errors here,
> however I receive different errors depending on the different attempts I've
> made.

The above code looks at least like a code snippet for the 
SourceWritingTransformer, which is a possible choice. But we can't help 
if you don't provide at least the pipeline code from your sitemap, which 
seem to be named usecase.xmap in your case.

Jörg

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Create New File

Posted by "Steven D. Majewski" <sd...@virginia.edu>.
On Jan 12, 2007, at 2:14 PM, BMur wrote:

> Thanks for the reply Steve.  I apologize for not being clear.   
> Since this is
> a Cocoon mailing list I was trying not to add too much Lenya stuff,  
> but
> obviously I'm not sending enough details.
> Here is my goal -
> I'm using Cocoon 2.1.7 and Lenya 1.2.4, and in Lenya (for those  
> that are
> unfamiliar) you can create/edit pages in an authoring environment,  
> and when
> done the page can be published to show in the live area of the  
> site.  When
> creating/editing a page you can add a metadata attribute (tags)  
> which shows
> up as <dc:subject>news</dc:subject> in the generated xml content file
> (assuming the page was tagged as "news").  What I would like to do  
> while
> publishing and deactivating a page is to add it to an rss feed  
> file.  So, if
> the page is tagged as news (as in my example), when publishing I'd  
> like to
> first check to see if news.rss exists, and if it doesn't create and  
> build
> the file.  This would build the regular rss tags, including one  
> entry with
> the pages information (title, description, etc).  If the page already
> exists, I simply want to append a new rss item to the list.
> I may have been attempting to do this from the wrong location
> (usecase.xmap), however my first goal was trying to actually create  
> a file
> with the default rss xml tags (channel, items, etc).
> If I'm going about this the wrong way and you have any adivse, it  
> would be
> appreciated.
> -- 

Do I have this right ? :

	The user is uploading or somehow creating an xml file with lenya.
	When that happens, you want to generate an RSS item from data in  
that file
	( and either append it to an existing RSS item list, or create a new  
one )


If the original item is in xml, then I would use xslt to generate the  
rss item.
I don't have much experience with source-writer, but it looks like  
that could
be used to do the appending. If you have to tie a whole sequence of  
steps together,
then flowscript may be the best way to do that.

[ You could also just leave each rss fragment in it's own file and  
collect them
    together as another step -- what's best probably depends on  
details. ]

In general: if you're new to cocoon, it would be worth the time to  
start out looking
at some of the samples and trying out some simple stuff first until  
you understand
the cocoon processing model. I don't know if those are included in  
lenya (probably
not). You can probably run both webapps ( lenya.war and cocoon ) side  
by side in
tomcat.

Cocoon documentation leaves a bit to be desired. Cocoon has been  
quite a moving target,
and the existing books, while useful, all hardly touch some of the  
newer methods, which
seem to be the preferred way of doing things now. ( The main  
components I'm using seem
to be: xslt, xinclude, jx (generator/transformer) & flowscript. I  
also started trying
the authorization framework, but that seems to be deprecated in the  
latest release. )




-- Steve Majewski - University of Virginia Alderman Library


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Create New File

Posted by BMur <br...@hotmail.com>.
> It's not really clear from your message either what you're trying to  
> accomplish,
> or how you're trying to do it currently.  ( For example: I'm not  
> quite sure what
> you could mean by "pass the xmap file some variables" -- this doesn't  
> quite
> parse for me. Are you trying to modify an uploaded file, or are you  
> trying to
> generate a file from a template with variables ? Sourcewriter is  
> probably not
> the best tool for the latter. )
> 
> You're not trying to put the <source:*> tags in the xmap file, are you ?
> 
> If you look at the fragment in lenya's usecase.xmap file where the  
> source writer is called,
> what's happening is that a file is being sent via HTTP POST, the  
> stream generator is
> being called to start processing that file thru the xml pipeline, and  
> and xslt transform is
> done ( using xslt/authoring/edit/addSourceTags.xsl ) to wrap the  
> <source:write> and other
> source:tags around the content. ( That's where the source:tags  
> belong, not in the sitemap. )
> 
> 

> These are quite distinct steps in cocoon.
> If you want to generate content from a template using parameters, jx  
> transformer/generator or xslt
> might be the tool for that step.

> -- Steve Majewski / UVA Alderman Library

Thanks for the reply Steve.  I apologize for not being clear.  Since this is
a Cocoon mailing list I was trying not to add too much Lenya stuff, but
obviously I'm not sending enough details.  
Here is my goal - 
I'm using Cocoon 2.1.7 and Lenya 1.2.4, and in Lenya (for those that are
unfamiliar) you can create/edit pages in an authoring environment, and when
done the page can be published to show in the live area of the site.  When
creating/editing a page you can add a metadata attribute (tags) which shows
up as <dc:subject>news</dc:subject> in the generated xml content file
(assuming the page was tagged as "news").  What I would like to do while
publishing and deactivating a page is to add it to an rss feed file.  So, if
the page is tagged as news (as in my example), when publishing I'd like to
first check to see if news.rss exists, and if it doesn't create and build
the file.  This would build the regular rss tags, including one entry with
the pages information (title, description, etc).  If the page already
exists, I simply want to append a new rss item to the list.
I may have been attempting to do this from the wrong location
(usecase.xmap), however my first goal was trying to actually create a file
with the default rss xml tags (channel, items, etc).
If I'm going about this the wrong way and you have any adivse, it would be
appreciated.
-- 
View this message in context: http://www.nabble.com/Create-New-File-tf2961773.html#a8304419
Sent from the Cocoon - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Create New File

Posted by "Steven D. Majewski" <sd...@virginia.edu>.
On Jan 11, 2007, at 4:18 PM, BMur wrote:

>
> Hello, I'm using Cocoon version 2.1.7:
>
> I have an instance of Lenya, which uses Cocoon, and I beleive this  
> question
> is related to Cocoon more than Lenya.
>
> I would like to create a new file within the filesystem on-the- 
> fly.  If
> possible I would like to do this in an xmap file (usecase.xmap).   
> I'd like
> to pass the xmap file some variables, and create a new xml file  
> based on
> those variables.  For instance:
> <source:write create="true"
> xmlns:source="http://apache.org/cocoon/source/1.0">
> <source:source>MyTestfileName.xml</source:source>
> <source:fragment>"Value of passed variable"</source:fragment>
> </source:write>
>
> I've tried various methods of creating the file using source:write  
> in the
> xmap, however nothing has worked thus far.  I'd paste my errors here,
> however I receive different errors depending on the different  
> attempts I've
> made.
>
> Can anyone help, or provide an alternative for creating files on  
> the fly?

It's not really clear from your message either what you're trying to  
accomplish,
or how you're trying to do it currently.  ( For example: I'm not  
quite sure what
you could mean by "pass the xmap file some variables" -- this doesn't  
quite
parse for me. Are you trying to modify an uploaded file, or are you  
trying to
generate a file from a template with variables ? Sourcewriter is  
probably not
the best tool for the latter. )

You're not trying to put the <source:*> tags in the xmap file, are you ?

If you look at the fragment in lenya's usecase.xmap file where the  
source writer is called,
what's happening is that a file is being sent via HTTP POST, the  
stream generator is
being called to start processing that file thru the xml pipeline, and  
and xslt transform is
done ( using xslt/authoring/edit/addSourceTags.xsl ) to wrap the  
<source:write> and other
source:tags around the content. ( That's where the source:tags  
belong, not in the sitemap. )



           <map:match pattern="xml" type="step">
             <map:match pattern="*/*/**.html">
               <map:select type="request-method">
                 <map:when test="POST"> <!-- Save -->

                   <!-- test if the document is checked out -->
         	        <map:act type="reserved-checkout-test">
             	      <map:generate type="serverpages" src="../../ 
content/rc/{exception}.xsp">
                 	    <map:parameter name="user" value="{user}"/>
                     	<map:parameter name="filename"  
value="{filename}"/>
         	            <map:parameter name="date" value="{date}"/>
                         <map:parameter name="message"  
value="{message}"/>
             	      </map:generate>
                 	  <map:transform src="../../xslt/rc/rco- 
exception.xsl"/>
         	          <map:call resource="style-cms-page"/>
                 	</map:act>

                   <map:generate type="stream"/>
                   <map:transform src="xslt/authoring/edit/ 
addSourceTags.xsl">
                     <map:parameter name="source" value="pubs/{1}/ 
content/{2}/{page-envelope:document-path}"/>
                     <!--<map:parameter name="source" value="pubs/{1}/ 
test-xopus.xml"/>-->
                   </map:transform>
                   <map:transform type="write-source">
                     <map:parameter name="serializer" value="xml"/>
                   </map:transform>
		  <map:act type="workflow">
		    <map:parameter name="area" value="{page-envelope:area}"/>
		    <map:parameter name="document-id" value="{page- 
envelope:document-id}"/>
		    <map:parameter name="language" value="{page-envelope:document- 
language}"/>
		    <map:parameter name="event" value="edit"/>
		  </map:act>
                   <map:serialize type="xml"/>
                 </map:when>
                 <map:otherwise> <!-- GET: Open -->
                   <map:generate src="pubs/{1}/content/{2}/{page- 
envelope:document-path}"/>
                   <map:serialize type="xml"/>
                 </map:otherwise>
               </map:select>
             </map:match>
           </map:match>


These are quite distinct steps in cocoon.
If you want to generate content from a template using parameters, jx  
transformer/generator or xslt
might be the tool for that step.

-- Steve Majewski / UVA Alderman Library



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org