List of usage examples for org.apache.commons.lang3 StringUtils startsWith
public static boolean startsWith(final CharSequence str, final CharSequence prefix)
Check if a CharSequence starts with a specified prefix.
null s are handled without exceptions.
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.AbstractOwncloudRestServiceImpl.java
protected String getAuthorizationUserFromHeaders(HttpHeaders headers) { Validate.notNull(headers);/* ww w .j av a 2 s .c om*/ List<String> authorizations = headers.get(HttpHeaders.AUTHORIZATION); if (CollectionUtils.isEmpty(authorizations)) { return null; } String encodedCredentials = authorizations.get(0); if (StringUtils.startsWith(encodedCredentials, AUTHORIZATION_METHOD_PREFIX)) { encodedCredentials = StringUtils.substring(encodedCredentials, AUTHORIZATION_METHOD_PREFIX.length()); } final byte[] rawDecodedCredentials = Base64.getDecoder().decode(encodedCredentials.getBytes()); final String decodedCredentials = new String(rawDecodedCredentials); if (!StringUtils.contains(decodedCredentials, ':')) { return null; } return StringUtils.split(decodedCredentials, ':')[0]; }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceTest.java
private boolean isResourceLocation() { return StringUtils.startsWith(properties.getLocation(), "file:") || StringUtils.startsWith(properties.getLocation(), "classpath:"); }
From source file:spdxedit.SpdxLogic.java
public static FileType[] getTypesForFile(Path path) { String extension = StringUtils .lowerCase(StringUtils.substringAfterLast(path.getFileName().toString(), ".")); ArrayList<FileType> fileTypes = new ArrayList<>(); if (sourceFileExtensions.contains(extension)) { fileTypes.add(SpdxFile.FileType.fileType_source); }/*from ww w . j ava 2 s. c o m*/ if (binaryFileExtensions.contains(extension)) { fileTypes.add(FileType.fileType_binary); } if (textFileExtensions.contains(extension)) { fileTypes.add(FileType.fileType_text); } if (archiveFileExtensions.contains(extension)) { fileTypes.add(FileType.fileType_archive); } if ("spdx".equals(extension)) { fileTypes.add(FileType.fileType_spdx); } try { String mimeType = Files.probeContentType(path); if (StringUtils.startsWith(mimeType, MediaType.ANY_AUDIO_TYPE.type())) { fileTypes.add(FileType.fileType_audio); } if (StringUtils.startsWith(mimeType, MediaType.ANY_IMAGE_TYPE.type())) { fileTypes.add(FileType.fileType_image); } if (StringUtils.startsWith(mimeType, MediaType.ANY_APPLICATION_TYPE.type())) { fileTypes.add(FileType.fileType_application); } } catch (IOException ioe) { logger.warn("Unable to access file " + path.toString() + " to determine its type.", ioe); } return fileTypes.toArray(new FileType[] {}); }
From source file:syncthing.android.service.SyncthingUtils.java
public static File[] listExportedConfigs(Context context) { File root = Environment.getExternalStorageDirectory(); return root//from w ww . j av a 2 s .c o m .listFiles((dir, filename) -> StringUtils.startsWith(filename, context.getPackageName() + "-export") && StringUtils.endsWith(filename, ".zip")); }
From source file:syncthing.android.ui.sessionsettings.EditDevicePresenter.java
boolean validateAddress(String addr) { return StringUtils.startsWith(addr.trim(), "tcp://") && (SyncthingUtils.isIpAddressWithPort(StringUtils.removeStart(addr.trim(), "tcp://")) || SyncthingUtils.isDomainNameWithPort(StringUtils.removeStart(addr.trim(), "tcp://"))); }
From source file:syncthing.android.ui.sessionsettings.SettingsPresenter.java
boolean validateListenAddresses(CharSequence text) { int err = 0;//from w w w.j a v a 2 s .c o m if (StringUtils.isEmpty(text)) { err = R.string.input_error; } else { String string = StringUtils.trim(text.toString()); if (!StringUtils.startsWith(string, "tcp://")) { err = R.string.input_error; } //todo ip w/ port or ? } if (hasView()) { String msg = err != 0 ? getView().getContext().getString(err) : null; setGuiListenAddressError(msg); } return err == 0; }
From source file:tinyequationscoringengine.MathExpression.java
public MathExpression(final String sympy) throws QTIScoringException { try {/*from w w w. j a v a2s. c om*/ mathMLNodeList = null; if (StringUtils.startsWith(sympy, "<?xml")) { MathExpressionInfo info = MathExpressionInfo.getMathExpressionInfoFromXml(sympy); sympyResponse = info.getSympyResponse(); _sympyResponseNotSimplified = info.getSympyResponseNotSimplified(); _overcorrectedSympyResponse = info.getOvercorrectedSympyResponse(); _triedToApplyCorrection = info.getTriedToApplyCorrection(); _appliedCorrection = info.getAppliedCorrection(); } else { sympyResponse = Arrays.asList(sympy); } } catch (Exception exp) { throw new QTIScoringException(exp); } }
From source file:tinyequationscoringengine.MathScoringService.java
public boolean isEquivalent(MathExpression mathexp, String exemplar, boolean allowSimplify, boolean trig, boolean log, boolean force, int expInd) throws QTIScoringException { if (mathexp == null || mathexp.getSympyResponse() == null || expInd == -1 && mathexp.getSympyResponse().size() != 1 || expInd > -1 && mathexp.getSympyResponse().size() <= expInd) return false; String rubric = exemplar;/*from ww w . j ava 2s . c om*/ if (StringUtils.startsWith(rubric, "<?xml")) { MathExpressionInfo info = MathExpressionInfo.getMathExpressionInfoFromXml(rubric); rubric = info.getSympyResponse().size() > 0 ? info.getSympyResponse().get(0) : ""; } if (expInd < 0) expInd = 0; boolean parsable; if (allowSimplify) { parsable = sympify(mathexp.getSympyResponse().get(expInd)); // first try to correct syntax of the response expressions if (!parsable) { if (mathexp.correct()) parsable = sympify(mathexp.getSympyResponse().get(expInd)); } // correction worked if (parsable) { if (proxy.isEquivalent(mathexp.getSympyResponse().get(expInd), rubric, allowSimplify, trig, log, force)) return true; } // continue to over-corrected the response hoping that it would score // higher if (mathexp.correct() && mathexp.getOvercorrectedSympyResponse() != null && mathexp.getOvercorrectedSympyResponse().size() > expInd) { parsable = sympify(mathexp.getOvercorrectedSympyResponse().get(expInd)); if (parsable) return proxy.isEquivalent(mathexp.getOvercorrectedSympyResponse().get(expInd), rubric, allowSimplify, trig, log, force); } } else { // building a full AST of sympy String to later do traversal and apply // combinatorial rules for comparison Tree rubricAST, responseAST; try { rubricAST = antlrize(rubric); responseAST = antlrize(mathexp.getSympyResponse().get(expInd)); } catch (RecognitionException exp) { return false; } catch (RewriteEmptyStreamException exp) { return false; } catch (NullPointerException exp) { // happens within ANTLR during recovery in the expression rule: // Antlr.Runtime.Parser.GetMissingSymbol(IIntStream input, // RecognitionException e, Int32 expectedTokenType, BitSet follow) // since we do not try to recover on the top level of expression, it is // safe to return false here return false; } return isEquivalent(responseAST, rubricAST); } return false; }
From source file:tinyequationscoringengine.MathScoringService.java
public int countEquations(MathExpression mathexp) { int count = 0; if (mathexp == null || mathexp.getSympyResponse() == null) return count; for (String r : mathexp.getSympyResponse()) if (StringUtils.startsWith(r, "Eq(")) count += 1;//from w w w .j av a2s . co m return count; }