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

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

Introduction

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

Prototype

public static boolean startsWith(String str, String prefix) 

Source Link

Document

Check if a String starts with a specified prefix.

Usage

From source file:com.ariht.maven.plugins.config.DirectoryReader.java

private boolean isFileToIgnore(File file) {
    for (File f : filesToIgnore) {
        if (StringUtils.startsWith(file.getAbsolutePath(), f.getAbsolutePath())) {
            log.debug(// w w  w  . ja v  a  2  s .c  o m
                    "Matched prefix so will ignore: \n" + file.getAbsolutePath() + "\n" + f.getAbsolutePath());
            return true;
        } else {
            log.debug("Not same: \n" + file.getAbsolutePath() + "\n" + f.getAbsolutePath());
        }
    }
    return false;
}

From source file:de.dev.eth0.retweeter.Retweeter.java

/**
 * Performs the retweet-action and returns the number of tweets found with the configured hashtag
 *
 * @return number of retweeted tweets/*from ww  w  .  j a va  2s . com*/
 * @throws TwitterException
 */
public int retweet() throws TwitterException {
    if (!getConfig().isRetweeterConfigValid()) {
        return Integer.MIN_VALUE;
    }
    Twitter twitter = getTwitter();
    String search = buildSearchString();
    Query query = new Query(search);
    QueryResult result = twitter.search(query);

    List<Status> lastretweets = twitter.getRetweetedByMe();
    int count = 0;
    for (Tweet tweet : result.getTweets()) {
        // ignore retweets and check if the hashtag is really in the tweet's text
        if (!StringUtils.startsWith(tweet.getText(), "RT @")
                && StringUtils.contains(tweet.getText(), getConfig().getRetweeterConfig().getHashtag())
                && !ALREADY_RETWEETED.contains(tweet.getId())) {
            boolean retweeted = false;
            for (Status retweet : lastretweets) {
                if (tweet.getId() == retweet.getRetweetedStatus().getId()) {
                    retweeted = true;
                    break;
                }
            }
            if (!retweeted) {
                // try to retweet, might fail
                logger.debug("found new tweet to retweet: {}", tweet.toString());
                try {
                    twitter.retweetStatus(tweet.getId());
                    count++;
                } catch (TwitterException te) {
                    logger.debug("retweet failed", te);
                } finally {
                    ALREADY_RETWEETED.add(tweet.getId());
                }
            }
        }
    }
    return count;
}

From source file:com.github.dbourdette.glass.web.interceptor.AddToModelInterceptor.java

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    if (modelAndView == null) {
        return;/*  w w w.j a  va2 s . c  o m*/
    }

    if (StringUtils.startsWith(modelAndView.getViewName(), "redirect:")) {
        return;
    }

    ModelMap model = modelAndView.getModelMap();

    model.addAttribute("standby", quartzScheduler.isInStandbyMode());
    model.addAttribute("root", configuration.getRoot());
    model.addAttribute("current", URLEncoder.encode(request.getRequestURI(), "UTF-8"));
    model.addAttribute("utils", utilsTool);
    model.addAttribute("format", formatTool);
    model.addAttribute("version", version);
}

From source file:hydrograph.ui.datastructure.property.Schema.java

/**
 * Sets the external schema path./*from w  w w.j av a2s  . c  o m*/
 * 
 * @param externalSchemaPath
 *            the new external schema path
 */
public void setExternalSchemaPath(String externalSchemaPath) {
    if (StringUtils.startsWith(externalSchemaPath, RELATIVE_PATH_PREFIX))
        externalSchemaPath = StringUtils.replace(externalSchemaPath, RELATIVE_PATH_PREFIX, "");
    this.externalSchemaPath = externalSchemaPath;
}

From source file:com.adobe.acs.commons.workflow.synthetic.impl.granite.SyntheticWorkflowModelImpl.java

public SyntheticWorkflowModelImpl(WorkflowSession workflowSession, String modelId,
        boolean ignoredIncompatibleTypes) throws WorkflowException {

    if (!StringUtils.startsWith(modelId, WORKFLOW_MODEL_PATH_PREFIX)) {
        modelId = WORKFLOW_MODEL_PATH_PREFIX + modelId;
    }//from   w w  w . ja va 2  s  .co m

    if (!StringUtils.endsWith(modelId, WORKFLOW_MODEL_PATH_SUFFIX)) {
        modelId = modelId + WORKFLOW_MODEL_PATH_SUFFIX;
    }

    final WorkflowModel model = workflowSession.getModel(modelId);

    log.debug("Located Workflow Model [ {} ] with modelId [ {} ]", model.getTitle(), modelId);

    final List<WorkflowNode> nodes = model.getNodes();

    for (final WorkflowNode node : nodes) {
        if (!ignoredIncompatibleTypes && !this.isValidType(node)) {
            // Only Process Steps are allowed
            throw new SyntheticWorkflowModelException(
                    node.getId() + " is of incompatible type " + node.getType());
        } else if (node.getTransitions().size() > 1) {
            throw new SyntheticWorkflowModelException(node.getId()
                    + " has unsupported decision based execution (more than 1 transitions is not allowed)");
        }

        // No issues with Workflow Model; Collect the Process type
        log.debug("Workflow node title [ {} ]", node.getTitle());

        if (this.isProcessType(node)) {
            final String processName = node.getMetaDataMap().get("PROCESS", "");

            if (StringUtils.isNotBlank(processName)) {
                log.debug("Adding Workflow Process [ {} ] to Synthetic Workflow", processName);
                syntheticWorkflowModel.put(processName, node.getMetaDataMap());
            }
        }
    }
}

From source file:it.openutils.mgnlaws.magnolia.init.ClasspathBindableRepository.java

@Override
protected JackrabbitRepository createRepository() throws RepositoryException {
    Reference reference = this.getReference();
    String configFilePath = reference.get(CONFIGFILEPATH_ADDRTYPE).getContent().toString();
    if (StringUtils.startsWith(configFilePath, ClasspathPropertiesInitializer.CLASSPATH_PREFIX)) {
        InputStream resource = getClass().getResourceAsStream(
                StringUtils.substringAfter(configFilePath, ClasspathPropertiesInitializer.CLASSPATH_PREFIX));
        if (resource != null) {
            RepositoryConfig config = RepositoryConfig.create(resource,
                    reference.get(REPHOMEDIR_ADDRTYPE).getContent().toString());
            return RepositoryImpl.create(config);
        }/*w ww  .j  av  a2s.  c  o  m*/
    }
    return super.createRepository();
}

From source file:io.wcm.tooling.netbeans.sightly.completion.classLookup.ClassLookupResolver.java

/**
 * returns a list with all classes matchting the given filter
 *///from   w w w.  j  a  va 2 s . c om
public List<CompletionItem> resolve(String filter, int startOffset, int caretOffset) {
    final Set<ElementHandle<TypeElement>> result = classpath.getClassIndex().getDeclaredTypes("",
            ClassIndex.NameKind.PREFIX, EnumSet.of(ClassIndex.SearchScope.SOURCE));
    List<CompletionItem> ret = new ArrayList<>();

    for (ElementHandle<TypeElement> te : result) {
        if (te.getKind().isClass()) {
            String binaryName = te.getBinaryName();
            if (!StringUtils.equals(binaryName, "") && StringUtils.startsWith(binaryName, filter)) {
                ret.add(new BasicCompletionItem(te.getBinaryName(), false, startOffset, caretOffset));
            }
        }
    }
    return ret;
}

From source file:com.adobe.acs.commons.workflow.bulk.execution.impl.ConfigResourceVisitor.java

@Override
public final void accept(final Resource resource) {
    // Only accept the Root folder and cq:Page and cq:PageContent nodes; All other structures are uninteresting
    // to this functionality and may be very large
    if (StringUtils.startsWith(resource.getPath(), BULK_WORKFLOW_MANAGER_PAGE_FOLDER_PATH)) {
        final ValueMap properties = resource.adaptTo(ValueMap.class);
        final String primaryType = properties.get(JcrConstants.JCR_PRIMARYTYPE, String.class);

        if (BULK_WORKFLOW_MANAGER_PAGE_FOLDER_PATH.equals(resource.getPath())
                || ArrayUtils.contains(ACCEPTED_PRIMARY_TYPES, primaryType)) {
            super.accept(resource);
        }//from   www  .  j  a  v  a 2s.  c  o  m
    }
}

From source file:eionet.meta.filters.DDCORSFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
        throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) resp;

    HttpServletRequest request = (HttpServletRequest) req;
    String requestUrl = request.getRequestURL().toString();

    // filter only if request ends with /json
    int lastIndexOfSlash = StringUtils.lastIndexOf(requestUrl, "/");
    String subString = StringUtils.substring(requestUrl, lastIndexOfSlash);
    if (StringUtils.startsWith(subString, "/json")) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
        response.setHeader("Access-Control-Max-Age", "3600");
        response.setHeader("Access-Control-Allow-Headers", "x-requested-with");
    }/*from   ww w  .ja v a  2s.c om*/

    chain.doFilter(req, resp);
}

From source file:hydrograph.ui.validators.impl.IntegerOrParameterValidationRule.java

@Override
public boolean validate(Object object, String propertyName, Map<String, List<FixedWidthGridRow>> inputSchemaMap,
        boolean isJobImported) {
    String value = (String) object;
    if (StringUtils.isNotBlank(value)) {
        Matcher matcher = Pattern.compile("[\\d]*").matcher(value);
        if ((matcher.matches()) || ((StringUtils.startsWith(value, "@{") && StringUtils.endsWith(value, "}"))
                && !StringUtils.contains(value, "@{}"))) {
            return true;
        }/*w  w w  .  ja  va2s. c o  m*/
        errorMessage = propertyName + " is mandatory";
    }
    errorMessage = propertyName + " is not integer value or valid parameter";
    return false;
}