1 package org.apache.archiva.redback.struts2.checks;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import java.util.List;
25 import org.codehaus.plexus.util.StringUtils;
26 import org.apache.archiva.redback.integration.checks.xwork.XworkActionConfig;
27 import org.apache.archiva.redback.integration.checks.xwork.XworkPackageConfig;
29 import com.opensymphony.xwork2.config.Configuration;
30 import com.opensymphony.xwork2.config.entities.ActionConfig;
31 import com.opensymphony.xwork2.config.entities.PackageConfig;
34 * AbstractXworkConfigurationCheck
36 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
39 public class AbstractXworkConfigurationCheck
42 protected void checkAction( List<String> violations, XworkPackageConfig expectedPackage, XworkActionConfig expectedAction,
43 Map<?, ?> xwActionMap )
45 ActionConfig xwActionConfig = (ActionConfig) xwActionMap.get( expectedAction.name );
46 if ( xwActionConfig != null )
48 if ( StringUtils.isNotEmpty( expectedAction.clazz ) )
50 if ( !StringUtils.equals( expectedAction.clazz, xwActionConfig.getClassName() ) )
52 violations.add( "xwork.xml - Expected class attribute value of " + quote( expectedAction.clazz ) +
53 " but got " + quote( xwActionConfig.getClassName() ) + " instead, on action " +
54 quote( expectedAction.name ) + " in package " + quote( expectedPackage.name ) + "." );
58 if ( StringUtils.isNotEmpty( expectedAction.method ) )
60 if ( !StringUtils.equals( expectedAction.method, xwActionConfig.getMethodName() ) )
62 violations.add( "xwork.xml - Expected method attribute value of " + quote( expectedAction.method ) +
63 " but got " + quote( xwActionConfig.getMethodName() ) + " instead, on action " +
64 quote( expectedAction.name ) + " in package " + quote( expectedPackage.name ) + "." );
68 Map<?, ?> xwResultMap = xwActionConfig.getResults();
70 if ( expectedAction.results.isEmpty() )
72 // Check for single default result.
73 if ( xwResultMap.size() < 1 )
75 violations.add( "xwork.xml - Missing default result on action name " +
76 quote( expectedAction.name ) + " in package " + quote( expectedPackage.name ) + "." );
81 // Check for named result names.
82 for ( String resultName : expectedAction.results )
84 if ( xwResultMap.get( resultName ) == null )
86 violations.add( "xwork.xml - Missing named result " + quote( resultName ) + " in action " +
87 quote( expectedAction.name ) + " in package " + quote( expectedPackage.name ) + "." );
94 violations.add( "xwork.xml - Missing action named " + quote( expectedAction.name ) + " in package " +
95 quote( expectedPackage.name ) + "." );
99 protected void checkPackage( List<String> violations, XworkPackageConfig expectedPackage, Configuration xwConfig )
101 PackageConfig xwPackageConfig = findPackageNamespace( xwConfig, expectedPackage.name );
103 if ( xwPackageConfig != null )
105 Map<?, ?> xwActionMap = xwPackageConfig.getActionConfigs();
107 for ( XworkActionConfig expectedAction : expectedPackage.actions )
109 checkAction( violations, expectedPackage, expectedAction, xwActionMap );
114 violations.add( "Missing " + quote( expectedPackage.name ) + " package namespace in xwork.xml" );
118 @SuppressWarnings("unchecked")
119 protected PackageConfig findPackageNamespace( Configuration xwConfig, String name )
121 Map<?,PackageConfig> xwPackageConfigMap = xwConfig.getPackageConfigs();
123 for ( PackageConfig xwPackageConfig : xwPackageConfigMap.values() )
125 if ( StringUtils.equals( name, xwPackageConfig.getNamespace() ) )
127 return xwPackageConfig;
134 protected String quote( Object o )
140 return "\"" + o.toString() + "\"";