use of jmri.server.web.spi.AngularRoute in project JMRI by JMRI.
the class JsonManifest method initialize.
private synchronized void initialize() {
if (!this.initialized) {
// NOI18N
Set<File> manifests = FileUtil.findFiles("manifest.json", "web");
ObjectMapper mapper = new ObjectMapper();
manifests.forEach((manifest) -> {
try {
JsonNode root = mapper.readTree(manifest);
root.path("scripts").forEach((script) -> {
if (!this.scripts.contains(script.asText())) {
this.scripts.add(script.asText());
}
});
root.path("styles").forEach((style) -> {
if (!this.styles.contains(style.asText())) {
this.styles.add(style.asText());
}
});
root.path("dependencies").forEach((dependency) -> {
if (!this.dependencies.contains(dependency.asText())) {
this.dependencies.add(dependency.asText());
}
});
root.path("navigation").forEach((navigation) -> {
JsonMenuItem menuItem = new JsonMenuItem(navigation);
if (!this.menuItems.contains(menuItem)) {
this.menuItems.add(menuItem);
}
});
root.path("routes").forEach((route) -> {
// NOI18N
String when = route.path("when").asText();
// NOI18N
String template = route.path("template").asText();
// NOI18N
String controller = route.path("controller").asText();
// NOI18N
String redirection = route.path("redirection").asText();
if (template.isEmpty() || controller.isEmpty()) {
template = null;
controller = null;
}
if (redirection.isEmpty()) {
redirection = null;
}
if (when != null && !when.isEmpty()) {
try {
this.routes.add(new AngularRoute(when, template, controller, redirection));
} catch (NullPointerException | IllegalArgumentException ex) {
log.error("Unable to add route for {}", when);
}
}
});
root.path("sources").forEach((source) -> {
URL url = FileUtil.findURL(source.asText());
if (url != null) {
this.sources.add(url);
}
});
} catch (IOException ex) {
log.error("Unable to read {}", manifest, ex);
}
});
this.initialized = true;
}
}
use of jmri.server.web.spi.AngularRoute in project JMRI by JMRI.
the class WebAppManager method getAngularRoutes.
public String getAngularRoutes(Profile profile, Locale locale) {
// NOI18N
StringJoiner routes = new StringJoiner("\n", "\n", "");
Set<AngularRoute> items = new HashSet<>();
this.getManifests(profile).forEach((WebManifest manifest) -> {
items.addAll(manifest.getAngularRoutes());
});
items.forEach((route) -> {
if (route.getRedirection() != null) {
// NOI18N
routes.add(String.format(" .when('%s', { redirectTo: '%s' })", route.getWhen(), route.getRedirection()));
} else if (route.getTemplate() != null && route.getController() != null) {
// NOI18N
routes.add(String.format(" .when('%s', { templateUrl: '%s', controller: '%s' })", route.getWhen(), route.getTemplate(), route.getController()));
}
});
return routes.toString();
}
Aggregations