Copy
Introduction
The copy operation is performed on the subtree corresponding to a given document id and a given area.
We have to :
- compute a new id (to not overwrite an already existing file)
- copy the contents (xml file)
- copy the resources
- instantiate the workflow for the new documents
- insert a node (with the subtree) in the site tree
Implementation
It is implemented in a sequence of usecases to get all needed parameters, and use the task concept to execute some ant task
To perform the different operations on the desired subtree, we used the visitor pattern
Parameters
The parameters are string-value parameters
Required parameters:
- the area for the source document
- the document id for the source document
- the area for the destination document
- the document id for the destination document
- the user id
- the ip adress
- the task id
usecase
They are implemented in the usecase sitmap (core)
Copy screen
URL :
{document-URL}?lenya.usecase=copy&lenya.step=showscreen
usecase sitemap:
<map:match pattern="copy" type="usecase"> <map:match pattern="showscreen" type="step"> <map:generate src="content/info/copy.xsp" type="serverpages"/> <map:transform src="xslt/info/copy.xsl"/> <map:call resource="style-cms-page"/> </map:match> </map:match>
The parameters for the source are get with the serverpage through the page envelope input module. A form (build with the xslt transformation) sends then the parameters as request parameters with the new URL.
Copy confirmation
URL :
{document-URL}?lenya.usecase=copy&lenya.step=step&...{source parameters}
usecase sitemap:
<map:match pattern="copy" type="usecase"> <map:match pattern="copy" type="step"> <map:act type="session-propagator"> <map:parameter name="org.apache.lenya.cms.info.cutdocumentid" value=""/> <map:parameter name="org.apache.lenya.cms.info.firstdocid" value="{request-param:documentid}"/> <map:parameter name="org.apache.lenya.cms.info.firstarea" value="{request-param:area}"/> <map:parameter name="org.apache.lenya.cms.info.action" value="{request-param:action}"/> </map:act> <map:redirect-to session="true" uri="{request:requestURI}"/> </map:match> </map:match>
The source parameters are saved in the session with the org.apache.cocoon.acting.SessionPropagatorAction
Rem
The session parameter org.apache.lenya.cms.info.cutdocumentid is needed by the move function. It must be reset to "" else
Paste screen
URL :
{document-URL}?lenya.usecase=paste&lenya.step=showscreen
usecase sitemap (Core):
<map:match pattern="paste" type="usecase"> <map:match pattern="showscreen" type="step"> <map:generate src="content/info/paste.xsp" type="serverpages"/> <map:transform src="xslt/info/paste.xsl"/> <map:call resource="style-cms-page"/> </map:match> </map:match>
The parameters for the destination are get with the serverpage through the page envelope input module. Parameters needed by the access controller are also get with this serverpage through the access control input module. The parameters for the source are get from the session with the serverpage . A form (build with the xslt transformation) sends then the parameters as request parameters with the new URL.
Paste confirmation
URL :
{document-URL}?lenya.usecase=paste&lenya.step=paste&...{parameters}
usecase sitemap (Core):
<map:match pattern="paste" type="usecase"> <map:match pattern="paste" type="step"> <map:select type="request-parameter"> <map:parameter name="parameter-name" value="task-id"/> <map:when test="moveDocument"> <map:act type="session-propagator"> <map:parameter name="org.apache.lenya.cms.info.firstdocid" value=""/> <map:parameter name="org.apache.lenya.cms.info.cutdocumentid" value=""/> </map:act> </map:when> <map:otherwise> <map:act type="session-propagator"> <map:parameter name="org.apache.lenya.cms.info.cutdocumentid" value=""/> </map:act> </map:otherwise> </map:select> <map:act type="task"> <map:redirect-to session="true" uri="{request:requestURI}"/> </map:act> </map:match> </map:match>
The paste step is also used by the move operation. In this case the parameter org.apache.lenya.cms.info.cutdocumentid must be set to the value of the document id (see Move). In case of the copy function the value of org.apache.lenya.cms.info.cutdocumentid in the session must be "". The action org.apache.lenya.cms.cocoon.acting.TaskAction calls the execution of the ant task.
Ant Task
The ant target is in the publication :
{publication}/config/tasks/targets.xml
The target for copying a document depends on the target newdocumentid, to be sure, that the document id for the destination is unique
For more information about the Ant task, see the documentation Ant Task and the Javadocs.