Search in sources :

Example 66 with SAXBuilder

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);
            }
        }
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) Element(org.jdom.Element) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.jdom.Document) Date(java.util.Date) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 67 with SAXBuilder

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;
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) Element(org.jdom.Element) StringReader(java.io.StringReader) Document(org.jdom.Document)

Example 68 with SAXBuilder

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;
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) PropertiesCopyData(org.csstudio.opibuilder.datadefinition.PropertiesCopyData) ByteArrayInputStream(java.io.ByteArrayInputStream) Element(org.jdom.Element) ArrayList(java.util.ArrayList) Document(org.jdom.Document) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

SAXBuilder (org.jdom.input.SAXBuilder)68 Document (org.jdom.Document)51 Element (org.jdom.Element)47 IOException (java.io.IOException)27 JDOMException (org.jdom.JDOMException)24 InputStream (java.io.InputStream)18 StringReader (java.io.StringReader)13 HttpMethod (org.apache.commons.httpclient.HttpMethod)10 XPath (org.jdom.xpath.XPath)9 File (java.io.File)7 ArrayList (java.util.ArrayList)7 List (java.util.List)7 XMLOutputter (org.jdom.output.XMLOutputter)5 Nullable (org.jetbrains.annotations.Nullable)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 PostMethod (org.apache.commons.httpclient.methods.PostMethod)4 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)4 Format (org.jdom.output.Format)4 NotNull (org.jetbrains.annotations.NotNull)4 Logger (com.intellij.openapi.diagnostic.Logger)3