Example usage for org.w3c.dom DOMException printStackTrace

List of usage examples for org.w3c.dom DOMException printStackTrace

Introduction

In this page you can find the example usage for org.w3c.dom DOMException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:Pathway2Rdf.java

public static void main(String[] args) {
    // The identifer of the pathway under scrutiny

    // Initiate the model
    Model model = ModelFactory.createDefaultModel();
    try {/*  www .j a va 2s  .  co m*/
        File fileName = new File("/tmp/WpGPML/WP1531_45011.gpml");
        String gpml = FileUtils.readFileToString(fileName);
        String wpIdentifier = fileName.getName().substring(0, fileName.getName().indexOf("_"));
        String wpRevision = fileName.getName().substring(fileName.getName().indexOf("_") + 1,
                fileName.getName().indexOf("."));
        addPathway2Rdf(wpIdentifier, wpRevision, gpml);
        System.out.println(FOAF.NS);
        // FileOutputStream fout;
        // fout = new FileOutputStream("/tmp/" + wpIdentifier + ".rdf");
        // model.write(fout, "N-TRIPLE");
    } catch (DOMException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (XPathExpressionException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (ServiceException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (ConverterException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (ParserConfigurationException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (SAXException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:controllers.BIProxy.java

public static F.Promise<Result> index(String query) {

    if (StringUtils.isEmpty(query)) {

        F.Promise.promise(new F.Function0<Object>() {
            @Override/*w  ww.j a va 2  s .  co m*/
            public Object apply() throws Throwable {
                return ok(Json.toJson("Query parameter (q) not provided "));
            }

        });
    }

    F.Promise<WSResponse> wsResponsePromise = WS.url("http://www.businessinsider.com/s")
            .setQueryParameter("q", query).get();

    return wsResponsePromise.map(new F.Function<WSResponse, Result>() {
        @Override
        public Result apply(WSResponse wsResponse) throws Throwable {

            String body = wsResponse.getBody();
            List<Map<String, String>> results = new ArrayList<Map<String, String>>();

            try {
                // Insert into map
                org.jsoup.nodes.Document doc = Jsoup.parse(body);
                Elements items = doc.select("div.search-result");

                // Iterate through results
                for (Element item : items) {
                    Map<String, String> keyValue = new LinkedHashMap<String, String>();

                    keyValue.put("image", item.select("img").attr("src"));
                    keyValue.put("title", item.select("h3").text());
                    keyValue.put("content", item.select("div.excerpt").first().text());
                    keyValue.put("date", item.select("li.date").text());
                    keyValue.put("url", item.select("a").attr("href"));

                    results.add(keyValue);
                }

            } catch (DOMException e) {
                e.printStackTrace();
            }

            return ok(Json.toJson(results));
        }
    });
}

From source file:controllers.FRBProxy.java

public static F.Promise<Result> index(String query) {

    if (StringUtils.isEmpty(query)) {

        F.Promise.promise(new F.Function0<Object>() {
            @Override//from   w w w .  j av  a 2 s . c om
            public Object apply() throws Throwable {
                return ok(Json.toJson("Query parameter (q) not provided "));
            }

        });
    }

    F.Promise<WSResponse> wsResponsePromise = WS.url("http://www.forbes.com/search/")
            .setQueryParameter("q", query).get();

    return wsResponsePromise.map(new F.Function<WSResponse, Result>() {
        @Override
        public Result apply(WSResponse wsResponse) throws Throwable {

            String body = wsResponse.getBody();

            List<Map<String, String>> results = new ArrayList<Map<String, String>>();

            try {

                // Insert into map
                org.jsoup.nodes.Document doc = Jsoup.parse(body);
                Elements items = doc.select("li.edittools-contentitem"); // All articles belong to this class

                for (Element item : items) {
                    Map<String, String> keyValue = new LinkedHashMap<String, String>();

                    // Check if specific article belongs to gallery class (therefore it contains an image)
                    if (item.hasClass("gallery")) {
                        // Add image key and value to map
                        keyValue.put("image", item.select("img").attr("src"));
                    }

                    // Add the rest of keys and values
                    keyValue.put("title", item.select("h2").select("a").text());
                    keyValue.put("content", item.select("p").first().ownText());
                    keyValue.put("date", item.select("time").text());
                    keyValue.put("url", item.select("h2").select("a").attr("href"));

                    results.add(keyValue);
                }
            } catch (DOMException e) {
                e.printStackTrace();
            }

            return ok(Json.toJson(results));
        }
    });
}

From source file:controllers.KWProxy.java

public static F.Promise<Result> index(String query) {

    if (StringUtils.isEmpty(query)) {

        F.Promise.promise(new F.Function0<Object>() {
            @Override//from  w w w  .j av  a 2s  .  c  o  m
            public Object apply() throws Throwable {
                return ok(Json.toJson("Query parameter (q) not provided "));
            }

        });
    }

    F.Promise<WSResponse> wsResponsePromise = WS.url("http://knowledge.wharton.upenn.edu/")
            .setQueryParameter("s", query).get();

    return wsResponsePromise.map(new F.Function<WSResponse, Result>() {
        @Override
        public Result apply(WSResponse wsResponse) throws Throwable {

            String body = wsResponse.getBody();

            List<Map<String, String>> results = new ArrayList<Map<String, String>>();

            try {

                // Insert into map
                org.jsoup.nodes.Document doc = Jsoup.parse(body);
                Elements items = doc.select("div.article.type-article.status-publish"); // All articles belong to this classes

                for (Element item : items) {
                    Map<String, String> keyValue = new LinkedHashMap<String, String>();

                    // Check if specific article belongs to "has-post-thumbnail" class (therefore it contains an image)
                    if (item.hasClass("has-post-thumbnail")) {
                        // Add image key and value to map
                        keyValue.put("image", item.select("img").attr("src"));
                    }

                    // Add the rest of keys and values
                    keyValue.put("title", item.select("h2").select("a").text());
                    keyValue.put("content", item.select("div.attribute.categorythumbs").first().text());
                    keyValue.put("date", item.select("ul.datestamp").select("li").first().text());
                    keyValue.put("url", item.select("h2").select("a").attr("href"));

                    results.add(keyValue);
                }
            } catch (DOMException e) {
                e.printStackTrace();
            }

            return ok(Json.toJson(results));
        }
    });
}

From source file:controllers.BBProxy.java

public static F.Promise<Result> index(String query) {

    if (StringUtils.isEmpty(query)) {

        F.Promise.promise(new F.Function0<Object>() {
            @Override/*  www . j ava 2  s  .c o m*/
            public Object apply() throws Throwable {
                return ok(Json.toJson("Query parameter (q) not provided "));
            }

        });
    }

    F.Promise<WSResponse> wsResponsePromise = WS.url("http://www.bloomberg.com/search")
            .setQueryParameter("query", query).get();

    return wsResponsePromise.map(new F.Function<WSResponse, Result>() {
        @Override
        public Result apply(WSResponse wsResponse) throws Throwable {

            String body = wsResponse.getBody();

            List<Map<String, String>> ret = new ArrayList<Map<String, String>>();

            try {
                // Insert into map
                org.jsoup.nodes.Document doc = Jsoup.parse(body);
                Elements items = doc.getElementsByClass("search-result");

                for (Element item : items) {
                    Map<String, String> keyValue = new LinkedHashMap<String, String>();

                    keyValue.put("image",
                            item.getElementsByClass("search-result-story__thumbnail__image").attr("src"));
                    keyValue.put("title", item.getElementsByClass("search-result-story__headline").text());

                    int index = item.getElementsByClass("search-result-story__body").text()
                            .indexOf(" (Source: Bloomberg");

                    if (index == -1) {
                        keyValue.put("content", item.getElementsByClass("search-result-story__body").text());
                    } else {
                        keyValue.put("content", item.getElementsByClass("search-result-story__body").text()
                                .substring(0, index));
                    }

                    keyValue.put("date", item.getElementsByClass("published-at").text());
                    keyValue.put("url", "www.bloomberg.com/"
                            + item.getElementsByClass("search-result-story__thumbnail__link").attr("href"));

                    ret.add(keyValue);
                }

            } catch (DOMException e) {
                e.printStackTrace();
            }

            return ok(Json.toJson(ret));
        }
    });
}

From source file:controllers.NWProxy.java

public static F.Promise<Result> index(String query) {

    if (StringUtils.isEmpty(query)) {

        F.Promise.promise(new F.Function0<Object>() {
            @Override//w  ww. ja va  2 s .c o  m
            public Object apply() throws Throwable {
                return ok(Json.toJson("Query parameter (q) not provided "));
            }

        });
    }

    final String officialUrl = "http://www.newsweek.com";

    F.Promise<WSResponse> wsResponsePromise = WS.url(officialUrl + "/search/site/" + query).get();

    return wsResponsePromise.map(new F.Function<WSResponse, Result>() {
        @Override
        public Result apply(WSResponse wsResponse) throws Throwable {

            String body = wsResponse.getBody();

            List<Map<String, String>> results = new ArrayList<Map<String, String>>();

            try {

                // Insert into map
                org.jsoup.nodes.Document doc = Jsoup.parse(body);
                Elements items = doc.select("li.search-result"); // All articles belong to this class

                for (Element item : items) {
                    Map<String, String> keyValue = new LinkedHashMap<String, String>();

                    keyValue.put("image", item.select("img").attr("src"));
                    keyValue.put("title", item.select("h2").select("a").text());
                    keyValue.put("content", item.select("div.article-summary").first().text());

                    // Get date from each article separately
                    org.jsoup.nodes.Document articleDoc = RedirectionHandler(
                            officialUrl + item.select("a").attr("href"));

                    keyValue.put("date", articleDoc.select("span.timedate").text());
                    keyValue.put("url", officialUrl + item.select("a").attr("href"));

                    results.add(keyValue);
                }
            } catch (DOMException e) {
                e.printStackTrace();
            }

            return ok(Json.toJson(results));
        }
    });
}

From source file:controllers.TREEProxy.java

public static F.Promise<Result> index(String query) {

    if (StringUtils.isEmpty(query)) {

        F.Promise.promise(new F.Function0<Object>() {
            @Override//ww w .  j  av  a 2 s  .c om
            public Object apply() throws Throwable {
                return ok(Json.toJson("Query parameter (q) not provided "));
            }

        });
    }

    String basicUrl = "https://www.googleapis.com/customsearch/v1element";

    // Additional query parameters
    String key = "AIzaSyCVAXiUzRYsML1Pv6RwSG1gunmMikTzQqY";
    String rsz = "filtered_cse";
    final int num = 10;
    String hl = "el";
    String cx = "017401606067716418337:btpggki1yw8";

    F.Promise<WSResponse> wsResponsePromise = WS.url(basicUrl).setQueryParameter("key", key)
            .setQueryParameter("rsz", rsz).setQueryParameter("num", Integer.toString(num))
            .setQueryParameter("hl", hl).setQueryParameter("cx", cx).setQueryParameter("q", query).get();

    return wsResponsePromise.map(new F.Function<WSResponse, Result>() {
        @Override
        public Result apply(WSResponse wsResponse) throws Throwable {

            String body = wsResponse.getBody();
            List<Map<String, String>> results = new ArrayList<Map<String, String>>();

            try {

                JSONObject initialBody = new JSONObject(body);
                JSONArray resultArray = (JSONArray) initialBody.get("results");

                for (int i = 0; i < resultArray.length(); i++) {

                    Map<String, String> keyValue = new LinkedHashMap<String, String>();

                    JSONObject innerObj = new JSONObject(resultArray.get(i).toString());
                    JSONObject metaTags = (JSONObject) innerObj.get("richSnippet");
                    JSONObject ogTags = (JSONObject) metaTags.get("metatags");

                    keyValue.put("image", ogTags.get("ogImage").toString());
                    keyValue.put("title", ogTags.get("ogTitle").toString());
                    keyValue.put("content", ogTags.get("ogDescription").toString());
                    keyValue.put("date", innerObj.get("contentNoFormatting").toString().substring(0,
                            innerObj.get("contentNoFormatting").toString().indexOf("..")));
                    keyValue.put("url", ogTags.get("ogUrl").toString());

                    results.add(keyValue);
                }
            } catch (DOMException e) {
                e.printStackTrace();
            }

            return ok(Json.toJson(results));
        }
    });
}

From source file:controllers.WDCDProxy.java

public static F.Promise<Result> index(String query) {

    if (StringUtils.isEmpty(query)) {

        F.Promise.promise(new F.Function0<Object>() {
            @Override/*from   w w  w. j av  a  2 s  .  c  o  m*/
            public Object apply() throws Throwable {
                return ok(Json.toJson("Query parameter (q) not provided "));
            }

        });
    }

    F.Promise<WSResponse> wsResponsePromise = WS.url("http://www.whatdesigncando.com/")
            .setQueryParameter("s", query).get();

    return wsResponsePromise.map(new F.Function<WSResponse, Result>() {
        @Override
        public Result apply(WSResponse wsResponse) throws Throwable {

            String body = wsResponse.getBody();
            List<Map<String, String>> results = new ArrayList<Map<String, String>>();

            try {
                // Insert into map
                org.jsoup.nodes.Document doc = Jsoup.parse(body);
                Elements items = doc.select("div.item");

                // Iterate through results
                for (Element item : items) {
                    Map<String, String> keyValue = new LinkedHashMap<String, String>();

                    String imageUrl = item.select("a").attr("style");

                    keyValue.put("image", imageUrl.substring(imageUrl.indexOf("'") + 1,
                            imageUrl.indexOf("'", imageUrl.indexOf("'") + 1)));
                    keyValue.put("title", item.select("h3").text());

                    // Get date and the first sentence as "content" from each article separately (or the "sub-title" tag)
                    org.jsoup.nodes.Document articleDoc = Jsoup.connect(item.select("a").attr("href")).get();

                    String datePublished = articleDoc.select("div#maincontent p.metainfo").text().substring(0,
                            articleDoc.select("div#maincontent p.metainfo").text().indexOf("Published"));
                    String firstSentence;

                    if (articleDoc.select("div#maincontent p.sub-title").text().length() == 0) {
                        firstSentence = articleDoc.select("div#maincontent p:not(.metainfo)").text().substring(
                                0,
                                articleDoc.select("div#maincontent p:not(.metainfo)").text().indexOf(".") + 1);
                        firstSentence = firstSentence + ".";
                    } else {
                        firstSentence = articleDoc.select("div#maincontent p.sub-title").text();
                        firstSentence = firstSentence + "..";
                    }

                    keyValue.put("content", firstSentence);
                    keyValue.put("date", datePublished);
                    keyValue.put("url", item.select("a").attr("href"));

                    results.add(keyValue);
                }

            } catch (DOMException e) {
                e.printStackTrace();
            }

            return ok(Json.toJson(results));
        }
    });
}

From source file:controllers.FASTCOProxy.java

public static F.Promise<Result> index(String query) {

    if (StringUtils.isEmpty(query)) {

        F.Promise.promise(new F.Function0<Object>() {
            @Override/*from www  .  jav  a  2s  .  c  om*/
            public Object apply() throws Throwable {
                return ok(Json.toJson("Query parameter (q) not provided "));
            }

        });
    }

    String basicUrl = "http://www.fastcodesign.com/api/v1/search";

    // Additional query parameters
    String paged = "0";
    int limit = 10;

    F.Promise<WSResponse> wsResponsePromise = WS.url(basicUrl).setQueryParameter("q", query)
            .setQueryParameter("paged", paged).setQueryParameter("limit", Integer.toString(limit)).get();

    return wsResponsePromise.map(new F.Function<WSResponse, Result>() {
        @Override
        public Result apply(WSResponse wsResponse) throws Throwable {

            String body = wsResponse.getBody();
            List<Map<String, String>> results = new ArrayList<Map<String, String>>();

            try {

                JSONObject initialBody = new JSONObject(body);
                JSONArray resultArray = (JSONArray) initialBody.get("items");

                for (int i = 0; i < resultArray.length(); i++) {

                    Map<String, String> keyValue = new LinkedHashMap<String, String>();

                    JSONObject element = (JSONObject) resultArray.get(i);

                    // Get title
                    keyValue.put("title", element.get("title").toString());

                    // Get content
                    keyValue.put("content", element.get("deck").toString());

                    // Get date
                    element = (JSONObject) resultArray.get(i);
                    element = (JSONObject) element.get("date");
                    element = (JSONObject) element.get("updated");

                    keyValue.put("date", element.get("long").toString());

                    // Get url
                    element = (JSONObject) resultArray.get(i);

                    keyValue.put("url", "www." + element.get("url").toString().substring(2));

                    results.add(keyValue);
                }
            } catch (DOMException e) {
                e.printStackTrace();
            }

            return ok(Json.toJson(results));
        }
    });
}

From source file:controllers.CNNProxy.java

public static F.Promise<Result> index(String query) {

    if (StringUtils.isEmpty(query)) {

        F.Promise.promise(new F.Function0<Object>() {
            @Override//from ww  w . ja  va2  s  . c  o m
            public Object apply() throws Throwable {
                return ok(Json.toJson("Query parameter  (q) not provided "));
            }

        });
    }

    String feedUrl = "http://searchapp.cnn.com/search/query.jsp";

    //query = query  + "&type=all";
    String page = "1";
    String npp = "10";
    String start = "1";
    String type = "all";
    String bucket = "true";
    String sort = "relevance";
    String csiID = "csi1";

    F.Promise<WSResponse> wsResponsePromise = WS.url(feedUrl).setQueryParameter("page", page)
            .setQueryParameter("npp", npp).setQueryParameter("start", start).setQueryParameter("text", query)
            .setQueryParameter("type", type).setQueryParameter("bucket", bucket).setQueryParameter("sort", sort)
            .setQueryParameter("csiID", csiID).get();

    return wsResponsePromise.map(new F.Function<WSResponse, Result>() {
        @Override
        public Result apply(WSResponse wsResponse) throws Throwable {

            String body = wsResponse.getBody();

            List<Map<String, String>> ret = new ArrayList<Map<String, String>>();

            try {
                // Reach json code into html response from ajax call
                org.jsoup.nodes.Document doc = Jsoup.parse(body);
                Element resultElement = doc.select("textarea#jsCode").first();
                String resultString = resultElement.text();

                // Parse the json code
                JSONObject obj = new JSONObject(resultString);
                JSONArray array = new JSONArray(obj.get("results").toString());
                JSONArray internalArray = new JSONArray(array.get(0).toString());

                // Insert each result's elements into map with corresponding key
                for (int i = 0; i < internalArray.length(); i++) {
                    JSONObject elementObj = new JSONObject(internalArray.get(i).toString());

                    String image = elementObj.get("thumbnail").toString();
                    String title = elementObj.get("title").toString();
                    String content = elementObj.get("description").toString();
                    String date = elementObj.get("mediaDateUts").toString();
                    String url = elementObj.get("url").toString();

                    Map<String, String> keyValue = new LinkedHashMap<String, String>();

                    keyValue.put("image", image);
                    keyValue.put("title", title);
                    keyValue.put("content", content);
                    keyValue.put("date", date);
                    keyValue.put("url", url);

                    ret.add(keyValue);
                }
            } catch (DOMException e) {
                e.printStackTrace();
            }

            return ok(Json.toJson(ret));

        }
    });
}