
org.talend.sdk.component.runtime.internationalization.ParameterBundle Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of component-runtime-impl Show documentation
Show all versions of component-runtime-impl Show documentation
Module responsible to understand the API model and make it runnable.
This MUST be considered as an internal of the stack.
The newest version!
/**
* Copyright (C) 2006-2023 Talend Inc. - www.talend.com
*
* 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 org.talend.sdk.component.runtime.internationalization;
import java.util.Objects;
import java.util.Optional;
import java.util.ResourceBundle;
import java.util.stream.Stream;
public class ParameterBundle extends InternalBundle {
private final String[] simpleNames;
public ParameterBundle(final ResourceBundle[] bundles, final String prefix, final String... simpleNames) {
super(bundles, prefix);
this.simpleNames = simpleNames;
}
public Optional documentation(final ParameterBundle parent) {
return get(parent, "_documentation", false);
}
public Optional displayName(final ParameterBundle parent) {
return get(parent, "_displayName", false);
}
public Optional enumDisplayName(final ParameterBundle parent, final String enumName) {
return get(parent, enumName + "._displayName", true);
}
public Optional placeholder(final ParameterBundle parent) {
return get(parent, "_placeholder", false);
}
public Optional gridLayoutName(final ParameterBundle parent, final String tabName) {
return get(parent, "_gridlayout." + tabName + "._displayName", false);
}
private Optional get(final ParameterBundle parentBundle, final String suffix,
final boolean stripLastSegment) {
Optional v = readValue(suffix);
if (!v.isPresent()) {
v = Stream
.of(simpleNames)
.map(s -> !stripLastSegment || s.lastIndexOf('.') < 0 ? s : s.substring(0, s.lastIndexOf('.')))
.map(s -> {
final String k = s + "." + suffix;
return readRawValue(k)
.orElse(parentBundle == null ? null : parentBundle.readRawValue(k).orElse(null));
})
.filter(Objects::nonNull)
.findFirst();
}
return v;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy