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

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

Introduction

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

Prototype

public static String strip(final String str) 

Source Link

Document

Strips whitespace from the start and end of a String.

This is similar to #trim(String) but removes whitespace.

Usage

From source file:io.cloudslang.content.utils.NumberUtilities.java

/**
 * Given an double string if it's a valid double (see isValidDouble) it converts it into an double otherwise it throws an exception
 *
 * @param doubleStr the double to convert
 * @return the double value of the doubleStr
 * @throws IllegalArgumentException if the passed double string is not a valid double
 *///www  .ja  v a 2  s  .c  o  m
public static double toDouble(@Nullable final String doubleStr) {
    if (!isValidDouble(doubleStr)) {
        throw new IllegalArgumentException(
                doubleStr + ExceptionValues.EXCEPTION_DELIMITER + ExceptionValues.INVALID_DOUBLE_VALUE);
    }
    final String stripedDouble = StringUtils.strip(doubleStr);
    return NumberUtils.createDouble(stripedDouble);
}

From source file:com.neophob.sematrix.core.properties.ApplicationConfigurationHelper.java

/**
 * get a int value from the config file.
 *
 * @param property the property//from  w  w  w.  j a va  2 s  .c  o m
 * @return the int
 */
private int parseInt(String property, int defaultValue) {
    String rawConfig = config.getProperty(property);
    if (StringUtils.isNotBlank(rawConfig)) {
        try {
            int val = Integer.parseInt(StringUtils.strip(rawConfig));
            if (val >= 0) {
                return val;
            } else {
                LOG.log(Level.WARNING, "Ignored negative value {0}", rawConfig);
            }
        } catch (Exception e) {
            LOG.log(Level.WARNING, FAILED_TO_PARSE, rawConfig);
        }
    }
    return defaultValue;
}

From source file:by.lang.StringUtilsTest.java

public static void main(String[] args) {
    System.out.println("?,....");
    System.out.println(StringUtils.abbreviate("The quick brown fox jumps over the lazy dog.", 10));

    System.out.println(".");
    System.out.println(StringUtils.chomp("1,2,3,", ","));

    System.out.println("???.");
    System.out.println(StringUtils.contains("defg", "ef"));
    System.out.println(StringUtils.contains("ef", "defg"));

    System.out.println("??nulltoString().");
    System.out.println(StringUtils.defaultString(null, "defaultIfEmpty"));
    System.out.println(".");
    System.out.println(StringUtils.deleteWhitespace("aa  bb  cc"));

    System.out.println("??.");
    System.out.println(StringUtils.isAlpha("ab"));
    System.out.println(StringUtils.isAlphanumeric("12"));
    System.out.println(StringUtils.isBlank(""));
    System.out.println(StringUtils.isNumeric("123"));

    System.out.println("?Null  \"\"");
    System.out.println(StringUtils.isEmpty(null));
    System.out.println(StringUtils.isNotEmpty(null));
    System.out.println("?null  \"\" ");
    System.out.println(StringUtils.isBlank("  "));
    System.out.println(StringUtils.isNotBlank(null));
    System.out.println(".Nullnull");
    System.out.println(StringUtils.trim(null));
    System.out.println("Null\"\" ?Null");
    System.out.println(StringUtils.trimToNull(""));
    // NULL  "" ?""
    // System.out.println(StringUtils.trimToEmpty(null));
    // ??//  w ww  .j  ava2  s  . c o  m
    // System.out.println(StringUtils.strip("  \t"));
    // ?""null?Null
    // System.out.println(StringUtils.stripToNull(" \t"));
    // ?""null?""
    // System.out.println(StringUtils.stripToEmpty(null));
    // ""Null ? ""
    // System.out.println(StringUtils.defaultString(null));
    // Null ?(?)
    // System.out.println(StringUtils.defaultString("", "df"));
    // null""?(?)
    // System.out.println(StringUtils.defaultIfEmpty(null, "sos"));
    // .~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // ?null(?2?)
    // System.out.println(StringUtils.strip("fsfsdf", "f"));
    // ?null???(????)
    // System.out.println(StringUtils.stripStart("ddsuuu ", "d"));
    // ?null???(????)
    // System.out.println(StringUtils.stripEnd("dabads", "das"));
    // 
    // ArrayToList(StringUtils.stripAll(new String[]{" ? ", "  ",
    // " "}));
    // ?null.?(??)
    // ArrayToList(StringUtils.stripAll(new String[]{" ? ", " ", ""},
    // ""));
    // ,~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // 2?,Null
    // System.out.println(StringUtils.equals(null, null));
    // ??
    // System.out.println(StringUtils.equalsIgnoreCase("abc", "ABc"));
    // ????~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // ?null""-1
    // System.out.println(StringUtils.indexOf(null, "a"));
    // ?(?)2k
    // System.out.println(StringUtils.indexOf("akfekcd?", "k", 2));
    // ???
    // System.out.println(StringUtils.ordinalIndexOf("akfekcd?", "k", 2));
    // ,??
    // System.out.println(StringUtils.indexOfIgnoreCase("adfs", "D"));
    // ?(?),??
    // System.out.println(StringUtils.indexOfIgnoreCase("adfs", "a", 3));
    // ??
    // System.out.println(StringUtils.lastIndexOf("adfas", "a"));
    // ?,2
    // System.out.println(StringUtils.lastIndexOf("dabasdafs", "a", 3));
    // ,-1
    // System.out.println(StringUtils.lastOrdinalIndexOf("yksdfdht", "f",
    // 2));
    // ????
    // System.out.println(StringUtils.lastIndexOfIgnoreCase("sdffet", "E"));
    // ,1
    // System.out.println(StringUtils.lastIndexOfIgnoreCase("efefrfs", "F"
    // , 2));
    // ?boolean,null?
    // System.out.println(StringUtils.contains("sdf", "dg"));
    // ?boolean,null?,??
    // System.out.println(StringUtils.containsIgnoreCase("sdf", "D"));
    // ??,boolean
    // System.out.println(StringUtils.containsWhitespace(" d"));
    // ???
    // System.out.println(StringUtils.indexOfAny("absfekf", new
    // String[]{"f", "b"}));
    // (?)
    // System.out.println(StringUtils.indexOfAny("afefes", "e"));
    // ??boolean
    // System.out.println(StringUtils.containsAny("asfsd", new char[]{'k',
    // 'e', 's'}));
    // ?lastIndexOf???boolean
    // System.out.println(StringUtils.containsAny("f", ""));
    // 
    // System.out.println(StringUtils.indexOfAnyBut("seefaff", "af"));
    // ?
    // System.out.println(StringUtils.containsOnly("??", "?"));
    // ?
    // System.out.println(StringUtils.containsOnly("?", new char[]{'',
    // '?'}));
    // ??
    // System.out.println(StringUtils.containsNone("??", ""));
    // ??
    // System.out.println(StringUtils.containsNone("?", new char[]{'',
    // ''}));
    // ????4
    // System.out.println(StringUtils.lastIndexOfAny("", new
    // String[]{"", ""}));
    // ?indexOfAny?? (?)
    // System.out.println(StringUtils.countMatches("", ""));
    // ?CharSequence??Unicode?falseCharSequence=
    // 0true
    // System.out.println(StringUtils.isAlpha("2"));
    // ???UnicodeCharSequence?''CharSequence?=
    // 0true
    // System.out.println(StringUtils.isAlphaSpace("NBA "));
    // ???UnicodeCharSequence?falseCharSequence=
    // 0true
    // System.out.println(StringUtils.isAlphanumeric("NBA"));
    // Unicode
    // CharSequence???''falseCharSequence=
    // 0true
    // System.out.println(StringUtils.isAlphanumericSpace("NBA"));
    // ???ASCII?CharSequencefalseCharSequence=
    // 0true
    // System.out.println(StringUtils.isAsciiPrintable("NBA"));
    // ???
    // System.out.println(StringUtils.isNumeric("NBA"));
    // ???
    // System.out.println(StringUtils.isNumericSpace("33 545"));
    // ??""
    // System.out.println(StringUtils.isWhitespace(" "));
    // ??
    // System.out.println(StringUtils.isAllLowerCase("kjk33"));
    // ?
    // System.out.println(StringUtils.isAllUpperCase("KJKJ"));
    // ?~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // ?2?:
    // System.out.println(StringUtils.difference("", ""));
    // 2
    // System.out.println(StringUtils.indexOfDifference("ww.taobao",
    // "www.taobao.com"));
    // ?
    // System.out.println(StringUtils.indexOfDifference(new String[]
    // {"", "", ""}));
    // ???
    // System.out.println(StringUtils.getCommonPrefix(new String[] {"",
    // "", ""}));
    // ??????
    // System.out.println(StringUtils.getLevenshteinDistance("?",
    // ""));
    // ???
    // System.out.println(StringUtils.startsWith("", ""));
    // ?????
    // System.out.println(StringUtils.startsWithIgnoreCase("",
    // ""));
    // ???
    // System.out.println(StringUtils.startsWithAny("abef", new
    // String[]{"ge", "af", "ab"}));
    // ??
    // System.out.println(StringUtils.endsWith("abcdef", "def"));
    // ????
    // System.out.println(StringUtils.endsWithIgnoreCase("abcdef", "Def"));
    // ?~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // ??nullnull.""""
    // System.out.println(StringUtils.substring("", 2));
    // ?
    // System.out.println(StringUtils.substring("", 2, 4));
    // ?
    // System.out.println(StringUtils.left("", 3));
    // ??
    // System.out.println(StringUtils.right("", 3));
    // ???
    // System.out.println(StringUtils.mid("", 3, 2));
    // ??
    // System.out.println(StringUtils.substringBefore("", ""));
    // ?????
    // System.out.println(StringUtils.substringAfter("", ""));
    // ??.
    // System.out.println(StringUtils.substringBeforeLast("", ""));
    // ?????
    // System.out.println(StringUtils.substringAfterLast("", ""));
    // ???null:2010?
    // System.out.println(StringUtils.substringBetween("??2010?????",
    // "??"));
    // ???
    // ArrayToList(StringUtils.substringsBetween("[a][b][c]", "[", "]"));
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // ?nullnull
    // ArrayToList(StringUtils.split("?  "));
    // ?
    // ArrayToList(StringUtils.split("? ,,", ","));
    // ???0
    // ArrayToList(StringUtils.split("? ", "", 2));
    // ???,?
    // ArrayToList(StringUtils.splitByWholeSeparator("ab-!-cd-!-ef",
    // "-!-"));
    // ???,???
    // ArrayToList(StringUtils.splitByWholeSeparator("ab-!-cd-!-ef", "-!-",
    // 2));
    // " "?,?null
    // ArrayToList(StringUtils.splitByWholeSeparatorPreserveAllTokens(" ab
    // de fg ",
    // null));
    // ?," "??
    // ArrayToList(StringUtils.splitByWholeSeparatorPreserveAllTokens("ab de
    // fg",
    // null, 3));
    // ???,
    // ArrayToList(StringUtils.splitPreserveAllTokens(" ab de fg "));
    // ???,?
    // ArrayToList(StringUtils.splitPreserveAllTokens(" ab de fg ",
    // null));
    // ???,???
    // ArrayToList(StringUtils.splitPreserveAllTokens(" ab de fg ", null,
    // 2));
    // ??
    // ArrayToList(StringUtils.splitByCharacterType("AEkjKr i39:"));
    // 
    // ArrayToList(StringUtils.splitByCharacterTypeCamelCase("ASFSRules234"));
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // ??
    // System.out.println(StringUtils.concat(getArrayData()));
    // ?.?null
    // System.out.println(StringUtils.concatWith(",", getArrayData()));
    // ?
    // System.out.println(StringUtils.join(getArrayData()));
    // ?
    // System.out.println(StringUtils.join(getArrayData(), ":"));
    // (?)?(?,??)
    // System.out.println(StringUtils.join(getArrayData(), ":", 1, 3));
    // ?.?
    // System.out.println(StringUtils.join(getListData(), ":"));
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // 
    // System.out.println(StringUtils.deleteWhitespace(" s   4j"));
    // ?
    // System.out.println(StringUtils.removeStart("www.baidu.com", "www."));
    // ?,??
    // System.out.println(StringUtils.removeStartIgnoreCase("www.baidu.com",
    // "WWW"));
    // ???
    // System.out.println(StringUtils.removeEnd("www.baidu.com", ".com"));
    // ?????
    // System.out.println(StringUtils.removeEndIgnoreCase("www.baidu.com",
    // ".COM"));
    // ?
    // System.out.println(StringUtils.remove("www.baidu.com/baidu", "bai"));
    // "\n", "\r",  "\r\n".
    // System.out.println(StringUtils.chomp("abcrabc\r"));
    // ?
    // System.out.println(StringUtils.chomp("baidu.com", "com"));
    // ?."\n", "\r",  "\r\n"
    // System.out.println(StringUtils.chop("wwe.baidu"));
    // ?~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // ???
    // System.out.println(StringUtils.replaceOnce("www.baidu.com/baidu",
    // "baidu", "hao123"));
    // ?
    // System.out.println(StringUtils.replace("www.baidu.com/baidu",
    // "baidu", "hao123"));
    // ????
    // System.out.println(StringUtils.replace("www.baidu.com/baidu",
    // "baidu", "hao123", 1));
    // ?????:baidu?taobaocom?net
    // System.out.println(StringUtils.replaceEach("www.baidu.com/baidu", new
    // String[]{"baidu", "com"}, new String[]{"taobao", "net"}));
    // ????
    // System.out.println(StringUtils.replaceEachRepeatedly("www.baidu.com/baidu",
    // new String[]{"baidu", "com"}, new String[]{"taobao", "net"}));
    // ????.(????)
    // System.out.println(StringUtils.replaceChars("www.baidu.com", "bdm",
    // "qo"));
    // ?(?)?(?)
    // System.out.println(StringUtils.overlay("www.baidu.com", "hao123", 4,
    // 9));
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // ????
    // System.out.println(StringUtils.repeat("ba", 3));
    // ??????
    // System.out.println(StringUtils.repeat("ab", "ou", 3));
    // ??(???)
    // System.out.println(StringUtils.rightPad("?", 4));
    // ????(?)
    // System.out.println(StringUtils.rightPad("?", 4, "?"));
    // ???
    // System.out.println(StringUtils.leftPad("?", 4));
    // ??????(?)
    // System.out.println(StringUtils.leftPad("?", 4, ""));
    // ?????
    // System.out.println(StringUtils.center("?", 3));
    // ??????
    // System.out.println(StringUtils.center("?", 5, "?"));
    // ??(?),??(??+=?)
    // System.out.println(StringUtils.abbreviate("?", 5));
    // 2: ...ijklmno
    // System.out.println(StringUtils.abbreviate("abcdefghijklmno", 12,
    // 10));
    // ???.: ab.f
    // System.out.println(StringUtils.abbreviateMiddle("abcdef", ".", 4));
    // ?,~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // ?.
    // System.out.println(StringUtils.capitalize("Ddf"));
    // ?.
    // System.out.println(StringUtils.uncapitalize("DTf"));
    // ????????
    // System.out.println(StringUtils.swapCase("I am Jiang, Hello"));
    // ?
    // System.out.println(StringUtils.reverse(""));
    // ?(?)??
    // System.out.println(StringUtils.reverseDelimited("::", ':'));
    // isEmpty
    System.out.println(StringUtils.isEmpty(null)); // true
    System.out.println(StringUtils.isEmpty("")); // true
    System.out.println(StringUtils.isEmpty(" ")); // false
    System.out.println(StringUtils.isEmpty("bob")); // false
    System.out.println(StringUtils.isEmpty("  bob  ")); // false

    // isBlank
    System.out.println(StringUtils.isBlank(null)); // true
    System.out.println(StringUtils.isBlank("")); // true
    System.out.println(StringUtils.isBlank(" ")); // true
    System.out.println(StringUtils.isBlank("bob")); // false
    System.out.println(StringUtils.isBlank("  bob  ")); // false

    // trim
    System.out.println(StringUtils.trim(null)); // null
    System.out.println(StringUtils.trim("")); // ""
    System.out.println(StringUtils.trim("     ")); // ""
    System.out.println(StringUtils.trim("abc")); // "abc"
    System.out.println(StringUtils.trim("    abc")); // "abc"
    System.out.println(StringUtils.trim("    abc  ")); // "abc"
    System.out.println(StringUtils.trim("    ab c  ")); // "ab c"

    // strip
    System.out.println(StringUtils.strip(null)); // null
    System.out.println(StringUtils.strip("")); // ""
    System.out.println(StringUtils.strip("   ")); // ""
    System.out.println(StringUtils.strip("abc")); // "abc"
    System.out.println(StringUtils.strip("  abc")); // "abc"
    System.out.println(StringUtils.strip("abc  ")); // "abc"
    System.out.println(StringUtils.strip(" abc ")); // "abc"
    System.out.println(StringUtils.strip(" ab c ")); // "ab c"
    System.out.println(StringUtils.strip("  abcyx", "xyz")); // " abc"
    System.out.println(StringUtils.stripStart("yxabcxyz  ", "xyz")); // "abcxyz
    // "
    System.out.println(StringUtils.stripEnd("  xyzabcyx", "xyz")); // "
    // xyzabc"
    // ?
    String str1 = "aaa bbb ccc";
    String[] dim1 = StringUtils.split(str1); // => ["aaa", "bbb", "ccc"]

    System.out.println(dim1.length);// 3
    System.out.println(dim1[0]);// "aaa"
    System.out.println(dim1[1]);// "bbb"
    System.out.println(dim1[2]);// "ccc"

    // 
    String str2 = "aaa,bbb,ccc";
    String[] dim2 = StringUtils.split(str2, ","); // => ["aaa", "bbb",
    // "ccc"]

    System.out.println(dim2.length);// 3
    System.out.println(dim2[0]);// "aaa"
    System.out.println(dim2[1]);// "bbb"
    System.out.println(dim2[2]);// "ccc"

    // 
    String str3 = "aaa,,bbb";
    String[] dim3 = StringUtils.split(str3, ","); // => ["aaa", "bbb"]

    System.out.println(dim3.length);// 2
    System.out.println(dim3[0]);// "aaa"
    System.out.println(dim3[1]);// "bbb"

    // ?
    String str4 = "aaa,,bbb";
    String[] dim4 = StringUtils.splitPreserveAllTokens(str4, ","); // =>
    // ["aaa",
    // "",
    // "bbb"]

    System.out.println(dim4.length);// 3
    System.out.println(dim4[0]);// "aaa"
    System.out.println(dim4[1]);// ""
    System.out.println(dim4[2]);// "bbb"

    // ??
    String str5 = "aaa,bbb,ccc";
    String[] dim5 = StringUtils.split(str5, ",", 2); // => ["aaa",
    // "bbb,ccc"]

    System.out.println(dim5.length);// 2
    System.out.println(dim5[0]);// "aaa"
    System.out.println(dim5[1]);// "bbb,ccc"

    // 
    String[] array = { "aaa", "bbb", "ccc" };
    String result1 = StringUtils.join(array, ",");

    System.out.println(result1);// "aaa,bbb,ccc"

    // ?
    List<String> list = new ArrayList<String>();
    list.add("aaa");
    list.add("bbb");
    list.add("ccc");
    String result2 = StringUtils.join(list, ",");
    System.out.println(result2);// "aaa,bbb,ccc"

}

From source file:ca.phon.app.session.editor.view.session_information.SessionInfoEditorView.java

private void update() {
    final SessionEditor editor = getEditor();
    final Session session = editor.getDataModel().getSession();

    final Project project = editor.getExtension(Project.class);
    if (project == null)
        return;/*from   w  w w  . j  a v  a 2 s  . co m*/

    final LocalDate sessionDate = getEditor().getSession().getDate();
    if (sessionDate != null) {
        dateField.setValueIsAdjusting(true);
        dateField.setDateTime(sessionDate);
        dateField.setValueIsAdjusting(false);
    }

    final File mediaFile = MediaLocator.findMediaFile(project, session);
    if (mediaFile != null) {
        mediaLocationField.removePropertyChangeListener(FileSelectionField.FILE_PROP, mediaLocationListener);
        mediaLocationField.setFile(mediaFile);
        mediaLocationField.addPropertyChangeListener(FileSelectionField.FILE_PROP, mediaLocationListener);
    } else {
        if (session.getMediaLocation() != null && StringUtils.strip(session.getMediaLocation()).length() > 0) {
            mediaLocationField.getTextField().setState(FieldState.INPUT);
            mediaLocationField.removePropertyChangeListener(FileSelectionField.FILE_PROP,
                    mediaLocationListener);
            mediaLocationField.setFile(new File(session.getMediaLocation()));
            mediaLocationField.addPropertyChangeListener(FileSelectionField.FILE_PROP, mediaLocationListener);
        } else {
            mediaLocationField.getTextField().setState(FieldState.PROMPT);
        }
    }

    languageField.getDocument().removeDocumentListener(languageFieldListener);
    languageField.setText(session.getLanguage());
    languageField.getDocument().addDocumentListener(languageFieldListener);

    ParticipantsTableModel tableModel = new ParticipantsTableModel(session);
    participantTable.setModel(tableModel);
}

From source file:io.seldon.importer.articles.FileItemAttributesImporter.java

public static Map<String, String> getAttributes(String url, String existingCategory) {
    ItemProcessResult itemProcessResult = new ItemProcessResult();
    itemProcessResult.client_item_id = url;
    itemProcessResult.extraction_status = "EXTRACTION_FAILED";

    logger.info("Trying to get attributes for " + url);
    Map<String, String> attributes = null;
    String title = "";
    String category = "";
    String subCategory = "";
    String img_url = "";
    String description = "";
    String tags = "";
    String leadtext = "";
    String link = "";
    String publishDate = "";
    String domain = "";
    try {//from   ww  w  .j  a v a 2  s  .c  o  m
        long now = System.currentTimeMillis();
        long timeSinceLastRequest = now - lastUrlFetchTime;
        if (timeSinceLastRequest < minFetchGapMsecs) {
            long timeToSleep = minFetchGapMsecs - timeSinceLastRequest;
            logger.info(
                    "Sleeping " + timeToSleep + "msecs as time since last fetch is " + timeSinceLastRequest);
            Thread.sleep(timeToSleep);
        }
        Document articleDoc = Jsoup.connect(url).userAgent("SeldonBot/1.0").timeout(httpGetTimeout).get();
        lastUrlFetchTime = System.currentTimeMillis();
        //get IMAGE URL
        if (StringUtils.isNotBlank(imageCssSelector)) {
            Element imageElement = articleDoc.select(imageCssSelector).first();
            if (imageElement != null) {
                if (imageElement.attr("content") != null) {
                    img_url = imageElement.attr("content");
                }
                if (StringUtils.isBlank(img_url) && imageElement.attr("src") != null) {
                    img_url = imageElement.attr("src");
                }
                if (StringUtils.isBlank(img_url) && imageElement.attr("href") != null) {
                    img_url = imageElement.attr("href");
                }

            }
        }
        if (StringUtils.isBlank(img_url) && StringUtils.isNotBlank(defImageUrl)) {
            logger.info("Setting image to default: " + defImageUrl);
            img_url = defImageUrl;
        }
        img_url = StringUtils.strip(img_url);

        //get TITLE
        if (StringUtils.isNotBlank(titleCssSelector)) {
            Element titleElement = articleDoc.select(titleCssSelector).first();
            if (titleElement != null && titleElement.attr("content") != null) {
                title = titleElement.attr("content");
            }
        }

        //get Lead Text
        if (StringUtils.isNotBlank(leadTextCssSelector)) {
            Element leadElement = articleDoc.select(leadTextCssSelector).first();
            if (leadElement != null && leadElement.attr("content") != null) {
                leadtext = leadElement.attr("content");
            }
        }

        //get publish date
        if (StringUtils.isNotBlank(publishDateCssSelector)) {
            //2013-01-21T10:40:55Z
            Element pubElement = articleDoc.select(publishDateCssSelector).first();
            if (pubElement != null && pubElement.attr("content") != null) {
                String pubtext = pubElement.attr("content");
                SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH);
                Date result = null;
                try {
                    result = df.parse(pubtext);
                } catch (ParseException e) {
                    logger.info("Failed to parse date withUTC format " + pubtext);
                }
                //try a simpler format
                df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH);
                try {
                    result = df.parse(pubtext);
                } catch (ParseException e) {
                    logger.info("Failed to parse date " + pubtext);
                }

                if (result != null)
                    publishDate = dateFormatter.format(result);
                else
                    logger.error("Failed to parse date " + pubtext);
            }
        }

        //get Link
        if (StringUtils.isNotBlank(linkCssSelector)) {
            Element linkElement = articleDoc.select(linkCssSelector).first();
            if (linkElement != null && linkElement.attr("content") != null) {
                link = linkElement.attr("content");
            }
        }

        //get CONTENT
        if (StringUtils.isNotBlank(textCssSelector)) {
            Element descriptionElement = articleDoc.select(textCssSelector).first();
            if (descriptionElement != null)
                description = Jsoup.parse(descriptionElement.html()).text();
        }

        //get TAGS
        Set<String> tagSet = AttributesImporterUtils.getTags(articleDoc, tagsCssSelector, title);

        if (tagSet.size() > 0)
            tags = CollectionTools.join(tagSet, ",");

        //get CATEGORY - client specific
        if (StringUtils.isNotBlank(categoryCssSelector)) {
            Element categoryElement = articleDoc.select(categoryCssSelector).first();
            if (categoryElement != null && categoryElement.attr("content") != null) {
                category = categoryElement.attr("content");
                if (StringUtils.isNotBlank(category))
                    category = category.toUpperCase();
            }
        } else if (StringUtils.isNotBlank(categoryClassPrefix)) {
            String className = "io.seldon.importer.articles.category." + categoryClassPrefix
                    + "CategoryExtractor";
            Class<?> clazz = Class.forName(className);
            Constructor<?> ctor = clazz.getConstructor();
            CategoryExtractor extractor = (CategoryExtractor) ctor.newInstance();
            category = extractor.getCategory(url, articleDoc);
        }

        //get Sub CATEGORY - client specific
        if (StringUtils.isNotBlank(subCategoryCssSelector)) {
            Element subCategoryElement = articleDoc.select(subCategoryCssSelector).first();
            if (subCategoryElement != null && subCategoryElement.attr("content") != null) {
                subCategory = subCategoryElement.attr("content");
                if (StringUtils.isNotBlank(subCategory))
                    subCategory = category.toUpperCase();
            }
        } else if (StringUtils.isNotBlank(subCategoryClassPrefix)) {
            String className = "io.seldon.importer.articles.category." + subCategoryClassPrefix
                    + "SubCategoryExtractor";
            Class<?> clazz = Class.forName(className);
            Constructor<?> ctor = clazz.getConstructor();
            CategoryExtractor extractor = (CategoryExtractor) ctor.newInstance();
            subCategory = extractor.getCategory(url, articleDoc);
        }

        // Get domain
        if (domainIsNeeded) {
            domain = getDomain(url);
        }

        if (StringUtils.isNotBlank(title) && (imageNotNeeded || StringUtils.isNotBlank(img_url))
                && (categoryNotNeeded || StringUtils.isNotBlank(category))
                && (!domainIsNeeded || StringUtils.isNotBlank(domain))) {
            attributes = new HashMap<String, String>();
            attributes.put(TITLE, title);
            if (StringUtils.isNotBlank(category))
                attributes.put(CATEGORY, category);
            if (StringUtils.isNotBlank(subCategory))
                attributes.put(SUBCATEGORY, subCategory);
            if (StringUtils.isNotBlank(link))
                attributes.put(LINK, link);
            if (StringUtils.isNotBlank(leadtext))
                attributes.put(LEAD_TEXT, leadtext);
            if (StringUtils.isNotBlank(img_url))
                attributes.put(IMG_URL, img_url);
            if (StringUtils.isNotBlank(tags))
                attributes.put(TAGS, tags);
            attributes.put(CONTENT_TYPE, VERIFIED_CONTENT_TYPE);
            if (StringUtils.isNotBlank(description))
                attributes.put(DESCRIPTION, description);
            if (StringUtils.isNotBlank(publishDate))
                attributes.put(PUBLISH_DATE, publishDate);
            if (StringUtils.isNotBlank(domain))
                attributes.put(DOMAIN, domain);
            System.out.println("Item: " + url + "; Category: " + category);
            itemProcessResult.extraction_status = "EXTRACTION_SUCCEEDED";
        } else {
            logger.warn("Failed to get title for article " + url);
            logger.warn("[title=" + title + ", img_url=" + img_url + ", category=" + category + ", domain="
                    + domain + "]");
        }

        { // check for failures for the log result
            if (StringUtils.isBlank(title)) {
                itemProcessResult.attrib_failure_list = itemProcessResult.attrib_failure_list
                        + ((StringUtils.isBlank(itemProcessResult.attrib_failure_list)) ? "" : ",") + "title";
            }
            if (!imageNotNeeded && StringUtils.isBlank(img_url)) {
                itemProcessResult.attrib_failure_list = itemProcessResult.attrib_failure_list
                        + ((StringUtils.isBlank(itemProcessResult.attrib_failure_list)) ? "" : ",") + "img_url";
            }
            if (!categoryNotNeeded && StringUtils.isBlank(category)) {
                itemProcessResult.attrib_failure_list = itemProcessResult.attrib_failure_list
                        + ((StringUtils.isBlank(itemProcessResult.attrib_failure_list)) ? "" : ",")
                        + "category";
            }
        }
    } catch (Exception e) {
        logger.warn("Article: " + url + ". Attributes import FAILED", e);
        itemProcessResult.error = e.toString();
    }

    AttributesImporterUtils.logResult(logger, itemProcessResult);

    return attributes;
}

From source file:com.neophob.sematrix.core.properties.ApplicationConfigurationHelper.java

/**
 * Parses the lpd address.//from w ww. j a va2 s.c  o m
 *
 * @return the int
 */
private int parsePixelInvaderConfig() {
    lpdDevice = new ArrayList<DeviceConfig>();

    String value = config.getProperty(ConfigConstant.PIXELINVADERS_ROW1);
    if (StringUtils.isNotBlank(value)) {

        if (parseBoolean(ConfigConstant.PIXELINVADERS_IS_AN_EXPEDITINVADER)) {
            this.deviceXResolution = 4;
            this.deviceYResolution = 4;
        } else {
            this.deviceXResolution = 8;
            this.deviceYResolution = 8;
        }

        devicesInRow1 = 0;
        devicesInRow2 = 0;

        for (String s : value.split(ConfigConstant.DELIM)) {
            try {
                DeviceConfig cfg = DeviceConfig.valueOf(StringUtils.strip(s));
                lpdDevice.add(cfg);
                devicesInRow1++;
            } catch (Exception e) {
                LOG.log(Level.WARNING, FAILED_TO_PARSE, s);
            }
        }
    }

    value = config.getProperty(ConfigConstant.PIXELINVADERS_ROW2);
    if (StringUtils.isNotBlank(value)) {
        for (String s : value.split(ConfigConstant.DELIM)) {
            try {
                DeviceConfig cfg = DeviceConfig.valueOf(StringUtils.strip(s));
                lpdDevice.add(cfg);
                devicesInRow2++;
            } catch (Exception e) {
                LOG.log(Level.WARNING, FAILED_TO_PARSE, s);
            }
        }
    }

    String tmp = config.getProperty(ConfigConstant.PIXELINVADERS_NET_IP);
    this.pixelinvadersNetIp = StringUtils.strip(tmp);
    this.pixelinvadersNetPort = parseInt(ConfigConstant.PIXELINVADERS_NET_PORT);

    //check if PixelController Net Device is enabled
    if (StringUtils.isNotBlank(pixelinvadersNetIp) && pixelinvadersNetPort > 0) {
        LOG.log(Level.INFO,
                "Found PixelInvaders Net Config " + pixelinvadersNetIp + ":" + pixelinvadersNetPort);
        return 0;
    }

    //get blacklist devices
    String blacklist = config.getProperty(ConfigConstant.PIXELINVADERS_BLACKLIST);
    if (blacklist != null) {
        pixelInvadersBlacklist = new ArrayList<String>();
        for (String s : blacklist.split(",")) {
            pixelInvadersBlacklist.add(StringUtils.strip(s));
        }
    }

    //colorcorrection, maximal 16 panels
    for (int i = 0; i < 16; i++) {
        String pixColAdjustR = config.getProperty(ConfigConstant.PIXELINVADERS_COLORADJUST_R + i);
        String pixColAdjustG = config.getProperty(ConfigConstant.PIXELINVADERS_COLORADJUST_G + i);
        String pixColAdjustB = config.getProperty(ConfigConstant.PIXELINVADERS_COLORADJUST_B + i);

        if (pixColAdjustR != null && pixColAdjustG != null && pixColAdjustB != null) {
            RGBAdjust adj = new RGBAdjust(parseInt(ConfigConstant.PIXELINVADERS_COLORADJUST_R + i),
                    parseInt(ConfigConstant.PIXELINVADERS_COLORADJUST_G + i),
                    parseInt(ConfigConstant.PIXELINVADERS_COLORADJUST_B + i));
            LOG.log(Level.INFO, "Found PixelInvaders color correction for output " + i + ": " + adj);
            pixelInvadersCorrectionMap.put(i, adj);
        }
    }

    return lpdDevice.size();
}

From source file:ch.cyberduck.core.Host.java

/**
 * @return HTTP accessible URL with the same hostname as the server
 *//*w w  w.  j  a va  2 s .  c o m*/
public String getDefaultWebURL() {
    return String.format("http://%s", StringUtils.strip(hostname));
}

From source file:ca.phon.ipamap.IpaMap.java

/**
 * Perform a search/*w w w  .jav a  2 s  .com*/
 * 
 * @param search - a set of search terms (separated by ',')
 * @return a set of results
 */
private static Set<Cell> performSearch(SearchType st, String search) {
    Set<Cell> retVal = new HashSet<Cell>();

    FeatureMatrix fm = FeatureMatrix.getInstance();
    search = StringUtils.strip(search.toLowerCase());
    if (search.length() > 0) {
        for (Grid grid : getGridData().getGrid()) {
            for (Cell cell : grid.getCell()) {
                //            for(String searchTerm:searchTerms) {
                //               searchTerm = StringUtils.strip(searchTerm).toLowerCase();
                //               if(searchTerm.length() == 0) continue; 

                boolean addToResults = false;

                if (st == SearchType.ALL) {
                    addToResults = cell.getText().toLowerCase().contains(search);
                }

                if (st == SearchType.ALL) {
                    for (CellProp prop : cell.getProperty()) {
                        if (prop.getName().equalsIgnoreCase("description"))
                            continue;
                        addToResults |= prop.getContent().toLowerCase().contains(search);
                    }
                }

                if (st == SearchType.ALL || st == SearchType.FEATURES) {
                    String[] asFeature = search.split(",");
                    FeatureSet fs = new FeatureSet();
                    for (String feature : asFeature) {
                        if (feature == null)
                            break;
                        Feature f = FeatureMatrix.getInstance().getFeature(StringUtils.strip(feature));
                        if (f != null) {
                            fs.union(f.getFeatureSet());
                        }
                    }
                    FeatureSet charFs = new FeatureSet();
                    // check feature set(s)
                    for (Character c : cell.getText().toCharArray()) {
                        FeatureSet cFs = fm.getFeatureSet(c);
                        if (cFs != null) {
                            charFs.union(cFs);
                        }
                    }
                    FeatureSet intersectFs = FeatureSet.intersect(charFs, fs);
                    if (intersectFs.getFeatures().size() > 0
                            && intersectFs.getFeatures().size() == fs.getFeatures().size()) {
                        addToResults |= true;
                    }
                }
                //               
                if (addToResults)
                    retVal.add(cell);
                //            }
            }
        }
    }

    return retVal;
}

From source file:io.seldon.importer.articles.GeneralItemAttributesImporter.java

public static Map<String, String> getAttributes(UrlFetcher urlFetcher, String url, String existingCategory) {
    ItemProcessResult itemProcessResult = new ItemProcessResult();
    itemProcessResult.client_item_id = url;
    itemProcessResult.extraction_status = "EXTRACTION_FAILED";

    logger.info("Trying to get attributes for " + url);
    Map<String, String> attributes = null;
    try {/*from w  w w.j a v a 2s  . c o m*/
        long now = System.currentTimeMillis();
        long timeSinceLastRequest = now - lastUrlFetchTime;
        if (timeSinceLastRequest < minFetchGapMsecs) {
            long timeToSleep = minFetchGapMsecs - timeSinceLastRequest;
            logger.info(
                    "Sleeping " + timeToSleep + "msecs as time since last fetch is " + timeSinceLastRequest);
            Thread.sleep(timeToSleep);
        }

        String page = urlFetcher.getUrl(url); // fetch the article page
        Document articleDoc = Jsoup.parse(page);

        lastUrlFetchTime = System.currentTimeMillis();

        attributes = new HashMap<String, String>();

        if (attribute_detail_list != null) {

            for (AttributeDetail attributeDetail : attribute_detail_list) {
                String attrib_name = attributeDetail.name;
                String attrib_value = null;
                String attrib_default_value = attributeDetail.default_value;

                String extractorType = attributeDetail.extractor_type;
                if (StringUtils.isNotBlank(extractorType)) {
                    DynamicExtractor extractor = DynamicExtractor.build(extractorType);
                    attrib_value = extractor.extract(attributeDetail, url, articleDoc);
                }

                attrib_name = (attrib_name != null) ? StringUtils.strip(attrib_name) : "";
                attrib_value = (attrib_value != null) ? StringUtils.strip(attrib_value) : "";
                attrib_default_value = (attrib_default_value != null) ? StringUtils.strip(attrib_default_value)
                        : "";

                // Use the default value if necessary
                if (StringUtils.isBlank(attrib_value) && StringUtils.isNotBlank(attrib_default_value)) {
                    attrib_value = attrib_default_value;
                }

                if (StringUtils.isNotBlank(attrib_name) && StringUtils.isNotBlank(attrib_value)) {
                    attributes.put(attrib_name, attrib_value);
                }
            }

            // check if the import was ok
            boolean required_import_ok = true;
            for (AttributeDetail attributeDetail : attribute_detail_list) {
                if (attributeDetail.is_required && (!attributes.containsKey(attributeDetail.name))) {
                    required_import_ok = false;
                    itemProcessResult.attrib_failure_list = itemProcessResult.attrib_failure_list
                            + ((StringUtils.isBlank(itemProcessResult.attrib_failure_list)) ? "" : ",")
                            + attributeDetail.name;
                }
            }

            if (required_import_ok) {
                if (contentTypeOverride == null) {
                    attributes.put(CONTENT_TYPE, VERIFIED_CONTENT_TYPE);
                } else {
                    attributes.put(CONTENT_TYPE, contentTypeOverride);
                }
                if (addBaseUrlAttribute) {
                    String baseUrl = AttributesImporterUtils.getBaseUrl(url);
                    attributes.put("baseurl", baseUrl);
                }
                itemProcessResult.extraction_status = "EXTRACTION_SUCCEEDED";
            } else {
                attributes = null;
                logger.warn("Failed to get needed attributes for article " + url);
            }

        }

    } catch (Exception e) {
        logger.error("Article: " + url + ". Attributes import FAILED", e);
        itemProcessResult.error = e.toString();
    }

    AttributesImporterUtils.logResult(logger, itemProcessResult);

    return attributes;
}

From source file:com.neophob.sematrix.core.properties.ApplicationConfigurationHelper.java

/**
 * Parses the stealth address./*www  . ja  va2 s  .  c  om*/
 *
 * @return the int
 */
private int parseStealthConfig() {
    stealthDevice = new ArrayList<DeviceConfig>();

    String value = config.getProperty(ConfigConstant.STEALTH_ROW1);
    if (StringUtils.isNotBlank(value)) {
        this.deviceXResolution = 16;
        this.deviceYResolution = 16;
        for (String s : value.split(ConfigConstant.DELIM)) {
            try {
                DeviceConfig cfg = DeviceConfig.valueOf(StringUtils.strip(s));
                stealthDevice.add(cfg);
                devicesInRow1++;
            } catch (Exception e) {
                LOG.log(Level.WARNING, FAILED_TO_PARSE, s);
            }
        }
    }

    value = config.getProperty(ConfigConstant.STEALTH_ROW2);
    if (StringUtils.isNotBlank(value)) {
        for (String s : value.split(ConfigConstant.DELIM)) {
            try {
                DeviceConfig cfg = DeviceConfig.valueOf(StringUtils.strip(s));
                stealthDevice.add(cfg);
                devicesInRow2++;
            } catch (Exception e) {
                LOG.log(Level.WARNING, FAILED_TO_PARSE, s);
            }
        }
    }

    return stealthDevice.size();
}