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 2007/04/17 17:57:18 UTC
svn commit: r529653 - in /lenya/trunk/src/modules/opendocument:
java/src/org/apache/lenya/cms/publication/
java/src/org/apache/lenya/cms/site/usecases/ resources/ resources/i18n/
usecases/
Author: andreas
Date: Tue Apr 17 08:57:17 2007
New Revision: 529653
URL: http://svn.apache.org/viewvc?view=rev&rev=529653
Log:
Use wrapper class to access ODTs, added some i18n to opendocument module
Added:
lenya/trunk/src/modules/opendocument/java/src/org/apache/lenya/cms/publication/
lenya/trunk/src/modules/opendocument/java/src/org/apache/lenya/cms/publication/OpenDocumentWrapper.java
lenya/trunk/src/modules/opendocument/resources/
lenya/trunk/src/modules/opendocument/resources/i18n/
lenya/trunk/src/modules/opendocument/resources/i18n/cmsui.xml
lenya/trunk/src/modules/opendocument/resources/i18n/cmsui_de.xml
Modified:
lenya/trunk/src/modules/opendocument/java/src/org/apache/lenya/cms/site/usecases/CreateOpenDocument.java
lenya/trunk/src/modules/opendocument/java/src/org/apache/lenya/cms/site/usecases/UploadOpenDocument.java
lenya/trunk/src/modules/opendocument/usecases/upload.jx
Added: lenya/trunk/src/modules/opendocument/java/src/org/apache/lenya/cms/publication/OpenDocumentWrapper.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/opendocument/java/src/org/apache/lenya/cms/publication/OpenDocumentWrapper.java?view=auto&rev=529653
==============================================================================
--- lenya/trunk/src/modules/opendocument/java/src/org/apache/lenya/cms/publication/OpenDocumentWrapper.java (added)
+++ lenya/trunk/src/modules/opendocument/java/src/org/apache/lenya/cms/publication/OpenDocumentWrapper.java Tue Apr 17 08:57:17 2007
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.publication;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.cocoon.servlet.multipart.Part;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.output.ByteArrayOutputStream;
+
+/**
+ * Wrapper class for the ODT resource type.
+ */
+public class OpenDocumentWrapper extends AbstractLogEnabled {
+
+ /**
+ * The extension for ODT documents.
+ */
+ public static final String ODT_EXTENSION = "odt";
+
+ /**
+ * The mime-type for ODT documents.
+ */
+ public static final String ODT_MIME_TYPE = "application/vnd.oasis.opendocument.text";
+
+ private Document delegate;
+
+ /**
+ * @param doc The document to wrap.
+ * @param logger The logger.
+ */
+ public OpenDocumentWrapper(Document doc, Logger logger) {
+ enableLogging(logger);
+ this.delegate = doc;
+ }
+
+ /**
+ * @param file The part to write.
+ */
+ public void write(Part file) {
+ if (!file.getMimeType().equals(ODT_MIME_TYPE)) {
+ throw new IllegalArgumentException("Invalid mime type: [" + file.getMimeType() + "]");
+ }
+ try {
+ write(file.getInputStream());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Writes the content of the resource.
+ * @param inputStream The input stream providing the content.
+ */
+ public void write(InputStream inputStream) {
+ final ByteArrayOutputStream sourceBos = new ByteArrayOutputStream();
+
+ OutputStream destOutputStream = null;
+ try {
+
+ IOUtils.copy(inputStream, sourceBos);
+
+ destOutputStream = delegate.getOutputStream();
+ IOUtils.write(sourceBos.toByteArray(), destOutputStream);
+
+ delegate.setMimeType(ODT_MIME_TYPE);
+
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ if (destOutputStream != null) {
+ try {
+ destOutputStream.flush();
+ destOutputStream.close();
+ } catch (Exception ignore) {
+ }
+ }
+ }
+
+ }
+
+}
Modified: lenya/trunk/src/modules/opendocument/java/src/org/apache/lenya/cms/site/usecases/CreateOpenDocument.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/opendocument/java/src/org/apache/lenya/cms/site/usecases/CreateOpenDocument.java?view=diff&rev=529653&r1=529652&r2=529653
==============================================================================
--- lenya/trunk/src/modules/opendocument/java/src/org/apache/lenya/cms/site/usecases/CreateOpenDocument.java (original)
+++ lenya/trunk/src/modules/opendocument/java/src/org/apache/lenya/cms/site/usecases/CreateOpenDocument.java Tue Apr 17 08:57:17 2007
@@ -17,6 +17,8 @@
*/
package org.apache.lenya.cms.site.usecases;
+import org.apache.lenya.cms.publication.OpenDocumentWrapper;
+
/**
* Usecase to create a document.
@@ -25,10 +27,8 @@
*/
public class CreateOpenDocument extends CreateDocument {
- protected static final String ODT_EXTENSION = "odt";
-
-
protected String getSourceExtension() {
- return ODT_EXTENSION;
+ String extension = OpenDocumentWrapper.ODT_EXTENSION;
+ return extension;
}
}
Modified: lenya/trunk/src/modules/opendocument/java/src/org/apache/lenya/cms/site/usecases/UploadOpenDocument.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/opendocument/java/src/org/apache/lenya/cms/site/usecases/UploadOpenDocument.java?view=diff&rev=529653&r1=529652&r2=529653
==============================================================================
--- lenya/trunk/src/modules/opendocument/java/src/org/apache/lenya/cms/site/usecases/UploadOpenDocument.java (original)
+++ lenya/trunk/src/modules/opendocument/java/src/org/apache/lenya/cms/site/usecases/UploadOpenDocument.java Tue Apr 17 08:57:17 2007
@@ -17,13 +17,8 @@
*/
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.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.OpenDocumentWrapper;
import org.apache.lenya.cms.usecase.DocumentUsecase;
/**
@@ -33,76 +28,32 @@
*/
public class UploadOpenDocument extends DocumentUsecase {
- protected static final String ODT_EXTENSION = ".odt";
-
- protected static final String ODT_MIME_TYPE = "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 source = getSourceDocument();
-
+ protected void doCheckExecutionConditions() throws Exception {
+ super.doCheckExecutionConditions();
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_TYPE.equals(mimeType)) {
- saveResource(source.getOutputStream(), file);
+ if (file == null) {
+ addErrorMessage("missing-file");
} else {
- addErrorMessage("The mime type of the document you want to upload does not match the mime type: \""
- + ODT_MIME_TYPE + "\"");
+ if (file.isRejected()) {
+ String[] params = { Integer.toString(file.getSize()) };
+ addErrorMessage("upload-size-exceeded", params);
+ } else {
+ String mimeType = file.getMimeType();
+ if (!OpenDocumentWrapper.ODT_MIME_TYPE.equals(mimeType)) {
+ String[] params = { mimeType, OpenDocumentWrapper.ODT_MIME_TYPE };
+ addErrorMessage("wrong-mime-type", params);
+ }
+ }
}
}
/**
- * Saves the resource to a file.
- *
- * @param out The destination to write the file.
- * @param part The part of the multipart request.
- * @throws IOException if an error occurs.
+ * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
*/
- protected void saveResource(OutputStream out, Part part) throws IOException {
- InputStream in = null;
-
- try {
- byte[] buf = new byte[4096];
- 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();
- }
- }
+ protected void doExecute() throws Exception {
+ OpenDocumentWrapper odt = new OpenDocumentWrapper(getSourceDocument(), getLogger());
+ Part file = getPart("file");
+ odt.write(file);
}
}
Added: lenya/trunk/src/modules/opendocument/resources/i18n/cmsui.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/opendocument/resources/i18n/cmsui.xml?view=auto&rev=529653
==============================================================================
--- lenya/trunk/src/modules/opendocument/resources/i18n/cmsui.xml (added)
+++ lenya/trunk/src/modules/opendocument/resources/i18n/cmsui.xml Tue Apr 17 08:57:17 2007
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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: cmsui.xml 446542 2006-09-15 08:14:39Z andreas $ -->
+
+<catalogue xml:lang="en" xmlns:xhtml="http://www.w3.org/1999/xhtml">
+
+ <message key="Upload ODT">Upload ODT</message>
+ <message key="Download ODT">Download ODT</message>
+ <message key="Upload ODT File">Upload ODT File</message>
+ <message key="Warning">Warning</message>
+ <message key="document-will-be-overwritten">The existing document will be overwritten!</message>
+ <message key="missing-file">Please select a file.</message>
+ <message key="wrong-mime-type">
+ The mime type of the document you want to upload ("{0}") does not match the required mime type "{1}"
+ </message>
+
+</catalogue>
Added: lenya/trunk/src/modules/opendocument/resources/i18n/cmsui_de.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/opendocument/resources/i18n/cmsui_de.xml?view=auto&rev=529653
==============================================================================
--- lenya/trunk/src/modules/opendocument/resources/i18n/cmsui_de.xml (added)
+++ lenya/trunk/src/modules/opendocument/resources/i18n/cmsui_de.xml Tue Apr 17 08:57:17 2007
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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: cmsui_de.xml 446542 2006-09-15 08:14:39Z andreas $ -->
+
+<catalogue xml:lang="de" xmlns:xhtml="http://www.w3.org/1999/xhtml">
+
+ <message key="Upload ODT">ODT hochladen</message>
+ <message key="Download ODT">ODT herunterladen</message>
+ <message key="Upload ODT File">ODT-Datei hochladen</message>
+ <message key="Warning">Warnung</message>
+ <message key="document-will-be-overwritten">Das existierende Dokument wird überschrieben!</message>
+ <message key="missing-file">Bitte wählen Sie eine Datei.</message>
+ <message key="wrong-mime-type">
+ Der Mime-Type der Datei, die Sie hochladen möchten ("{0}"), entspricht nicht dem
+ benötigten Mime-Type "{1}"
+ </message>
+
+</catalogue>
+
Modified: lenya/trunk/src/modules/opendocument/usecases/upload.jx
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/opendocument/usecases/upload.jx?view=diff&rev=529653&r1=529652&r2=529653
==============================================================================
--- lenya/trunk/src/modules/opendocument/usecases/upload.jx (original)
+++ lenya/trunk/src/modules/opendocument/usecases/upload.jx Tue Apr 17 08:57:17 2007
@@ -28,6 +28,7 @@
</page:title>
<page:body>
+ <div class="lenya-box">
<div class="lenya-box-title">
<i18n:text>Upload ODT File</i18n:text>
</div>
@@ -42,14 +43,14 @@
</td>
</tr>
<tr>
- <td colspan="2">
- <strong><i18n:text>HEADSUP:</i18n:text> <i18n:text>The existing document will be overwritten!</i18n:text></strong>
+ <td colspan="2" style="padding-bottom: 2em;">
+ <strong><i18n:text>Warning</i18n:text>:</strong> <i18n:text>document-will-be-overwritten</i18n:text>
</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>
+ <td><input type="file" name="file" class="lenya-form-element" size="50"/></td>
</tr>
<tr>
<td class="lenya-entry-caption">*
@@ -59,12 +60,13 @@
<tr>
<td/>
<td>
- <input i18n:attr="value" name="submit" type="submit"
- value="Upload ODT"/>
+ <input i18n:attr="value" name="submit" type="submit" value="Upload ODT"/>
+ <input i18n:attr="value" name="cancel" type="submit" value="Cancel"/>
</td>
</tr>
</table>
</form>
+ </div>
</div>
</page:body>
</page:page>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org