View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     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  
19  package org.apache.oodt.cas.curation.servlet;
20  
21  //OODT imports
22  import org.apache.oodt.cas.curation.policymgr.CurationPolicyManager;
23  import org.apache.oodt.cas.metadata.util.PathUtils;
24  
25  //JDK imports
26  import java.io.IOException;
27  import java.io.PrintWriter;
28  import javax.servlet.RequestDispatcher;
29  import javax.servlet.ServletConfig;
30  import javax.servlet.ServletException;
31  import javax.servlet.http.HttpServletRequest;
32  import javax.servlet.http.HttpServletResponse;
33  import javax.servlet.http.HttpSession;
34  
35  // Displays the contents of the staging area as an HTML unordered list (<ul></ul>): 
36  // This servlet is meant to be invoked via an AJAX call, the generated HTML output
37  // will be dynamically inserted into a DOM element on the requesting page.
38  //
39  
40  public class ShowExistingPoliciesServlet extends SSOConfiguredCuratorWebService {
41  
42    private String stagingAreaPath;
43    
44    private String policyDirPath;
45    
46    private static final long serialVersionUID = 4844652723865688280L;
47  
48    public ShowExistingPoliciesServlet() {
49    }
50  
51    public void init(ServletConfig conf) throws ServletException {
52      super.init(conf);
53      this.stagingAreaPath = PathUtils.replaceEnvVariables(getServletContext().getInitParameter(STAGING_AREA_PATH));
54      this.policyDirPath = PathUtils.replaceEnvVariables(getServletContext().getInitParameter(POLICY_UPLOAD_PATH));
55    }
56  
57    public void doPost(HttpServletRequest req, HttpServletResponse res)
58        throws ServletException, IOException {
59  
60      HttpSession session = req.getSession();
61      session.setAttribute("errorMsg", "You must use GET to access this page");
62      RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(
63          "/error.jsp");
64      dispatcher.forward(req, res);
65    }
66  
67    // Handle HTTP GET requests by forwarding to a common processor
68    public void doGet(HttpServletRequest req, HttpServletResponse res)
69        throws ServletException, IOException {
70  
71      this.configureSingleSignOn(req, res);
72  
73      // Redirect if no valid user logged in
74      if (!this.sso.isLoggedIn()) {
75        res.sendRedirect("/login.jsp?from=" + req.getRequestURL());
76        return;
77      }
78  
79      PrintWriter out = res.getWriter();
80      CurationPolicyManager pm = new CurationPolicyManager(this.policyDirPath, this.stagingAreaPath);
81      out.println(pm.getExistingPoliciesAsHTML());
82  
83      return;
84    }
85  }