List of usage examples for org.apache.commons.lang3 StringUtils substringBefore
public static String substringBefore(final String str, final String separator)
Gets the substring before the first occurrence of a separator.
From source file:com.thruzero.common.jsf.support.beans.dialog.AbstractAboutApplicationBean.java
public String getJarRows() { StringBuffer result = new StringBuffer(); try {/*from w ww.j a va 2 s .c o m*/ File webInfDir = FacesUtils.getWebInfDir(); if (webInfDir != null) { File libDir = new File(webInfDir, "lib"); String[] extensions = { "jar" }; @SuppressWarnings("unchecked") // FileUtils isn't generic Collection<File> jarFiles = FileUtils.listFiles(libDir, extensions, false); StringMap aboutLibs = ConfigLocator.locate() .getSectionAsStringMap(AboutBoxConfigKeys.ABOUT_LIBS_SECTION); if (aboutLibs == null) { result.append("<br/><span style=\"color:red;\">The " + AboutBoxConfigKeys.ABOUT_LIBS_SECTION + " config section was not found.</span>"); } else { for (File jarFile : jarFiles) { String version = StringUtils.substringAfterLast(jarFile.getName(), "-"); version = StringUtils.remove(version, ".jar"); String aboutKey = StringUtils.substringBeforeLast(jarFile.getName(), "-"); // make sure it's the full version number (e.g., "hibernate-c3p0-3.5.0-Final" at this point will be "Final". Need to back up a segment to get the version number. String versComp = StringUtils.substringBefore(version, "."); if (!StringUtils.isNumeric(versComp)) { String version2 = StringUtils.substringAfterLast(aboutKey, "-"); versComp = StringUtils.substringBefore(version2, "."); if (StringUtils.isNumeric(versComp)) { aboutKey = StringUtils.substringBeforeLast(aboutKey, "-"); version = version2 + "-" + version; } else { continue; // give up on this one } } // get config value for this jar file if (StringUtils.isNotEmpty(aboutKey) && StringUtils.isNotEmpty(version) && aboutLibs.containsKey(aboutKey)) { String href = aboutLibs.get(aboutKey); aboutKey = StringUtils.remove(aboutKey, "-core"); result.append(TableUtils.createSimpleFormRow(aboutKey, href, version)); } } } } } catch (Exception e) { // don't let the about box crash the app } return result.toString(); }
From source file:com.cognifide.qa.bb.scope.frame.FramePath.java
private FramePath addFrame(String path) { if (StringUtils.isEmpty(path)) { return this; }//from www . ja va 2 s .c om final String firstPart = StringUtils.substringBefore(path, "/"); final String rest = StringUtils.substringAfter(path, "/"); List<FrameDescriptor> modifiedLocation = new ArrayList<>(frames); if (firstPart.isEmpty()) { modifiedLocation.clear(); } else if (firstPart.matches("\\$[0-9]+")) { final int index = Integer.parseInt(firstPart.substring(1)); modifiedLocation.add(new IndexedFrame(index)); } else if ("$cq".equals(firstPart)) { modifiedLocation.clear(); modifiedLocation.add(AemContentFrame.INSTANCE); } else if ("..".equals(firstPart) && !modifiedLocation.isEmpty()) { modifiedLocation.remove(modifiedLocation.size() - 1); } else { modifiedLocation.add(new NamedFrame(firstPart)); } return new FramePath(modifiedLocation).addFrame(rest); }
From source file:info.magnolia.security.app.dialog.field.validator.UniqueUserNameValidator.java
private String getRealmName(String path) { path = path.substring(1); // remove slash from the beginning of the string int idx = path.indexOf("/"); if (idx == -1) { return path; }//from www . jav a 2 s . co m return StringUtils.substringBefore(path, "/"); }
From source file:io.wcm.handler.url.impl.modes.DefaultUrlMode.java
/** * Gets site root level path of a site./*from w ww.ja v a 2s .c o m*/ * @param path Path of page within the site * @param rootLevel Level of root page * @return Site root path for the site. The path is not checked for validness. */ private String getRootPath(String path, int rootLevel) { String rootPath = Text.getAbsoluteParent(path, rootLevel); // strip off everything after first "." - root path may be passed with selectors/extension which is not relevant if (StringUtils.contains(rootPath, ".")) { rootPath = StringUtils.substringBefore(rootPath, "."); } return rootPath; }
From source file:cool.pandora.modeller.ui.handlers.text.PatchAreasHandler.java
@Override public void execute() { final String message = ApplicationContextUtil.getMessage("bag.message.areapatched"); final DefaultBag bag = bagView.getBag(); final Map<String, BagInfoField> map = bag.getInfo().getFieldMap(); final URI canvasContainerURI = IIIFObjectURI.getCanvasContainerURI(map); final URI lineContainerIRI = TextObjectURI.getLineContainerURI(map); final String collectionPredicate = "http://iiif.io/api/text#hasLines"; final String url = bag.gethOCRResource(); List<String> pageIdList = null; final List<String> areaIdList; Map<String, List<String>> lineIdmap = null; Map<String, String> bboxmap = null; final Map<String, String> canvasPageMap; final Map<String, String> pageIdMap; InputStream rdfBody;/*www .ja v a 2 s.c om*/ try { final hOCRData hocr = DocManifestBuilder.gethOCRProjectionFromURL(url); pageIdList = getPageIdList(hocr); areaIdList = getAreaIdList(hocr); lineIdmap = NodeMap.getLineIdMap(hocr, areaIdList); bboxmap = NodeMap.getBBoxAreaMap(hocr, areaIdList); } catch (final IOException e) { e.printStackTrace(); } canvasPageMap = getCanvasPageMap(pageIdList, canvasContainerURI); pageIdMap = getPageIdMap(pageIdList); assert lineIdmap != null; final List<String> areaKeyList = new ArrayList<>(lineIdmap.keySet()); for (final String areaId : areaKeyList) { final URI areaObjectURI = TextObjectURI.getAreaObjectURI(map, areaId); assert canvasPageMap != null; final String canvasURI = canvasPageMap.get(StringUtils.substringBefore(areaId, "_")); assert pageIdMap != null; final String hOCRAreaId = "block_" + areaId; final String bbox = bboxmap.get(hOCRAreaId); final String region = Region.region().bbox(bbox).build(); final String canvasRegionURI = CanvasRegionURI.regionuri().region(region).canvasURI(canvasURI).build(); rdfBody = TextSequenceMetadata.getTextSequenceMetadata(lineIdmap, areaId, canvasRegionURI, collectionPredicate, lineContainerIRI); try { ModellerClient.doPatch(areaObjectURI, rdfBody); ApplicationContextUtil.addConsoleMessage(message + " " + areaObjectURI); } catch (final ModellerClientFailedException e) { ApplicationContextUtil.addConsoleMessage(getMessage(e)); } } bagView.getControl().invalidate(); }
From source file:net.siegmar.japtproxy.fetcher.HttpClientConfigurer.java
protected Credentials buildCredentials(final String userInfo) throws InitializationException { final String username = StringUtils.substringBefore(userInfo, ":"); final String password = StringUtils.substringAfter(userInfo, ":"); return username.contains("\\") ? buildNTCredentials(username, password) : new UsernamePasswordCredentials(username, password); }
From source file:eu.openanalytics.rsb.data.FileResultStore.java
@PreAuthorize("hasPermission(#applicationName, 'APPLICATION_USER')") public Collection<PersistedResult> findByApplicationName(final String applicationName, final String userName) { final File[] resultFiles = getResultsDirectory(applicationName, userName).listFiles(); if ((resultFiles == null) || (resultFiles.length == 0)) { return Collections.emptyList(); }//from w w w . j a v a2 s .c o m final Collection<PersistedResult> persistedResults = new ArrayList<PersistedResult>(); final List<File> sortedFiles = new ArrayList<File>(Arrays.asList(resultFiles)); Collections.sort(sortedFiles, LastModifiedFileComparator.LASTMODIFIED_REVERSE); for (final File resultFile : sortedFiles) { final UUID jobId = Util.safeUuidFromString(StringUtils.substringBefore(resultFile.getName(), ".")); if (jobId != null) { persistedResults.add(buildPersistedResult(applicationName, userName, jobId, resultFile)); } } return persistedResults; }
From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.DeckProfileFactory.java
@Override protected void setProfile(Profile profile, DeploymentConfiguration deploymentConfiguration, SpinnakerRuntimeSettings endpoints) { StringResource configTemplate = new StringResource(profile.getBaseContents()); UiSecurity uiSecurity = deploymentConfiguration.getSecurity().getUiSecurity(); Features features = deploymentConfiguration.getFeatures(); Map<String, String> bindings = new HashMap<>(); // Configure global settings bindings.put("gate.baseUrl", endpoints.getServices().getGate().getBaseUrl()); bindings.put("timezone", deploymentConfiguration.getTimezone()); bindings.put("version", deploymentConfiguration.getVersion()); // Configure feature-flags bindings.put("features.auth", Boolean.toString(features.isAuth(deploymentConfiguration))); bindings.put("features.chaos", Boolean.toString(features.isChaos())); bindings.put("features.fiat", Boolean.toString(features.isFiat())); bindings.put("features.jobs", Boolean.toString(features.isJobs())); // Configure Kubernetes KubernetesProvider kubernetesProvider = deploymentConfiguration.getProviders().getKubernetes(); bindings.put("kubernetes.default.account", kubernetesProvider.getPrimaryAccount()); bindings.put("kubernetes.default.namespace", "default"); bindings.put("kubernetes.default.proxy", "localhost:8001"); // Configure GCE GoogleProvider googleProvider = deploymentConfiguration.getProviders().getGoogle(); bindings.put("google.default.account", googleProvider.getPrimaryAccount()); bindings.put("google.default.region", "us-central1"); bindings.put("google.default.zone", "us-central1-f"); // Configure Appengine AppengineProvider appengineProvider = deploymentConfiguration.getProviders().getAppengine(); bindings.put("appengine.default.account", appengineProvider.getPrimaryAccount()); bindings.put("appengine.enabled", Boolean.toString(appengineProvider.getPrimaryAccount() != null)); // Configure Openstack OpenstackProvider openstackProvider = deploymentConfiguration.getProviders().getOpenstack(); bindings.put("openstack.default.account", openstackProvider.getPrimaryAccount()); if (openstackProvider.getPrimaryAccount() != null) { OpenstackAccount openstackAccount = (OpenstackAccount) accountService.getProviderAccount( deploymentConfiguration.getName(), "openstack", openstackProvider.getPrimaryAccount()); //Regions in openstack are a comma separated list. Use the first as primary. String firstRegion = StringUtils.substringBefore(openstackAccount.getRegions(), ","); bindings.put("openstack.default.region", firstRegion); }/*w w w .ja v a2s.c o m*/ profile.appendContents(configTemplate.setBindings(bindings).toString()) .setRequiredFiles(processRequiredFiles(uiSecurity)); }
From source file:net.sf.dynamicreports.examples.complex.applicationform.ApplicationFormDesign.java
private HorizontalListBuilder dateOfBirth(Date dateOfBirth) { String date = new SimpleDateFormat("MM/dd/yyyy").format(dateOfBirth); HorizontalListBuilder list = cmp.horizontalList().add(label("Date Of Birth", 5)) .add(textCell(StringUtils.substringBefore(date, "/"), 2), label("/", 1, centeredStyle)) .add(textCell(StringUtils.substringBetween(date, "/"), 2), label("/", 1, centeredStyle)) .add(textCell(StringUtils.substringAfterLast(date, "/"), 4)); return list;/* w w w .java 2 s. co m*/ }
From source file:com.mycompany.crawlertest.GrabManager.java
private void addNewURLs(GrabPage grabPage) { for (URL url : grabPage.getUrlList()) { if (url.toString().contains("#")) { try { url = new URL(StringUtils.substringBefore(url.toString(), "#")); } catch (MalformedURLException e) { }/* w ww .j a v a2 s . c o m*/ } submitNewURL(url, grabPage.getDepth() + 1); } }