List of usage examples for org.apache.commons.lang StringUtils remove
public static String remove(String str, char remove)
Removes all occurrences of a character from within the source string.
From source file:org.apache.wookie.tests.functional.FolderLocalizationTest.java
@BeforeClass public static void setup() { // Set up the client and enable cookies client = new HttpClient(); client.getParams().setCookiePolicy(CookiePolicy.RFC_2109); get = new GetMethod(); // Create a widget instance localized to Yorkshire English try {/*from w w w . j a v a 2 s . co m*/ PostMethod post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID); post.setQueryString("api_key=" + API_KEY_VALID + "&widgetid=" + LOCALIZED_WIDGET + "&userid=foldertest1&shareddatakey=foldertest1&locale=en-gb-yorks"); client.executeMethod(post); WIDGET_START_URL_ROOT = getStartFile(post.getResponseBodyAsString()); // We have to load the start file in order to start the session getResource(WIDGET_START_URL_ROOT); // take off the resource bit String path = WIDGET_START_URL_ROOT.substring(WIDGET_START_URL_ROOT.indexOf("locales")); WIDGET_START_URL_ROOT = StringUtils.remove(WIDGET_START_URL_ROOT, path); post.releaseConnection(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.apache.wookie.tests.functional.FolderLocalizationTest.java
@Test // Request the instance with different locales, and check that the correct // resources are returned in each case (i.e. that the locale of the instance has changed) public void updateLocalizedResources() { // Update the widget instance localized to French try {/*from ww w. jav a 2 s . c om*/ PostMethod post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID); post.setQueryString("api_key=" + API_KEY_VALID + "&widgetid=" + LOCALIZED_WIDGET + "&userid=foldertest1&shareddatakey=foldertest1&locale=fr"); client.executeMethod(post); WIDGET_START_URL_ROOT = getStartFile(post.getResponseBodyAsString()); // We have to load the start file in order to start the session getResource(WIDGET_START_URL_ROOT); // take off the resource bit String path = WIDGET_START_URL_ROOT.substring(WIDGET_START_URL_ROOT.indexOf("locales")); WIDGET_START_URL_ROOT = StringUtils.remove(WIDGET_START_URL_ROOT, path); post.releaseConnection(); } catch (Exception e) { e.printStackTrace(); } String resource = "index.htm"; String url = WIDGET_START_URL_ROOT + resource; assertEquals(WIDGET_START_URL_ROOT + "locales/fr/index.htm", getResource(url)); // Update the widget instance localized to English try { PostMethod post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID); post.setQueryString("api_key=" + API_KEY_VALID + "&widgetid=" + LOCALIZED_WIDGET + "&userid=foldertest1&shareddatakey=foldertest1&locale=en"); client.executeMethod(post); WIDGET_START_URL_ROOT = getStartFile(post.getResponseBodyAsString()); // We have to load the start file in order to start the session getResource(WIDGET_START_URL_ROOT); // take off the resource bit String path = WIDGET_START_URL_ROOT.substring(WIDGET_START_URL_ROOT.indexOf("locales")); WIDGET_START_URL_ROOT = StringUtils.remove(WIDGET_START_URL_ROOT, path); post.releaseConnection(); } catch (Exception e) { e.printStackTrace(); } resource = "index.htm"; url = WIDGET_START_URL_ROOT + resource; assertEquals(WIDGET_START_URL_ROOT + "locales/en/index.htm", getResource(url)); // Update the widget instance unlocalized (expecting the default locale here to be "en") try { PostMethod post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID); post.setQueryString("api_key=" + API_KEY_VALID + "&widgetid=" + LOCALIZED_WIDGET + "&userid=foldertest1&shareddatakey=foldertest1"); client.executeMethod(post); WIDGET_START_URL_ROOT = getStartFile(post.getResponseBodyAsString()); // We have to load the start file in order to start the session getResource(WIDGET_START_URL_ROOT); // take off the resource bit String path = WIDGET_START_URL_ROOT.substring(WIDGET_START_URL_ROOT.indexOf("locales")); WIDGET_START_URL_ROOT = StringUtils.remove(WIDGET_START_URL_ROOT, path); post.releaseConnection(); } catch (Exception e) { e.printStackTrace(); } resource = "index.htm"; url = WIDGET_START_URL_ROOT + resource; assertEquals(WIDGET_START_URL_ROOT + "locales/en/index.htm", getResource(url)); }
From source file:org.apereo.lap.kettle.KettleConfiguration.java
private void configureSharedObjects() throws KettleException, IOException { // gets existing shared.xml objects, or creates a new object to store properties sharedObjects = new SharedObjects(); // process and store each defined database connection for (String databaseConnectionName : kettleProperties.getDatabaseConnectionNames()) { // must remove existing connection, as multiple connection names are allowed DatabaseMeta existingDatabaseConnection = sharedObjects.getSharedDatabase(databaseConnectionName); if (existingDatabaseConnection != null) { sharedObjects.removeObject(existingDatabaseConnection); }//from w ww . jav a 2 s.c om // remove the prefix from the url property String databaseName = StringUtils.remove(datasourceProperties.getTemp().getUrl(), "jdbc:h2:"); // create a fully-configured H2 database connection H2DatabaseMeta h2DatabaseMeta = new H2DatabaseMeta(); h2DatabaseMeta.setName(databaseConnectionName); h2DatabaseMeta.setUsername(datasourceProperties.getTemp().getUsername()); h2DatabaseMeta.setPassword(datasourceProperties.getTemp().getPassword()); h2DatabaseMeta.setDatabaseName(databaseName); h2DatabaseMeta.setAccessType(DatabaseMeta.TYPE_ACCESS_NATIVE); h2DatabaseMeta.setPluginId("H2"); // create new default database container DatabaseMeta databaseMeta = new DatabaseMeta(); // set the interface to the H2 configuration databaseMeta.setDatabaseInterface(h2DatabaseMeta); // store the database connection in the shared objects sharedObjects.storeObject(databaseMeta); logger.info("Created shared database connection '" + databaseConnectionName + "'"); } // save the new configuration to shared.xml // NOTE: since we effectively cache the SharedObjects in memory does it make sense to // save them to disk? e.g. does it lead to unnecessary brittleness in tests/deploy // environments? sharedObjects.saveToFile(); logger.info("Shared objects saved to: " + sharedObjects.getFilename()); }
From source file:org.apereo.lap.services.pipeline.KettleBasePipelineProcessor.java
/** * Creates shared connections for use in transformations and jobs * Uses connection properties from db.properties with a prefix of "db." * Stores the dynamic configuration in a shared.xml file * /*from w w w . jav a 2s. c om*/ * Currently, only an H2 database is configured */ private void createSharedDatabaseConnections() { Configuration configuration = configurationService.getConfig(); try { if (databaseConnectionNames == null) { setDatabaseConnectionNames(); } // gets existing shared.xml objects, or creates a new object to store properties sharedObjects = new SharedObjects(); // process and store each defined database connection for (String databaseConnectionName : databaseConnectionNames) { // must remove existing connection, as multiple connection names are allowed DatabaseMeta existingDatabaseConnection = sharedObjects.getSharedDatabase(databaseConnectionName); if (existingDatabaseConnection != null) { sharedObjects.removeObject(existingDatabaseConnection); } // remove the prefix from the url property String databaseName = StringUtils.remove(configuration.getString("db.url", ""), "jdbc:h2:"); // create a fully-configured H2 database connection H2DatabaseMeta h2DatabaseMeta = new H2DatabaseMeta(); h2DatabaseMeta.setName(databaseConnectionName); h2DatabaseMeta.setUsername(configuration.getString("db.username", "")); h2DatabaseMeta.setPassword(configuration.getString("db.password", "")); h2DatabaseMeta.setDatabaseName(databaseName); h2DatabaseMeta.setAccessType(DatabaseMeta.TYPE_ACCESS_NATIVE); //h2DatabaseMeta.setDatabasePortNumberString(null); h2DatabaseMeta.setPluginId("H2"); // create new default database container DatabaseMeta databaseMeta = new DatabaseMeta(); // set the interface to the H2 configuration databaseMeta.setDatabaseInterface(h2DatabaseMeta); // store the database connection in the shared objects sharedObjects.storeObject(databaseMeta); logger.info("Created shared database connection '" + databaseConnectionName + "'"); } // save the new configuration to shared.xml sharedObjects.saveToFile(); logger.info("Saved new shared database connections to file."); } catch (Exception e) { logger.error("An error occurred dynamically configuring the shared database connection. Error: " + e, e); } }
From source file:org.artifactory.api.maven.MavenArtifactInfo.java
public static MavenArtifactInfo fromRepoPath(RepoPath repoPath) { String groupId, artifactId, version, type = MavenArtifactInfo.NA, classifier = MavenArtifactInfo.NA; String path = repoPath.getPath(); String fileName = repoPath.getName(); //The format of the relative path in maven is a/b/c/artifactId/baseVer/fileName where //groupId="a.b.c". We split the path to elements and analyze the needed fields. LinkedList<String> pathElements = new LinkedList<>(); StringTokenizer tokenizer = new StringTokenizer(path, "/"); while (tokenizer.hasMoreTokens()) { pathElements.add(tokenizer.nextToken()); }// ww w .j a v a 2s.c o m //Sanity check, we need groupId, artifactId and version if (pathElements.size() < 3) { log.debug( "Cannot build MavenArtifactInfo from '{}'. The groupId, artifactId and version are unreadable.", repoPath); return new MavenArtifactInfo(); } //Extract the version, artifactId and groupId int pos = pathElements.size() - 2; // one before the last path element version = pathElements.get(pos--); artifactId = pathElements.get(pos--); StringBuilder groupIdBuff = new StringBuilder(); for (; pos >= 0; pos--) { if (groupIdBuff.length() != 0) { groupIdBuff.insert(0, '.'); } groupIdBuff.insert(0, pathElements.get(pos)); } groupId = groupIdBuff.toString(); //Extract the type and classifier except for metadata files boolean metaData = NamingUtils.isMetadata(fileName); if (!metaData) { if (MavenNaming.isUniqueSnapshotFileName(fileName)) { version = StringUtils.remove(version, "-" + MavenNaming.SNAPSHOT); version = version + "-" + MavenNaming.getUniqueSnapshotVersionTimestampAndBuildNumber(fileName); } type = StringUtils.substring(fileName, artifactId.length() + version.length() + 2); int versionStartIndex = StringUtils.indexOf(fileName, "-", artifactId.length()) + 1; int classifierStartIndex = StringUtils.indexOf(fileName, "-", versionStartIndex + version.length()); if (classifierStartIndex >= 0) { Set<String> customMavenTypes = getMavenCustomTypes(); for (String customMavenType : customMavenTypes) { if (StringUtils.endsWith(fileName, customMavenType)) { classifier = StringUtils.remove(type, "." + customMavenType); type = customMavenType; break; } } if (MavenArtifactInfo.NA.equals(classifier)) { int typeDotStartIndex = StringUtils.lastIndexOf(type, "."); classifier = StringUtils.substring(type, 0, typeDotStartIndex); type = StringUtils.substring(type, classifier.length() + 1); } } } return new MavenArtifactInfo(groupId, artifactId, version, classifier, type); }
From source file:org.artifactory.api.search.gavc.GavcSearchControls.java
@Override public boolean isWildcardsOnly() { String expression = StringUtils.remove(getSearchExpression(), '-'); return StringUtils.isBlank(expression) || isWildcardsOnly(expression); }
From source file:org.artifactory.maven.MavenMetadataCalculator.java
private Collection<SnapshotVersion> getFolderItemSnapshotVersions(Collection<ItemNode> folderItems) { List<SnapshotVersion> snapshotVersionsToReturn = Lists.newArrayList(); Map<SnapshotVersionType, ModuleInfo> latestSnapshotVersions = Maps.newHashMap(); for (ItemNode folderItem : folderItems) { String folderItemPath = folderItem.getItemInfo().getRelPath(); if (MavenNaming.isUniqueSnapshot(folderItemPath)) { ModuleInfo folderItemModuleInfo; if (MavenNaming.isPom(folderItemPath)) { folderItemModuleInfo = ModuleInfoUtils.moduleInfoFromDescriptorPath(folderItemPath, RepoLayoutUtils.MAVEN_2_DEFAULT); } else { folderItemModuleInfo = ModuleInfoUtils.moduleInfoFromArtifactPath(folderItemPath, RepoLayoutUtils.MAVEN_2_DEFAULT); }/*from ww w . j av a 2 s.c o m*/ if (!folderItemModuleInfo.isValid() || !folderItemModuleInfo.isIntegration()) { continue; } SnapshotVersionType folderItemSnapshotVersionType = new SnapshotVersionType( folderItemModuleInfo.getExt(), folderItemModuleInfo.getClassifier()); if (latestSnapshotVersions.containsKey(folderItemSnapshotVersionType)) { SnapshotComparator snapshotComparator = createSnapshotComparator(); ModuleInfo latestSnapshotVersion = latestSnapshotVersions.get(folderItemSnapshotVersionType); if (snapshotComparator.compare(folderItemModuleInfo, latestSnapshotVersion) > 0) { latestSnapshotVersions.put(folderItemSnapshotVersionType, folderItemModuleInfo); } } else { latestSnapshotVersions.put(folderItemSnapshotVersionType, folderItemModuleInfo); } } } for (ModuleInfo latestSnapshotVersion : latestSnapshotVersions.values()) { SnapshotVersion snapshotVersion = new SnapshotVersion(); snapshotVersion.setClassifier(latestSnapshotVersion.getClassifier()); snapshotVersion.setExtension(latestSnapshotVersion.getExt()); String fileItegRev = latestSnapshotVersion.getFileIntegrationRevision(); snapshotVersion.setVersion(latestSnapshotVersion.getBaseRevision() + "-" + fileItegRev); snapshotVersion.setUpdated(StringUtils.remove(StringUtils.substringBefore(fileItegRev, "-"), '.')); snapshotVersionsToReturn.add(snapshotVersion); } return snapshotVersionsToReturn; }
From source file:org.artifactory.maven.MavenModelUtils.java
/** * Build custom maven-metadata.xml according to a specific version. * * @param moduleInfo The original {@code ModuleInfo} to assemble the maven metadata according to the same * gid,aid,and version, {@link org.apache.maven.artifact.repository.metadata.Versioning#setLastUpdatedTimestamp(java.util.Date)} is updated to now. and * the build number and timestamp in the {@link org.apache.maven.artifact.repository.metadata.Snapshot} is set according to the name. * @param fileName The file name// w w w.ja va 2 s . c o m * @return The custom maven-metadata.xml */ public static Metadata buildSnapshotMavenMetadata(ModuleInfo moduleInfo, String fileName) { Metadata metadata = new Metadata(); metadata.setGroupId(moduleInfo.getOrganization()); metadata.setArtifactId(moduleInfo.getModule()); metadata.setVersion(moduleInfo.getBaseRevision() + "-" + moduleInfo.getFolderIntegrationRevision()); Versioning versioning = new Versioning(); metadata.setVersioning(versioning); versioning.setLastUpdatedTimestamp(new Date()); Snapshot snapshot = new Snapshot(); versioning.setSnapshot(snapshot); snapshot.setBuildNumber(MavenNaming.getUniqueSnapshotVersionBuildNumber(fileName)); snapshot.setTimestamp(MavenNaming.getUniqueSnapshotVersionTimestamp(fileName)); if (ConstantValues.mvnMetadataVersion3Enabled.getBoolean()) { SnapshotVersion snapshotVersion = new SnapshotVersion(); snapshotVersion.setUpdated(StringUtils.remove(snapshot.getTimestamp(), '.')); snapshotVersion .setVersion(moduleInfo.getBaseRevision() + "-" + moduleInfo.getFileIntegrationRevision()); //Should always be a pom, since this method is called only by PropertiesAddonImpl.assembleDynamicMetadata snapshotVersion.setExtension(moduleInfo.getExt()); versioning.setSnapshotVersions(Lists.newArrayList(snapshotVersion)); } return metadata; }
From source file:org.artifactory.repo.webdav.methods.MoveMethod.java
@Override public void handle(ArtifactoryRequest request, ArtifactoryResponse response) throws IOException { log.debug("Handling {}", getName()); RepoPath repoPath = request.getRepoPath(); if (StringUtils.isEmpty(repoPath.getPath())) { response.sendError(HttpStatus.SC_BAD_REQUEST, "Cannot perform MOVE action on a repository. " + "Please specify a valid path", log); return;//from www. java 2 s . co m } String destination = URLDecoder.decode(request.getHeader("Destination"), "UTF-8"); if (StringUtils.isEmpty(destination)) { response.sendError(HttpStatus.SC_BAD_REQUEST, "Header 'Destination' is required.", log); return; } String targetPathWithoutContextUrl = StringUtils.remove(destination, request.getServletContextUrl()); String targetPathParent = PathUtils.getParent(targetPathWithoutContextUrl); RepoPath targetPath = InternalRepoPathFactory.create(targetPathParent); if (!authService.canDelete(repoPath) || !authService.canDeploy(targetPath)) { response.sendError(HttpStatus.SC_FORBIDDEN, "Insufficient permissions.", log); return; } MoveMultiStatusHolder status; status = getMoveMultiStatusHolder(repoPath, targetPath, request); if (!status.hasWarnings() && !status.hasErrors()) { response.sendSuccess(); } else { response.sendError(status); } }
From source file:org.artifactory.repo.webdav.WebdavServiceImpl.java
@Override public void handleMove(ArtifactoryRequest request, ArtifactoryResponse response) throws IOException { RepoPath repoPath = request.getRepoPath(); if (StringUtils.isEmpty(repoPath.getPath())) { response.sendError(HttpStatus.SC_BAD_REQUEST, "Cannot perform MOVE action on a repository. " + "Please specify a valid path", log); return;//from www . j a v a2 s.co m } String destination = URLDecoder.decode(request.getHeader("Destination"), "UTF-8"); if (StringUtils.isEmpty(destination)) { response.sendError(HttpStatus.SC_BAD_REQUEST, "Header 'Destination' is required.", log); return; } String targetPathWithoutContextUrl = StringUtils.remove(destination, request.getServletContextUrl()); String targetPathParent = PathUtils.getParent(targetPathWithoutContextUrl); RepoPath targetPath = InternalRepoPathFactory.create(targetPathParent); if (!authService.canDelete(repoPath) || !authService.canDeploy(targetPath)) { response.sendError(HttpStatus.SC_FORBIDDEN, "Insufficient permissions.", log); return; } MoveMultiStatusHolder status = repoService.move(repoPath, targetPath, false, true, true); if (!status.hasWarnings() && !status.hasErrors()) { response.sendSuccess(); } else { response.sendError(status); } }