Search in sources :

Example 86 with Document

use of com.google.cloud.language.v1beta2.Document in project JMRI by JMRI.

the class VariableTableModelTest method testVarSpeedTable.

// Check creating a speed table, then finding it by name
public void testVarSpeedTable() {
    String[] args = { "CV", "Name" };
    VariableTableModel t = new VariableTableModel(null, args, new CvTableModel(null, p), null);
    // create a JDOM tree with just some elements
    Element root = new Element("decoder-config");
    Document doc = new Document(root);
    doc.setDocType(new DocType("decoder-config", "decoder-config.dtd"));
    // add some elements
    Element el0;
    root.addContent(// the sites information here lists all relevant
    new Element("decoder").addContent(new Element("variables").addContent(el0 = new Element("variable").setAttribute("CV", "67").setAttribute("label", "Speed Table").setAttribute("mask", "VVVVVVVV").setAttribute("readOnly", "").addContent(new Element("speedTableVal")))));
    // end of adding contents
    // and test reading this
    t.setRow(0, el0);
    // check finding
    Assert.assertEquals("length of variable list ", 1, t.getRowCount());
    Assert.assertEquals("name of 1st variable ", "Speed Table", t.getLabel(0));
    Assert.assertEquals("find Speed Table ", 0, t.findVarIndex("Speed Table"));
    Assert.assertEquals("find nonexistant variable ", -1, t.findVarIndex("not there, eh?"));
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) DocType(org.jdom2.DocType)

Example 87 with Document

use of com.google.cloud.language.v1beta2.Document in project JMRI by JMRI.

the class PaneProgPaneTest method setupDoc.

// provide a test document in the above static variables
void setupDoc() {
    // create a JDOM tree with just some elements
    root = new Element("programmer-config");
    doc = new Document(root);
    doc.setDocType(new DocType("programmer-config", "programmer-config.dtd"));
    // add some elements
    root.addContent(new Element("programmer").addContent(pane1 = new Element("pane").setAttribute("name", "Basic").addContent(new Element("column").addContent(new Element("display").setAttribute("item", "Primary Address")).addContent(new Element("display").setAttribute("item", "Start voltage")).addContent(new Element("display").setAttribute("item", "Normal direction of motion"))).addContent(new Element("column").addContent(new Element("display").setAttribute("item", "Address")).addContent(new Element("display").setAttribute("item", "Normal direction of motion")).addContent(new Element("display").setAttribute("item", "Normal direction of motion").setAttribute("format", "checkbox")).addContent(new Element("display").setAttribute("item", "Normal direction of motion").setAttribute("format", "radiobuttons")))).addContent(pane2 = new Element("pane").setAttribute("name", "CV").addContent(new Element("column").addContent(new Element("cvtable")))).addContent(pane3 = new Element("pane").setAttribute("name", "Other").addContent(new Element("column").addContent(new Element("display").setAttribute("item", "Address")).addContent(new Element("display").setAttribute("item", "Normal direction of motion")))));
    // end of adding contents
    log.debug("setupDoc complete");
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) DocType(org.jdom2.DocType)

Example 88 with Document

use of com.google.cloud.language.v1beta2.Document in project JMRI by JMRI.

the class VariableTableModelTest method testVarTableLoad_2_3.

// Check loading two columns, three rows
public void testVarTableLoad_2_3() {
    String[] args = { "CV", "Name" };
    VariableTableModel t = new VariableTableModel(null, args, new CvTableModel(null, p), null);
    // create a JDOM tree with just some elements
    Element root = new Element("decoder-config");
    Document doc = new Document(root);
    doc.setDocType(new DocType("decoder-config", "decoder-config.dtd"));
    // add some elements
    Element el0, el1;
    root.addContent(// the sites information here lists all relevant
    new Element("decoder").addContent(new Element("variables").addContent(el0 = new Element("variable").setAttribute("CV", "1").setAttribute("label", "one").setAttribute("mask", "VVVVVVVV").setAttribute("item", "really two").setAttribute("readOnly", "no").addContent(new Element("decVal").setAttribute("max", "31").setAttribute("min", "1"))).addContent(el1 = new Element("variable").setAttribute("CV", "4").setAttribute("readOnly", "no").setAttribute("mask", "XXXVVVVX").setAttribute("label", "two").addContent(new Element("decVal").setAttribute("max", "31").setAttribute("min", "1")))));
    // end of adding contents
    // print JDOM tree, to check
    //OutputStream o = System.out;
    //XMLOutputter fmt = new XMLOutputter();
    //fmt.setNewlines(true);   // pretty printing
    //fmt.setIndent(true);
    //try {
    //	 fmt.output(doc, o);
    //} catch (Exception e) { System.out.println("error writing XML: "+e);}
    // and test reading this
    t.setRow(0, el0);
    Assert.assertTrue(t.getValueAt(0, 0).equals("1"));
    Assert.assertTrue(t.getValueAt(0, 1).equals("one"));
    // check that the variable names were set right
    Assert.assertEquals("check loaded label ", "one", t.getLabel(0));
    Assert.assertEquals("check loaded item ", "really two", t.getItem(0));
    t.setRow(1, el1);
    Assert.assertTrue(t.getValueAt(1, 0).equals("4"));
    Assert.assertTrue(t.getValueAt(1, 1).equals("two"));
    Assert.assertTrue(t.getRowCount() == 2);
    // check finding
    Assert.assertEquals("find variable two ", 1, t.findVarIndex("two"));
    Assert.assertEquals("find nonexistant variable ", -1, t.findVarIndex("not there, eh?"));
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) DocType(org.jdom2.DocType)

Example 89 with Document

use of com.google.cloud.language.v1beta2.Document in project JMRI by JMRI.

the class VariableTableModelTest method testVarTableLoadLongAddr.

// Check creating a longaddr type, walk through its programming
public void testVarTableLoadLongAddr() {
    String[] args = { "CV", "Name" };
    VariableTableModel t = new VariableTableModel(null, args, new CvTableModel(null, p), null);
    // create a JDOM tree with just some elements
    Element root = new Element("decoder-config");
    Document doc = new Document(root);
    doc.setDocType(new DocType("decoder-config", "decoder-config.dtd"));
    // add some elements
    Element el0;
    root.addContent(// the sites information here lists all relevant
    new Element("decoder").addContent(new Element("variables").addContent(el0 = new Element("variable").setAttribute("CV", "17").setAttribute("readOnly", "no").setAttribute("mask", "VVVVVVVV").setAttribute("label", "long").addContent(new Element("longAddressVal")))));
    // end of adding contents
    // print JDOM tree, to check
    //OutputStream o = System.out;
    //XMLOutputter fmt = new XMLOutputter();
    //fmt.setNewlines(true);   // pretty printing
    //fmt.setIndent(true);
    //try {
    //	 fmt.output(doc, o);
    //} catch (Exception e) { System.out.println("error writing XML: "+e);}
    // and test reading this
    t.setRow(0, el0);
    Assert.assertTrue(t.getValueAt(0, 0).equals("17"));
    Assert.assertTrue(t.getValueAt(0, 1).equals("long"));
    Assert.assertTrue(t.getRowCount() == 1);
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) DocType(org.jdom2.DocType)

Example 90 with Document

use of com.google.cloud.language.v1beta2.Document in project JMRI by JMRI.

the class XmlFile method newDocument.

/**
     * Create the Document object to store a particular root Element.
     *
     * @param root Root element of the final document
     * @param dtd  name of an external DTD
     * @return new Document, with root installed
     */
public static Document newDocument(Element root, String dtd) {
    Document doc = new Document(root);
    doc.setDocType(new DocType(root.getName(), dtd));
    addDefaultInfo(root);
    return doc;
}
Also used : Document(org.jdom2.Document) DocType(org.jdom2.DocType)

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