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

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

Introduction

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

Prototype

public static String deleteWhitespace(final String str) 

Source Link

Document

Deletes all whitespaces from a String as defined by Character#isWhitespace(char) .

 StringUtils.deleteWhitespace(null)         = null StringUtils.deleteWhitespace("")           = "" StringUtils.deleteWhitespace("abc")        = "abc" StringUtils.deleteWhitespace("   ab  c  ") = "abc" 

Usage

From source file:io.bibleget.BibleGetSelection.java

public void getQuoteFromSelection() {
    List<String> preferredVersions = new ArrayList<>();
    Object retVal = biblegetDB.getOption("PREFERREDVERSIONS");
    if (null == retVal) {
    } else {/*  ww w  .  j av  a 2  s.c o m*/
        String[] favoriteVersions = StringUtils.split((String) retVal, ',');
        preferredVersions = Arrays.asList(favoriteVersions);
    }

    if (preferredVersions.isEmpty()) {
        preferredVersions.add("NVBSE");
    }

    String versions = StringUtils.join(preferredVersions.toArray(), ',');

    Object m_xCurSel;
    try {
        m_xCurSel = m_xTextDocument.getCurrentSelection();
        if (m_xCurSel != null) {
            //there is a selection, we can do something with it
            XIndexAccess xIndex = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, m_xCurSel);
            Object Sel0;
            try {
                Sel0 = xIndex.getByIndex(0);
                XTextRange xTextRange = (XTextRange) UnoRuntime.queryInterface(XTextRange.class, Sel0);
                String myInputContent = xTextRange.getString();
                myInputContent = StringUtils.deleteWhitespace(myInputContent);
                //System.out.println("You typed : "+myInputContent);
                if (myInputContent.isEmpty() == false) {

                    HTTPCaller myHTTPCaller = new HTTPCaller();
                    String myResponse;
                    try {
                        Boolean querycheck = myHTTPCaller.integrityCheck(myInputContent, preferredVersions);
                        if (querycheck) {
                            //JOptionPane.showMessageDialog(null, "All is proceeding nicely", "progress info", JOptionPane.INFORMATION_MESSAGE);
                            myResponse = myHTTPCaller.sendGet(myInputContent, versions);
                            if (myResponse != null) {
                                xTextRange.setString("");
                                BibleGetJSON myJSON = new BibleGetJSON(m_xController);
                                myJSON.JSONParse(myResponse);
                            } else {
                                JOptionPane.showMessageDialog(null, __(
                                        "There was a problem communicating with the BibleGet server. Please try again."),
                                        "ERROR >> SERVER CONNECTIVITY ISSUE", JOptionPane.ERROR_MESSAGE);
                            }
                        } else {
                            String[] errorMessages = myHTTPCaller.getErrorMessages();
                            String errorDialog = StringUtils.join(errorMessages, "\n\n");
                            JOptionPane.showMessageDialog(null, errorDialog, "ERROR >> MALFORMED QUERYSTRING",
                                    JOptionPane.ERROR_MESSAGE);
                        }
                    } catch (HeadlessException | ClassNotFoundException | UnknownPropertyException
                            | PropertyVetoException | com.sun.star.lang.IllegalArgumentException
                            | WrappedTargetException ex) {
                        Logger.getLogger(BibleGetFrame.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } else {
                    JOptionPane.showMessageDialog(null, __("You cannot send an empty query."),
                            "ERROR >> EMPTY SELECTION", JOptionPane.ERROR_MESSAGE);
                }

            } catch (IndexOutOfBoundsException | WrappedTargetException ex) {
                Logger.getLogger(BibleGetSelection.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    } catch (Exception ex) {
        Logger.getLogger(BibleGetSelection.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.github.devnied.emvnfccard.enums.EmvCardScheme.java

 /**
 * Get card type by AID/* w w  w  .  ja v a  2  s  .  co m*/
 * 
 * @param pAid
 *            card AID
 * @return CardType or null
 */
public static EmvCardScheme getCardTypeByAid(final String pAid) {
   EmvCardScheme ret = null;
   if (pAid != null) {
      String aid = StringUtils.deleteWhitespace(pAid);
      for (EmvCardScheme val : EmvCardScheme.values()) {
         for (String schemeAid : val.getAid()) {
            if (aid.startsWith(StringUtils.deleteWhitespace(schemeAid))) {
               ret = val;
               break;
            }
         }
      }
   }
   return ret;
}

From source file:com.civis.utils.opennlp.models.contactperson.ContactPersonSpan.java

/**
 * Remove whitespace between first and second name.
 * <p/>//w  w w.j  av a 2 s.co m
 * Alexander Rom return AlexanderRom
 */
public String getFullNameWithoutWhiteSpace() {
    return StringUtils.deleteWhitespace(getFullName());
}

From source file:com.amashchenko.struts2.pdfstream.PdfStreamResultTest.java

@Test
public void testParseContent() throws Exception {
    Assert.assertNotNull(pdfStreamResult);

    final Document doc = pdfStreamResult.parseContent("<div>text</div>");
    Assert.assertNotNull(doc);//from  www .  j  a va2 s  .c  o m

    Assert.assertEquals("<html><head></head><body><div>text</div></body></html>",
            StringUtils.deleteWhitespace(doc.html()));
}

From source file:freddo.dtalk2.broker.servlet.DTalkServerEndpoint.java

@OnMessage
public void onMessage(String message) {
    message = StringUtils.deleteWhitespace(message);

    if (LOG.isTraceEnabled()) {
        String _message = message;
        if (_message.length() > 64) {
            _message = _message.substring(0, 64) + "...";
        }//from  w  ww .  j a  v a 2  s.c  o  m
        LOG.trace(">>> onMessage: {}", _message);
    }

    // Handle message.
    BrokerMessageHandler.onMessage(this, message);
}

From source file:com.github.devnied.emvnfccard.enums.EmvCardScheme.java

 /**
 * Method used to the the card type with regex
 * /*from   w w w .  ja v a  2 s . c om*/
 * @param pCardNumber
 *            card number
 * @return the type of the card using regex
 */
public static EmvCardScheme getCardTypeByCardNumber(final String pCardNumber) {
   EmvCardScheme ret = null;
   if (pCardNumber != null) {
      for (EmvCardScheme val : EmvCardScheme.values()) {
         if (val.pattern != null && val.pattern.matcher(StringUtils.deleteWhitespace(pCardNumber)).matches()) {
            ret = val;
            break;
         }
      }
   }
   return ret;
}

From source file:com.amashchenko.struts2.pdfstream.PdfStreamResultTest.java

@Test
public void testParseContentInput() throws Exception {
    Assert.assertNotNull(pdfStreamResult);

    final Document doc = pdfStreamResult.parseContent("<form><input type='text' name='name'></form>");
    Assert.assertNotNull(doc);/*from ww  w  . ja  va  2  s.c o  m*/

    Assert.assertEquals(
            "<html><head></head><body><form><inputtype=\"text\"name=\"name\"/></form></body></html>",
            StringUtils.deleteWhitespace(doc.html()));
}

From source file:freddo.dtalk2.broker.servlet.DTalkServerEndpoint.java

@Override
public Future<Void> sendMessage(String message) {
    message = StringUtils.deleteWhitespace(message);

    if (LOG.isTraceEnabled()) {
        String _message = message;
        if (_message.length() > 64) {
            _message = _message.substring(0, 64) + "...";
        }//from ww  w. j  a  va 2s .  c  o  m
        LOG.trace(">>> onMessage: {}", _message);
    }

    return mSession.getAsyncRemote().sendText(message);
}

From source file:com.amashchenko.struts2.pdfstream.PdfStreamResultTest.java

@Test
public void testParseContentScript() throws Exception {
    Assert.assertNotNull(pdfStreamResult);

    final Document doc = pdfStreamResult.parseContent(
            "<head><script>alert('alert 1');<\\/script></head><script>alert('alert 2');</script><div>text</div>");
    Assert.assertNotNull(doc);/*from  ww w.jav a 2s.c om*/

    Assert.assertEquals("<html><head></head><body><div>text</div></body></html>",
            StringUtils.deleteWhitespace(doc.html()));
}

From source file:com.santhoshknn.sudoku.GridExtractor.java

/**
 * <p>/*w ww. j  a  v  a  2 s.co  m*/
 * Parses the supplied file to extract a 9x9 grid of integers substituting
 * the supplied x with a 0
 * </p>
 * <b>Note:</b>Used internally for testing with various data. REST API uses
 * the operation above
 *
 * @param input
 * @return extracted grid if valid input, null otherwise
 */
public GridResponse parseFromFile(final String fileName) {
    int[][] grid = new int[9][9]; // default 0 vals
    GridResponse response = new GridResponse();
    Scanner scanner = null;
    String error = null;
    try {
        URL url = getClass().getResource(fileName);
        log.info("Reading input file [{}]", url.getFile());
        scanner = new Scanner(new File(url.getPath()));
        int row = 0;
        while (scanner.hasNext()) {
            int col = 0;
            String line = scanner.nextLine();
            // delete whitespaces added for cosmetic purpose
            line = StringUtils.deleteWhitespace(line);
            if (line.isEmpty())
                continue; // Sanitize input. Remove line added for
                          // readability
                          // fail if line's length!=9
            if (line.length() != 9) {
                error = INVALID_CHARS_IN_FILE + ":" + (row + 1);
                break;
            }

            for (int i = 0; i < line.length(); i++) {
                //log.info("Row [{}] Char is [{}]",row,line.charAt(i));
                if (Character.isDigit(line.charAt(i))) {
                    int number = Character.getNumericValue(line.charAt(i));
                    grid[row][col] = number;
                } else {
                    grid[row][col] = 0;
                }
                col++;
            }
            if (row == 9)
                break;
            row++;
        }
    } catch (FileNotFoundException e) {
        log.error("Error reading file [{}]", fileName, e);
    } finally {
        if (scanner != null)
            scanner.close();
    }
    if (null == error) {
        response.setGrid(grid);
    } else {
        response.setError(error);
        log.error(error);
    }
    return response;
}