List of usage examples for org.springframework.util StringUtils hasLength
public static boolean hasLength(@Nullable String str)
From source file:com.github.springtestdbunit.DbUnitRunner.java
private IDataSet loadDataset(DbUnitTestContext testContext, String dataSetLocation) throws Exception { DataSetLoader dataSetLoader = testContext.getDataSetLoader(); if (StringUtils.hasLength(dataSetLocation)) { IDataSet dataSet = dataSetLoader.loadDataSet(testContext.getTestClass(), dataSetLocation); Assert.notNull(dataSet,/* w w w . j av a 2s . c om*/ "Unable to load dataset from \"" + dataSetLocation + "\" using " + dataSetLoader.getClass()); return dataSet; } return null; }
From source file:uk.ac.gda.dls.client.views.LinearPositionerCompositeFactory.java
LinearPositionerComposite(Composite parent, int style, ScannableMotion positioner, String label, Integer labelWidth, Integer contentWidth, Integer lowScale, Integer highScale) { super(parent, style); this.display = parent.getDisplay(); this.positioner = positioner; this.labelWidth = labelWidth; this.contentWidth = contentWidth; formats = positioner.getOutputFormat(); GridLayoutFactory.fillDefaults().numColumns(2).applyTo(this); GridDataFactory.fillDefaults().applyTo(this); // GridDataFactory.fillDefaults().align(GridData.FILL, SWT.FILL).applyTo(this); // Label lbl = new Label(this, SWT.RIGHT |SWT.WRAP | SWT.BORDER); Label lbl = new Label(this, SWT.RIGHT | SWT.WRAP); lbl.setText(StringUtils.hasLength(label) ? label : positioner.getName()); GridData labelGridData = new GridData(GridData.HORIZONTAL_ALIGN_END); if (labelWidth != null) labelGridData.widthHint = labelWidth.intValue(); lbl.setLayoutData(labelGridData);/*from www .ja v a 2 s. c o m*/ scale = new Scale(this, SWT.BORDER | SWT.HORIZONTAL); Rectangle clientArea = this.getClientArea(); scale.setBounds(clientArea.x, clientArea.y, 200, 64); scale.setMaximum(highScale); scale.setMinimum(lowScale); // scale.setPageIncrement(1); // pcom.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); GridData textGridData = new GridData(GridData.FILL_HORIZONTAL); textGridData.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; if (contentWidth != null) textGridData.widthHint = contentWidth.intValue(); scale.setLayoutData(textGridData); scale.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { valueChanged((Scale) e.widget); } }); setSlideRunnable = new Runnable() { @Override public void run() { scale.setSelection(selectionValue); EclipseWidgetUtils.forceLayoutOfTopParent(LinearPositionerComposite.this); } }; observer = new IObserver() { @Override public void update(Object source, Object arg) { logger.info("Got the who knows what type event!"); displayValue(); } }; displayValue(); positioner.addIObserver(observer); }
From source file:com.ethlo.geodata.importer.file.FileIpLookupImporter.java
private String findMapValue(Map<String, String> map, String... needles) { final Iterator<String> it = Arrays.asList(needles).iterator(); while (it.hasNext()) { final String key = it.next(); final String val = map.get(key); if (StringUtils.hasLength(val)) { return val; }/*from w ww . ja v a 2 s . c o m*/ } return null; }
From source file:net.collegeman.grails.e3db.SqlBuffer.java
protected static final boolean hasLength(Object o) { if (o == null) return false; else// w w w. j ava 2 s . c om return StringUtils.hasLength(String.valueOf(o)); }
From source file:org.codehaus.groovy.grails.scaffolding.AbstractGrailsTemplateGenerator.java
public void generateView(GrailsDomainClass domainClass, String viewName, Writer out) throws IOException { String templateText = getTemplateText(viewName + ".gsp"); if (!StringUtils.hasLength(templateText)) { return;/*from w w w.j a v a 2 s . c o m*/ } GrailsDomainClassProperty multiPart = null; for (GrailsDomainClassProperty property : domainClass.getProperties()) { if (property.getType() == Byte[].class || property.getType() == byte[].class) { multiPart = property; break; } } String packageName = StringUtils.hasLength(domainClass.getPackageName()) ? "<%@ page import=\"" + domainClass.getFullName() + "\" %>" : ""; Map<String, Object> binding = createBinding(domainClass); binding.put("packageName", packageName); binding.put("multiPart", multiPart); binding.put("propertyName", getPropertyName(domainClass)); generate(templateText, binding, out); }
From source file:com.starit.diamond.server.controller.AdminController.java
/** * ??//from w w w. j a v a 2s .c o m * * @param request * @param dataId * @param group * @param content * @param modelMap * @return */ @RequestMapping(value = "/updateConfig", method = RequestMethod.POST) public String updateConfig(HttpServletRequest request, HttpServletResponse response, @RequestParam("dataId") String dataId, @RequestParam("group") String group, @RequestParam("description") String description, @RequestParam("content") String content, ModelMap modelMap) { response.setCharacterEncoding(Constants.ENCODE); String remoteIp = getRemoteIP(request); String userName = (String) request.getSession().getAttribute("user"); ConfigInfo configInfo = new ConfigInfo(dataId, group, userName, content, description); boolean checkSuccess = true; String errorMessage = "?"; if (!StringUtils.hasLength(dataId) || DiamondUtils.hasInvalidChar(dataId.trim())) { checkSuccess = false; errorMessage = "DataId"; } if (!StringUtils.hasLength(group) || DiamondUtils.hasInvalidChar(group.trim())) { checkSuccess = false; errorMessage = ""; } if (!StringUtils.hasLength(content)) { checkSuccess = false; errorMessage = ""; } if (!checkSuccess) { modelMap.addAttribute("message", errorMessage); modelMap.addAttribute("configInfo", configInfo); return "/admin/detailConfig"; } // ?,? ConfigInfo oldConfigInfo = this.configService.findConfigInfo(dataId, group); if (oldConfigInfo == null) { updateLog.warn("?,???, dataId=" + dataId + ",group=" + group); modelMap.addAttribute("message", "?, ???, dataId=" + dataId + ",group=" + group); return listConfig(request, response, dataId, group, 1, 20, modelMap); } String oldContent = oldConfigInfo.getContent(); this.configService.updateConfigInfo(dataId, group, content, userName, description); // updateLog.warn("??\ndataId=" + dataId + "\ngroup=" + group + "\noldContent=\n" + oldContent + "\nnewContent=\n" + content + "\nsrc ip=" + remoteIp); request.getSession().setAttribute("message", "???!"); return "redirect:" + listConfig(request, response, null, null, 1, 10, modelMap); }
From source file:org.jasig.portlet.contacts.adapters.impl.ldap.ConfigurableContactAttributesMapper.java
/** * Sets the object's property from the LDAP attribute value or default property value. * @param obj object to set property on//from w w w . ja v a 2s .co m * @param propertyName property name to set * @param propertyNameToLDAPNameMap Map of object property names to ldap attribute names * @param attrs LDAP attributes * @return Populated object, or null if the LDAP attributes do not contain values that create a * reasonably useful object of the requested type */ private <T> void setProperty(T obj, String propertyName, Map<String, ?> propertyNameToLDAPNameMap, Attributes attrs) { String method = "set" + StringUtils.capitalize(propertyName); String ldapAttributeName = (String) propertyNameToLDAPNameMap.get(propertyName); try { if (StringUtils.hasLength(ldapAttributeName)) { if (ldapAttributeName.startsWith(defaultPrefix)) { obj.getClass().getMethod(method, String.class).invoke(obj, ldapAttributeName.substring(defaultPrefix.length())); } else { Attribute attr = attrs.get(ldapAttributeName); obj.getClass().getMethod(method, String.class).invoke(obj, getValue(attr)); if (attr != null && attr.size() > 1) { logger.warn("Found multiple values for LDAP attribute " + ldapAttributeName + attrs.get("cn") != null ? ", cn=" + config.get("cn") : ""); } } } } catch (Exception ex) { logger.error("Exception setting property for " + obj.getClass().getCanonicalName() + "." + method + ", LDAP attribute " + ldapAttributeName, ex); } }
From source file:grails.plugin.springsecurity.web.access.intercept.AnnotationFilterInvocationDefinition.java
@Override protected String determineUrl(final FilterInvocation filterInvocation) { HttpServletRequest request = filterInvocation.getHttpRequest(); HttpServletResponse response = filterInvocation.getHttpResponse(); GrailsWebRequest existingRequest;/*w w w .j ava 2 s . c om*/ try { existingRequest = WebUtils.retrieveGrailsWebRequest(); } catch (IllegalStateException e) { throw new IllegalStateException( "There was a problem retrieving the current GrailsWebRequest. This usually indicates a filter ordering " + "issue in web.xml (the 'springSecurityFilterChain' filter-mapping element must be positioned after the " + "'grailsWebRequest' element when using @Secured annotations) but this should be handled correctly by the " + "webxml plugin. Ensure that the webxml plugin is installed (it should be transitively installed as a " + "dependency of the spring-security-core plugin)"); } String requestUrl = calculateUri(request); String url = null; try { GrailsWebRequest grailsRequest = new GrailsWebRequest(request, response, servletContext); WebUtils.storeGrailsWebRequest(grailsRequest); Map<String, Object> savedParams = copyParams(grailsRequest); UrlMappingInfo[] urlInfos; if (grails23Plus) { urlInfos = grails.plugin.springsecurity.ReflectionUtils.matchAllUrlMappings(urlMappingsHolder, requestUrl, grailsRequest, responseMimeTypesApi); } else { urlInfos = urlMappingsHolder.matchAll(requestUrl); } for (UrlMappingInfo mapping : urlInfos) { if (grails23Plus && grails.plugin.springsecurity.ReflectionUtils.isRedirect(mapping)) { break; } configureMapping(mapping, grailsRequest, savedParams); url = findGrailsUrl(mapping); if (url != null) { break; } } } finally { if (existingRequest == null) { WebUtils.clearGrailsWebRequest(); } else { WebUtils.storeGrailsWebRequest(existingRequest); } } if (!StringUtils.hasLength(url)) { // probably css/js/image url = requestUrl; } return lowercaseAndStripQuerystring(url); }
From source file:org.elasticsoftware.elasterix.server.actors.User.java
@Override public void onReceive(ActorRef sender, Object message) throws Exception { ActorRef sipService = getSystem().serviceActorFor("sipService"); State state = getState(null).getAsObject(State.class); if (message instanceof SipRequestMessage) { SipRequestMessage request = (SipRequestMessage) message; // check if request authenticated if (request.isAuthenticated()) { // previously authenticated. Continue } else {// ww w .j a v a2 s . c o m if (authenticate(sender, request, state)) { request.setAuthenticated(true); if (request.getSipMethod() == SipMethod.REGISTER) { // OK, Update nonce so that next requests are automatically rejected. state.setNonce(generateNonce()); } sender.tell(request, getSelf()); } else { if (request.getSipMethod() == SipMethod.REGISTER) { state.setNonce(generateNonce()); request.addHeader(SipHeader.WWW_AUTHENTICATE, String.format("Digest algorithm=%s, " + "realm=\"%s\", nonce=\"%s\"", ServerConfig.getDigestAlgorithm(), ServerConfig.getRealm(), state.getNonce())); } sipService.tell(request.toSipResponseMessage(SipResponseStatus.UNAUTHORIZED), getSelf()); } return; } switch (request.getSipMethod()) { case REGISTER: register(sipService, request, state); return; case INVITE: invite(sipService, request, state); return; default: log.warn(String.format("onReceive. Unsupported message[%s]", message.getClass().getSimpleName())); unhandled(message); } } else if (message instanceof ApiHttpMessage) { ApiHttpMessage apiMessage = (ApiHttpMessage) message; HttpMethod method = apiMessage.getMethod(); if (HttpMethod.GET == method) { sender.tell(apiMessage.toHttpResponse(HttpResponseStatus.OK, state), getSelf()); } else if (HttpMethod.PUT == method || HttpMethod.POST == method) { // check action. No matter if GET or POST/UPDATE? if ("reset".equalsIgnoreCase(apiMessage.getAction()) || "clear".equalsIgnoreCase(apiMessage.getAction())) { log.info("Resetting: " + state.getUsername()); state.userAgentClients.clear(); sender.tell(apiMessage.toHttpResponse(HttpResponseStatus.OK, state), getSelf()); return; } // update and post state afterwards... User.State update = apiMessage.getContent(User.State.class); if (update == null) { sender.tell(apiMessage.toHttpResponse(HttpResponseStatus.NO_CONTENT), getSelf()); return; } // update current state... if (StringUtils.hasLength(update.getFirstName())) { state.firstName = update.getFirstName(); } if (StringUtils.hasLength(update.getLastName())) { state.lastName = update.getLastName(); } if (StringUtils.hasLength(update.getPassword())) { state.password = update.getPassword(); } sender.tell(apiMessage.toHttpResponse(HttpResponseStatus.OK, state), getSelf()); } else if (HttpMethod.DELETE == method) { // TODO: we can either remove user here or at UserController#onReceive getSystem().stop(getSelf()); sender.tell(apiMessage.toHttpResponse(HttpResponseStatus.OK, state), getSelf()); } } else if (message instanceof TimeoutMessage) { state.clearUserAgentClients(); } else { unhandled(message); } }
From source file:cn.leancloud.diamond.server.service.ConfigService.java
/** * ??/*from w ww . ja v a 2 s. c om*/ * * @param pageNo * @param pageSize * @param group * @param dataId * @return */ public Page<ConfigInfo> findConfigInfo(final int pageNo, final int pageSize, final String group, final String dataId) { if (StringUtils.hasLength(dataId) && StringUtils.hasLength(group)) { ConfigInfo ConfigInfo = this.persistService.findConfigInfo(dataId, group); Page<ConfigInfo> page = new Page<ConfigInfo>(); if (ConfigInfo != null) { page.setPageNumber(1); page.setTotalCount(1); page.setPagesAvailable(1); page.getPageItems().add(ConfigInfo); } return page; } else if (StringUtils.hasLength(dataId) && !StringUtils.hasLength(group)) { return this.persistService.findConfigInfoByDataId(pageNo, pageSize, dataId); } else if (!StringUtils.hasLength(dataId) && StringUtils.hasLength(group)) { return this.persistService.findConfigInfoByGroup(pageNo, pageSize, group); } else { return this.persistService.findAllConfigInfo(pageNo, pageSize); } }