Skip to content

Commit

Permalink
WW-5411 Delete deprecated code part 3
Browse files Browse the repository at this point in the history
  • Loading branch information
kusalk committed Jul 25, 2024
1 parent 36176b6 commit 6c6ef44
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 333 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,6 @@ public AbstractMatcher(PatternMatcher<?> helper, boolean appendNamedParameters)
this.appendNamedParameters = appendNamedParameters;
}

/**
* Creates a matcher with {@link #appendNamedParameters} set to true to keep backward compatibility
*
* @param helper an instance of {@link PatternMatcher}
* @deprecated use @{link {@link AbstractMatcher(PatternMatcher, boolean)} instead
*/
@Deprecated
public AbstractMatcher(PatternMatcher<?> helper) {
this(helper, true);
}

/**
* <p>
* Finds and precompiles the wildcard patterns. Patterns will be evaluated
Expand All @@ -108,7 +97,7 @@ public void addPattern(String name, E target, boolean looseMatch) {
Object pattern;

if (!wildcard.isLiteral(name)) {
if (looseMatch && (name.length() > 0) && (name.charAt(0) == '/')) {
if (looseMatch && (!name.isEmpty()) && (name.charAt(0) == '/')) {
name = name.substring(1);
}

Expand Down Expand Up @@ -142,14 +131,14 @@ public void freeze() {
public E match(String potentialMatch) {
E config = null;

if (compiledPatterns.size() > 0) {
if (!compiledPatterns.isEmpty()) {
LOG.debug("Attempting to match '{}' to a wildcard pattern, {} available", potentialMatch, compiledPatterns.size());

Map<String, String> vars = new LinkedHashMap<>();
for (Mapping<E> m : compiledPatterns) {
if (wildcard.match(vars, potentialMatch, m.getPattern())) {
LOG.debug("Value matches pattern '{}'", m.getOriginalPattern());
config = convert(potentialMatch, m.getTarget(), vars);
if (wildcard.match(vars, potentialMatch, m.pattern())) {
LOG.debug("Value matches pattern '{}'", m.originalPattern());
config = convert(potentialMatch, m.target(), vars);
break;
}
}
Expand Down Expand Up @@ -216,7 +205,7 @@ protected String convertParam(String val, Map<String, String> vars) {

Matcher wildcardMatcher = WILDCARD_PATTERN.matcher(val);

StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
while (wildcardMatcher.find()) {
wildcardMatcher.appendReplacement(result, vars.getOrDefault(wildcardMatcher.group(1), ""));
}
Expand All @@ -228,62 +217,11 @@ protected String convertParam(String val, Map<String, String> vars) {
/**
* <p> Stores a compiled wildcard pattern and the object it came
* from. </p>
*
* @param originalPattern <p> The original pattern. </p>
* @param pattern <p> The compiled pattern. </p>
* @param target <p> The original object. </p>
*/
private static class Mapping<E> implements Serializable {
/**
* <p> The original pattern. </p>
*/
private final String original;


/**
* <p> The compiled pattern. </p>
*/
private final Object pattern;

/**
* <p> The original object. </p>
*/
private final E config;

/**
* <p> Contructs a read-only Mapping instance. </p>
*
* @param original The original pattern
* @param pattern The compiled pattern
* @param config The original object
*/
public Mapping(String original, Object pattern, E config) {
this.original = original;
this.pattern = pattern;
this.config = config;
}

/**
* <p> Gets the compiled wildcard pattern. </p>
*
* @return The compiled pattern
*/
public Object getPattern() {
return this.pattern;
}

/**
* <p> Gets the object that contains the pattern. </p>
*
* @return The associated object
*/
public E getTarget() {
return this.config;
}

/**
* <p> Gets the original wildcard pattern. </p>
*
* @return The original pattern
*/
public String getOriginalPattern() {
return this.original;
}
private record Mapping<E>(String originalPattern, Object pattern, E target) implements Serializable {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public CompiledPattern compilePattern(String data) {
*/
public boolean match(Map<String, String> map, String data, CompiledPattern expr) {

if (data != null && data.length() > 0) {
if (data != null && !data.isEmpty()) {
Matcher matcher = expr.getPattern().matcher(data);
if (matcher.matches()) {
for (int x = 0; x < expr.getVariableNames().size(); x++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

/**
* Compiles and matches a pattern against a value
*
*
* @since 2.1
*/
public interface PatternMatcher<E extends Object> {
public interface PatternMatcher<E> {

/**
* Determines if the pattern is a simple literal string or contains wildcards that will need to be processed
Expand All @@ -36,16 +36,16 @@ public interface PatternMatcher<E extends Object> {

/**
* <p> Translate the given <code>String</code> into an object
* representing the pattern matchable by this class.
* representing the pattern matchable by this class.
*
* @param data The string to translate.
* @return The encoded string
* @return The encoded string
* @throws NullPointerException If data is null.
*/
E compilePattern(String data);

/**
* Match a pattern against a string
* Match a pattern against a string
*
* @param map The map to store matched values
* @param data The string to match
Expand All @@ -54,5 +54,5 @@ public interface PatternMatcher<E extends Object> {
* @throws NullPointerException If any parameters are null
*/
boolean match(Map<String,String> map, String data, E expr);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,65 +38,11 @@ public class StrutsLocalizedTextProvider extends AbstractLocalizedTextProvider {

private static final Logger LOG = LogManager.getLogger(StrutsLocalizedTextProvider.class);

/**
* Clears the internal list of resource bundles.
*
* @deprecated used only in tests
*/
@Deprecated
public static void clearDefaultResourceBundles() {
// no-op
}

public StrutsLocalizedTextProvider() {
addDefaultResourceBundle(XWORK_MESSAGES_BUNDLE);
addDefaultResourceBundle(STRUTS_MESSAGES_BUNDLE);
}

/**
* Builds a {@link java.util.Locale} from a String of the form en_US_foo into a Locale
* with language "en", country "US" and variant "foo". This will parse the output of
* {@link java.util.Locale#toString()}.
*
* @param localeStr The locale String to parse.
* @param defaultLocale The locale to use if localeStr is <tt>null</tt>.
* @return requested Locale
* @deprecated please use {@link org.apache.commons.lang3.LocaleUtils#toLocale(String)}
*/
@Deprecated
public static Locale localeFromString(String localeStr, Locale defaultLocale) {
if ((localeStr == null) || (localeStr.trim().length() == 0) || ("_".equals(localeStr))) {
if (defaultLocale != null) {
return defaultLocale;
}
return Locale.getDefault();
}

int index = localeStr.indexOf('_');
if (index < 0) {
return new Locale(localeStr);
}

String language = localeStr.substring(0, index);
if (index == localeStr.length()) {
return new Locale(language);
}

localeStr = localeStr.substring(index + 1);
index = localeStr.indexOf('_');
if (index < 0) {
return new Locale(language, localeStr);
}

String country = localeStr.substring(0, index);
if (index == localeStr.length()) {
return new Locale(language, country);
}

localeStr = localeStr.substring(index + 1);
return new Locale(language, country, localeStr);
}

/**
* Calls {@link #findText(Class aClass, String aTextName, Locale locale, String defaultMessage, Object[] args)}
* with aTextName as the default message.
Expand Down Expand Up @@ -135,7 +81,7 @@ public String findText(Class aClass, String aTextName, Locale locale) {
* object. If so, repeat the entire process from the beginning with the object's class as
* aClass and "address.state" as the message key.</li>
* <li>If not found, look for the message in aClass' package hierarchy.</li>
* <li>If still not found, look for the message in the default resource bundles
* <li>If still not found, look for the message in the default resource bundles
* (Note: the lookup is not repeated again if {@link #searchDefaultBundlesFirst} was <code>true</code>).</li>
* <li>Return defaultMessage</li>
* </ol>
Expand Down Expand Up @@ -190,7 +136,7 @@ public String findText(Class aClass, String aTextName, Locale locale, String def
* object. If so, repeat the entire process from the beginning with the object's class as
* aClass and "address.state" as the message key.</li>
* <li>If not found, look for the message in aClass' package hierarchy.</li>
* <li>If still not found, look for the message in the default resource bundles
* <li>If still not found, look for the message in the default resource bundles
* (Note: the lookup is not repeated again if {@link #searchDefaultBundlesFirst} was <code>true</code>).</li>
* <li>Return defaultMessage</li>
* </ol>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,33 @@
import freemarker.cache.FileTemplateLoader;
import freemarker.cache.MultiTemplateLoader;
import freemarker.cache.TemplateLoader;
import freemarker.ext.jakarta.servlet.WebappTemplateLoader;
import freemarker.core.HTMLOutputFormat;
import freemarker.core.TemplateClassResolver;
import freemarker.ext.jakarta.jsp.TaglibFactory;
import freemarker.ext.jakarta.servlet.HttpRequestHashModel;
import freemarker.ext.jakarta.servlet.HttpRequestParametersHashModel;
import freemarker.ext.jakarta.servlet.HttpSessionHashModel;
import freemarker.ext.jakarta.servlet.ServletContextHashModel;
import freemarker.ext.jakarta.servlet.WebappTemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.ObjectWrapper;
import freemarker.template.TemplateException;
import freemarker.template.TemplateExceptionHandler;
import freemarker.template.TemplateModel;
import freemarker.template.Version;
import freemarker.template.utility.StringUtil;
import jakarta.servlet.GenericServlet;
import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts2.StrutsConstants;
import org.apache.struts2.views.JspSupportServlet;
import org.apache.struts2.views.TagLibraryModelProvider;
import org.apache.struts2.views.util.ContextUtil;

import jakarta.servlet.GenericServlet;
import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -137,27 +137,6 @@ public class FreemarkerManager {

public static final String EXPIRATION_DATE;

/**
* @deprecated since Struts 6.5.0, do not use as it will be removed in Struts 7.0.0
*/
@Deprecated
public static final String KEY_INCLUDE = "include_page";
/**
* @deprecated since Struts 6.5.0, do not use as it will be removed in Struts 7.0.0
*/
@Deprecated
public static final String KEY_REQUEST_PRIVATE = "__FreeMarkerServlet.Request__";
/**
* @deprecated since Struts 6.5.0, do not use as it will be removed in Struts 7.0.0
*/
@Deprecated
public static final String KEY_REQUEST_PARAMETERS = "RequestParameters";
/**
* @deprecated since Struts 6.5.0, do not use as it will be removed in Struts 7.0.0
*/
@Deprecated
public static final String KEY_HASHMODEL_PRIVATE = "__FreeMarkerManager.Request__";

/**
* Adds individual settings.
*
Expand Down
15 changes: 0 additions & 15 deletions core/src/main/resources/struts-beans.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,6 @@
<bean type="com.opensymphony.xwork2.ognl.accessor.RootAccessor" name="struts"
class="com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor"/>

<!-- DEPRECATED since 6.4.0 - The following 3 beans are retained for backwards compatibility
with custom beans that may expect them to be present. Inject the DEFAULT bean of type
'com.opensymphony.xwork2.ognl.accessor.RootAccessor' above instead. -->
<bean type="ognl.ClassResolver" name="com.opensymphony.xwork2.util.CompoundRoot"
class="com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor"/>
<bean type="ognl.PropertyAccessor" name="com.opensymphony.xwork2.util.CompoundRoot"
class="com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor"/>
<bean type="ognl.MethodAccessor" name="com.opensymphony.xwork2.util.CompoundRoot"
class="com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor"/>

<bean type="ognl.PropertyAccessor" name="java.lang.Object"
class="com.opensymphony.xwork2.ognl.accessor.ObjectAccessor"/>
<bean type="ognl.PropertyAccessor" name="java.util.Iterator"
Expand All @@ -212,11 +202,6 @@
<bean type="ognl.MethodAccessor" name="struts"
class="com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor"/>

<!-- DEPRECATED since 6.4.0 - Retained for backwards compatibility with custom beans
that may expect it to be present. Inject the DEFAULT bean of 'ognl.MethodAccessor' above instead. -->
<bean type="ognl.MethodAccessor" name="java.lang.Object"
class="com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor"/>

<bean type="org.apache.struts2.dispatcher.StaticContentLoader"
class="org.apache.struts2.dispatcher.DefaultStaticContentLoader" name="struts"/>
<bean type="com.opensymphony.xwork2.UnknownHandlerManager"
Expand Down

This file was deleted.

Loading

0 comments on commit 6c6ef44

Please sign in to comment.