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:org.alfresco.po.share.MyTasksPage.java

/**
 * Method to find given task row/*from w ww . j ava  2s.co  m*/
 * 
 * @param taskName String
 * @return WebElement
 */
public WebElement findTaskRow(String taskName) {
    try {
        List<WebElement> taskRows = findAndWaitForElements(TASKS_ROWS);
        if (null != taskRows && taskRows.size() > 0) {
            for (WebElement taskRow : taskRows) {
                String tName = StringUtils.deleteWhitespace(taskName);
                WebElement el = taskRow.findElement(By.cssSelector("h3 a"));
                String eln = el.getText();
                String elName = StringUtils.deleteWhitespace(eln);
                if (tName.equals(elName)) {
                    return taskRow;
                }
            }
        }
    } catch (StaleElementReferenceException e) {
        return findTaskRow(taskName);
    } catch (TimeoutException e) {
        return null;
    }
    return null;
}

From source file:org.alfresco.po.share.MyTasksPage.java

/**
 * Return count workFlows with same taskName.
 * //  w w w .ja v  a2  s .  c om
 * @param taskName String
 * @return int
 */
public int getTaskCount(String taskName) {
    int count = 0;
    try {
        List<WebElement> taskRows = findAndWaitForElements(TASKS_ROWS);
        if (null != taskRows && taskRows.size() > 0) {
            for (WebElement taskRow : taskRows) {
                String tName = StringUtils.deleteWhitespace(taskName);
                WebElement el = taskRow.findElement(By.cssSelector("h3 a"));
                String eln = el.getText();
                String elName = StringUtils.deleteWhitespace(eln);
                if (tName.equals(elName)) {
                    count++;
                }
            }
        }
    } catch (StaleElementReferenceException e) {
        return getTaskCount(taskName);
    } catch (TimeoutException e) {
        return count;
    }
    return count;
}

From source file:org.alfresco.po.share.MyTasksPage.java

public boolean isTaskNameUnique(String taskName) {
    List<WebElement> taskRows = driver.findElements(TASKS_ROWS);
    int count = 0;
    if (null != taskRows && taskRows.size() > 0) {
        for (WebElement taskRow : taskRows) {
            if (StringUtils.deleteWhitespace(taskName).equals(
                    StringUtils.deleteWhitespace(taskRow.findElement(By.cssSelector("h3 a")).getText()))) {
                count++;//from   w  w  w.jav  a 2 s  .co m
            }
        }
    }
    if (count == 1) {
        return true;
    }
    return false;
}

From source file:org.alfresco.po.share.workflow.MyWorkFlowsPage.java

/**
 * @param workFlowName String/*w  ww.ja v a  2  s.c  o  m*/
 * @return List<WebElement>
 */
private List<WebElement> findWorkFlowRow(String workFlowName) {
    if (workFlowName == null) {
        throw new IllegalArgumentException("Workflow Name can't be null");
    }
    List<WebElement> workflowRowsElements = new ArrayList<WebElement>();

    try {
        List<WebElement> workFlowRows = findAndWaitForElements(WORKFLOW_ROWS);
        if (null != workFlowRows && workFlowRows.size() > 0) {
            for (WebElement workFlowRow : workFlowRows) {

                if (StringUtils.deleteWhitespace(workFlowName).equals(StringUtils
                        .deleteWhitespace(workFlowRow.findElement(By.cssSelector("h3 a")).getText()))) {
                    workflowRowsElements.add(workFlowRow);
                }
            }
        }
    } catch (NoSuchElementException nse) {
        if (logger.isTraceEnabled()) {
            logger.trace("No workflow found", nse);
        }
    } catch (StaleElementReferenceException se) {
    }
    return workflowRowsElements;
}

From source file:org.apache.nifi.controller.cluster.ZooKeeperClientConfig.java

/**
 * Takes a given connect string and splits it by ',' character. For each
 * split result trims whitespace then splits by ':' character. For each
 * secondary split if a single value is returned it is trimmed and then the
 * default zookeeper 2181 is append by adding ":2181". If two values are
 * returned then the second value is evaluated to ensure it contains only
 * digits and if not then the entry is in error and exception is raised.
 * If more than two values are//from   w  w w  .jav a2  s .c o m
 * returned the entry is in error and an exception is raised.
 * Each entry is trimmed and if empty the
 * entry is skipped. After all splits are cleaned then they are all appended
 * back together demarcated by "," and the full string is returned.
 *
 * @param connectString the string to clean
 * @return cleaned connect string guaranteed to be non null but could be
 * empty
 * @throws IllegalStateException if any portions could not be cleaned/parsed
 */
public static String cleanConnectString(final String connectString) {
    final String nospaces = StringUtils.deleteWhitespace(connectString);
    final String hostPortPairs[] = StringUtils.split(nospaces, ",", 100);
    final List<String> cleanedEntries = new ArrayList<>(hostPortPairs.length);
    for (final String pair : hostPortPairs) {
        final String pairSplits[] = StringUtils.split(pair, ":", 3);
        if (pairSplits.length > 2 || pairSplits[0].isEmpty()) {
            throw new IllegalStateException("Invalid host:port pair entry '" + pair + "' in nifi.properties "
                    + NiFiProperties.ZOOKEEPER_CONNECT_STRING + "' property");
        }
        if (pairSplits.length == 1) {
            cleanedEntries.add(pairSplits[0] + ":2181");
        } else {
            if (PORT_PATTERN.matcher(pairSplits[1]).matches()) {
                cleanedEntries.add(pairSplits[0] + ":" + pairSplits[1]);
            } else {
                throw new IllegalStateException(
                        "The port specified in this pair must be 1 to 5 digits only but was '" + pair
                                + "' in nifi.properties " + NiFiProperties.ZOOKEEPER_CONNECT_STRING
                                + "' property");
            }
        }
    }
    return StringUtils.join(cleanedEntries, ",");
}

From source file:org.apache.openmeetings.core.servlet.outputhandler.DownloadHandler.java

@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {//  w w w  . ja v  a2s .com
        request.setCharacterEncoding(StandardCharsets.UTF_8.name());

        log.debug("\nquery = " + request.getQueryString());
        log.debug("\n\nfileName = " + request.getParameter("fileName"));
        log.debug("\n\nparentPath = " + request.getParameter("parentPath"));

        String queryString = request.getQueryString();
        if (queryString == null) {
            queryString = "";
        }

        String sid = request.getParameter("sid");

        if (sid == null) {
            sid = "default";
        }
        log.debug("sid: " + sid);

        Long users_id = getBean(SessiondataDao.class).check(sid);
        Set<Right> rights = getBean(UserDao.class).getRights(users_id);

        if (rights != null && !rights.isEmpty()) {
            String room_id = request.getParameter("room_id");
            if (room_id == null) {
                room_id = "default";
            }

            String moduleName = request.getParameter("moduleName");
            if (moduleName == null) {
                moduleName = "nomodule";
            }

            String parentPath = request.getParameter("parentPath");
            if (parentPath == null) {
                parentPath = "nomodule";
            }

            String requestedFile = request.getParameter("fileName");
            if (requestedFile == null) {
                requestedFile = "";
            }

            String fileIdParam = request.getParameter("fileId");
            Long fileId = null;
            if (fileIdParam != null) {
                fileId = Long.valueOf(fileIdParam);
            }

            // make a complete name out of domain(group) + roomname
            String roomName = room_id;
            // trim whitespaces cause it is a directory name
            roomName = StringUtils.deleteWhitespace(roomName);

            // Get the current User-Directory

            File working_dir;

            // Add the Folder for the Room
            if (moduleName.equals("lzRecorderApp")) {
                working_dir = OmFileHelper.getStreamsHibernateDir();
            } else if (moduleName.equals("videoconf1")) {
                working_dir = OmFileHelper.getUploadRoomDir(roomName);
                if (parentPath.length() != 0 && !parentPath.equals("/")) {
                    working_dir = new File(working_dir, parentPath);
                }
            } else if (moduleName.equals("userprofile")) {
                working_dir = OmFileHelper.getUploadProfilesUserDir(users_id);
                logNonExistentFolder(working_dir);
            } else if (moduleName.equals("remoteuserprofile")) {
                String remoteUser_id = request.getParameter("remoteUserid");
                working_dir = OmFileHelper
                        .getUploadProfilesUserDir(remoteUser_id == null ? "0" : remoteUser_id);
                logNonExistentFolder(working_dir);
            } else if (moduleName.equals("remoteuserprofilebig")) {
                String remoteUser_id = request.getParameter("remoteUserid");
                working_dir = OmFileHelper
                        .getUploadProfilesUserDir(remoteUser_id == null ? "0" : remoteUser_id);
                logNonExistentFolder(working_dir);

                requestedFile = getBigProfileUserName(working_dir);
            } else if (moduleName.equals("chat")) {
                String remoteUser_id = request.getParameter("remoteUserid");
                working_dir = OmFileHelper
                        .getUploadProfilesUserDir(remoteUser_id == null ? "0" : remoteUser_id);
                logNonExistentFolder(working_dir);

                requestedFile = getChatUserName(working_dir);
            } else {
                working_dir = OmFileHelper.getUploadRoomDir(roomName);
            }

            if (!moduleName.equals("nomodule")) {
                log.debug("requestedFile: " + requestedFile + " current_dir: " + working_dir);

                File full_path = new File(working_dir, requestedFile);

                // If the File does not exist or is not readable show/load a
                // place-holder picture

                if (!full_path.exists() || !full_path.canRead()) {
                    if (!full_path.canRead()) {
                        log.debug("LOG DownloadHandler: The request file is not readable ");
                    } else {
                        log.debug(
                                "LOG DownloadHandler: The request file does not exist / has already been deleted");
                    }
                    log.debug("LOG ERROR requestedFile: " + requestedFile);
                    // replace the path with the default picture/document

                    if (requestedFile.endsWith(".jpg")) {
                        log.debug("LOG endsWith d.jpg");

                        log.debug("LOG moduleName: " + moduleName);

                        requestedFile = defaultImageName;
                        if (moduleName.equals("remoteuserprofile")) {
                            requestedFile = defaultProfileImageName;
                        } else if (moduleName.equals("remoteuserprofilebig")) {
                            requestedFile = defaultProfileImageNameBig;
                        } else if (moduleName.equals("userprofile")) {
                            requestedFile = defaultProfileImageName;
                        } else if (moduleName.equals("chat")) {
                            requestedFile = defaultChatImageName;
                        }
                    } else if (requestedFile.endsWith(".swf")) {
                        requestedFile = defaultSWFName;
                    } else {
                        requestedFile = defaultImageName;
                    }
                    full_path = new File(OmFileHelper.getDefaultDir(), requestedFile);
                }

                log.debug("full_path: " + full_path);

                if (!full_path.exists() || !full_path.canRead()) {
                    log.debug(
                            "DownloadHandler: The request DEFAULT-file does not exist / has already been deleted");
                    // no file to handle abort processing
                    return;
                }
                // Requested file is outside OM webapp folder
                File curDirFile = OmFileHelper.getOmHome();
                if (!full_path.getCanonicalPath().startsWith(curDirFile.getCanonicalPath())) {
                    throw new Exception("Invalid file requested: f2.cp == " + full_path.getCanonicalPath()
                            + "; curDir.cp == " + curDirFile.getCanonicalPath());
                }

                // Default type - Explorer, Chrome and others
                int browserType = 0;

                // Firefox and Opera browsers
                if (request.getHeader("User-Agent") != null) {
                    if ((request.getHeader("User-Agent").contains("Firefox"))
                            || (request.getHeader("User-Agent").contains("Opera"))) {
                        browserType = 1;
                    }
                }

                log.debug("Detected browser type:" + browserType);

                response.reset();
                response.resetBuffer();
                try (OutputStream out = response.getOutputStream()) {
                    if (requestedFile.endsWith(".swf")) {
                        // trigger download to SWF => THIS is a workaround for
                        // Flash Player 10, FP 10 does not seem
                        // to accept SWF-Downloads with the Content-Disposition
                        // in the Header
                        response.setContentType("application/x-shockwave-flash");
                        response.setHeader("Content-Length", "" + full_path.length());
                    } else {
                        response.setContentType("APPLICATION/OCTET-STREAM");

                        String fileNameResult = requestedFile;
                        if (fileId != null && fileId > 0) {
                            FileExplorerItem fileExplorerItem = getBean(FileExplorerItemDao.class).get(fileId);
                            if (fileExplorerItem != null) {

                                fileNameResult = fileExplorerItem.getName().substring(0,
                                        fileExplorerItem.getName().length() - 4)
                                        + fileNameResult.substring(fileNameResult.length() - 4,
                                                fileNameResult.length());

                            }
                        }

                        if (browserType == 0) {
                            response.setHeader("Content-Disposition", "attachment; filename="
                                    + URLEncoder.encode(fileNameResult, StandardCharsets.UTF_8.name()));
                        } else {
                            response.setHeader("Content-Disposition", "attachment; filename*=UTF-8'en'"
                                    + URLEncoder.encode(fileNameResult, StandardCharsets.UTF_8.name()));
                        }

                        response.setHeader("Content-Length", "" + full_path.length());
                    }

                    OmFileHelper.copyFile(full_path, out);
                    out.flush();
                }
            }
        } else {
            log.error("ERROR DownloadHandler: not authorized FileDownload ");
        }

    } catch (ServerNotInitializedException e) {
        return;
    } catch (Exception er) {
        log.error("Error downloading: ", er);
    }
}

From source file:org.apache.sling.contextaware.config.impl.metadata.BundleConfigurationMapping.java

/**
 * Parse all annotation classes/*from  www  .  jav a2  s .c  o  m*/
 * @return
 */
private Map<String, ConfigurationMapping> initializeConfigMappings() {
    Map<String, ConfigurationMapping> configMappings = new HashMap<>();

    String[] classNames = StringUtils.split(StringUtils.deleteWhitespace(classNamesList), ",");
    for (String className : classNames) {
        try {
            Class<?> configClass = bundle.loadClass(className);
            if (AnnotationClassParser.isContextAwareConfig(configClass)) {
                log.debug("{}: Add configuration class {}", bundle.getSymbolicName(), className);

                ConfigurationMapping configMapping = new ConfigurationMapping(configClass);
                if (!hasMappingConflict(configMapping, configMappings)) {
                    configMappings.put(configMapping.getConfigName(), configMapping);
                }
            } else {
                log.warn("Ignoring invalid configuration class: {}", className);
            }
        } catch (ClassNotFoundException ex) {
            log.warn("Unable to load class: " + className, ex);
        }
    }

    return configMappings;
}

From source file:org.apache.struts2.EmbeddedJSPResultTest.java

public void testScriptlet() throws Exception {
    result.setLocation("org/apache/struts2/scriptlet.jsp");
    result.execute(null);/*from   w w  w. java  2 s .  c  o m*/

    assertEquals("Saynotoscriptlets", StringUtils.deleteWhitespace(response.getContentAsString()));
}

From source file:org.apache.struts2.EmbeddedJSPResultTest.java

public void testEmbedded() throws Exception {
    //the jsp is inside jsps.jar
    result.setLocation("dir/all.jsp");
    result.execute(null);/*from  ww w .j av  a 2 s  . com*/

    assertEquals("helloJGWhoamI?XXXXXXXXXXXYThissessionisnotsecure.",
            StringUtils.deleteWhitespace(response.getContentAsString()));
}

From source file:org.apache.struts2.EmbeddedJSPResultTest.java

public void testEmbeddedAbsolutePath() throws Exception {
    //the jsp is inside jsps.jar
    result.setLocation("/dir/all.jsp");
    result.execute(null);/*  w ww  .j a  va 2s .c  o  m*/

    assertEquals("helloJGWhoamI?XXXXXXXXXXXYThissessionisnotsecure.",
            StringUtils.deleteWhitespace(response.getContentAsString()));
}