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

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

Introduction

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

Prototype

public static boolean contains(final CharSequence seq, final CharSequence searchSeq) 

Source Link

Document

Checks if CharSequence contains a search CharSequence, handling null .

Usage

From source file:io.wcm.tooling.commons.contentpackagebuilder.XmlContentBuilder.java

private String getNamespace(String key) {
    if (!StringUtils.contains(key, ":")) {
        return null;
    }/*from   w  w  w . j av  a  2s. c  o  m*/
    String nsPrefix = StringUtils.substringBefore(key, ":");
    return xmlNamespaces.get(nsPrefix);
}

From source file:de.tuberlin.uebb.jbop.access.ClassAccessor.java

/**
 * Return the bytes of the corresponding class.
 * /*  ww w .  j  av a2s  .  c  om*/
 * @param input
 *          the input Object (may be a class-Object)
 * @return the byte[] of the class
 * @throws JBOPClassException
 *           if the Classfile for the given Object cannot be accessed
 *           (e.g. if the class is synthetic)
 */
public static byte[] toBytes(final Object input) throws JBOPClassException {
    if (input == null) {
        throw new JBOPClassException("Nullvalue for input is not allowed.", null);
    }
    Path file;
    Class<?> clazz;
    if (input instanceof Class) {
        clazz = (Class<?>) input;
    } else {
        clazz = input.getClass();
    }
    file = toPath(clazz);
    final String filename = file.toString();
    if (StringUtils.contains(filename, "!")) {
        file = getPathInJar(filename);
    }
    try {
        return Files.readAllBytes(file);
    } catch (final IOException e) {
        throw new JBOPClassException("The content of the Classfile (" + filename + ") couldn't be read.", e);
    }
}

From source file:io.wcm.handler.mediasource.inline.InlineMediaSource.java

/**
 * Detect filename for inline binary./*from  ww  w. ja v  a2 s .  c  o  m*/
 * @param referencedResource Resource that was referenced in media reference and may contain file name property.
 * @param ntFileResource nt:file resource (optional, null if not existent)
 * @param ntResourceResource nt:resource resource
 * @return Detected or virtual filename. Never null.
 */
private String detectFileName(Resource referencedResource, Resource ntFileResource,
        Resource ntResourceResource) {
    // detect file name
    String fileName = null;
    // if referenced resource is not the nt:file node check for <nodename>Name property
    if (ntFileResource != null && !referencedResource.equals(ntFileResource)) {
        fileName = referencedResource.getValueMap().get(ntFileResource.getName() + "Name", String.class);
    }
    // if not nt:file node exists and the referenced resource is not the nt:resource node check for <nodename>Name property
    else if (ntFileResource == null && !referencedResource.equals(ntResourceResource)) {
        fileName = referencedResource.getValueMap().get(ntResourceResource.getName() + "Name", String.class);
    }
    // otherwise use node name of nt:file resource if it exists
    else if (ntFileResource != null) {
        fileName = ntFileResource.getName();
    }
    // make sure filename has an extension, otherwise build virtual file name
    if (!StringUtils.contains(fileName, ".")) {
        fileName = null;
    }

    // if no filename found detect extension from mime type and build virtual filename
    if (StringUtils.isBlank(fileName)) {
        String fileExtension = null;
        if (ntResourceResource != null) {
            String mimeType = ntResourceResource.getValueMap().get(JcrConstants.JCR_MIMETYPE, String.class);
            if (StringUtils.isNotEmpty(mimeType) && mimeTypeService != null) {
                fileExtension = mimeTypeService.getExtension(mimeType);
            }
        }
        if (StringUtils.isEmpty(fileExtension)) {
            fileExtension = "bin";
        }
        fileName = "file." + fileExtension;
    }

    return fileName;
}

From source file:com.mirth.connect.server.ExtensionLoader.java

/**
 * Loads the metadata files (plugin.xml, source.xml, destination.xml) for all extensions of the
 * specified type. If this function fails to parse the metadata file for an extension, it will
 * skip it and continue.//from w ww  . j a  v  a 2  s .co m
 */
private synchronized void loadExtensions() {
    if (!loadedExtensions) {
        try {
            // match all of the file names for the extension
            IOFileFilter nameFileFilter = new NameFileFilter(
                    new String[] { "plugin.xml", "source.xml", "destination.xml" });
            // this is probably not needed, but we dont want to pick up directories,
            // so we AND the two filters
            IOFileFilter andFileFilter = new AndFileFilter(nameFileFilter, FileFilterUtils.fileFileFilter());
            // this is directory where extensions are located
            File extensionPath = new File(getExtensionsPath());
            // do a recursive scan for extension files
            Collection<File> extensionFiles = FileUtils.listFiles(extensionPath, andFileFilter,
                    FileFilterUtils.trueFileFilter());

            for (File extensionFile : extensionFiles) {
                try {
                    MetaData metaData = (MetaData) serializer
                            .deserialize(FileUtils.readFileToString(extensionFile), MetaData.class);

                    if (isExtensionCompatible(metaData)) {
                        if (metaData instanceof ConnectorMetaData) {
                            ConnectorMetaData connectorMetaData = (ConnectorMetaData) metaData;
                            connectorMetaDataMap.put(connectorMetaData.getName(), connectorMetaData);

                            if (StringUtils.contains(connectorMetaData.getProtocol(), ":")) {
                                for (String protocol : connectorMetaData.getProtocol().split(":")) {
                                    connectorProtocolsMap.put(protocol, connectorMetaData);
                                }
                            } else {
                                connectorProtocolsMap.put(connectorMetaData.getProtocol(), connectorMetaData);
                            }
                        } else if (metaData instanceof PluginMetaData) {
                            pluginMetaDataMap.put(metaData.getName(), (PluginMetaData) metaData);
                        }
                    } else {
                        logger.error("Extension \"" + metaData.getName()
                                + "\" is not compatible with this version of Mirth Connect and was not loaded. Please install a compatible version.");
                        invalidMetaDataMap.put(metaData.getName(), metaData);
                    }
                } catch (Exception e) {
                    logger.error("Error reading or parsing extension metadata file: " + extensionFile.getName(),
                            e);
                }
            }
        } catch (Exception e) {
            logger.error("Error loading extension metadata.", e);
        } finally {
            loadedExtensions = true;
        }
    }
}

From source file:com.glaf.base.modules.website.springmvc.UserAuthController.java

/**
 * /*  w w  w.j  a  v a2  s  . co  m*/
 * 
 * @param request
 * @param modelMap
 * @return
 */
@RequestMapping("/login")
public ModelAndView login(HttpServletRequest request, HttpServletResponse response) {
    String ip = RequestUtils.getIPAddress(request);
    /**
     * ????
     */
    if (StringUtils.contains(conf.get("login.allow.ip", "127.0.0.1"), ip)
            || StringUtils.contains(SystemConfig.getString("login.allow.ip", "127.0.0.1"), ip)) {
        String actorId = request.getParameter("x");
        String password = request.getParameter("y");
        HttpSession session = request.getSession(true);
        java.util.Random random = new java.util.Random();
        String rand = Math.abs(random.nextInt(999999)) + com.glaf.core.util.UUID32.getUUID()
                + Math.abs(random.nextInt(999999));
        session = request.getSession(true);
        if (session != null) {
            session.setAttribute("x_y", rand);
        }
        String url = request.getContextPath() + "/mx/login/doLogin?x=" + actorId + "&y=" + rand + password;
        try {
            response.sendRedirect(url);
            return null;
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    return new ModelAndView("/modules/login");
}

From source file:com.jeans.iservlet.service.portal.impl.FtsServiceImpl.java

@Override
public Map<String, List<FtsResultItem>> search(String catalog, String keyword, User user) {
    Map<String, List<FtsResultItem>> results = new LinkedHashMap<String, List<FtsResultItem>>();
    if (StringUtils.contains(catalog, "S")) {
        // TODO ???
    }/*from   w ww . jav  a 2 s . c om*/
    if (StringUtils.contains(catalog, "A")) {
        // ??
        List<Asset> assets = assetSearch(keyword, user.getCompany().getId());
        if (null != assets && assets.size() > 0) {
            // ?
            List<FtsResultItem> items = new ArrayList<FtsResultItem>();
            for (Asset asset : assets) {
                FtsResultItem item = new FtsResultItem();
                item.setId(asset.getId());
                item.setTitle(asset.getFullName());
                if (asset instanceof Hardware) {
                    item.setType(FTS_ASSET_HARDWARE);
                } else {
                    item.setType(FTS_ASSET_SOFTWARE);
                }
                items.add(item);
            }
            results.put("?", items);
        }
    }
    if (StringUtils.contains(catalog, "W")) {
        // ???ITSystem, Post
        List<FtsResultItem> items = new ArrayList<FtsResultItem>();
        List<ITSystem> systems = systemSearch(keyword);
        Company company = user.getCompany();
        for (ITSystem system : systems) {
            if (system.getOwner().equals(company)) {
                items.add(wrapSystem(system));
                continue;
            }
            boolean branched = false;
            Set<SystemBranch> branches = system.getBranches();
            for (SystemBranch branch : branches) {
                if (branch.getCompany().equals(company)) {
                    branched = true;
                    items.add(wrapSystem(system));
                    break;
                }
            }
            if (branched) {
                continue;
            }
            if (system.getScope() == SystemScope.Custom) {
                if (system.getCompaniesInScope().contains(company)) {
                    items.add(wrapSystem(system));
                    continue;
                }
            } else {
                if (company.getLevel() != Company.PROVINCE) {
                    if (system.getOwner().equals(company.getSuperior())
                            && system.getScope() != SystemScope.Private) {
                        items.add(wrapSystem(system));
                        continue;
                    }
                    if (company.getLevel() == Company.BRANCH
                            && system.getOwner().equals(company.getSuperior().getSuperior())
                            && (system.getScope() == SystemScope.PrivateAndInferiors
                                    || system.getScope() == SystemScope.Inferiors)) {
                        items.add(wrapSystem(system));
                        continue;
                    }
                }
            }
        }
        List<Post> posts = wikiSearch(keyword);
        Set<Page> pages = new HashSet<Page>();
        for (Post post : posts) {
            if (null == post.getPage()) {
                Page p = pageDao.getById(Page.class, post.getId());
                if (p.getWiki().getCompanies().contains(company) || (company.getLevel() == Company.BRANCH
                        && p.getWiki().getCompanies().contains(company.getSuperior()))) {
                    System.out.println("id=" + p.getId());
                    pages.add(p);
                }
            } else {
                if (post.getPage().getWiki().getCompanies().contains(company)
                        || (company.getLevel() == Company.BRANCH
                                && post.getPage().getWiki().getCompanies().contains(company.getSuperior()))) {
                    pages.add(post.getPage());
                }
            }
        }
        for (Page page : pages) {
            items.add(wrapPage(page));
        }
        if (!items.isEmpty()) {
            results.put("?", items);
        }
    }
    if (StringUtils.contains(catalog, "P")) {
        // ??
        List<Project> projects = projectSearch(keyword);
        if (null != projects && projects.size() > 0) {
            List<FtsResultItem> items = new ArrayList<FtsResultItem>();
            for (Project project : projects) {
                if (project.getProjectTeam().getStaff().contains(user.getEmployee())) {
                    FtsResultItem item = new FtsResultItem();
                    item.setId(project.getId());
                    item.setTitle(project.getName());
                    item.setType(FTS_PROJECT);
                    items.add(item);
                }
            }
            results.put("", items);
        }
    }
    if (StringUtils.contains(catalog, "M")) {
        // TODO ???
    }
    if (StringUtils.contains(catalog, "D")) {
        // ??
        List<CloudUnit> units = cloudSearch(keyword);
        if (null != units && units.size() > 0) {
            List<FtsResultItem> items = new ArrayList<FtsResultItem>();
            for (CloudUnit unit : units) {
                // ?
                FtsResultItem item = new FtsResultItem();
                item.setId(unit.getId());
                if (unit instanceof CloudFile) {
                    item.setTitle(unit.getOwner().getName() + " - " + ((CloudFile) unit).getVersionFilename());
                    item.setType(FTS_CLOUD_FILE);
                } else {
                    item.setTitle(unit.getOwner().getName() + " - " + unit.getName());
                    item.setType(FTS_CLOUD_LIST);
                }
                items.add(item);
            }
            results.put("", items);
        }
    }
    return results;
}

From source file:com.cognifide.qa.bb.aem.touch.pageobjects.pages.AuthorPage.java

private boolean isLoadedCondition() {
    return conditions.isConditionMet(not(ignored -> StringUtils
            .contains(authoringOverlay.getAttribute(HtmlTags.Attributes.CLASS), IS_HIDDEN)));
}

From source file:com.dchq.docker.volume.driver.controller.DockerVolumeDriverControllerIntegrationTests.java

@Test
public void listTest() {

    String name = RandomStringUtils.randomAlphabetic(6);
    CreateRequest request = new CreateRequest();
    request.setName(name);//from ww w . jav a  2  s.co  m

    String response = restTemplate.postForObject(baseUrl + DockerVolumeDriverController.CREATE, request,
            String.class);
    Assert.assertNotNull(response);
    Assert.assertEquals(response, "{\"Err\":\"\"}");

    String listResponse = restTemplate.postForObject(baseUrl + DockerVolumeDriverController.LIST, null,
            String.class);
    Assert.assertNotNull(listResponse);
    Assert.assertTrue(StringUtils.contains(listResponse, "\"Err\":\"\""));
    logger.info("Response [{}]", listResponse);
}

From source file:io.wcm.handler.url.impl.UrlHandlerImpl.java

String buildUrl(String path, String selector, String extension, String suffix) { //NOPMD
    if (StringUtils.isBlank(path)) {
        return null;
    }/*from  w  ww  .j a v  a  2s. co  m*/

    // Extension url part
    StringBuilder extensionPart = new StringBuilder();
    if (StringUtils.isNotBlank(extension)) {
        extensionPart.append('.').append(extension);
    }

    // Selector url part
    StringBuilder selectorPart = new StringBuilder();
    if (StringUtils.isNotBlank(selector)) {
        // prepend delimiter to selector if required
        if (!StringUtils.startsWith(selector, ".")) {
            selectorPart.append('.');
        }
        selectorPart.append(selector);
    }

    // Suffix part
    StringBuilder suffixPart = new StringBuilder();
    if (StringUtils.isNotBlank(suffix)) {
        // prepend delimiter to suffix if required and add extension
        if (!StringUtils.startsWith(suffix, "/")) {
            suffixPart = suffixPart.append("/");
        }
        suffixPart.append(suffix);

        // if suffix does not contain a file extension add main file extension
        if (!StringUtils.contains(suffix, ".")) {
            suffixPart.append(extensionPart);
        }

        // add a ".suffix" selector to avoid overlapping of filenames between suffixed and non-suffixed versions of the same page in the dispatcher cache
        selectorPart.append('.').append(UrlHandler.SELECTOR_SUFFIX);
    }

    // build externalized url
    return path + selectorPart.toString() + extensionPart.toString() + suffixPart.toString();
}

From source file:io.wcm.devops.conga.generator.GeneratorTest.java

private void assertContains(File file, String contains, String charset) {
    try {//from w w w .j  av a 2  s.co  m
        String fileContent = FileUtils.readFileToString(file, charset);
        assertTrue("File " + FileUtil.getCanonicalPath(file) + " does not contain: " + contains,
                StringUtils.contains(fileContent, contains));
    } catch (IOException ex) {
        throw new RuntimeException("Unable to read contents from: " + FileUtil.getCanonicalPath(file), ex);
    }
}