You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by gr...@apache.org on 2005/05/27 03:20:52 UTC

svn commit: r178723 - in /lenya/sandbox/cformedit/lenya/usecases/cformedit: flow/form_editor.js usecase-cformedit.xmap

Author: gregor
Date: Thu May 26 18:20:50 2005
New Revision: 178723

URL: http://svn.apache.org/viewcvs?rev=178723&view=rev
Log:
Added cforms cleanup patch by Maxim Wasiliev. This resolves http://issues.apache.org/bugzilla/show_bug.cgi?id=34562

Added:
    lenya/sandbox/cformedit/lenya/usecases/cformedit/flow/form_editor.js
Modified:
    lenya/sandbox/cformedit/lenya/usecases/cformedit/usecase-cformedit.xmap

Added: lenya/sandbox/cformedit/lenya/usecases/cformedit/flow/form_editor.js
URL: http://svn.apache.org/viewcvs/lenya/sandbox/cformedit/lenya/usecases/cformedit/flow/form_editor.js?rev=178723&view=auto
==============================================================================
--- lenya/sandbox/cformedit/lenya/usecases/cformedit/flow/form_editor.js (added)
+++ lenya/sandbox/cformedit/lenya/usecases/cformedit/flow/form_editor.js Thu May 26 18:20:50 2005
@@ -0,0 +1,126 @@
+/*
+* Copyright 1999-2004 The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+/*
+* @version $Id: form_model_gui.js 151173 2005-02-03 16:07:11Z tim $
+*/
+
+cocoon.load("resource://org/apache/cocoon/forms/flow/javascript/Form.js");
+
+function formedit(form) {
+
+    var locale = determineLocale();
+    var model = form.getModel();
+    form.locale = locale;
+
+    // get the documentURI parameter from the sitemap which
+    // contains the location of the file to be edited
+    var documentURI = cocoon.parameters["documentURI"];
+    var tmpdocumentURI = cocoon.parameters["tmpURI"];
+
+    // parse the document to a DOM-tree
+    var document = loadDocument(documentURI);
+
+    // bind the document data to the form
+    form.load(document);
+
+    // show the form, until it is valid or canceled
+		do {
+			form.showForm("form_model_gui-display-pipeline");
+			if( form.submitId == "cancel" ) {
+				cocoon.sendPage("form_model_gui-cancel-pipeline");
+				}
+			} while( ! form.isValid );
+
+    // bind the form's data back to the document
+    form.save(document);
+
+    // save the DOM-tree back to an XML file, the makeTargetURI
+    // function makes a modified filename so that the
+    // original document is not overwritten
+    saveDocument(document, tmpdocumentURI);
+
+    // also store the form as a request attribute as the XSP isn't flow-aware
+    //cocoon.request.setAttribute("form_model_gui", form.getWidget());
+    cocoon.sendPage("form_model_gui-submit-pipeline");
+}
+
+function determineLocale() {
+    var localeParam = cocoon.request.get("locale");
+    if (localeParam != null && localeParam.length > 0) {
+        return Packages.org.apache.cocoon.i18n.I18nUtils.parseLocale(localeParam);
+    }
+    return null;
+}
+
+function loadDocument(uri) {
+    var parser = null;
+    var source = null;
+    var resolver = null;
+    try {
+        parser = cocoon.getComponent(Packages.org.apache.excalibur.xml.dom.DOMParser.ROLE);
+        resolver = cocoon.getComponent(Packages.org.apache.cocoon.environment.SourceResolver.ROLE);
+        source = resolver.resolveURI(uri);
+        var is = new Packages.org.xml.sax.InputSource(source.getInputStream());
+        is.setSystemId(source.getURI());
+        return parser.parseDocument(is);
+    } finally {
+        if (source != null)
+            resolver.release(source);
+        cocoon.releaseComponent(parser);
+        cocoon.releaseComponent(resolver);
+    }
+}
+
+function saveDocument(document, uri) {
+    var source = null;
+    var resolver = null;
+    var outputStream = null;
+    try {
+        resolver = cocoon.getComponent(Packages.org.apache.cocoon.environment.SourceResolver.ROLE);
+        source = resolver.resolveURI(uri);
+
+        var tf = Packages.javax.xml.transform.TransformerFactory.newInstance();
+
+        if (source instanceof Packages.org.apache.excalibur.source.ModifiableSource
+            && tf.getFeature(Packages.javax.xml.transform.sax.SAXTransformerFactory.FEATURE)) {
+
+            outputStream = source.getOutputStream();
+            var transformerHandler = tf.newTransformerHandler();
+            var transformer = transformerHandler.getTransformer();
+            transformer.setOutputProperty(Packages.javax.xml.transform.OutputKeys.INDENT, "true");
+            transformer.setOutputProperty(Packages.javax.xml.transform.OutputKeys.METHOD, "xml");
+            transformerHandler.setResult(new Packages.javax.xml.transform.stream.StreamResult(outputStream));
+
+            var streamer = new Packages.org.apache.cocoon.xml.dom.DOMStreamer(transformerHandler);
+            streamer.stream(document);
+        } else {
+            throw new Packages.org.apache.cocoon.ProcessingException("Cannot write to source " + uri);
+        }
+    } finally {
+        if (source != null)
+            resolver.release(source);
+        cocoon.releaseComponent(resolver);
+        if (outputStream != null) {
+            try {
+                outputStream.flush();
+                outputStream.close();
+            } catch (error) {
+                cocoon.log.error("Could not flush/close outputstream: " + error);
+            }
+        }
+    }
+}

Modified: lenya/sandbox/cformedit/lenya/usecases/cformedit/usecase-cformedit.xmap
URL: http://svn.apache.org/viewcvs/lenya/sandbox/cformedit/lenya/usecases/cformedit/usecase-cformedit.xmap?rev=178723&r1=178722&r2=178723&view=diff
==============================================================================
--- lenya/sandbox/cformedit/lenya/usecases/cformedit/usecase-cformedit.xmap (original)
+++ lenya/sandbox/cformedit/lenya/usecases/cformedit/usecase-cformedit.xmap Thu May 26 18:20:50 2005
@@ -1,214 +1,115 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-  Copyright 1999-2004 The Apache Software Foundation
-
-  Licensed under the Apache License, Version 2.0 (the "License");
-  you may not use this file except in compliance with the License.
-  You may obtain a copy of the License at
-
-      http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
--->
-
-<!-- $Id$ -->
-
-<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
-  <!-- =========================== Components ================================ -->
-  <map:components/>
-  <!-- =========================== Resources ================================ -->
-  <map:resources>
-    <map:resource name="style-cms-page">
-      <map:transform type="i18n">      
-        <map:parameter name="locale" value="{request:locale}"/>
-      </map:transform>    
-      <map:transform src="{global:basedir}/xslt/util/page2xhtml.xsl">
-        <map:parameter name="contextprefix" value="{request:contextPath}"/>
-      </map:transform>
-      <map:transform src="{global:basedir}/xslt/util/strip_namespaces.xsl"/>
-      <map:serialize type="xhtml"/>
-    </map:resource>    
-
-     <!-- this will later become a virtual transformer -->
-        <map:resource name="simple-page2html">
-	     <map:transform src="context://samples/common/style/xsl/html/simple-page2html.xsl">
-	            <map:parameter name="contextPath" value="{request:contextPath}"/>
-		           <map:parameter name="servletPath" value="{request:servletPath}"/>
-			          <map:parameter name="sitemapURI" value="{request:sitemapURI}"/>
-				         <map:parameter name="file" value="{file}"/>
-					        <map:parameter name="remove" value="{../0}"/>
-						     </map:transform>
-						        </map:resource>
-
-  </map:resources>  
-
-  <!-- =========================== Flow ===================================== -->
-  <map:flow language="javascript">
-    <map:script src="../edit-document.js"/>
-
-    <map:script src="flow/forms_flow_example.js"/>
-    <map:script src="flow/binding_example.js"/>
-    <map:script src="flow/upload_example.js"/>
-    <map:script src="flow/registration.js"/>
-    <map:script src="flow/bindings.js"/>
-    <map:script src="flow/form_model_gui.js"/>
-    <map:script src="flow/htmlarea.js"/>
-
-  </map:flow>
-
-  <!-- =========================== Pipelines ================================ -->  
-  <map:pipelines>
-    
-    <map:component-configurations>
-      <global-variables>
-        <!-- To access core resources -->
-        <basedir>../..</basedir>
-      </global-variables>
-    </map:component-configurations>
-
-
-    <map:pipeline internal-only="true">     
-      <map:match pattern="request2document">
-        <map:generate src="{global:basedir}/pubs/{page-envelope:publication-id}/work/oneformeditor/authoring/{page-envelope:document-id}.xml"/>
-        <map:serialize type="xml"/>
-      </map:match>
-    </map:pipeline>   
-    
-    <!-- Usecase pipeline -->  
-    <map:pipeline>           
-
-      <map:match pattern="cformedit" type="usecase">
-
-        <map:match pattern="open" type="step">
-
-          <map:match pattern="*/authoring/**.html">
-            <map:act type="reserved-checkout">
-              <map:generate type="serverpages" src="{global:basedir}/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="{global:basedir}/xslt/rc/rco-exception.xsl"/>
-              <map:call resource="style-cms-page"/>
-            </map:act>
-              
-            <map:call function="handleForm">
-              <map:parameter name="function" value="form2xml"/>
-              <map:parameter name="form-definition" value="forms/linkform_model.xml"/>
-              <map:parameter name="documentURI" value="lenya:/{page-envelope:document-path}"/>
-              <map:parameter name="bindingURI" value="forms/linkform_binding.xml"/>
-            </map:call>
-
-	    <!--
-            <map:generate src="{global:basedir}/pubs/{1}/content/authoring/{page-envelope:document-path}"/>
-            <map:transform src="{global:basedir}/xslt/authoring/edit/oneform.xsl">
-               <map:parameter name="docid" value="{page-envelope:document-id}"/>
-               <map:parameter name="language" value="{page-envelope:document-language}"/>
-            </map:transform>
-            <map:call resource="style-cms-page"/>
-	    -->
-          </map:match>
-        </map:match>
-	
-
-	<!--+
-	    | In this usecase just for debugging:
-	    | Output the raw XML document
-	    +-->
-
-	<map:match pattern="xml" type="step">
-
-          <map:match pattern="*/authoring/**.html">
-
-	    <map:generate src="lenya:/{page-envelope:document-path}" />
-	    <map:serialize type="xml" />
-
-	  </map:match>
-
-	</map:match>
-
-
-        <map:match pattern="close" type="step">
-            <map:match pattern="*/authoring/**.html">
-              <map:act type="request-parameter-exists">
-                <map:parameter name="parameters" value="save"/>
-                <map:act type="oneformeditorsave">
-                  <map:parameter name="file" value="{global:basedir}/pubs/{../1}/work/oneformeditor/authoring/{page-envelope:document-id}.xml"/>
-                  <map:parameter name="schema" value="{global:basedir}/pubs/{../1}/config/doctypes/schemas/{page-envelope:document-type}.rng"/>
-                  <map:generate src="{global:basedir}/pubs/{../../1}/content/authoring/{page-envelope:document-path}"/>
-                  <map:transform src="{global:basedir}/xslt/authoring/edit/oneform.xsl">
-                    <map:parameter name="docid" value="{page-envelope:document-id}"/>
-                    <map:parameter name="language" value="{page-envelope:document-language}"/>
-                    <map:parameter name="message" value="{message}"/>
-                  </map:transform>
-                  <map:call resource="style-cms-page"/>
-                </map:act>
-
-                <!-- Validation succeeded -->
-                <!-- Save: Overwrite original file  -->
-                <map:call function="editDocument">
-                  <map:parameter name="sourceUri" value="cocoon:/request2document"/>
-                  <map:parameter name="useBuffer" value="false"/>
-                  <map:parameter name="noStatus" value="true"/>
-                  <map:parameter name="redirectUrl" value="{request:requestURI}"/>
-                </map:call>               
-              </map:act>
-              <!-- 
-                Cancel is pressed. Unlock the document. 
-                Alternatively one could use the reserved-checkin action direct.
-              -->
-              <map:redirect-to uri="{page-envelope:context-prefix}/{1}/authoring/{2}.html?lenya.usecase=checkin&amp;lenya.step=checkin&amp;backup=false"/>
-            </map:match>
-          </map:match>
-
-        </map:match>
-
-    </map:pipeline>
-
-    <map:pipeline>
-
-      <!--+
-          | Show a form, using the forms transformer
-          +-->
-      <map:match pattern="*-display-pipeline">
-			           <map:generate src="forms/linkform_template.xml"/>
-				          <map:transform type="forms" label="content1"/>
-					         <map:transform type="i18n">
-						          <!--map:parameter name="locale" value="en-US"/-->
-							         </map:transform>
-								        <map:call resource="simple-page2html">
-									         <map:parameter name="file" value="forms/{1}_template.xml"/>
-										        </map:call>
-											       <map:transform src="resources/forms-samples-styling.xsl"/>
-											              <map:serialize/>
-												           </map:match>
-
-      <map:match pattern="form2-success-pipeline">
-        <map:generate src="../../pubs/default/content/authoring/links/index_en-result.xml"/>
-        <map:transform type="i18n">
-	           <!--map:parameter name="locale" value="en-US"/-->
-		          </map:transform>
-			         <map:serialize type="xml"/>
-      </map:match>
-
-       <!-- Continue a scenario. The continuation id is passed in the URL
-                 (typically used for GET requests) -->
-		      <map:match pattern="**/*.continue">
-		             <map:call continuation="{2}"/>
-			          </map:match>
-
-				       <!-- Continue a scenario. The continuation id is passed as a request
-				                 parameter (typically used for POST request) -->
-						      <map:match pattern="continue">
-						             <map:call continuation="{request-param:continuation-id}"/>
-							          </map:match>
-
-  </map:pipeline>
-  </map:pipelines>
-
-</map:sitemap>
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  Copyright 1999-2004 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<!-- $Id$ -->
+
+<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
+
+<!-- =========================== Resources ================================ -->
+	<map:resources>
+		<map:resource name="style-cms-page">
+			<map:transform type="i18n">
+				<map:parameter name="locale" value="{request:locale}"/>
+			</map:transform>
+			<map:transform src="fallback://xslt/util/page2xhtml.xsl">
+				<map:parameter name="contextprefix" value="{request:contextPath}"/>
+			</map:transform>
+			<map:transform src="fallback://xslt/util/strip_namespaces.xsl"/>
+			<map:serialize type="xhtml"/>
+		</map:resource>
+		<!-- this will later become a virtual transformer -->
+		<map:resource name="simple-page2html">
+			<map:transform src="context://samples/common/style/xsl/html/simple-page2html.xsl">
+				<map:parameter name="contextPath" value="{request:contextPath}"/>
+				<map:parameter name="servletPath" value="{request:servletPath}"/>
+				<map:parameter name="sitemapURI" value="{request:sitemapURI}"/>
+				<map:parameter name="file" value="{file}"/>
+				<map:parameter name="remove" value="{../0}"/>
+			</map:transform>
+		</map:resource>
+	</map:resources>
+
+<!-- =========================== Flow ===================================== -->
+	<map:flow language="javascript">
+		<map:script src="../edit-document.js"/>
+		<map:script src="flow/form_editor.js"/>
+	</map:flow>
+
+<!-- =========================== Pipelines ================================ -->
+	<map:pipelines>
+
+		<map:pipeline>
+			<map:match pattern="cformedit" type="usecase">
+				<map:match pattern="open" type="step">
+					<map:match pattern="*/authoring/**.html">
+						<map:act type="reserved-checkout">
+							<map:generate type="serverpages" src="fallback://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="fallback://xslt/rc/rco-exception.xsl"/>
+							<map:call resource="style-cms-page"/>
+						</map:act>
+						<map:call function="handleForm">
+							<map:parameter name="function" value="formedit"/>
+							<map:parameter name="form-definition" value="fallback://config/doctypes/cforms/{page-envelope:document-type}-model.xml"/>
+							<map:parameter name="bindingURI" value="fallback://config/doctypes/cforms/{page-envelope:document-type}-binding.xml"/>
+							<map:parameter name="documentURI" value="fallback://content/authoring/{page-envelope:document-path}"/>
+							<map:parameter name="tmpURI" value="fallback://work/cformeditor/{page-envelope:document-path}"/>
+						</map:call>
+					</map:match>
+				</map:match>
+			</map:match>
+		</map:pipeline>
+
+
+		<map:pipeline>
+			<map:match pattern="form_model_gui-display-pipeline">
+				<map:generate src="fallback://config/doctypes/cforms/{page-envelope:document-type}-template.xml"/>
+				<map:transform type="forms" label="content1"/>
+				<map:call resource="simple-page2html">
+					<map:parameter name="file" value="forms/{1}_template.xml"/>
+				</map:call>
+				<map:transform src="resources/forms-samples-styling.xsl">
+					<map:parameter name="resources-uri" value="/lenya"/>
+				</map:transform>
+				<map:serialize/>
+			</map:match>
+
+			<map:match pattern="form_model_gui-submit-pipeline">
+				<map:call function="editDocument">
+					<map:parameter name="sourceUri" value="fallback://work/cformeditor/{page-envelope:document-path}"/>
+					<map:parameter name="useBuffer" value="false"/>
+					<map:parameter name="noStatus" value="true"/>
+					<map:parameter name="redirectUrl" value="{request:requestURI}?"/>
+				</map:call>
+			</map:match>
+			
+			<map:match pattern="form_model_gui-cancel-pipeline">
+				<map:redirect-to uri="{request:requestURI}?"/>
+			</map:match>
+
+			<map:match type="request-parameter" pattern="continue">
+				<map:call continuation="{1}"/>
+			</map:match>
+
+		</map:pipeline>
+	</map:pipelines>
+
+</map:sitemap>



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