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

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

Introduction

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

Prototype

public static boolean endsWith(String str, String suffix) 

Source Link

Document

Check if a String ends with a specified suffix.

Usage

From source file:com.glaf.core.test.MongoDBGridFSThread.java

public void run() {
    if (file.exists() && file.isFile()) {
        String path = file.getAbsolutePath();
        path = path.replace('\\', '/');
        if (StringUtils.contains(path, "/temp/") || StringUtils.contains(path, "/tmp/")
                || StringUtils.contains(path, "/logs/") || StringUtils.contains(path, "/work/")
                || StringUtils.endsWith(path, ".log") || StringUtils.endsWith(path, ".class")) {
            return;
        }//  w ww.  j  a  va2 s  .c om
        int retry = 0;
        boolean success = false;
        byte[] bytes = null;
        GridFSInputFile inputFile = null;
        while (retry < 1 && !success) {
            try {
                retry++;
                bytes = FileUtils.getBytes(file);
                if (bytes != null) {
                    inputFile = gridFS.createFile(bytes);
                    DBObject metadata = new BasicDBObject();
                    metadata.put("path", path);
                    metadata.put("filename", file.getName());
                    metadata.put("size", bytes.length);
                    inputFile.setMetaData(metadata);
                    inputFile.setId(path);
                    inputFile.setFilename(file.getName());// ??
                    inputFile.save();// ?
                    bytes = null;
                    success = true;
                    logger.debug(file.getAbsolutePath() + " save ok.");
                }
            } catch (Exception ex) {
                logger.error(ex);
                ex.printStackTrace();
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            } finally {
                bytes = null;
                inputFile = null;
            }
        }
    }
}

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;
        }/*from w w w . j  a v  a  2s .  c  o  m*/
        errorMessage = propertyName + " is mandatory";
    }
    errorMessage = propertyName + " is not integer value or valid parameter";
    return false;
}

From source file:com.microsoft.alm.plugin.external.tools.TfTool.java

/**
 * This method returns the path to the TF command line program.
 * It relies on the vsts-settings file.//from   w w  w  . ja  v a  2s .  c o  m
 * This method will throw if no valid path exists.
 */
public static String getValidLocation() {
    // Get the tf command location from file
    final String location = getLocation();
    if (StringUtil.isNullOrEmpty(location)) {
        // tfHome property not set
        throw new ToolException(ToolException.KEY_TF_HOME_NOT_SET);
    }

    final String[] filenames = Platform.isWindows() ? TF_WINDOWS_PROGRAMS : TF_OTHER_PROGRAMS;

    // Verify the path leads to a tf command and exists
    for (final String filename : filenames) {
        if (StringUtils.endsWith(location, filename) && (new File(location)).exists()) {
            return location;
        }
    }

    // The saved location does not point to the tf command
    throw new ToolException(ToolException.KEY_TF_EXE_NOT_FOUND);
}

From source file:com.microsoft.alm.common.utils.UrlHelper.java

public static boolean isVSO(final URI uri) {
    if (uri != null && uri.getHost() != null) {
        final String host = uri.getHost().toLowerCase();
        if (StringUtils.endsWith(host, HOST_VSO) || StringUtils.endsWith(host, HOST_TFS_ALL_IN)) {
            return true;
        }//w w w  .  ja  va 2  s. c  om
    }
    return false;
}

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;
    }// ww  w  . ja  v a2 s .c  o 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:io.wcm.tooling.netbeans.sightly.completion.classLookup.MemberLookupResult.java

/**
 *
 * @param variableName/*from w  ww . j a va  2 s .c  o  m*/
 * @param methodName
 * @param returnType
 */
public MemberLookupResult(String variableName, String methodName, String returnType) {
    this.variableName = variableName;
    this.methodName = methodName;

    //TODO: this is a hack to get support for list, set, map, enumeration, array and collection
    String tmp = returnType;
    if (StringUtils.startsWith(returnType, List.class.getName())
            || StringUtils.startsWith(returnType, Set.class.getName())
            || StringUtils.startsWith(returnType, Map.class.getName())
            || StringUtils.startsWith(returnType, Iterator.class.getName())
            || StringUtils.startsWith(returnType, Enum.class.getName())
            || StringUtils.startsWith(returnType, Collection.class.getName())) {
        while (StringUtils.contains(tmp, "<") && StringUtils.contains(tmp, ">")) {
            tmp = StringUtils.substringBetween(tmp, "<", ">");
        }
        if (StringUtils.contains(tmp, ",")) {
            // we want the first variable
            tmp = StringUtils.substringBefore(tmp, ",");
        }
    } else if (StringUtils.endsWith(returnType, "[]")) {
        tmp = StringUtils.substringBeforeLast(returnType, "[]");
    }

    this.returnType = tmp;
}

From source file:com.htmlhifive.tools.jslint.engine.option.CheckOptionFileWrapperFactory.java

/**
 * ???.//from  ww w.j ava 2 s. c om
 * 
 * @param file ?.
 * @param extension ?.
 * @return ?.
 * @throws CoreException ?.
 */
private static CheckOptionFileWrapper createCheckOptionFileWrapper(IFile file, String extension)
        throws CoreException {

    try {
        if (!file.exists()) {
            JaxbUtil.saveJsCheckOption(new JsCheckOption(), file);
        }
        if (StringUtils.endsWith(extension, "xml")) {
            return new CheckOptionXmlWrapper(file);
        } else if (StringUtils.endsWith(extension, "properties")) {
            Properties prop = new Properties();
            prop.load(file.getContents());
            // TODO ?.
            return new CheckOptionPropertyWrapper(prop);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (JAXBException e) {
        throw new CoreException(
                new Status(IStatus.ERROR, JSLintPlugin.PLUGIN_ID, Messages.EM0008.getText(), e));
    }
    return null;
}

From source file:biz.netcentric.vlt.upgrade.handler.GroovyConsoleHandler.java

/**
 * Builds the Map of Phases with a List of ScriptPaths for each Phase.
 * @return Map of ScriptPaths per Phase/*w  ww  .j a v a2s .c om*/
 */
private Map<Phase, LinkedList<String>> getScriptsFromConfig() {
    scripts = new HashMap<>();
    for (Phase phase : Phase.values()) {
        scripts.put(phase, new LinkedList<String>());
    }

    Resource resource = upgradeInfo.getConfigResource();
    for (Resource child : resource.getChildren()) {
        // groovy scripts
        if (StringUtils.endsWith(child.getName(), ".groovy") && child.isResourceType("nt:file")) {
            // it's a script, assign the script to a phase
            scripts.get(getPhaseFromPrefix(child.getName())).add(child.getPath());
        }
    }
    return scripts;
}

From source file:com.inktomi.wxmetar.MetarParser.java

/**
 * Parses a String[] of metar parts into a Metar
 * <p/>/*  w w w.j a  va 2 s  .c om*/
 * KCLE 050551Z 17012G24KT 10SM SCT070 SCT085 OVC110 09/03 A3005 RMK AO2 SLP180 8/57/ 60004 T00940028 10094 20061 56026
 * KL35 051752Z AUTO 26006KT 10SM CLR 11/M19 A3030 RMK AO2
 *
 * @param tokens the tokens to parse
 * @return the assembled Metar
 */
private static Metar parseTokens(final String[] tokens) {
    Metar rval = new Metar();

    rval.station = tokens[0];

    // The day of the month is the first 2
    rval.dayOfMonth = Integer.parseInt(StringUtils.substring(tokens[1], 0, 2));

    // The time is from 0 to length-1
    rval.zuluHour = Integer.parseInt(StringUtils.substring(tokens[1], 2, tokens[1].length() - 3));
    rval.zuluMinute = Integer.parseInt(StringUtils.substring(tokens[1], 4, tokens[1].length() - 1));

    // We start our actual parsing at the third element
    for (int i = 2; i < tokens.length; i++) {
        String token = tokens[i];
        String nextToken = null;
        if (tokens.length > i + 1) {
            nextToken = tokens[i + 1];
        }

        // First, we have AUTO or COR
        if (parseModifier(token, rval)) {
            continue;
        }

        if (parseWinds(token, rval)) {
            continue;
        }

        if (null != nextToken && parseVisibility(token, nextToken, rval)) {
            Matcher numberMatcher = NUMBER.matcher(token);
            Matcher fractionMatcher = FRACTION.matcher(nextToken);

            if (!StringUtils.endsWith(token, "SM") && numberMatcher.matches()
                    && StringUtils.endsWith(nextToken, "SM") && fractionMatcher.matches()) {

                // Increment i one here since we had a fraction: 1 1/2SM
                i = i + 1;
            }

            continue;
        }

        if (parsePresentWeather(token, rval)) {
            continue;
        }

        if (parseClouds(token, rval)) {
            continue;
        }

        if (parseTempDewpoint(token, rval)) {
            continue;
        }

        if (parseAltimeter(token, rval)) {
            continue;
        }

    }

    return rval;
}

From source file:com.taobao.tdhs.jdbc.util.StringUtil.java

public static String escapeValue(String value) {
    value = StringUtils.trim(value);//from  w w  w. j ava  2  s.com
    if (StringUtils.startsWith(value, FIELD_ESCAPE_QUOTATION)
            || StringUtils.endsWith(value, FIELD_ESCAPE_QUOTATION)) {
        return null;
    }
    if (StringUtils.startsWith(value, VALUE_ESCAPE_QUOTATION_1)
            && !StringUtils.endsWith(value, VALUE_ESCAPE_QUOTATION_1)) {
        return null;
    }
    if (!StringUtils.startsWith(value, VALUE_ESCAPE_QUOTATION_1)
            && StringUtils.endsWith(value, VALUE_ESCAPE_QUOTATION_1)) {
        return null;
    }
    if (StringUtils.startsWith(value, VALUE_ESCAPE_QUOTATION_2)
            && !StringUtils.endsWith(value, VALUE_ESCAPE_QUOTATION_2)) {
        return null;
    }
    if (!StringUtils.startsWith(value, VALUE_ESCAPE_QUOTATION_2)
            && StringUtils.endsWith(value, VALUE_ESCAPE_QUOTATION_2)) {
        return null;
    }

    if (StringUtils.startsWith(value, VALUE_ESCAPE_QUOTATION_1)
            && StringUtils.endsWith(value, VALUE_ESCAPE_QUOTATION_1)) {
        if (value.length() > 1)
            return value.substring(1, value.length() - 1);
        else
            return null;
    }

    if (StringUtils.startsWith(value, VALUE_ESCAPE_QUOTATION_2)
            && StringUtils.endsWith(value, VALUE_ESCAPE_QUOTATION_2)) {
        if (value.length() > 1)
            return value.substring(1, value.length() - 1);
        else
            return null;
    }

    return value;
}