View Javadoc

1   package org.apache.maven.continuum.web.view.jsp.ui;
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 org.apache.maven.continuum.Continuum;
23  import org.codehaus.plexus.spring.PlexusToSpringUtils;
24  import org.springframework.context.ApplicationContext;
25  import org.springframework.web.context.support.WebApplicationContextUtils;
26  
27  import javax.servlet.jsp.JspTagException;
28  import javax.servlet.jsp.jstl.core.ConditionalTagSupport;
29  
30  /**
31   * ifBuildTypeEnabledTag:
32   *
33   * @author Jan Ancajas <jansquared@gmail.com>
34   * @version $Id: IfBuildTypeEnabledTag.java
35   */
36  public class IfBuildTypeEnabledTag
37      extends ConditionalTagSupport
38  {
39      private Continuum continuum;
40  
41      private String buildType;
42  
43      public static final String DISTRIBUTED = "distributed";
44  
45      protected boolean condition()
46          throws JspTagException
47      {
48  
49          ApplicationContext applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(
50              pageContext.getServletContext() );
51          this.setContinuum( (Continuum) applicationContext.getBean( PlexusToSpringUtils.buildSpringId( Continuum.ROLE,
52                                                                                                        "default" ) ) );
53  
54          if ( continuum == null )
55          {
56              throw new JspTagException( "cannot lookup component:  " + Continuum.ROLE );
57          }
58  
59          if ( DISTRIBUTED.equals( buildType ) )
60          {
61              return continuum.getConfiguration().isDistributedBuildEnabled();
62          }
63  
64          // left out 'parallel' buildType checking for cyclomatic complexity's sake :)
65          return !continuum.getConfiguration().isDistributedBuildEnabled();
66  
67      }
68  
69      public String getBuildType()
70      {
71          return buildType;
72      }
73  
74      public void setBuildType( String buildType )
75      {
76          this.buildType = buildType;
77      }
78  
79      public Continuum getContinuum()
80      {
81          return continuum;
82      }
83  
84      public void setContinuum( Continuum continuum )
85      {
86          this.continuum = continuum;
87      }
88  }