Search in sources :

Example 66 with Document

use of org.jdom2.Document in project JMRI by JMRI.

the class QualifierAdderTest method testNotExistsOk1.

public void testNotExistsOk1() {
    Element e = new Element("variable").addContent(new Element("qualifier").addContent(new Element("variableref").addContent("none")).addContent(new Element("relation").addContent("exists")).addContent(new Element("value").addContent("1")));
    // 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"));
    root.addContent(// the sites information here lists all relevant
    new Element("decoder").addContent(new Element("variables").addContent(e)));
    // test Exists
    processModifierElements(e, v2);
    Assert.assertFalse(v2.getAvailable());
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) DocType(org.jdom2.DocType)

Example 67 with Document

use of org.jdom2.Document in project JMRI by JMRI.

the class QualifierCombinerTest method setUp.

// The minimal setup for log4J
@Before
public void setUp() {
    apps.tests.Log4JFixture.setUp();
    p = new ProgDebugger();
    cvtable = new CvTableModel(new JLabel(""), p);
    model = new VariableTableModel(new JLabel(""), new String[] { "Name", "Value" }, cvtable, new IndexedCvTableModel(new JLabel(""), p));
    // 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 el1, el2, el3;
    root.addContent(// the sites information here lists all relevant
    new Element("decoder").addContent(new Element("variables").addContent(el1 = new Element("variable").setAttribute("CV", "1").setAttribute("item", "one").addContent(new Element("decVal").setAttribute("max", "31").setAttribute("min", "1"))).addContent(el2 = new Element("variable").setAttribute("CV", "2").setAttribute("item", "two").addContent(new Element("decVal").setAttribute("max", "31").setAttribute("min", "1"))).addContent(el3 = new Element("variable").setAttribute("CV", "3").setAttribute("item", "three").addContent(new Element("decVal").setAttribute("max", "31").setAttribute("min", "1")))));
    // end of adding contents
    // and test reading this
    model.setRow(0, el1);
    model.setRow(1, el2);
    model.setRow(1, el3);
    v1 = model.findVar("one");
    v2 = model.findVar("two");
    v3 = model.findVar("three");
}
Also used : ProgDebugger(jmri.progdebugger.ProgDebugger) Element(org.jdom2.Element) JLabel(javax.swing.JLabel) Document(org.jdom2.Document) DocType(org.jdom2.DocType) Before(org.junit.Before)

Example 68 with Document

use of org.jdom2.Document in project JMRI by JMRI.

the class CdiPanelDemo method getRootFromFile.

Element getRootFromFile(String name) {
    Element root = null;
    try {
        // argument controls validation
        SAXBuilder builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser", false);
        Document doc = builder.build(new BufferedInputStream(new FileInputStream(new File(name))));
        root = doc.getRootElement();
    } catch (Exception e) {
        System.out.println("While reading file: " + e);
    }
    return root;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) BufferedInputStream(java.io.BufferedInputStream) Element(org.jdom2.Element) Document(org.jdom2.Document) DemoReadWriteAccess.demoRepFromFile(org.openlcb.cdi.impl.DemoReadWriteAccess.demoRepFromFile) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 69 with Document

use of org.jdom2.Document in project JMRI by JMRI.

the class SampleFactory method main.

// Main entry point for standalone run
public static void main(String[] args) {
    // dump a document to stdout
    Element root = getBasicSample();
    Document doc = new Document(root);
    try {
        org.jdom2.output.XMLOutputter fmt = new org.jdom2.output.XMLOutputter();
        fmt.setFormat(org.jdom2.output.Format.getPrettyFormat());
        fmt.output(doc, System.out);
    } catch (Exception e) {
        System.err.println("Exception writing file: " + e);
    }
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document)

Example 70 with Document

use of org.jdom2.Document in project ddf by codice.

the class OpenSearchSource method createResponseFromEntry.

/**
     * Creates a single response from input parameters. Performs XPath operations on the document to
     * retrieve data not passed in.
     *
     * @param entry a single Atom entry
     * @return single response
     * @throws ddf.catalog.source.UnsupportedQueryException
     */
private List<Result> createResponseFromEntry(SyndEntry entry) throws UnsupportedQueryException {
    String id = entry.getUri();
    if (id != null && !id.isEmpty()) {
        id = id.substring(id.lastIndexOf(':') + 1);
    }
    List<SyndContent> contents = entry.getContents();
    List<SyndCategory> categories = entry.getCategories();
    List<Metacard> metacards = new ArrayList<>();
    List<Element> foreignMarkup = entry.getForeignMarkup();
    String relevance = "";
    String source = "";
    for (Element element : foreignMarkup) {
        if (element.getName().equals("score")) {
            relevance = element.getContent(0).getValue();
        }
    }
    //we currently do not support downloading content via an RSS enclosure, this support can be added at a later date if we decide to include it
    for (SyndContent content : contents) {
        MetacardImpl metacard = getMetacardImpl(parseContent(content.getValue(), id));
        metacard.setSourceId(this.shortname);
        String title = metacard.getTitle();
        if (StringUtils.isEmpty(title)) {
            metacard.setTitle(entry.getTitle());
        }
        if (!source.isEmpty()) {
            metacard.setSourceId(source);
        }
        metacards.add(metacard);
    }
    for (int i = 0; i < categories.size() && i < metacards.size(); i++) {
        SyndCategory category = categories.get(i);
        Metacard metacard = metacards.get(i);
        if (StringUtils.isBlank(metacard.getContentTypeName())) {
            ((MetacardImpl) metacard).setContentTypeName(category.getName());
        }
    }
    List<Result> results = new ArrayList<>();
    for (Metacard metacard : metacards) {
        ResultImpl result = new ResultImpl(metacard);
        if (relevance == null || relevance.isEmpty()) {
            LOGGER.debug("couldn't find valid relevance. Setting relevance to 0");
            relevance = "0";
        }
        result.setRelevanceScore(new Double(relevance));
        results.add(result);
    }
    return results;
}
Also used : SyndCategory(com.rometools.rome.feed.synd.SyndCategory) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) SyndContent(com.rometools.rome.feed.synd.SyndContent)

Aggregations

Document (org.jdom2.Document)86 Element (org.jdom2.Element)76 Test (org.junit.Test)33 File (java.io.File)29 DocType (org.jdom2.DocType)24 SAXBuilder (org.jdom2.input.SAXBuilder)21 IOException (java.io.IOException)16 XMLOutputter (org.jdom2.output.XMLOutputter)15 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 ArrayList (java.util.ArrayList)9 EncodingType (com.google.cloud.language.v1beta2.EncodingType)8 FileOutputStream (java.io.FileOutputStream)8 JLabel (javax.swing.JLabel)7 EncodingType (com.google.cloud.language.v1.EncodingType)6