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.tesora.dve.db.NativeType.java

/**
 * Make sure the type name is always the same.  Sets the name to lower case with spaces instead of '_'
 * //www  .java 2  s  .  co m
 * Does the 'opposite' of fixNameForEnum.
 * 
 * @param name
 * @return
 */
public static String fixName(String name, boolean stripEnum) {
    final String[] matches = new String[] { "enum", "set" };
    final String[] replacements = new String[] { "enum", "set" };
    for (int i = 0; i < matches.length; i++) {
        if (StringUtils.startsWith(StringUtils.lowerCase(name, Locale.ENGLISH), matches[i])) {
            if (stripEnum) {
                return replacements[i];
            }
            return matches[i] + name.substring(matches[i].length());
        }

    }

    return name == null ? null : StringUtils.lowerCase(name.replaceAll("_", " "), Locale.ENGLISH);
}

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

protected void cleanupActivePayloadGroups(Workspace workspace) {
    for (PayloadGroup payloadGroup : workspace.getActivePayloadGroups()) {
        boolean removeActivePayloadGroup = true;
        for (Payload payload : workspace.getActivePayloads()) {
            if (StringUtils.startsWith(payload.getPath(), payloadGroup.getPath() + "/")) {
                removeActivePayloadGroup = false;
                break;
            }/*w  w w  . j  a v  a 2s.c o m*/
        }

        if (removeActivePayloadGroup) {
            workspace.removeActivePayloadGroup(payloadGroup);
        }
    }
}

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.action.MafFileProcessor.java

@Override
protected File doWork(final File mafFile, final QcContext context) throws ProcessorException {
    // make sure the disease is set
    if (context.getArchive() != null) {
        DiseaseContextHolder.setDisease(context.getArchive().getTumorType());
    }/*from ww w. j  ava  2s  .  c om*/

    FileReader fileReader = null;
    BufferedReader bufferedReader = null;

    try {
        // open file
        fileReader = new FileReader(mafFile);
        bufferedReader = new BufferedReader(fileReader);

        int lineNum = 0;

        // find first non-blank line not starting with #, this is the header
        String headerLine = bufferedReader.readLine();
        lineNum++;
        while (StringUtils.isEmpty(headerLine.trim())
                || StringUtils.startsWith(headerLine, COMMENT_LINE_TOKEN)) {
            headerLine = bufferedReader.readLine();
            lineNum++;
        }

        final List<String> headers = Arrays.asList(headerLine.split("\\t"));

        context.setFile(mafFile);
        final Map<String, Integer> fieldOrder = mapFieldOrder(headers);
        // need to find out the file id for this maf file
        final Long mafFileId = fileInfoQueries.getFileId(mafFile.getName(), context.getArchive().getId());
        if (mafFileId == null || mafFileId == -1) {
            context.getArchive().setDeployStatus(Archive.STATUS_IN_REVIEW);
            throw new ProcessorException(new StringBuilder().append("File '").append(mafFile.getName())
                    .append("' was not found in the database").toString());
        }
        if (isAddMafInfo(mafFileId)) {
            HashMap<String, BCRID> biospecimens = new HashMap<String, BCRID>();
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                lineNum++;
                if (!StringUtils.isBlank(line.trim()) && !StringUtils.startsWith(line, COMMENT_LINE_TOKEN)) {
                    final String[] row = line.split("\\t");

                    try {
                        processRow(row, fieldOrder, mafFileId, biospecimens, context, mafFile, lineNum);
                        //  If exceeds batch size store it in the database
                        if (biospecimens.size() >= getBatchSize()) {
                            try {
                                insertBiospecimenToFileRelationships(biospecimens, context, mafFile);
                            } catch (UUIDException ue) {
                                throw new ProcessorException(ue.getMessage(), ue);
                            }
                            biospecimens.clear();
                        }
                    } catch (DataAccessException e) {
                        // catch DB errors per line
                        context.getArchive().setDeployStatus(Archive.STATUS_IN_REVIEW);
                        context.addError(MessageFormat.format(MessagePropertyType.MAF_FILE_PROCESSING_ERROR,
                                mafFile.getName(),
                                new StringBuilder().append("Mutation information from file at line '")
                                        .append(lineNum).append("' was not successfully added. Root cause: ")
                                        .append(e.getMessage()).toString()));
                    }
                }
            }
            // process remaining biospecimens
            if (biospecimens.size() > 0) {
                try {
                    insertBiospecimenToFileRelationships(biospecimens, context, mafFile);
                } catch (UUIDException ue) {
                    context.getArchive().setDeployStatus(Archive.STATUS_IN_REVIEW);
                    throw new ProcessorException(ue.getMessage(), ue);
                } catch (DataAccessException e) {
                    context.getArchive().setDeployStatus(Archive.STATUS_IN_REVIEW);
                    throw new ProcessorException(e.getMessage(), e);
                }
                biospecimens.clear();
            }
        }
    } catch (IOException e) {
        context.getArchive().setDeployStatus(Archive.STATUS_IN_REVIEW);
        throw new ProcessorException(
                new StringBuilder().append("Error reading maf file ").append(mafFile.getName()).toString());
    } finally {
        if (bufferedReader != null) {
            try {
                bufferedReader.close();
            } catch (IOException e) {
                // ignore
            }
        }

        if (fileReader != null) {
            try {
                fileReader.close();
            } catch (IOException e) {
                // ignore
            }
        }
    }

    return mafFile;
}

From source file:com.eincs.athens.core.Analyzers.java

/**
 * travel all analyzers and invoke analyze method
 * @param request request information of analyze
 * @return report of analyze//from   w  ww. j  a  v  a2  s  .c  om
 */
public AthensReport invokeAnalyzers(AthensRequest request) {
    // invoke analyzers
    AnalyzeResult result = AnalyzeResult.create(AnalyzeResultType.PANALTY);
    synchronized (this) {
        for (AnalyzerHodler holder : analyzerHolders) {
            try {
                AnalyzeResult newResult = holder.analyzer.analyze(request);
                result.merge(newResult);
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }

        }
    }
    // create report with result and request
    AthensReport report = new AthensReport();
    report.setRequestSeq(request.getRequestSeq());
    report.setTargetKey(request.getTargetKey());
    report.setResult(result);
    report.setTags(request.getTags());

    if (report.needNotify()) {
        try {
            String ipAddr = InetAddress.getByAddress(request.getTargetKey().getAddress()).toString();
            if (StringUtils.startsWith(ipAddr, "/")) {
                ipAddr = ipAddr.substring(1);
            }
            MysqlHandler.insert(ipAddr, request.getTargetKey().getMethod(), request.getTargetKey().getPath(),
                    RateLimitAnalyzer.class.getSimpleName(), System.currentTimeMillis() + result.getPanalty());
        } catch (UnknownHostException e) {
            logger.error(e.getMessage(), e);
        }
    }

    return report;
}

From source file:com.activecq.samples.eventhandlers.impl.SampleEventPublisher.java

@Override
public boolean process(Event event) {
    final String path = (String) event.getProperty(SlingConstants.PROPERTY_PATH);
    final String resourceType = (String) event.getProperty(SlingConstants.PROPERTY_RESOURCE_TYPE);

    if (!StringUtils.startsWith(path, "/content/samples")) {
        // Only handle events here from resources under /content/samples
        return true;
    }/*w ww .  ja v a  2 s . co m*/

    try {
        // Only return false if job processing failed and the job should be rescheduled
        return fowardEvent(path);
    } catch (Exception ex) {
        // If this event could not be processes to satisfaction, return false
        // so it can be rescheduled.
        return false;
    }
}

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

@Override
public List<CompletionItem> getCompletionItems(Document document, String filter, int startOffset,
        int caretOffset) {
    List<CompletionItem> ret = new ArrayList<>();
    try {/*  w  w w.j  a v  a 2  s  .  c  om*/
        String text = document.getText(0, caretOffset);
        List<String> variables = resolveVariable(filter, text);
        // if the filter is not the complete variable, we first autocomplete the actual variable
        for (String variable : variables) {
            if (!StringUtils.equals(filter, variable)) {
                ret.add(new BasicCompletionItem(variable, true, startOffset, caretOffset));
            }
        }
        // otherwise we lookup the defined class and return all of it's members
        if (ret.isEmpty()) {
            Set<String> items = resolveClass(filter, text, document);
            for (String item : items) {
                if (StringUtils.startsWith(item, filter)) {
                    ret.add(new BasicCompletionItem(item, false, startOffset, caretOffset));
                }
            }
        }
    } catch (BadLocationException ex) {
        Exceptions.printStackTrace(ex);
    }
    return ret;
}

From source file:mitm.test.TestUtils.java

public static int getTempFileCount(final String prefix, final String postfix) {
    String[] files = SystemUtils.getJavaIoTmpDir().list(new FilenameFilter() {
        @Override/*from  w  ww . ja  va  2 s.co m*/
        public boolean accept(File file, String s) {
            return StringUtils.startsWith(s, prefix) && StringUtils.endsWith(s, postfix);
        }
    });

    return files != null ? files.length : 0;
}

From source file:com.gst.infrastructure.documentmanagement.contentrepository.ContentRepositoryUtils.java

/**
 * Extracts Image from a Data URL/*from  w ww. j  a  va  2s  . c o m*/
 * 
 * @param mimeType
 */
public static Base64EncodedImage extractImageFromDataURL(final String dataURL) {
    String fileExtension = "";
    String base64EncodedString = null;
    if (StringUtils.startsWith(dataURL, IMAGE_DATA_URI_SUFFIX.GIF.getValue())) {
        base64EncodedString = dataURL.replaceAll(IMAGE_DATA_URI_SUFFIX.GIF.getValue(), "");
        fileExtension = IMAGE_FILE_EXTENSION.GIF.getValue();
    } else if (StringUtils.startsWith(dataURL, IMAGE_DATA_URI_SUFFIX.PNG.getValue())) {
        base64EncodedString = dataURL.replaceAll(IMAGE_DATA_URI_SUFFIX.PNG.getValue(), "");
        fileExtension = IMAGE_FILE_EXTENSION.PNG.getValue();
    } else if (StringUtils.startsWith(dataURL, IMAGE_DATA_URI_SUFFIX.JPEG.getValue())) {
        base64EncodedString = dataURL.replaceAll(IMAGE_DATA_URI_SUFFIX.JPEG.getValue(), "");
        fileExtension = IMAGE_FILE_EXTENSION.JPEG.getValue();
    } else {
        throw new ImageDataURLNotValidException();
    }

    return new Base64EncodedImage(base64EncodedString, fileExtension);
}

From source file:com.dp2345.interceptor.MemberInterceptor.java

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    if (modelAndView != null) {
        String viewName = modelAndView.getViewName();
        if (!StringUtils.startsWith(viewName, REDIRECT_VIEW_NAME_PREFIX)) {
            modelAndView.addObject(MEMBER_ATTRIBUTE_NAME, memberService.getCurrent());
        }/*from   w  w w  .  j a  v a2s.  c o m*/
    }
}

From source file:hydrograph.ui.expression.editor.composites.FunctionsComposite.java

private void addDoubleClickListner(final List methodList) {
    methodList.addMouseListener(new MouseAdapter() {
        @Override/*from   ww  w .  j a  v a 2  s .  com*/
        public void mouseDoubleClick(MouseEvent e) {
            if (methodList.getSelectionIndex() != -1
                    && !StringUtils.startsWith(methodList.getItem(methodList.getSelectionIndex()),
                            Messages.CANNOT_SEARCH_INPUT_STRING)) {
                MethodDetails methodDetails = (MethodDetails) methodList
                        .getData(String.valueOf(methodList.getSelectionIndex()));
                if (methodDetails != null && StringUtils.isNotBlank(methodDetails.getPlaceHolder())) {
                    expressionEditorTextBox.insert(methodDetails.getPlaceHolder());
                }
            }
        }
    });
}