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

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

Introduction

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

Prototype

public static boolean startsWithAny(String string, String[] searchStrings) 

Source Link

Document

Check if a String starts with any of an array of specified strings.

Usage

From source file:com.censoredsoftware.library.util.StringUtil2.java

/**
 * Returns true if the <code>string</code> starts with a vowel.
 *
 * @param string the string to check.// w  w  w .j  a  va  2s  .c  o m
 */
public static boolean beginsWithVowel(String string) {
    String[] vowels = { "a", "e", "i", "o", "u" };
    return StringUtils.startsWithAny(string.toLowerCase(), vowels);
}

From source file:com.egt.core.db.util.DBUtils.java

/**
 * Busca el nombre del constraint en el mensaje que envia el RDBMS cuando se produce un conflicto
 *
 * @param message Cadena correspondiente al mensaje que envia el RDBMS
 * @param status Entero correspondiente al tipo de conflicto (cualquiera de las constantes ROW_CONFLICT de
 * SyncResolver)/*from  w ww. jav  a 2  s  .  c  o  m*/
 * @return Si se consigue, el nombre del constraint; de lo contratio retorna null
 */
public static String getConstraintMessageKey(String message, int status) {
    String trimmed = StringUtils.trimToNull(message);
    if (trimmed != null) {
        String[] tokens = StringUtils.split(trimmed, SEPARADORES);
        if (tokens != null && tokens.length > 0) {
            String key;
            for (int i = 0; i < tokens.length; i++) {
                key = tokens[i].toLowerCase();
                if (key.endsWith(SUFIJO) && StringUtils.startsWithAny(key, PREFIJOS)) {
                    if (status == 1 && key.startsWith("fk_")) {
                        key += "_" + status;
                    }
                    return "<" + key + ">";
                }
            }
        }
    }
    return null;
}

From source file:edu.ku.kuali.kra.award.awardhierarchy.sync.service.AwardSyncServiceImpl.java

/**
 * Run the {@link AwardDocumentRule#processSaveDocument} and {@link AwardDocumentRule#processRunAuditBusinessRules} against award. Add all
 * messages generated from running the rules to logList as {@link AwardSyncLog}.
 * Return false if any of the error keys generated by the rules are not in the ignoredMessageKeys list.
 * //from   w  w  w  .j a  v  a 2 s . c  o m
 * @param award
 * @param logs
 * @return
 */
@Override
@SuppressWarnings("deprecation")
protected boolean validateModifiedAward(AwardDocument award, AwardSyncStatus awardStatus) {
    AwardDocumentRule rule = new AwardDocumentRule();
    boolean result = true;
    if (!rule.processSaveDocument(award)) {
        getAwardSyncUtilityService().getLogsFromSaveErrors(awardStatus);
    }
    if (!rule.processRunAuditBusinessRules(award)) {
        getAwardSyncUtilityService().getLogsFromAuditErrors(awardStatus);
    }
    String[] ignoredErrors = IGNORED_MESSAGE_KEYS.split(",");
    for (AwardSyncLog log : awardStatus.getValidationLogs()) {
        if (!StringUtils.startsWithAny(log.getMessageKey(), ignoredErrors) && !log.isSuccess()) {
            result = false;
        } else {
            log.setSuccess(true);
        }
    }
    return result;
}

From source file:com.adobe.acs.tools.hc.impl.TemplateThumbnailHealthCheck.java

@Override
public Result execute() {
    final FormattingResultLog resultLog = new FormattingResultLog();
    int templatesWithoutIcons = 0;

    ResourceResolver resolver = null;//w ww.j  a v  a  2 s.c  o m
    try {
        resolver = rrFactory.getAdministrativeResourceResolver(null);
        PageManager pageManager = resolver.adaptTo(PageManager.class);

        Collection<Template> templates = pageManager.getTemplates(null);
        for (Template template : templates) {
            String path = template.getPath();
            if (StringUtils.startsWithAny(path, paths)) {
                String thumbnailPath = template.getThumbnailPath();

                if (thumbnailPath == null) {
                    templatesWithoutIcons++;
                    resultLog.warn("Template {} doesn't have a thumbnail.", path);
                }
            }
        }

        if (templatesWithoutIcons > 0) {
            resultLog.info("[You have templates without thumbnails.]");
        } else {
            resultLog.debug("All templates have thumbnails.");
        }
    } catch (Exception e) {
        log.error("Unable to list templates", e);
    } finally {
        if (resolver != null) {
            resolver.close();
        }
    }

    return new Result(resultLog);
}

From source file:com.adobe.acs.tools.hc.impl.ComponentIconHealthCheck.java

@Override
public Result execute() {
    final FormattingResultLog resultLog = new FormattingResultLog();
    int componentsWithoutIcons = 0;

    ResourceResolver resolver = null;/*from  w w w.  j  av a2  s .com*/
    try {
        resolver = rrFactory.getAdministrativeResourceResolver(null);
        ComponentManager compManager = resolver.adaptTo(ComponentManager.class);

        Collection<Component> components = compManager.getComponents();
        for (Component component : components) {
            String path = component.getPath();
            if (StringUtils.startsWithAny(path, paths)) {
                String iconPath = component.getIconPath();

                if (isDroppable(component) && !isPageType(component) && iconPath == null) {
                    componentsWithoutIcons++;
                    resultLog.warn("Component {} is editable, but doesn't have an icon.", path);
                }
            }
        }

        if (componentsWithoutIcons > 0) {
            resultLog.info("[You have component without icons.]");
        } else {
            resultLog.debug("All components have icons.");
        }
    } catch (Exception e) {
        log.error("Unable to list components", e);
    } finally {
        if (resolver != null) {
            resolver.close();
        }
    }

    return new Result(resultLog);
}

From source file:com.adobe.acs.commons.quickly.impl.QuicklyFilter.java

@SuppressWarnings("squid:S3923")
private boolean accepts(final HttpServletRequest request) {
    if (!StringUtils.equalsIgnoreCase("get", request.getMethod())) {
        // Only inject on GET requests
        return false;
    } else if (StringUtils.startsWithAny(request.getRequestURI(), REJECT_PATH_PREFIXES)) {
        return false;
    } else if (StringUtils.equals(request.getHeader("X-Requested-With"), "XMLHttpRequest")) {
        // Do not inject into XHR requests
        return false;
    } else if (StringUtils.endsWith(request.getHeader("Referer"), "/editor.html" + request.getRequestURI())) {
        // Do not apply to pages loaded in the TouchUI editor.html
        return false;
    } else if (StringUtils.endsWith(request.getHeader("Referer"), "/cf")) {
        // Do not apply to pages loaded in the Content Finder
        return false;
    }/*  w ww .  j a v  a  2  s.co  m*/
    return true;
}

From source file:au.edu.anu.portal.portlets.rss.validator.SimpleRSSPreferencesValidator.java

@Override
protected boolean isValidScheme(String url) {

    //check if url starts with one of the schemes
    if (StringUtils.startsWithAny(url, schemes)) {
        return true;
    }// w  ww.j a v  a2 s  . c o  m
    return false;

}

From source file:com.adobe.acs.livereload.impl.JavaScriptInjectionFilter.java

private boolean accepts(final SlingHttpServletRequest slingRequest) {
    final Resource resource = slingRequest.getResource();

    if (!StringUtils.equalsIgnoreCase("get", slingRequest.getMethod())) {
        // Only inject on GET requests
        return false;
    } else if (!StringUtils.startsWithAny(resource.getPath(), prefixes)) {
        return false;
    } else if (StringUtils.equals(slingRequest.getHeader("X-Requested-With"), "XMLHttpRequest")) {
        // Do not inject into XHR requests
        return false;
    }//from   ww  w .  ja  v  a  2 s .c om
    return true;
}

From source file:com.digitalpebble.storm.crawler.elasticsearch.metrics.MetricsConsumer.java

boolean shouldSkip(String name) {
    if (StringUtils.startsWithAny(name, blacklist)) {
        return true;
    }//from   w  w  w.  j  a v  a2s .co m
    if (whitelist.length > 0) {
        return !StringUtils.startsWithAny(name, whitelist);
    }
    return false;
}

From source file:eu.apenet.dpt.standalone.gui.eag2012.EagRelationsPanel.java

@Override
protected JComponent buildEditorPanel(List<String> errors) {
    if (errors == null)
        errors = new ArrayList<String>(0);
    else if (Utilities.isDev && errors.size() > 0) {
        LOG.info("Errors in form:");
        for (String error : errors) {
            LOG.info(error);//  w w w  .  j av  a  2  s.  c o m
        }
    }

    FormLayout layout = new FormLayout("right:max(50dlu;p), 4dlu, 100dlu, 7dlu, right:p, 4dlu, 100dlu",
            EDITOR_ROW_SPEC);

    layout.setColumnGroups(new int[][] { { 1, 3, 5, 7 } });
    PanelBuilder builder = new PanelBuilder(layout);

    builder.setDefaultDialogBorder();
    CellConstraints cc = new CellConstraints();

    rowNb = 1;
    if (eag.getRelations() == null)
        eag.setRelations(new Relations());
    Relations relations = eag.getRelations();

    builder.addSeparator(labels.getString("eag2012.relations.resourceRelations"), cc.xyw(1, rowNb, 7));
    setNextRow();

    resourceRelationTypes = new ArrayList<ResourceRelationType>(relations.getResourceRelation().size());

    if (relations.getResourceRelation().isEmpty())
        relations.getResourceRelation().add(new ResourceRelation());

    for (ResourceRelation resourceRelation : relations.getResourceRelation()) {
        if (resourceRelation.getRelationEntry() == null)
            resourceRelation.setRelationEntry(new RelationEntry());
        if (resourceRelation.getDescriptiveNote() == null) {
            DescriptiveNote descriptiveNote = new DescriptiveNote();
            descriptiveNote.setP(new ArrayList<P>() {
                {
                    add(new P());
                }
            });
            resourceRelation.setDescriptiveNote(descriptiveNote);
        }
        ResourceRelationType resourceRelationType = new ResourceRelationType(
                resourceRelation.getResourceRelationType(), resourceRelation.getHref(),
                resourceRelation.getRelationEntry().getContent(),
                resourceRelation.getDescriptiveNote().getP().get(0).getContent(),
                resourceRelation.getDescriptiveNote().getP().get(0).getLang(), true);
        resourceRelationTypes.add(resourceRelationType);

        builder.addLabel(labels.getString("eag2012.relations.linkToResourceRelation"), cc.xy(1, rowNb));
        builder.add(resourceRelationType.getWebsite(), cc.xy(3, rowNb));
        builder.addLabel(labels.getString("eag2012.relations.typeOfRelation"), cc.xy(5, rowNb));
        builder.add(resourceRelationType.getTypeRelations(), cc.xy(7, rowNb));
        setNextRow();
        if (errors.contains("resourceRelationTypes")) {
            if (StringUtils.isNotBlank(resourceRelationType.getWebsite().getText())
                    && !StringUtils.startsWithAny(resourceRelationType.getWebsite().getText(), webPrefixes)) {
                builder.add(createErrorLabel(labels.getString("eag2012.errors.webpageProtocol")),
                        cc.xy(1, rowNb));
                setNextRow();
            }
        } else if (StringUtils.isNotBlank(resourceRelationType.getWebsite().getText())
                && !StringUtils.startsWithAny(resourceRelationType.getWebsite().getText(), webPrefixes)) {
            builder.add(createErrorLabel(labels.getString("eag2012.errors.webpageProtocol")), cc.xy(1, rowNb));
            setNextRow();
        }

        builder.addLabel(labels.getString("eag2012.relations.titleOfRelatedMaterial"), cc.xy(1, rowNb));
        builder.add(resourceRelationType.getTitleAndId(), cc.xy(3, rowNb));
        setNextRow();

        builder.addLabel(labels.getString("eag2012.relations.descriptionOfRelation"), cc.xy(1, rowNb));
        builder.add(resourceRelationType.getDescription().getTextField(), cc.xy(3, rowNb));
        builder.addLabel(labels.getString("eag2012.commons.language"), cc.xy(5, rowNb));
        builder.add(resourceRelationType.getDescription().getLanguageBox(), cc.xy(7, rowNb));
        setNextRow();
    }

    JButton addResourceRelation = new ButtonTab(labels.getString("eag2012.relations.addNewResourceRelation"));
    builder.add(addResourceRelation, cc.xy(1, rowNb));
    addResourceRelation.addActionListener(new AddResourceRelationAction(eag, tabbedPane, model));
    setNextRow();

    builder.addSeparator(labels.getString("eag2012.relations.institutionRelation"), cc.xyw(1, rowNb, 7));
    setNextRow();

    institutionRelationTypes = new ArrayList<ResourceRelationType>(relations.getEagRelation().size());

    if (relations.getEagRelation().isEmpty())
        relations.getEagRelation().add(new EagRelation());

    for (EagRelation eagRelation : relations.getEagRelation()) {
        if (eagRelation.getRelationEntry().size() == 0)
            eagRelation.getRelationEntry().add(new RelationEntry());
        if (eagRelation.getDescriptiveNote() == null) {
            DescriptiveNote descriptiveNote = new DescriptiveNote();
            descriptiveNote.setP(new ArrayList<P>() {
                {
                    add(new P());
                }
            });
            eagRelation.setDescriptiveNote(descriptiveNote);
        }
        ResourceRelationType resourceRelationType = new ResourceRelationType(eagRelation.getEagRelationType(),
                eagRelation.getHref(), eagRelation.getRelationEntry().get(0).getContent(),
                eagRelation.getDescriptiveNote().getP().get(0).getContent(),
                eagRelation.getDescriptiveNote().getP().get(0).getLang(), false);
        institutionRelationTypes.add(resourceRelationType);

        builder.addLabel(labels.getString("eag2012.relations.websiteOfDescription"), cc.xy(1, rowNb));
        builder.add(resourceRelationType.getWebsite(), cc.xy(3, rowNb));
        builder.addLabel(labels.getString("eag2012.relations.typeOfRelation"), cc.xy(5, rowNb));
        builder.add(resourceRelationType.getTypeRelations(), cc.xy(7, rowNb));
        setNextRow();
        if (errors.contains("institutionRelationTypes")) {
            if (StringUtils.isNotBlank(resourceRelationType.getWebsite().getText())
                    && !StringUtils.startsWithAny(resourceRelationType.getWebsite().getText(), webPrefixes)) {
                builder.add(createErrorLabel(labels.getString("eag2012.errors.webpageProtocol")),
                        cc.xy(1, rowNb));
                setNextRow();
            }
        } else if (StringUtils.isNotBlank(resourceRelationType.getWebsite().getText())
                && !StringUtils.startsWithAny(resourceRelationType.getWebsite().getText(), webPrefixes)) {
            builder.add(createErrorLabel(labels.getString("eag2012.errors.webpageProtocol")), cc.xy(1, rowNb));
            setNextRow();
        }

        builder.addLabel(labels.getString("eag2012.relations.nameIdRelatedInstitution"), cc.xy(1, rowNb));
        builder.add(resourceRelationType.getTitleAndId(), cc.xy(3, rowNb));
        setNextRow();

        builder.addLabel(labels.getString("eag2012.relations.descriptionOfRelation"), cc.xy(1, rowNb));
        builder.add(resourceRelationType.getDescription().getTextField(), cc.xy(3, rowNb));
        builder.addLabel(labels.getString("eag2012.commons.language"), cc.xy(5, rowNb));
        builder.add(resourceRelationType.getDescription().getLanguageBox(), cc.xy(7, rowNb));
        setNextRow();
    }

    JButton addInstitutionRelation = new ButtonTab(
            labels.getString("eag2012.relations.addNewInstitutionRelation"));
    builder.add(addInstitutionRelation, cc.xy(1, rowNb));
    addInstitutionRelation.addActionListener(new AddInstitutionRelationAction(eag, tabbedPane, model));
    setNextRow();

    builder.addSeparator("", cc.xyw(1, rowNb, 7));
    setNextRow();

    JButton exitBtn = new ButtonTab(labels.getString("eag2012.commons.exit"));
    builder.add(exitBtn, cc.xy(1, rowNb));
    exitBtn.addActionListener(new ExitBtnAction(eag, tabbedPane, model));

    JButton previousTabBtn = new ButtonTab(labels.getString("eag2012.commons.previousTab"));
    builder.add(previousTabBtn, cc.xy(3, rowNb));
    previousTabBtn.addActionListener(new PreviousTabBtnAction(eag, tabbedPane, model));

    JButton saveBtn = new ButtonTab(labels.getString("eag2012.commons.save"));
    builder.add(saveBtn, cc.xy(5, rowNb));
    saveBtn.addActionListener(new SaveBtnAction(eag, tabbedPane, model));

    setNextRow();
    builder.addSeparator("", cc.xyw(1, rowNb, 7));
    setNextRow();
    JButton nextInstitutionTabBtn = new ButtonTab(labels.getString("eag2012.controls.nextInstitution"));
    nextInstitutionTabBtn.addActionListener(new NextInstitutionTabBtnAction(eag, tabbedPane, model));
    builder.add(nextInstitutionTabBtn, cc.xy(5, rowNb));

    // Define the change tab listener.
    this.removeChangeListener();
    this.tabbedPane.addChangeListener(new ChangeTabListener(this.eag, this.tabbedPane, this.model, 6));

    JPanel panel = builder.getPanel();
    KeyboardFocusManager.getCurrentKeyboardFocusManager()
            .addPropertyChangeListener(new FocusManagerListener(panel));
    return panel;
}