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.Publication;
23: import org.apache.lenya.cms.publication.ResourceWrapper;
24: import org.apache.lenya.cms.workflow.usecases.InvokeWorkflow;
25: import org.apache.lenya.util.ServletHelper;
26:
27: /**
28: * Usecase to upload a resource.
29: *
30: */
31: public class UploadResource extends InvokeWorkflow {
32:
33: protected void doCheckPreconditions() throws Exception {
34: super .doCheckPreconditions();
35: if (!ServletHelper.isUploadEnabled(manager)) {
36: addErrorMessage("Upload is not enabled. Please check local.build.properties!");
37: }
38: Document doc = getSourceDocument();
39: if (!doc.getArea().equals(Publication.AUTHORING_AREA)) {
40: addErrorMessage("This usecase can only be invoked in the authoring area!");
41: }
42: }
43:
44: protected void doCheckExecutionConditions() throws Exception {
45: super .doCheckExecutionConditions();
46: Part file = getPart("file");
47: if (file.isRejected()) {
48: String[] params = { Integer.toString(file.getSize()) };
49: addErrorMessage("upload-size-exceeded", params);
50: }
51: }
52:
53: /**
54: * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
55: */
56: protected void doExecute() throws Exception {
57: super .doExecute();
58: Part file = getPart("file");
59: Document document = getSourceDocument();
60: ResourceWrapper wrapper = new ResourceWrapper(document,
61: this.manager, getLogger());
62: wrapper.write(file);
63: }
64:
65: }
|