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

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

Introduction

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

Prototype

public static boolean startsWith(final CharSequence str, final CharSequence prefix) 

Source Link

Document

Check if a CharSequence starts with a specified prefix.

null s are handled without exceptions.

Usage

From source file:com.nridge.connector.common.con_com.transform.TFieldDelete.java

private void load(String aPathFileName) throws IOException {
    List<String> lineList;
    Logger appLogger = mAppMgr.getLogger(this, "load");

    appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER);

    try (FileReader fileReader = new FileReader(aPathFileName)) {
        lineList = IOUtils.readLines(fileReader);
    }/*from www  . j  ava2 s  . c  om*/

    for (String patternString : lineList) {
        if (!StringUtils.startsWith(patternString, "#"))
            mPatternList.add(patternString);
    }

    appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART);
}

From source file:ch.cyberduck.core.googledrive.AbstractDriveListService.java

protected PathAttributes toAttributes(final File f) {
    final PathAttributes attributes = new PathAttributes();
    if (null != f.getExplicitlyTrashed()) {
        if (f.getExplicitlyTrashed()) {
            // Mark as hidden
            attributes.setDuplicate(true);
        }/*from w  ww.  jav a 2 s.  c  o m*/
    }
    if (null != f.getSize()) {
        if (!DRIVE_FOLDER.equals(f.getMimeType())
                && !StringUtils.startsWith(f.getMimeType(), GOOGLE_APPS_PREFIX)) {
            attributes.setSize(f.getSize());
        }
    }
    attributes.setVersionId(f.getId());
    if (f.getModifiedTime() != null) {
        attributes.setModificationDate(f.getModifiedTime().getValue());
    }
    if (f.getCreatedTime() != null) {
        attributes.setCreationDate(f.getCreatedTime().getValue());
    }
    attributes.setChecksum(Checksum.parse(f.getMd5Checksum()));
    if (StringUtils.isNotBlank(f.getWebViewLink())) {
        attributes.setLink(new DescriptiveUrl(URI.create(f.getWebViewLink()), DescriptiveUrl.Type.http,
                MessageFormat.format(LocaleFactory.localizedString("{0} URL"), "HTTP")));
        if (!DRIVE_FOLDER.equals(f.getMimeType())
                && StringUtils.startsWith(f.getMimeType(), GOOGLE_APPS_PREFIX)) {
            attributes.setSize(
                    UrlFileWriterFactory.get().write(new DescriptiveUrl(URI.create(f.getWebViewLink())))
                            .getBytes(Charset.defaultCharset()).length);
        }
    }
    return attributes;
}

From source file:com.adguard.filter.rules.ContentType.java

/**
 * Checks if response content type has one of the specified prefixes
 *
 * @param responseContentType Response content type
 * @param contentTypes        Content types to check
 * @return true if any of the prefixes match
 *///w  w  w. j a v  a  2s  .  c  om
private static boolean isContentType(String responseContentType, String... contentTypes) {

    for (String contentType : contentTypes) {
        if (StringUtils.startsWith(responseContentType, contentType)) {
            return true;
        }
    }

    return false;
}

From source file:io.wcm.wcm.parsys.componentinfo.impl.OsgiParsysConfigProvider.java

@Activate
private void activate(ComponentContext componentContext) {
    @SuppressWarnings("unchecked")
    final Dictionary<String, Object> props = componentContext.getProperties();

    // read config properties
    this.pageComponentPath = PropertiesUtil.toString(props.get(PROPERTY_PAGE_COMPONENT_PATH), null);
    String path = PropertiesUtil.toString(props.get(PROPERTY_PATH), null);
    String patternString = PropertiesUtil.toString(props.get(PROPERTY_PATH_PATTERN), null);
    String[] allowedChildrenArray = PropertiesUtil.toStringArray(props.get(PROPERTY_ALLOWED_CHILDREN), null);
    String[] deniedChildrenArray = PropertiesUtil.toStringArray(props.get(PROPERTY_DENIED_CHILDREN), null);
    String[] allowedParentsArray = PropertiesUtil.toStringArray(props.get(PROPERTY_ALLOWED_PARENTS), null);
    this.parentAncestorLevel = PropertiesUtil.toInteger(props.get(PROPERTY_PARENT_ANCESTOR_LEVEL),
            DEFAULT_PARENT_ANCESTOR_LEVEL);

    // set path pattern if any
    if (StringUtils.isNotEmpty(patternString)) {
        this.pathPattern = Pattern.compile(patternString);
    }//from   ww w . ja  va2s. c  o  m
    // alternative: use path to build a pattern
    else if (StringUtils.isNotBlank(path)) {
        // path may also contain a simple node name
        if (!StringUtils.startsWith(path, JcrConstants.JCR_CONTENT + "/")) {
            path = JcrConstants.JCR_CONTENT + "/" + path; //NOPMD
        }
        this.pathPattern = Pattern.compile("^" + Pattern.quote(path) + "$");
    }

    // set allowed children
    Set<String> allowedChildrenSet = new HashSet<>();
    if (allowedChildrenArray != null) {
        for (String resourceType : allowedChildrenArray) {
            if (StringUtils.isNotBlank(resourceType)) {
                allowedChildrenSet.add(resourceType);
            }
        }
    }
    this.allowedChildren = ImmutableSet.copyOf(allowedChildrenSet);

    // set denied children
    Set<String> deniedChildrenSet = new HashSet<>();
    if (deniedChildrenArray != null) {
        for (String resourceType : deniedChildrenArray) {
            if (StringUtils.isNotBlank(resourceType)) {
                deniedChildrenSet.add(resourceType);
            }
        }
    }
    this.deniedChildren = ImmutableSet.copyOf(deniedChildrenSet);

    // set allowed parents
    Set<String> allowedParentsSet = new HashSet<>();
    if (allowedParentsArray != null) {
        for (String resourceType : allowedParentsArray) {
            if (StringUtils.isNotBlank(resourceType)) {
                allowedParentsSet.add(resourceType);
            }
        }
    }
    this.allowedParents = ImmutableSet.copyOf(allowedParentsSet);

    if (log.isDebugEnabled()) {
        log.debug(
                getClass().getSimpleName() + ": " + PROPERTY_PAGE_COMPONENT_PATH + "={}, " + PROPERTY_PATH
                        + "={}, " + PROPERTY_PATH_PATTERN + "={}, " + PROPERTY_ALLOWED_CHILDREN + "={}, "
                        + PROPERTY_DENIED_CHILDREN + "={}, " + PROPERTY_ALLOWED_PARENTS + "={}, "
                        + PROPERTY_PARENT_ANCESTOR_LEVEL + "={}",
                new Object[] { this.pageComponentPath, path, this.pathPattern, this.allowedChildren,
                        this.deniedChildren, this.allowedParents, this.parentAncestorLevel });
    }

    // validation messages
    if (StringUtils.isBlank(this.pageComponentPath)) {
        log.warn(
                PROPERTY_PAGE_COMPONENT_PATH + " cannot be null or empty. This configuration will be ignored.");
    }
    if (this.pathPattern == null) {
        log.warn("Path pattern cannot be null. Please set the property " + PROPERTY_PATH_PATTERN + " or "
                + PROPERTY_PATH);
    }
}

From source file:io.treefarm.plugins.haxe.components.NativeBootstrap.java

private void initializePrograms(MavenProject project, File pluginHome, List<Dependency> pluginDependencies)
        throws Exception {
    Map<String, Artifact> artifactsMap = new HashMap<String, Artifact>();
    Set<String> path = new HashSet<String>();
    File outputDirectory = getOutputDirectory();

    // Add java to PATH
    path.add(new File(System.getProperty("java.home"), "bin").getAbsolutePath());

    for (Dependency dependency : pluginDependencies) {
        String artifactKey = dependency.getGroupId() + ":" + dependency.getArtifactId();

        if (artifactKey.equals(HAXE_COMPILER_KEY) || artifactKey.equals(NEKO_KEY) || artifactKey.equals(NME_KEY)
                || artifactKey.equals(HXCPP_KEY) || StringUtils.startsWith(artifactKey, OPENFL_KEY)) {
            /*    String classifier = OSClassifiers.getDefaultClassifier();
                String packaging = PackageTypes.getSDKArtifactPackaging(classifier);
                if (artifactKey.equals(OPENFL_KEY)) classifier = null;
                    //from   w  ww.j av  a 2s  .  c  o  m
                Artifact artifact = repositorySystem.createArtifactWithClassifier(
                dependency.getGroupId(), 
                dependency.getArtifactId(), 
                dependency.getVersion(),
                packaging,
                classifier
                );
                    
                Artifact resolvedArtifact = resolveArtifact(artifact, true);
                boolean resolvedLocally = (resolvedArtifact != null);
                if (!resolvedLocally) {
            resolvedArtifact = resolveArtifact(artifact, false);
                }
                if (resolvedArtifact != null) {
            resolvedArtifact.setVersion(artifact.getVersion());
            artifactsMap.put(artifactKey, resolvedArtifact);
                }*/

            Artifact artifact = repositorySystem.createArtifactWithClassifier(dependency.getGroupId(),
                    dependency.getArtifactId(), dependency.getVersion(), dependency.getType(),
                    dependency.getClassifier());
            Artifact resolvedArtifact = resolveArtifact(artifact, false);
            if (resolvedArtifact != null) {
                artifactsMap.put(artifactKey, resolvedArtifact);
            }
        }
    }

    if (artifactsMap.get(NEKO_KEY) == null) {
        throw new Exception(String.format(
                "Neko Runtime dependency (%s) not found in haxebuildr-maven-plugin dependencies", NEKO_KEY));
    }

    if (artifactsMap.get(HAXE_COMPILER_KEY) == null) {
        throw new Exception(
                String.format("Haxe Compiler dependency (%s) not found in haxebuildr-maven-plugin dependencies",
                        HAXE_COMPILER_KEY));
    }

    neko.initialize(artifactsMap.get(NEKO_KEY), outputDirectory, pluginHome, path);
    haxe.initialize(artifactsMap.get(HAXE_COMPILER_KEY), outputDirectory, pluginHome, path);
    haxelib.initialize(artifactsMap.get(HAXE_COMPILER_KEY), outputDirectory, pluginHome, path);
    HaxelibHelper.setHaxelib(haxelib);

    Iterator<Artifact> iterator;
    Set<Artifact> projectDependencies = project.getDependencyArtifacts();
    if (projectDependencies != null) {
        iterator = projectDependencies.iterator();
        while (iterator.hasNext()) {
            Artifact a = iterator.next();

            if (a.getType().equals(HaxeFileExtensions.HAXELIB)) {
                File haxelibDirectory = HaxelibHelper.getHaxelibDirectoryForArtifact(a.getArtifactId(),
                        a.getVersion());

                if (haxelibDirectory != null && haxelibDirectory.exists()) {
                    iterator.remove();
                }
            } else {
                if (a.getGroupId().equals(HaxelibHelper.HAXELIB_GROUP_ID)) {
                    /*String packaging = PackageTypes.getSDKArtifactPackaging(OSClassifiers.getDefaultClassifier());
                    Artifact artifact = repositorySystem.createArtifactWithClassifier(
                    a.getGroupId(), a.getArtifactId(), a.getVersion(),
                    packaging, null
                    );
                    Artifact resolvedArtifact = resolveArtifact(artifact, true);
                    boolean resolvedLocally = (resolvedArtifact != null);
                    if (!resolvedLocally) {
                    resolvedArtifact = resolveArtifact(artifact, false);
                    }
                    if (resolvedArtifact != null) {
                    HaxelibHelper.injectPomHaxelib(resolvedArtifact, outputDirectory, logger, resolvedLocally);
                    iterator.remove();
                    }*/
                    /*Artifact resolvedArtifact = resolveArtifact(a, false);
                    if (resolvedArtifact != null) {
                    HaxelibHelper.injectPomHaxelib(a, outputDirectory, logger);
                    }*/

                    Artifact artifact = repositorySystem.createArtifactWithClassifier(a.getGroupId(),
                            a.getArtifactId(), a.getVersion(), a.getType(), null);

                    Artifact resolvedArtifact = resolveArtifact(artifact, false);
                    if (resolvedArtifact != null && resolvedArtifact.getFile() != null) {
                        HaxelibHelper.injectPomHaxelib(a.getArtifactId(), a.getVersion(), a.getType(),
                                a.getFile(), logger);
                    }
                }
            }

            if (a.getArtifactId().equals(MUNIT_ID)) {
                munit.initialize(a, outputDirectory, pluginHome, path);
            }

            if (a.getArtifactId().equals(CHXDOC_ID)) {
                chxdoc.initialize(a, outputDirectory, pluginHome, path);
            }
        }
    }

    Iterator<String> mapIterator = artifactsMap.keySet().iterator();
    while (mapIterator.hasNext()) {
        String key = mapIterator.next();
        if (key.equals(NME_KEY) || StringUtils.startsWith(key, OPENFL_KEY)) {
            if (projectDependencies != null) {
                iterator = projectDependencies.iterator();
                while (iterator.hasNext()) {
                    Artifact a = iterator.next();
                    if (a.getType().equals(HaxeFileExtensions.HAXELIB)
                            && StringUtils.startsWith(a.getArtifactId(), OPENFL_ARTIFACT_ID_PREFIX)
                            && (a.getVersion() == null || a.getVersion().equals("")
                                    || a.getVersion().equals(artifactsMap.get(key).getVersion()))) {
                        iterator.remove();
                    }
                }
            }
            // inject all openfl accessory libs
            Artifact a = artifactsMap.get(key);
            Artifact resolvedArtifact = resolveArtifact(a, false);
            if (resolvedArtifact != null && resolvedArtifact.getFile() != null) {
                HaxelibHelper.injectPomHaxelib(a.getArtifactId(), a.getVersion(), a.getType(), a.getFile(),
                        logger);
            }
        }
    }

    if (artifactsMap.get(OPENFL_KEY) != null) {
        File nmeDirectory = null;
        Artifact nmeArtifact = artifactsMap.get(NME_KEY);
        if (nmeArtifact != null) {
            nmeDirectory = HaxelibHelper.getHaxelibDirectoryForArtifact(nmeArtifact.getArtifactId(),
                    nmeArtifact.getVersion());
        }

        File openflNativeDirectory = null;
        Artifact openflNativeArtifact = artifactsMap
                .get(OPENFL_GROUP + OPENFL_ARTIFACT_ID_PREFIX + OPENFL_NATIVE_SUFFIX);
        if (openflNativeArtifact != null) {
            openflNativeDirectory = HaxelibHelper.getHaxelibDirectoryForArtifact(
                    openflNativeArtifact.getArtifactId(), openflNativeArtifact.getVersion());
        }

        openfl.initialize(artifactsMap.get(OPENFL_KEY), outputDirectory, pluginHome, path, nmeDirectory,
                openflNativeDirectory);
    }

    if (artifactsMap.get(HXCPP_KEY) != null) {
        hxcpp.initialize(artifactsMap.get(HXCPP_KEY), outputDirectory, pluginHome, path);
    }
}

From source file:io.wcm.devops.conga.tooling.maven.plugin.GenerateMojo.java

/**
 * Checks if the JAR file of the given dependency has a CONGA-INF/ directory.
 * @param dependency Dependency//  ww w . j a va2  s.c  o m
 * @return true if configuration definitions found
 */
private boolean hasCongaDefinitions(Dependency dependency) {
    if (!StringUtils.equals(dependency.getType(), "jar")) {
        return false;
    }
    String fileInfo = dependency.toString();
    try {
        Artifact artifact = getArtifact(dependency);
        fileInfo = FileUtil.getCanonicalPath(artifact.getFile());
        try (ZipFile zipFile = new ZipFile(artifact.getFile())) {
            Enumeration<? extends ZipEntry> entries = zipFile.entries();
            while (entries.hasMoreElements()) {
                ZipEntry entry = entries.nextElement();
                if (StringUtils.startsWith(entry.getName(), BuildConstants.CLASSPATH_PREFIX)) {
                    return true;
                }
            }
        }
    } catch (IOException ex) {
        throw new GeneratorException("Unable to read from JAR file: " + fileInfo, ex);
    }
    return false;
}

From source file:com.nridge.connector.common.con_com.crawl.CrawlFollow.java

/**
 * Parses a file identified by the path/file name parameter
 * and loads it into an internally managed follow URI list.
 *
 * @param aPathFileName Absolute file name (e.g. 'crawl_follow.txt').
 *
 * @throws IOException I/O related exception.
 *///from w w  w.j ava 2  s. co  m
public void load(String aPathFileName) throws IOException {
    List<String> lineList;
    Logger appLogger = mAppMgr.getLogger(this, "load");

    appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER);

    try (FileReader fileReader = new FileReader(aPathFileName)) {
        lineList = IOUtils.readLines(fileReader);
    }

    for (String followString : lineList) {
        if (!StringUtils.startsWith(followString, "#"))
            mFollowList.add(followString);
    }

    appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART);
}

From source file:fi.foyt.fni.view.users.UsersProfileBackingBean.java

private String prepareContactField(String value) {
    if (StringUtils.isNotBlank(value)) {
        if ((!StringUtils.startsWith(value, "http://")) && (!StringUtils.startsWith(value, "https://"))) {
            return "http://" + value;
        }/*from  ww w. j  a v  a2 s  .com*/
    }

    return value;
}

From source file:eu.openanalytics.rsb.EmailDepositITCase.java

private BodyPart getMailBodyPart(final Multipart parts, final String contentType) throws MessagingException {
    for (int i = 0; i < parts.getCount(); i++) {
        final BodyPart part = parts.getBodyPart(i);
        if (StringUtils.startsWith(part.getContentType(), contentType)) {
            return part;
        }//from ww w.j av  a2 s.  c  o  m
    }
    throw new IllegalStateException("No part of type " + contentType + " found");
}

From source file:com.erudika.scoold.utils.LanguageUtils.java

/**
 * Returns a non-null locale for a given language code.
 * @param langCode the 2-letter language code
 * @return a locale. default is English//from  w w w  .  j a  va2 s .  c o  m
 */
public Locale getProperLocale(String langCode) {
    if (StringUtils.startsWith(langCode, "zh")) {
        if ("zh_tw".equalsIgnoreCase(langCode)) {
            return Locale.TRADITIONAL_CHINESE;
        } else {
            return Locale.SIMPLIFIED_CHINESE;
        }
    }
    String lang = StringUtils.substring(langCode, 0, 2);
    lang = (StringUtils.isBlank(lang) || !ALL_LOCALES.containsKey(lang)) ? "en" : lang.trim().toLowerCase();
    return ALL_LOCALES.get(lang);
}