List of usage examples for org.apache.commons.lang3 StringUtils substringAfterLast
public static String substringAfterLast(final String str, final String separator)
Gets the substring after the last occurrence of a separator.
From source file:com.sketchy.server.ImageUploadServlet.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { JSONServletResult jsonServletResult = new JSONServletResult(Status.SUCCESS); try {// ww w. j a v a 2s . co m boolean isMultipart = ServletFileUpload.isMultipartContent(request); if (isMultipart) { DiskFileItemFactory factory = new DiskFileItemFactory(); factory.setRepository(FileUtils.getTempDirectory()); factory.setSizeThreshold(MAX_SIZE); ServletFileUpload servletFileUpload = new ServletFileUpload(factory); List<FileItem> files = servletFileUpload.parseRequest(request); for (FileItem fileItem : files) { String uploadFileName = fileItem.getName(); if (StringUtils.isNotBlank(uploadFileName)) { // Don't allow \\ in the filename, assume it's a directory separator and convert to "/" // and take the filename after the last "/" // This will fix the issue of Jetty not reading and serving files // with "\" (%5C) characters // This also fixes the issue of IE sometimes sending the whole path // (depending on the security settings) uploadFileName = StringUtils.replaceChars(uploadFileName, "\\", "/"); if (StringUtils.contains(uploadFileName, "/")) { uploadFileName = StringUtils.substringAfterLast(uploadFileName, "/"); } File uploadFile = HttpServer.getUploadFile(uploadFileName); // make sure filename is actually in the upload directory // we don't want any funny games if (!uploadFile.getParentFile().equals(HttpServer.IMAGE_UPLOAD_DIRECTORY)) { throw new RuntimeException("Can not upload File. Invalid directory!"); } // if saved ok, then need to add the data file SourceImageAttributes sourceImageAttributes = new SourceImageAttributes(); sourceImageAttributes.setImageName(uploadFileName); File pngFile = HttpServer.getUploadFile(sourceImageAttributes.getImageFilename()); if (pngFile.exists()) { throw new Exception( "Can not Upload file. File '" + uploadFileName + "' already exists!"); } File dataFile = HttpServer.getUploadFile(sourceImageAttributes.getDataFilename()); // Convert the image to a .PNG file BufferedImage image = ImageUtils.loadImage(fileItem.getInputStream()); ImageUtils.saveImage(pngFile, image); sourceImageAttributes.setWidth(image.getWidth()); sourceImageAttributes.setHeight(image.getHeight()); FileUtils.writeStringToFile(dataFile, sourceImageAttributes.toJson()); jsonServletResult.put("imageName", uploadFileName); } } } } catch (Exception e) { jsonServletResult = new JSONServletResult(Status.ERROR, e.getMessage()); } response.setContentType("text/html"); response.setStatus(HttpServletResponse.SC_OK); response.getWriter().print(jsonServletResult.toJSONString()); }
From source file:com.xpn.xwiki.api.PropertyClass.java
/** * Get the actual type of the wrapped {@link com.xpn.xwiki.objects.classes.PropertyClass}. The returned value is * extracted from the class name of the runtime object representing this property definition, and denotes a * user-friendly data type name, for example {@code StringClass}, {@code NumberClass} or {@code StaticListClass}. * /*from w ww.java2 s. c o m*/ * @return the type of this property definition * @see #getClassType() {@code getClassType()} for a more formal type */ public String getType() { return StringUtils.substringAfterLast(getClassType(), "."); }
From source file:com.neatresults.mgnltweaks.ui.field.DialogIdSelectFieldFactory.java
@Override public List<SelectFieldOptionDefinition> getSelectFieldOptionDefinition() { List<SelectFieldOptionDefinition> fields = new ArrayList<SelectFieldOptionDefinition>(); try {// ww w . j av a 2 s .co m DialogDefinitionRegistry ddr = Components.getComponent(DialogDefinitionRegistry.class); Field registryField = ddr.getClass().getDeclaredField("registry"); registryField.setAccessible(true); RegistryMap<String, DialogDefinitionProvider> registry = (RegistryMap<String, DialogDefinitionProvider>) registryField .get(ddr); for (String id : registry.keySet()) { SelectFieldOptionDefinition field = new SelectFieldOptionDefinition(); FormDialogDefinition dialogDef = registry.get(id).getDialogDefinition(); // directly defined label String label = dialogDef.getLabel(); if (label == null) { // new i18n maybe? String name = dialogDef.getId().indexOf("/") > 0 ? StringUtils.substringAfterLast(dialogDef.getId(), "/") : StringUtils.substringAfterLast(dialogDef.getId(), ":"); String key = StringUtils.substringBefore(dialogDef.getId(), ":") + "." + name + ".label"; label = i18n.translate(key); // old i18n maybe? if (key.equals(label)) { // no .level suffix maybe? label = i18n.translate(StringUtils.substringBeforeLast(key, ".")); if (StringUtils.substringBeforeLast(key, ".").equals(label)) { String oldFormLabel = dialogDef.getForm().getLabel(); if (StringUtils.isNotBlank(oldFormLabel)) { label = oldi18n.getMessages(dialogDef.getForm().getI18nBasename()) .get(oldFormLabel); } else { // some weird guessing label = oldi18n.getMessages(dialogDef.getForm().getI18nBasename()).get(key); if (label.startsWith("???")) { // one last try - pbly old not translated dialog, get label from first tab List<TabDefinition> tabs = dialogDef.getForm().getTabs(); if (tabs.size() > 0) { label = tabs.get(0).getLabel(); } } } } } } field.setLabel(id + " (" + label + ")"); field.setName(definition.getName()); field.setValue(id); fields.add(field); } } catch (SecurityException | IllegalArgumentException | IllegalAccessException | RegistrationException | NoSuchFieldException e) { log.error(e.getMessage(), e); SelectFieldOptionDefinition field = new SelectFieldOptionDefinition(); field.setName("It looks like an error has occured. Please contact admin or developers about it: " + e.getMessage()); field.setValue(e.getMessage()); fields.add(field); } return fields; }
From source file:info.magnolia.ui.contentapp.setup.for5_3.MigrateAvailabilityRulesTask.java
private String resolveRuleName(String ruleClass) { return StringUtils.substringAfterLast(ruleClass, "."); }
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 ww . ja 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.thruzero.common.jsf.support.beans.dialog.AbstractAboutApplicationBean.java
public String getJarRows() { StringBuffer result = new StringBuffer(); try {/*from w ww . j av 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.neatresults.mgnltweaks.ui.field.NodeTypeSelectFieldFactory.java
@Override public List<SelectFieldOptionDefinition> getSelectFieldOptionDefinition() { List<SelectFieldOptionDefinition> fields = new ArrayList<SelectFieldOptionDefinition>(); try {/*from w ww .j a va2s .c o m*/ Field registryField = registry.getClass().getDeclaredField("registry"); registryField.setAccessible(true); RegistryMap<String, DialogDefinitionProvider> registryMap = (RegistryMap<String, DialogDefinitionProvider>) registryField .get(this.registry); for (String id : registryMap.keySet()) { SelectFieldOptionDefinition field = new SelectFieldOptionDefinition(); FormDialogDefinition dialogDef = registryMap.get(id).getDialogDefinition(); // directly defined label String label = dialogDef.getLabel(); if (label == null) { // new i18n maybe? String name = dialogDef.getId().indexOf("/") > 0 ? StringUtils.substringAfterLast(dialogDef.getId(), "/") : StringUtils.substringAfterLast(dialogDef.getId(), ":"); String key = StringUtils.substringBefore(dialogDef.getId(), ":") + "." + name + ".label"; label = i18n.translate(key); // old i18n maybe? if (key.equals(label)) { // no .level suffix maybe? label = i18n.translate(StringUtils.substringBeforeLast(key, ".")); if (StringUtils.substringBeforeLast(key, ".").equals(label)) { String oldFormLabel = dialogDef.getForm().getLabel(); if (StringUtils.isNotBlank(oldFormLabel)) { label = oldi18n.getMessages(dialogDef.getForm().getI18nBasename()) .get(oldFormLabel); } else { // some weird guessing label = oldi18n.getMessages(dialogDef.getForm().getI18nBasename()).get(key); if (label.startsWith("???")) { // one last try - pbly old not translated dialog, get label from first tab List<TabDefinition> tabs = dialogDef.getForm().getTabs(); if (tabs.size() > 0) { label = tabs.get(0).getLabel(); } } } } } } field.setLabel(id + " (" + label + ")"); field.setName(definition.getName()); field.setValue(id); fields.add(field); } } catch (SecurityException | IllegalArgumentException | IllegalAccessException | RegistrationException | NoSuchFieldException e) { log.error(e.getMessage(), e); SelectFieldOptionDefinition field = new SelectFieldOptionDefinition(); field.setName("It looks like an error has occured. Please contact admin or developers about it: " + e.getMessage()); field.setValue(e.getMessage()); fields.add(field); } return fields; }
From source file:com.xpn.xwiki.objects.meta.MetaClass.java
@Override public PropertyInterface get(String name) { PropertyInterface property = safeget(name); if (property == null) { // In previous versions the property name was the full Java class name of the property class implementation. // Extract the actual property name (the hint used to lookup the property class provider) by removing the // Java package prefix and the Class suffix. property = safeget(StringUtils.removeEnd(StringUtils.substringAfterLast(name, "."), "Class")); }/*from w ww. j ava 2s. c om*/ return property; }
From source file:com.quatico.base.aem.test.api.setup.Resources.java
private Resource getOrCreate(String path, Map<String, Object> properties) throws PersistenceException, RepositoryException { ResourceResolver resolver = client.getResourceResolver(); Resource resource = resolver.getResource(path); if (properties.containsKey("unit:vanityTarget")) { resource = resolver.resolve((String) properties.get("unit:vanityTarget")); } else {//from www . ja v a 2 s . c o m Resource parent = resolver.getResource("/"); PathIterator it = new PathIterator(path); it.first(); while (it.hasNext()) { String curPath = it.next(); String segment = StringUtils.substringAfterLast(curPath, "/"); resource = resolver.getResource(curPath); if (resource == null) { if (it.hasNext()) { resource = resolver.create(parent, segment, new HashMap<>()); } else { resource = resolver.create(parent, segment, properties); } } parent = resource; } } return resource; }
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(); //??//from w w w. jav a 2s.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_update_template_dir, data, filePath); }