Search in sources :

Example 51 with Document

use of org.geotoolkit.sml.xml.v100.Document in project JMRI by JMRI.

the class EngineManagerXml method writeFile.

@Override
public void writeFile(String name) throws java.io.FileNotFoundException, java.io.IOException {
    log.debug("writeFile {}", name);
    // This is taken in large part from "Java and XML" page 368
    File file = findFile(name);
    if (file == null) {
        file = new File(name);
    }
    // create root element
    // NOI18N
    Element root = new Element("operations-config");
    // NOI18N
    Document doc = newDocument(root, dtdLocation + "operations-engines.dtd");
    // add XSLT processing instruction
    java.util.Map<String, String> m = new java.util.HashMap<String, String>();
    // NOI18N
    m.put("type", "text/xsl");
    // NOI18N
    m.put("href", xsltLocation + "operations-engines.xsl");
    // NOI18N
    ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
    doc.addContent(0, p);
    EngineModels.instance().store(root);
    EngineTypes.instance().store(root);
    EngineLengths.instance().store(root);
    EngineManager.instance().store(root);
    writeXML(file, doc);
    // done - engine file now stored, so can't be dirty
    setDirty(false);
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) File(java.io.File) ProcessingInstruction(org.jdom2.ProcessingInstruction)

Example 52 with Document

use of org.geotoolkit.sml.xml.v100.Document in project JMRI by JMRI.

the class OperationsSetupXml method writeFile.

@Override
public void writeFile(String name) throws java.io.FileNotFoundException, java.io.IOException {
    log.debug("writeFile {}", name);
    // This is taken in large part from "Java and XML" page 368
    File file = findFile(name);
    if (file == null) {
        file = new File(name);
    }
    // create root element
    // NOI18N
    Element root = new Element("operations-config");
    // NOI18N
    Document doc = newDocument(root, dtdLocation + "operations-config.dtd");
    // add XSLT processing instruction
    java.util.Map<String, String> m = new java.util.HashMap<String, String>();
    // NOI18N
    m.put("type", "text/xsl");
    // NOI18N
    m.put("href", xsltLocation + "operations-config.xsl");
    // NOI18N
    ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
    doc.addContent(0, p);
    // add top-level elements         
    root.addContent(Setup.store());
    // add manifest header text strings
    root.addContent(TrainManifestHeaderText.store());
    // add manifest text strings
    root.addContent(TrainManifestText.store());
    // add switch list text strings
    root.addContent(TrainSwitchListText.store());
    // add control elements
    root.addContent(Control.store());
    writeXML(file, doc);
    // done, so can't be dirty
    setDirty(false);
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) File(java.io.File) ProcessingInstruction(org.jdom2.ProcessingInstruction)

Example 53 with Document

use of org.geotoolkit.sml.xml.v100.Document in project JMRI by JMRI.

the class TrainManagerXml method writeFile.

@Override
public void writeFile(String name) throws java.io.FileNotFoundException, java.io.IOException {
    log.debug("writeFile {}", name);
    // This is taken in large part from "Java and XML" page 368
    File file = findFile(name);
    if (file == null) {
        file = new File(name);
    }
    // create root element
    // NOI18N
    Element root = new Element("operations-config");
    // NOI18N
    Document doc = newDocument(root, dtdLocation + "operations-trains.dtd");
    // add XSLT processing instruction
    java.util.Map<String, String> m = new java.util.HashMap<String, String>();
    // NOI18N
    m.put("type", "text/xsl");
    // NOI18N
    m.put("href", xsltLocation + "operations-trains.xsl");
    // NOI18N
    ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
    doc.addContent(0, p);
    TrainManager.instance().store(root);
    TrainScheduleManager.instance().store(root);
    AutomationManager.instance().store(root);
    writeXML(file, doc);
    // done - train file now stored, so can't be dirty
    setDirty(false);
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) File(java.io.File) ProcessingInstruction(org.jdom2.ProcessingInstruction)

Example 54 with Document

use of org.geotoolkit.sml.xml.v100.Document in project JMRI by JMRI.

the class VSDecoderPreferences method save.

public void save() {
    if (prefFile == null) {
        return;
    }
    XmlFile xf = new XmlFile() {
    };
    // odd syntax is due to XmlFile being abstract
    xf.makeBackupFile(prefFile);
    File file = new File(prefFile);
    try {
        //The file does not exist, create it before writing
        File parentDir = file.getParentFile();
        if (!parentDir.exists()) {
            if (// make directory, check result
            !parentDir.mkdir()) {
                log.error("failed to make parent directory");
            }
        }
        if (// create file, check result
        !file.createNewFile()) {
            log.error("createNewFile failed");
        }
    } catch (Exception exp) {
        log.error("Exception while writing the new VSDecoder preferences file, may not be complete: " + exp);
    }
    try {
        Element root = new Element("vsdecoder-preferences");
        //Document doc = XmlFile.newDocument(root, XmlFile.dtdLocation+"vsdecoder-preferences.dtd");
        Document doc = XmlFile.newDocument(root);
        // add XSLT processing instruction
        // <?xml-stylesheet type="text/xsl" href="XSLT/throttle.xsl"?>
        /*TODO      java.util.Map<String,String> m = new java.util.HashMap<String,String>();
             m.put("type", "text/xsl");
             m.put("href", jmri.jmrit.XmlFile.xsltLocation+"throttles-preferences.xsl");
             ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
             doc.addContent(0,p);*/
        root.setContent(store());
        xf.writeXML(file, doc);
    } catch (Exception ex) {
        // TODO fix null value for Attribute
        log.warn("Exception in storing vsdecoder preferences xml: " + ex);
    }
}
Also used : XmlFile(jmri.jmrit.XmlFile) Element(org.jdom2.Element) Document(org.jdom2.Document) File(java.io.File) XmlFile(jmri.jmrit.XmlFile)

Example 55 with Document

use of org.geotoolkit.sml.xml.v100.Document in project xwiki-platform by xwiki.

the class DefaultEntityResourceActionLister method initialize.

@Override
public void initialize() throws InitializationException {
    // Parse the Struts config file (struts-config.xml) to extract all available actions
    List<String> actionNames = new ArrayList<>();
    SAXBuilder builder = new SAXBuilder();
    // Make sure we don't require an Internet Connection to parse the Struts config file!
    builder.setEntityResolver(new EntityResolver() {

        @Override
        public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
            return new InputSource(new StringReader(""));
        }
    });
    // Step 1: Get a stream on the Struts config file if it exists
    InputStream strutsConfigStream = this.environment.getResourceAsStream(getStrutsConfigResource());
    if (strutsConfigStream != null) {
        // Step 2: Parse the Strust config file, looking for action names
        Document document;
        try {
            document = builder.build(strutsConfigStream);
        } catch (JDOMException | IOException e) {
            throw new InitializationException(String.format("Failed to parse Struts Config file [%s]", getStrutsConfigResource()), e);
        }
        Element mappingElement = document.getRootElement().getChild("action-mappings");
        for (Element element : mappingElement.getChildren("action")) {
            // We extract the action name from the path mapping. Note that we cannot use the "name" attribute since
            // it's not reliable (it's not unique) and for example the sanveandcontinue action uses "save" as its
            // "name" element value.
            actionNames.add(StringUtils.strip(element.getAttributeValue("path"), "/"));
        }
    }
    this.strutsActionNames = actionNames;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) InputSource(org.xml.sax.InputSource) InputStream(java.io.InputStream) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) EntityResolver(org.xml.sax.EntityResolver) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) InitializationException(org.xwiki.component.phase.InitializationException) SAXException(org.xml.sax.SAXException) StringReader(java.io.StringReader)

Aggregations

Document (org.jdom2.Document)882 Element (org.jdom2.Element)491 Test (org.junit.Test)320 IOException (java.io.IOException)211 SAXBuilder (org.jdom2.input.SAXBuilder)207 XMLOutputter (org.jdom2.output.XMLOutputter)144 File (java.io.File)131 JDOMException (org.jdom2.JDOMException)120 InputStream (java.io.InputStream)61 DocumentHelper.getDocument (com.mulesoft.tools.migration.helper.DocumentHelper.getDocument)53 DocumentHelper.getElementsFromDocument (com.mulesoft.tools.migration.helper.DocumentHelper.getElementsFromDocument)53 ArrayList (java.util.ArrayList)52 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)48 PID (edu.unc.lib.boxc.model.api.ids.PID)47 Path (java.nio.file.Path)46 HashMap (java.util.HashMap)46 List (java.util.List)36 Attribute (org.jdom2.Attribute)35 Document (com.google.cloud.language.v1.Document)34 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)34