use of org.jdom.input.SAXBuilder in project vcell by virtualcell.
the class VCActiveMQMonitor method startMonitors.
public void startMonitors(String filename) throws Exception {
File xml = new File(filename);
if (!xml.canRead()) {
throw new IOException("Can't read " + xml.getAbsolutePath());
}
SAXBuilder builder = new SAXBuilder();
Document config = builder.build(xml);
String deployFilename = null;
List<SiteConfig> sites = new ArrayList<>();
{
Element r = config.getRootElement();
Element f = requireElement(r, "deployXml");
deployFilename = f.getText();
if (LG.isInfoEnabled()) {
LG.info("reading configuration from" + deployFilename);
}
Element s = requireElement(r, "sites");
@SuppressWarnings("unchecked") List<Element> children = s.getChildren("site");
;
for (Element child : children) {
SiteConfig sc = parseMonitor(child);
LG.info(sc);
sites.add(sc);
}
}
Document doc = builder.build(deployFilename);
Element root = doc.getRootElement();
Element dp = requireElement(root, DEPLOYPROP);
Element jmsProv = requireElement(dp, PROVIDER);
Runnable sd = () -> closeMonitors();
Runtime.getRuntime().addShutdownHook(new Thread(sd));
String now = dateFormat.format(new Date());
for (SiteConfig siteConfig : sites) {
SiteUrl su = parseSite(jmsProv, siteConfig.name);
if (LG.isDebugEnabled()) {
LG.debug(jmsProv.getName() + " parsed to " + su);
}
if (su != null) {
String logname = su.jmsName + ".log";
if (LG.isInfoEnabled()) {
LG.debug("logging " + su.jmsName + " to " + logname);
}
// true -> append
PrintWriter pw = new PrintWriter(new FileWriter(logname, true));
pw.println("Commencing log of " + su.jmsName + " at " + now);
SiteMonitor sm = new SiteMonitor(su.jmsName, pw, su.url);
siteMonitors.add(sm);
sm.start();
int tstamp = siteConfig.timestampSeconds;
if (tstamp > 0) {
Runnable r = () -> timestamp(pw);
executorService.scheduleAtFixedRate(r, tstamp, tstamp, TimeUnit.SECONDS);
}
int flush = siteConfig.flushSeconds;
if (flush > 0) {
Runnable r = () -> flush(pw);
executorService.scheduleAtFixedRate(r, flush, flush, TimeUnit.SECONDS);
}
}
}
}
use of org.jdom.input.SAXBuilder in project vcell by virtualcell.
the class ExpressionMathMLParser method fromMathML.
/**
* Insert the method's description here.
* Creation date: (2/11/2002 1:34:06 PM)
* @return cbit.vcell.parser.Expression
* @param mathML java.lang.String
*/
public Expression fromMathML(String mathML) throws ExpressionException {
if (mathML == null || mathML.length() == 0) {
throw new ExpressionException("Invalid null or empty MathML string");
}
Element rootElement;
try {
SAXBuilder builder = new SAXBuilder(false);
Document sDoc = builder.build(new StringReader(mathML));
rootElement = sDoc.getRootElement();
} catch (Exception e) {
e.printStackTrace(System.out);
throw new ExpressionException("Unable to parse the xml string.");
}
Expression exp = fromMathML(rootElement);
return exp;
}
use of org.jdom.input.SAXBuilder in project yamcs-studio by yamcs.
the class PropertiesCopyDataTransfer method nativeToJava.
@Override
protected Object nativeToJava(TransferData transferData) {
if (!isSupportedType(transferData))
return null;
byte[] bytes = (byte[]) super.nativeToJava(transferData);
if (bytes == null)
return null;
try {
SAXBuilder saxBuilder = new SAXBuilder();
// $NON-NLS-1$
Document doc = saxBuilder.build(new ByteArrayInputStream(bytes));
Element root = doc.getRootElement();
List<String> propIDList = new ArrayList<String>();
AbstractWidgetModel widgetModel = null;
for (Object o : root.getChildren()) {
if (o instanceof Element) {
Element e = (Element) o;
if (e.getName().equals(CopyPropertiesAction.PROPID_ELEMENT))
for (Object po : e.getChildren()) {
Element pe = (Element) po;
propIDList.add(pe.getName());
}
else
widgetModel = XMLUtil.XMLElementToWidget(e);
}
}
return new PropertiesCopyData(widgetModel, propIDList);
} catch (Exception e) {
// $NON-NLS-1$
OPIBuilderPlugin.getLogger().log(Level.WARNING, "Failed to transfer XML to widget", e);
}
return null;
}
Aggregations