Search in sources :

Example 46 with Format

use of org.jdom2.output.Format in project scylla by bptlab.

the class SimulationManager method run.

/**
 * parses input, runs DesmoJ simulation experiment, writes BPS output logs
 */
public String run() {
    try {
        SAXBuilder builder = new SAXBuilder();
        if (globalConfigurationFilename == null || globalConfigurationFilename.isEmpty()) {
            throw new ScyllaValidationException("No global configuration provided.");
        } else {
            // parse global configuration XML
            Document gcDoc = builder.build(globalConfigurationFilename);
            Element gcRootElement = gcDoc.getRootElement();
            GlobalConfigurationParser globalConfigurationParser = new GlobalConfigurationParser(this);
            globalConfiguration = globalConfigurationParser.parse(gcDoc.getRootElement());
            String fileNameWithoutExtension = // filename.lastIndexOf("\\") +
            globalConfigurationFilename.substring(// 1,
            globalConfigurationFilename.lastIndexOf(Scylla.FILEDELIM) + 1, globalConfigurationFilename.lastIndexOf(".xml"));
            globalConfiguration.setFileNameWithoutExtension(fileNameWithoutExtension);
            // plugins to parse global configuration
            GlobalConfigurationParserPluggable.runPlugins(this, globalConfiguration, gcRootElement);
            DateTimeUtils.setZoneId(globalConfiguration.getZoneId());
        }
        CommonProcessElementsParser cpeParser = new CommonProcessElementsParser(this);
        for (String filename : processModelFilenames) {
            Document pmDoc = builder.build(filename);
            Element pmRootElement = pmDoc.getRootElement();
            // parse common process elements from XML (BPMN)
            CommonProcessElements commonProcessElementsFromFile = cpeParser.parse(pmRootElement);
            String fileNameWithoutExtension = // filename.lastIndexOf("\\") + 1,
            filename.substring(filename.lastIndexOf(Scylla.FILEDELIM) + 1, filename.lastIndexOf(".bpmn"));
            commonProcessElementsFromFile.setBpmnFileNameWithoutExtension(fileNameWithoutExtension);
            // plugins to parse common process elements
            CommonProcessElementsParserPluggable.runPlugins(this, commonProcessElementsFromFile, pmRootElement);
            // parse process model(s) from XML (BPMN)
            ProcessModelParser pmParser = new ProcessModelParser(this);
            pmParser.setCommonProcessElements(commonProcessElementsFromFile);
            ProcessModel processModelFromFile = pmParser.parse(pmDoc.getRootElement());
            String processId = processModelFromFile.getId();
            if (processModels.containsKey(processId)) {
                throw new ScyllaValidationException("Duplicate process model with id " + processId + ".");
            }
            // plugins to parse process model(s)
            ProcessModelParserPluggable.runPlugins(this, processModelFromFile, pmRootElement);
            processModels.put(processId, processModelFromFile);
            commonProcessElements.put(processId, commonProcessElementsFromFile);
        }
        SimulationConfigurationParser simParser = new SimulationConfigurationParser(this);
        // parse each simulation configuration XML
        for (String filename : simulationConfigurationFilenames) {
            Document scDoc = builder.build(filename);
            SimulationConfiguration simulationConfigurationFromFile = simParser.parse(scDoc.getRootElement());
            String processId = simulationConfigurationFromFile.getProcessModel().getId();
            if (simulationConfigurations.containsKey(processId)) {
                throw new ScyllaValidationException("Multiple simulation configurations for process with id " + processId + ".");
            }
            // plugins to parse simulation configuration
            SimulationConfigurationParserPluggable.runPlugins(this, simulationConfigurationFromFile, scDoc);
            simulationConfigurations.put(processId, simulationConfigurationFromFile);
        }
    } catch (JDOMException | IOException | ScyllaValidationException e) {
        DebugLogger.error(e.getMessage());
        e.printStackTrace();
    }
    // TODO validate resources in process models (i.e. check if they are all covered in resource data)
    TimeUnit epsilon = TimeUnit.SECONDS;
    DateTimeUtils.setReferenceTimeUnit(epsilon);
    String experimentName = Long.toString((new Date()).getTime());
    Experiment.setEpsilon(epsilon);
    Experiment exp = new Experiment(experimentName, experimentOutputFolder);
    exp.setShowProgressBar(false);
    // XXX each simulation configuration may have its own seed
    Long randomSeed = globalConfiguration.getRandomSeed();
    if (randomSeed != null) {
        exp.setSeedGenerator(randomSeed);
    } else {
        exp.setSeedGenerator((new Random()).nextLong());
    }
    SimulationModel sm = new SimulationModel(null, globalConfiguration, commonProcessElements, processModels, simulationConfigurations, enableBpsLogging, enableDesLogging);
    sm.connectToExperiment(exp);
    int lambda = 1;
    if (sm.getEndDateTime() != null) {
        // have to use time which is slightly after intended end time (epsilon)
        // otherwise the AbortProcessSimulationEvent(s) may not fire
        long simulationDuration = DateTimeUtils.getDuration(sm.getStartDateTime(), sm.getEndDateTime());
        TimeInstant simulationTimeInstant = new TimeInstant(simulationDuration + lambda, epsilon);
        exp.stop(simulationTimeInstant);
        exp.tracePeriod(new TimeInstant(0), simulationTimeInstant);
        exp.debugPeriod(new TimeInstant(0), simulationTimeInstant);
    } else {
        exp.traceOn(new TimeInstant(0));
        exp.debugOn(new TimeInstant(0));
    }
    if (!enableDesLogging) {
        exp.debugOff(new TimeInstant(0));
        exp.traceOff(new TimeInstant(0));
    }
    exp.start();
    exp.report();
    exp.finish();
    try {
        // log process execution
        // log resources, process, tasks
        StringBuilder strb = new StringBuilder(globalConfigurationFilename.substring(0, globalConfigurationFilename.lastIndexOf(Scylla.FILEDELIM) + 1));
        outputPath = strb.substring(0, strb.lastIndexOf(Scylla.FILEDELIM) + 1) + "output_" + new SimpleDateFormat("yy_MM_dd_HH_mm_ss").format(new Date()) + Scylla.FILEDELIM;
        File outputPathFolder = new File(outputPath);
        if (!outputPathFolder.exists())
            outputPathFolder.mkdir();
        OutputLoggerPluggable.runPlugins(sm, outputPath);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return outputPath;
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) Element(org.jdom2.Element) Document(org.jdom2.Document) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) Random(java.util.Random) TimeUnit(java.util.concurrent.TimeUnit) SimulationConfigurationParser(de.hpi.bpt.scylla.parser.SimulationConfigurationParser) CommonProcessElements(de.hpi.bpt.scylla.model.process.CommonProcessElements) SAXBuilder(org.jdom2.input.SAXBuilder) Experiment(desmoj.core.simulator.Experiment) IOException(java.io.IOException) JDOMException(org.jdom2.JDOMException) CommonProcessElementsParser(de.hpi.bpt.scylla.parser.CommonProcessElementsParser) Date(java.util.Date) SimulationConfiguration(de.hpi.bpt.scylla.model.configuration.SimulationConfiguration) ProcessModelParser(de.hpi.bpt.scylla.parser.ProcessModelParser) GlobalConfigurationParser(de.hpi.bpt.scylla.parser.GlobalConfigurationParser) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel) TimeInstant(desmoj.core.simulator.TimeInstant)

Example 47 with Format

use of org.jdom2.output.Format in project jPOS by jpos.

the class SelectDestination method setConfiguration.

/**
 * @param xml Configuration element
 * @throws ConfigurationException
 *
 * SelectDestination expects an XML configuration in the following format:
 *
 * <endpoint destination="XXX">
 *   4000000..499999
 *   4550000..455999
 *   5
 * </endpoint>
 */
public void setConfiguration(Element xml) throws ConfigurationException {
    for (Element ep : xml.getChildren("endpoint")) {
        String destination = ep.getAttributeValue("destination");
        StringTokenizer st = new StringTokenizer(ep.getText());
        while (st.hasMoreElements()) {
            BinRange br = new BinRange(destination, st.nextToken());
            binranges.add(br);
        }
    }
    for (Element re : xml.getChildren("regexp")) {
        String destination = re.getAttributeValue("destination");
        regexps.add(new PanRegExp(re.getAttributeValue("destination"), re.getTextTrim()));
    }
    LogEvent evt = Log.getLog(Q2.LOGGER_NAME, this.getClass().getName()).createLogEvent("config");
    for (PanRegExp r : regexps) evt.addMessage("00:" + r);
    for (BinRange r : binranges) evt.addMessage(r);
    Logger.log(evt);
}
Also used : LogEvent(org.jpos.util.LogEvent) Element(org.jdom2.Element)

Example 48 with Format

use of org.jdom2.output.Format in project jspwiki by apache.

the class WysiwygEditingRenderer method getString.

/**
 *  {@inheritDoc}
 */
public String getString() throws IOException {
    Element rootElement = m_document.getRootElement();
    processChildren(rootElement);
    m_document.setContext(m_context);
    XMLOutputter output = new XMLOutputter();
    StringWriter out = new StringWriter();
    Format fmt = Format.getRawFormat();
    fmt.setExpandEmptyElements(false);
    fmt.setLineSeparator(LINEBREAK);
    output.setFormat(fmt);
    output.outputElementContent(m_document.getRootElement(), out);
    return out.toString();
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) Format(org.jdom2.output.Format) StringWriter(java.io.StringWriter) Element(org.jdom2.Element)

Example 49 with Format

use of org.jdom2.output.Format in project jspwiki by apache.

the class XHTMLRenderer method getString.

/**
 *  {@inheritDoc}
 */
public String getString() throws IOException {
    m_document.setContext(m_context);
    CustomXMLOutputProcessor processor = new CustomXMLOutputProcessor();
    XMLOutputter output = new XMLOutputter(processor);
    StringWriter out = new StringWriter();
    Format fmt = Format.getRawFormat();
    fmt.setExpandEmptyElements(false);
    fmt.setLineSeparator(LINEBREAK);
    output.setFormat(fmt);
    output.outputElementContent(m_document.getRootElement(), out);
    String result = out.toString();
    return result;
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) Format(org.jdom2.output.Format) StringWriter(java.io.StringWriter)

Example 50 with Format

use of org.jdom2.output.Format in project jspwiki by apache.

the class AtomFeed method getString.

/**
 *  {@inheritDoc}
 */
@Override
public String getString() {
    Element root = getElement("feed");
    WikiEngine engine = m_wikiContext.getEngine();
    Date lastModified = new Date(0L);
    for (Iterator i = m_entries.iterator(); i.hasNext(); ) {
        Entry e = (Entry) i.next();
        if (e.getPage().getLastModified().after(lastModified))
            lastModified = e.getPage().getLastModified();
    }
    // 
    // Mandatory parts
    // 
    root.addContent(getElement("title").setText(getChannelTitle()));
    root.addContent(getElement("id").setText(getFeedID()));
    root.addContent(getElement("updated").setText(DateFormatUtils.formatUTC(lastModified, RFC3339FORMAT)));
    // 
    // Optional
    // 
    // root.addContent( getElement("author").addContent(getElement("name").setText(format())))
    root.addContent(getElement("link").setAttribute("href", engine.getBaseURL()));
    root.addContent(getElement("generator").setText("JSPWiki " + Release.VERSTR));
    String rssFeedURL = engine.getURL(WikiContext.NONE, "rss.jsp", "page=" + engine.encodeName(m_wikiContext.getPage().getName()) + "&mode=" + m_mode + "&type=atom", true);
    Element self = getElement("link").setAttribute("rel", "self");
    self.setAttribute("href", rssFeedURL);
    root.addContent(self);
    // 
    // Items
    // 
    root.addContent(getItems());
    // 
    // aaand output
    // 
    XMLOutputter output = new XMLOutputter();
    output.setFormat(Format.getPrettyFormat());
    try {
        StringWriter res = new StringWriter();
        output.output(root, res);
        return res.toString();
    } catch (IOException e) {
        return null;
    }
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) StringWriter(java.io.StringWriter) Element(org.jdom2.Element) Iterator(java.util.Iterator) IOException(java.io.IOException) WikiEngine(org.apache.wiki.WikiEngine) Date(java.util.Date)

Aggregations

Element (org.jdom2.Element)56 Document (org.jdom2.Document)20 XMLOutputter (org.jdom2.output.XMLOutputter)19 IOException (java.io.IOException)15 StringWriter (java.io.StringWriter)9 Attribute (org.jdom2.Attribute)9 Format (org.jdom2.output.Format)7 File (java.io.File)5 ArrayList (java.util.ArrayList)5 MCRRestAPIError (org.mycore.restapi.v1.errors.MCRRestAPIError)5 MCRRestAPIException (org.mycore.restapi.v1.errors.MCRRestAPIException)5 JsonWriter (com.google.gson.stream.JsonWriter)4 Date (java.util.Date)4 SAXBuilder (org.jdom2.input.SAXBuilder)4 SimpleDateFormat (java.text.SimpleDateFormat)3 JDOMException (org.jdom2.JDOMException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MalformedURLException (java.net.MalformedURLException)2 List (java.util.List)2 JComponent (javax.swing.JComponent)2