Example usage for org.apache.commons.logging LogFactory getFactory

List of usage examples for org.apache.commons.logging LogFactory getFactory

Introduction

In this page you can find the example usage for org.apache.commons.logging LogFactory getFactory.

Prototype

@Deprecated
public static LogFactory getFactory() 

Source Link

Document

This method only exists for compatibility with unusual Commons Logging API usage like e.g.

Usage

From source file:it.drwolf.ridire.utility.RIDIRECleaner.java

private boolean getTextWithReadability() {
    LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log",
            "org.apache.commons.logging.impl.NoOpLog");
    boolean textExtracted = false;
    WebClient webClient = new WebClient();
    webClient = new WebClient(BrowserVersion.FIREFOX_3);
    webClient.setThrowExceptionOnFailingStatusCode(false);
    webClient.setThrowExceptionOnScriptError(false);
    try {//w  ww .  ja  va  2 s. c  om
        Page p = webClient
                .getPage(
                        "https://readability.com/api/content/v1/parser?token=" + this.readabilityKey + "&url="
                                + URLEncoder.encode(this.host + System.getProperty("file.separator")
                                        + "?filename=" + this.fileName + "&encoding=" + this.encoding,
                                        "UTF-8"));
        if (p != null) {
            String responseBody = p.getWebResponse().getContentAsString();
            Map<String, String> map = new Gson().fromJson(responseBody, new TypeToken<Map<String, String>>() {
            }.getType());
            String text = map.get("content").replaceAll("\\<.*?\\>", " ").replaceAll("\\s{2,}", " ");
            if (text != null && text.trim().length() > 50) {
                System.out.println(StringEscapeUtils.unescapeHtml(text));
                textExtracted = true;
                System.err.println(RIDIRECleaner.READABILITY);
            }
        }
    } catch (FailingHttpStatusCodeException e) {
        // TODO Auto-generated catch block
        // e.printStackTrace();
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        // e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        // e.printStackTrace();
    } catch (Throwable t) {
    } finally {
        webClient.closeAllWindows();
    }
    return textExtracted;
}

From source file:io.github.lal872k.monotifier.MyBackPack.java

public static boolean hasValidCredentials(User user, Engine engine) throws IOException {
    System.out.println("Checking validity of " + user.getName() + "'s credentials for MyBackPack...");

    final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_45);

    LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log",
            "org.apache.commons.logging.impl.NoOpLog");

    java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF);
    java.util.logging.Logger.getLogger("org.apache.commons.httpclient").setLevel(Level.OFF);

    //webClient.setCssEnabled(false);
    // http://stackoverflow.com/questions/3600557/turning-htmlunit-warnings-off

    webClient.setIncorrectnessListener(new IncorrectnessListener() {

        @Override//from   w ww .j a v a  2  s.  co m
        public void notify(String arg0, Object arg1) {
            // TODO Auto-generated method stub

        }
    });
    webClient.setCssErrorHandler(new ErrorHandler() {

        @Override
        public void warning(CSSParseException exception) throws CSSException {
            // TODO Auto-generated method stub

        }

        @Override
        public void fatalError(CSSParseException exception) throws CSSException {
            // TODO Auto-generated method stub

        }

        @Override
        public void error(CSSParseException exception) throws CSSException {
            // TODO Auto-generated method stub

        }
    });
    webClient.setJavaScriptErrorListener(new JavaScriptErrorListener() {

        @Override
        public void scriptException(InteractivePage ip, ScriptException se) {
            //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public void timeoutError(InteractivePage ip, long l, long l1) {
            //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public void malformedScriptURL(InteractivePage ip, String string, MalformedURLException murle) {
            //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public void loadScriptError(InteractivePage ip, URL url, Exception excptn) {
            //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    });
    webClient.setHTMLParserListener(new HTMLParserListener() {

        @Override
        public void error(String string, URL url, String string1, int i, int i1, String string2) {
            //
        }

        @Override
        public void warning(String string, URL url, String string1, int i, int i1, String string2) {
            //
        }
    });

    //webClient.setThrowExceptionOnFailingStatusCode(false);
    //webClient.setThrowExceptionOnScriptError(false);

    //http://stackoverflow.com/questions/19551043/process-ajax-request-in-htmlunit/26268815#26268815
    webClient.getOptions().setJavaScriptEnabled(true);
    webClient.getOptions().setThrowExceptionOnScriptError(false);
    webClient.getOptions().setCssEnabled(false);
    webClient.setAjaxController(new NicelyResynchronizingAjaxController());

    // get the page
    HtmlPage page = webClient.getPage(
            "https://peddie.seniormbp.com/SeniorApps/studentParent/attendSummary.faces?selectedMenuId=true");

    // get login form
    final HtmlForm login_form = page.getFormByName("form");

    final HtmlTextInput username = login_form.getInputByName("form:userId");
    final HtmlPasswordInput password = login_form.getInputByName("form:userPassword");

    final HtmlButtonInput login_submit = login_form.getInputByName("form:signIn");

    username.setValueAttribute(user.getMyBackPackUsername());
    password.setValueAttribute(user.getDecryptedMyBackPackPassword());

    URL oldURL = page.getUrl();

    // Now submit the form by clicking the button and get back the new page.
    page = login_submit.click();

    engine.getHistory()
            .addAction(new Action("Accessed MyBackPack",
                    "Accessed the MyBackPack of " + user.getName() + " (" + user.getID() + ")("
                            + user.getEmail() + ") to check the validity of the account credentials."));

    if (oldURL.equals(page.getUrl())) {
        return false;
    }

    return true;
}

From source file:it.drwolf.ridire.utility.RIDIRECleaner.java

private boolean getTextWithReadability_old() throws IOException, MalformedURLException {
    LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log",
            "org.apache.commons.logging.impl.NoOpLog");
    WebClient webClient = new WebClient();
    webClient = new WebClient(BrowserVersion.FIREFOX_3);
    webClient.setCssEnabled(true);//from   w  ww.  j av  a2  s.  c  o m
    webClient.setJavaScriptEnabled(true);
    // vedi FAQ: http://htmlunit.sourceforge.net/faq.html#AJAXDoesNotWork
    webClient.setAjaxController(new NicelyResynchronizingAjaxController());
    webClient.waitForBackgroundJavaScript(5000);
    webClient.waitForBackgroundJavaScriptStartingBefore(5000);
    // i seguenti 4 set servono per limitare i log
    webClient.setHTMLParserListener(null);
    webClient.setIncorrectnessListener(new NoOpIncorrectnessListener());
    webClient.setCssErrorHandler(new NoOpErrorHandler());
    webClient.setThrowExceptionOnFailingStatusCode(false);
    webClient.setRefreshHandler(new ThreadedRefreshHandler());
    webClient.setThrowExceptionOnScriptError(false);
    ProxyConfig proxyConfig = new ProxyConfig("", 8056);
    proxyConfig.addHostsToProxyBypass("localhost.*");
    webClient.setProxyConfig(proxyConfig);
    HtmlPage htmlPage = webClient.getPage(this.host + System.getProperty("file.separator") + "?filename="
            + this.fileName + "&encoding=" + this.encoding);
    // System.out.println(htmlPage.asXml());
    // List<HtmlElement> scripts = htmlPage.getElementsByTagName("script");
    // for (HtmlElement script : scripts) {
    // script.setAttribute("src", "");
    // }
    String jsSrc = FileUtils.readFileToString(new File(this.bookmark));
    jsSrc = jsSrc.replaceAll("@@@HOST@@@", this.host);
    htmlPage.executeJavaScript(jsSrc);
    // System.out.println(htmlPage.asXml());
    List elements = htmlPage.getByXPath("//div[@id='readability-content']/div");
    HtmlElement element = null;
    if (elements != null && elements.size() > 0) {
        element = (HtmlElement) elements.get(0);
    }
    String ret = new String();
    boolean textExtracted = false;
    if (element != null) {
        ret = element.asText();
        if (ret != null && ret.trim().length() > 50) {
            textExtracted = true;
            System.out.println(ret);
            System.err.println(RIDIRECleaner.READABILITY);
        }
    }
    webClient.closeAllWindows();
    return textExtracted;
}

From source file:io.hummer.util.ws.WebServiceClient.java

private static StringBuilder getPageUsingHtmlUnit(String urlString, Map<String, String> httpHeaders,
        long timeoutMS, String proxyHost) throws Exception {
    LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log",
            "org.apache.commons.logging.impl.NoOpLog");
    System.getProperties().put("org.apache.commons.logging.simplelog.defaultlog", "WARN");
    // try to make request using HtmlUnit..
    System.out.println("Making request to " + urlString + " using HtmlUnit WebClient..");
    WebClient client = getWebClient(timeoutMS);
    if (proxyHost != null) {
        client.getProxyConfig().setProxyHost(proxyHost);
    }/*ww  w .  j a v  a2  s  . com*/
    if (httpHeaders != null) {
        for (String name : httpHeaders.keySet()) {
            client.addRequestHeader(name, httpHeaders.get(name));
        }
    }
    client.setPrintContentOnFailingStatusCode(false);
    Page p = client.getPage(urlString);
    String pageContent = null;
    if (p instanceof HtmlPage) {
        pageContent = ((HtmlPage) p).asXml();
    } else if (p instanceof TextPage) {
        pageContent = ((TextPage) p).getContent();
    } else {
        throw new RuntimeException("Unexpected page result type: " + p);
    }
    StringBuilder b = new StringBuilder(pageContent);
    try {
        p.cleanUp();
        client.closeAllWindows();
    } catch (Exception e2) {
        logger.warn(e2);
    }
    return b;
}

From source file:io.hummer.util.ws.WebServiceClient.java

public static WebClient getWebClient(long timeoutMS) {
    LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log",
            "org.apache.commons.logging.impl.NoOpLog");
    System.getProperties().put("org.apache.commons.logging.simplelog.defaultlog", "WARN");
    WebClient client = new WebClient(BrowserVersion.FIREFOX_3_6);
    client.setThrowExceptionOnScriptError(false);
    client.setTimeout((int) timeoutMS);
    client.setThrowExceptionOnFailingStatusCode(false);
    client.setIncorrectnessListener(new IncorrectnessListener() {
        public void notify(String arg0, Object arg1) {
        }// w w  w .  j a va 2  s. c  o m
    });
    client.setCssErrorHandler(new ErrorHandler() {
        public void warning(CSSParseException arg0) throws CSSException {
        }

        public void fatalError(CSSParseException arg0) throws CSSException {
        }

        public void error(CSSParseException arg0) throws CSSException {
        }
    });
    client.setAlertHandler(new AlertHandler() {
        public void handleAlert(Page arg0, String arg1) {
        }
    });
    client.setJavaScriptErrorListener(new JavaScriptErrorListener() {
        public void timeoutError(HtmlPage arg0, long arg1, long arg2) {
        }

        public void scriptException(HtmlPage arg0, ScriptException arg1) {
        }

        public void malformedScriptURL(HtmlPage arg0, String arg1, MalformedURLException arg2) {
        }

        public void loadScriptError(HtmlPage arg0, URL arg1, Exception arg2) {
        }
    });
    return client;
}

From source file:facturas.PDF.CommandLineOptions.java

private void setLogLevel(String level) {
    // Set the level for future loggers.
    LogFactory.getFactory().setAttribute("level", level);
    if (log instanceof CommandLineLogger) {
        // Set the level for the logger created already.
        ((CommandLineLogger) log).setLogLevel(level);
    }//from ww w  .  jav  a 2  s  .c  om
}

From source file:org.acmsl.commons.logging.UniqueLogFactory.java

/**
 * Convenience method to derive a name from the specified class and
 * call <code>getInstance(String)</code> with it.
 * @param clazz Class for which a suitable Log name will be derived
 * @param log the cached log instance.//  w w w .  j ava  2 s  .c o m
 * @throws LogConfigurationException if a suitable <code>Log</code>
 * instance cannot be returned
 * @param <T> the type.
 * @return the instance.
 */
@Nullable
protected <T> Log getInstance(@NotNull final Class<T> clazz, @Nullable final Log log)
        throws LogConfigurationException {
    @Nullable
    final Log result;

    @Nullable
    final LogFactory t_LogFactory = LogFactory.getFactory();

    if (t_LogFactory != null) {
        result = t_LogFactory.getInstance(clazz);
    } else {
        result = log;
    }

    return result;
}

From source file:org.acmsl.commons.logging.UniqueLogFactory.java

/**
 * <p>Construct (if necessary) and return a <code>Log</code> instance,
 * using the factory's current set of configuration attributes.</p>
 * <p><strong>NOTE</strong> - Depending upon the implementation of
 * the <code>LogFactory</code> you are using, the <code>Log</code>
 * instance you are returned may or may not be local to the current
 * application, and may or may not be returned again on a subsequent
 * call with the same name argument.</p>
 * @param name Logical name of the <code>Log</code> instance to be
 * returned (the meaning of this name is only known to the underlying
 * logging implementation that is being wrapped)
 * @param log the possibly cached log instance.
 * @throws LogConfigurationException if a suitable <code>Log</code>
 * instance cannot be returned/* w  w  w .j a va2 s  .com*/
 * @return the log instance.
 */
@Nullable
public Log getInstance(@NotNull final String name, @Nullable final Log log) throws LogConfigurationException {
    @Nullable
    final Log result;

    if (log == null) {
        @Nullable
        final LogFactory t_LogFactory = LogFactory.getFactory();

        if (t_LogFactory != null) {
            result = t_LogFactory.getInstance(name);
        } else {
            result = null;
        }
    } else {
        result = log;
    }

    return result;
}

From source file:org.acmsl.queryj.tools.logging.QueryJLogFactory.java

/**
 * Convenience method to derive a name from the specified class and
 * call <code>getInstance(String)</code> with it.
 * @param clazz Class for which a suitable Log name will be derived
 * @param log the cached log instance.//from  w w  w  .  java  2s  .c  o  m
 * @return the {@link Log} instance.
 */
@Nullable
protected Log getInstance(@NotNull final Class<?> clazz, @Nullable final Log log)
        throws LogConfigurationException {
    @Nullable
    Log result = log;

    @Nullable
    final LogFactory t_LogFactory = LogFactory.getFactory();

    if (t_LogFactory != null) {
        result = t_LogFactory.getInstance(clazz);
    }

    return result;
}

From source file:org.acmsl.queryj.tools.logging.QueryJLogFactory.java

/**
 * <p>Construct (if necessary) and return a <code>Log</code> instance,
 * using the factory's current set of configuration attributes.</p>
 * <p><strong>NOTE</strong> - Depending upon the implementation of
 * the <code>LogFactory</code> you are using, the <code>Log</code>
 * instance you are returned may or may not be local to the current
 * application, and may or may not be returned again on a subsequent
 * call with the same name argument.</p>
 * @param name Logical name of the <code>Log</code> instance to be
 * returned (the meaning of this name is only known to the underlying
 * logging implementation that is being wrapped)
 * @param log the possibly cached log instance.
 * @return the {@link Log} instance.// www  .  j  av a 2 s. c  o m
 * @throws LogConfigurationException in case of misconfiguration.
 */
@Nullable
public Log getInstance(@NotNull final String name, @Nullable final Log log) throws LogConfigurationException {
    @Nullable
    Log result = log;

    if (result == null) {
        @Nullable
        final LogFactory t_LogFactory = LogFactory.getFactory();

        if (t_LogFactory != null) {
            result = t_LogFactory.getInstance(name);
        }
    }

    return result;
}