summaryrefslogtreecommitdiffstats
path: root/sandbox/thilina/geronimo_ACE/src/main/java/org/apache/tuscany/geronimoace/GeronimoACE.java
blob: 3eb5b82ed3b3011aef56a791eecf985e63f7d69f (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
/*
 * 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);
    }

    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 domain = request.getParameter("domainName");
        if (task != null) {
            if (task.equals("composites")) {       // if the request is for Composites,forwarding to Composites.html
                viewUrl = "/pages/Composite.html";
            }
            if (task.equals("workspace")) {       // if the request is for Contributions,forwarding to workspace.html
                viewUrl = "/pages/Workspace.html";
            }
            if (task.equals("cloud")) {       // if the request is for Clouds,forwarding to Cloud.html
                viewUrl = "/pages/Cloud.html";
            }
            if (task.equals("files")) {       // iif the request is for Files,forwarding to Files.html
                viewUrl = "/pages/Files.html";
            }
        }

        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;
        }
    }

}