com.adobe.acs.commons.i18n.impl.I18nProviderImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of acs-aem-commons-bundle Show documentation
Show all versions of acs-aem-commons-bundle Show documentation
Main ACS AEM Commons OSGi Bundle. Includes commons utilities.
/*
* ACS AEM Commons
*
* Copyright (C) 2013 - 2023 Adobe
*
* Licensed 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.adobe.acs.commons.i18n.impl;
import com.adobe.acs.commons.i18n.I18nProvider;
import com.adobe.acs.commons.models.injectors.impl.InjectorUtils;
import com.adobe.acs.commons.util.impl.AbstractGuavaCacheMBean;
import com.adobe.acs.commons.util.impl.CacheMBean;
import com.adobe.acs.commons.util.impl.exception.CacheMBeanException;
import com.day.cq.i18n.I18n;
import com.day.cq.wcm.api.Page;
import acscommons.com.google.common.cache.Cache;
import acscommons.com.google.common.cache.CacheBuilder;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.commons.osgi.Order;
import org.apache.sling.commons.osgi.RankedServices;
import org.apache.sling.i18n.ResourceBundleProvider;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.osgi.service.metatype.annotations.Designate;
import javax.management.NotCompliantMBeanException;
import javax.management.openmbean.CompositeType;
import javax.management.openmbean.OpenDataException;
import javax.management.openmbean.OpenType;
import javax.management.openmbean.SimpleType;
import javax.servlet.http.HttpServletRequest;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.concurrent.TimeUnit;
@Component(
property= {
"jmx.objectname=com.adobe.acs.commons.i18n:type=I18N Provider Cache"
},
service = I18nProvider.class,
immediate = true,
reference = {
@Reference(
name="resourceBundleProviders",
service = ResourceBundleProvider.class,
cardinality = ReferenceCardinality.AT_LEAST_ONE,
policy = ReferencePolicy.DYNAMIC,
bind="bindResourceBundleProvider",
unbind="unbindResourceBundleProvider"
)
}
)
@Designate(ocd = Config.class)
public class I18nProviderImpl extends AbstractGuavaCacheMBean implements I18nProvider {
private static final String JMX_PN_I18N = "I18n Object";
private final RankedServices resourceBundleProviders = new RankedServices<>(Order.ASCENDING);
private Cache cache;
public I18nProviderImpl() throws NotCompliantMBeanException {
super(CacheMBean.class);
}
protected void bindResourceBundleProvider(final ResourceBundleProvider resourceBundleProvider, final Map props) {
resourceBundleProviders.bind(resourceBundleProvider, props);
}
protected void unbindResourceBundleProvider(final ResourceBundleProvider resourceBundleProvider, final Map props) {
resourceBundleProviders.unbind(resourceBundleProvider, props);
}
protected void activate(final Config config) {
final long size = config.maxSizeCount();
final CacheBuilder
© 2015 - 2024 Weber Informatics LLC | Privacy Policy