List of usage examples for org.apache.commons.lang3 StringUtils equals
public static boolean equals(final CharSequence cs1, final CharSequence cs2)
Compares two CharSequences, returning true if they represent equal sequences of characters.
null s are handled without exceptions.
From source file:com.xpn.xwiki.internal.merge.MergeUtils.java
/** * Merge String at characters level./* w ww . j a v a 2s . c om*/ * * @param previousStr previous version of the string * @param newStr new version of the string * @param currentStr current version of the string * @param mergeResult the merge report * @return the merged string or the provided current string if the merge fail */ public static String mergeCharacters(String previousStr, String newStr, String currentStr, MergeResult mergeResult) { org.xwiki.diff.MergeResult<Character> result; try { result = diffManager.merge(toCharacters(previousStr), toCharacters(newStr), toCharacters(currentStr), null); mergeResult.getLog().addAll(result.getLog()); String resultStr = fromCharacters(result.getMerged()); if (!StringUtils.equals(resultStr, currentStr)) { mergeResult.setModified(true); } return resultStr; } catch (MergeException e) { mergeResult.getLog().error("Failed to execute merge characters", e); } return currentStr; }
From source file:com.glaf.core.web.springmvc.MxSystemPropertyController.java
@RequestMapping("/edit") public ModelAndView edit(HttpServletRequest request, ModelMap modelMap) { RequestUtils.setRequestParameterToAttribute(request); String category = request.getParameter("category"); if (StringUtils.isNotEmpty(category)) { List<SystemProperty> rows = systemPropertyService.getSystemProperties(category); if (rows != null && !rows.isEmpty()) { for (SystemProperty p : rows) { if (StringUtils.equals(p.getInputType(), "combobox")) { if (StringUtils.isNotEmpty(p.getInitValue()) && StringUtils.startsWith(p.getInitValue(), "[") && StringUtils.endsWith(p.getInitValue(), "]")) { try { JSONArray array = JSON.parseArray(p.getInitValue()); p.setArray(array); StringBuffer buffer = new StringBuffer(); for (int i = 0, len = array.size(); i < len; i++) { JSONObject json = array.getJSONObject(i); buffer.append("<option value=\"").append(json.getString("value")).append("\">") .append(json.getString("name")).append("</option>") .append(FileUtils.newline); }/*from w ww. j a va2s.c om*/ p.setSelectedScript(buffer.toString()); } catch (Exception ex) { ex.printStackTrace(); logger.error("parse json error :" + p.getInitValue(), ex); } } } } } request.setAttribute("rows", rows); } String jx_view = request.getParameter("jx_view"); if (StringUtils.isNotEmpty(jx_view)) { return new ModelAndView(jx_view, modelMap); } String x_view = ViewProperties.getString("sys_property.edit"); if (StringUtils.isNotEmpty(x_view)) { return new ModelAndView(x_view, modelMap); } return new ModelAndView("/modules/sys/property/edit"); }
From source file:ch.cyberduck.core.openstack.SwiftContainerListService.java
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { if (log.isDebugEnabled()) { log.debug(String.format("List containers for %s", session)); }/*from w w w . j a va2 s . c o m*/ try { final AttributedList<Path> containers = new AttributedList<Path>(); final int limit = preferences.getInteger("openstack.list.container.limit"); final Client client = session.getClient(); for (final Region region : client.getRegions()) { if (this.region.getIdentifier() != null) { if (!StringUtils.equals(region.getRegionId(), this.region.getIdentifier())) { log.warn(String.format("Skip region %s", region)); continue; } } // List all containers List<Container> chunk; String marker = null; do { chunk = client.listContainers(region, limit, marker); for (final Container f : chunk) { final PathAttributes attributes = new PathAttributes(); attributes.setRegion(f.getRegion().getRegionId()); containers.add(new Path(String.format("/%s", f.getName()), EnumSet.of(Path.Type.volume, Path.Type.directory), attributes)); marker = f.getName(); } listener.chunk(directory, containers); } while (!chunk.isEmpty()); } return containers; } catch (GenericException e) { throw new SwiftExceptionMappingService().map("Listing directory {0} failed", e, directory); } catch (IOException e) { throw new DefaultIOExceptionMappingService().map(e); } }
From source file:com.mirth.connect.plugins.datatypes.ncpdp.NCPDPReference.java
public String getSegment(String key, String version) { if (StringUtils.equals(version, VERSION_D0)) { return MapUtils.getString(segmentD0Map, key, key); } else {/*from w w w . j a va 2 s . c o m*/ return MapUtils.getString(segment51Map, key, key); } }
From source file:com.inkubator.hrm.web.lazymodel.AppraisalProgramEmployeeLazyDataModel.java
@Override public EmpData getRowData(String id) { for (EmpData empData : list) { if (StringUtils.equals(id, String.valueOf(empData.getId()))) { return empData; }//from w ww . j av a 2 s . c om } return null; }
From source file:io.wcm.handler.media.markup.MediaMarkupBuilderUtil.java
/** * Adds CSS classes that denote the changes to the media element when compared to a different version. * If no diff has been requested by the WCM UI, there won't be any changes to the element. * @param mediaElement Element to be decorated * @param resource Resource pointing to JCR node * @param refProperty Name of property for media library item reference. If null, default name is used. * @param request Servlet request//from w w w .j a v a 2 s . c o m */ public static void addDiffDecoration(HtmlElement<?> mediaElement, Resource resource, String refProperty, SlingHttpServletRequest request) { PageManager pageManager = request.getResourceResolver().adaptTo(PageManager.class); Page currentPage = pageManager.getContainingPage(request.getResource()); Page resourcePage = pageManager.getContainingPage(resource); String versionLabel = RequestParam.get(request, DiffService.REQUEST_PARAM_DIFF_TO); // Only try to diff when the resource is contained within the current page as the version number requested always // refers to the version history of the current page. So chances a resource on another page doesn't have a matching // version, and even if it has, it's comparing apples and oranges if (StringUtils.isNotEmpty(versionLabel) && currentPage != null && currentPage.equals(resourcePage)) { Resource versionedResource = DiffInfo.getVersionedResource(resource, versionLabel); if (versionedResource != null) { ValueMap currentProperties = resource.getValueMap(); ValueMap oldProperties = versionedResource.getValueMap(); String currentMediaRef = currentProperties.get(refProperty, String.class); String oldMediaRef = oldProperties.get(refProperty, String.class); if (!StringUtils.equals(currentMediaRef, oldMediaRef)) { if (StringUtils.isEmpty(currentMediaRef)) { mediaElement.addCssClass(MediaNameConstants.CSS_DIFF_REMOVED); } else if (StringUtils.isEmpty(oldMediaRef)) { mediaElement.addCssClass(MediaNameConstants.CSS_DIFF_ADDED); } else { mediaElement.addCssClass(MediaNameConstants.CSS_DIFF_UPDATED); } } else { // If the mediaRef itself hasn't changed, check the cropping coordinates String currentMediaCrop = currentProperties.get(MediaNameConstants.PN_MEDIA_CROP, String.class); String oldMediaCrop = oldProperties.get(MediaNameConstants.PN_MEDIA_CROP, String.class); if (!StringUtils.equals(currentMediaCrop, oldMediaCrop)) { mediaElement.addCssClass(MediaNameConstants.CSS_DIFF_UPDATED); } // we also could try to determine here whether it resolves to another rendition // or if the timestamp of the rendition has been updated (which would indicate the the binary payload has been // changed). // This however, is out of scope for this feature right now } } else { // The resource didn't exist in the old version at all mediaElement.addCssClass(MediaNameConstants.CSS_DIFF_ADDED); } } }
From source file:de.micromata.genome.gwiki.pagetemplates_1_0.editor.PtWikiUploadEditor.java
/** * @param ctx/* www. ja va 2 s . c om*/ * @param maxWidthInPx * @return */ private String uploadFile(final GWikiContext ctx) { String parentPageId = ctx.getRequestParameter("pageId"); if (dataFile == null) { dataFile = ctx.getFileItem(sectionName); } String name = dataFile.getName(); String pageIdFromTitle = GWikiContext.getPageIdFromTitle(dataFile.getName()); if (!StringUtils.equals(name, pageIdFromTitle)) { ctx.addSimpleValidationError(ctx.getTranslated("gwiki.editor.upload.allowdSymbols")); return null; } String pageId = parentPageId + "/" + pageIdFromTitle; if (ctx.getWikiWeb().findElement(pageId) != null) { ctx.addSimpleValidationError(ctx.getTranslated("gwiki.editor.upload.fileExists")); return null; } String title = ctx.getRequest().getParameter("title"); try { ByteArrayOutputStream bout = new ByteArrayOutputStream(); IOUtils.copy(dataFile.getInputStream(), bout); data = bout.toByteArray(); String metaTemplateId = "admin/templates/FileWikiPageMetaTemplate"; GWikiElement element = GWikiWebUtils.createNewElement(ctx, pageId, metaTemplateId, parentPageId); GWikiArtefakt<?> art = element.getMainPart(); GWikiBinaryAttachmentArtefakt att = (GWikiBinaryAttachmentArtefakt) art; att.setStorageData(data); if (data.length > 0) { element.getElementInfo().getProps().setIntValue(GWikiPropKeys.SIZE, data.length); } else { ctx.addSimpleValidationError(ctx.getTranslated("gwiki.editor.empty")); return null; } if (!StringUtils.isEmpty(title)) { element.getElementInfo().getProps().setStringValue(GWikiPropKeys.TITLE, title); } else { element.getElementInfo().getProps().setStringValue(GWikiPropKeys.TITLE, pageIdFromTitle); } element.getElementInfo().getProps().setStringValue(GWikiPropKeys.PARENTPAGE, parentPageId); if (maxFileSize != null && StringUtils.isNotEmpty(maxFileSize)) { try { long maxSize = Long.parseLong(StringUtils.trimToEmpty(maxFileSize)) * 1024; long currSize = dataFile.getSize(); if (maxSize < currSize) { ctx.addSimpleValidationError( ctx.getTranslated("gwiki.editor.upload.filesize") + maxFileSize + " kB"); } else { ctx.getWikiWeb().saveElement(ctx, element, false); } } catch (Exception e) { GWikiLog.error(e.getMessage(), e); } } else { ctx.getWikiWeb().saveElement(ctx, element, false); } } catch (IOException ex) { ctx.addValidationError("gwiki.edit.EditPage.attach.message.uploadfailed", ex.getMessage()); } return parentPageId; }
From source file:com.glaf.dts.web.rest.MxSchedulerResource.java
@POST @Path("/delete/{taskId}") public void delete(@PathParam("taskId") String taskId, @Context UriInfo uriInfo) { if (StringUtils.isNotEmpty(taskId)) { Scheduler scheduler = sysSchedulerService.getSchedulerByTaskId(taskId); if (scheduler != null && StringUtils.equals(scheduler.getTaskType(), Constants.DTS_TASK_TYPE)) { sysSchedulerService.deleteScheduler(taskId); }/*from w w w. ja v a 2 s . c o m*/ } }
From source file:com.glaf.ui.service.impl.MxUserPortalServiceImpl.java
@Transactional public void save(String actorId, String panelId, int columnIndex, int position) { List<UserPortal> portals = this.getUserPortals(actorId); if (portals != null && !portals.isEmpty()) { for (UserPortal p : portals) { if (StringUtils.equals(panelId, p.getPanelId())) { p.setColumnIndex(columnIndex); p.setPosition(position); userPortalMapper.updateUserPortal(p); } else { if (p.getColumnIndex() == columnIndex) { if (p.getPosition() >= position) { p.setPosition(p.getPosition() + 1); userPortalMapper.updateUserPortal(p); }/* w w w .java 2s. com*/ } } } } }
From source file:io.wcm.config.core.impl.ApplicationImplementationPicker.java
private Class<?> pickMatchingApplication(Class<?>[] implementationsTypes, Object adaptable) { String applicationId = getApplicationId(adaptable); if (applicationId != null) { for (Class<?> clazz : implementationsTypes) { io.wcm.config.spi.annotations.Application applicationAnnotation = clazz .getAnnotation(io.wcm.config.spi.annotations.Application.class); if (applicationAnnotation != null && StringUtils.equals(applicationId, applicationAnnotation.value())) { return clazz; }// w ww. j a v a 2 s . c o m } } return null; }