View Javadoc

1   package org.apache.maven.continuum.web.view;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import com.opensymphony.xwork2.ActionContext;
23  
24  import java.util.HashMap;
25  
26  import javax.servlet.http.HttpServletRequest;
27  import javax.servlet.http.HttpServletResponse;
28  import javax.servlet.jsp.PageContext;
29  
30  import org.apache.maven.continuum.security.ContinuumRoleConstants;
31  import org.apache.maven.continuum.web.model.ProjectSummary;
32  import org.apache.struts2.views.util.UrlHelper;
33  import org.codehaus.plexus.PlexusConstants;
34  import org.codehaus.plexus.PlexusContainer;
35  import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
36  import org.codehaus.plexus.redback.authorization.AuthorizationException;
37  import org.codehaus.plexus.redback.system.SecuritySession;
38  import org.codehaus.plexus.redback.system.SecuritySystem;
39  import org.codehaus.plexus.redback.system.SecuritySystemConstants;
40  import org.extremecomponents.table.bean.Column;
41  import org.extremecomponents.table.cell.DisplayCell;
42  import org.extremecomponents.table.core.TableModel;
43  
44  /**
45   * Used in Summary view
46   *
47   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
48   * @version $Id: BuildCell.java 765340 2009-04-15 20:22:00Z evenisse $
49   * @deprecated use of cells is discouraged due to lack of i18n and design in java code.
50   *             Use jsp:include instead.
51   */
52  public class BuildCell
53      extends DisplayCell
54  {
55      protected String getCellValue( TableModel tableModel, Column column )
56      {
57          ProjectSummary project = (ProjectSummary) tableModel.getCurrentRowBean();
58          String contextPath = tableModel.getContext().getContextPath();
59  
60          int buildNumber = project.getBuildNumber();
61  
62          String result = "<div align=\"center\">";
63  
64          if ( project.isInBuildingQueue() )
65          {
66              result +=
67                  "<img src=\"" + contextPath + "/images/inqueue.gif\" alt=\"In Queue\" title=\"In Queue\" border=\"0\">";
68          }
69          else if ( project.isInCheckoutQueue() )
70          {
71              result += "<img src=\"" + contextPath +
72                  "/images/checkingout.gif\" alt=\"Checking Out sources\" title=\"Checking Out sources\" border=\"0\">";
73          }
74          else
75          {
76              if ( project.getState() == 1 || project.getState() == 10 || project.getState() == 2 ||
77                  project.getState() == 3 || project.getState() == 4 )
78              {
79                  if ( buildNumber > 0 )
80                  {
81                      HashMap<String, Object> params = new HashMap<String, Object>();
82  
83                      params.put( "projectId", project.getId() );
84  
85                      params.put( "projectName", project.getName() );
86  
87                      params.put( "buildId", project.getBuildInSuccessId() );
88  
89                      params.put( "projectGroupId", project.getProjectGroupId() );
90  
91                      PageContext pageContext = (PageContext) tableModel.getContext().getContextObject();
92  
93                      HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
94  
95                      HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
96  
97                      String url = UrlHelper.buildUrl( "/buildResult.action", request, response, params );
98  
99                      if ( isAuthorized( project ) )
100                     {
101                         // we are authzd so act normally
102                         result += "<a href=\"" + url + "\">" + buildNumber + "</a>";
103                     }
104                     else
105                     {
106                         result += buildNumber;
107                     }
108                 }
109                 else
110                 {
111                     result += "&nbsp;";
112                 }
113             }
114             else if ( project.getState() == 6 )
115             {
116                 result += "<img src=\"" + contextPath +
117                     "/images/building.gif\" alt=\"Building\" title=\"Building\" border=\"0\">";
118             }
119             else if ( project.getState() == 7 )
120             {
121                 result += "<img src=\"" + contextPath +
122                     "/images/checkingout.gif\" alt=\"Checking Out sources\" title=\"Checking Out sources\" border=\"0\">";
123             }
124             else if ( project.getState() == 8 )
125             {
126                 result += "<img src=\"" + contextPath +
127                     "/images/checkingout.gif\" alt=\"Updating sources\" title=\"Updating sources\" border=\"0\">";
128             }
129             else
130             {
131                 result += "<img src=\"" + contextPath +
132                     "/images/inqueue.gif\" alt=\"In Queue\" title=\"In Queue\" border=\"0\">";
133             }
134         }
135 
136         return result + "</div>";
137     }
138 
139     private boolean isAuthorized( ProjectSummary project )
140     {
141         // do the authz bit
142         ActionContext context = ActionContext.getContext();
143 
144         PlexusContainer container = (PlexusContainer) context.getApplication().get( PlexusConstants.PLEXUS_KEY );
145         SecuritySession securitySession =
146             (SecuritySession) context.getSession().get( SecuritySystemConstants.SECURITY_SESSION_KEY );
147 
148         try
149         {
150             SecuritySystem securitySystem = (SecuritySystem) container.lookup( SecuritySystem.ROLE );
151 
152             if ( !securitySystem.isAuthorized( securitySession, ContinuumRoleConstants.CONTINUUM_VIEW_GROUP_OPERATION,
153                                                project.getProjectGroupName() ) )
154             {
155                 return false;
156             }
157         }
158         catch ( ComponentLookupException cle )
159         {
160             return false;
161         }
162         catch ( AuthorizationException ae )
163         {
164             return false;
165         }
166 
167         return true;
168     }
169 }