01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.lenya.cms.site.usecases;
19:
20: import org.apache.cocoon.servlet.multipart.Part;
21: import org.apache.lenya.cms.publication.Document;
22: import org.apache.lenya.cms.publication.OpenDocumentWrapper;
23: import org.apache.lenya.cms.publication.Publication;
24: import org.apache.lenya.cms.workflow.usecases.InvokeWorkflow;
25: import org.apache.lenya.util.ServletHelper;
26:
27: /**
28: * Usecase to create a document.
29: *
30: * @version $Id: CreateDocument.java 379098 2006-02-20 11:35:10Z andreas $
31: */
32: public class UploadOpenDocument extends InvokeWorkflow {
33:
34: protected void doCheckPreconditions() throws Exception {
35: super .doCheckPreconditions();
36: if (!ServletHelper.isUploadEnabled(manager)) {
37: addErrorMessage("Upload is not enabled. Please check local.build.properties!");
38: }
39: Document doc = getSourceDocument();
40: if (!doc.getArea().equals(Publication.AUTHORING_AREA)) {
41: addErrorMessage("This usecase can only be invoked in the authoring area!");
42: }
43: }
44:
45: protected void doCheckExecutionConditions() throws Exception {
46: super .doCheckExecutionConditions();
47: Part file = getPart("file");
48: if (file == null) {
49: addErrorMessage("missing-file");
50: } else {
51: if (file.isRejected()) {
52: String[] params = { Integer.toString(file.getSize()) };
53: addErrorMessage("upload-size-exceeded", params);
54: } else {
55: String mimeType = file.getMimeType();
56: if (!OpenDocumentWrapper.ODT_MIME_TYPE.equals(mimeType)) {
57: String[] params = { mimeType,
58: OpenDocumentWrapper.ODT_MIME_TYPE };
59: addErrorMessage("wrong-mime-type", params);
60: }
61: }
62: }
63: }
64:
65: /**
66: * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
67: */
68: protected void doExecute() throws Exception {
69: super .doExecute();
70: OpenDocumentWrapper odt = new OpenDocumentWrapper(
71: getSourceDocument(), getLogger());
72: Part file = getPart("file");
73: odt.write(file);
74: }
75:
76: }
|