Example usage for org.jsoup.nodes Element text

List of usage examples for org.jsoup.nodes Element text

Introduction

In this page you can find the example usage for org.jsoup.nodes Element text.

Prototype

public String text() 

Source Link

Document

Gets the combined text of this element and all its children.

Usage

From source file:org.asqatasun.rules.textbuilder.SimpleTextElementBuilder.java

@Override
public String buildTextFromElement(Element element) {
    return StringUtils.trim(element.text());
}

From source file:org.b3log.solo.plugin.list.ListHandler.java

@Override
public void action(final Event<JSONObject> event) throws EventException {
    final JSONObject data = event.getData();
    final JSONObject article = data.optJSONObject(Article.ARTICLE);

    String content = article.optString(Article.ARTICLE_CONTENT);

    final Document doc = Jsoup.parse(content, StringUtils.EMPTY, Parser.htmlParser());
    doc.outputSettings().prettyPrint(false);

    final StringBuilder listBuilder = new StringBuilder();

    listBuilder.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + Latkes.getStaticServePath()
            + "/plugins/list/style.css\" />");

    final Elements hs = doc.select("h1, h2, h3, h4, h5");

    listBuilder.append("<ul class='b3-solo-list'>");
    for (int i = 0; i < hs.size(); i++) {
        final Element element = hs.get(i);
        final String tagName = element.tagName().toLowerCase();
        final String text = element.text();
        final String id = "b3_solo_" + tagName + "_" + i;

        element.before("<span id='" + id + "'></span>");

        listBuilder.append("<li class='b3-solo-list-").append(tagName).append("'><a href='#").append(id)
                .append("'>").append(text).append("</a></li>");
    }//w w w  . j  a va  2s. co m
    listBuilder.append("</ul>");

    final Element body = doc.getElementsByTag("body").get(0);

    content = listBuilder.toString() + body.html();

    article.put(Article.ARTICLE_CONTENT, content);
}

From source file:org.bigmouth.tfc.v1.PageImpl.java

@Override
public List<Item> getItems() {
    if (null == this.asynSearchDoc) {
        throw new IllegalStateException("Please do init.");
    }// www .  j a  va 2  s  .co m
    List<Item> result = Lists.newArrayList();
    Elements itemLines = asynSearchDoc.select("div.J_TItems div");
    for (Element line : itemLines) {
        Elements items = line.select(".item");
        for (Element item : items) {
            Elements data = item.select(".J_TGoldData");
            if (CollectionUtils.isNotEmpty(data)) {
                // ?
                Item o = new Item();
                Elements a = item.select(".detail a");
                String name = a.text();
                if (LOGGER.isInfoEnabled()) {
                    LOGGER.info("Captured item: {}", name);
                }
                o.setName(name);

                Elements priceElements = item.select(".detail .attribute .cprice-area .c-price");
                if (CollectionUtils.isNotEmpty(priceElements)) {
                    Element price = priceElements.get(0);
                    o.setPrice(new BigDecimal(price.text()));
                }

                Element datainf = data.get(0);
                String href = Constants.PROTOCOL_PREFIX + datainf.attr("href");

                o.setUrl(href);

                DetailPage dp = new DetailPage(href);
                o.parseAttributes(dp.getAttributes());

                result.add(o);
            } else {
                // ??
            }
        }
    }
    return result;
}

From source file:org.bigmouth.tfc.v1.PageIteratorImpl.java

protected void initPagination() {
    Elements paginationEle = this.asynSearchDoc.select("div.J_TItems .pagination");
    if (CollectionUtils.isNotEmpty(paginationEle)) {
        Element firstPagination = paginationEle.get(0);
        Elements aEles = firstPagination.select("a");
        if (CollectionUtils.isNotEmpty(aEles)) {
            for (Element element : aEles) {
                String href = element.attr("href");
                if (StringHelper.isNotBlank(href)) {
                    String url = Constants.PROTOCOL_PREFIX + href;
                    String text = element.text();
                    int pageNo = NumberUtils.toInt(text, -1);
                    if (pageNo != -1) {
                        this.elementData.add(new PageImpl(url, pageNo));
                    }/*from   w  w  w  .ja v  a  2  s  .co  m*/
                }
            }
        }
    }
}

From source file:org.commonjava.aprox.ftest.core.urls.StoreOneAndSourceStoreUrlInHtmlListingTest.java

@Test
public void storeOneFileAndVerifyItInParentDirectoryListing() throws Exception {
    final byte[] data = "this is a test".getBytes();
    final ByteArrayInputStream stream = new ByteArrayInputStream(data);
    final String root = "/path/to/";
    final String path = root + "foo.txt";

    client.content().store(hosted, STORE, path, stream);

    final AproxClientHttp http = getHttp();

    final HttpGet request = http.newRawGet(client.content().contentUrl(hosted, STORE, root));

    request.addHeader("Accept", "text/html");

    final CloseableHttpClient hc = http.newClient();
    final CloseableHttpResponse response = hc.execute(request);

    final InputStream listing = response.getEntity().getContent();
    final String html = IOUtils.toString(listing);

    // TODO: Charset!!
    final Document doc = Jsoup.parse(html);
    for (final Element item : doc.select("a.source-link")) {
        final String fname = item.text();
        System.out.printf("Listing contains: '%s'\n", fname);
        final String href = item.attr("href");
        final String expected = client.content().contentUrl(hosted, STORE);

        assertThat(fname + " does not have a href", href, notNullValue());
        assertThat(fname + " has incorrect link: '" + href + "' (" + href.getClass().getName()
                + ")\nshould be: '" + expected + "' (String)", href, equalTo(expected));
    }/*from w  w w .  j ava  2 s  . c  o m*/
}

From source file:org.commonjava.aprox.ftest.core.urls.StoreOneAndVerifyInHtmlListingTest.java

@Test
public void storeOneFileAndVerifyItInParentDirectoryListing() throws Exception {
    final byte[] data = "this is a test".getBytes();
    final ByteArrayInputStream stream = new ByteArrayInputStream(data);
    final String root = "/path/to/";
    final String path = root + "foo.txt";

    client.content().store(hosted, STORE, path, stream);

    final AproxClientHttp http = getHttp();

    final HttpGet request = http.newRawGet(client.content().contentUrl(hosted, STORE, root));

    request.addHeader("Accept", "text/html");

    final CloseableHttpClient hc = http.newClient();
    final CloseableHttpResponse response = hc.execute(request);

    final InputStream listing = response.getEntity().getContent();
    final String html = IOUtils.toString(listing);

    // TODO: Charset!!
    final Document doc = Jsoup.parse(html);
    for (final Element item : doc.select("a.item-link")) {
        final String fname = item.text();
        System.out.printf("Listing contains: '%s'\n", fname);
        final String href = item.attr("href");
        final String expected = client.content().contentUrl(hosted, STORE, root, fname);

        assertThat(fname + " does not have a href", href, notNullValue());
        assertThat(fname + " has incorrect link: '" + href + "' (" + href.getClass().getName()
                + ")\nshould be: '" + expected + "' (String)", href, equalTo(expected));
    }/*  w  w  w .j  av  a  2s .c  o m*/
}

From source file:org.crazyt.xgogdownloader.Main.java

public static void main(String[] args) {
    Util util = new Util();
    Config.sVersionString = VERSION_STRING + VERSION_NUMBER;
    Config.sConfigDirectory = "xgogdownloader";
    Config.sCookiePath = "cookies.txt";
    Config.sConfigFilePath = "config.cfg";
    Config.sXMLDirectory = "xgogdownloader/xml";
    // Create xgogdownloader directories
    File path = Factory.newFile(Config.sXMLDirectory);
    if (!path.exists()) {
        if (!path.mkdirs()) {
            System.out.print("Failed to create directory: ");
            System.out.print(path);
            throw new RuntimeException("Failed to create directory. ");
        }/*from w  ww. j  a  va  2s  .  c o  m*/
    }
    path = Factory.newFile(Config.sConfigDirectory);
    if (!path.exists()) {
        if (!path.mkdirs()) {
            System.out.print("Failed to create directory: ");
            System.out.print(path);
            throw new RuntimeException("Failed to create directory. ");
        }
    }
    // Create help text for --platform option
    String platform_text = "Select which installers are downloaded\n";
    int platform_sum = 0;
    for (int i = 0; i < GlobalConstants.PLATFORMS.size(); ++i) {
        platform_text += GlobalConstants.PLATFORMS.get(i).platformId + " = "
                + GlobalConstants.PLATFORMS.get(i).platformString + "\n";
        platform_sum += GlobalConstants.LANGUAGES.get(i).languageId;
    }
    platform_text += platform_sum + " = All";

    // Create help text for --language option
    String language_text = "Select which language installers are downloaded\n";
    int language_sum = 0;
    for (int i = 0; i < GlobalConstants.LANGUAGES.size(); ++i) {
        language_text += GlobalConstants.LANGUAGES.get(i).languageId + " = "
                + GlobalConstants.LANGUAGES.get(i).languageString + "\n";
        language_sum += GlobalConstants.LANGUAGES.get(i).languageId;
    }
    language_text += "Add the values to download multiple languages\nAll = " + language_sum + "\n"
            + "French + Polish = " + GlobalConstants.LANGUAGE_FR + "+" + GlobalConstants.LANGUAGE_PL + " = "
            + GlobalConstants.LANGUAGE_FR + GlobalConstants.LANGUAGE_PL;

    // Create help text for --check-orphans
    String[] orphans_regex_default = new String[] { "zip", "exe", "bin", "dmg", "old" };
    // List<File> files = (List<File>) FileUtils.listFiles(dir, extensions,
    // true);
    String check_orphans_text = "Check for orphaned files (files found on local filesystem that are not found on GOG servers). Sets regular expression filter (Perl syntax) for files to check. If no argument is given then the regex defaults to '"
            + StringUtils.join(orphans_regex_default, ",") + "'";

    CommandOptions options_cli_all = new CommandOptions();
    CommandOptions options_cli_no_cfg = new CommandOptions();
    ConfigOptions options_cli_cfg = new ConfigOptions();
    ConfigOptions options_cfg_only = new ConfigOptions();
    ConfigOptions options_cfg_all = new ConfigOptions();
    try {
        OptionValue<Boolean> bInsecure = new OptionValue<>(false);
        OptionValue<Boolean> bNoColor = new OptionValue<>(false);
        OptionValue<Boolean> bNoUnicode = new OptionValue<>(false);
        OptionValue<Boolean> bNoDuplicateHandler = new OptionValue<>(false);
        OptionValue<Boolean> bNoCover = new OptionValue<>(false);
        OptionValue<Boolean> bNoInstallers = new OptionValue<>(false);
        OptionValue<Boolean> bNoExtras = new OptionValue<>(false);
        OptionValue<Boolean> bNoPatches = new OptionValue<>(false);
        OptionValue<Boolean> bNoLanguagePacks = new OptionValue<>(false);
        OptionValue<Boolean> bNoRemoteXML = new OptionValue<>(false);
        OptionValue<Boolean> bNoSubDirectories = new OptionValue<>(false);

        OptionValue<String> sGame = new OptionValue<>("free");
        OptionValue<String> sToken = new OptionValue<>("");
        OptionValue<String> sSecret = new OptionValue<>("");
        OptionValue<String> sSearch = new OptionValue<>("");
        OptionValue<Boolean> bList = new OptionValue<>(false);
        OptionValue<Boolean> bDownload = new OptionValue<>(false);
        OptionValue<Integer> iDownloadRate = new OptionValue<>(0);

        // //switch to OptionBuilder
        // Commandline options (no config file)
        options_cli_no_cfg.addOption("debug", "d", false, "Print debug messages");
        options_cli_no_cfg.addOption("help", "h", false, "Print help message");
        options_cli_no_cfg.addOption("version", false, "Print version information");
        options_cli_no_cfg.addOption("versionUpdate", false, "Updates this program to the current version.");
        options_cli_no_cfg.addOption("login", true, "Login");
        // config.bLogin false
        options_cli_no_cfg.addOption(bList, "list", false, "List games");
        // config.bList false
        options_cli_no_cfg.addOption(sSearch, "search", true, "search games by title");
        options_cli_no_cfg.addOption("listdetails", "list-details", true, "List games with detailed info"); // config.bListDetails
        // false
        options_cli_no_cfg.addOption(bDownload, "download", false, "Download");
        // config.bDownload false
        options_cli_no_cfg.addOption("repair", true,
                "Repair downloaded files\nUse --repair --download to redownload files when filesizes don't match (possibly different version). Redownload will delete the old file"); // config.bRepair
        // false
        options_cli_no_cfg.addOption("game", true,
                "Set regular expression filter\nfor download/list/repair (Perl syntax)\nAliases: \"all\", \"free\""); // config.sGameRegex
        // ""
        options_cli_no_cfg.addOption("createxml", "create-xml", true,
                "Create GOG XML for file\n\"automatic\" to enable automatic XML creation"); // config.sXMLFile
        // ""
        options_cli_no_cfg.addOption("updatecheck", "update-check", true, "Check for update notifications");
        // config.bUpdateCheck false

        options_cli_no_cfg.addOption("checkorphans", "check-orphans", true, check_orphans_text);
        // config.sOrphanRegex ""

        options_cli_no_cfg.addOption("status", true,
                "Show status of files\n\nOutput format:\nstatuscode gamename filename filesize filehash\n\nStatus codes:\nOK - File is OK\nND - File is not downloaded\nMD5 - MD5 mismatch, different version");// config.bCheckStatus
        // false
        options_cli_no_cfg.addOption("saveconfig", "save-config", true,
                "Create config file with current settings");
        // config.bSaveConfig false

        options_cli_no_cfg.addOption("resetconfig", "reset-config", true, "Reset config settings to default");
        // config.bResetConfig false

        options_cli_no_cfg.addOption("report", true, "Save report of downloaded/repaired files");
        // config.bReport false

        // Commandline options (config file)
        options_cli_cfg.addOption("directory", true, "Set download directory");
        // config.sDirectory ""

        options_cli_cfg.addOption(iDownloadRate, "limitRate", true,
                "Limit download rate to value in kB\n0 = unlimited");
        // config.iDownloadRate 0

        options_cli_cfg.addOption("xmlDirectory", true, "Set directory for GOG XML files");
        // config.sXMLDirectory ""

        options_cli_cfg.addOption("chunkSize", true, "Chunk size (in MB) when creating XML");
        // config.iChunkSize 10

        options_cli_cfg.addOption("platform", true, platform_text);
        // config.iInstallerType GlobalConstants.PLATFORM_WINDOWS

        options_cli_cfg.addOption("language", true, language_text);
        // config.iInstallerLanguage GlobalConstants.LANGUAGE_EN

        options_cli_cfg.addOption("noInstallers", true, "Don't download/list/repair installers");
        // bNoInstallers false

        options_cli_cfg.addOption("noExtras", true, "Don't download/list/repair extras");
        // bNoExtras false

        options_cli_cfg.addOption("noPatches", true, "Don't download/list/repair patches");
        // bNoPatches false

        options_cli_cfg.addOption("noLanguagePacks", true, "Don't download/list/repair language packs");
        // bNoLanguagePacks false

        options_cli_cfg.addOption("noCover", true, "Don't download cover images");
        // bNoCover false

        options_cli_cfg.addOption("noRemoteXml", true, "Don't use remote XML for repair");
        // bNoRemoteXML false

        options_cli_cfg.addOption(bNoUnicode, "noUnicode", true, "Don't use Unicode in the progress bar");
        // bNoUnicode false

        options_cli_cfg.addOption(bNoColor, "noColor", true, "Don't use coloring in the progress bar");
        // bNoColor false

        options_cli_cfg.addOption("noDuplicateHandling", true,
                "Don't use duplicate handler for installers\nDuplicate installers from different languages are handled separately");// bNoDuplicateHandler
        // false
        options_cli_cfg.addOption("noSubdirectories", true,
                "Don't create subdirectories for extras, patches and language packs");
        // bNoSubDirectories false

        options_cli_cfg.addOption("verbose", true, "Print lots of information");

        options_cli_cfg.addOption("insecure", true, "Don't verify authenticity of SSL certificates");
        // bInsecure false

        options_cli_cfg.addOption("timeout", true,
                "Set timeout for connection\nMaximum time in seconds that connection phase is allowed to take");
        // config.iTimeout 10
        options_cli_cfg.addOption("retries", true, "Set maximum number of retries on failed download");
        // config.iRetries 3

        // Options read from config file
        options_cfg_only.addOption(sToken, "token", true, "oauth token");
        // config.sToken ""

        options_cfg_only.addOption(sSecret, "secret", true, "oauth secret");
        // config.sSecret ""

        options_cli_all.addOptions(options_cli_no_cfg);
        options_cli_all.addOptions(options_cli_cfg);

        options_cfg_all.addOptions(options_cfg_only);
        options_cfg_all.addOptions(options_cli_cfg);

        options_cfg_all.parse(Config.sConfigFilePath);

        // boost.program_options.store(boost.program_options
        // .parse_command_line(argc, args, options_cli_all), vm);

        CommandLineParser parser = new GnuParser();
        String[] args2;
        if (args.length == 0) {
            args2 = new String[] { "-help" };
        } else {
            args2 = args;
        }
        CommandLine cmd = parser.parse(options_cli_all, args2);
        options_cli_all.parseCmdLine(cmd);

        path = Factory.newFile(Config.sConfigDirectory);
        if (path.exists()) {
            Properties prop = new Properties();
            try {
                FileInputStream fileInputStream = new FileInputStream(
                        Config.sConfigDirectory + File.separatorChar + Config.sConfigFilePath);
                try {
                    prop.load(fileInputStream);
                } finally {
                    fileInputStream.close();
                }
            } catch (FileNotFoundException e) {
                System.out.println("Could not open config file: " + Config.sConfigDirectory + File.separatorChar
                        + Config.sConfigFilePath + ", creating new one.");
                Factory.newFile(Config.sConfigDirectory + File.separatorChar + Config.sConfigFilePath)
                        .createNewFile();
            }
        }

        if (cmd.hasOption("help")) {
            System.out.println(Config.sVersionString);
            System.out.println("Options:");
            for (Option option : (Collection<Option>) options_cli_all.getOptions()) {
                System.out.println(String.format("%20s\t-\t%s", option.getOpt(),
                        option.getDescription().replace("\n", String.format("\n%20s\t \t", ""))));
            }
            return;
        }
        if (cmd.hasOption("version")) {
            System.out.print(Config.sVersionString);
            return;
        }
        if (cmd.hasOption("versionUpdate")) {
            String sub = "xgogdownloader-";

            try {
                HttpClient client = Factory.createHttpClient();
                HttpGet request = new HttpGet("https://drone.io/github.com/TheCrazyT/xgogdownloader/files");
                request.setHeader("User-Agent", Main.USER_AGENT);
                HttpResponse response_full = client.execute(request);
                int result = response_full.getStatusLine().getStatusCode();

                if (result != HttpStatus.SC_OK) {
                    System.err.println("Error " + result);
                }
                String response = EntityUtils.toString(response_full.getEntity());
                Document html = Jsoup.parse(response);

                Iterator<org.jsoup.nodes.Element> iterator = html.getElementsByTag("div").iterator();
                while (iterator.hasNext()) {
                    org.jsoup.nodes.Element node = iterator.next();
                    String hash = "";
                    Elements spans = node.getElementsByTag("span");
                    Iterator<org.jsoup.nodes.Element> iterator2 = spans.iterator();
                    while (iterator2.hasNext()) {
                        org.jsoup.nodes.Element span = iterator2.next();
                        if (span.text().startsWith("SHA")) {
                            hash = span.text().substring(4, 44);
                            break;
                        }
                    }
                    if (!hash.isEmpty()) {
                        iterator2 = node.getElementsByTag("a").iterator();
                        while (iterator2.hasNext()) {
                            Element a = iterator2.next();
                            String url = a.attr("href");
                            if (a.text().startsWith(sub) && a.text().endsWith(".zip")) {
                                // TODO
                                System.out.println("... TODO ...");
                                System.out.println(url);
                                return;
                            }
                        }
                    }
                }

                return;
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        if (cmd.hasOption("chunkSize")) {
            Config.iChunkSize <<= 20;
            // Convert chunk size from bytes to megabytes
        }

        if (cmd.hasOption("limitRate")) {
            Config.iDownloadRate = iDownloadRate.getValue();
            Config.iDownloadRate <<= 10;
            // Convert download rate from bytes to kilobytes
        }
        if (cmd.hasOption("check-orphans")) {
            if (Config.sOrphanRegex.isEmpty()) {
                Config.sOrphanRegex = StringUtils.join(orphans_regex_default, "|");
            }
        }

        Config.bDownload = bDownload.getValue();
        Config.sToken = sToken.getValue();
        Config.sSecret = sToken.getValue();
        Config.sSearch = sSearch.getValue();
        Config.sGameRegex = sGame.getValue();
        Config.bList = bList.getValue();

        Config.bVerifyPeer = !bInsecure.getValue();
        Config.bColor = !bNoColor.getValue();
        Config.bUnicode = !bNoUnicode.getValue();
        Config.bDuplicateHandler = !bNoDuplicateHandler.getValue();
        Config.bCover = !bNoCover.getValue();
        Config.bInstallers = !bNoInstallers.getValue();
        Config.bExtras = !bNoExtras.getValue();
        Config.bPatches = !bNoPatches.getValue();
        Config.bLanguagePacks = !bNoLanguagePacks.getValue();
        Config.bRemoteXML = !bNoRemoteXML.getValue();
        Config.bSubDirectories = !bNoSubDirectories.getValue();
    } catch (RuntimeException e) {
        System.err.println("Error: " + e.getMessage());
        throw e;
    } catch (java.lang.Exception e) {
        System.err.println("Exception of unknown type!");
        throw new RuntimeException(e);
    }

    if (Config.iInstallerType < GlobalConstants.PLATFORMS.get(0).platformId
            || Config.iInstallerType > platform_sum) {
        System.out.println("Invalid value for --platform");
        throw new RuntimeException("Invalid value for --platform");
    }

    if (Config.iInstallerLanguage < GlobalConstants.LANGUAGES.get(0).languageId
            || Config.iInstallerLanguage > language_sum) {
        System.out.println("Invalid value for --language");
        throw new RuntimeException("Invalid value for --language");
    }

    if (Config.sXMLDirectory != "") {
        // Make sure that xml directory doesn't have trailing slash
        if (Config.sXMLDirectory.charAt(Config.sXMLDirectory.length() - 1) == '/') {
            // config.sXMLDirectory.assign(config.sXMLDirectory.begin(),config.sXMLDirectory.end()
            // - 1);
        }
    }
    // Create GOG XML for a file
    if ((Config.sXMLFile != null) && !Config.sXMLFile.isEmpty() && !Config.sXMLFile.equals("automatic")) {
        util.createXML(Config.sXMLFile, Config.iChunkSize, Config.sXMLDirectory);
    }
    // Make sure that directory has trailing slash
    // if (Config.sDirectory != null && !Config.sDirectory.isEmpty()) {
    // if (Config.sDirectory.charAt(Config.sDirectory.length() - 1) != '/')
    // {
    // Config.sDirectory += "/";
    // }
    // }
    Downloader downloader = new Downloader();
    boolean result = downloader.init();

    if (Config.bLogin) {
        if (!result) {
            throw new RuntimeException("downloader.init failed");
        }
        return;
    } else if (Config.bSaveConfig) {
        // std.ofstream ofs = new
        // std.ofstream(config.sConfigFilePath.c_str());
        String ofs = null;
        if (ofs != null) {
            System.out.println("Saving config: " + Config.sConfigFilePath);
            /*
             * for (boost.program_options.variables_map.iterator it =
             * vm.begin(); it != vm.end(); ++it) { String option = it.first;
             * String option_value_string;
             * boost.program_options.variable_value option_value =
             * it.second;
             * 
             * try { if (option.equals(options_cfg_all.find(option,
             * false).long_name())) { if (!option_value.empty()) {
             * std.type_info type = option_value.value().type(); if (type ==
             * typeid(String)) { option_value_string =
             * option_value.<String>as(); }
             * 
             * } } } catch (java.lang.Exception e2) { continue; }
             * 
             * if (option_value_string!="") {
             * System.out.println(option+" = "+option_value_string); //ofs
             * << option.compareTo() < 0 < < " = " <<
             * option_value_string.compareTo() < 0 < < std.endl; } }
             * //ofs.close();
             */
        } else {
            System.out.println("Failed to create config: " + Config.sConfigFilePath);
            throw new RuntimeException("Failed to create config: " + Config.sConfigFilePath);
        }
    } else if (Config.bResetConfig) {
        String ofs = null;
        // std.ofstream ofs = new
        // std.ofstream(config.sConfigFilePath.c_str());
        if (ofs != null) {
            /*
             * if (config.sToken!="" && config.sSecret!="") { ofs
             * +="token = " +config.sToken+"\n"; ofs +="secret = "
             * +config.sSecret+"\n"; }
             */
            // ofs.close();
        } else {
            System.out.println("Failed to create config: " + Config.sConfigFilePath);
            throw new RuntimeException("Failed to create config: " + Config.sConfigFilePath);
        }
    } else if (Config.bUpdateCheck) {
        // Update check has priority over download and list
        downloader.updateCheck();
    } else if (Config.bRepair) {
        // Repair file
        downloader.repair();
    } else if ((Config.sSearch != null) && (!Config.sSearch.isEmpty())) {
        // search games
        downloader.searchGames(Config.sSearch);
    } else if (Config.bDownload) {
        // Download games
        downloader.download();
    } else if (Config.bListDetails || Config.bList) {
        // Detailed list of games/extras
        downloader.listGames();
    } else if (Config.sOrphanRegex != null) {
        // Check for orphaned files if regex for orphans is set
        downloader.checkOrphans();
    } else if (Config.bCheckStatus) {
        downloader.checkStatus();
    } else {
        // Show help message
        System.out.println(Config.sVersionString + "" + options_cli_all);
    }

    // Orphan check was called at the same time as download. Perform it
    // after download has finished
    if (Config.sOrphanRegex != null && Config.bDownload) {
        downloader.checkOrphans();
    }
    return;
}

From source file:org.dataconservancy.ui.it.UiConfigurationActionBeanIT.java

/**
 * Insures that an XSD schema, composed of a single schema document (no &lt;xsd:include> statements), can be
 * added to the system.//from ww  w.ja  va2s  .  c  om
 *
 * @throws Exception
 */
@Test
public void testAddMavenPomMetadataFormat() throws Exception {
    // Get a count of the current number of metadata formats in the system
    List<UiConfigurationActionBean.MetaDataFormatTransport> mdfts = getMdfs();
    int mdfCount = mdfts.size();

    // Compose the mdft to add
    final UiConfigurationActionBean.MetaDataFormatTransport mdft = new UiConfigurationActionBean()
            .getNewMetadataFormatTransport();
    final AddMetadataFormatRequest req = new AddMetadataFormatRequest(urlConfig);
    // A unique name insures that this Metadata Format doesn't exist yet in the system (but we verify this
    // assumption anyway)
    final String name = UUID.randomUUID().toString();
    final boolean validates = true;
    final String version = this.getClass().getSimpleName() + " Maven 4.0.0 POM";
    final boolean appliesToCollection = false;
    final boolean appliesToProject = false;
    final boolean appliesToItem = true;
    final List<String> disciplineIds = Arrays.asList("dc:discipline:Biology");
    mdft.setName(name);
    mdft.setVersion(version);
    mdft.setSchemaURL(MAVEN_MODEL_4_0_0_SCHEMA_URL);
    mdft.setSchemaSource(MAVEN_MODEL_4_0_0_SCHEMA_URL);
    mdft.setValidates(validates);
    mdft.setAppliesToCollection(appliesToCollection);
    mdft.setAppliesToProject(appliesToProject);
    mdft.setAppliesToItem(appliesToItem);
    mdft.setDisciplineIds(disciplineIds);

    // Insure that the new Metadata Format being added isn't in the list of existing metadata formats
    assertFalse(mdfts.contains(mdft));

    // Add the metadata format
    HttpAssert.ResponseHolder holder = new HttpAssert.ResponseHolder();

    HttpAssert.assertStatus(hc, req.asHttpPost(mdft), 200, holder);

    final String html = IOUtils.toString(holder.getBody());
    assertNotNull(html);
    final Document dom = Jsoup.parse(html);
    assertNotNull(dom);
    Element nameElement = dom.getElementById("schemaName");
    assertNotNull(nameElement);
    String testText = nameElement.text();
    assertTrue(nameElement.text().equalsIgnoreCase("Schema Name: " + name));

    Element versionElement = dom.getElementById("schemaVersion");
    assertNotNull(versionElement);
    assertTrue(versionElement.text().equalsIgnoreCase("Version: " + version));

    Element namespacesElement = dom.getElementById("namespaces");
    //assertEquals(2, namespacesElement.childNodeSize());

    Elements namespaceElements = namespacesElement.children();
    boolean foundPrefixedNamespace = false;
    boolean foundNamespace = false;
    for (Element namespaceElement : namespaceElements) {
        String namespaceText = namespaceElement.text();
        if (namespaceText.contains("Namespace:")) {
            if (namespaceText.contains("Prefix")) {
                assertTrue(namespaceText
                        .equalsIgnoreCase("Namespace: http://www.w3.org/2001/XMLSchema Prefix: xs"));
                foundPrefixedNamespace = true;
            } else {
                assertTrue(namespaceText.equalsIgnoreCase("Namespace: http://maven.apache.org/POM/4.0.0"));
                foundNamespace = true;
            }
        }
    }

    assertTrue(foundPrefixedNamespace);
    assertTrue(foundNamespace);

    // Now we need to persist the format in the system by emulating a click on the "save" button
    HttpAssert.assertStatus(hc, new SaveMetadataFormatRequest(urlConfig).asHttpPost(), 200);

    // insure that the format we've added was added properly (all the values for table columns were
    // persisted properly)
    mdfts = getMdfs();
    assertTrue(mdfts.contains(mdft));
    assertEquals(mdfCount + 1, mdfts.size());
}

From source file:org.dronix.android.unisannio.fragment.TabOne.java

public List<News> getNews() {
    List<News> newsList = new ArrayList<News>();

    try {//  w ww.ja  v a2  s  .com
        Document doc = Jsoup.connect(URL).timeout(10000).get();
        Elements newsItems = doc.select("div.meta > table > tbody > tr");

        for (int i = 2; i < newsItems.size(); i++) {
            String date = null;
            Element dateElement = newsItems.get(i).select("p").first();
            if (dateElement != null) {
                date = dateElement.text();
            }

            String body = null;
            Element bodyElement = newsItems.get(i).select("a").first();
            if (bodyElement != null) {
                body = bodyElement.text();
            }

            if (date != null && body != null)
                newsList.add(new News(date, body));
        }

    } catch (SocketException e) {
        return null;
    } catch (IOException e) {
        e.printStackTrace();
    }

    /*
     * for (News n : newsList) { Log.i("NEWS", n.getDate() + " " +
     * n.getBody()); }
     */
    return newsList;
}

From source file:org.jorge.lolin1dp.io.net.Internet.java

public static List<ArticleWrapper> getNews(String baseUrl, String url) {
    Elements newsHeadLines, newsSubTitles, descVerification;
    try {/*w w  w . j ava 2  s.  c  o m*/
        System.out.println("Performing get on " + url);
        Document doc = Jsoup.connect(url).timeout(URL_TIMEOUT_MILLIS).get();
        System.out.println("Get performed on " + url);
        newsHeadLines = doc.select("div.panelizer-view-mode").select("div.node").select("div.node-teaser")
                .select("div.node-article").select("div.field").select("div.field-name-field-article-media")
                .select("div.field-type-file").select("div.field-label-hidden");
        newsSubTitles = doc.select("div.field").select("div.field-name-field-body-medium")
                .select("div.field-type-text-long").select("div.field-label-hidden");
        descVerification = doc.select("div.default-2-3");
    } catch (IOException e) {
        e.printStackTrace(System.err);
        return new ArrayList<ArticleWrapper>();
    }

    final List<ArticleWrapper> ret = new ArrayList<>();
    Boolean addThis = Boolean.TRUE;
    int i = 0;
    for (Element elem : newsHeadLines) {

        Element linkElem = elem.getElementsByTag("a").first(), imageElem = elem.getElementsByTag("img").first();

        if (addThis) {
            final String title = linkElem.attr("title");
            final String link = baseUrl + linkElem.attr("href");
            final String imageLink = baseUrl + imageElem.attr("src");
            final String subtitle;
            if (descVerification.get(i).select("div").size() < 7) {
                subtitle = "";
            } else {
                Element removed = newsSubTitles.remove(0);
                subtitle = removed.text();
            }
            ret.add(new ArticleWrapper(title, link, imageLink, subtitle));
            addThis = Boolean.FALSE;
            i++;
        } else {
            addThis = Boolean.TRUE;
        }
    }

    return ret;
}