public Optional<String> displayName() { return readValue("_displayName"); }
public Optional<String> placeholder(final ParameterBundle parent) { return get(parent, "_placeholder", false); }
protected Optional<String> readValue(final String key) { return readRawValue(prefix + key); }
private String toAsciidoctor(final ParameterMeta p, final DefaultValueInspector.Instance instance, final ParameterBundle parent) { final ParameterBundle bundle = findBundle(p); return "|" + bundle.displayName(parent).orElse(p.getName()) + '|' + bundle.documentation(parent).orElseGet(() -> findDocumentation(p)) + '|' + ofNullable(findDefault(p, instance)).orElse("-") + '|' + renderConditions(p.getPath(), p.getMetadata()) + '|' + p.getPath(); }
.computeIfAbsent(method, m -> new MethodMeta(createLocaleExtractor(m), createParameterFactory(m))); final Locale locale = methodMeta.localeExtractor.apply(args); final String template = getTemplate(locale, method);
final IconResolver.Icon iconFamilyContent = iconResolver.resolve(container, familyIcon); final String familyDisplayName = meta.getParent().findBundle(loader, locale).displayName().orElse(meta.getParent().getName()); final List<String> categories = ofNullable(meta.getParent().getCategories()) .map(vals -> vals .getParent() .findBundle(loader, locale) .category(category) .orElseGet(() -> category .replace("/" + meta.getParent().getName() + "/", ofNullable(originalId).map(ComponentManager.OriginalId::getValue).orElse(plugin), meta.getParent().getName(), meta.getName()), meta.findBundle(loader, locale).displayName().orElse(meta.getName()), familyDisplayName, new Icon(icon, iconContent == null ? null : iconContent.getType(), !includeIcon ? null : (iconContent == null ? null : iconContent.getBytes())),
private Map<String, String> rewriteMetadataForLocale(final Map<String, String> metadata, final ParameterBundle parentBundle, final ParameterBundle bundle) { final String defaultDoc = metadata.get("documentation::value"); final String bundleDoc = bundle.documentation(parentBundle).orElse(null); if (bundleDoc == null || bundleDoc.equals(defaultDoc)) { return metadata; } final Map<String, String> copy = new HashMap<>(metadata); copy.put("documentation::value", bundleDoc); return copy; }
private Optional<String> get(final ParameterBundle parentBundle, final String suffix, final boolean stripLastSegment) { Optional<String> 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; } }
public Optional<String> actionDisplayName(final String type, final String name) { return readRawValue(prefix + "actions." + type + "." + name + "._displayName"); }
public Optional<String> displayName() { return readValue("_displayName"); } }
public FamilyBundle findBundle(final ClassLoader loader, final Locale locale) { return bundles.computeIfAbsent(locale, l -> { try { final ResourceBundle bundle = ResourceBundle .getBundle((packageName.isEmpty() ? packageName : (packageName + '.')) + "Messages", locale, loader); return new FamilyBundle(bundle, name + '.'); } catch (final MissingResourceException mre) { log .warn("No bundle for " + packageName + " (" + name + "), means the display names will be the technical names"); log.debug(mre.getMessage(), mre); return NO_COMPONENT_BUNDLE; } }); }
public ComponentBundle findBundle(final ClassLoader loader, final Locale locale) { return bundles.computeIfAbsent(locale, l -> { try { final ResourceBundle bundle = ResourceBundle .getBundle((packageName.isEmpty() ? packageName : (packageName + '.')) + "Messages", locale, loader); return new ComponentBundle(bundle, parent.name + '.' + name + '.'); } catch (final MissingResourceException mre) { log .warn("No bundle for " + packageName + " (" + parent.name + " / " + name + "), means the display names will be the technical names"); log.debug(mre.getMessage(), mre); return NO_COMPONENT_BUNDLE; } }); }
public Set<ActionReference> getActionReference(final Stream<ParameterMeta> parameters, final String familyName, final FamilyBundle familyBundle) { return parameters .flatMap(p -> p.getMetadata().entrySet().stream()) .filter(e -> e.getKey().startsWith(ActionParameterEnricher.META_PREFIX)) .map(e -> { final String type = e.getKey().substring(ActionParameterEnricher.META_PREFIX.length()); return new ActionReference(familyName, e.getValue(), type, familyBundle.actionDisplayName(type, e.getValue()).orElse(e.getValue()), null); }) .collect(toSet()); }
public <T> T create(final Class<T> api, final ClassLoader loader) { if (!api.isInterface()) { throw new IllegalArgumentException(api + " is not an interface"); } if (Stream .of(api.getMethods()) .filter(m -> m.getDeclaringClass() != Object.class) .anyMatch(m -> m.getReturnType() != String.class)) { throw new IllegalArgumentException(api + " methods must return a String"); } if (Stream .of(api.getMethods()) .flatMap(m -> Stream.of(m.getParameters())) .anyMatch(p -> p.isAnnotationPresent(Language.class) && p.getType() != Locale.class)) { throw new IllegalArgumentException("@Language can only be used with Locales"); } final String pck = api.getPackage().getName(); return api .cast(Proxy .newProxyInstance(loader, new Class<?>[] { api }, new InternationalizedHandler( api.getName() + '.', (pck == null || pck.isEmpty() ? "" : (pck + '.')) + "Messages"))); }
public Optional<String> documentation(final ParameterBundle parent) { return get(parent, "_documentation", false); }
public Optional<String> configurationDisplayName(final String type, final String name) { return readValue(type + "." + name + "._displayName"); } }
protected Optional<String> readRawValue(final String key) { final Optional<String> value = Stream.of(bundles).filter(b -> b.containsKey(key)).map(b -> b.getString(key)).findFirst(); if (value.isPresent() || !key.contains("${index}")) { return value; } return readRawValue(key.replace("${index}", "")); } }
public Optional<String> displayName(final ParameterBundle parent) { return get(parent, "_displayName", false); }
public Optional<String> category(final String value) { return readValue(value + "._category"); }
public Optional<String> enumDisplayName(final ParameterBundle parent, final String enumName) { return get(parent, enumName + "._displayName", true); }