List of usage examples for org.apache.commons.lang StringUtils startsWithIgnoreCase
public static boolean startsWithIgnoreCase(String str, String prefix)
Case insensitive check if a String starts with a specified prefix.
From source file:org.eclipse.skalli.testutil.HttpServerMock.java
@Override public void run() { BufferedReader request = null; DataOutputStream response = null; try {//from w w w .j a v a 2s . c o m server = new ServerSocket(port); while (true) { Socket connection = server.accept(); request = new BufferedReader(new InputStreamReader(connection.getInputStream(), "ISO8859_1")); response = new DataOutputStream(connection.getOutputStream()); String httpCode; String contentId = ""; String requestLine = request.readLine(); if (!StringUtils.startsWithIgnoreCase(requestLine, "GET")) { httpCode = "405"; } else { String path = StringUtils.split(requestLine, " ")[1]; int n = StringUtils.lastIndexOf(path, "/"); contentId = StringUtils.substring(path, 1, n); httpCode = StringUtils.substring(path, n + 1); } String content = bodies.get(contentId); StringBuffer sb = new StringBuffer(); sb.append("HTTP/1.1 ").append(httpCode).append(" CustomStatus\r\n"); sb.append("Server: MiniMockUnitServer\r\n"); sb.append("Content-Type: text/plain\r\n"); if (content != null) { sb.append("Content-Length: ").append(content.length()).append("\r\n"); } sb.append("Connection: close\r\n"); sb.append("\r\n"); if (content != null) { sb.append(content); } response.writeBytes(sb.toString()); IOUtils.closeQuietly(response); } } catch (IOException e) { IOUtils.closeQuietly(request); IOUtils.closeQuietly(response); } finally { try { server.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:org.eclipse.smarthome.binding.homematic.internal.communicator.client.RpcClient.java
/** * Tries to identify the gateway and returns the GatewayInfo. *//* w ww . j a v a 2s . c om*/ public HmGatewayInfo getGatewayInfo(String id) throws IOException { boolean isHomegear = false; GetDeviceDescriptionParser ddParser; ListBidcosInterfacesParser biParser; try { ddParser = getDeviceDescription(HmInterface.RF); isHomegear = StringUtils.equalsIgnoreCase(ddParser.getType(), "Homegear"); } catch (IOException ex) { // can't load gateway infos via RF interface ddParser = new GetDeviceDescriptionParser(); } try { biParser = listBidcosInterfaces(HmInterface.RF); } catch (IOException ex) { biParser = listBidcosInterfaces(HmInterface.HMIP); } HmGatewayInfo gatewayInfo = new HmGatewayInfo(); gatewayInfo.setAddress(biParser.getGatewayAddress()); if (isHomegear) { gatewayInfo.setId(HmGatewayInfo.ID_HOMEGEAR); gatewayInfo.setType(ddParser.getType()); gatewayInfo.setFirmware(ddParser.getFirmware()); } else if ((StringUtils.startsWithIgnoreCase(biParser.getType(), "CCU") || StringUtils.startsWithIgnoreCase(biParser.getType(), "HMIP_CCU") || StringUtils.startsWithIgnoreCase(ddParser.getType(), "HM-RCV-50") || config.isCCUType()) && !config.isNoCCUType()) { gatewayInfo.setId(HmGatewayInfo.ID_CCU); String type = StringUtils.isBlank(biParser.getType()) ? "CCU" : biParser.getType(); gatewayInfo.setType(type); gatewayInfo .setFirmware(ddParser.getFirmware() != null ? ddParser.getFirmware() : biParser.getFirmware()); } else { gatewayInfo.setId(HmGatewayInfo.ID_DEFAULT); gatewayInfo.setType(biParser.getType()); gatewayInfo.setFirmware(biParser.getFirmware()); } if (gatewayInfo.isCCU() || config.hasRfPort()) { gatewayInfo.setRfInterface(hasInterface(HmInterface.RF, id)); } if (gatewayInfo.isCCU() || config.hasWiredPort()) { gatewayInfo.setWiredInterface(hasInterface(HmInterface.WIRED, id)); } if (gatewayInfo.isCCU() || config.hasHmIpPort()) { gatewayInfo.setHmipInterface(hasInterface(HmInterface.HMIP, id)); } if (gatewayInfo.isCCU() || config.hasCuxdPort()) { gatewayInfo.setCuxdInterface(hasInterface(HmInterface.CUXD, id)); } if (gatewayInfo.isCCU() || config.hasGroupPort()) { gatewayInfo.setGroupInterface(hasInterface(HmInterface.GROUP, id)); } return gatewayInfo; }
From source file:org.eclipse.smarthome.binding.homematic.internal.communicator.parser.DeleteDevicesParser.java
@Override public List<String> parse(Object[] message) throws IOException { List<String> adresses = new ArrayList<String>(); if (message != null && message.length > 1) { Object[] data = (Object[]) message[1]; for (int i = 0; i < message.length; i++) { String address = getSanitizedAddress(data[i]); boolean isDevice = !StringUtils.contains(address, ":") && !StringUtils.startsWithIgnoreCase(address, "BidCos"); if (isDevice) { adresses.add(address);/*from ww w .ja v a 2s .c o m*/ } } } return adresses; }
From source file:org.eclipse.smarthome.binding.homematic.internal.communicator.parser.NewDevicesParser.java
@Override @SuppressWarnings("unchecked") public List<String> parse(Object[] message) throws IOException { List<String> adresses = new ArrayList<String>(); if (message != null && message.length > 1) { message = (Object[]) message[1]; for (int i = 0; i < message.length; i++) { Map<String, ?> data = (Map<String, ?>) message[i]; String address = toString(data.get("ADDRESS")); boolean isDevice = !StringUtils.contains(address, ":") && !StringUtils.startsWithIgnoreCase(address, "BidCos"); if (isDevice) { adresses.add(getSanitizedAddress(address)); }/*from ww w.j a v a2 s . c o m*/ } } return adresses; }
From source file:org.executequery.base.DockedTabContainer.java
private TabComponent getTabComponent(String title) { String tabTitle = title.toUpperCase(); int[] positions = { SwingConstants.NORTH, SwingConstants.SOUTH, SwingConstants.CENTER }; for (int tabPosition : positions) { List<TabComponent> tabs = getOpenTabs(tabPosition); if (tabs != null) { for (TabComponent tab : tabs) { if (StringUtils.startsWithIgnoreCase(tab.getTitle(), tabTitle)) { return tab; }//from w w w . j av a2 s .c o m } } } return null; }
From source file:org.fao.geonet.kernel.search.SearchManager.java
/** * Browses the index for the specified Lucene field and return the list of terms found containing the search value * with their frequency.//from www . j a va 2 s . c o m * * @param fieldName The Lucene field name * @param searchValue The value to search for. Could be "". * @param maxNumberOfTerms Max number of term's values to look in the index. For large catalogue * this value should be increased in order to get better results. If this * value is too high, then looking for terms could take more times. The use * of good analyzer should allow to reduce the number of useless values like * (a, the, ...). * @param threshold Minimum frequency for a term to be returned. * @return An unsorted and unordered list of terms with their frequency. * @throws Exception */ public Collection<TermFrequency> getTermsFequency(String fieldName, String searchValue, int maxNumberOfTerms, int threshold, String language) throws Exception { Collection<TermFrequency> termList = new ArrayList<TermFrequency>(); IndexAndTaxonomy indexAndTaxonomy = getNewIndexReader(null); String searchValueWithoutWildcard = searchValue.replaceAll("[*?]", ""); String analyzedSearchValue = LuceneSearcher.analyzeText(fieldName, searchValueWithoutWildcard, SearchManager.getAnalyzer(language, true)); boolean startsWithOnly = !searchValue.startsWith("*") && searchValue.endsWith("*"); try { GeonetworkMultiReader multiReader = indexAndTaxonomy.indexReader; @SuppressWarnings("resource") SlowCompositeReaderWrapper atomicReader = new SlowCompositeReaderWrapper(multiReader); Terms terms = atomicReader.terms(fieldName); if (terms != null) { TermsEnum termEnum = terms.iterator(null); int i = 1; BytesRef term = termEnum.next(); while (term != null && i++ < maxNumberOfTerms) { String text = term.utf8ToString(); if (termEnum.docFreq() >= threshold) { String analyzedText = LuceneSearcher.analyzeText(fieldName, text, SearchManager.getAnalyzer(language, true)); if ((startsWithOnly && StringUtils.startsWithIgnoreCase(analyzedText, analyzedSearchValue)) || (!startsWithOnly && StringUtils.containsIgnoreCase(analyzedText, analyzedSearchValue)) || (startsWithOnly && StringUtils.startsWithIgnoreCase(text, searchValueWithoutWildcard)) || (!startsWithOnly && StringUtils.containsIgnoreCase(text, searchValueWithoutWildcard))) { TermFrequency freq = new TermFrequency(text, termEnum.docFreq()); termList.add(freq); } } term = termEnum.next(); } } } finally { releaseIndexReader(indexAndTaxonomy); } return termList; }
From source file:org.hippoecm.frontend.editor.plugins.resource.MimeTypeHelper.java
/** * Checks whether the given MIME type indicates an image. * * @param mimeType the MIME type to check * @return true if the given MIME type indicates an image, false otherwise. *//*from w ww .j a v a2s.co m*/ public static boolean isImageMimeType(String mimeType) { return StringUtils.startsWithIgnoreCase(mimeType, MIMETYPE_IMAGE_PREFIX); }
From source file:org.jahia.modules.serversettings.flow.WebprojectHandler.java
private void validateSite(MessageContext messageContext, ImportInfo infos) { try {/* w w w .j a va 2 s . com*/ infos.setSiteTitleInvalid(StringUtils.isEmpty(infos.getSiteTitle())); String siteKey = infos.getSiteKey(); if (infos.isSite()) { boolean valid = sitesService.isSiteKeyValid(siteKey); if (!valid) { messageContext.addMessage(new MessageBuilder().error().source("siteKey") .code("serverSettings.manageWebProjects.invalidSiteKey").build()); } if (valid && sitesService.getSiteByKey(siteKey) != null) { messageContext.addMessage(new MessageBuilder().error().source("siteKey") .code("serverSettings.manageWebProjects.siteKeyExists").build()); } String serverName = infos.getSiteServername(); if (infos.isLegacyImport() && (StringUtils.startsWithIgnoreCase(serverName, "http://") || StringUtils.startsWithIgnoreCase(serverName, "https://"))) { serverName = StringUtils.substringAfter(serverName, "://"); infos.setSiteServername(serverName); } valid = sitesService.isServerNameValid(serverName); if (!valid) { messageContext.addMessage(new MessageBuilder().error().source("siteKey") .code("serverSettings.manageWebProjects.invalidServerName").build()); } if (valid && !Url.isLocalhost(serverName) && sitesService.getSite(serverName) != null) { messageContext.addMessage(new MessageBuilder().error().source("siteKey") .code("serverSettings.manageWebProjects.serverNameExists").build()); } } } catch (JahiaException e) { logger.error(e.getMessage(), e); } }
From source file:org.jenkinsci.plugins.pipeline.maven.util.XmlUtils.java
/** * Relativize path//w w w . j av a 2s . com * <p> * TODO replace all the workarounds (JENKINS-44088, JENKINS-46084, mac special folders...) by a unique call to * {@link File#getCanonicalPath()} on the workspace for the whole "MavenSpyLogProcessor#processMavenSpyLogs" code block. * We donb't want to pay an RPC call to {@link File#getCanonicalPath()} each time. * * @return relativized path * @throws IllegalArgumentException if {@code other} is not a {@code Path} that can be relativized * against this path * @see java.nio.file.Path#relativize(Path) */ @Nonnull public static String getPathInWorkspace(@Nonnull final String absoluteFilePath, @Nonnull FilePath workspace) { boolean windows = isWindows(workspace); final String workspaceRemote = workspace.getRemote(); String sanitizedAbsoluteFilePath; String sanitizedWorkspaceRemote; if (windows) { // sanitize to workaround JENKINS-44088 sanitizedWorkspaceRemote = workspaceRemote.replace('/', '\\'); sanitizedAbsoluteFilePath = absoluteFilePath.replace('/', '\\'); } else if (workspaceRemote.startsWith("/var/") && absoluteFilePath.startsWith("/private/var/")) { // workaround MacOSX special folders path // eg String workspace = "/var/folders/lq/50t8n2nx7l316pwm8gc_2rt40000gn/T/jenkinsTests.tmp/jenkins3845105900446934883test/workspace/build-on-master-with-tool-provided-maven"; // eg String absolutePath = "/private/var/folders/lq/50t8n2nx7l316pwm8gc_2rt40000gn/T/jenkinsTests.tmp/jenkins3845105900446934883test/workspace/build-on-master-with-tool-provided-maven/pom.xml"; sanitizedWorkspaceRemote = workspaceRemote; sanitizedAbsoluteFilePath = absoluteFilePath.substring("/private".length()); } else { sanitizedAbsoluteFilePath = absoluteFilePath; sanitizedWorkspaceRemote = workspaceRemote; } if (StringUtils.startsWithIgnoreCase(sanitizedAbsoluteFilePath, sanitizedWorkspaceRemote)) { // OK } else if (sanitizedWorkspaceRemote.contains("/workspace/") && sanitizedAbsoluteFilePath.contains("/workspace/")) { // workaround JENKINS-46084 // sanitizedAbsoluteFilePath = '/app/Jenkins/home/workspace/testjob/pom.xml' // sanitizedWorkspaceRemote = '/var/lib/jenkins/workspace/testjob' sanitizedAbsoluteFilePath = "/workspace/" + StringUtils.substringAfter(sanitizedAbsoluteFilePath, "/workspace/"); sanitizedWorkspaceRemote = "/workspace/" + StringUtils.substringAfter(sanitizedWorkspaceRemote, "/workspace/"); } else if (sanitizedWorkspaceRemote.endsWith("/workspace") && sanitizedAbsoluteFilePath.contains("/workspace/")) { // workspace = "/var/lib/jenkins/jobs/Test-Pipeline/workspace"; // absolutePath = "/storage/jenkins/jobs/Test-Pipeline/workspace/pom.xml"; sanitizedAbsoluteFilePath = "workspace/" + StringUtils.substringAfter(sanitizedAbsoluteFilePath, "/workspace/"); sanitizedWorkspaceRemote = "workspace/"; } else { throw new IllegalArgumentException( "Cannot relativize '" + absoluteFilePath + "' relatively to '" + workspace.getRemote() + "'"); } String relativePath = StringUtils.removeStartIgnoreCase(sanitizedAbsoluteFilePath, sanitizedWorkspaceRemote); String fileSeparator = windows ? "\\" : "/"; if (relativePath.startsWith(fileSeparator)) { relativePath = relativePath.substring(fileSeparator.length()); } LOGGER.log(Level.FINEST, "getPathInWorkspace({0}, {1}: {2}", new Object[] { absoluteFilePath, workspaceRemote, relativePath }); return relativePath; }
From source file:org.kuali.kra.questionnaire.answer.QuestionnaireAnswerServiceImpl.java
protected boolean isAnswerMatched(String condition, String parentAnswer, String conditionValue) { boolean valid = false; if (ConditionType.CONTAINS_TEXT.getCondition().equals(condition)) { valid = StringUtils.containsIgnoreCase(parentAnswer, conditionValue); } else if (ConditionType.BEGINS_WITH_TEXT.getCondition().equals(condition)) { valid = (StringUtils.startsWithIgnoreCase(parentAnswer, conditionValue)); } else if (ConditionType.ENDS_WITH_TEXT.getCondition().equals(condition)) { valid = (StringUtils.endsWithIgnoreCase(parentAnswer, conditionValue)); } else if (ConditionType.MATCH_TEXT.getCondition().equals(condition)) { valid = parentAnswer.equalsIgnoreCase(conditionValue); } else if (Integer.parseInt(condition) >= 5 && Integer.parseInt(condition) <= 10) { valid = (ConditionType.LESS_THAN_NUMBER.getCondition().equals(condition) && (Integer.parseInt(parentAnswer) < Integer.parseInt(conditionValue))) || (ConditionType.LESS_THAN_OR_EQUALS_NUMBER.getCondition().equals(condition) && (Integer.parseInt(parentAnswer) <= Integer.parseInt(conditionValue))) || (ConditionType.EQUALS_NUMBER.getCondition().equals(condition) && (Integer.parseInt(parentAnswer) == Integer.parseInt(conditionValue))) || (ConditionType.NOT_EQUAL_TO_NUMBER.getCondition().equals(condition) && (Integer.parseInt(parentAnswer) != Integer.parseInt(conditionValue))) || (ConditionType.GREATER_THAN_OR_EQUALS_NUMBER.getCondition().equals(condition) && (Integer.parseInt(parentAnswer) >= Integer.parseInt(conditionValue))) || (ConditionType.GREATER_THAN_NUMBER.getCondition().equals(condition) && (Integer.parseInt(parentAnswer) > Integer.parseInt(conditionValue))); } else if (Integer.parseInt(condition) >= 11) { final DateFormat dateFormat = new SimpleDateFormat(Constants.DEFAULT_DATE_FORMAT_PATTERN); try {/*from ww w .j a v a 2 s. com*/ Date date1 = new Date(dateFormat.parse(parentAnswer).getTime()); Date date2 = new Date(dateFormat.parse(conditionValue).getTime()); valid = (ConditionType.BEFORE_DATE.getCondition().equals(condition) && (date1.before(date2))) || (ConditionType.AFTER_DATE.getCondition().equals(condition) && (date1.after(date2))); } catch (Exception e) { } } return valid; }