01: /*
02: * Copyright 2007 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.outerj.daisy.emailnotifier.serverimpl.httphandlers;
17:
18: import org.outerj.daisy.httpconnector.spi.HttpUtil;
19: import org.outerj.daisy.httpconnector.spi.RequestHandlerSupport;
20: import org.outerj.daisy.repository.Repository;
21: import org.outerj.daisy.repository.VariantKey;
22: import org.outerj.daisy.emailnotifier.EmailSubscriptionManager;
23: import org.outerj.daisy.util.HttpConstants;
24: import org.outerx.daisy.x10.SubscribedDocument;
25:
26: import javax.servlet.http.HttpServletRequest;
27: import javax.servlet.http.HttpServletResponse;
28: import java.util.Map;
29:
30: public class DocumentSubscriptionForUserHandler extends
31: AbstractSubscriptionRequestHandler {
32: public void handleRequest(Map matchMap, HttpServletRequest request,
33: HttpServletResponse response, Repository repository,
34: RequestHandlerSupport support) throws Exception {
35: EmailSubscriptionManager subscriptionManager = (EmailSubscriptionManager) repository
36: .getExtension("EmailSubscriptionManager");
37: if (request.getMethod().equals("GET")) {
38: String documentId = (String) matchMap.get("1");
39: long branchId = HttpUtil.getLongParam(request, "branch");
40: long languageId = HttpUtil
41: .getLongParam(request, "language");
42: long userId = HttpUtil.parseId("user", (String) matchMap
43: .get("2"));
44: boolean isSubscribed = subscriptionManager.isSubsribed(
45: userId, new VariantKey(documentId, branchId,
46: languageId));
47: SubscribedDocument subscribedDocument = SubscribedDocument.Factory
48: .newInstance();
49: subscribedDocument.setSubscribed(isSubscribed);
50: subscribedDocument.save(response.getOutputStream());
51: } else {
52: response.sendError(HttpConstants._405_Method_Not_Allowed);
53: }
54: }
55:
56: public String getPathPattern() {
57: return "/documentSubscription/*/*";
58: }
59: }
|