Example usage for org.apache.commons.text WordUtils wrap

List of usage examples for org.apache.commons.text WordUtils wrap

Introduction

In this page you can find the example usage for org.apache.commons.text WordUtils wrap.

Prototype

public static String wrap(final String str, final int wrapLength) 

Source Link

Document

Wraps a single line of text, identifying words by ' '.

New lines will be separated by the system property line separator.

Usage

From source file:com.commander4j.sys.JHost.java

public synchronized boolean connect(String sessionID, String host, String sqlPath, String viewPath) {
    Connection tempConn;//  w ww  .j  a  va2 s.  c  o  m
    boolean result = false;

    if (getSqlstatements().IsInitialised() == false) {

        getSqlstatements().setXMLFilename(sqlPath);
        getSqlstatements().setjdbcDriver(getDatabaseParameters().getjdbcDriver());
        getSqlstatements().loadSQLStatements(host);

        getViewstatements().setXMLFilename(viewPath);
        getViewstatements().setjdbcDriver(getDatabaseParameters().getjdbcDriver());
        getViewstatements().loadSQLStatements(host);

        getSqlstatements().setSubstitutions(getViewstatements().getSQLStatements());
        getSqlstatements().setInitialised();
    }

    if (connections.containsKey(sessionID) == false) {
        try {
            Class.forName(getDatabaseParameters().getjdbcDriver()).newInstance();
            try {
                logger.debug(getDatabaseParameters().getjdbcConnectString());
                DriverManager.setLoginTimeout(5);
                tempConn = DriverManager.getConnection(getDatabaseParameters().getjdbcConnectString(),
                        getDatabaseParameters().getjdbcUsername(), getDatabaseParameters().getjdbcPassword());
                tempConn.setAutoCommit(false);
                tempConn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
                ++instanceCount;
                addConnection(sessionID, tempConn);
                result = true;
                setConnected(sessionID, true);
                logger.debug("Opened connection for session ID : " + sessionID);
            } catch (Exception ex) {
                String err = "";
                try {
                    err = ex.getMessage().substring(0, ex.getMessage().indexOf("\n"));
                } catch (Exception ex2) {
                    err = ex.getMessage();
                }

                logger.fatal(ex);
                if (Common.sd.getData(sessionID, "silentExceptions").equals("Yes") == false) {
                    JUtility.errorBeep();
                    JSplashScreenUtils.hide();
                    JOptionPane.showMessageDialog(null, WordUtils.wrap(err, 100),
                            "Database Connection Error (" + getSiteDescription() + ")",
                            JOptionPane.ERROR_MESSAGE);
                }
                result = false;
            }
        } catch (Exception ex) {
            logger.fatal(ex);
            if (Common.sd.getData(sessionID, "silentExceptions").equals("Yes") == false) {
                JUtility.errorBeep();
                JOptionPane.showMessageDialog(null, "Invalid jdbc driver [" + ex.getMessage() + "]",
                        "Login Error (" + getSiteDescription() + ")", JOptionPane.ERROR_MESSAGE);
            }
            result = false;
        }
    }

    return result;
}