Search in sources :

Example 31 with Document

use of org.datanucleus.samples.annotations.one_many.bidir_3.Document in project google-cloud-java by GoogleCloudPlatform.

the class LanguageServiceClientTest method analyzeSentimentExceptionTest.

@Test
@SuppressWarnings("all")
public void analyzeSentimentExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockLanguageService.addException(exception);
    try {
        Document document = Document.newBuilder().build();
        client.analyzeSentiment(document);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) Document(com.google.cloud.language.v1.Document) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 32 with Document

use of org.datanucleus.samples.annotations.one_many.bidir_3.Document in project google-cloud-java by GoogleCloudPlatform.

the class LanguageServiceClientTest method annotateTextTest.

@Test
@SuppressWarnings("all")
public void annotateTextTest() {
    String language = "language-1613589672";
    AnnotateTextResponse expectedResponse = AnnotateTextResponse.newBuilder().setLanguage(language).build();
    mockLanguageService.addResponse(expectedResponse);
    Document document = Document.newBuilder().build();
    AnnotateTextRequest.Features features = AnnotateTextRequest.Features.newBuilder().build();
    EncodingType encodingType = EncodingType.NONE;
    AnnotateTextResponse actualResponse = client.annotateText(document, features, encodingType);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockLanguageService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    AnnotateTextRequest actualRequest = (AnnotateTextRequest) actualRequests.get(0);
    Assert.assertEquals(document, actualRequest.getDocument());
    Assert.assertEquals(features, actualRequest.getFeatures());
    Assert.assertEquals(encodingType, actualRequest.getEncodingType());
}
Also used : AnnotateTextRequest(com.google.cloud.language.v1.AnnotateTextRequest) EncodingType(com.google.cloud.language.v1.EncodingType) AnnotateTextResponse(com.google.cloud.language.v1.AnnotateTextResponse) Document(com.google.cloud.language.v1.Document) Features(com.google.cloud.language.v1.AnnotateTextRequest.Features) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 33 with Document

use of org.datanucleus.samples.annotations.one_many.bidir_3.Document in project JMRI by JMRI.

the class SwitchboardServlet method getXmlPanel.

@Override
protected String getXmlPanel(String name) {
    log.debug("Getting {} for {}", getPanelType(), name);
    try {
        SwitchboardEditor editor = (SwitchboardEditor) getEditor(name);
        Element panel = new Element("panel");
        JFrame frame = editor.getTargetFrame();
        panel.setAttribute("name", name);
        panel.setAttribute("height", Integer.toString(frame.getContentPane().getHeight()));
        panel.setAttribute("width", Integer.toString(frame.getContentPane().getWidth()));
        panel.setAttribute("panelheight", Integer.toString(editor.getTargetPanel().getHeight()));
        panel.setAttribute("panelwidth", Integer.toString(editor.getTargetPanel().getWidth()));
        // add more properties
        panel.setAttribute("showtooltips", (editor.showTooltip()) ? "yes" : "no");
        panel.setAttribute("controlling", (editor.allControlling()) ? "yes" : "no");
        panel.setAttribute("hideunconnected", (editor.hideUnconnected()) ? "yes" : "no");
        panel.setAttribute("rangemin", Integer.toString(editor.getPanelMenuRangeMin()));
        panel.setAttribute("rangemax", Integer.toString(editor.getPanelMenuRangeMax()));
        panel.setAttribute("type", editor.getSwitchType());
        panel.setAttribute("connection", editor.getSwitchManu());
        panel.setAttribute("shape", editor.getSwitchShape());
        panel.setAttribute("columns", Integer.toString(editor.getColumns()));
        panel.setAttribute("defaulttextcolor", editor.getDefaultTextColor());
        log.debug("webserver Switchboard attribs ready");
        Element bgColor = new Element("backgroundColor");
        if (editor.getBackgroundColor() == null) {
            // set to light grey
            bgColor.setAttribute("red", Integer.toString(192));
            bgColor.setAttribute("green", Integer.toString(192));
            bgColor.setAttribute("blue", Integer.toString(192));
        } else {
            bgColor.setAttribute("red", Integer.toString(editor.getBackgroundColor().getRed()));
            bgColor.setAttribute("green", Integer.toString(editor.getBackgroundColor().getGreen()));
            bgColor.setAttribute("blue", Integer.toString(editor.getBackgroundColor().getBlue()));
        }
        panel.addContent(bgColor);
        Element text = new Element("text");
        text.setAttribute("color", editor.getDefaultTextColor());
        text.setAttribute("content", "For now, Switchboards only present buttons in JMRI WebServer.");
        panel.addContent(text);
        // include switches, Bug: how to delete the old ones?
        // call method in SwitchboardEditor
        List<BeanSwitch> _switches = editor.getSwitches();
        log.debug("SwbServlet N switches: {}", _switches.size());
        for (BeanSwitch sub : _switches) {
            if (sub != null) {
                try {
                    Element e = ConfigXmlManager.elementFromObject(sub);
                    if (e != null) {
                        log.debug("element name: {}", e.getName());
                        // }
                        try {
                            e.setAttribute("label", sub.getNameString());
                            e.setAttribute(JSON.ID, sub.getNamedBean().getSystemName());
                            if (sub.getNamedBean() == null) {
                                e.setAttribute("connected", "false");
                                log.debug("switch {} NOT connected", sub.getNameString());
                            } else {
                                // activate click action via class
                                e.setAttribute("connected", "true");
                            }
                        } catch (NullPointerException ex) {
                            if (sub.getNamedBean() == null) {
                                log.debug("{} {} does not have an associated NamedBean", e.getName(), e.getAttribute(JSON.NAME));
                            } else {
                                log.debug("{} {} does not have a SystemName", e.getName(), e.getAttribute(JSON.NAME));
                            }
                        }
                        // read shared attribs
                        e.setAttribute("textcolor", editor.getDefaultTextColor());
                        e.setAttribute("type", editor.getSwitchType());
                        e.setAttribute("connection", editor.getSwitchManu());
                        e.setAttribute("shape", editor.getSwitchShape());
                        e.setAttribute("columns", Integer.toString(editor.getColumns()));
                        // process and add
                        parsePortableURIs(e);
                        panel.addContent(e);
                    }
                } catch (Exception ex) {
                    log.error("Error reading xml panel element: " + ex, ex);
                }
            }
        }
        Document doc = new Document(panel);
        XMLOutputter out = new XMLOutputter();
        out.setFormat(Format.getPrettyFormat().setLineSeparator(System.getProperty("line.separator")).setTextMode(Format.TextMode.TRIM));
        return out.outputString(doc);
    } catch (NullPointerException ex) {
        log.warn("Requested Switchboard [" + name + "] does not exist.");
        return "ERROR Requested Switchboard [" + name + "] does not exist.";
    }
}
Also used : SwitchboardEditor(jmri.jmrit.display.switchboardEditor.SwitchboardEditor) XMLOutputter(org.jdom2.output.XMLOutputter) JFrame(javax.swing.JFrame) Element(org.jdom2.Element) BeanSwitch(jmri.jmrit.display.switchboardEditor.SwitchboardEditor.BeanSwitch) Document(org.jdom2.Document)

Example 34 with Document

use of org.datanucleus.samples.annotations.one_many.bidir_3.Document in project JMRI by JMRI.

the class ControlPanelServlet method getXmlPanel.

@Override
protected String getXmlPanel(String name) {
    log.debug("Getting {} for {}", getPanelType(), name);
    try {
        ControlPanelEditor editor = (ControlPanelEditor) getEditor(name);
        Element panel = new Element("panel");
        JFrame frame = editor.getTargetFrame();
        panel.setAttribute("name", name);
        panel.setAttribute("height", Integer.toString(frame.getContentPane().getHeight()));
        panel.setAttribute("width", Integer.toString(frame.getContentPane().getWidth()));
        panel.setAttribute("panelheight", Integer.toString(editor.getTargetPanel().getHeight()));
        panel.setAttribute("panelwidth", Integer.toString(editor.getTargetPanel().getWidth()));
        panel.setAttribute("showtooltips", (editor.showTooltip()) ? "yes" : "no");
        panel.setAttribute("controlling", (editor.allControlling()) ? "yes" : "no");
        if (editor.getBackgroundColor() != null) {
            Element color = new Element("backgroundColor");
            color.setAttribute("red", Integer.toString(editor.getBackgroundColor().getRed()));
            color.setAttribute("green", Integer.toString(editor.getBackgroundColor().getGreen()));
            color.setAttribute("blue", Integer.toString(editor.getBackgroundColor().getBlue()));
            panel.addContent(color);
        }
        // include contents
        List<Positionable> contents = editor.getContents();
        log.debug("N elements: {}", contents.size());
        for (Positionable sub : contents) {
            if (sub != null) {
                try {
                    Element e = ConfigXmlManager.elementFromObject(sub);
                    if (e != null) {
                        if ("signalmasticon".equals(e.getName())) {
                            //insert icon details into signalmast
                            e.addContent(getSignalMastIconsElement(e.getAttributeValue("signalmast")));
                        }
                        try {
                            e.setAttribute(JSON.ID, sub.getNamedBean().getSystemName());
                        } catch (NullPointerException ex) {
                            if (sub.getNamedBean() == null) {
                                log.debug("{} {} does not have an associated NamedBean", e.getName(), e.getAttribute(JSON.NAME));
                            } else {
                                log.debug("{} {} does not have a SystemName", e.getName(), e.getAttribute(JSON.NAME));
                            }
                        }
                        parsePortableURIs(e);
                        panel.addContent(e);
                    }
                } catch (Exception ex) {
                    log.error("Error storing panel element: " + ex, ex);
                }
            }
        }
        Document doc = new Document(panel);
        XMLOutputter out = new XMLOutputter();
        out.setFormat(Format.getPrettyFormat().setLineSeparator(System.getProperty("line.separator")).setTextMode(Format.TextMode.TRIM));
        return out.outputString(doc);
    } catch (NullPointerException ex) {
        log.warn("Requested ControlPanel [" + name + "] does not exist.");
        return "ERROR Requested panel [" + name + "] does not exist.";
    }
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) ControlPanelEditor(jmri.jmrit.display.controlPanelEditor.ControlPanelEditor) JFrame(javax.swing.JFrame) Element(org.jdom2.Element) Positionable(jmri.jmrit.display.Positionable) Document(org.jdom2.Document)

Example 35 with Document

use of org.datanucleus.samples.annotations.one_many.bidir_3.Document in project JMRI by JMRI.

the class QualifiedVarTest 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").setAttribute("showFnLanelPane", "no").setAttribute("showRosterMediaPane", "no").addContent(new Element("pane").setAttribute("name", "Test").addContent(new Element("column").addContent(new Element("display").setAttribute("item", "Primary Address")).addContent(new Element("display").setAttribute("item", "CV2")).addContent(new Element("display").setAttribute("item", "CV3")).addContent(new Element("display").setAttribute("item", "CV4")).addContent(new Element("display").setAttribute("item", "CV5")).addContent(new Element("display").setAttribute("item", "CV6")).addContent(new Element("separator")).addContent(new Element("label").setAttribute("label", "set cv3 >= 100 to see CV4")).addContent(new Element("label").setAttribute("label", "set cv3 <=100 to see CV5, CV6"))).addContent(new Element("column").addContent(new Element("display").setAttribute("item", "Minor Version Number")).addContent(new Element("display").setAttribute("item", "Major Version Number")).addContent(new Element("display").setAttribute("item", "iCV53.5.0")).addContent(new Element("display").setAttribute("item", "iCV55.92.0")).addContent(new Element("display").setAttribute("item", "iCV55.92.1")).addContent(new Element("separator")).addContent(new Element("label").setAttribute("label", "set cv3 >= 100 to see iCV53.5.0")).addContent(new Element("label").setAttribute("label", "set minor >= 100 to see iCV55.92.0")).addContent(new Element("label").setAttribute("label", "set minor, major >= 100 to see iCV55.92.1")))).addContent(new Element("pane").setAttribute("name", "CV").addContent(new Element("column").addContent(new Element("cvtable")))).addContent(new Element("pane").setAttribute("name", "iCV").addContent(new Element("column").addContent(new Element("indxcvtable")))).addContent(new Element("pane").setAttribute("name", "CV3>50").addContent(new Element("qualifier").addContent(new Element("variableref").addContent("CV3")).addContent(new Element("relation").addContent("gt")).addContent(new Element("value").addContent("50"))).addContent(new Element("column").addContent(new Element("display").setAttribute("item", "CV3")).addContent(new Element("display").setAttribute("item", "CV4")).addContent(new Element("label").setAttribute("label", "Pane visible with CV3>100")))));
    return;
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) DocType(org.jdom2.DocType)

Aggregations

Document (org.jdom2.Document)391 Element (org.jdom2.Element)243 Test (org.junit.Test)104 SAXBuilder (org.jdom2.input.SAXBuilder)84 IOException (java.io.IOException)72 File (java.io.File)56 XMLOutputter (org.jdom2.output.XMLOutputter)56 JDOMException (org.jdom2.JDOMException)44 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)34 MCRNodeBuilder (org.mycore.common.xml.MCRNodeBuilder)25 DocType (org.jdom2.DocType)24 ArrayList (java.util.ArrayList)22 MCRContent (org.mycore.common.content.MCRContent)22 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)22 MCRException (org.mycore.common.MCRException)21 Document (com.google.cloud.language.v1.Document)20 HashMap (java.util.HashMap)19 Attribute (org.jdom2.Attribute)19 MCRObject (org.mycore.datamodel.metadata.MCRObject)19 URL (java.net.URL)18