use of org.jdom.input.SAXBuilder in project openremote by openremote.
the class SequenceNumberPersistencyManager method load.
public synchronized void load() {
if (!fileExists()) {
return;
}
File file = new File(filePath);
SAXBuilder builder = new SAXBuilder();
Document doc = null;
try {
doc = builder.build(file);
} catch (JDOMException e) {
LOG.severe("Failed to load sequence number file: '" + file.getPath() + "' because: " + e.getMessage());
e.printStackTrace();
return;
} catch (IOException e) {
LOG.severe("Failed to load sequence number file: '" + file.getPath() + "' because: " + e.getMessage());
e.printStackTrace();
return;
}
map.clear();
Element root = doc.getRootElement();
@SuppressWarnings("unchecked") List<Element> itemElements = root.getChildren(XML_TAG_SEQUENCE_NUMBER_ITEM);
for (Element itemElement : itemElements) {
Element keyElement = itemElement.getChild(XML_TAG_NETWORK_KEY);
Element addressElement = itemElement.getChild(XML_TAG_ADDRESS);
Element numberElement = itemElement.getChild(XML_TAG_SEQUENCE_NUMBER);
if (keyElement == null || addressElement == null | numberElement == null) {
continue;
}
String key = keyElement.getText();
String address = addressElement.getText();
String number = numberElement.getText();
if (!map.containsKey(key)) {
map.put(key, new HashMap<String, Integer>());
}
try {
map.get(key).put(address, Integer.valueOf(number));
} catch (NumberFormatException e) {
LOG.severe("Error while loading sequence number file: '" + file.getPath() + "' because: " + e.getMessage());
e.printStackTrace();
continue;
}
}
}
use of org.jdom.input.SAXBuilder in project checkstyle-idea by jshiell.
the class ConfigurationLocation method extractProperties.
private List<String> extractProperties(@Nullable final InputStream inputStream, @NotNull final ClassLoader checkstyleClassLoader) {
if (inputStream != null) {
try {
final SAXBuilder saxBuilder = new SAXBuilder();
saxBuilder.setEntityResolver(new CheckStyleEntityResolver(this, checkstyleClassLoader));
final Document configDoc = saxBuilder.build(inputStream);
return extractProperties(configDoc.getRootElement());
} catch (Exception e) {
LOG.warn("CheckStyle file could not be parsed for properties.", e);
}
}
return new ArrayList<>();
}
use of org.jdom.input.SAXBuilder in project che by eclipse.
the class EffectivePomWriter method addMavenNamespace.
/**
* method from org.apache.maven.plugins.help.AbstractEffectiveMojo
* Add a Pom/Settings namespaces to the effective XML content.
*
* @param effectiveXml not null the effective POM or Settings
* @param isPom if <code>true</code> add the Pom xsd url, otherwise add the settings xsd url.
* @return the content of the root element, i.e. <project/> or <settings/> with the Maven namespace or
* the original <code>effective</code> if an error occurred.
* @see #POM_XSD_URL
* @see #SETTINGS_XSD_URL
*/
protected static String addMavenNamespace(String effectiveXml, boolean isPom) {
SAXBuilder builder = new SAXBuilder();
try {
Document document = builder.build(new StringReader(effectiveXml));
Element rootElement = document.getRootElement();
// added namespaces
Namespace pomNamespace = Namespace.getNamespace("", "http://maven.apache.org/POM/4.0.0");
rootElement.setNamespace(pomNamespace);
Namespace xsiNamespace = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
rootElement.addNamespaceDeclaration(xsiNamespace);
if (rootElement.getAttribute("schemaLocation", xsiNamespace) == null) {
rootElement.setAttribute("schemaLocation", "http://maven.apache.org/POM/4.0.0 " + (isPom ? POM_XSD_URL : SETTINGS_XSD_URL), xsiNamespace);
}
ElementFilter elementFilter = new ElementFilter(Namespace.getNamespace(""));
for (Iterator<?> i = rootElement.getDescendants(elementFilter); i.hasNext(); ) {
Element e = (Element) i.next();
e.setNamespace(pomNamespace);
}
StringWriter w = new StringWriter();
Format format = Format.getPrettyFormat();
XMLOutputter out = new XMLOutputter(format);
out.output(document.getRootElement(), w);
return w.toString();
} catch (JDOMException e) {
return effectiveXml;
} catch (IOException e) {
return effectiveXml;
}
}
use of org.jdom.input.SAXBuilder in project intellij-plugins by JetBrains.
the class JabberFacadeImpl method getServers.
public String[] getServers() {
SAXBuilder saxBuilder = new SAXBuilder();
try {
Document document = saxBuilder.build(getClass().getResource("servers.xml"));
Element rootElement = document.getRootElement();
List children = rootElement.getChildren("item", rootElement.getNamespace());
List<String> result = new ArrayList<>();
for (Object aChildren : children) {
Element element = (Element) aChildren;
result.add(element.getAttributeValue("jid"));
}
return ArrayUtil.toStringArray(result);
} catch (JDOMException e) {
LOG.error(e.getMessage(), e);
} catch (IOException e) {
LOG.error(e.getMessage(), e);
}
return new String[] { "jabber.org" };
}
use of org.jdom.input.SAXBuilder in project intellij-plugins by JetBrains.
the class ProjectsData method serialize.
public Element serialize() {
XStream xStream = new XStream(new DomDriver());
String s = xStream.toXML(myStatus);
try {
return new SAXBuilder().build(new StringReader(s)).getRootElement();
} catch (JDOMException e) {
LOG.error(e.getMessage(), e);
} catch (IOException e) {
LOG.error(e.getMessage(), e);
}
return new Element("");
}
Aggregations