Example usage for javax.json JsonArray getJsonArray

List of usage examples for javax.json JsonArray getJsonArray

Introduction

In this page you can find the example usage for javax.json JsonArray getJsonArray.

Prototype

JsonArray getJsonArray(int index);

Source Link

Document

Returns the array value at the specified position in this array.

Usage

From source file:io.hops.hopsworks.common.util.WebCommunication.java

public List<NodesTableItem> getNdbinfoNodesTable(String hostAddress, String agentPassword)
        throws GenericException {
    List<NodesTableItem> resultList = new ArrayList<NodesTableItem>();

    String url = createUrl("mysql", hostAddress, "ndbinfo", "nodes");
    String jsonString = fetchContent(url, agentPassword);
    InputStream stream = new ByteArrayInputStream(jsonString.getBytes(StandardCharsets.UTF_8));
    try {//from   ww w  .ja va2  s  .co m
        JsonArray json = Json.createReader(stream).readArray();
        if (json.get(0).equals("Error")) {
            resultList.add(new NodesTableItem(null, json.getString(1), null, null, null));
            return resultList;
        }
        for (int i = 0; i < json.size(); i++) {
            JsonArray node = json.getJsonArray(i);
            Integer nodeId = node.getInt(0);
            Long uptime = node.getJsonNumber(1).longValue();
            String status = node.getString(2);
            Integer startPhase = node.getInt(3);
            Integer configGeneration = node.getInt(4);
            resultList.add(new NodesTableItem(nodeId, status, uptime, startPhase, configGeneration));
        }
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Exception: {0}", ex);
        resultList.add(new NodesTableItem(null, "Error", null, null, null));
    }
    return resultList;
}

From source file:io.bibleget.BibleGetHelp.java

/**
 * Creates new form BibleGetHelp/* w w  w.  j a  v a2  s . com*/
 */
private BibleGetHelp() throws ClassNotFoundException, UnsupportedEncodingException {
    //jTextPane does not initialize correctly, it causes a Null Exception Pointer
    //Following line keeps this from crashing the program
    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

    String packagePath = BibleGetIO.getPackagePath();
    //String locale = BibleGetIO.getLocale();

    String langsSupported;
    List<String> langsLocalized = new ArrayList<>();
    String bbBooks;

    bibleGetDB = BibleGetDB.getInstance();
    if (bibleGetDB != null) {
        //System.out.println("oh good, biblegetDB is not null!");
        JsonReader jsonReader;
        langsSupported = bibleGetDB.getMetaData("LANGUAGES");
        //System.out.println(langsSupported);
        jsonReader = Json.createReader(new StringReader(langsSupported));
        bibleVersionsObj = jsonReader.readArray();
        booksLangs = bibleVersionsObj.size();
        for (JsonValue jsonValue : bibleVersionsObj) {
            //System.out.println(jsonValue.toString());
            langsLocalized.add(BibleGetI18N.localizeLanguage(jsonValue.toString()));
        }
        booksStr = StringUtils.join(langsLocalized, ", ");

        List<JsonArray> bibleBooksTemp = new ArrayList<>();
        for (int i = 0; i < 73; i++) {
            bbBooks = bibleGetDB.getMetaData("BIBLEBOOKS" + Integer.toString(i));
            jsonReader = Json.createReader(new StringReader(bbBooks));
            JsonArray bibleBooksObj = jsonReader.readArray();
            bibleBooksTemp.add(bibleBooksObj);
        }

        String curLang;
        List<String[]> booksForCurLang;
        //bibleBooks = new HashMap<>();
        booksAndAbbreviations = new HashMap<>();
        String buildStr;
        for (int q = 0; q < bibleVersionsObj.size(); q++) {
            curLang = (bibleVersionsObj.getString(q) != null)
                    ? BibleGetI18N.localizeLanguage(bibleVersionsObj.getString(q)).toUpperCase()
                    : "";
            buildStr = "";
            for (int i = 0; i < 73; i++) {

                String styleStr = "";
                if (bibleVersionsObj.getString(q).equals("TAMIL")
                        || bibleVersionsObj.getString(q).equals("KOREAN")) {
                    styleStr = " style=\"font-family:'Arial Unicode MS';\"";
                }

                JsonArray curBook = bibleBooksTemp.get(i);
                JsonArray curBookCurLang = curBook.getJsonArray(q);
                String str1 = (curBookCurLang.getString(0) != null) ? curBookCurLang.getString(0) : "";
                String str2 = (curBookCurLang.getString(1) != null) ? curBookCurLang.getString(1) : "";
                buildStr += "<tr><td" + styleStr + ">" + str1 + "</td><td" + styleStr + ">" + str2
                        + "</td></tr>";
                //buildStr += "<tr><td style=\"font-family:'Arial Unicode MS';\">"+str1+"</td><td style=\"font-family:'Arial Unicode MS';\">"+str2+"</td></tr>";
            }
            booksAndAbbreviations.put(curLang, buildStr);
        }

    } else {
        booksLangs = 0;
        booksStr = "";
    }
    kit = new HTMLEditorKit();
    doc = kit.createDefaultDocument();
    styles = kit.getStyleSheet();
    styles.addRule("body { background-color: #FFFFDD; border: 2px inset #CC9900; }");
    styles.addRule("h1 { color: #0000AA; }");
    styles.addRule("h2 { color: #0000AA; }");
    styles.addRule("h3 { color: #0000AA; }");
    styles.addRule("p { text-align: justify; }");
    styles.addRule("table { border-collapse: collapse; width: 600px; margin-left: auto; }");
    styles.addRule(
            "th { text-align: center; border: 4px ridge #DEB887; background-color: #F5F5DC; padding: 3px; }");
    styles.addRule(
            "td { text-align: justify; border: 3px ridge #DEB887; background-color: #F5F5DC; padding: 3px; }");

    //System.out.println("We have package path in BibleGetHelp! It is: "+packagePath);

    HTMLStr0 = "<html><head><meta charset=\"utf-8\"></head><body>" + "<h1>"
            + __("Help for BibleGet (Open Office Writer)") + "</h1>" + "<p>"
            + __("This Help dialog window introduces the user to the usage of the BibleGet I/O plugin for Open Office Writer.")
            + "</p>" + "<p>" + __("The Help is divided into three sections:") + "</p>" + "<ul>" + "<li>"
            + __("Usage of the Plugin") + "</li>" + "<li>" + __("Formulation of the Queries") + "</li>" + "<li>"
            + __("Biblical Books and Abbreviations") + "</li>" + "</ul>" + "<p><b>" + __("AUTHOR") + ":</b> "
            + __("John R. D'Orazio (chaplain at Roma Tre University)") + "</p>" + "<p><b>" + __("COLLABORATORS")
            + ":</b> " + __("Giovanni Gregori (computing) and Simone Urbinati (MUG Roma Tre)") + "</p>"
            + "<p><b>" + __("Version").toUpperCase() + ":</b> " + String.valueOf(BibleGetIO.VERSION) + "</p>"
            + "<p> <b>Copyright 2014 BibleGet I/O by John R. D'Orazio</b> <span style=\"color:blue;\">john.dorazio@cappellaniauniroma3.org</span></p>"
            + "<p><b>" + __("PROJECT WEBSITE")
            + ": </b><span style=\"color:blue;\">http://www.bibleget.io</span> | <b>"
            + __("EMAIL ADDRESS FOR INFORMATION OR FEEDBACK ON THE PROJECT")
            + ":</b> <span style=\"color:blue;\">bibleget.io@gmail.com</span></p>"
            + "<p>Cappellania Universit degli Studi Roma Tre - Piazzale San Paolo 1/d - 00120 Citt del Vaticano - +39 06.69.88.08.09 - <span style=\"color:blue;\">cappellania.uniroma3@gmail.com</span></p></body></html>";

    String strfmt1 = __("Insert quote from input window");
    String strfmt2 = __("About this plugin");
    String strfmt3 = __("RENEW SERVER DATA");
    String strfmt4 = strfmt1;
    String strfmt5 = __("Insert quote from text selection");
    String strfmt6 = strfmt1;

    HTMLStr1 = "<html><head><meta charset=\"utf-8\"></head><body>" + "<h2>" + __("How to use the plugin")
            + "</h2>" + "<h3>" + __("Description of the menu icons and their functionality.") + "</h3>" + "<p>"
            + __("Once the extension is installed, a new menu 'BibleGet I/O' will appear on the menu bar. Also a new floating toolbar will appear. The buttons on the floating toolbar correspond to the menu items in the new menu, as can be seen in this image:")
            + "</p><br /><br />" + "<img src=\"" + packagePath + "/images/Screenshot.jpg\" /><br /><br />"
            + "<p>"
            + __("The floating toolbar can be dragged and placed anywhere on the screen. It can also be docked to certain areas of the workspace, for example on the toolbar below the menu bar, like in this image:")
            + "</p><br /><br />" + "<img src=\"" + packagePath + "/images/Screenshot2.jpg\" /><br /><br />"
            + "<p>" + __("There are two ways of inserting a bible quote into a document.") + " "
            + __("The first way is by using the input window.") + " "
            + MessageFormat.format(__(
                    "If you click on the menu item ''{0}'', an input window will open where you can input your query and choose the version or versions you would like to take the quote from."),
                    strfmt1)
            + " "
            + __("This list of versions is updated from the available versions on the BibleGet server, but since the information is stored locally it may be necessary to renew the server information when new versions are added to the BibleGet server database.")
            + " "
            + MessageFormat.format(__(
                    "In order to renew the information from the BibleGet server, click on the ''{0}'' menu item, and then click on the button ''{1}''."),
                    strfmt2, strfmt3)
            + " "
            + MessageFormat.format(__(
                    "When you choose a version or multiple versions to quote from, this choice is automatically saved as a preference, and will be pre-selected the next time you open the ''{0}'' menu item."),
                    strfmt4)
            + "<br /><br />" + "<img src=\"" + packagePath + "/images/Screenshot4.jpg\" /><br /><br />"
            + MessageFormat.format(__(
                    "The second way is by writing your desired quote directly in the document, and then selecting it and choosing the menu item ''{0}''. The selected text will be substituted by the Bible Quote retrieved from the BibleGet server."),
                    strfmt5)
            + " "
            + MessageFormat.format(__(
                    "The versions previously selected in the ''{0}'' window will be used, so you must have selected your preferred versions at least once from the ''{0}'' window."),
                    strfmt6)
            + "</p><br /><br />" + "<img src=\"" + packagePath + "/images/Screenshot3.jpg\" /><br /><br />"
            + "<p>"
            + __("Formatting preferences can be set using the 'Preferences' window. You can choose the desired font for the Bible quotes as well as the desired line-spacing, and you can choose separate formatting (font size, font color, font style) for the book / chapter, for the verse numbers, and for the verse text. Preferences are saved automatically.")
            + "</p><br /><br />" + "<img src=\"" + packagePath + "/images/Screenshot5.jpg\" /><br /><br />"
            + "<p>"
            + __("After the 'Help' menu item that opens up this same help window, the last three menu items are:")
            + "</p>" + "<ul>" + "<li><img src=\"" + packagePath + "/images/email.png\" />" + " '"
            + __("Send feedback") + "': <span>"
            + __("This will open up your system's default email application with the bibleget.io@gmail.com feedback address already filled in.")
            + "</span></li>" + "<li><img src=\"" + packagePath + "/images/paypal.png\" />" + " '"
            + __("Contribute") + "': <span>"
            + __("This will open a Paypal page in the system's default browser where you can make a donation to contribute to the project. Even just 1 can help to cover the expenses of this project. Just the server costs 120 a year.")
            + "</span></li>" + "<li><img src=\"" + packagePath + "/images/info.png\" />" + " '"
            + __("Information on the BibleGet I/O Project") + "': <span>"
            + __("This opens a dialog window with some information on the project and it's plugins, on the author and contributors, and on the current locally stored information about the versions and languages that the BibleGet server supports.")
            + "</span></li>" + "</ul>" + "</body></html>";

    String strfmt7 = __("Biblical Books and Abbreviations");

    HTMLStr2 = "<html>" + "<head><meta charset=\"utf-8\"></head>" + "<body>" + "<h2>"
            + __("How to formulate a bible query") + "</h2>" + "<p>"
            + __("The queries for bible quotes must be formulated using standard notation for bible citation.")
            + " "
            + __("This can be either the english notation (as explained here: https://en.wikipedia.org/wiki/Bible_citation), or the european notation as explained here below. ")
            + "</p>" + "<p>"
            + __("A basic query consists of at least two elements: the bible book and the chapter.") + " "
            + __("The bible book can be written out in full, or in an abbreviated form.") + " "
            + MessageFormat.format(__(
                    "The BibleGet engine recognizes the names of the books of the bible in {0} different languages: {1}"),
                    Integer.toString(booksLangs), booksStr)
            + " "
            + MessageFormat.format(__("See the list of valid books and abbreviations in the section {0}."),
                    "<span class=\"internal-link\" id=\"to-bookabbrevs\">" + strfmt7 + "</span>")
            + " "
            + __("For example, the query \"Matthew 1\" means the book of Matthew (or better the gospel according to Matthew) at chapter 1.")
            + " " + __("This can also be written as \"Mt 1\".") + "</p>" + "<p>"
            + __("Different combinations of books, chapters, and verses can be formed using the comma delimiter and the dot delimiter (in european notation, in english notation instead a colon is used instead of a comma and a comma is used instead of a dot):")
            + "</p>" + "<ul>" + "<li>"
            + __("\",\": the comma is the chapter-verse delimiter. \"Matthew 1,5\" means the book (gospel) of Matthew, chapter 1, verse 5. (In English notation: \"Matthew 1:5\".)")
            + "</li>" + "<li>"
            + __("\".\": the dot is a delimiter between verses. \"Matthew 1,5.7\" means the book (gospel) of Matthew, chapter 1, verses 5 and 7. (In English notation: \"Matthew 1:5,7\".)")
            + "</li>" + "<li>"
            + __("\"-\": the dash is a range delimiter, which can be used in a variety of ways:") + "<ol>"
            + "<li>"
            + __("For a range of chapters: \"Matthew 1-2\" means the gospel according to Matthew, from chapter 1 to chapter 2.")
            + "</li>" + "<li>"
            + __("For a range of verses within the same chapter: \"Matthew 1,1-5\" means the gospel according to Matthew, chapter 1, from verse 1 to verse 5. (In English notation: \"Matthew 1:1-5\".)")
            + "</li>" + "<li>"
            + __("For a range of verses that span over different chapters: \"Matthew 1,5-2,13\" means the gospel according to Matthew, from chapter 1, verse 5 to chapter 2, verse 13. (In English notation: \"Matthew 1:5-2:13\".)")
            + "</li>" + "</ol>" + "</ul>" + "<p>"
            + __("Different combinations of these delimiters can form fairly complex queries, for example \"Mt1,1-3.5.7-9\" means the gospel according to Matthew, chapter 1, verses 1 to 3, verse 5, and verses 7 to 9. (In English notation: \"Mt1:1-3,5,7-9\".)")
            + "</p>" + "<p>" + __("Multiple queries can be combined together using a semi-colon \";\".") + " "
            + __("If the query following the semi-colon refers to the same book as the preceding query, it is not necessary to indicate the book a second time.")
            + " "
            + __("For example, \"Matthew 1,1;2,13\" means the gospel according to Matthew, chapter 1 verse 1 and chapter 2 verse 13. (In English notation: \"Matthew 1:1;2:13\".)")
            + " "
            + __("Here is an example of multiple complex queries combined into a single querystring: \"Genesis 1,3-5.7.9-11.13;2,4-9.11-13;Apocalypse 3,10.12-14\". (In English notation: \"Genesis 1:3-5,7,9-11,13;2:4-9,11-13;Apocalypse 3:10,12-14\").")
            + "</p>" + "<p>"
            + __("It doesn't matter whether or not you use a space between the book and the chapter, the querystring will be interpreted just the same.")
            + __("It is also indifferent whether you use uppercase or lowercase letters, the querystring will be interpreted just the same.")
            + "</p>" + "</body>" + "</html>";

    HTMLStr3 = "<html>" + "<head><meta charset=\"utf-8\"></head>" + "<body>" + "<h2>"
            + __("Biblical Books and Abbreviations") + "</h2>" + "<p>"
            + __("Here is a list of valid books and their corresponding abbreviations, either of which can be used in the querystrings.")
            + " "
            + __("The abbreviations do not always correspond with those proposed by the various editions of the Bible, because they would conflict with those proposed by other editions.")
            + " "
            + __("For example some english editions propose \"Gn\" as an abbreviation for \"Genesis\", while some italian editions propose \"Gn\" as an abbreviation for \"Giona\" (= \"Jonah\").")
            + " "
            + __("Therefore you will not always be able to use the abbreviations proposed by any single edition of the Bible, you must use the abbreviations that are recognized by the BibleGet engine as listed in the following table:")
            + "</p><br /><br />" + "<table cellspacing='0'>" + "<caption>{1}</caption>"
            + "<tr><th style=\"width:70%;\">" + __("BOOK") + "</th><th style=\"width:30%;\">"
            + __("ABBREVIATION") + "</th></tr>" + "{0}" + "</table>" + "</body>" + "</html>";

    Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    screenWidth = (int) screenSize.getWidth();
    screenHeight = (int) screenSize.getHeight();
    frameWidth = 1250;
    frameHeight = 700;
    frameLeft = (screenWidth / 2) - (frameWidth / 2);
    frameTop = (screenHeight / 2) - (frameHeight / 2);
    initComponents();
}