/
base_resource_catalog.java
66 lines (62 loc) · 2.35 KB
/
base_resource_catalog.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Autogenerated from isource/runtime/resources/base_resource_catalog.i
package ideal.runtime.resources;
import ideal.library.elements.*;
import ideal.library.resources.*;
import ideal.runtime.elements.*;
import ideal.library.patterns.*;
import ideal.runtime.patterns.*;
import javax.annotation.Nullable;
public class base_resource_catalog implements resource_catalog {
private static final pattern<Character> path_separator = new singleton_pattern<Character>('/');
private final resource_store the_resource_store;
private final immutable_list<string> path;
protected base_resource_catalog(final resource_store the_resource_store, final immutable_list<string> path) {
this.the_resource_store = the_resource_store;
this.path = path;
}
public @Override resource_identifier get_id() {
return new base_resource_identifier(the_resource_store, path);
}
public @Override resource_identifier resolve(final string name) {
if (name.is_empty()) {
return new base_resource_identifier(the_resource_store, path);
}
final immutable_list<immutable_list<Character>> components = path_separator.split(name);
boolean absolute = false;
int index;
final base_list<string> result = new base_list<string>();
if (components.get(0).is_empty()) {
if (the_resource_store.allow_up()) {
absolute = true;
} else { }
index = 1;
} else {
index = 0;
result.append_all(path);
}
while (index < components.size()) {
final string component = (string) components.get(index);
index += 1;
if (component.is_empty() || ideal.machine.elements.runtime_util.values_equal(component, resource_util.CURRENT_CATALOG)) {
continue;
} else if (ideal.machine.elements.runtime_util.values_equal(component, resource_util.PARENT_CATALOG)) {
if (result.is_empty()) { } else {
result.remove_last();
}
} else {
result.append(component);
}
}
if (absolute) {
result.prepend(new base_string(""));
}
return new base_resource_identifier(the_resource_store, result.frozen_copy());
}
public @Override resource_identifier resolve(final string name, final @Nullable extension the_extension) {
if (the_extension != null) {
return resolve(new base_string(name, the_extension.dot_name()));
} else {
return resolve(name);
}
}
}