From ebcabb17a35c53bc107f0d5ec07ff749f57d1bd3 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Tue, 4 Oct 2011 13:58:52 +0000 Subject: [PATCH] [MRM-1173] Cannot delete patterns with single and double quotes. git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1178794 13f79535-47bb-0310-9956-ffa450edef68 --- .../AbstractProxyConnectorFormAction.java | 168 +++++++++--------- .../jsp/admin/include/proxyConnectorForm.jspf | 14 +- 2 files changed, 92 insertions(+), 90 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/connectors/proxy/AbstractProxyConnectorFormAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/connectors/proxy/AbstractProxyConnectorFormAction.java index a59984200..19d454eb0 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/connectors/proxy/AbstractProxyConnectorFormAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/connectors/proxy/AbstractProxyConnectorFormAction.java @@ -24,11 +24,11 @@ import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.admin.model.beans.NetworkProxy; import org.apache.archiva.admin.model.beans.ProxyConnector; import org.apache.archiva.admin.model.networkproxy.NetworkProxyAdmin; -import org.apache.commons.lang.StringUtils; import org.apache.archiva.policies.DownloadErrorPolicy; import org.apache.archiva.policies.Policy; import org.apache.archiva.policies.PostDownloadPolicy; import org.apache.archiva.policies.PreDownloadPolicy; +import org.apache.commons.lang.StringUtils; import javax.annotation.PostConstruct; import javax.inject.Inject; @@ -102,9 +102,9 @@ public abstract class AbstractProxyConnectorFormAction private NetworkProxyAdmin networkProxyAdmin; @PostConstruct - public void initialize() + public void initialize( ) { - super.initialize(); + super.initialize( ); this.preDownloadPolicyMap = getBeansOfType( PreDownloadPolicy.class ); this.postDownloadPolicyMap = getBeansOfType( PostDownloadPolicy.class ); this.downloadErrorPolicyMap = getBeansOfType( DownloadErrorPolicy.class ); @@ -112,12 +112,13 @@ public abstract class AbstractProxyConnectorFormAction protected List escapePatterns( List patterns ) { - List escapedPatterns = new ArrayList(); + List escapedPatterns = new ArrayList( ); if ( patterns != null ) { for ( String pattern : patterns ) { - escapedPatterns.add( StringUtils.replace( pattern, "\\", "\\\\" ) ); + String escapedPattern = StringUtils.replace( pattern, "\\", "\\\\" ); + escapedPatterns.add( escapedPattern ); } } @@ -126,12 +127,13 @@ public abstract class AbstractProxyConnectorFormAction protected List unescapePatterns( List patterns ) { - List rawPatterns = new ArrayList(); + List rawPatterns = new ArrayList( ); if ( patterns != null ) { for ( String pattern : patterns ) { - rawPatterns.add( StringUtils.replace( pattern, "\\\\", "\\" ) ); + String unescapedPattern = StringUtils.replace( pattern, "\\\\", "\\" ); + rawPatterns.add( unescapedPattern ); } } @@ -143,18 +145,18 @@ public abstract class AbstractProxyConnectorFormAction return StringUtils.replace( pattern, "\\", "\\\\" ); } - public String addBlackListPattern() + public String addBlackListPattern( ) { - String pattern = getBlackListPattern(); + String pattern = getBlackListPattern( ); if ( StringUtils.isBlank( pattern ) ) { addActionError( "Cannot add a blank black list pattern." ); } - if ( !hasActionErrors() ) + if ( !hasActionErrors( ) ) { - getConnector().getBlackListPatterns().add( escapePattern( pattern ) ); + getConnector( ).getBlackListPatterns( ).add( escapePattern( pattern ) ); setBlackListPattern( null ); } @@ -162,10 +164,10 @@ public abstract class AbstractProxyConnectorFormAction } @SuppressWarnings( "unchecked" ) - public String addProperty() + public String addProperty( ) { - String key = getPropertyKey(); - String value = getPropertyValue(); + String key = getPropertyKey( ); + String value = getPropertyValue( ); if ( StringUtils.isBlank( key ) ) { @@ -177,9 +179,9 @@ public abstract class AbstractProxyConnectorFormAction addActionError( "Unable to add property with blank value." ); } - if ( !hasActionErrors() ) + if ( !hasActionErrors( ) ) { - getConnector().getProperties().put( key, value ); + getConnector( ).getProperties( ).put( key, value ); setPropertyKey( null ); setPropertyValue( null ); } @@ -187,101 +189,101 @@ public abstract class AbstractProxyConnectorFormAction return INPUT; } - public String addWhiteListPattern() + public String addWhiteListPattern( ) { - String pattern = getWhiteListPattern(); + String pattern = getWhiteListPattern( ); if ( StringUtils.isBlank( pattern ) ) { addActionError( "Cannot add a blank white list pattern." ); } - if ( !hasActionErrors() ) + if ( !hasActionErrors( ) ) { - getConnector().getWhiteListPatterns().add( escapePattern( pattern ) ); + getConnector( ).getWhiteListPatterns( ).add( escapePattern( pattern ) ); setWhiteListPattern( null ); } return INPUT; } - public String getBlackListPattern() + public String getBlackListPattern( ) { return blackListPattern; } - public ProxyConnector getConnector() + public ProxyConnector getConnector( ) { return connector; } - public List getManagedRepoIdList() + public List getManagedRepoIdList( ) { return managedRepoIdList; } - public String getPattern() + public String getPattern( ) { return pattern; } - public Map getPolicyMap() + public Map getPolicyMap( ) { return policyMap; } - public String getPropertyKey() + public String getPropertyKey( ) { return propertyKey; } - public String getPropertyValue() + public String getPropertyValue( ) { return propertyValue; } - public List getProxyIdOptions() + public List getProxyIdOptions( ) { return proxyIdOptions; } - public List getRemoteRepoIdList() + public List getRemoteRepoIdList( ) { return remoteRepoIdList; } - public String getWhiteListPattern() + public String getWhiteListPattern( ) { return whiteListPattern; } - public void prepare() + public void prepare( ) throws RepositoryAdminException { - proxyIdOptions = createNetworkProxyOptions(); - managedRepoIdList = createManagedRepoOptions(); - remoteRepoIdList = createRemoteRepoOptions(); - policyMap = createPolicyMap(); + proxyIdOptions = createNetworkProxyOptions( ); + managedRepoIdList = createManagedRepoOptions( ); + remoteRepoIdList = createRemoteRepoOptions( ); + policyMap = createPolicyMap( ); } - public String removeBlackListPattern() + public String removeBlackListPattern( ) { - String pattern = getPattern(); + String pattern = getPattern( ); if ( StringUtils.isBlank( pattern ) ) { addActionError( "Cannot remove a blank black list pattern." ); } - if ( !getConnector().getBlackListPatterns().contains( pattern ) - && !getConnector().getBlackListPatterns().contains( StringUtils.replace( pattern, "\\", "\\\\" ) ) ) + if ( !getConnector( ).getBlackListPatterns( ).contains( pattern ) + && !getConnector( ).getBlackListPatterns( ).contains( StringUtils.replace( pattern, "\\", "\\\\" ) ) ) { addActionError( "Non-existant black list pattern [" + pattern + "], no black list pattern removed." ); } - if ( !hasActionErrors() ) + if ( !hasActionErrors( ) ) { - getConnector().getBlackListPatterns().remove( escapePattern( pattern ) ); + getConnector( ).getBlackListPatterns( ).remove( escapePattern( pattern ) ); } setBlackListPattern( null ); @@ -290,23 +292,23 @@ public abstract class AbstractProxyConnectorFormAction return INPUT; } - public String removeProperty() + public String removeProperty( ) { - String key = getPropertyKey(); + String key = getPropertyKey( ); if ( StringUtils.isBlank( key ) ) { addActionError( "Unable to remove property with blank key." ); } - if ( !getConnector().getProperties().containsKey( key ) ) + if ( !getConnector( ).getProperties( ).containsKey( key ) ) { addActionError( "Non-existant property key [" + pattern + "], no property was removed." ); } - if ( !hasActionErrors() ) + if ( !hasActionErrors( ) ) { - getConnector().getProperties().remove( key ); + getConnector( ).getProperties( ).remove( key ); } setPropertyKey( null ); @@ -315,24 +317,24 @@ public abstract class AbstractProxyConnectorFormAction return INPUT; } - public String removeWhiteListPattern() + public String removeWhiteListPattern( ) { - String pattern = getPattern(); + String pattern = getPattern( ); if ( StringUtils.isBlank( pattern ) ) { addActionError( "Cannot remove a blank white list pattern." ); } - if ( !getConnector().getWhiteListPatterns().contains( pattern ) - && !getConnector().getWhiteListPatterns().contains( StringUtils.replace( pattern, "\\", "\\\\" ) ) ) + if ( !getConnector( ).getWhiteListPatterns( ).contains( pattern ) + && !getConnector( ).getWhiteListPatterns( ).contains( StringUtils.replace( pattern, "\\", "\\\\" ) ) ) { addActionError( "Non-existant white list pattern [" + pattern + "], no white list pattern removed." ); } - if ( !hasActionErrors() ) + if ( !hasActionErrors( ) ) { - getConnector().getWhiteListPatterns().remove( escapePattern( pattern ) ); + getConnector( ).getWhiteListPatterns( ).remove( escapePattern( pattern ) ); } setWhiteListPattern( null ); @@ -391,43 +393,43 @@ public abstract class AbstractProxyConnectorFormAction this.whiteListPattern = whiteListPattern; } - protected List createManagedRepoOptions() + protected List createManagedRepoOptions( ) throws RepositoryAdminException { - return new ArrayList( getManagedRepositoryAdmin().getManagedRepositoriesAsMap().keySet() ); + return new ArrayList( getManagedRepositoryAdmin( ).getManagedRepositoriesAsMap( ).keySet( ) ); } - protected List createNetworkProxyOptions() + protected List createNetworkProxyOptions( ) throws RepositoryAdminException { - List options = new ArrayList(); + List options = new ArrayList( ); options.add( DIRECT_CONNECTION ); - options.addAll( getNetworkProxiesKeys() ); + options.addAll( getNetworkProxiesKeys( ) ); return options; } - private Collection getNetworkProxiesKeys() + private Collection getNetworkProxiesKeys( ) throws RepositoryAdminException { - List networkProxies = networkProxyAdmin.getNetworkProxies(); - if ( networkProxies == null || networkProxies.isEmpty() ) + List networkProxies = networkProxyAdmin.getNetworkProxies( ); + if ( networkProxies == null || networkProxies.isEmpty( ) ) { - return Collections.emptyList(); + return Collections.emptyList( ); } - List keys = new ArrayList( networkProxies.size() ); + List keys = new ArrayList( networkProxies.size( ) ); for ( NetworkProxy networkProxy : networkProxies ) { - keys.add( networkProxy.getId() ); + keys.add( networkProxy.getId( ) ); } return keys; } - protected Map createPolicyMap() + protected Map createPolicyMap( ) { - Map policyMap = new HashMap(); + Map policyMap = new HashMap( ); policyMap.putAll( preDownloadPolicyMap ); policyMap.putAll( postDownloadPolicyMap ); @@ -436,49 +438,49 @@ public abstract class AbstractProxyConnectorFormAction return policyMap; } - protected List createRemoteRepoOptions() + protected List createRemoteRepoOptions( ) throws RepositoryAdminException { - return new ArrayList( getRemoteRepositoryAdmin().getRemoteRepositoriesAsMap().keySet() ); + return new ArrayList( getRemoteRepositoryAdmin( ).getRemoteRepositoriesAsMap( ).keySet( ) ); } @SuppressWarnings( "unchecked" ) - protected void validateConnector() + protected void validateConnector( ) { - if ( connector.getPolicies() == null ) + if ( connector.getPolicies( ) == null ) { addActionError( "Policies must be set." ); } else { // Validate / Fix policy settings arriving from browser. - for ( Map.Entry entry : getPolicyMap().entrySet() ) + for ( Map.Entry entry : getPolicyMap( ).entrySet( ) ) { - String policyId = entry.getKey(); - Policy policy = entry.getValue(); - List options = policy.getOptions(); + String policyId = entry.getKey( ); + Policy policy = entry.getValue( ); + List options = policy.getOptions( ); - if ( !connector.getPolicies().containsKey( policyId ) ) + if ( !connector.getPolicies( ).containsKey( policyId ) ) { addActionError( "Policy [" + policyId + "] must be set (missing id)." ); continue; } - Map properties = connector.getProperties(); - for ( Map.Entry entry2 : properties.entrySet() ) + Map properties = connector.getProperties( ); + for ( Map.Entry entry2 : properties.entrySet( ) ) { - Object value = entry2.getValue(); - if ( value.getClass().isArray() ) + Object value = entry2.getValue( ); + if ( value.getClass( ).isArray( ) ) { String[] arr = (String[]) value; - properties.put( entry2.getKey(), arr[0] ); + properties.put( entry2.getKey( ), arr[0] ); } } // Ugly hack to compensate for ugly browsers. - Object o = connector.getPolicies().get( policyId ); + Object o = connector.getPolicies( ).get( policyId ); String value; - if ( o.getClass().isArray() ) + if ( o.getClass( ).isArray( ) ) { String arr[] = (String[]) o; value = arr[0]; @@ -488,7 +490,7 @@ public abstract class AbstractProxyConnectorFormAction value = (String) o; } - connector.getPolicies().put( policyId, value ); + connector.getPolicies( ).put( policyId, value ); if ( StringUtils.isBlank( value ) ) { @@ -506,7 +508,7 @@ public abstract class AbstractProxyConnectorFormAction } } - public NetworkProxyAdmin getNetworkProxyAdmin() + public NetworkProxyAdmin getNetworkProxyAdmin( ) { return networkProxyAdmin; } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/proxyConnectorForm.jspf b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/proxyConnectorForm.jspf index 01ad6149c..dc06b416f 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/proxyConnectorForm.jspf +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/proxyConnectorForm.jspf @@ -173,20 +173,20 @@ - + - +
- - "${pattern}" + + "${currentPattern}" - ', 'removeWhiteListPattern')" theme="simple"> - +
-- 2.39.5