You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by th...@apache.org on 2006/03/08 17:51:04 UTC
svn commit: r384267 - in /lenya/trunk/src/modules/opendocument:
config/cocoon-xconf/usecase-upload-odt.xconf config/menus/opendocument.xsp
java/src/org/apache/lenya/cms/site/usecases/UploadOpenDocument.java
usecases/upload.jx
Author: thorsten
Date: Wed Mar 8 08:51:02 2006
New Revision: 384267
URL: http://svn.apache.org/viewcvs?rev=384267&view=rev
Log:
Added new usecase for the opendocument module.
You can now upload opendocuments to already existing odt docs in lenya.
This will replace the existing document.
Added:
lenya/trunk/src/modules/opendocument/config/cocoon-xconf/usecase-upload-odt.xconf (with props)
lenya/trunk/src/modules/opendocument/java/src/org/apache/lenya/cms/site/usecases/UploadOpenDocument.java (with props)
lenya/trunk/src/modules/opendocument/usecases/upload.jx
Modified:
lenya/trunk/src/modules/opendocument/config/menus/opendocument.xsp
Added: lenya/trunk/src/modules/opendocument/config/cocoon-xconf/usecase-upload-odt.xconf
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/opendocument/config/cocoon-xconf/usecase-upload-odt.xconf?rev=384267&view=auto
==============================================================================
--- lenya/trunk/src/modules/opendocument/config/cocoon-xconf/usecase-upload-odt.xconf (added)
+++ lenya/trunk/src/modules/opendocument/config/cocoon-xconf/usecase-upload-odt.xconf Wed Mar 8 08:51:02 2006
@@ -0,0 +1,27 @@
+<?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: usecase-create-metadata.xconf 7081 2005-11-11 13:04:23Z felix $ -->
+
+<xconf xpath="/cocoon/usecases" unless="/cocoon/usecases/component-instance[@name = 'module.odt.upload']">
+
+ <component-instance name="module.odt.upload" logger="lenya.module.odt"
+ class="org.apache.lenya.cms.site.usecases.UploadOpenDocument">
+ <view template="modules/opendocument/usecases/upload.jx"/>
+ </component-instance>
+
+</xconf>
Propchange: lenya/trunk/src/modules/opendocument/config/cocoon-xconf/usecase-upload-odt.xconf
------------------------------------------------------------------------------
svn:eol-style = native
Modified: lenya/trunk/src/modules/opendocument/config/menus/opendocument.xsp
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/opendocument/config/menus/opendocument.xsp?rev=384267&r1=384266&r2=384267&view=diff
==============================================================================
--- lenya/trunk/src/modules/opendocument/config/menus/opendocument.xsp (original)
+++ lenya/trunk/src/modules/opendocument/config/menus/opendocument.xsp Wed Mar 8 08:51:02 2006
@@ -43,19 +43,19 @@
<item uc:usecase="module.odt.create" href="?doctype=opendocument"><i18n:text>New ODT</i18n:text></item>
</block>
</menu>
- <!--<menu i18n:attr="name" name="Edit">
+ <menu i18n:attr="name" name="Edit">
<xsp:logic>
String doctype = <input:get-attribute module="page-envelope" as="string" name="document-type"/>;
if ("opendocument".equals(doctype)) {
- <block info="false">
+ <!--<block info="false">
<item wf:event="edit" uc:usecase="module.odt.download" href="?"><i18n:text>Download ODT</i18n:text></item>
- </block>
+ </block>-->
<block info="false">
<item wf:event="edit" uc:usecase="module.odt.upload" href="?"><i18n:text>Upload ODT</i18n:text></item>
</block>
}
</xsp:logic>
- </menu>-->
+ </menu>
</menus>
Added: lenya/trunk/src/modules/opendocument/java/src/org/apache/lenya/cms/site/usecases/UploadOpenDocument.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/opendocument/java/src/org/apache/lenya/cms/site/usecases/UploadOpenDocument.java?rev=384267&view=auto
==============================================================================
--- lenya/trunk/src/modules/opendocument/java/src/org/apache/lenya/cms/site/usecases/UploadOpenDocument.java (added)
+++ lenya/trunk/src/modules/opendocument/java/src/org/apache/lenya/cms/site/usecases/UploadOpenDocument.java Wed Mar 8 08:51:02 2006
@@ -0,0 +1,168 @@
+/*
+ * Copyright 1999-2005 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.site.usecases;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.cocoon.servlet.multipart.Part;
+import org.apache.excalibur.source.ModifiableSource;
+import org.apache.excalibur.source.SourceResolver;
+import org.apache.lenya.cms.cocoon.source.RepositorySource;
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.repository.Node;
+import org.apache.lenya.cms.usecase.DocumentUsecase;
+
+/**
+ * Usecase to create a document.
+ *
+ * @version $Id: CreateDocument.java 379098 2006-02-20 11:35:10Z andreas $
+ */
+public class UploadOpenDocument extends DocumentUsecase {
+
+ protected static final String PARENT_ID = "parentId";
+
+ protected static final String ODT_EXTENSION = ".odt";
+
+ protected static final String DEFAULT_INDEX = "index";
+
+ protected static final String ODT_MIME = "application/vnd.oasis.opendocument.text";
+
+ /**
+ * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
+ */
+ protected void initParameters() {
+ super.initParameters();
+ }
+
+ /**
+ * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
+ */
+ protected void doExecute() throws Exception {
+ if (getLogger().isDebugEnabled())
+ getLogger().debug("ODT::uploadODT() called");
+ Document parent = getSourceDocument();
+ String sourceURI = parent.getSourceURI();
+ String destination = sourceURI.substring(0, sourceURI
+ .lastIndexOf(".xml"))
+ + ODT_EXTENSION;
+
+ Part file = getPart("file");
+ String mimeType = file.getMimeType();
+
+ if (file.isRejected()) {
+ String[] params = { Integer.toString(file.getSize()) };
+ addErrorMessage("upload-size-exceeded", params);
+ } else if (ODT_MIME.equals(mimeType)){
+ saveResource(destination, file);
+ } else {
+ addErrorMessage("The mime type of the document you want to upload does not match the mime type: \""+ODT_MIME+"\"");
+ }
+
+ }
+
+ /**
+ * Saves the resource to a file.
+ *
+ * @param destination
+ * The destination to write the file.
+ * @param part
+ * The part of the multipart request.
+ * @throws IOException
+ * if an error occurs.
+ */
+ protected void saveResource(String destination, Part part)
+ throws IOException {
+ OutputStream out = null;
+ InputStream in = null;
+
+ SourceResolver resolver = null;
+ ModifiableSource source = null;
+
+ try {
+ resolver = (SourceResolver) this.manager
+ .lookup(SourceResolver.ROLE);
+ source = (ModifiableSource) resolver.resolveURI(destination);
+ // now that the source is determined, lock involved nodes
+ Node node = getRepositoryNode(destination);
+ node.lock();
+
+ byte[] buf = new byte[4096];
+ out = source.getOutputStream();
+ in = part.getInputStream();
+ int read = in.read(buf);
+
+ while (read > 0) {
+ out.write(buf, 0, read);
+ read = in.read(buf);
+ }
+ } catch (final FileNotFoundException e) {
+ getLogger().error("file not found" + e.toString());
+ throw new IOException(e.toString());
+ } catch (IOException e) {
+ getLogger().error("IO error " + e.toString());
+ throw new IOException(e.toString());
+ } catch (Exception e) {
+ getLogger().error("Exception" + e.toString());
+ throw new IOException(e.toString());
+ } finally {
+ if (in != null) {
+ in.close();
+ }
+ if (out != null) {
+ out.flush();
+ out.close();
+ }
+
+ if (resolver != null) {
+ if (source != null) {
+ resolver.release(source);
+ }
+ this.manager.release(resolver);
+ }
+ }
+ }
+
+ /**
+ * @return The repository node that represents the document identified by the destination string.
+ */
+ public Node getRepositoryNode(String destination) {
+ Node node = null;
+ SourceResolver resolver = null;
+ RepositorySource documentSource = null;
+ try {
+ resolver = (SourceResolver) this.manager
+ .lookup(SourceResolver.ROLE);
+ documentSource = (RepositorySource) resolver
+ .resolveURI(destination);
+ node = documentSource.getNode();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ if (resolver != null) {
+ if (documentSource != null) {
+ resolver.release(documentSource);
+ }
+ this.manager.release(resolver);
+ }
+ }
+ return node;
+ }
+
+}
Propchange: lenya/trunk/src/modules/opendocument/java/src/org/apache/lenya/cms/site/usecases/UploadOpenDocument.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: lenya/trunk/src/modules/opendocument/usecases/upload.jx
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/opendocument/usecases/upload.jx?rev=384267&view=auto
==============================================================================
--- lenya/trunk/src/modules/opendocument/usecases/upload.jx (added)
+++ lenya/trunk/src/modules/opendocument/usecases/upload.jx Wed Mar 8 08:51:02 2006
@@ -0,0 +1,65 @@
+<?xml version="1.0"?>
+<!--
+Copyright 1999-2005 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: assets.jx 374391 2006-02-02 14:02:17Z andreas $ -->
+
+<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">
+
+ <page:body>
+ <div class="lenya-box-title">
+ <i18n:text>Upload odt</i18n:text>
+ </div>
+ <div class="lenya-box-body">
+ <form method="POST" enctype="multipart/form-data" id="form-upload">
+ <input type="hidden" name="lenya.usecase" value="${usecase.getName()}"/>
+ <input type="hidden" name="lenya.continuation" value="${continuation.id}"/>
+ <table class="lenya-table-noborder">
+ <tr>
+ <td colspan="2">
+ <jx:import uri="fallback://lenya/usecases/templates/messages.jx"/>
+ </td>
+ </tr>
+ <tr>
+ <td colspan="2">
+ <strong><i18n:text>HEADSUP:</i18n:text> <i18n:text>The existing document will be deleted!</i18n:text></strong>
+ </td>
+ </tr>
+ <tr>
+ <td class="lenya-entry-caption"><label for="file">
+ <i18n:text>File</i18n:text> *</label></td>
+ <td><input type="file" name="file" class="lenya-form-element"/></td>
+ </tr>
+ <tr>
+ <td class="lenya-entry-caption">*
+ <i18n:text>required fields</i18n:text>
+ </td>
+ </tr>
+ <tr>
+ <td/>
+ <td>
+ <input i18n:attr="value" name="submit" type="submit"
+ value="New Asset"/>
+ </td>
+ </tr>
+ </table>
+ </form>
+ </div>
+ </page:body>
+</page:page>
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org