Example usage for org.apache.commons.lang3 StringUtils trimToEmpty

List of usage examples for org.apache.commons.lang3 StringUtils trimToEmpty

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils trimToEmpty.

Prototype

public static String trimToEmpty(final String str) 

Source Link

Document

Removes control characters (char <= 32) from both ends of this String returning an empty String ("") if the String is empty ("") after the trim or if it is null .

Usage

From source file:de.gbv.ole.Marc21ToOleBulk.java

/**
 * Return the data of the control field with number tag with
 * whitespace trimmed./*from w w  w . j  a  v a  2s . c o m*/
 * @param record    Where to search for the control field.
 * @param tag       The number of the control field.
 * @return  The data of the control field, or an empty String if
 *          the field does not exist or contains only whitespace
 */
final static String getOptionalControlField(Record record, String tag) {
    for (ControlField controlField : record.getControlFields()) {
        if (!tag.equals(controlField.getTag())) {
            continue;
        }

        return StringUtils.trimToEmpty(controlField.getData());
    }

    return "";
}

From source file:mfi.filejuggler.responsibles.BasicApplication.java

@Responsible(conditions = { Condition.SYS_SYSTEM_INFO, Condition.SYS_EXECUTE_JOB })
public void fjSystemInfo(StringBuilder sb, Map<String, String> parameters, Model model) throws Exception {

    if (model.lookupConversation().getCondition().equals(Condition.SYS_EXECUTE_JOB)) {
        String executeJob = StringUtils.trimToEmpty(parameters.get("execute_job"));
        for (String schedulerName : CronSchedulers.getInstance().getSchedulersIDs().keySet()) {
            if (StringUtils.equalsIgnoreCase(schedulerName, executeJob)) {
                Runnable r = CronSchedulers.getInstance().getSchedulersInstances().get(schedulerName);
                r.run();/* w  w w  .  ja  v a  2s.  c  om*/
                model.lookupConversation().getMeldungen().add(r.getClass().getName() + " wurde gestartet");
                break;
            }
        }
    }

    String warfilename = KVMemoryMap.getInstance().readValueFromKey("application.warfile");
    String builddate = KVMemoryMap.getInstance().readValueFromKey("application.builddate");
    if (warfilename == null) {
        warfilename = "Development Version";
    }
    if (builddate == null) {
        builddate = "n/v";
    }

    ButtonBar buttonBar = new ButtonBar();
    buttonBar.getButtons().add(new Button("Reload", Condition.SYS_SYSTEM_INFO));
    sb.append(HTMLUtils.buildMenuNar(model, "Systeminformationen", Condition.FS_NAVIGATE, buttonBar, false));

    String attributeLeftCol = model.isPhone() ? HTMLUtils.buildAttribute("width", "40%") : null;

    HTMLTable table = new HTMLTable();

    table.addTD("Anwendungsvariablen:", 2, HTMLTable.TABLE_HEADER);
    table.addNewRow();
    table.addTD("Build:", 1, null);
    table.addTD(builddate, 1, null);
    table.addNewRow();
    table.addTD("Systemzeit:", 1, null);
    table.addTD(Hilfsklasse.zeitstempelAlsString(), 1, null);
    table.addNewRow();
    table.addTD("Zwischenablage:", 1, attributeLeftCol);
    String clip;
    if (model.getZwischenablage() != null) {
        clip = HTMLUtils.spacifyFilePath(model.getZwischenablage(), model);
    } else {
        clip = "[ leer ]";
    }
    table.addTD(clip, 1, null);
    table.addNewRow();
    table.addTD("Session:", 1, null);
    table.addTD(StringHelper.langenStringFuerAnzeigeAufbereiten(model.getSessionID()), 1, null);
    table.addNewRow();
    table.addTD("Login:", 1, null);
    table.addTD(StringHelper.langenStringFuerAnzeigeAufbereiten(model.getLoginCookieID()), 1, null);
    table.addNewRow();
    if (model.lookupConversation().getCookiesReadFromRequest() != null && model.isDevelopmentMode()) {
        for (Cookie cookieReadFromRequest : model.lookupConversation().getCookiesReadFromRequest()) {
            String cookieName = cookieReadFromRequest.getName();
            String cookieValue = cookieReadFromRequest.getValue();
            table.addTD("Cookie (Request):", 1, null);
            table.addTD(cookieName, 1, null);
            table.addNewRow();
            table.addTD("", 1, null);
            table.addTD(StringHelper.langenStringFuerAnzeigeAufbereiten(cookieValue), 1, null);
            table.addNewRow();
        }
    }
    table.addTD("Conversation ID:", 1, null);
    table.addTD(model.lookupConversation().getConversationID().toString(), 1, null);
    table.addNewRow();
    table.addTD("Remote IP:", 1, null);
    table.addTD(parameters.get(ServletHelper.SERVLET_REMOTE_IP), 1, null);
    table.addNewRow();
    table.addTD("LocalNetwork:", 1, null);
    table.addTD(ServletHelper.isLocalNetworkClient(parameters) + "", 1, null);
    table.addNewRow();
    table.addTD("Touch / Phone / Tablet:", 1, null);
    table.addTD(Boolean.toString(model.isClientTouchDevice()) + " / " + Boolean.toString(model.isPhone())
            + " / " + Boolean.toString(model.isTablet()), 1, null);
    table.addNewRow();
    table.addTD("Ist FullScreen:", 1, null);
    table.addTD(Boolean.toString(model.isIstWebApp()), 1, null);
    table.addNewRow();
    table.addTD("Ajax / current request:", 1, null);
    table.addTD(Boolean.toString(ServletHelper.lookupUseAjax()) + " / "
            + ServletHelper.lookupIsCurrentRequestTypeAjax(parameters), 1, null);
    table.addNewRow();
    table.addTD("Gzip Response:", 1, null);
    table.addTD(Boolean.toString(ServletHelper.lookupUseGzip(parameters)), 1, null);
    table.addNewRow();

    if (model.isPhone()) {
        sb.append(table.buildTable(model));
        table = new HTMLTable();
    }

    table.addTD("Java", 2, HTMLTable.TABLE_HEADER);
    table.addNewRow();
    table.addTD("total / max memory:", 1, attributeLeftCol);
    table.addTD(DateiZugriff.speicherGroesseFormatieren(Runtime.getRuntime().totalMemory()) + " / "
            + DateiZugriff.speicherGroesseFormatieren(Runtime.getRuntime().maxMemory()), 1, null);
    table.addNewRow();
    table.addTD("freeMemory:", 1, null);
    table.addTD(DateiZugriff.speicherGroesseFormatieren(Runtime.getRuntime().freeMemory()), 1, null);
    table.addNewRow();
    table.addTD("catalina.home:", 1, null);
    table.addTD(
            HTMLUtils.spacifyFilePath(
                    System.getProperties().getProperty(ServletHelper.SYSTEM_PROPERTY_CATALINA_HOME), model),
            1, null);
    table.addNewRow();
    table.addTD("catalina.base:", 1, null);
    table.addTD(
            HTMLUtils.spacifyFilePath(
                    System.getProperties().getProperty(ServletHelper.SYSTEM_PROPERTY_CATALINA_BASE), model),
            1, null);
    table.addNewRow();
    table.addTD("WarFile:", 1, HTMLTable.NO_BORDER);
    table.addTD(HTMLUtils.spacifyFilePath(warfilename, model), 1, HTMLTable.NO_BORDER);
    table.addNewRow();

    if (model.isPhone()) {
        sb.append(table.buildTable(model));
        table = new HTMLTable();
    }

    table.addTD("Hardware / Software", 2, HTMLTable.TABLE_HEADER);
    table.addNewRow();
    table.addTD("CPU Cores:", 1, attributeLeftCol);
    table.addTD(Runtime.getRuntime().availableProcessors() + "", 1, null);
    table.addNewRow();
    table.addTD("Architecture:", 1, null);
    table.addTD(System.getProperty("sun.arch.data.model", "") + " bit", 1, null);
    table.addNewRow();
    table.addTD("Java Version:", 1, null);
    table.addTD(System.getProperty("java.version", ""), 1, null);
    table.addNewRow();
    table.addTD("Java VM:", 1, null);
    table.addTD(System.getProperty("java.vm.name", ""), 1, null);
    table.addNewRow();
    table.addTD("Server:", 1, null);
    table.addTD(KVMemoryMap.getInstance().readValueFromKey("application.server"), 1, null);
    table.addNewRow();

    if (model.isPhone()) {
        sb.append(table.buildTable(model));
        table = new HTMLTable();
    }

    table.addTD("Cron Jobs", 2, HTMLTable.TABLE_HEADER);
    table.addNewRow();

    int a = 0;
    List<String> jobs = new LinkedList<String>();
    jobs.add("");
    for (String schedulerName : CronSchedulers.getInstance().getSchedulersIDs().keySet()) {
        jobs.add(schedulerName);
        String cssClass = a % 2 != 0 ? attributeLeftCol : HTMLUtils.buildAttribute("class", "alt");
        Scheduler s = CronSchedulers.getInstance().getSchedulers().get(schedulerName);
        table.addTD(schedulerName, 1, cssClass);
        table.addTD(((s != null && s.isStarted()) ? "@ " : "not running")
                + CronSchedulers.getInstance().lookupCronStringOfScheduler(schedulerName), 1, cssClass);
        table.addNewRow();
        table.addTD("", 1, cssClass);
        table.addTD(CronSchedulers.getInstance().getSchedulersInstances().get(schedulerName).status(), 1,
                cssClass);
        table.addNewRow();
        a++;
    }

    if (model.isPhone()) {
        sb.append(table.buildTable(model));
        table = new HTMLTable();
    }

    table.addTD("Manueller Job-Start", 2, HTMLTable.TABLE_HEADER);
    table.addNewRow();
    table.addTDSource(HTMLUtils.buildDropDownListe("execute_job", jobs, null), 2, null);
    table.addNewRow();
    String buttonJobStart = new Button("Job starten", Condition.SYS_EXECUTE_JOB).printForUseInTable();
    table.addTDSource(buttonJobStart, 2, HTMLTable.NO_BORDER);
    table.addNewRow();

    sb.append(table.buildTable(model));
    return;
}

From source file:com.willwinder.universalgcodesender.model.GUIBackend.java

@Override
public void setWorkPositionUsingExpression(final Axis axis, final String expression) throws Exception {
    String expr = StringUtils.trimToEmpty(expression);
    expr = expr.replaceAll("#", String.valueOf(getWorkPosition().get(axis)));

    // If the expression starts with a mathimatical operation add the original position
    if (StringUtils.startsWithAny(expr, "/", "*")) {
        double value = getWorkPosition().get(axis);
        expr = value + " " + expr;
    }/*from www.  ja va2  s . co m*/

    // Start a script engine and evaluate the expression
    ScriptEngineManager mgr = new ScriptEngineManager();
    ScriptEngine engine = mgr.getEngineByName("JavaScript");
    try {
        double position = Double.valueOf(engine.eval(expr).toString());
        setWorkPosition(axis, position);
    } catch (ScriptException e) {
        throw new Exception("Invalid expression", e);
    }
}

From source file:gov.ca.cwds.es.live.RawClient.java

@Override
public int compare(RawClient o1, RawClient o2) {
    return StringUtils.trimToEmpty(o1.getCltId()).compareTo(StringUtils.trimToEmpty(o2.getCltId()));
}

From source file:com.moviejukebox.scanner.artwork.ArtworkScanner.java

/**
 * Scan for artwork named like: {videoFileName}{artworkToken}.{artworkExtensions}
 *
 * @param movie/*w w w  .  j  a v a  2 s.  co  m*/
 * @param artworkFilename
 * @param additionalPath A sub-directory of the movie to scan
 * @return UNKNOWN or Absolute Path
 */
protected String scanVideoArtwork(Movie movie, String artworkFilename, String additionalPath) {
    String parentPath = StringTools.appendToPath(FileTools.getParentFolder(movie.getFile()),
            StringUtils.trimToEmpty(additionalPath));
    return scanDirectoryForArtwork(artworkFilename, parentPath);
}

From source file:com.moviejukebox.plugin.ImdbPlugin.java

private boolean extractWritersFromFullCredits(Movie movie, String fullcreditsXML, boolean overrideNormal,
        boolean overridePeople) {
    // count for already set writers
    int count = 0;
    // flag to indicate if writers must be cleared
    boolean clearWriters = Boolean.TRUE;
    boolean clearPeopleWriters = Boolean.TRUE;
    // flag to indicate if match has been found
    boolean found = Boolean.FALSE;

    for (String writerMatch : new String[] { "Writing credits", "Writer", "Writers" }) {
        if (StringUtils.indexOfIgnoreCase(fullcreditsXML, HTML_GT + writerMatch) >= 0) {
            for (String member : HTMLTools.extractTags(fullcreditsXML, HTML_GT + writerMatch, HTML_TABLE_END,
                    HTML_A_START, HTML_A_END, Boolean.FALSE)) {
                int beginIndex = member.indexOf("href=\"/name/");
                if (beginIndex > -1) {
                    String personID = member.substring(beginIndex + 12, member.indexOf("/", beginIndex + 12));
                    String name = StringUtils
                            .trimToEmpty(member.substring(member.indexOf(HTML_GT, beginIndex) + 1));
                    if (!name.contains("more credit")) {

                        if (overrideNormal) {
                            // clear writers if not already done
                            if (clearWriters) {
                                movie.clearWriters();
                                clearWriters = Boolean.FALSE;
                            }//from   w ww  .ja  v a 2  s .  co m
                            // add writer
                            movie.addWriter(name, IMDB_PLUGIN_ID);
                        }

                        if (overridePeople) {
                            // clear writers if not already done
                            if (clearPeopleWriters) {
                                movie.clearPeopleWriters();
                                clearPeopleWriters = Boolean.FALSE;
                            }
                            // add writer
                            movie.addWriter(IMDB_PLUGIN_ID + ":" + personID, name,
                                    imdbInfo.getImdbSite() + IMDB_NAME + personID + "/", IMDB_PLUGIN_ID);
                        }

                        found = Boolean.TRUE;
                        count++;
                        if (count == writerMax) {
                            break;
                        }
                    }
                }
            }
        }

        if (found) {
            // We found a match, so stop search.
            break;
        }
    }

    return found;
}

From source file:com.hp.hpl.inkml.InkMLDOMParser.java

/**
 * @return/*from   w w w. j  a  v  a  2s.co m*/
 */
private boolean isSchemaValidationEnabled() {
    // check the JVM parameter java -DschemaValidation={"true"|"false"}
    boolean isSchemaValidationEnabled = true;
    final String validationStatus = StringUtils
            .trimToEmpty(System.getProperty("com.hp.hpl.inkml.SchemaValidation"));
    if (StringUtils.isNotEmpty(validationStatus)) {
        if ("true".equalsIgnoreCase(validationStatus)) {
            isSchemaValidationEnabled = true;
        } else {
            isSchemaValidationEnabled = false;
        }
    }
    return isSchemaValidationEnabled;
}

From source file:com.moviejukebox.plugin.ImdbPlugin.java

/**
 * Process a awards in the IMDb web page
 *
 * @param movie/*w  w  w.ja  v a  2s .c o m*/
 * @return
 */
private boolean updateAwards(Movie movie) {
    String imdbId = movie.getId(IMDB_PLUGIN_ID);

    String awardXML = getImdbData(getImdbUrl(imdbId, IMDB_TITLE, SUFFIX_AWARDS));
    if (awardXML.contains("<h1 class=\"header\">Awards</h1>")) {

        List<String> awardHtmlList = HTMLTools.extractTags(awardXML, "<h1 class=\"header\">Awards</h1>",
                "<div class=\"article\"", "<h3>", "</table>", false);

        Collection<AwardEvent> awardList = new ArrayList<>();
        for (String awardBlock : awardHtmlList) {
            String awardEvent = awardBlock.substring(0, awardBlock.indexOf('<')).trim();

            AwardEvent aEvent = new AwardEvent();
            aEvent.setName(awardEvent);

            String tmpString = HTMLTools.extractTag(awardBlock, "<a href=", HTML_A_END).trim();
            tmpString = tmpString.substring(tmpString.indexOf('>') + 1).trim();
            int awardYear = NumberUtils.isNumber(tmpString) ? Integer.parseInt(tmpString) : -1;

            tmpString = StringUtils.trimToEmpty(
                    HTMLTools.extractTag(awardBlock, "<span class=\"award_category\">", "</span>"));
            Award aAward = new Award();
            aAward.setName(tmpString);
            aAward.setYear(awardYear);

            boolean awardOutcomeWon = true;
            for (String outcomeBlock : HTMLTools.extractHtmlTags(awardBlock, "<table class=", null, "<tr>",
                    "</tr>")) {
                String outcome = HTMLTools.extractTag(outcomeBlock, "<b>", "</b>");
                if (StringTools.isValidString(outcome)) {
                    awardOutcomeWon = "won".equalsIgnoreCase(outcome);
                }

                String awardDescription = StringUtils.trimToEmpty(
                        HTMLTools.extractTag(outcomeBlock, "<td class=\"award_description\">", "<br />"));
                // Check to see if there was a missing title and just the name in the result
                if (awardDescription.contains("href=\"/name/")) {
                    awardDescription = StringUtils.trimToEmpty(
                            HTMLTools.extractTag(outcomeBlock, "<span class=\"award_category\">", "</span>"));
                }

                if (awardOutcomeWon) {
                    aAward.addWon(awardDescription);
                } else {
                    aAward.addNomination(awardDescription);
                }
            }

            if (!scrapeWonAwards || (aAward.getWon() > 0)) {
                LOG.debug("{} - Adding award: {}", movie.getBaseName(), aAward.toString());
                aEvent.addAward(aAward);
            }

            if (!aEvent.getAwards().isEmpty()) {
                awardList.add(aEvent);
            }
        }

        if (!awardList.isEmpty()) {
            movie.setAwards(awardList);
        }
    } else {
        LOG.debug("No awards found for {}", movie.getBaseName());
    }
    return Boolean.TRUE;
}

From source file:io.sinistral.proteus.server.tools.swagger.Reader.java

private static Set<Scheme> parseSchemes(String schemes) {
    final Set<Scheme> result = EnumSet.noneOf(Scheme.class);
    for (String item : StringUtils.trimToEmpty(schemes).split(",")) {
        final Scheme scheme = Scheme.forValue(StringUtils.trimToNull(item));
        if (scheme != null) {
            result.add(scheme);/*from  w  ww  .  j ava 2s .co m*/
        }
    }
    return result;
}

From source file:com.moviejukebox.plugin.ImdbPlugin.java

/**
 * Process the new IMDb format web page//w ww .  j a va2s. c om
 *
 * @param person
 * @param xml
 * @return
 */
private boolean updateInfo(Person person, String xml) {
    person.setUrl(ImdbPlugin.this.getImdbUrl(person));

    if (xml.contains("Alternate Names:")) {
        String name = HTMLTools.extractTag(xml, "Alternate Names:</h4>", HTML_DIV_END);
        if (isValidString(name)) {
            for (String item : name.split("<span>\\|</span>")) {
                person.addAka(StringUtils.trimToEmpty(item));
            }
        }
    }

    if (xml.contains("id=\"img_primary\"")) {
        LOG.debug("Looking for image on webpage for {}", person.getName());
        String photoURL = HTMLTools.extractTag(xml, "id=\"img_primary\"", HTML_TD_END);

        if (photoURL.contains("http://ia.media-imdb.com/images")) {
            photoURL = "http://ia.media-imdb.com/images"
                    + HTMLTools.extractTag(photoURL, "src=\"http://ia.media-imdb.com/images", "\"");
            if (isValidString(photoURL)) {
                person.setPhotoURL(photoURL);
                person.setPhotoFilename();
            }
        }
    } else {
        LOG.debug("No image found on webpage for {}", person.getName());
    }

    // get personal information
    String xmlInfo = getImdbData(getImdbUrl(person, SUFFIX_BIO));

    StringBuilder date = new StringBuilder();
    int endIndex;
    int beginIndex = xmlInfo.indexOf(">Date of Birth</td>");

    if (beginIndex > -1) {
        endIndex = xmlInfo.indexOf(">Date of Death</td>");
        beginIndex = xmlInfo.indexOf("birth_monthday=", beginIndex);
        if (beginIndex > -1 && (endIndex == -1 || beginIndex < endIndex)) {
            Matcher m = PATTERN_DOB.matcher(xmlInfo.substring(beginIndex + 15, beginIndex + 20));
            if (m.find()) {
                date.append(m.group(2)).append("-").append(m.group(1));
            }
        }

        beginIndex = xmlInfo.indexOf("birth_year=", beginIndex);
        if (beginIndex > -1 && (endIndex == -1 || beginIndex < endIndex)) {
            if (date.length() > 0) {
                date.append("-");
            }
            date.append(xmlInfo.substring(beginIndex + 11, beginIndex + 15));
        }

        beginIndex = xmlInfo.indexOf("birth_place=", beginIndex);
        String place;
        if (beginIndex > -1) {
            place = HTMLTools.extractTag(xmlInfo, "birth_place=", HTML_A_END);
            int start = place.indexOf('>');
            if (start > -1 && start < place.length()) {
                place = place.substring(start + 1);
            }
            if (isValidString(place)) {
                person.setBirthPlace(place);
            }
        }
    }

    beginIndex = xmlInfo.indexOf(">Date of Death</td>");
    if (beginIndex > -1) {
        endIndex = xmlInfo.indexOf(">Mini Bio (1)</h4>", beginIndex);
        beginIndex = xmlInfo.indexOf("death_monthday=", beginIndex);
        StringBuilder dDate = new StringBuilder();
        if (beginIndex > -1 && (endIndex == -1 || beginIndex < endIndex)) {
            Matcher m = PATTERN_DOB.matcher(xmlInfo.substring(beginIndex + 15, beginIndex + 20));
            if (m.find()) {
                dDate.append(m.group(2));
                dDate.append("-");
                dDate.append(m.group(1));
            }
        }
        beginIndex = xmlInfo.indexOf("death_date=", beginIndex);
        if (beginIndex > -1 && (endIndex == -1 || beginIndex < endIndex)) {
            if (dDate.length() > 0) {
                dDate.append("-");
            }
            dDate.append(xmlInfo.substring(beginIndex + 11, beginIndex + 15));
        }
        if (dDate.length() > 0) {
            date.append("/").append(dDate);
        }
    }

    if (StringUtils.isNotBlank(date)) {
        person.setYear(date.toString());
    }

    beginIndex = xmlInfo.indexOf(">Birth Name</td>");
    if (beginIndex > -1) {
        beginIndex += 20;
        String name = xmlInfo.substring(beginIndex, xmlInfo.indexOf(HTML_TD_END, beginIndex));
        if (isValidString(name)) {
            person.setBirthName(HTMLTools.decodeHtml(name));
        }
    }

    beginIndex = xmlInfo.indexOf(">Nickname</td>");
    if (beginIndex > -1) {
        String name = xmlInfo.substring(beginIndex + 17, xmlInfo.indexOf(HTML_TD_END, beginIndex + 17));
        if (isValidString(name)) {
            person.addAka(name);
        }
    } else {
        beginIndex = xmlInfo.indexOf(">Nicknames</td>");
        if (beginIndex > -1) {
            String name = xmlInfo.substring(beginIndex + 19, xmlInfo.indexOf(HTML_TD_END, beginIndex + 19));
            for (String n : name.split("<br>")) {
                person.addAka(n.trim());
            }
        }
    }

    Matcher m = PATTERN_BIO.matcher(xmlInfo);
    if (m.find()) {
        String bio = HTMLTools.stripTags(m.group(1), true);
        if (isValidString(bio)) {
            bio = trimToLength(bio, preferredBiographyLength);
            person.setBiography(bio);
        }
    }

    // get known movies
    xmlInfo = getImdbData(getImdbUrl(person, SUFFIX_FILMOYEAR));
    if (xmlInfo.contains("<div id=\"tn15content\">")) {
        int count = HTMLTools.extractTags(xmlInfo, "<div id=\"tn15content\">", HTML_DIV_END, "<li>", "</li>")
                .size();
        person.setKnownMovies(count);
    }

    // get filmography
    processFilmography(person, xml);

    int version = person.getVersion();
    person.setVersion(++version);
    return Boolean.TRUE;
}