File: RootLoader.java

package info (click to toggle)
python-schema-salad 8.9.20251102115403-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,060 kB
  • sloc: python: 19,247; cpp: 2,631; cs: 1,869; java: 1,341; makefile: 187; xml: 184; sh: 103; javascript: 46
file content (105 lines) | stat: -rw-r--r-- 3,734 bytes parent folder | download | duplicates (3)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package ${package}.utils;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;

public class RootLoader {
  public static ${root_loader_instance_type} loadDocument(
      final Map<String, Object> doc, final String baseUri_, final LoadingOptions loadingOptions_) {
    final String baseUri = ensureBaseUri(baseUri_);
    LoadingOptions loadingOptions = loadingOptions_;
    if (loadingOptions == null) {
      loadingOptions = new LoadingOptionsBuilder().setFileUri(baseUri).build();
    }
    return LoaderInstances.${root_loader_name}.documentLoad(doc, baseUri, loadingOptions);
  }

  public static ${root_loader_instance_type} loadDocument(
      final Map<String, Object> doc, final String baseUri) {
    return loadDocument(doc, baseUri, null);
  }

  public static ${root_loader_instance_type} loadDocument(final Map<String, Object> doc) {
    return loadDocument(doc, ensureBaseUri(null));
  }

  public static ${root_loader_instance_type} loadDocument(final Path path) {
    return loadDocument(readPath(path), path.toUri().toString());
  }

  public static ${root_loader_instance_type} loadDocument(final Path path, String baseUri) {
    return loadDocument(readPath(path), baseUri);
  }

  public static ${root_loader_instance_type} loadDocument(
      final Path path, LoadingOptions loadingOptions) {
    return loadDocument(readPath(path), loadingOptions);
  }

  public static ${root_loader_instance_type} loadDocument(
final Path path, String baseUri, LoadingOptions loadingOptions) {
    return loadDocument(readPath(path), baseUri, loadingOptions);
  }

  public static ${root_loader_instance_type} loadDocument(final File file) {
    return loadDocument(file.toPath());
  }

  public static ${root_loader_instance_type} loadDocument(final File file, String baseUri) {
    return loadDocument(file.toPath(), baseUri);
  }

  public static ${root_loader_instance_type} loadDocument(final File file, LoadingOptions loadingOptions) {
    return loadDocument(file.toPath(), loadingOptions);
  }

  public static ${root_loader_instance_type} loadDocument(
      final File file, String baseUri, LoadingOptions loadingOptions) {
    return loadDocument(file.toPath(), baseUri, loadingOptions);
  }

  public static ${root_loader_instance_type} loadDocument(final String doc) {
    return loadDocument(doc, ensureBaseUri(null));
  }

  public static ${root_loader_instance_type} loadDocument(final String doc, final LoadingOptions loadingOptions) {
    return loadDocument(doc, ensureBaseUri(null), loadingOptions);
  }

  public static ${root_loader_instance_type} loadDocument(final String doc, final String uri) {
    return loadDocument(doc, uri, null);
  }

  public static ${root_loader_instance_type} loadDocument(
      final String doc, final String uri_, final LoadingOptions loadingOptions_) {
    final String uri = ensureBaseUri(uri_);
    LoadingOptions loadingOptions = loadingOptions_;
    if (loadingOptions == null) {
      loadingOptions = new LoadingOptionsBuilder().setFileUri(uri).build();
    }
    final Map<String, Object> result = YamlUtils.mapFromString(doc);
    loadingOptions.idx.put(uri, result);
    return loadDocument(result, uri, loadingOptions);
  }

  static String readPath(final Path path) {
    try {
      return new String(Files.readAllBytes(path), "UTF8");
    } catch (final IOException e) {
      throw new RuntimeException(e);
    }
  }

  static String ensureBaseUri(final String baseUri_) {
    String baseUri = baseUri_;
    if(baseUri == null) {
      baseUri = Uris.fileUri(Paths.get(".").toAbsolutePath().normalize().toString()) + "/";
    }
    return baseUri;
  }

}