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.editors;
19:
20: import java.util.HashMap;
21: import java.util.Iterator;
22: import java.util.List;
23: import java.util.Map;
24:
25: import org.apache.lenya.cms.usecase.DocumentUsecase;
26: import org.apache.lenya.cms.usecase.UsecaseInvoker;
27: import org.apache.lenya.cms.usecase.UsecaseMessage;
28: import org.apache.lenya.util.Assert;
29:
30: /**
31: * <p>
32: * This usecase saves the document from the request stream <em>before</em> the
33: * view is displayed using the {@link EditDocument} usecase. That's kind of a
34: * hack, since it violates the standard usecase principle, but it is very
35: * convenient because you can save and re-load the document without a redirect.
36: * </p>
37: *
38: * @version $Id: EditDocument.java 495324 2007-01-11 18:44:04Z andreas $
39: */
40: public class SaveDocument extends DocumentUsecase {
41:
42: protected static final String USECASE_NAME = "usecaseName";
43:
44: protected void doCheckPreconditions() throws Exception {
45: super .doCheckPreconditions();
46:
47: String usecase = getParameterAsString(USECASE_NAME);
48: Assert.notNull("usecase", usecase);
49:
50: UsecaseInvoker invoker = null;
51: try {
52: invoker = (UsecaseInvoker) this .manager
53: .lookup(UsecaseInvoker.ROLE);
54: Map params = new HashMap();
55: params.put(EditDocument.SOURCE_URI,
56: getParameter(EditDocument.SOURCE_URI));
57: params.put(EditDocument.EVENT,
58: getParameter(EditDocument.EVENT));
59: invoker.invoke(getSourceURL(), usecase, params);
60:
61: if (invoker.getResult() != UsecaseInvoker.SUCCESS) {
62: List messages = invoker.getErrorMessages();
63: for (Iterator i = messages.iterator(); i.hasNext();) {
64: UsecaseMessage message = (UsecaseMessage) i.next();
65: addErrorMessage(message.getMessage(), message
66: .getParameters());
67: }
68: }
69: } finally {
70: if (invoker != null) {
71: this.manager.release(invoker);
72: }
73: }
74:
75: }
76:
77: }
|