List of usage examples for org.apache.commons.lang3 StringUtils removeEnd
public static String removeEnd(final String str, final String remove)
Removes a substring only if it is at the end of a source string, otherwise returns the source string.
A null source string will return null .
From source file:org.broadleafcommerce.test.BroadleafGenericGroovyXmlWebContextLoader.java
/** * Load a {@link MergeXmlWebApplicationContext} from the supplied {@link MergedContextConfiguration} * //from ww w. jav a2 s. com * <p>Implementation details: * * <ul> * <li>Calls {@link #validateMergedContextConfiguration(WebMergedContextConfiguration)} * to allow subclasses to validate the supplied configuration before proceeding.</li> * <li>Creates a {@link MergeXmlWebApplicationContext} instance.</li> * <li>If the supplied {@link MergeXmlWebApplicationContext} references a * {@linkplain MergeXmlWebApplicationContext#getParent() parent configuration}, * the corresponding {@link MergeXmlWebApplicationContext#getParentApplicationContext() * ApplicationContext} will be retrieved and * {@linkplain MergeXmlWebApplicationContext#setParent(ApplicationContext) set as the parent} * for the context created by this method.</li> * <li>Converts the patch locations into a single string to be set via * {@link MergeXmlWebApplicationContext#setPatchLocation(String)}</li> * <li>Sets the patch locations via {@link MergeXmlWebApplicationContext#setStandardLocationTypes(String)} * to the {@link StandardConfigLocations.TESTCONTEXTTYPE} for integration tests.</li> * <li>Delegates to {@link #configureWebResources} to create the {@link MockServletContext} and * set it in the {@code MergeXmlWebApplicationContext}.</li> * <li>Calls {@link #prepareContext} to allow for customizing the context before bean * definitions are loaded.</li> * <li>{@link ConfigurableApplicationContext#refresh Refreshes} the context and registers * a JVM shutdown hook for it.</li> * </ul></p> * * Refactored from {@link org.springframework.test.context.web.AbstractGenericWebContextLoader#loadContext(MergedContextConfiguration)} * * @return a new merge xml web application context * @see org.springframework.test.context.SmartContextLoader#loadContext(MergedContextConfiguration) * @see MergeXmlWebApplicationContext */ @Override public ConfigurableApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception { if (!(mergedConfig instanceof WebMergedContextConfiguration)) { throw new IllegalArgumentException( String.format( "Cannot load WebApplicationContext from non-web merged context configuration %s. " + "Consider annotating your test class with @WebAppConfiguration.", mergedConfig)); } WebMergedContextConfiguration webMergedConfig = (WebMergedContextConfiguration) mergedConfig; validateMergedContextConfiguration(webMergedConfig); MergeXmlWebApplicationContext context = new MergeXmlWebApplicationContext(); context.setPatchLocation(""); ApplicationContext parent = mergedConfig.getParentApplicationContext(); if (parent != null) { context.setParent(parent); context.setPatchLocation( StringUtils.removeEnd(((MergeXmlWebApplicationContext) parent).getPatchLocation(), "classpath:/bl-applicationContext-test.xml")); System.out.println(context.getPatchLocation()); } //Calls unique to Broadleaf Implementation of the Smart Context Loader // the ";classpath:/bl-applicationContext-test.xml" is required by all integration tests so we add it here. context.setPatchLocation(context.getPatchLocation() + StringUtils.join(mergedConfig.getLocations(), ";") + ";classpath:/bl-applicationContext-test.xml"); context.setStandardLocationTypes(StandardConfigLocations.TESTCONTEXTTYPE); configureWebResources(context, webMergedConfig); prepareContext(context, webMergedConfig); context.refresh(); context.registerShutdownHook(); return context; }
From source file:org.codice.ddf.test.common.UrlBuilder.java
private String cleanContextPath(String contextPath) { String cleanContextPath = StringUtils.removeEnd(contextPath, "/"); return StringUtils.removeStart(cleanContextPath, "/"); }
From source file:org.craftercms.core.url.impl.RemovePrefixAndSuffixUrlTransformer.java
@Override public String transformUrl(Context context, CachingOptions cachingOptions, String url) throws UrlTransformationException { if (StringUtils.isNotEmpty(prefix)) { url = StringUtils.removeStart(url, prefix); }//from www . j a v a2 s .c o m if (StringUtils.isNotEmpty(suffix)) { url = StringUtils.removeEnd(url, suffix); } return url; }
From source file:org.craftercms.engine.url.RemoveIndexUrlTransformer.java
@Override public String transformUrl(Context context, CachingOptions cachingOptions, String url) throws UrlTransformationException { return StringUtils.removeEnd(url, SiteProperties.getIndexFileName()); }
From source file:org.cryptomator.crypto.aes256.Aes256Cryptor.java
/** * @see #encryptPathComponent(String, SecretKey, CryptorIOSupport) *//*from ww w. j a v a2 s. c o m*/ private String decryptPathComponent(final String encrypted, final SecretKey key, CryptorIOSupport ioSupport) throws IllegalBlockSizeException, BadPaddingException, IOException { final String ivAndCiphertext; if (encrypted.endsWith(LONG_NAME_FILE_EXT)) { final String basename = StringUtils.removeEnd(encrypted, LONG_NAME_FILE_EXT); final String crc32 = StringUtils.substringBefore(basename, LONG_NAME_PREFIX_SEPARATOR); final String uuid = StringUtils.substringAfter(basename, LONG_NAME_PREFIX_SEPARATOR); final String metadataFilename = crc32 + METADATA_FILE_EXT; final LongFilenameMetadata metadata = this.getMetadata(ioSupport, metadataFilename); ivAndCiphertext = metadata.getEncryptedFilenameForUUID(UUID.fromString(uuid)); } else if (encrypted.endsWith(BASIC_FILE_EXT)) { ivAndCiphertext = StringUtils.removeEndIgnoreCase(encrypted, BASIC_FILE_EXT); } else { throw new IllegalArgumentException("Unsupported path component: " + encrypted); } final String partialIvStr = StringUtils.substringBefore(ivAndCiphertext, IV_PREFIX_SEPARATOR); final String ciphertext = StringUtils.substringAfter(ivAndCiphertext, IV_PREFIX_SEPARATOR); final ByteBuffer iv = ByteBuffer.allocate(AES_BLOCK_LENGTH); iv.put(ENCRYPTED_FILENAME_CODEC.decode(partialIvStr)); final Cipher cipher = this.aesCtrCipher(key, iv.array(), Cipher.DECRYPT_MODE); final byte[] encryptedBytes = ENCRYPTED_FILENAME_CODEC.decode(ciphertext); final byte[] paddedCleartextBytes = cipher.doFinal(encryptedBytes); // remove NULL padding (not valid in file names anyway) final int beginOfPadding = ArrayUtils.indexOf(paddedCleartextBytes, (byte) 0x00); if (beginOfPadding == -1) { return new String(paddedCleartextBytes, StandardCharsets.UTF_8); } else { final byte[] cleartextBytes = Arrays.copyOf(paddedCleartextBytes, beginOfPadding); return new String(cleartextBytes, StandardCharsets.UTF_8); } }
From source file:org.cryptomator.cryptofs.CryptoDirectoryStreamTest.java
License:asdf
@Before @SuppressWarnings("unchecked") public void setup() throws IOException { filenameCryptor = cryptorProvider.createNew().fileNameCryptor(); ciphertextDirPath = Mockito.mock(Path.class); FileSystem fs = Mockito.mock(FileSystem.class); Mockito.when(ciphertextDirPath.getFileSystem()).thenReturn(fs); FileSystemProvider provider = Mockito.mock(FileSystemProvider.class); Mockito.when(fs.provider()).thenReturn(provider); dirStream = Mockito.mock(DirectoryStream.class); Mockito.when(provider.newDirectoryStream(Mockito.same(ciphertextDirPath), Mockito.any())) .thenReturn(dirStream);/*from w w w . ja va 2 s . c o m*/ longFileNameProvider = Mockito.mock(LongFileNameProvider.class); conflictResolver = Mockito.mock(ConflictResolver.class); finallyUtil = mock(FinallyUtil.class); Mockito.when(longFileNameProvider.inflate(Mockito.anyString())).then(invocation -> { String shortName = invocation.getArgument(0); if (shortName.contains("invalid")) { throw new IOException("invalid shortened name"); } else { return StringUtils.removeEnd(shortName, ".lng"); } }); cryptoPathMapper = Mockito.mock(CryptoPathMapper.class); Mockito.when(cryptoPathMapper.resolveDirectory(Mockito.any())).then(invocation -> { Path dirFilePath = invocation.getArgument(0); if (dirFilePath.toString().contains("invalid")) { throw new IOException("Invalid directory."); } Path dirPath = Mockito.mock(Path.class); BasicFileAttributes attrs = Mockito.mock(BasicFileAttributes.class); Mockito.when(dirPath.getFileSystem()).thenReturn(fs); Mockito.when(provider.readAttributes(dirPath, BasicFileAttributes.class)).thenReturn(attrs); Mockito.when(attrs.isDirectory()).thenReturn(!dirFilePath.toString().contains("noDirectory")); return new Directory("asdf", dirPath); }); Mockito.when(conflictResolver.resolveConflictsIfNecessary(Mockito.any(), Mockito.any())) .then(returnsFirstArg()); doAnswer(invocation -> { for (Object runnable : invocation.getArguments()) { ((RunnableThrowingException<?>) runnable).run(); } return null; }).when(finallyUtil).guaranteeInvocationOf(any(RunnableThrowingException.class), any(RunnableThrowingException.class), any(RunnableThrowingException.class)); }
From source file:org.cryptomator.filesystem.jackrabbit.FileSystemResourceLocatorFactory.java
public FileSystemResourceLocatorFactory(URI contextRootUri, Folder root) { String pathPrefix = StringUtils.removeEnd(contextRootUri.toString(), "/"); this.fs = new FileSystemLocator(this, pathPrefix, root); }
From source file:org.cryptomator.filesystem.jackrabbit.FileSystemResourceLocatorFactory.java
@Override public FileSystemResourceLocator createResourceLocator(String prefix, String href) { final String fullPrefix = StringUtils.removeEnd(prefix, "/"); final String remainingHref = StringUtils.removeStart(href, fullPrefix); final String unencodedRemaingingHref = EncodeUtil.unescape(remainingHref); return createResourceLocator(unencodedRemaingingHref); }
From source file:org.cryptomator.frontend.webdav.servlet.DavLocatorImpl.java
/** * Behold, this is a constructor. It constructs constructions. Didn't see that coming, did you? * /*w w w . jav a 2 s .c om*/ * @param factory Locator factory. * @param prefix Must end on "/". * @param resourcePath Must be an relative path, i.e. must not start with "/". */ public DavLocatorImpl(DavLocatorFactoryImpl factory, String prefix, String resourcePath) { if (!prefix.endsWith("/")) { throw new IllegalArgumentException("prefix must end on '/' but was: " + prefix); } if (resourcePath.startsWith("/")) { throw new IllegalArgumentException("resourcePath must not start with '/' but was: " + resourcePath); } this.factory = Objects.requireNonNull(factory); this.prefix = prefix; this.resourcePath = StringUtils.removeEnd(resourcePath, "/"); }
From source file:org.cryptomator.frontend.webdav.servlet.DavLocatorImpl.java
@Override public String getHref(boolean isCollection) { if (isCollection) { return StringUtils.appendIfMissing(getHref(), "/"); } else {/*from w ww.j a v a 2s . co m*/ return StringUtils.removeEnd(getHref(), "/"); } }