List of usage examples for org.apache.commons.lang3 StringUtils substringBeforeLast
public static String substringBeforeLast(final String str, final String separator)
Gets the substring before the last occurrence of a separator.
From source file:eionet.webq.converter.CdrRequestConverter.java
@Override public CdrRequest convert(HttpServletRequest httpRequest) { QueriedParametersTracker parametersTracker = new QueriedParametersTracker(httpRequest); CdrRequest parameters = new CdrRequest(); parameters.setContextPath(httpRequest.getContextPath()); parameters.setEnvelopeUrl(parametersTracker.getParameter("envelope")); parameters.setSchema(parametersTracker.getParameter("schema")); parameters.setNewFormCreationAllowed(Boolean.valueOf(parametersTracker.getParameter("add"))); parameters.setNewFileName(parametersTracker.getParameter("file_id")); String instanceUrl = parametersTracker.getParameter("instance"); parameters.setInstanceUrl(instanceUrl); if (isNotEmpty(instanceUrl)) { int fileNameSeparatorIndex = instanceUrl.lastIndexOf("/"); parameters.setInstanceName(instanceUrl.substring(fileNameSeparatorIndex + 1)); if (isEmpty(parameters.getEnvelopeUrl())) { parameters.setEnvelopeUrl(instanceUrl.substring(0, fileNameSeparatorIndex)); }//from ww w . j a v a 2s . co m } parameters.setInstanceTitle(parametersTracker.getParameter("instance_title")); if (StringUtils.isEmpty(parameters.getEnvelopeUrl()) && StringUtils.isNotEmpty(parameters.getInstanceUrl())) { parameters.setEnvelopeUrl(StringUtils.substringBeforeLast(parameters.getInstanceUrl(), "/")); } parameters.setSessionId(requestBasedUserIdProvider.getUserId(httpRequest)); String authorizationHeader = httpRequest.getHeader("Authorization"); if (authorizationAgainstCdrSucceed(httpRequest) && hasBasicAuthorization(authorizationHeader)) { try { setAuthorizationDetails(parameters, authorizationHeader); } catch (UnsupportedEncodingException e) { LOGGER.error("Unable to parse authorisation details" + e.toString()); } } if (authorizationAgainstCdrSucceed(httpRequest) && !parameters.isAuthorizationSet() && httpRequest.getAttribute(CdrAuthorizationInterceptor.PARSED_COOKIES_ATTRIBUTE) != null) { parameters.setAuthorizationSet(true); parameters.setCookies( (String) httpRequest.getAttribute(CdrAuthorizationInterceptor.PARSED_COOKIES_ATTRIBUTE)); } parameters.setAdditionalParametersAsQueryString(createQueryStringFromParametersNotRead(parametersTracker)); return parameters; }
From source file:io.wcm.handler.media.impl.ImageFileServlet.java
/** * Get image filename to be used for the URL with file extension matching the image format which is produced by this * servlet./*from w w w . j a v a 2 s . c o m*/ * @param pOriginalFilename Original filename of the image to render. * @return Filename to be used for URL. */ public static String getImageFileName(String pOriginalFilename) { String namePart = StringUtils.substringBeforeLast(pOriginalFilename, "."); String extensionPart = StringUtils.substringAfterLast(pOriginalFilename, "."); // use PNG format if original image is PNG, otherwise always use JPEG if (StringUtils.equalsIgnoreCase(extensionPart, FileExtension.PNG)) { extensionPart = FileExtension.PNG; } else { extensionPart = FileExtension.JPEG; } return namePart + "." + extensionPart; }
From source file:com.zht.common.generator.excute.impl.JSPGeneratorImplNew.java
@Override public void genjsp_update(String entityFullClassName, String controllerNameSpace, GenEntity genEntity, List<GenEntityProperty> genEntityPropertyList) { JSPModelNew jSPModel = new JSPModelNew(); //??/*ww w . ja v a 2 s . c o m*/ String entitySimpleClassName = StringUtils.substringAfterLast(entityFullClassName, "."); // String str = StringUtils.substringBeforeLast(entityFullClassName, "."); str = StringUtils.substringBeforeLast(str, "."); String firstLower = ZStrUtil.toLowerCaseFirst(entitySimpleClassName); jSPModel.setControllerNameSpace(controllerNameSpace); jSPModel.setEntityFullClassName(entityFullClassName); jSPModel.setEntitySimpleClassName(entitySimpleClassName); jSPModel.setGenEntity(genEntity); jSPModel.setGenEntityPropertyList(genEntityPropertyList); Map<String, Object> data = new HashMap<String, Object>(); data.put("model", jSPModel); String filePath = new String(GenConstant.project_path + "WebRoot/WEB-INF/jsp/" + controllerNameSpace + "/" + firstLower + "Update.jsp"); super.generate(GenConstant.jsp_add_template_dir, data, filePath); }
From source file:com.xpn.xwiki.user.impl.xwiki.AppServerTrustedKerberosAuthServiceImpl.java
/** * Helper method to extract the username part out of a Kerberos principal. * // w w w . j av a 2 s .co m * @param principal the principal to extract the username from * @return the extracted username */ private String extractUsernameFromPrincipal(final String principal) { String username = principal; // Clears the Kerberos principal, by removing the domain part, to retain only the user name of the // authenticated remote user. if (username.contains(ANTI_SLASH)) { // old domain form username = StringUtils.substringAfter(username, ANTI_SLASH); } if (username.contains(AT_SIGN)) { // new domain form username = StringUtils.substringBeforeLast(username, AT_SIGN); } return username; }
From source file:bear.main.ProjectGenerator.java
private void addPlugin(Class<? extends Plugin> plugin, StringBuilder fieldsSB, StringBuilder importsSB) { String simpleName = plugin.getSimpleName(); String varName = WordUtils.uncapitalize(StringUtils.substringBeforeLast(simpleName, "Plugin")); fieldsSB.append(" ").append(simpleName).append(" ").append(varName).append("\n"); importsSB.append("import ").append(plugin.getName()).append("\n"); }
From source file:eu.chocolatejar.eclipse.plugin.cleaner.ArtifactParser.java
/** * Resolve artifact by reg exp from the filename * /*from w w w.j av a 2 s. c om*/ * @param file * @return <code>null</code> if not found */ private Artifact getArtifactBasedOnFilename(File file) { if (file == null) { return null; } try { String baseName = FilenameUtils.getName(file.getAbsolutePath()); Matcher versionMatcher = VERSION_PATTERN.matcher(baseName); if (versionMatcher.find()) { String version = versionMatcher.group(0); if (baseName.contains("_")) { String bundleSymbolicName = StringUtils.substringBeforeLast(baseName, "_" + version); return new Artifact(file, bundleSymbolicName, version); } } } catch (Exception e) { logger.debug("Unable to parse artifact based on filename from the file '{}'.", file, e); } return null; }
From source file:com.projectsontracks.model.CaribooKey.java
/** * Open an AES key stored in an encrypted and password protected ZIP file * Then store the key in local variable byte[] key * * @param inputFileName/*from w w w .j a v a 2s . c om*/ * @param password * @throws java.security.GeneralSecurityException * @throws java.io.FileNotFoundException * @throws net.lingala.zip4j.exception.ZipException * @throws com.projectsontracks.model.CaribooException */ public void loadKey(String inputFileName, String password) throws GeneralSecurityException, FileNotFoundException, IOException, ZipException, CaribooException { // read private key to be used to decrypt the AES key // Name of the file inside the ZIP String keyFileName = StringUtils.substringBeforeLast(inputFileName, ".") + "." + KEY_FILE_EXTENSION; keyFileName = StringUtils.substringAfterLast(keyFileName, "\\"); // Initiate ZipFile object with the path/name of the zip file. ZipFile zipFile = new ZipFile(inputFileName); //System.out.println("ZIP Key file: " + inputFileName); //System.out.println("Key file: " + keyFileName); ZipParameters parameters = new ZipParameters(); //parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE); // set compression method to store compression //parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL); if (zipFile.isEncrypted()) { zipFile.setPassword(password); } //parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES); //parameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256); //Get a list of FileHeader. FileHeader is the header information for all the files in the ZipFile List fileHeaderList = zipFile.getFileHeaders(); // Loop through all the fileHeaders for (int i = 0; i < fileHeaderList.size(); i++) { FileHeader fileHeader = (FileHeader) fileHeaderList.get(i); if (fileHeader != null) { String fileName = fileHeader.getFileName(); //System.out.println(" Zip contains : " + fileName); if (keyFileName != null && keyFileName.equalsIgnoreCase(fileName)) { //Get the InputStream from the ZipFile ZipInputStream is = zipFile.getInputStream(fileHeader); File file = new File(fileName); // read the InputStream int readLen = -1; byte[] buff = new byte[32]; while ((readLen = is.read(buff)) != -1) { } // Assign to local variable this.key = buff; keySpec = new SecretKeySpec(this.key, "AES"); //System.out.println("Key: " + new String(this.key)); } else { throw new CaribooException(fileName + " does not match " + keyFileName); } } } //for }
From source file:com.thruzero.common.jsf.support.beans.dialog.AbstractAboutApplicationBean.java
public String getJarRows() { StringBuffer result = new StringBuffer(); try {/*ww w .jav a 2 s .co 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.zht.common.codegen.excute.impl.JSPGeneratorImplNew.java
@Override public void genjsp_update(String entityFullClassName, String controllerNameSpace, GenEntity genEntity, List<GenEntityProperty> genEntityPropertyList) { JSPModelNew jSPModel = new JSPModelNew(); //??/* ww w . j a v a 2 s.co m*/ String entitySimpleClassName = StringUtils.substringAfterLast(entityFullClassName, "."); // String str = StringUtils.substringBeforeLast(entityFullClassName, "."); str = StringUtils.substringBeforeLast(str, "."); String firstLower = ZStrUtil.toLowerCaseFirst(entitySimpleClassName); jSPModel.setControllerNameSpace(controllerNameSpace); jSPModel.setEntityFullClassName(entityFullClassName); jSPModel.setEntitySimpleClassName(entitySimpleClassName); jSPModel.setGenEntity(genEntity); jSPModel.setGenEntityPropertyList(genEntityPropertyList); Map<String, Object> data = new HashMap<String, Object>(); data.put("model", jSPModel); String filePath = new String(GenConstant.project_path + "WebRoot/WEB-INF/jsp/" + controllerNameSpace + "/" + firstLower + "Update.jsp"); super.generate(GenConstant.jsp_update_template_dir, data, filePath); }
From source file:io.wcm.handler.mediasource.inline.InlineRendition.java
/** * @param resource Binary resource//from ww w.j a v a 2s. c o m * @param media Media metadata * @param mediaArgs Media args * @param fileName File name */ InlineRendition(Resource resource, Media media, MediaArgs mediaArgs, String fileName, Adaptable adaptable) { this.resource = resource; this.media = media; this.mediaArgs = mediaArgs; this.adaptable = adaptable; // detect image dimension String processedFileName = fileName; // check if scaling is possible String fileExtension = StringUtils.substringAfterLast(processedFileName, "."); boolean isImage = FileExtension.isImage(fileExtension); Dimension dimension = null; Dimension scaledDimension = null; if (isImage) { // get dimension from image binary dimension = getImageDimension(); // check if scaling is required scaledDimension = getScaledDimension(dimension); if (scaledDimension != null && !scaledDimension.equals(SCALING_NOT_POSSIBLE_DIMENSION)) { // overwrite image dimension of {@link Rendition} instance with scaled dimensions dimension = scaledDimension; // change extension to JPEG because scaling always produces JPEG images processedFileName = StringUtils.substringBeforeLast(processedFileName, ".") + "." + FileExtension.JPEG; } } this.fileName = processedFileName; this.imageDimension = dimension; // build media url (it is null if no rendition is available for the given media args) this.url = buildMediaUrl(scaledDimension); // set first media format as resolved format - because only the first is supported if (url != null && mediaArgs.getMediaFormats() != null && mediaArgs.getMediaFormats().length > 0) { this.resolvedMediaFormat = mediaArgs.getMediaFormats()[0]; } }