You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by eg...@apache.org on 2003/09/18 10:10:54 UTC

cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/acting DocumentIdExistsAction.java

egli        2003/09/18 01:10:54

  Modified:    src/webapp/lenya usecase.xmap
  Added:       src/java/org/apache/lenya/cms/cocoon/acting
                        DocumentIdExistsAction.java
  Log:
  Added an action that checks for the existence of a document-id in the
  authoring site tree. This is used in the creation usecase. If a
  child-id is already taken redirect back to the creation screen and
  displey an error message.
  
  Revision  Changes    Path
  1.108     +157 -154  cocoon-lenya/src/webapp/lenya/usecase.xmap
  
  Index: usecase.xmap
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/webapp/lenya/usecase.xmap,v
  retrieving revision 1.107
  retrieving revision 1.108
  diff -u -r1.107 -r1.108
  --- usecase.xmap	12 Sep 2003 17:41:34 -0000	1.107
  +++ usecase.xmap	18 Sep 2003 08:10:54 -0000	1.108
  @@ -12,6 +12,7 @@
       <map:actions>
         <map:action name="save" logger="sitemap.action.save" src="org.apache.lenya.cms.cocoon.acting.HTMLFormSaveAction" />
         <map:action name="asset-upload" logger="sitemap.action.upload" src="org.apache.lenya.cms.cocoon.acting.AssetUploadAction" />
  +      <map:action name="document-id-exists" logger="sitemap.action.document-id-exists" src="org.apache.lenya.cms.cocoon.acting.DocumentIdExistsAction" />
       </map:actions>
   
       <map:selectors>
  @@ -21,9 +22,9 @@
           <exception class="org.xml.sax.SAXException" name="sax" unroll="true"/>
           <exception class="org.apache.cocoon.ResourceNotFoundException" name="resourcenotfound"/>
           <exception class="org.apache.lenya.cms.publishing.ParentNodeNotFoundException"
  -	  name="parent-node-not-found"/>
  -<!--         <exception class="org.apache.lenya.cms.publishing.PublishingException" name="publishing"/> -->
  -<!--         <exception class="org.apache.lenya.cms.publication.SiteTreeException" name="sitetree"/> -->
  +          name="parent-node-not-found"/>
  +        <!--         <exception class="org.apache.lenya.cms.publishing.PublishingException" name="publishing"/> -->
  +        <!--         <exception class="org.apache.lenya.cms.publication.SiteTreeException" name="sitetree"/> -->
         </map:selector>
       </map:selectors>
       
  @@ -76,13 +77,13 @@
         </map:select>
         
       </map:resource>
  -      
  +    
       <map:resource name="cms-screen">
  -    	<map:call resource="cms-screen-xml">
  -    		<map:parameter name="publication-id" value="{publication-id}"/>
  -    		<map:parameter name="serverpage" value="{serverpage}"/>
  -    		<map:parameter name="stylesheet" value="{stylesheet}"/>
  -    	</map:call>
  +      <map:call resource="cms-screen-xml">
  +        <map:parameter name="publication-id" value="{publication-id}"/>
  +        <map:parameter name="serverpage" value="{serverpage}"/>
  +        <map:parameter name="stylesheet" value="{stylesheet}"/>
  +      </map:call>
         <map:call resource="style-cms-page"/>
       </map:resource>
       
  @@ -98,34 +99,34 @@
       <!-- =================================================================== -->
       
       <map:pipeline>
  -    	
  -    	<!-- notification/{publication-id}/{usecase}.xml -->
  -    	<map:match pattern="notification/*/*.xml">
  -    		<map:select type="resource-exists">
  -    			<map:when test="lenya/pubs/{1}/config/notification/notification.xconf">
  +      
  +      <!-- notification/{publication-id}/{usecase}.xml -->
  +      <map:match pattern="notification/*/*.xml">
  +        <map:select type="resource-exists">
  +          <map:when test="lenya/pubs/{1}/config/notification/notification.xconf">
               <map:generate src="pubs/{1}/config/notification/notification.xconf"/>
  -    			</map:when>
  -    			<map:otherwise>
  +          </map:when>
  +          <map:otherwise>
               <map:generate src="config/notification/notification.xconf"/>
  -    			</map:otherwise>	
  -    		</map:select>
  -    		<map:transform src="xslt/notification/notification2message.xsl">
  -    			<map:parameter name="usecase" value="{2}"/>
  -    		</map:transform>
  -    		<map:serialize type="xml"/>
  -    	</map:match>
  -    	
  -    	<!-- notification/{publication-id}/{usecase}.xsl -->
  -    	<map:match pattern="notification/*/*.xsl">
  -    		<map:generate src="cocoon:/notification/{1}/{2}.xml"/>
  -    		<map:transform src="xslt/notification/message2xslt.xsl">
  -    			<map:parameter name="usecase" value="{2}"/>
  -    			<map:parameter name="server-uri" value="http://{request:serverName}:{request:serverPort}"/>
  -    			<map:parameter name="document-url" value="{request:contextPath}/{page-envelope:publication-id}/{page-envelope:area}{page-envelope:document-url}"/>
  -    		</map:transform>
  -    		<map:serialize type="xml"/>
  -    	</map:match>
  -    	
  +          </map:otherwise>      
  +        </map:select>
  +        <map:transform src="xslt/notification/notification2message.xsl">
  +          <map:parameter name="usecase" value="{2}"/>
  +        </map:transform>
  +        <map:serialize type="xml"/>
  +      </map:match>
  +      
  +      <!-- notification/{publication-id}/{usecase}.xsl -->
  +      <map:match pattern="notification/*/*.xsl">
  +        <map:generate src="cocoon:/notification/{1}/{2}.xml"/>
  +        <map:transform src="xslt/notification/message2xslt.xsl">
  +          <map:parameter name="usecase" value="{2}"/>
  +          <map:parameter name="server-uri" value="http://{request:serverName}:{request:serverPort}"/>
  +          <map:parameter name="document-url" value="{request:contextPath}/{page-envelope:publication-id}/{page-envelope:area}{page-envelope:document-url}"/>
  +        </map:transform>
  +        <map:serialize type="xml"/>
  +      </map:match>
  +      
       </map:pipeline>
       
       <!-- =================================================================== -->
  @@ -139,18 +140,18 @@
           
           <!-- mount publication-specific usecase sitemap -->
           <map:match type="usecase" pattern="*">
  -        <map:act src="pubs/{../1}/usecase-{1}.xmap" type="resource-exists">
  -          <map:mount check-reload="true" reload-method="synchron" src="pubs/{../../1}/usecase-{../1}.xmap" uri-prefix="{../../1}"/>
  -        </map:act>
  +          <map:act src="pubs/{../1}/usecase-{1}.xmap" type="resource-exists">
  +            <map:mount check-reload="true" reload-method="synchron" src="pubs/{../../1}/usecase-{../1}.xmap" uri-prefix="{../../1}"/>
  +          </map:act>
           </map:match>
           
           <!-- Scheduler -->
           <!-- Schedule Document: View, Add, Edit, Delete Jobs -->
           <map:match pattern="schedule" type="usecase">
  -        	
  -        	<!-- show scheduler screen -->
  +          
  +          <!-- show scheduler screen -->
             <map:match pattern="showscreen" type="step">
  -          	<map:generate src="cocoon://scheduler/publication/{../../1}"/>
  +            <map:generate src="cocoon://scheduler/publication/{../../1}"/>
               <map:transform src="xslt/scheduler/scheduler-page.xsl">
                 <map:parameter name="context-prefix" value="{request:contextPath}"/>
                 <map:parameter name="publication-id" value="{../../1}"/>
  @@ -161,11 +162,11 @@
             </map:match>
             
             <!-- other steps: add job (redirect to page) -->
  -         	<map:generate src="cocoon://scheduler/publication/{../1}"/>
  -					<map:transform src="xslt/util/redirect.xsl">
  -						<map:parameter name="url" value="{request:requestURI}"/>
  -					</map:transform>
  -					<map:serialize/>
  +          <map:generate src="cocoon://scheduler/publication/{../1}"/>
  +          <map:transform src="xslt/util/redirect.xsl">
  +            <map:parameter name="url" value="{request:requestURI}"/>
  +          </map:transform>
  +          <map:serialize/>
             
           </map:match>
           
  @@ -312,121 +313,123 @@
             </map:match>
             
             <map:match pattern="create" type="step">
  -            <map:act type="task">
  -              <map:parameter name="task-id" value="create"/>
  -              <!-- if the action suceeds redirect to the requestURI -->
  -              <map:redirect-to uri="{request:requestURI}"/>
  +            <!-- Make sure the child-id doesn't exist yet -->
  +            <map:act type="document-id-exists">
  +              <map:parameter name="document-id" value="{request-param:properties.create.parent-id}/{request-param:properties.create.child-id}"/>
  +              <map:act type="task">
  +                <map:parameter name="task-id" value="create"/>
  +                <map:redirect-to uri="{request:requestURI}"/>
  +              </map:act>
  +              <map:call resource="cms-screen">
  +                <map:parameter name="publication-id" value="{../../1}"/>
  +                <map:parameter name="serverpage" value="authoring/create.xsp"/>
  +                <map:parameter name="stylesheet" value="authoring/create.xsl"/>
  +              </map:call>
               </map:act>
  -            <!-- otherwise the action could not validate some of the -->
  -            <!-- input and we present the upload form again -->
  -            <map:call resource="cms-screen">
  -              <map:parameter name="publication-id" value="{../../1}"/>
  -              <map:parameter name="serverpage" value="authoring/create.xsp"/>
  -              <map:parameter name="stylesheet" value="authoring/create.xsl"/>
  -            </map:call>
  +            <map:redirect-to uri="{request:requestURI}?lenya.usecase=create&amp;lenya.step=showscreen&amp;status=duplicate-id"/>
             </map:match>
             
           </map:match>
  -	
  +        
   
   
  -      <!-- ************************************************************** -->
  -      <!-- ** HTML Form Editor                                         ** -->
  -      <!-- **                                                          ** -->
  -      <!-- ** NOTE: page-envelope:document-path depends on the         ** -->
  -      <!-- **       publication specific DocumentIdToPathMapper which  ** -->
  -      <!-- **       is configured within config/publication.xconf      ** -->
  -      <!-- ************************************************************** -->
  -      <map:match pattern="edit" type="usecase">
  -        <map:match pattern="open" type="step">
  -          <map:match pattern="*/authoring/**.html">
  -            <map:generate src="pubs/{1}/content/authoring/{page-envelope:document-path}"/>
  -            <map:transform src="xslt/authoring/edit/numberTags.xsl"/>
  -            <map:transform src="xslt/authoring/edit/addSourceTags.xsl">
  -              <map:parameter name="source" value="pubs/{1}/work/editor/authoring/{page-envelope:document-path}"/>
  -            </map:transform>
  -            <map:transform type="write-source"/>
  -            <map:transform src="xslt/authoring/edit/removeSourceTags.xsl"/>
  -            <map:transform src="pubs/{1}/lenya/xslt/formeditor/{request-param:doctype}.xsl">
  -              <map:parameter name="docid" value="{page-envelope:document-path}"/>
  -              <map:parameter name="doctype" value="{request-param:doctype}"/>
  -            </map:transform>
  -            <map:serialize type="html" />
  +        <!-- ************************************************************** -->
  +        <!-- ** HTML Form Editor                                         ** -->
  +        <!-- **                                                          ** -->
  +        <!-- ** NOTE: page-envelope:document-path depends on the         ** -->
  +        <!-- **       publication specific DocumentIdToPathMapper which  ** -->
  +        <!-- **       is configured within config/publication.xconf      ** -->
  +        <!-- ************************************************************** -->
  +        <map:match pattern="edit" type="usecase">
  +          <map:match pattern="open" type="step">
  +            <map:match pattern="*/authoring/**.html">
  +              <map:generate src="pubs/{1}/content/authoring/{page-envelope:document-path}"/>
  +              <map:transform src="xslt/authoring/edit/numberTags.xsl"/>
  +              <map:transform src="xslt/authoring/edit/addSourceTags.xsl">
  +                <map:parameter name="source" value="pubs/{1}/work/editor/authoring/{page-envelope:document-path}"/>
  +              </map:transform>
  +              <map:transform type="write-source"/>
  +              <map:transform src="xslt/authoring/edit/removeSourceTags.xsl"/>
  +              <map:transform src="pubs/{1}/lenya/xslt/formeditor/{request-param:doctype}.xsl">
  +                <map:parameter name="docid" value="{page-envelope:document-path}"/>
  +                <map:parameter name="doctype" value="{request-param:doctype}"/>
  +              </map:transform>
  +              <map:serialize type="html" />
  +            </map:match>
             </map:match>
  -        </map:match>
   
  -        <map:match pattern="close" type="step">
  -          <map:match pattern="*/authoring/**.html">
  -            <map:act type="save">
  -              <map:parameter name="file" value="pubs/{1}/work/editor/authoring/{page-envelope:document-path}"/>
  +          <map:match pattern="close" type="step">
  +            <map:match pattern="*/authoring/**.html">
  +              <map:act type="save">
  +                <map:parameter name="file" value="pubs/{1}/work/editor/authoring/{page-envelope:document-path}"/>
  +
  +                <!-- Continue editing: Insert, Delete, etc. -->
  +                <map:generate src="pubs/{../1}/work/editor/authoring/{page-envelope:document-path}"/>
  +                <map:transform src="xslt/authoring/edit/unnumberTags.xsl"/>
  +
  +                <map:transform src="xslt/authoring/edit/numberTags.xsl"/>
  +                <map:transform src="xslt/authoring/edit/addSourceTags.xsl">
  +                  <map:parameter name="source" value="pubs/{../1}/work/editor/authoring/{page-envelope:document-path}"/>
  +                </map:transform>
  +                <map:transform type="write-source"/>
  +                <map:transform src="xslt/authoring/edit/removeSourceTags.xsl"/>
  +
  +                <map:transform src="pubs/{../1}/lenya/xslt/formeditor/{request-param:doctype}.xsl">
  +                  <map:parameter name="docid" value="{page-envelope:document-path}"/>
  +                  <map:parameter name="doctype" value="{request-param:doctype}"/>
  +                  <map:parameter name="message" value="{message}"/>
  +                </map:transform>
  +                <map:serialize type="html" />
  +              </map:act>
   
  -              <!-- Continue editing: Insert, Delete, etc. -->
  -              <map:generate src="pubs/{../1}/work/editor/authoring/{page-envelope:document-path}"/>
  +              <!-- Stop Editing: Save and Cancel -->
  +              <map:generate src="pubs/{1}/work/editor/authoring/{page-envelope:document-path}"/>
                 <map:transform src="xslt/authoring/edit/unnumberTags.xsl"/>
   
  -              <map:transform src="xslt/authoring/edit/numberTags.xsl"/>
  +              <!-- Save: Overwrite original file (FIXME: Cancel should not overwrite original file) -->
                 <map:transform src="xslt/authoring/edit/addSourceTags.xsl">
  -                <map:parameter name="source" value="pubs/{../1}/work/editor/authoring/{page-envelope:document-path}"/>
  +                <map:parameter name="source" value="pubs/{1}/content/authoring/{page-envelope:document-path}"/>
                 </map:transform>
                 <map:transform type="write-source"/>
  -              <map:transform src="xslt/authoring/edit/removeSourceTags.xsl"/>
  -
  -              <map:transform src="pubs/{../1}/lenya/xslt/formeditor/{request-param:doctype}.xsl">
  -                <map:parameter name="docid" value="{page-envelope:document-path}"/>
  -                <map:parameter name="doctype" value="{request-param:doctype}"/>
  -                <map:parameter name="message" value="{message}"/>
  +              <map:transform src="xslt/authoring/edit/redirect-to.xsl">
  +                <map:parameter name="uri" value="{page-envelope:context-prefix}/{1}/authoring/{2}.html"/>
                 </map:transform>
                 <map:serialize type="html" />
  -            </map:act>
  +            </map:match>
  +          </map:match>
  +        </map:match>
  +        <!-- ************************************************************** -->
  +        <!-- ********  /HTML Form Editor *********************************** -->
  +        <!-- ************************************************************** -->
   
  -            <!-- Stop Editing: Save and Cancel -->
  -            <map:generate src="pubs/{1}/work/editor/authoring/{page-envelope:document-path}"/>
  -            <map:transform src="xslt/authoring/edit/unnumberTags.xsl"/>
  -
  -            <!-- Save: Overwrite original file (FIXME: Cancel should not overwrite original file) -->
  -            <map:transform src="xslt/authoring/edit/addSourceTags.xsl">
  -              <map:parameter name="source" value="pubs/{1}/content/authoring/{page-envelope:document-path}"/>
  -            </map:transform>
  -            <map:transform type="write-source"/>
  -            <map:transform src="xslt/authoring/edit/redirect-to.xsl">
  -              <map:parameter name="uri" value="{page-envelope:context-prefix}/{1}/authoring/{2}.html"/>
  -            </map:transform>
  -            <map:serialize type="html" />
  +        <!-- This matcher is very specific for unipublic and should -->
  +        <!-- probably go away -->
  +        <map:match pattern="upload" type="usecase">
  +
  +          <map:match pattern="showscreen" type="step">
  +            <map:generate type="serverpages" src="content/authoring/upload-image.xsp"/>
  +            <map:transform src="xslt/authoring/upload-image.xsl"/>
  +            <map:serialize/>
  +          </map:match>
  +
  +          <map:match type="step" pattern="showteaserscreen">
  +            <map:generate type="serverpages" src="content/authoring/upload-image.xsp"/>
  +            <map:transform src="xslt/authoring/upload-teaserimage.xsl"/>
  +            <map:serialize/>
  +          </map:match>
  +
  +          <map:match type="step" pattern="upload">
  +            <map:act type="file-upload">
  +              <map:redirect-to uri="{request:requestURI}"/>
  +            </map:act>
  +            <map:generate type="serverpages" src="content/authoring/upload-image.xsp"/>
  +            <map:transform src="xslt/authoring/upload-image.xsl"/>
  +            <map:serialize/>
             </map:match>
           </map:match>
  -      </map:match>
  -      <!-- ************************************************************** -->
  -      <!-- ********  /HTML Form Editor *********************************** -->
  -      <!-- ************************************************************** -->
  -
  -	<!-- This matcher is very specific for unipublic and should -->
  -	<!-- probably go away -->
  -	<map:match pattern="upload" type="usecase">
  -
  -	  <map:match pattern="showscreen" type="step">
  -	    <map:generate type="serverpages" src="content/authoring/upload-image.xsp"/>
  -	    <map:transform src="xslt/authoring/upload-image.xsl"/>
  -	    <map:serialize/>
  -	  </map:match>
  -
  -	  <map:match type="step" pattern="showteaserscreen">
  -	    <map:generate type="serverpages" src="content/authoring/upload-image.xsp"/>
  -	    <map:transform src="xslt/authoring/upload-teaserimage.xsl"/>
  -	    <map:serialize/>
  -	  </map:match>
  -
  -	  <map:match type="step" pattern="upload">
  -	    <map:act type="file-upload">
  -	      <map:redirect-to uri="{request:requestURI}"/>
  -	    </map:act>
  -	    <map:generate type="serverpages" src="content/authoring/upload-image.xsp"/>
  -	    <map:transform src="xslt/authoring/upload-image.xsl"/>
  -	    <map:serialize/>
  -	  </map:match>
  -	</map:match>
   
  -	<!-- This is the generic asset upload matcher and should be -->
  -	<!-- used for all publiations --> 
  +        <!-- This is the generic asset upload matcher and should be -->
  +        <!-- used for all publiations --> 
           <map:match pattern="asset" type="usecase">
   
             <map:match pattern="showscreen" type="step">
  @@ -454,10 +457,10 @@
             <map:match pattern="upload-and-insert" type="step">
               <map:act type="asset-upload">
                 <map:parameter name="task-id" value="{request-param:task-id}"/>
  -	      <map:act type="task">
  -		<map:parameter name="task-id" value="{request-param:task-id}"/>
  -		<map:redirect-to session="true" uri="{request:requestURI}"/>
  -	      </map:act>
  +              <map:act type="task">
  +                <map:parameter name="task-id" value="{request-param:task-id}"/>
  +                <map:redirect-to session="true" uri="{request:requestURI}"/>
  +              </map:act>
               </map:act>
             </map:match>
   
  @@ -546,8 +549,8 @@
               </map:act>
             </map:match>
   
  -	</map:match>
  -          
  +        </map:match>
  +        
           
           <!-- Info area use cases start here -->
           
  @@ -614,7 +617,7 @@
             <map:match pattern="showscreen" type="step">
               <map:generate src="content/info/archive.xsp" type="serverpages"/>
               <map:transform src="xslt/info/archive.xsl">
  -            	<map:parameter name="use-request-parameters" value="true"/>
  +              <map:parameter name="use-request-parameters" value="true"/>
               </map:transform>
               <map:call resource="style-cms-page"/>
             </map:match>
  @@ -633,7 +636,7 @@
             <map:match pattern="showscreen" type="step">
               <map:generate src="content/info/restore.xsp" type="serverpages"/>
               <map:transform src="xslt/info/restore.xsl">
  -            	<map:parameter name="use-request-parameters" value="true"/>
  +              <map:parameter name="use-request-parameters" value="true"/>
               </map:transform>
               <map:call resource="style-cms-page"/>
             </map:match>
  @@ -693,7 +696,7 @@
             <map:match pattern="showscreen" type="step">
               <map:generate src="content/info/deactivate.xsp" type="serverpages"/>
               <map:transform src="xslt/info/deactivate.xsl">
  -            	<map:parameter name="use-request-parameters" value="true"/>
  +              <map:parameter name="use-request-parameters" value="true"/>
               </map:transform>
               <map:transform src="cocoon:/notification/{../../1}/deactivate.xsl"/>
               <map:call resource="style-cms-page"/>
  @@ -713,7 +716,7 @@
             <map:match pattern="showscreen" type="step">
               <map:generate src="content/info/delete.xsp" type="serverpages"/>
               <map:transform src="xslt/info/delete.xsl">
  -            	<map:parameter name="use-request-parameters" value="true"/>
  +              <map:parameter name="use-request-parameters" value="true"/>
               </map:transform>
               <map:call resource="style-cms-page"/>
             </map:match>
  @@ -821,14 +824,14 @@
               <map:redirect-to session="true" uri="{request:requestURI}"/>
             </map:act>
           </map:match>
  -          
  +        
         </map:match>
         
         <map:handle-errors type="500">
           <map:select type="exception">
             <map:when test="parent-node-not-found">
  -	    <map:transform src="xslt/exception/parent-node-not-found.xsl"/>
  -	    <map:call resource="style-cms-page"/>
  +            <map:transform src="xslt/exception/parent-node-not-found.xsl"/>
  +            <map:call resource="style-cms-page"/>
             </map:when>
           </map:select>
           <map:serialize type="html"/>
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/acting/DocumentIdExistsAction.java
  
  Index: DocumentIdExistsAction.java
  ===================================================================
  /*
  $Id: DocumentIdExistsAction.java,v 1.1 2003/09/18 08:10:54 egli Exp $
  <License>
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Lenya" and  "Apache Software Foundation"  must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Michael Wechner <mi...@apache.org>. For more information on the Apache Soft-
   ware Foundation, please see <http://www.apache.org/>.
  
   Lenya includes software developed by the Apache Software Foundation, W3C,
   DOM4J Project, BitfluxEditor, Xopus, and WebSHPINX.
  </License>
  */
  package org.apache.lenya.cms.cocoon.acting;
  
  import org.apache.avalon.framework.parameters.ParameterException;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.cocoon.acting.AbstractAction;
  import org.apache.cocoon.environment.Redirector;
  import org.apache.cocoon.environment.SourceResolver;
  import org.apache.lenya.cms.publication.PageEnvelope;
  import org.apache.lenya.cms.publication.PageEnvelopeException;
  import org.apache.lenya.cms.publication.PageEnvelopeFactory;
  import org.apache.lenya.cms.publication.Publication;
  import org.apache.lenya.cms.publication.SiteTree;
  import org.apache.lenya.cms.publication.SiteTreeException;
  
  import java.util.Collections;
  import java.util.Map;
  
  /**
   * Action that checks the sitetree if there is a node with the 
   * current document-id. This is used to prevent creation of documents
   * with non-unique document-ids
   * 
   * @author <a href="mailto:egli@apache.org">Christian Egli</a>
   */
  public class DocumentIdExistsAction extends AbstractAction {
  
      /**
       * Check if there is a doument in the site tree with the given
       * document-id.
       * 
       * If yes return an empty map, if not return null.
       * 
       * @param redirector a <code>Redirector</code> value
       * @param resolver a <code>SourceResolver</code> value
       * @param objectModel a <code>Map</code> value
       * @param source a <code>String</code> value
       * @param parameters a <code>Parameters</code> value
       *
       * @return an empty <code>Map</code> if there is a document 
       * with the given document-id, null otherwiese
       *
       * @exception DocumentDoesNotExistException if there is no document with the specified document-id.
       * @exception PageEnvelopeException if the PageEnvelope could not be created.
       * @exception DocumentException if the language information could not be fetched from the document.
       */
  
      public static final String DOCUMENT_ID_PARAMETER_NAME = "document-id";
  
      public Map act(
          Redirector redirector,
          SourceResolver resolver,
          Map objectModel,
          String source,
          Parameters parameters)
          throws PageEnvelopeException, SiteTreeException, ParameterException {
  
          String documentId = parameters.getParameter(DOCUMENT_ID_PARAMETER_NAME);
  
          if (documentId == null) {
              return null;
          }
  
          PageEnvelope pageEnvelope =
              PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel);
  
          SiteTree siteTree =
              pageEnvelope.getPublication().getSiteTree(
                  Publication.AUTHORING_AREA);
  
          if (siteTree.getNode(documentId) == null) {
              return Collections.EMPTY_MAP;
          }
          return null;
      }
  }
  
  

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