Search in sources :

Example 91 with SAXBuilder

use of org.jdom2.input.SAXBuilder in project cas by apereo.

the class AbstractSamlObjectBuilder method constructDocumentFromXml.

/**
 * Construct document from xml.
 *
 * @param xmlString the xml string
 * @return the document
 */
@SuppressWarnings("java:S2755")
public static Document constructDocumentFromXml(final String xmlString) {
    LOGGER.trace("Attempting to construct an instance of Document from xml: [{}]", xmlString);
    try {
        val builder = new SAXBuilder();
        builder.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
        builder.setFeature("http://xml.org/sax/features/external-general-entities", false);
        builder.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
        return builder.build(new ByteArrayInputStream(xmlString.getBytes(Charset.defaultCharset())));
    } catch (final Exception e) {
        LoggingUtils.error(LOGGER, e);
        return null;
    }
}
Also used : lombok.val(lombok.val) SAXBuilder(org.jdom2.input.SAXBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 92 with SAXBuilder

use of org.jdom2.input.SAXBuilder in project jena by apache.

the class GMLReader method newSAXBuilder.

// ---- XXE safe SAXBuilder
private static SAXBuilder newSAXBuilder() {
    SAXBuilder builder = new SAXBuilder();
    builder.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
    builder.setFeature("http://xml.org/sax/features/external-general-entities", false);
    builder.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
    builder.setExpandEntities(false);
    return builder;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder)

Example 93 with SAXBuilder

use of org.jdom2.input.SAXBuilder in project jPOS by jpos.

the class QThreadPoolExecutorTest method getDocument.

protected Document getDocument(InputStream is) {
    SAXBuilder builder = new SAXBuilder();
    builder.setValidation(false);
    Document doc = null;
    try {
        doc = builder.build(is);
        return doc;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Document(org.jdom2.Document) ConfigurationException(org.jpos.core.ConfigurationException) NotFoundException(org.jpos.util.NameRegistrar.NotFoundException) DataConversionException(org.jdom2.DataConversionException)

Example 94 with SAXBuilder

use of org.jdom2.input.SAXBuilder in project scylla by bptlab.

the class SimulationManager method parseInput.

protected void parseInput() throws ScyllaValidationException, JDOMException, IOException {
    SAXBuilder builder = new SAXBuilder();
    if (globalConfigurationFilename == null || globalConfigurationFilename.isEmpty())
        throw new ScyllaValidationException("No global configuration provided.");
    // parse global configuration XML
    Document gcDoc = builder.build(globalConfigurationFilename);
    Element gcRootElement = gcDoc.getRootElement();
    parseGlobalConfiguration(gcRootElement);
    CommonProcessElementsParser cpeParser = new CommonProcessElementsParser(this);
    // parse each process model XML (.bpmn)
    for (String filename : processModelFilenames) {
        Document pmDoc = builder.build(filename);
        parseProcessCommonsAndModel(cpeParser, pmDoc.getRootElement(), filename);
    }
    SimulationConfigurationParser simParser = new SimulationConfigurationParser(this);
    // parse each simulation configuration XML
    for (String filename : simulationConfigurationFilenames) {
        Document scDoc = builder.build(filename);
        parseSimulationConfiguration(simParser, scDoc);
    }
}
Also used : SimulationConfigurationParser(de.hpi.bpt.scylla.parser.SimulationConfigurationParser) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) Document(org.jdom2.Document) CommonProcessElementsParser(de.hpi.bpt.scylla.parser.CommonProcessElementsParser)

Example 95 with SAXBuilder

use of org.jdom2.input.SAXBuilder in project scylla by bptlab.

the class SimulationConfigurationPane method open.

@Override
protected void open() throws JDOMException, IOException {
    buttonClosefile.setEnabled(true);
    try {
        creator = SimulationConfigurationCreator.createFromFile(getFile().getPath());
    } catch (NotAValidFileException e1) {
        setFile(null);
        e1.printStackTrace();
        return;
    }
    if (gcc != null)
        creator.setGCC(gcc);
    Element modelRoot = null;
    if (bpmnPath != null && !bpmnPath.isEmpty())
        try {
            Document doc;
            SAXBuilder builder = new SAXBuilder();
            doc = builder.build(bpmnPath);
            modelRoot = doc.getRootElement();
            creator.setModel(modelRoot, false);
        } catch (JDOMException | IOException e) {
            e.printStackTrace();
        } catch (NoProcessSpecifiedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NotAuthorizedToOverrideException e) {
            int override = showModelOverrideConfirmationDialog(e);
            if (override == 0)
                try {
                    creator.setModel(modelRoot, true);
                } catch (NoProcessSpecifiedException | NotAuthorizedToOverrideException e1) {
                    e1.printStackTrace();
                }
            else
                clearBpmnPath();
            e.printStackTrace();
        }
    setChangeFlag(true);
    textfieldId.loadSavedValue();
    if (creator.getRandomSeed() != null) {
        textfieldSeed.setValue(creator.getRandomSeed());
    }
    if (creator.getProcessInstances() != null)
        spinnerNOI.setValue(Integer.parseInt(creator.getProcessInstances()));
    String startDt = creator.getStartDateTime();
    if (startDt != null) {
        startDateTime = ZonedDateTime.parse(startDt);
        textfieldStartTime.setValue(startDateTime.toLocalTime());
        textfieldStartDate.setValue(startDateTime.toLocalDate());
    }
    String endDt = creator.getEndDateTime();
    if (endDt != null) {
        checkboxUnlimited.setSelected(false);
        endDateTime = ZonedDateTime.parse(endDt);
        textfieldEndTime.setValue(endDateTime.toLocalTime());
        textfieldEndDate.setValue(endDateTime.toLocalDate());
    } else {
        checkboxUnlimited.setSelected(true);
        textfieldEndDate.getComponent().setEnabled(false);
        textfieldEndTime.getComponent().setEnabled(false);
    }
    importCreatorElements();
    setChangeFlag(false);
    setEnabled(true);
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) NotAuthorizedToOverrideException(de.hpi.bpt.scylla.creation.SimulationConfiguration.SimulationConfigurationCreator.NotAuthorizedToOverrideException) Element(org.jdom2.Element) Document(org.jdom2.Document) NoProcessSpecifiedException(de.hpi.bpt.scylla.creation.SimulationConfiguration.SimulationConfigurationCreator.NoProcessSpecifiedException) NotAValidFileException(de.hpi.bpt.scylla.creation.SimulationConfiguration.SimulationConfigurationCreator.NotAValidFileException)

Aggregations

SAXBuilder (org.jdom2.input.SAXBuilder)134 Document (org.jdom2.Document)94 Element (org.jdom2.Element)55 IOException (java.io.IOException)33 JDOMException (org.jdom2.JDOMException)27 File (java.io.File)20 StringReader (java.io.StringReader)20 Test (org.junit.jupiter.api.Test)18 InputStream (java.io.InputStream)14 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)11 URL (java.net.URL)9 XMLOutputter (org.jdom2.output.XMLOutputter)8 Modification (com.thoughtworks.go.domain.materials.Modification)7 List (java.util.List)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputSource (org.xml.sax.InputSource)6 ParseException (java.text.ParseException)5 MCRPath (org.mycore.datamodel.niofs.MCRPath)5 BufferedInputStream (java.io.BufferedInputStream)4