Search in sources :

Example 51 with Document

use of org.apache.type_test.types1.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 52 with Document

use of org.apache.type_test.types1.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 53 with Document

use of org.apache.type_test.types1.Document in project jPOS by jpos.

the class Q2Test method testDecrypt.

@Test
public void testDecrypt() throws Throwable {
    String[] args = new String[2];
    args[0] = "testString";
    args[1] = "testString";
    m_q2 = new Q2(args);
    Document doc = mock(Document.class);
    Element element = mock(Element.class);
    given(doc.getRootElement()).willReturn(element);
    given(element.getName()).willReturn("testString");
    Document result = m_q2.decrypt(doc);
    assertSame("result", doc, result);
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) Test(org.junit.Test)

Example 54 with Document

use of org.apache.type_test.types1.Document in project scylla by bptlab.

the class SimulationConfigurationPane method updateModel.

private boolean updateModel() throws JDOMException, IOException {
    Document doc;
    SAXBuilder builder = new SAXBuilder();
    doc = builder.build(bpmnPath);
    Element modelRoot = doc.getRootElement();
    try {
        creator.setModel(modelRoot, false);
    } catch (NoProcessSpecifiedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NotAuthorizedToOverrideException e) {
        if (showModelOverrideConfirmationDialog(e) == 0) {
            try {
                creator.setModel(modelRoot, true);
            } catch (NoProcessSpecifiedException | NotAuthorizedToOverrideException e1) {
                e1.printStackTrace();
            }
        } else
            return false;
    }
    // Reimport updated creator elements
    startEventPanel.setStartEvent(creator.getStartEvent());
    taskPanel.clear();
    gatewayPanel.clear();
    importCreatorElements();
    button_openPM.setEnabled(false);
    panelStarteventExpand.setContent(startEventPanel);
    panelTasksExpand.setContent(taskPanel);
    panelGatewaysExpand.setContent(gatewayPanel);
    gatewayPanel.forAll((gateway) -> {
        if (gateway instanceof ExclusiveGatewayPanel) {
            ((ExclusiveGatewayPanel) gateway).initBranches();
        }
    });
    return 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)

Example 55 with Document

use of org.apache.type_test.types1.Document in project scylla by bptlab.

the class GlobalConfigurationCreator method createFromFile.

/**
 * Creates a new GCCreator from an existing GC xml file
 * @param path to xml file
 * @return new GCCreator
 * @throws JDOMException when errors occur in parsing
 * @throws IOException when an I/O error prevents a document from being fully parsed
 */
public static GlobalConfigurationCreator createFromFile(String path) throws JDOMException, IOException {
    SAXBuilder builder = new SAXBuilder();
    Document doc = builder.build(path);
    Element r = doc.getRootElement();
    // }
    return new GlobalConfigurationCreator(r, doc);
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) Document(org.jdom2.Document)

Aggregations

Document (org.jdom2.Document)109 Element (org.jdom2.Element)74 SAXBuilder (org.jdom2.input.SAXBuilder)34 File (java.io.File)32 Test (org.junit.Test)29 DocType (org.jdom2.DocType)23 IOException (java.io.IOException)22 XMLOutputter (org.jdom2.output.XMLOutputter)20 JDOMException (org.jdom2.JDOMException)14 ProcessingInstruction (org.jdom2.ProcessingInstruction)13 XmlFile (jmri.jmrit.XmlFile)11 Document (com.google.cloud.language.v1beta2.Document)10 ApiException (com.google.api.gax.grpc.ApiException)9 Document (com.google.cloud.language.v1.Document)9 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)9 StatusRuntimeException (io.grpc.StatusRuntimeException)9 FileOutputStream (java.io.FileOutputStream)9 EncodingType (com.google.cloud.language.v1beta2.EncodingType)8 ArrayList (java.util.ArrayList)7 EncodingType (com.google.cloud.language.v1.EncodingType)6