Local mergeStringArrays variant for Portlets (superseding StringUtils)
This commit is contained in:
parent
8b5563ecab
commit
37ee264fbf
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -771,8 +771,8 @@ public class AnnotationMethodHandlerAdapter extends PortletContentGenerator
|
||||||
for (RequestMethod method : methods) {
|
for (RequestMethod method : methods) {
|
||||||
this.methods.add(method.name());
|
this.methods.add(method.name());
|
||||||
}
|
}
|
||||||
this.params = StringUtils.mergeStringArrays(this.params, params);
|
this.params = PortletAnnotationMappingUtils.mergeStringArrays(this.params, params);
|
||||||
this.headers = StringUtils.mergeStringArrays(this.headers, headers);
|
this.headers = PortletAnnotationMappingUtils.mergeStringArrays(this.headers, headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initPhaseMapping(String phase, String value, String[] params) {
|
public void initPhaseMapping(String phase, String value, String[] params) {
|
||||||
|
|
@ -782,7 +782,7 @@ public class AnnotationMethodHandlerAdapter extends PortletContentGenerator
|
||||||
}
|
}
|
||||||
this.phase = phase;
|
this.phase = phase;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.params = StringUtils.mergeStringArrays(this.params, params);
|
this.params = PortletAnnotationMappingUtils.mergeStringArrays(this.params, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean match(PortletRequest request) {
|
public boolean match(PortletRequest request) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -154,7 +154,7 @@ public class DefaultAnnotationHandlerMapping extends AbstractMapBasedHandlerMapp
|
||||||
String[] modeKeys = new String[0];
|
String[] modeKeys = new String[0];
|
||||||
String[] params = new String[0];
|
String[] params = new String[0];
|
||||||
if (typeMapping != null) {
|
if (typeMapping != null) {
|
||||||
params = StringUtils.mergeStringArrays(typeMapping.params(), params);
|
params = PortletAnnotationMappingUtils.mergeStringArrays(typeMapping.params(), params);
|
||||||
}
|
}
|
||||||
ActionMapping actionMapping = AnnotationUtils.findAnnotation(method, ActionMapping.class);
|
ActionMapping actionMapping = AnnotationUtils.findAnnotation(method, ActionMapping.class);
|
||||||
RenderMapping renderMapping = AnnotationUtils.findAnnotation(method, RenderMapping.class);
|
RenderMapping renderMapping = AnnotationUtils.findAnnotation(method, RenderMapping.class);
|
||||||
|
|
@ -162,11 +162,11 @@ public class DefaultAnnotationHandlerMapping extends AbstractMapBasedHandlerMapp
|
||||||
EventMapping eventMapping = AnnotationUtils.findAnnotation(method, EventMapping.class);
|
EventMapping eventMapping = AnnotationUtils.findAnnotation(method, EventMapping.class);
|
||||||
RequestMapping requestMapping = AnnotationUtils.findAnnotation(method, RequestMapping.class);
|
RequestMapping requestMapping = AnnotationUtils.findAnnotation(method, RequestMapping.class);
|
||||||
if (actionMapping != null) {
|
if (actionMapping != null) {
|
||||||
params = StringUtils.mergeStringArrays(params, actionMapping.params());
|
params = PortletAnnotationMappingUtils.mergeStringArrays(params, actionMapping.params());
|
||||||
predicate = new ActionMappingPredicate(actionMapping.name(), params);
|
predicate = new ActionMappingPredicate(actionMapping.name(), params);
|
||||||
}
|
}
|
||||||
else if (renderMapping != null) {
|
else if (renderMapping != null) {
|
||||||
params = StringUtils.mergeStringArrays(params, renderMapping.params());
|
params = PortletAnnotationMappingUtils.mergeStringArrays(params, renderMapping.params());
|
||||||
predicate = new RenderMappingPredicate(renderMapping.windowState(), params);
|
predicate = new RenderMappingPredicate(renderMapping.windowState(), params);
|
||||||
}
|
}
|
||||||
else if (resourceMapping != null) {
|
else if (resourceMapping != null) {
|
||||||
|
|
@ -183,7 +183,7 @@ public class DefaultAnnotationHandlerMapping extends AbstractMapBasedHandlerMapp
|
||||||
Arrays.asList(modeKeys) + " versus " + Arrays.asList(typeMapping.value()));
|
Arrays.asList(modeKeys) + " versus " + Arrays.asList(typeMapping.value()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
params = StringUtils.mergeStringArrays(params, requestMapping.params());
|
params = PortletAnnotationMappingUtils.mergeStringArrays(params, requestMapping.params());
|
||||||
if (predicate == null) {
|
if (predicate == null) {
|
||||||
predicate = new MethodLevelMappingPredicate(params);
|
predicate = new MethodLevelMappingPredicate(params);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2009 the original author or authors.
|
* Copyright 2002-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -16,7 +16,9 @@
|
||||||
|
|
||||||
package org.springframework.web.portlet.mvc.annotation;
|
package org.springframework.web.portlet.mvc.annotation;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javax.portlet.ClientDataRequest;
|
import javax.portlet.ClientDataRequest;
|
||||||
|
|
@ -24,6 +26,7 @@ import javax.portlet.PortletRequest;
|
||||||
|
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.portlet.util.PortletUtils;
|
import org.springframework.web.portlet.util.PortletUtils;
|
||||||
|
|
||||||
|
|
@ -35,6 +38,29 @@ import org.springframework.web.portlet.util.PortletUtils;
|
||||||
*/
|
*/
|
||||||
abstract class PortletAnnotationMappingUtils {
|
abstract class PortletAnnotationMappingUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merge the given {@code String} arrays into one, with each element only included once.
|
||||||
|
* <p>The order of elements in the original arrays is preserved (with the exception of
|
||||||
|
* overlapping elements, which are only included on their first occurrence).
|
||||||
|
* @param array1 the first array (can be {@code null})
|
||||||
|
* @param array2 the second array (can be {@code null})
|
||||||
|
* @return the new array ({@code null} if both given arrays were {@code null})
|
||||||
|
* @since 4.3.15 (superseding {@link StringUtils#mergeStringArrays})
|
||||||
|
*/
|
||||||
|
public static String[] mergeStringArrays(String[] array1, String[] array2) {
|
||||||
|
if (ObjectUtils.isEmpty(array1)) {
|
||||||
|
return array2;
|
||||||
|
}
|
||||||
|
if (ObjectUtils.isEmpty(array2)) {
|
||||||
|
return array1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<String> result = new LinkedHashSet<String>();
|
||||||
|
result.addAll(Arrays.asList(array1));
|
||||||
|
result.addAll(Arrays.asList(array2));
|
||||||
|
return StringUtils.toStringArray(result);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether the given portlet modes matches the specified type-level modes.
|
* Check whether the given portlet modes matches the specified type-level modes.
|
||||||
* @param modes the mapped portlet modes to check
|
* @param modes the mapped portlet modes to check
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue