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

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

Introduction

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

Prototype

public static String strip(String str) 

Source Link

Document

Strips whitespace from the start and end of a String.

Usage

From source file:de.codesourcery.eve.skills.datamodel.EveFlags.java

public static void main(String[] args) {

    final Pattern PATTERN = Pattern.compile("^([0-9]+),(.*?),(.*)$");

    for (String line : FLAGS.split("\n")) {
        final String trimmed = StringUtils.strip(line);

        final Matcher m = PATTERN.matcher(line);
        if (!m.matches()) {
            throw new RuntimeException();
        }//  ww w  .j  a  va2s .co m

        final int id = Integer.parseInt(m.group(1));
        final String name = m.group(2).toUpperCase().replaceAll(" ", "_");
        final String displayName = StringUtils.strip(m.group(3));
        System.out.println(name + "(" + id + ",\"" + displayName + "\"),");
    }
}

From source file:com.ah.ui.actions.config.ImportCsvFileAction.java

/**
 * Check the values in one line./*  w  ww .j a v  a2s.  com*/
 *
 *@param arg_Value : line value
 *@param arg_Line : the line number
 *@return boolean : true : the value is valid; false : the value is invalid
 */
private boolean checkTheLineValue(String[] arg_Value, int arg_Line) {
    boolean boolResult = true;
    int length = arg_Value.length;
    if (length == 0) {
        result.append(MgrUtil.getUserMessage("hm.system.log.import.csv.file.check")).append(" ")
                .append(arg_Line).append(" ").append(MgrUtil.getUserMessage("hm.system.log.import.csv.failure"))
                .append(". ").append(MgrUtil.getUserMessage("hm.system.log.import.csv.record.no.value"))
                .append("\n");
        boolResult = false;
    }
    if (arg_Value[0].startsWith("*") || arg_Value[0].startsWith("#")) {
        result.append(MgrUtil.getUserMessage("hm.system.log.import.csv.ignore.line")).append(" ")
                .append(arg_Line).append(MgrUtil.getUserMessage("hm.system.log.import.csv.record.start.char"))
                .append(" '").append(arg_Value[0].charAt(0)).append("'.").append("\n");
        boolResult = false;
    }
    if (arg_Value[0].startsWith("//")) {
        result.append(MgrUtil.getUserMessage("hm.system.log.import.csv.ignore.line")).append(" ")
                .append(arg_Line).append(MgrUtil.getUserMessage("hm.system.log.import.csv.record.start.char"))
                .append(" '//'.").append("\n");
        boolResult = false;
    }
    // ignore blank line
    if (StringUtils.strip(arg_Value[0]).isEmpty() && StringUtils.strip(arg_Value[length - 1]).isEmpty())
        if (StringUtils.isBlank(StringUtils.join(arg_Value))) {
            result.append(MgrUtil.getUserMessage("hm.system.log.import.csv.blank.line.check",
                    String.valueOf(arg_Line))).append("\n");
            boolResult = false;
        }

    return boolResult;
}

From source file:net.triptech.metahive.web.model.BackingForm.java

/**
 * Trim the supplied value.//from   w  w  w. j ava2  s.  com
 *
 * @param value the value
 * @return the string
 */
public static final String trim(final String value) {

    StringBuilder sb = new StringBuilder();

    if (StringUtils.isNotBlank(value)) {
        sb.append(StringUtils.strip(value));

        while (StringUtils.startsWith(sb.toString(), "\u00A0")) {
            sb.delete(0, 1);
        }
        while (StringUtils.startsWith(sb.toString(), " ")) {
            sb.delete(0, 6);
        }
        while (StringUtils.startsWith(sb.toString(), " ")) {
            sb.delete(0, 6);
        }
    }
    return sb.toString();
}

From source file:no.freecode.translator.business.MessageImporter.java

public void importData(InputStream input, String filename) throws IOException {
    MessageLocale locale = getLocale(filename);
    locale.persist();//from  ww w.  ja v  a 2 s. c om

    BufferedReader csvReader = new BufferedReader(new InputStreamReader(input));

    //        HashMap<String, MessageSection> sections = new HashMap<String, MessageSection>();

    //        MessageSection curSection = new MessageSection();
    String curSectionId;
    String curComment = null;

    String line;
    while ((line = StringEscapeUtils.unescapeJava(StringUtils.strip(csvReader.readLine()))) != null) {

        if (StringUtils.startsWith(line, "#")) {
            String comment = StringUtils.stripStart(line, "# ");
            if (StringUtils.isNotEmpty(comment)) {
                curComment = comment;
            }

        } else {
            // Proper line
            String[] entry = StringUtils.split(line, "=", 2);

            if (entry.length == 2) {
                String key = StringUtils.strip(entry[0]);
                String value = StringUtils.strip(entry[1]);

                String[] keyFragments = StringUtils.split(key, ".", 2);

                if (keyFragments.length < 2) {
                    // Root section
                    curSectionId = "root";

                } else {
                    // Split into sections based on what's before the first '.' in the key.
                    curSectionId = keyFragments[0];
                }

                MessageSection curSection = MessageSection.findMessageSection(curSectionId);
                //                    curSection = sections.get(curSectionId);

                if (curSection == null) {
                    curSection = new MessageSection();
                    curSection.setId(curSectionId);
                    //                        sections.put(curSectionId, curSection);
                }

                if (StringUtils.isNotBlank(curComment)) {
                    curSection.setDescription(curComment);
                    curComment = null;
                }

                Set<Message> messages = curSection.getMessages();
                if (messages == null) {
                    messages = new HashSet<Message>();
                    curSection.setMessages(messages);
                }

                // Does this message already have one or more translation? If not, create a new message.
                List<Message> res = Message.findMessagesByPropertyEquals(key).getResultList();
                Message message;
                if (res.size() > 0) {
                    message = res.get(0);
                    logger.trace("Yes, found an already persisted one: " + message);

                } else {
                    message = new Message();
                }

                message.setProperty(key);
                message.getTranslations().put(locale, value);

                messages.add(message);

                logger.trace("persisting curSection: " + curSection);
                curSection.persist();

            } else {
                // Could be an empty line, or an invalid line. Ignore it.
            }
        }
    }

    //        logger.info("sections: " + sections.size());
    //        for (MessageSection section : sections.values()) {
    //            System.out.println(": (id:" + section.getId() + ") " + section);
    //            
    //            for (Message message : section.getMessages()) {
    //                System.out.println("--: (id:" + message.getId() + ") " + message);
    //                
    //                for (Entry<MessageLocale, String> entry : message.getTranslations().entrySet()) {
    //                    System.out.println("-----: " + entry.getKey() + ": " + entry.getValue());
    //                }
    //            }
    //            
    //            section.persist();
    //        }
}

From source file:org.andromda.dbtest.H2.java

/**
 * Load a text file contents with SQL commands as a <code>List of Strings<code>.
 * This method does not perform encoding conversions
 *
 * @param fileName The input file location + name
 * @param delimiter The character delimiter used to separate statements within the file
 * @return The file contents as a <code>String</code>
 * @exception IOException IO Error/*from  w  w w.  j a va 2s. co  m*/
 */
public static List<String> fileToStrings(String fileName, char delimiter) throws IOException {
    File file = new File(fileName);
    if (!file.exists()) {
        LOGGER.error("File " + fileName + " does not exist");
        throw new FileNotFoundException("File " + fileName + " does not exist");
    }
    if (file.isDirectory()) {
        // TODO FileUtils.listFiles(dir, fileFilter, dirFilter) with wildcards to create the list of files to be loaded
    }
    String contents = FileUtils.readFileToString(file);
    List<String> sqls = new ArrayList<String>();
    String[] contentArray = StringUtils.split(contents, delimiter);
    for (int i = 0; i < contentArray.length; i++) {
        sqls.add(StringUtils.strip(contentArray[i]));
        //LOGGER.info(contentArray[i]);
    }
    return sqls;
}

From source file:org.apache.ambari.server.notifications.Notification.java

/**
 * {@inheritDoc}//from   w ww  .  j av  a2 s  . com
 */
@Override
public String toString() {
    StringBuilder buffer = new StringBuilder("Notification{ ");
    buffer.append("type=").append(getType());
    buffer.append(", subject=").append(StringUtils.strip(Subject));
    buffer.append("}");
    return buffer.toString();
}

From source file:org.apache.cloudstack.utils.security.ChecksumValue.java

public ChecksumValue(String digest) {
    digest = StringUtils.strip(digest);
    this.algorithm = algorithmFromDigest(digest);
    this.checksum = stripAlgorithmFromDigest(digest);
}

From source file:org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EP_Paper.java

public String getPaper() {
    if (_paper == null) {
        _paper = StringUtils.strip(this.getData());
    }
    return this._paper;
}

From source file:org.apache.eagle.security.hive.jobrunning.HiveJobFetchSpout.java

private boolean fetchFinishedConfig(AppInfo appInfo, List<MRJob> mrJobs) {
    InputStream is = null;/*  w ww.  j  a  v  a 2s .  c  om*/
    for (MRJob mrJob : mrJobs) {
        String urlString = crawlConfig.endPointConfig.HSBasePath + "jobhistory/conf/" + mrJob.getId() + "?"
                + Constants.ANONYMOUS_PARAMETER;
        try {
            LOG.info("fetch job conf from {}", urlString);
            is = InputStreamUtils.getInputStream(urlString, null, Constants.CompressionType.NONE);
            final org.jsoup.nodes.Document doc = Jsoup.parse(is, "UTF-8", urlString);
            doc.outputSettings().prettyPrint(false);
            org.jsoup.select.Elements elements = doc.select("table[id=conf]").select("tbody").select("tr");
            Map<String, String> hiveQueryLog = new HashMap<>();
            Iterator<org.jsoup.nodes.Element> iter = elements.iterator();
            while (iter.hasNext()) {
                org.jsoup.nodes.Element element = iter.next();
                org.jsoup.select.Elements tds = element.children();
                String key = tds.get(0).text();
                String value = "";
                org.jsoup.nodes.Element valueElement = tds.get(1);
                if (Constants.HIVE_QUERY_STRING.equals(key)) {
                    for (org.jsoup.nodes.Node child : valueElement.childNodes()) {
                        if (child instanceof TextNode) {
                            TextNode valueTextNode = (TextNode) child;
                            value = valueTextNode.getWholeText();
                            value = StringUtils.strip(value);
                        }
                    }
                } else {
                    value = valueElement.text();
                }
                hiveQueryLog.put(key, value);
            }
            if (hiveQueryLog.containsKey(Constants.HIVE_QUERY_STRING)) {
                collector.emit(new ValuesArray(appInfo.getUser(), mrJob.getId(),
                        Constants.ResourceType.JOB_CONFIGURATION, hiveQueryLog), mrJob.getId());
            }
        } catch (Exception e) {
            LOG.warn("fetch job conf from {} failed, {}", urlString, e);
            e.printStackTrace();
            return false;
        } finally {
            Utils.closeInputStream(is);
        }
    }
    return true;
}

From source file:org.apache.storm.st.wrapper.DecoratedLogLine.java

public DecoratedLogLine(String logLine) {
    final List<String> splitOnDecorator = Arrays.asList(StringDecorator.split2(StringUtils.strip(logLine)));
    AssertUtil.assertTwoElements(splitOnDecorator);
    this.logDate = DATE_FORMAT.parseDateTime(splitOnDecorator.get(0).substring(0, DATE_LEN));
    this.data = splitOnDecorator.get(1);
}