You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2005/04/13 00:08:32 UTC
svn commit: r161126 - in lenya/trunk/src:
java/org/apache/lenya/cms/editors/forms/ webapp/WEB-INF/
webapp/lenya/pubs/default/config/menus/ webapp/lenya/usecases/edit/
webapp/lenya/usecases/edit/forms/
Author: andreas
Date: Tue Apr 12 15:08:30 2005
New Revision: 161126
URL: http://svn.apache.org/viewcvs?view=rev&rev=161126
Log:
ported oneformeditor to usecase framework, removed obsolete HtmlFormSaveAction
Added:
lenya/trunk/src/java/org/apache/lenya/cms/editors/forms/OneFormEditor.java
lenya/trunk/src/webapp/lenya/usecases/edit/forms/oneform.jx
lenya/trunk/src/webapp/lenya/usecases/edit/forms/oneform.xsl
Modified:
lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl
lenya/trunk/src/webapp/lenya/pubs/default/config/menus/generic.xsp
lenya/trunk/src/webapp/lenya/usecases/edit/forms/forms.jx
lenya/trunk/src/webapp/lenya/usecases/edit/usecase.xmap
Added: lenya/trunk/src/java/org/apache/lenya/cms/editors/forms/OneFormEditor.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/editors/forms/OneFormEditor.java?view=auto&rev=161126
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/editors/forms/OneFormEditor.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/editors/forms/OneFormEditor.java Tue Apr 12 15:08:30 2005
@@ -0,0 +1,199 @@
+/*
+ * 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.
+ *
+ */
+package org.apache.lenya.cms.editors.forms;
+
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
+import java.io.Writer;
+
+import org.apache.cocoon.components.ContextHelper;
+import org.apache.cocoon.components.source.SourceUtil;
+import org.apache.cocoon.environment.Request;
+import org.apache.excalibur.source.ModifiableSource;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceResolver;
+import org.apache.lenya.cms.publication.DocumentType;
+import org.apache.lenya.cms.publication.DocumentTypeResolver;
+import org.apache.lenya.cms.usecase.DocumentUsecase;
+import org.apache.lenya.cms.usecase.UsecaseException;
+import org.apache.lenya.transaction.Transactionable;
+import org.apache.lenya.xml.DocumentHelper;
+import org.apache.lenya.xml.RelaxNG;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ * One form editor.
+ *
+ * @version $Id:$
+ */
+public class OneFormEditor extends DocumentUsecase {
+
+ /**
+ * @see org.apache.lenya.cms.usecase.AbstractUsecase#getObjectsToLock()
+ */
+ protected Transactionable[] getObjectsToLock() throws UsecaseException {
+ return getSourceDocument().getRepositoryNodes();
+ }
+
+ /**
+ * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
+ */
+ protected void doExecute() throws Exception {
+ super.doExecute();
+
+ // Get namespaces
+ String namespaces = removeRedundantNamespaces(getParameterAsString("namespaces"));
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug(namespaces);
+ }
+
+ // Aggregate content
+
+ Request request = ContextHelper.getRequest(this.context);
+ String encoding = request.getCharacterEncoding();
+ String content = "<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>\n"
+ + addNamespaces(namespaces, getParameterAsString("content"));
+
+ // Save file temporarily
+
+ DocumentType doctype;
+ DocumentTypeResolver doctypeResolver = null;
+ try {
+ doctypeResolver = (DocumentTypeResolver) this.manager.lookup(DocumentTypeResolver.ROLE);
+ doctype = doctypeResolver.resolve(getSourceDocument());
+ } finally {
+ if (doctypeResolver != null) {
+ this.manager.release(doctypeResolver);
+ }
+ }
+
+ String pubId = getSourceDocument().getPublication().getId();
+ String schemaUri = "context://lenya/pubs/" + pubId + "/config/doctypes/schemas/"
+ + doctype.getName() + ".rng";
+ Source schemaSource = null;
+ ModifiableSource xmlSource = null;
+ SourceResolver resolver = null;
+ try {
+ resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+ xmlSource = (ModifiableSource) resolver.resolveURI(getSourceDocument().getSourceURI());
+ saveXMLFile(encoding, content, xmlSource);
+
+ boolean wellFormed = false;
+ try {
+ DocumentHelper.readDocument(xmlSource.getInputStream());
+ wellFormed = true;
+ } catch (SAXException e) {
+ addErrorMessage("Document is not well-formed: " + e.getMessage());
+ }
+
+ if (wellFormed) {
+ schemaSource = resolver.resolveURI(schemaUri);
+ if (!schemaSource.exists()) {
+ throw new IllegalArgumentException("The schema [" + schemaSource.getURI()
+ + "] does not exist.");
+ }
+
+ InputSource schemaInputSource = SourceUtil.getInputSource(schemaSource);
+ InputSource xmlInputSource = SourceUtil.getInputSource(xmlSource);
+
+ String message = RelaxNG.validate(schemaInputSource, xmlInputSource);
+ if (message != null) {
+ addErrorMessage("RELAX NG Validation failed: " + message);
+ }
+ }
+
+ } finally {
+ if (resolver != null) {
+ if (schemaSource != null) {
+ resolver.release(schemaSource);
+ }
+ if (xmlSource != null) {
+ resolver.release(xmlSource);
+ }
+ this.manager.release(resolver);
+ }
+ }
+ }
+
+ /**
+ * Save the XML file
+ * @param encoding The encoding
+ * @param content The content
+ * @param xmlSource The source
+ * @throws FileNotFoundException if the file was not found
+ * @throws UnsupportedEncodingException if the encoding is not supported
+ * @throws IOException if an IO error occurs
+ */
+ private void saveXMLFile(String encoding, String content, ModifiableSource xmlSource)
+ throws FileNotFoundException, UnsupportedEncodingException, IOException {
+ FileOutputStream fileoutstream = null;
+ Writer writer = null;
+
+ try {
+ writer = new OutputStreamWriter(xmlSource.getOutputStream(), encoding);
+ writer.write(content, 0, content.length());
+ } catch (FileNotFoundException e) {
+ getLogger().error("File not found " + e.toString());
+ } catch (UnsupportedEncodingException e) {
+ getLogger().error("Encoding not supported " + e.toString());
+ } catch (IOException e) {
+ getLogger().error("IO error " + e.toString());
+ } finally {
+ // close all streams
+ if (writer != null)
+ writer.close();
+ if (fileoutstream != null)
+ fileoutstream.close();
+ }
+ }
+
+ /**
+ * Remove redundant namespaces
+ * @param namespaces The namespaces to remove
+ * @return The namespace string without the removed namespaces
+ */
+ private String removeRedundantNamespaces(String namespaces) {
+ String[] namespace = namespaces.split(" ");
+
+ String ns = "";
+ for (int i = 0; i < namespace.length; i++) {
+ if (ns.indexOf(namespace[i]) < 0) {
+ ns = ns + " " + namespace[i];
+ } else {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Redundant namespace: " + namespace[i]);
+ }
+ }
+ }
+ return ns;
+ }
+
+ /**
+ * Add namespaces
+ * @param namespaces The namespaces to add
+ * @param content The content to add them to
+ * @return The content with the added namespaces
+ */
+ private String addNamespaces(String namespaces, String content) {
+ int i = content.indexOf(">");
+ return content.substring(0, i) + " " + namespaces + content.substring(i);
+ }
+}
\ No newline at end of file
Modified: lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl?view=diff&r1=161125&r2=161126
==============================================================================
--- lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl (original)
+++ lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl Tue Apr 12 15:08:30 2005
@@ -420,9 +420,12 @@
<component-instance name="edit.forms" logger="lenya.publication"
class="org.apache.lenya.cms.editors.forms.FormsEditor">
<transaction policy="pessimistic"/>
- <view template="edit/forms/forms" menu="false">
- <parameter name="formUri" value="cocoon://core/edit/form.xml"/>
- </view>
+ <view template="edit/forms/forms" menu="false"/>
+ </component-instance>
+ <component-instance name="edit.oneform" logger="lenya.publication"
+ class="org.apache.lenya.cms.editors.forms.OneFormEditor">
+ <transaction policy="pessimistic"/>
+ <view template="edit/forms/oneform" menu="false"/>
</component-instance>
</usecases>
Modified: lenya/trunk/src/webapp/lenya/pubs/default/config/menus/generic.xsp
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/pubs/default/config/menus/generic.xsp?view=diff&r1=161125&r2=161126
==============================================================================
--- lenya/trunk/src/webapp/lenya/pubs/default/config/menus/generic.xsp (original)
+++ lenya/trunk/src/webapp/lenya/pubs/default/config/menus/generic.xsp Tue Apr 12 15:08:30 2005
@@ -79,7 +79,7 @@
<item wf:event="edit" uc:usecase="kupu" uc:step="open" href="?"><i18n:text>With Kupu</i18n:text></item>
<item wf:event="edit" uc:usecase="bxe" uc:step="open" href="?"><i18n:text>With BXE</i18n:text></item>
<item wf:event="edit" uc:usecase="edit.forms"><xsp:attribute name="href"><xsp:expr>"?form=" + docType</xsp:expr></xsp:attribute><i18n:text>With Forms</i18n:text></item>
- <item wf:event="edit" uc:usecase="1formedit" uc:step="open" href="?"><i18n:text>With one Form</i18n:text></item>
+ <item wf:event="edit" uc:usecase="edit.oneform" href="?"><i18n:text>With one Form</i18n:text></item>
</block>
<block info="false">
Modified: lenya/trunk/src/webapp/lenya/usecases/edit/forms/forms.jx
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/usecases/edit/forms/forms.jx?view=diff&r1=161125&r2=161126
==============================================================================
--- lenya/trunk/src/webapp/lenya/usecases/edit/forms/forms.jx (original)
+++ lenya/trunk/src/webapp/lenya/usecases/edit/forms/forms.jx Tue Apr 12 15:08:30 2005
@@ -11,8 +11,9 @@
<jx:import uri="templates/messages.jx"/>
- <form method="post" action="?lenya.usecase=edit.forms">
+ <form method="post">
<input type="hidden" name="lenya.continuation" value="${continuation.id}"/>
+ <input type="hidden" name="lenya.usecase" value="${usecase.getName()}"/>
<jx:choose>
<jx:when test="${usecase.getErrorMessages().isEmpty()}">
Added: lenya/trunk/src/webapp/lenya/usecases/edit/forms/oneform.jx
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/usecases/edit/forms/oneform.jx?view=auto&rev=161126
==============================================================================
--- lenya/trunk/src/webapp/lenya/usecases/edit/forms/oneform.jx (added)
+++ lenya/trunk/src/webapp/lenya/usecases/edit/forms/oneform.jx Tue Apr 12 15:08:30 2005
@@ -0,0 +1,55 @@
+<page:page
+ xmlns:jx="http://apache.org/cocoon/templates/jx/1.0"
+ xmlns:page="http://apache.org/cocoon/lenya/cms-page/1.0"
+ xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:i18n="http://apache.org/cocoon/i18n/2.1"
+ xmlns:cinclude="http://apache.org/cocoon/include/1.0"
+ >
+
+ <page:title><i18n:text>Edit</i18n:text></page:title>
+ <page:body>
+
+ <jx:import uri="templates/messages.jx"/>
+
+ <form method="post">
+ <input type="hidden" name="lenya.continuation" value="${continuation.id}"/>
+ <input type="hidden" name="lenya.usecase" value="${usecase.getName()}"/>
+ <jx:choose>
+ <jx:when test="${usecase.getErrorMessages().isEmpty()}">
+
+ <div class="lenya-box">
+ <div class="lenya-box-title">Information</div>
+ <div class="lenya-box-body">
+ <table class="lenya-table-noborder">
+ <tr>
+ <td class="lenya-entry-caption">Document:</td>
+ <td><jx:out value="${usecase.getParameter('document').getId()}"/></td>
+ </tr>
+ <tr>
+ <td class="lenya-entry-caption">Workflow Event:</td>
+ <jx:set var="event" value="${request.getParameter('lenya.event')}"/>
+ <jx:choose>
+ <jx:when test="${event.equals('') || event.equals('null')}">
+ <td>No workflow event specified</td>
+ </jx:when>
+ <jx:otherwise>
+ <td><jx:out value="${event}"/></td>
+ </jx:otherwise>
+ </jx:choose>
+ </tr>
+ </table>
+ </div>
+ </div>
+
+ <cinclude:includexml>
+ <cinclude:src>cocoon://core/edit/oneform</cinclude:src>
+ </cinclude:includexml>
+ </jx:when>
+ <jx:otherwise>
+ <input type="submit" name="cancel" value="Cancel"/>
+ </jx:otherwise>
+ </jx:choose>
+ </form>
+
+ </page:body>
+</page:page>
\ No newline at end of file
Added: lenya/trunk/src/webapp/lenya/usecases/edit/forms/oneform.xsl
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/usecases/edit/forms/oneform.xsl?view=auto&rev=161126
==============================================================================
--- lenya/trunk/src/webapp/lenya/usecases/edit/forms/oneform.xsl (added)
+++ lenya/trunk/src/webapp/lenya/usecases/edit/forms/oneform.xsl Tue Apr 12 15:08:30 2005
@@ -0,0 +1,76 @@
+<?xml version="1.0"?>
+<!--
+ 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: oneform.xsl 42908 2004-04-26 14:57:25Z michi $ -->
+
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:page="http://apache.org/cocoon/lenya/cms-page/1.0"
+ xmlns:i18n="http://apache.org/cocoon/i18n/2.1"
+ >
+
+ <xsl:output indent="no" />
+ <xsl:param name="docid" />
+ <xsl:param name="language" />
+
+ <xsl:include href="copy-mixed-content.xsl" />
+
+ <xsl:template match="/">
+ <div>
+ <div class="lenya-box">
+ <div class="lenya-box-title">
+ <a href="http://www.w3.org/TR/REC-xml#syntax">Predefined Entities</a>
+ </div>
+ <div class="lenya-box-body">
+ <ul>
+ <li>&lt; instead of < (left angle bracket <strong>must</strong> be escaped)</li>
+ <li>&amp; instead of & (ampersand <strong>must</strong> be escaped)</li>
+ <li>&gt; instead of > (right angle bracket)</li>
+ <li>&apos; instead of ' (single-quote)</li>
+ <li>&quot; instead of " (double-quote)</li>
+ </ul>
+ </div>
+ </div>
+ <div class="lenya-box">
+ <div class="lenya-box-body">
+ <input type="hidden" name="namespaces"><xsl:attribute name="value"><xsl:apply-templates mode="namespaces" /></xsl:attribute></input>
+ <table border="0">
+ <tr>
+ <td align="right">
+ <input type="submit" value="Save" name="submit" />
+ <input type="submit" value="Cancel" name="cancel" />
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <textarea name="content" cols="120" rows="80">
+ <xsl:apply-templates mode="mixedcontent" />
+ </textarea>
+ </td>
+ </tr>
+ <tr>
+ <td align="right">
+ <input type="submit" value="Save" name="submit" />
+ <input type="submit" value="Cancel" name="cancel" />
+ </td>
+ </tr>
+ </table>
+ </div>
+ </div>
+ </div>
+ </xsl:template>
+</xsl:stylesheet>
Modified: lenya/trunk/src/webapp/lenya/usecases/edit/usecase.xmap
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/usecases/edit/usecase.xmap?view=diff&r1=161125&r2=161126
==============================================================================
--- lenya/trunk/src/webapp/lenya/usecases/edit/usecase.xmap (original)
+++ lenya/trunk/src/webapp/lenya/usecases/edit/usecase.xmap Tue Apr 12 15:08:30 2005
@@ -30,7 +30,7 @@
</global-variables>
</map:component-configurations>
- <map:pipeline>
+ <map:pipeline>
<map:match pattern="form/*/**">
<map:generate src="lenya://lenya/pubs/{page-envelope:publication-id}/content/authoring/{page-envelope:document-path}"/>
<map:select type="parameter">
@@ -53,6 +53,16 @@
</map:transform>
<map:serialize type="xml"/>
</map:match>
+
+ <map:match pattern="oneform">
+ <map:generate src="lenya://lenya/pubs/{page-envelope:publication-id}/content/authoring/{page-envelope:document-path}"/>
+ <map:transform src="fallback://lenya/usecases/edit/forms/oneform.xsl">
+ <map:parameter name="docid" value="{page-envelope:document-id}"/>
+ <map:parameter name="language" value="{page-envelope:document-language}"/>
+ </map:transform>
+ <map:serialize type="xml"/>
+ </map:match>
+
</map:pipeline>
</map:pipelines>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org