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.inbox.usecases;
19:
20: import org.apache.lenya.ac.User;
21: import org.apache.lenya.cms.usecase.AbstractUsecase;
22: import org.apache.lenya.inbox.InboxManager;
23: import org.apache.lenya.inbox.InboxMessage;
24:
25: /**
26: * Show and manage an inbox.
27: */
28: public class Inbox extends AbstractUsecase {
29:
30: protected void initParameters() {
31: super .initParameters();
32:
33: User user = getSession().getIdentity().getUser();
34: setParameter("user", user);
35:
36: InboxManager inboxManager = null;
37: try {
38: inboxManager = (InboxManager) this .manager
39: .lookup(InboxManager.ROLE);
40: org.apache.lenya.inbox.Inbox inbox = inboxManager
41: .getInbox(user);
42: setParameter("inbox", inbox);
43: } catch (Exception e) {
44: throw new RuntimeException(e);
45: } finally {
46: if (inboxManager != null) {
47: this .manager.release(inboxManager);
48: }
49: }
50: }
51:
52: protected void doCheckPreconditions() throws Exception {
53: super .doCheckPreconditions();
54:
55: String id = getParameterAsString("messageId");
56: if (id != null) {
57: org.apache.lenya.inbox.Inbox inbox = (org.apache.lenya.inbox.Inbox) getParameter("inbox");
58: InboxMessage message = inbox.getMessage(id);
59: message.markAsRead(true);
60: }
61:
62: }
63:
64: protected void doExecute() throws Exception {
65: super .doExecute();
66:
67: String deleteId = getParameterAsString("deleteMessageId");
68: if (deleteId != null) {
69: org.apache.lenya.inbox.Inbox inbox = (org.apache.lenya.inbox.Inbox) getParameter("inbox");
70: InboxMessage message = inbox.getMessage(deleteId);
71: inbox.remove(message);
72: }
73: }
74:
75: }
|