use of jmri.profile.Profile in project JMRI by JMRI.
the class JUnitUtil method resetProfileManager.
/**
* Use only if profile contents are not to be verified or modified in test.
* If a profile will be written to and its contents verified as part of a
* test use {@link #resetProfileManager(jmri.profile.Profile)} with a
* provided profile.
*
* The new profile will have the name {@literal TestProfile }, the id
* {@literal 00000000 }, and will be in the directory {@literal temp }
* within the sources working copy.
*/
public static void resetProfileManager() {
try {
Profile profile = new NullProfile("TestProfile", "00000000", FileUtil.getFile(FileUtil.SETTINGS));
resetProfileManager(profile);
} catch (FileNotFoundException ex) {
log.error("Settings directory \"{}\" does not exist", FileUtil.SETTINGS);
} catch (IOException | IllegalArgumentException ex) {
log.error("Unable to create profile", ex);
}
}
use of jmri.profile.Profile in project JMRI by JMRI.
the class WebAppServlet method processApp.
private void processApp(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(UTF8_TEXT_HTML);
Profile profile = ProfileManager.getDefault().getActiveProfile();
File cache = new File(ProfileUtils.getCacheDirectory(profile, this.getClass()), request.getLocale().toString());
FileUtil.createDirectory(cache);
// NOI18N
File index = new File(cache, "index.html");
if (!index.exists()) {
// NOI18N
String inComments = "-->\n%s<!--";
WebAppManager manager = getWebAppManager();
// Format elements for index.html
// 1 = railroad name
// 2 = scripts (in comments)
// 3 = stylesheets (in comments)
// 4 = body content (divs)
// 5 = help menu title
// 6 = help menu contents (in comments)
// 7 = personal menu title
// 8 = personal menu contents (in comments)
// 9 = power menu title
FileUtil.appendTextToFile(index, String.format(request.getLocale(), FileUtil.readURL(FileUtil.findURL("web/app/index.html")), // railroad name
ServletUtil.getInstance().getRailroadName(false), // scripts (in comments)
String.format(inComments, manager.getScriptTags(profile)), // stylesheets (in comments)
String.format(inComments, manager.getStyleTags(profile)), // body content (divs)
"<!-- -->", // help menu title
Bundle.getMessage(request.getLocale(), "help"), // help menu contents (in comments)
String.format(inComments, manager.getHelpMenuItems(profile, request.getLocale())), // personal menu title
Bundle.getMessage(request.getLocale(), "user"), // personal menu contents (in comments)
String.format(inComments, manager.getUserMenuItems(profile, request.getLocale())), // power menu title
Bundle.getMessage(request.getLocale(), "power")));
}
response.getWriter().print(FileUtil.readFile(index));
}
use of jmri.profile.Profile in project JMRI by JMRI.
the class WebAppServlet method processScript.
private void processScript(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(UTF8_APPLICATION_JAVASCRIPT);
Profile profile = ProfileManager.getDefault().getActiveProfile();
File cache = new File(ProfileUtils.getCacheDirectory(profile, this.getClass()), request.getLocale().toString());
FileUtil.createDirectory(cache);
// NOI18N
File script = new File(cache, "script.js");
if (!script.exists()) {
WebAppManager manager = getWebAppManager();
FileUtil.appendTextToFile(script, String.format(request.getLocale(), // NOI18N
FileUtil.readURL(FileUtil.findURL("web/app/script.js")), manager.getAngularDependencies(profile, request.getLocale()), manager.getAngularRoutes(profile, request.getLocale()), // NOI18N
String.format("\n $scope.navigationItems = %s;\n", manager.getNavigation(profile, request.getLocale())), manager.getAngularSources(profile, request.getLocale())));
}
response.getWriter().print(FileUtil.readFile(script));
}
use of jmri.profile.Profile in project JMRI by JMRI.
the class WebAppServlet method processAbout.
private void processAbout(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(UTF8_APPLICATION_JSON);
Profile profile = ProfileManager.getDefault().getActiveProfile();
ObjectMapper mapper = new ObjectMapper();
ObjectNode about = mapper.createObjectNode();
// NOI18N
about.put("additionalInfo", "TRADEMARKS AND LICENSE GO HERE");
// NOI18N
about.put("copyright", Version.getCopyright());
// NOI18N
about.put("title", WebServerPreferences.getDefault().getRailRoadName());
// NOI18N
about.put("imgAlt", Application.getApplicationName());
// assuming Application.getLogo() is relative to program:
// NOI18N
about.put("imgSrc", "/" + Application.getLogo());
// NOI18N
ArrayNode productInfo = about.putArray("productInfo");
productInfo.add(mapper.createObjectNode().put(NAME, Application.getApplicationName()).put(VALUE, Version.name()));
// NOI18N
productInfo.add(mapper.createObjectNode().put(NAME, Bundle.getMessage(request.getLocale(), "ActiveProfile")).put(VALUE, profile.getName()));
productInfo.add(mapper.createObjectNode().put(NAME, // NOI18N
"Java").put(VALUE, Bundle.getMessage(request.getLocale(), "JavaVersion", // NOI18N
System.getProperty("java.version", Bundle.getMessage(request.getLocale(), "Unknown")), // NOI18N
System.getProperty("java.vm.name", Bundle.getMessage(request.getLocale(), "Unknown")), // NOI18N
System.getProperty("java.vm.version", ""), // NOI18N
System.getProperty("java.vendor", Bundle.getMessage(request.getLocale(), "Unknown")))));
productInfo.add(mapper.createObjectNode().put(NAME, Bundle.getMessage(request.getLocale(), "Runtime")).put(VALUE, Bundle.getMessage(request.getLocale(), "RuntimeVersion", // NOI18N
System.getProperty("java.runtime.name", Bundle.getMessage(request.getLocale(), "Unknown")), // NOI18N
System.getProperty("java.runtime.version", ""))));
for (ConnectionConfig conn : InstanceManager.getDefault(ConnectionConfigManager.class)) {
if (!conn.getDisabled()) {
productInfo.add(mapper.createObjectNode().put(NAME, Bundle.getMessage(request.getLocale(), "ConnectionName", conn.getConnectionName())).put(VALUE, Bundle.getMessage(request.getLocale(), "ConnectionValue", conn.name(), conn.getInfo())));
}
}
response.getWriter().print(mapper.writeValueAsString(about));
}
use of jmri.profile.Profile in project JMRI by JMRI.
the class JmriJTablePersistenceManager method savePreferences.
@Override
public synchronized void savePreferences(Profile profile) {
log.debug("Saving preferences (dirty={})...", this.dirty);
Element element = new Element(TABLES_ELEMENT, TABLES_NAMESPACE);
if (!this.columns.isEmpty()) {
this.columns.entrySet().stream().map((entry) -> {
Element table = new Element("table").setAttribute("name", entry.getKey());
Element columnsElement = new Element("columns");
entry.getValue().entrySet().stream().map((column) -> {
Element columnElement = new Element("column").setAttribute("name", column.getKey());
if (column.getValue().getOrder() != -1) {
columnElement.setAttribute("order", Integer.toString(column.getValue().getOrder()));
}
if (column.getValue().getWidth() != -1) {
columnElement.setAttribute("width", Integer.toString(column.getValue().getWidth()));
}
columnElement.setAttribute("hidden", Boolean.toString(column.getValue().getHidden()));
return columnElement;
}).forEach((columnElement) -> {
columnsElement.addContent(columnElement);
});
table.addContent(columnsElement);
List<SortKey> keys = this.sortKeys.get(entry.getKey());
if (keys != null) {
Element sorter = new Element(SORT_ORDER);
keys.stream().forEach((key) -> {
sorter.addContent(new Element("sortKey").setAttribute("column", Integer.toString(key.getColumn())).setAttribute(SORT_ORDER, key.getSortOrder().name()));
});
table.addContent(sorter);
}
return table;
}).forEach((table) -> {
element.addContent(table);
});
}
try {
ProfileUtils.getUserInterfaceConfiguration(ProfileManager.getDefault().getActiveProfile()).putConfigurationFragment(JDOMUtil.toW3CElement(element), false);
} catch (JDOMException ex) {
log.error("Unable to save user preferences", ex);
}
this.dirty = false;
}
Aggregations