List of usage examples for org.springframework.util StringUtils hasLength
public static boolean hasLength(@Nullable String str)
From source file:com.taobao.diamond.server.controller.BaseStoneController.java
@RequestMapping(params = "method=postConfig", method = RequestMethod.POST) public String postConfig(HttpServletRequest request, HttpServletResponse response, @RequestParam("dataId") String dataId, @RequestParam("group") String group, @RequestParam("content") String content) { response.setCharacterEncoding("GBK"); String remoteIp = getRemoteIp(request); boolean checkSuccess = true; String errorMessage = ""; if (!StringUtils.hasLength(dataId) || DiamondUtils.hasInvalidChar(dataId.trim())) { checkSuccess = false;//from w ww. j a v a2 s . co m errorMessage = "DataId"; } if (!StringUtils.hasLength(group) || DiamondUtils.hasInvalidChar(group.trim())) { checkSuccess = false; errorMessage = ""; } if (!StringUtils.hasLength(content)) { checkSuccess = false; errorMessage = ""; } if (!checkSuccess) { try { response.sendError(INVALID_PARAM, errorMessage); } catch (Exception e) { log.error("response:" + e.getMessage(), e); } return "536"; } // this.configService.addConfigInfo(dataId, group, content); try { // this.aggregationService.aggregation(dataId, group); } catch (Exception e) { log.error("", e); } try { // this.realTimeNotify(dataId, group); } catch (Exception e) { log.error("", e); } try { // ipdataIdredis this.addIpToDataIdAndGroup(remoteIp, dataId, group); } catch (Exception e) { log.error("redis", e); } return "200"; }
From source file:grails.plugin.springsecurity.web.access.intercept.AnnotationFilterInvocationDefinition.java
protected String findGrailsUrl(final UrlMappingInfo mapping) { String uri = mapping.getURI(); if (StringUtils.hasLength(uri)) { return uri; }// w w w .j a v a2s. c o m String viewName = mapping.getViewName(); if (viewName != null) { if (!viewName.startsWith(SLASH)) { viewName = SLASH + viewName; } return viewName; } String actionName = mapping.getActionName(); if (!StringUtils.hasLength(actionName)) { actionName = ""; } String controllerName = mapping.getControllerName(); if (isController(controllerName, actionName)) { return createControllerUri(controllerName, actionName); } if (grails23Plus && controllerName != null) { String namespace = mapping.getNamespace(); if (namespace != null) { String fullControllerName = resolveFullControllerName(controllerName, namespace); return createControllerUri(fullControllerName, actionName); } } return null; }
From source file:org.zilverline.extractors.AbstractExtractor.java
/** * This method extracts all relevant info of the file as an ParsedFileInfo object. Uses getContent as callback. * // www . j a v a2s .c o m * @param f the File to extract content from * * @return ParsedFileInfo the object containing relevant info of the provided file */ public final ParsedFileInfo extractInfo(final File f) { if (f == null) { log.warn("Something went terribly wrong, file = null, returning null "); return null; } try { setFile(f); Reader reader = getContent(f); fileInfo.setReader(reader); // get the summary from the reader if (reader != null) { String summary = fileInfo.getSummary(); if (!StringUtils.hasText(summary)) { char[] sumChars = new char[SUMMARY_SIZE]; int numChars = 0; try { if (reader.markSupported()) { reader.mark(SUMMARY_SIZE); numChars = reader.read(sumChars); reader.reset(); } if (numChars > 0) { summary = new String(sumChars, 0, numChars); } if (log.isDebugEnabled()) { log.debug("Summary extracted from reader: " + summary); } setSummary(getSummaryFromContent(summary)); } catch (IOException e) { log.warn("Error extracting summary form reader", e); } } } // Set the title if there's none yet if (!StringUtils.hasLength(fileInfo.getTitle())) { fileInfo.setTitle(FileUtils.getBasename(f)); } } catch (Exception e) { // here we don't throw any, since we do not want to interrupt the indexing process log.warn("Unexpected Error extracting content from " + f.getName(), e); } catch (OutOfMemoryError e) { // this happens with very, very large Documents log.error("Very Serious Error. Out of Memory for very large documents: " + f.getName() + ", try increasing your JVM heap size: for example, start your server with option '-Xmx128m'." + " Skipping file.", e); } catch (Throwable e) { log.error("Very Serious Error while extracting contents from: " + f.getName(), e); } return fileInfo; }
From source file:org.openmrs.module.patientnarratives.web.controller.FullNarrativeFormController.java
@Override protected Object formBackingObject(HttpServletRequest request) throws Exception { try {//from w w w.j av a2s . c om if (StringUtils.hasLength(request.getParameter("comment"))) { PatientNarrativesService patientNarrativesService = Context .getService(PatientNarrativesService.class); NarrativeComments narrativeComments = new NarrativeComments(); narrativeComments.setComment(request.getParameter("comment")); String encounterId = request.getParameter("encounterId"); narrativeComments.setEncounterId(Integer.parseInt(encounterId)); patientNarrativesService.saveNarrativesComment(narrativeComments); request.getSession().setAttribute(WebConstants.OPENMRS_MSG_ATTR, "patientnarratives.comment.added"); } if (StringUtils.hasLength(request.getParameter("newStatus"))) { String newStatus = request.getParameter("newStatus"); int encounterId = Integer.parseInt(request.getParameter("encounterId")); Encounter encounter = Context.getEncounterService().getEncounter(encounterId); Set<Obs> obs = encounter.getObs(); Iterator<Obs> observation = obs.iterator(); Integer statusObsId = null; Obs nowOb = null; while (observation.hasNext()) { nowOb = observation.next(); if (nowOb.getConcept().getConceptId() == 15 && !nowOb.isVoided()) { statusObsId = nowOb.getId(); Obs statusObs = Context.getObsService().getObs(statusObsId); Context.getObsService().voidObs(statusObs, "obs voided"); break; } } Person patient = encounter.getPatient(); Location location = Context.getLocationService().getDefaultLocation(); Obs newObs = new Obs(patient, nowOb.getConcept(), new Date(), location); newObs.setValueText(newStatus); newObs.setEncounter(encounter); Context.getObsService().saveObs(newObs, null); request.getSession().setAttribute(WebConstants.OPENMRS_MSG_ATTR, "patientnarratives.status.updated"); } if (StringUtils.hasLength(request.getParameter("registerEncounterId"))) { Integer encounterId = Integer.parseInt(request.getParameter("registerEncounterId")); PatientService patientService = Context.getPatientService(); Patient patient = new Patient(); EncounterService encounterService = Context.getEncounterService(); Encounter encounter = encounterService.getEncounter(encounterId); String patientName = ""; String patientAge = ""; String patientGender = ""; Set<Obs> obs = encounter.getObs(); Iterator<Obs> observation = obs.iterator(); while (observation.hasNext()) { Obs nowOb = observation.next(); if (nowOb.getConcept().getConceptId() == 12) { patientName = nowOb.getValueText(); } if (nowOb.getConcept().getConceptId() == 8) { patientAge = nowOb.getValueText(); } if (nowOb.getConcept().getConceptId() == 13) { patientGender = nowOb.getValueText(); } } PersonName personName = new PersonName(); int patientCount = patientService.getAllPatients().size(); int newPatientId = patientCount + 5; String nameArr[] = patientName.split(" "); if (nameArr.length == 1) { personName.setGivenName(nameArr[0]); personName.setFamilyName("----"); } else if (nameArr.length == 2) { personName.setGivenName(nameArr[0]); personName.setFamilyName(nameArr[1]); } else if (nameArr.length >= 3) { String nameArr2[] = parseFullName(patientName); personName.setGivenName(nameArr2[0]); personName.setMiddleName(nameArr2[1]); personName.setFamilyName(nameArr2[2]); } Set<PersonName> personNameSet = new TreeSet<PersonName>(); personNameSet.add(personName); patient.setNames(personNameSet); patient.setGender(patientGender); DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); patient.setBirthdateFromAge(Integer.parseInt(patientAge), df.parse(date)); PatientIdentifierType patientIdentifierType = Context.getPatientService() .getPatientIdentifierType(2); Location location = Context.getLocationService().getDefaultLocation(); PatientIdentifier patientIdentifier = new PatientIdentifier(String.valueOf(newPatientId), patientIdentifierType, location); patient.addIdentifier(patientIdentifier); patientService.savePatient(patient); int patientId = patientService.getPatients(String.valueOf(newPatientId)).get(0).getPatientId(); encounter.setPatient(patientService.getPatient(patientId)); encounterService.saveEncounter(encounter); request.getSession().setAttribute(WebConstants.OPENMRS_MSG_ATTR, "patientnarratives.newpatient.created.alert"); } } catch (Exception e) { request.getSession().setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Error occurred while Registering the Patient: " + e.getMessage()); log.error(e); } return request.getParameter("encounterId"); }
From source file:org.springsource.ide.eclipse.commons.internal.configurator.Configurator.java
private void persistRequest(String target) { String configureTargets = Activator.getDefault().getPreferenceStore() .getString(Activator.PROPERTY_CONFIGURE_TARGETS); if (StringUtils.hasLength(configureTargets)) { configureTargets += File.pathSeparatorChar + target; } else {//from ww w . j ava2 s .co m configureTargets = target; } Activator.getDefault().getPreferenceStore().setValue(Activator.PROPERTY_CONFIGURE_TARGETS, configureTargets); }
From source file:ui.web2.web.servlet.view.tiles2.DynamicTilesViewProcessor.java
/** * Processes values to get tiles template definition name. First * a Tiles definition matching the url is checked, then a * url specific template is checked, and then just the * default root definition is used.// w ww . jav a 2 s.co m * * @throws TilesException If no valid Tiles definition is found. */ protected String processTilesDefinitionName(String beanName, TilesContainer container, HttpServletRequest request, HttpServletResponse response) throws TilesException { // if definition already derived use it, otherwise // check if url (bean name) is a template definition, then // check for main template if (derivedDefinitionName != null) { return derivedDefinitionName; } else if (container.isValidDefinition(beanName, request, response)) { derivedDefinitionName = beanName; return beanName; } else { String result = null; StringBuilder sb = new StringBuilder(); int lastIndex = beanName.lastIndexOf("/"); boolean rootDefinition = false; // if delim, tiles def will start with it if (StringUtils.hasLength(tilesDefinitionDelimiter)) { sb.append(tilesDefinitionDelimiter); } // if no '/', then at context root if (lastIndex == -1) { rootDefinition = true; } else { String path = (beanName != null ? beanName.substring(0, lastIndex) : ""); if (StringUtils.hasLength(tilesDefinitionDelimiter)) { path = StringUtils.replace(path, "/", tilesDefinitionDelimiter); } sb.append(path); if (StringUtils.hasLength(tilesDefinitionDelimiter)) { sb.append(tilesDefinitionDelimiter); } } sb.append(tilesDefinitionName); if (container.isValidDefinition(sb.toString(), request, response)) { result = sb.toString(); } else if (!rootDefinition) { String root = null; if (StringUtils.hasLength(tilesDefinitionDelimiter)) { root = tilesDefinitionDelimiter; } root += tilesDefinitionName; if (container.isValidDefinition(root, request, response)) { result = root; } else { throw new TilesException( "No defintion of found for " + "'" + root + "'" + " or '" + sb.toString() + "'"); } } derivedDefinitionName = result; return result; } }
From source file:com.parakhcomputer.web.servlet.view.tiles2.DynamicTilesViewProcessor.java
/** * Processes values to get tiles template definition name. First * a Tiles definition matching the url is checked, then a * url specific template is checked, and then just the * default root definition is used./*from ww w .j a v a2 s . co m*/ * * @throws TilesException If no valid Tiles definition is found. */ protected String processTilesDefinitionName(String beanName, TilesContainer container, HttpServletRequest request, HttpServletResponse response) throws TilesException { // if definition already derived use it, otherwise // check if url (bean name) is a template definition, then // check for main template if (derivedDefinitionName != null) { return derivedDefinitionName; } else if (container.isValidDefinition(beanName, request, response)) { derivedDefinitionName = beanName; return beanName; } else { String result = null; StringBuilder sb = new StringBuilder(); int lastIndex = beanName.lastIndexOf("/"); boolean rootDefinition = false; // if delim, tiles def will start with it if (StringUtils.hasLength(tilesDefinitionDelimiter)) { sb.append(tilesDefinitionDelimiter); } // if no '/', then at context root if (lastIndex == -1) { rootDefinition = true; } else { String path = (beanName != null ? beanName.substring(0, lastIndex) : ""); if (StringUtils.hasLength(tilesDefinitionDelimiter)) { path = StringUtils.replace(path, "/", tilesDefinitionDelimiter); } sb.append(path); if (StringUtils.hasLength(tilesDefinitionDelimiter)) { sb.append(tilesDefinitionDelimiter); } } sb.append(tilesDefinitionName); if (container.isValidDefinition(sb.toString(), request, response)) { result = sb.toString(); } else if (!rootDefinition) { String root = null; if (StringUtils.hasLength(tilesDefinitionDelimiter)) { root = tilesDefinitionDelimiter; } root += tilesDefinitionName; if (container.isValidDefinition(root, request, response)) { result = root; } else { throw new TilesException( "No defintion of found for " + "'" + root + "'" + " or '" + sb.toString() + "'"); } } derivedDefinitionName = result; return result; } }
From source file:com._4dconcept.springframework.data.marklogic.datasource.UserCredentialsContentSourceAdapter.java
/** * This implementation delegates to the {@code newSession(username, password)} * method of the target ContentSource, passing in the specified user credentials. * If the specified username is empty, it will simply delegate to the standard * {@code newSession()} method of the target ContentSource. * @param username the username to use/*from w w w .ja v a2s . c o m*/ * @param password the password to use * @return the Session * @see com.marklogic.xcc.ContentSource#newSession(String, String) * @see com.marklogic.xcc.ContentSource#newSession() */ protected Session doGetSession(String username, String password) { Assert.state(getTargetContentSource() != null, "'targetContentSource' is required"); if (StringUtils.hasLength(username)) { return getTargetContentSource().newSession(username, password); } else { return getTargetContentSource().newSession(); } }
From source file:org.springbyexample.web.servlet.view.tiles2.MyDynamicTilesViewProcessor.java
/** * Processes values to get tiles template definition name. First * a Tiles definition matching the url is checked, then a * url specific template is checked, and then just the * default root definition is used.//w w w . java 2 s . c o m * * @throws TilesException If no valid Tiles definition is found. */ protected String processTilesDefinitionName(String beanName, TilesContainer container, HttpServletRequest request, HttpServletResponse response) throws TilesException { // if definition already derived use it, otherwise // check if url (bean name) is a template definition, then // check for main template Boolean isValidDefinition = true; try { isValidDefinition = container.isValidDefinition(beanName, request, response); } catch (NullPointerException e) { } if (derivedDefinitionName != null) { return derivedDefinitionName; } else if (isValidDefinition) { derivedDefinitionName = beanName; return beanName; } else { String result = null; StringBuilder sb = new StringBuilder(); int lastIndex = beanName.lastIndexOf("/"); boolean rootDefinition = false; // if delim, tiles def will start with it if (StringUtils.hasLength(tilesDefinitionDelimiter)) { sb.append(tilesDefinitionDelimiter); } // if no '/', then at context root if (lastIndex == -1) { rootDefinition = true; } else { String path = (beanName != null ? beanName.substring(0, lastIndex) : ""); if (StringUtils.hasLength(tilesDefinitionDelimiter)) { path = StringUtils.replace(path, "/", tilesDefinitionDelimiter); } sb.append(path); if (StringUtils.hasLength(tilesDefinitionDelimiter)) { sb.append(tilesDefinitionDelimiter); } } sb.append(tilesDefinitionName); if (container.isValidDefinition(sb.toString(), request, response)) { result = sb.toString(); } else if (!rootDefinition) { String root = null; if (StringUtils.hasLength(tilesDefinitionDelimiter)) { root = tilesDefinitionDelimiter; } root += tilesDefinitionName; if (container.isValidDefinition(root, request, response)) { result = root; } else { throw new TilesException( "No defintion of found for " + "'" + root + "'" + " or '" + sb.toString() + "'"); } } derivedDefinitionName = result; return result; } }