Search in sources :

Example 1 with Citation

use of beast.core.Citation in project beast2 by CompEvol.

the class DocMaker method getHTML.

// createBEASTObjectPage
public String getHTML(String beastObjectName, boolean useExternalStyleSheet) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
    StringBuffer buf = new StringBuffer();
    buf.append("<html>\n<head>\n<title>BEAST " + version.getVersionString() + " Documentation: " + beastObjectName + "</title>\n");
    if (useExternalStyleSheet) {
        buf.append("<link rel='StyleSheet' href='/tmp/styles.css' type='text/css'>\n");
    } else {
        buf.append("<style type='text/css'>\n");
        buf.append(getCSS());
        buf.append("</style>\n");
    }
    buf.append("</head>\n");
    buf.append("<body>\n");
    buf.append("<h1>BEAST " + version.getVersionString() + " Documentation: " + beastObjectName + "</h1>\n");
    BEASTObject beastObject = (BEASTObject) Class.forName(beastObjectName).newInstance();
    // show all implementation of this plug-in
    String[] implementations = m_isa.get(beastObjectName);
    if (implementations == null) {
        // this class is not documented, perhaps outside ClassDiscover path?
        buf.append("No documentation available for " + beastObjectName + ". Perhaps it is not in the ClassDiscovery path\n");
        buf.append("</body>\n");
        buf.append("</html>\n");
        return buf.toString();
    }
    if (implementations.length > 0) {
        buf.append("<table border='1px'>\n");
        buf.append("<thead><tr><td>implemented by the following</td></tr></thead>\n");
        for (String imp : implementations) {
            buf.append("<tr><td><a href='" + imp + ".html'>" + imp + "</a></td></tr>\n");
        }
        buf.append("</table>\n");
    }
    // show descriptions of all plug-ins implemented by this plug in...
    buf.append("<p>" + m_descriptions.get(beastObjectName) + "</p>\n");
    // show citation (if any)
    for (Citation citation : beastObject.getCitationList()) {
        buf.append("<h2>Reference:</h2><p>" + citation.value() + "</p>\n");
        if (citation.DOI().length() > 0) {
            buf.append("<p><a href=\"http://dx.doi.org/" + citation.DOI() + "\">doi:" + citation.DOI() + "</a></p>\n");
        }
    }
    // show if this is Loggable
    if (m_sLoggables.contains(beastObjectName)) {
        buf.append("<p>Logable:");
        buf.append(" yes, this can be used in a log.");
        buf.append("</p>\n");
    // } else {
    // buf.append(" no, this cannot be used in a log.");
    }
    // show short list its inputs
    buf.append("<h2>Inputs:</h2>\n");
    buf.append("<p>");
    List<Input<?>> inputs = beastObject.listInputs();
    for (Input<?> input : inputs) {
        buf.append("<a href='#" + input.getName() + "'>" + input.getName() + "</a>, ");
    }
    buf.delete(buf.length() - 3, buf.length() - 1);
    buf.append("</p>\n");
    // list its inputs
    if (inputs.size() == 0) {
        buf.append("&lt;none&gt;");
    }
    for (Input<?> input : inputs) {
        buf.append("<p>&nbsp</p>");
        buf.append("<table id='" + input.getName() + "' border='1px' width='90%'>\n");
        buf.append("<caption>" + input.getName() + "</caption>\n");
        buf.append("<thead><tr bgcolor='#AAAAAA'><td>type: " + getType(beastObject, input.getName()) + "</td></tr></thead>\n");
        buf.append("<tr><td>" + input.getTipText() + "</td></tr>\n");
        buf.append("<tr><td>\n");
        switch(input.getRule()) {
            case OPTIONAL:
                buf.append("Optional input");
                if (input.defaultValue != null) {
                    if (input.defaultValue instanceof Integer || input.defaultValue instanceof Double || input.defaultValue instanceof Boolean || input.defaultValue instanceof String) {
                        buf.append(". Default: " + input.defaultValue.toString());
                    }
                }
                break;
            case REQUIRED:
                buf.append("Required input");
                break;
            case XOR:
                buf.append("Either this, or " + input.getOther().getName() + " needs to be specified");
                break;
            case FORBIDDEN:
                buf.append("Forbidden: must not be specified");
                break;
        }
        buf.append("</td></tr>\n");
        buf.append("</table>\n");
    }
    buf.append("</body>\n");
    buf.append("</html>\n");
    return buf.toString();
}
Also used : Input(beast.core.Input) BEASTObject(beast.core.BEASTObject) Citation(beast.core.Citation)

Example 2 with Citation

use of beast.core.Citation in project beast2 by CompEvol.

the class BEASTInterfaceTest method testBEASTi.

@Test
public void testBEASTi() throws Exception {
    BEASTi beasti = new BEASTi();
    System.err.println("test getCitation");
    Citation citation = beasti.getCitation();
    assertEquals("this is a dummy citation", citation.value());
    citation = beasti.getCitationList().get(0);
    assertEquals("this is a dummy citation", citation.value());
    BEASTi beasti02 = new BEASTi2();
    List<Citation> citations = beasti02.getCitationList();
    assertEquals(3, citations.size());
    System.err.println("test initByName");
    beasti.initByName("value", "hello world");
    Input<?> input = beasti.getInput("value");
    assertEquals("hello world", input.get());
    System.err.println("test listInputs");
    List<?> list = beasti.listInputs();
    assertEquals(2, list.size());
    System.err.println("test initByName");
    BEASTi beasti2 = new BEASTi();
    beasti.initByName("value", "hello world", "other", beasti2);
    System.err.println("test getInputValue");
    BEASTi beasti3 = (BEASTi) beasti.getInputValue("other");
    assertEquals(beasti2, beasti3);
    System.err.println("test getOutputs");
    assertEquals(1, beasti2.getOutputs().size());
    String description = beasti.getDescription();
    assertEquals("class that impements BEASTInterface but is not a BEASTObject", description);
    List<BEASTInterface> predecessors = new ArrayList<BEASTInterface>();
    beasti2.getPredecessors(predecessors);
    assertEquals(1, predecessors.size());
    beasti.getPredecessors(predecessors);
    assertEquals(2, predecessors.size());
    assertEquals(beasti, predecessors.get(1));
    assertEquals(beasti2, predecessors.get(0));
    description = beasti.getTipText("other");
    assertEquals("link to another BEASTi object", description);
    boolean b = beasti.isPrimitive("value");
    assertEquals(true, b);
    b = beasti.isPrimitive("other");
    assertEquals(false, b);
    List<BEASTInterface> beastObjbects = beasti.listActiveBEASTObjects();
    assertEquals(1, beastObjbects.size());
    assertEquals(beasti2, beastObjbects.get(0));
    beastObjbects = beasti2.listActiveBEASTObjects();
    assertEquals(0, beastObjbects.size());
    beasti.validateInputs();
    try {
        beasti2.validateInputs();
        // should never get here
        assertEquals(true, false);
    } catch (Throwable t) {
    // lucky to be here
    }
    beasti2.setInputValue("value", "Goodbye!");
    String msg = (String) beasti2.getInputValue("value");
    assertEquals("Goodbye!", msg);
}
Also used : ArrayList(java.util.ArrayList) BEASTInterface(beast.core.BEASTInterface) Citation(beast.core.Citation) Test(org.junit.Test)

Aggregations

Citation (beast.core.Citation)2 BEASTInterface (beast.core.BEASTInterface)1 BEASTObject (beast.core.BEASTObject)1 Input (beast.core.Input)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1