MCPcopy Create free account
hub / github.com/apache/solr / InitParams

Class InitParams

solr/core/src/java/org/apache/solr/core/InitParams.java:33–147  ·  view source on GitHub ↗

An Object which represents a tag

Source from the content-addressed store, hash-verified

31
32/** An Object which represents a {@code <initParams>} tag */
33public class InitParams {
34 public static final String TYPE = "initParams";
35 public final String name;
36 public final Set<String> paths;
37 public final NamedList<?> defaults;
38 public final NamedList<?> invariants;
39 public final NamedList<?> appends;
40 private final PluginInfo pluginInfo;
41 private static final Set<String> KNOWN_KEYS = Set.of(DEFAULTS, INVARIANTS, APPENDS);
42
43 public InitParams(PluginInfo p) {
44 this.pluginInfo = p;
45 this.name = p.attributes.get(NAME);
46 Set<String> paths = null;
47 String pathStr = p.attributes.get(PATH);
48 if (pathStr != null) {
49 paths = Set.copyOf(StrUtils.splitSmart(pathStr, ','));
50 }
51 this.paths = paths;
52 NamedList<?> nl = (NamedList<?>) p.initArgs.get(DEFAULTS);
53 defaults = nl == null ? null : nl.getImmutableCopy();
54 nl = (NamedList<?>) p.initArgs.get(INVARIANTS);
55 invariants = nl == null ? null : nl.getImmutableCopy();
56 nl = (NamedList<?>) p.initArgs.get(APPENDS);
57 appends = nl == null ? null : nl.getImmutableCopy();
58 }
59
60 public boolean matchPath(String name) {
61 if (paths == null) return false;
62 if (paths.contains(name)) return true;
63
64 for (String path : paths) {
65 if (matchPath(path, name)) return true;
66 }
67
68 return false;
69 }
70
71 private static boolean matchPath(String path, String name) {
72 List<String> pathSplit = StrUtils.splitSmart(path, '/');
73 List<String> nameSplit = StrUtils.splitSmart(name, '/');
74 int i = 0;
75 for (; i < nameSplit.size(); i++) {
76 String s = nameSplit.get(i);
77 String ps = pathSplit.size() > i ? pathSplit.get(i) : null;
78 if (ps == null) return false;
79 if (s.equals(ps)) continue;
80 if ("*".equals(ps) && nameSplit.size() == i + 1) return true;
81 if ("**".equals(ps)) return true;
82 return false;
83 }
84 String ps = pathSplit.size() > i ? pathSplit.get(i) : null;
85 return "*".equals(ps) || "**".equals(ps);
86 }
87
88 public void apply(PluginInfo info) {
89 if (!info.isFromSolrConfig()) {
90 // if this is a component implicitly defined in code it should be overridden by initPrams

Callers

nothing calls this directly

Calls 1

ofMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…