summaryrefslogtreecommitdiffstats
path: root/sandbox/thilina/geronimo_ACE/src/main/java/org/apache/tuscany/geronimoace/GeronimoACE.java
blob: f7cb2d72cc30b5dde37582a35ddc4e69a932460b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.apache.tuscany.geronimoace;

import javax.portlet.*;
import java.io.IOException;

public class GeronimoACE extends GenericPortlet {
    private String viewUrl = "/pages/Home.jsp";       // viewUrl is set to the home page by default
    boolean isHome = true;       // used for navigating back to the home page.


    public void init(PortletConfig config) throws PortletException {
        super.init(config);
        config.getPortletContext().setAttribute("managenodes", new ManageNodes());

    }

    public void manageStandaloneNode(String loc, String nodeName, String composite) {

        /*SCANode2Factory factory = org.apache.tuscany.sca.node.SCANode2Factory.newInstance();
        SCAContribution contribution = new SCAContribution(nodeName, "file:"+loc);
        SCANode2 node = factory.createSCANode(composite, new SCAContribution[] {contribution});
                        
        node.start(); */
        ManageNodes manager = (ManageNodes) this.getPortletContext().getAttribute("managenodes");
        manager.serviceRequest(loc, nodeName, composite);
        this.getPortletContext().setAttribute("managenodes", manager);

    }

    public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException {
        isHome = true;
        String task = request.getParameter("task");                  // getting request parameters task and domain name
        String location = request.getParameter("contributionLocation");
        String nodeName = request.getParameter("nodeName");
        String composite = request.getParameter("composite");


        if (task != null) {
            if (task.equals("composites")) {       // if the request is for Composites,forwarding to Composites.html
                viewUrl = "/pages/Composite.jsp";
                System.out.println("sys:" + this.getPortletContext().getAttribute("test"));
            }
            if (task.equals("StandaloneNode")) {       // if the request is for Composites,forwarding to Composites.html
                viewUrl = "/pages/Standalone.jsp";
            }
            if (task.equals("workspace")) {       // if the request is for Contributions,forwarding to workspace.html
                viewUrl = "/pages/Workspace.jsp";
            }
            if (task.equals("cloud")) {       // if the request is for Clouds,forwarding to Cloud.html
                viewUrl = "/pages/Cloud.jsp";
                this.getPortletContext().setAttribute("test", "hello");

            }
            if (task.equals("files")) {       // iif the request is for Files,forwarding to Files.html
                viewUrl = "/pages/Files.jsp";
            }
        }
        if (location != null) {
            manageStandaloneNode(location, nodeName, composite);
        }

        response.setPortletMode(PortletMode.VIEW); // by changing portlet mode, doview methos is called again.


    }

    public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
        // Set the response to read HTML
        response.setContentType("text/html;charset=UTF-8");

        if (isHome) {
            // dispatching to the appropriate page
            PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher(viewUrl);
            dispatcher.include(request, response);
            isHome = false;
        } else {
            // dispatching to the home page.
            PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher("/pages/Home.jsp");
            dispatcher.include(request, response);
            isHome = true;
        }
    }

}