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.workflow.serverimpl.httpconnector.handlers;
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.workflow.WorkflowManager;
22: import org.outerj.daisy.workflow.WfVariable;
23: import org.outerj.daisy.workflow.WfVersionKey;
24: import org.outerj.daisy.workflow.commonimpl.WfXmlHelper;
25: import org.outerj.daisy.util.HttpConstants;
26:
27: import javax.servlet.http.HttpServletRequest;
28: import javax.servlet.http.HttpServletResponse;
29: import java.util.Map;
30: import java.util.List;
31:
32: public class InitialVariablesHandler extends
33: AbstractWorkflowRequestHandler {
34: public void handleRequest(Map matchMap, HttpServletRequest request,
35: HttpServletResponse response, Repository repository,
36: RequestHandlerSupport support) throws Exception {
37: String id = (String) matchMap.get("1");
38: WorkflowManager workflowManager = (WorkflowManager) repository
39: .getExtension("WorkflowManager");
40:
41: if (request.getMethod().equals(HttpConstants.GET)) {
42: String docId = request.getParameter("contextDocId");
43: long branchId = HttpUtil.getBranchId(request, repository,
44: "contextDocBranch");
45: long languageId = HttpUtil.getLanguageId(request,
46: repository, "contextDocLanguage");
47: String version = request.getParameter("contextDocVersion");
48:
49: WfVersionKey contextDoc = null;
50: if (docId != null) {
51: contextDoc = new WfVersionKey(docId, branchId,
52: languageId, version);
53: }
54:
55: List<WfVariable> variables = workflowManager
56: .getInitialVariables(id, contextDoc);
57: WfXmlHelper.getVariablesAsXml(variables).save(
58: response.getOutputStream());
59: } else {
60: response.sendError(HttpConstants._405_Method_Not_Allowed);
61: }
62: }
63:
64: public String getPathPattern() {
65: return "/processDefinition/*/initialVariables";
66: }
67: }
|