Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.opensymphony.xwork2;
import com.opensymphony.xwork2.util.ValueStack;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.*;
/**
* This is a composite {@link TextProvider} that takes in an array or {@link java.util.List} of {@link TextProvider}s, it will
* consult each of them in order to get a composite result. To know how each method behaves, please refer to the
* javadoc for each methods.
*
* @author tmjee
*/
public class CompositeTextProvider implements TextProvider {
private static final Logger LOG = LogManager.getLogger(CompositeTextProvider.class);
private List textProviders = new ArrayList<>();
/**
* Instantiates a {@link CompositeTextProvider} with some predefined textProviders.
*
* @param textProviders list of text providers
*/
public CompositeTextProvider(List textProviders) {
this.textProviders.addAll(textProviders);
}
/**
* Instantiates a {@link CompositeTextProvider} with some predefined textProviders.
*
* @param textProviders array of text providers
*/
public CompositeTextProvider(TextProvider[] textProviders) {
this(Arrays.asList(textProviders));
}
/**
* It will consult each individual {@link TextProvider}s and return true if either one of the {@link TextProvider}" has such a key else false.
*
* @param key The key to lookup in resource bundles.
* @return true, if the requested key is found in one of the resource bundles.
*
* @see com.opensymphony.xwork2.TextProvider#hasKey(String)
*
*/
public boolean hasKey(String key) {
// if there's a key in either text providers we are ok, else try the next text provider
for (TextProvider tp : textProviders) {
if (tp.hasKey(key)) {
return true;
}
}
return false;
}
/**
* It will consult each {@link TextProvider}s and return the first valid message for this
* key
*
* @param key The key to lookup in resource bundles.
* @return The i18n text for the requested key.
* @see com.opensymphony.xwork2.TextProvider#getText(String)
*/
public String getText(String key) {
return getText(key, key, Collections.emptyList());
}
/**
* It will consult each {@link TextProvider}s and return the first valid message for this
* key before returning defaultValue if every else fails.
*
* @param key the message key
* @param defaultValue the default value
* @return the first valid message for the key or default value
* @see com.opensymphony.xwork2.TextProvider#getText(String, String)
*/
public String getText(String key, String defaultValue) {
return getText(key, defaultValue, Collections.emptyList());
}
/**
* It will consult each {@link TextProvider}s and return the first valid message for this
* key, before returning defaultValue
* if every else fails.
*
* @param key the message key
* @param defaultValue the default value
* @param obj object
* @return the first valid message for the key or default value
* @see com.opensymphony.xwork2.TextProvider#getText(String, String, String)
*/
public String getText(String key, String defaultValue, final String obj) {
return getText(key, defaultValue, new ArrayList