use of org.jdom2.Namespace in project JMRI by JMRI.
the class LocaleSelectorTest method testFindPartialCode.
public void testFindPartialCode() {
LocaleSelector.suffixes = new String[] { "kl_KL", "kl" };
Namespace xml = Namespace.XML_NAMESPACE;
Element el = new Element("foo").setAttribute("temp", "a").addContent(new Element("temp").setAttribute("lang", "aa_BB", xml).addContent("b")).addContent(new Element("temp").setAttribute("lang", "kl", xml).addContent("c")).addContent(new Element("temp").setAttribute("lang", "kl_AA", xml).addContent("d"));
String result = LocaleSelector.getAttribute(el, "temp");
Assert.assertEquals("find default", "c", result);
}
use of org.jdom2.Namespace in project JMRI by JMRI.
the class LocaleSelectorTest method testFindFullCode.
public void testFindFullCode() {
LocaleSelector.suffixes = new String[] { "kl_KL", "kl" };
Namespace xml = Namespace.XML_NAMESPACE;
Element el = new Element("foo").setAttribute("temp", "a").addContent(new Element("temp").setAttribute("lang", "aa_BB", xml).addContent("b")).addContent(new Element("temp").setAttribute("lang", "kl", xml).addContent("b")).addContent(new Element("temp").setAttribute("lang", "kl_KL", xml).addContent("c"));
String result = LocaleSelector.getAttribute(el, "temp");
Assert.assertEquals("find default", "c", result);
}
use of org.jdom2.Namespace in project JMRI by JMRI.
the class ConnectionConfigManager method initialize.
@Override
public void initialize(Profile profile) throws InitializationException {
if (!isInitialized(profile)) {
log.debug("Initializing...");
Element sharedConnections = null;
Element perNodeConnections = null;
try {
sharedConnections = JDOMUtil.toJDOMElement(ProfileUtils.getAuxiliaryConfiguration(profile).getConfigurationFragment(CONNECTIONS, NAMESPACE, true));
} catch (NullPointerException ex) {
// Normal if this is a new profile
log.info("No connections configured.");
log.debug("Null pointer thrown reading shared configuration.", ex);
}
if (sharedConnections != null) {
try {
perNodeConnections = JDOMUtil.toJDOMElement(ProfileUtils.getAuxiliaryConfiguration(profile).getConfigurationFragment(CONNECTIONS, NAMESPACE, false));
} catch (NullPointerException ex) {
// Normal if the profile has not been used on this computer
log.info("No local configuration found.");
log.debug("Null pointer thrown reading local configuration.", ex);
// TODO: notify user
}
for (Element shared : sharedConnections.getChildren(CONNECTION)) {
Element perNode = shared;
String className = shared.getAttributeValue(CLASS);
// NOI18N
String userName = shared.getAttributeValue(USER_NAME, "");
// NOI18N
String systemName = shared.getAttributeValue(SYSTEM_NAME, "");
// NOI18N
String manufacturer = shared.getAttributeValue(MANUFACTURER, "");
log.debug("Read shared connection {}:{} ({}) class {}", userName, systemName, manufacturer, className);
if (perNodeConnections != null) {
for (Element e : perNodeConnections.getChildren(CONNECTION)) {
if (systemName.equals(e.getAttributeValue(SYSTEM_NAME))) {
perNode = e;
className = perNode.getAttributeValue(CLASS);
// NOI18N
userName = perNode.getAttributeValue(USER_NAME, "");
// NOI18N
manufacturer = perNode.getAttributeValue(MANUFACTURER, "");
log.debug("Read perNode connection {}:{} ({}) class {}", userName, systemName, manufacturer, className);
}
}
}
try {
log.debug("Creating connection {}:{} ({}) class {}", userName, systemName, manufacturer, className);
XmlAdapter adapter = (XmlAdapter) Class.forName(className).newInstance();
ConnectionConfigManagerErrorHandler handler = new ConnectionConfigManagerErrorHandler();
adapter.setExceptionHandler(handler);
if (!adapter.load(shared, perNode)) {
log.error("Unable to create {} for {}, load returned false", className, shared);
// NOI18N
String english = Bundle.getMessage(Locale.ENGLISH, "ErrorSingleConnection", userName, systemName);
// NOI18N
String localized = Bundle.getMessage("ErrorSingleConnection", userName, systemName);
this.addInitializationException(profile, new InitializationException(english, localized));
}
handler.exceptions.forEach((exception) -> {
this.addInitializationException(profile, exception);
});
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
log.error("Unable to create {} for {}", className, shared, ex);
// NOI18N
String english = Bundle.getMessage(Locale.ENGLISH, "ErrorSingleConnection", userName, systemName);
// NOI18N
String localized = Bundle.getMessage("ErrorSingleConnection", userName, systemName);
this.addInitializationException(profile, new InitializationException(english, localized, ex));
} catch (Exception ex) {
log.error("Unable to load {} into {}", shared, className, ex);
// NOI18N
String english = Bundle.getMessage(Locale.ENGLISH, "ErrorSingleConnection", userName, systemName);
// NOI18N
String localized = Bundle.getMessage("ErrorSingleConnection", userName, systemName);
this.addInitializationException(profile, new InitializationException(english, localized, ex));
}
}
}
setInitialized(profile, true);
List<Exception> exceptions = this.getInitializationExceptions(profile);
if (exceptions.size() == 1) {
if (exceptions.get(0) instanceof InitializationException) {
throw (InitializationException) exceptions.get(0);
} else {
throw new InitializationException(exceptions.get(0));
}
} else if (exceptions.size() > 1) {
// NOI18N
String english = Bundle.getMessage(Locale.ENGLISH, "ErrorMultipleConnections");
// NOI18N
String localized = Bundle.getMessage("ErrorMultipleConnections");
throw new InitializationException(english, localized);
}
log.debug("Initialized...");
}
}
use of org.jdom2.Namespace in project JMRI by JMRI.
the class RevHistoryXml method revisionElement.
static Element revisionElement(Revision r) {
Element rev = new Element("revision", NAMESPACE);
Element revnumber = new Element("revnumber", NAMESPACE);
revnumber.addContent("" + r.revnumber);
rev.addContent(revnumber);
Element date = new Element("date", NAMESPACE);
date.addContent(r.date);
rev.addContent(date);
Element authorinitials = new Element("authorinitials", NAMESPACE);
authorinitials.addContent(r.authorinitials);
rev.addContent(authorinitials);
Element revremark = new Element("revremark", NAMESPACE);
revremark.addContent(r.revremark);
rev.addContent(revremark);
return rev;
}
use of org.jdom2.Namespace in project JMRI by JMRI.
the class RevHistoryXml method loadRevision.
static void loadRevision(RevHistory r, Element e) {
Element s;
Namespace n = Namespace.getNamespace(NAMESPACE);
int revnumber = 0;
s = e.getChild("revnumber", n);
if (s != null) {
String c = s.getText();
revnumber = Integer.parseInt(c);
}
String date = null;
s = e.getChild("date", n);
if (s != null) {
date = s.getText();
}
String authorinitials = null;
s = e.getChild("authorinitials", n);
if (s != null) {
authorinitials = s.getText();
}
String revremark = null;
s = e.getChild("revremark", n);
if (s != null) {
revremark = s.getText();
}
r.addRevision(revnumber, date, authorinitials, revremark);
}
Aggregations