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.modules.news.usecases;
19:
20: import java.util.ArrayList;
21: import java.util.List;
22:
23: import org.apache.lenya.cms.workflow.usecases.InvokeWorkflow;
24: import org.apache.lenya.modules.collection.CollectionWrapper;
25: import org.apache.lenya.modules.news.NewsWrapper;
26:
27: /**
28: * Edit the properties of a news document.
29: */
30: public class Edit extends InvokeWorkflow {
31:
32: protected static final String INCLUDE_ITEM_NUMBER = "includeItems";
33: protected static final String NEWS_WRAPPER = "newsWrapper";
34: protected static final String NUMBERS = "numbers";
35: protected static final String TYPE = "type";
36: protected static final String HREF = "href";
37:
38: protected void initParameters() {
39: super .initParameters();
40: NewsWrapper news = new NewsWrapper(getSourceDocument(),
41: getLogger());
42: setParameter(NEWS_WRAPPER, news);
43:
44: setParameter(INCLUDE_ITEM_NUMBER, new Short(news
45: .getIncludeItemNumber()));
46: setParameter(TYPE, news.getType());
47: setParameter(HREF, news.getHref());
48:
49: List numbers = new ArrayList();
50: for (int i = 1; i <= 10; i++) {
51: numbers.add(new Integer(i));
52: }
53: setParameter(NUMBERS, numbers);
54: }
55:
56: protected void doExecute() throws Exception {
57: super .doExecute();
58:
59: String numberString = getParameterAsString(INCLUDE_ITEM_NUMBER);
60: short number = Short.parseShort(numberString);
61:
62: // we must create a new wrapper, because a new (modifiable) session is used
63: NewsWrapper news = new NewsWrapper(getSourceDocument(),
64: getLogger());
65: news.setIncludeItemNumber(number);
66: String type = getParameterAsString(TYPE);
67: news.setType(type);
68: if (type.equals(CollectionWrapper.TYPE_LINK)) {
69: news.setHref(getParameterAsString(HREF));
70: }
71: news.save();
72: }
73:
74: }
|