Java Code Examples for org.apache.commons.lang.StringUtils#trimToNull()

The following examples show how to use org.apache.commons.lang.StringUtils#trimToNull() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
@Override
public void proc(ArgsConfig aConfig) {
	
	try {
		if (StringUtils.trimToNull(aConfig.initFile) == null) {
			throw new MipsException(RespCode.INVALID_PARAM, "Missing mandatory parameter initFile for paymentInit operation");
		}
		File f = new File(aConfig.initFile);
		if (!f.isFile() || !f.canRead()) {
			throw new IllegalArgumentException("Unable to load initFile " + f.getAbsolutePath());
		}
		
		PayRes res = nativeApiService.paymentInit(f);
		LOG.info("result code: {} [{}], payment status {}, payId {}", res.resultCode, res.resultMessage, res.paymentStatus, res.payId);
		if (StringUtils.trimToNull(res.customerCode) != null) {
			LOG.info("Custom payment initialized, customer code {}, finish payment via https://(i)platebnibrana.csob.cz/zaplat/{}", res.customerCode, res.customerCode);
		}
		
	} catch (Exception e) {
		throw new RuntimeException(e);
	} 
	
}
 
Example 2
@Override
public void proc(ArgsConfig aConfig) {
	
	try {
		if (StringUtils.trimToNull(aConfig.oneclickFile) == null) {
			throw new MipsException(RespCode.INVALID_PARAM, "Missing mandatory parameter oneclickFile for oneclickInit operation");
		}
		File f = new File(aConfig.oneclickFile);
		if (!f.isFile() || !f.canRead()) {
			throw new IllegalArgumentException("Unable to load oneclickFile " + f.getAbsolutePath());
		}
		
		PayRes res = nativeApiService.oneclickInit(f);
		LOG.info("result code: {} [{}], payment status {}, payId {}", res.resultCode, res.resultMessage, res.paymentStatus, res.payId);
		
	} catch (Exception e) {
		throw new RuntimeException(e);
	} 
	
}
 
Example 3
@Override
public void proc(ArgsConfig aConfig) {
	
	try {
		if (StringUtils.trimToNull(aConfig.oneclickFile) == null) {
			throw new MipsException(RespCode.INVALID_PARAM, "Missing mandatory parameter oneclickFile for paymentOneclickInit operation");
		}
		File f = new File(aConfig.oneclickFile);
		if (!f.isFile() || !f.canRead()) {
			throw new IllegalArgumentException("Unable to load recurrentFile " + f.getAbsolutePath());
		}
		
		PayRes res = nativeApiV17Service.paymentOneclickInit(f);
		LOG.info("result code: {} [{}], payment status {}, payId {}", res.resultCode, res.resultMessage, res.paymentStatus, res.payId);
		
	} catch (Exception e) {
		throw new RuntimeException(e);
	} 
	
}
 
Example 4
@Override
public void proc(ArgsConfig aConfig) {
	
	try {
		if (StringUtils.trimToNull(aConfig.payId) == null) {
			throw new MipsException(RespCode.INVALID_PARAM, "Missing mandatory parameter payId");
		}
		PayRes res = nativeApiV16Service.paymentOneclickStart(aConfig.payId);
		LOG.info("result code: {} [{}], payment status {}", res.resultCode, res.resultMessage, res.paymentStatus);
		if (res.paymentStatus != null && res.paymentStatus == 2) {
			LOG.info("oneclick payment authorization is in pending state, call payment/status to check trx state");
		}
		
	} catch (Exception e) {
		throw new RuntimeException(e);
	} 
	
}
 
Example 5
Source Project: dubbox   File: Weights.java    License: Apache License 2.0 5 votes vote down vote up
public void index(Map<String, Object> context) {
    final String service = StringUtils.trimToNull((String) context.get("service"));
    String address = (String) context.get("address");
    address = Tool.getIP(address);
    List<Weight> weights;
    if (service != null && service.length() > 0) {
        weights = OverrideUtils.overridesToWeights(overrideService.findByService(service));
    } else if (address != null && address.length() > 0) {
        weights = OverrideUtils.overridesToWeights(overrideService.findByAddress(address));
    } else {
        weights = OverrideUtils.overridesToWeights(overrideService.findAll());
    }
    context.put("weights", weights);
}
 
Example 6
/**
 * Create the URL to be used for authentication of the user in the absence
 * of a JWT token within the incoming request.
 *
 * @param request
 *            for getting the original request URL
 * @return url to use as login url for redirect
 */
       protected String constructLoginURL(HttpServletRequest request, String xForwardedURL) {
	String delimiter = "?";
	if (authenticationProviderUrl.contains("?")) {
		delimiter = "&";
	}
               String loginURL = authenticationProviderUrl + delimiter + originalUrlQueryParam + "=";
               if (StringUtils.trimToNull(xForwardedURL) != null) {
                       loginURL += xForwardedURL + getOriginalQueryString(request);
               } else {
                       loginURL += request.getRequestURL().append(getOriginalQueryString(request));
               }
	return loginURL;
}
 
Example 7
@Override
public InputStream onLoad(String resourceName) throws IOException {
    if (StringUtils.trimToNull(resourceName) != null && WebContext.getContext() != null) {
        File _resFile = new File(WebContext.getContext().getOwner().getModuleCfg().getI18nResourcesHome(), resourceName);
        if (_resFile.exists() && _resFile.isFile() && _resFile.canRead()) {
            return new FileInputStream(_resFile);
        }
    }
    return null;
}
 
Example 8
@Override
public void proc(ArgsConfig aConfig) {
	
	try {
		if (StringUtils.trimToNull(aConfig.payId) == null) {
			throw new MipsException(RespCode.INVALID_PARAM, "Missing mandatory parameter payId");
		}
		String address = nativeApiV1Service.paymentProcess(aConfig.payId);
		LOG.info("To open payment in web browser go to " + address);
	} 
	catch (Exception e) {
		throw new RuntimeException(e);
	} 
	
}
 
Example 9
@Override
public void proc(ArgsConfig aConfig) {
	
	try {
		if (StringUtils.trimToNull(aConfig.payId) == null) {
			throw new MipsException(RespCode.INVALID_PARAM, "Missing mandatory parameter payId");
		}
		String address = nativeApiV16Service.paymentProcess(aConfig.payId);
		LOG.info("To open payment in web browser go to " + address);
	} 
	catch (Exception e) {
		throw new RuntimeException(e);
	} 
	
}
 
Example 10
@PostMapping
protected String onSubmit(HttpServletRequest request, HttpServletResponse response,@ModelAttribute("command") SearchCommand command, Model model)
        throws Exception {

    User user = securityService.getCurrentUser(request);
    UserSettings userSettings = settingsService.getUserSettings(user.getUsername());
    command.setUser(user);
    command.setPartyModeEnabled(userSettings.getPartyModeEnabled());

    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(user.getUsername());
    String query = StringUtils.trimToNull(command.getQuery());

    if (query != null) {

        SearchCriteria criteria = new SearchCriteria();
        criteria.setCount(MATCH_COUNT);
        criteria.setQuery(query);

        SearchResult artists = searchService.search(criteria, musicFolders, IndexType.ARTIST);
        command.setArtists(artists.getMediaFiles());

        SearchResult albums = searchService.search(criteria, musicFolders, IndexType.ALBUM);
        command.setAlbums(albums.getMediaFiles());

        SearchResult songs = searchService.search(criteria, musicFolders, IndexType.SONG);
        command.setSongs(songs.getMediaFiles());

        command.setPlayer(playerService.getPlayer(request, response));
    }

    return "search";
}
 
Example 11
private LyricsInfo parseSearchResult(String xml) throws Exception {
    SAXBuilder builder = new SAXBuilder();
    Document document = builder.build(new StringReader(xml));

    Element root = document.getRootElement();
    Namespace ns = root.getNamespace();

    String lyric = StringUtils.trimToNull(root.getChildText("Lyric", ns));
    String song =  root.getChildText("LyricSong", ns);
    String artist =  root.getChildText("LyricArtist", ns);

    return new LyricsInfo(lyric, artist, song);
}
 
Example 12
private static String getTagField(Tag tag, FieldKey fieldKey) {
    try {
        return StringUtils.trimToNull(tag.getFirst(fieldKey));
    } catch (Exception x) {
        // Ignored.
        return null;
    }
}
 
Example 13
private static String getTagField(Tag tag, FieldKey fieldKey) {
    try {
        return StringUtils.trimToNull(tag.getFirst(fieldKey));
    } catch (Exception x) {
        // Ignored.
        return null;
    }
}
 
Example 14
Source Project: git-client-plugin   File: CliGitAPIImpl.java    License: MIT License 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public ObjectId revParse(String revName) throws GitException, InterruptedException {

    String arg = sanitize(revName + "^{commit}");
    String result = launchCommand("rev-parse", arg);
    String line = StringUtils.trimToNull(result);
    if (line == null)
        throw new GitException("rev-parse no content returned for " + revName);
    return ObjectId.fromString(line);
}
 
Example 15
/**
 * {@inheritDoc}
 */
public void validate(Object obj, Errors errors) {
    UserSettingsCommand command = (UserSettingsCommand) obj;
    String username = command.getUsername();
    String email = StringUtils.trimToNull(command.getEmail());
    String password = StringUtils.trimToNull(command.getPassword());
    String confirmPassword = command.getConfirmPassword();

    if (command.isNewUser()) {
        if (username == null || username.length() == 0) {
            errors.rejectValue("username", "usersettings.nousername");
        } else if (securityService.getUserByName(username) != null) {
            errors.rejectValue("username", "usersettings.useralreadyexists");
        } else if (email == null) {
            errors.rejectValue("email", "usersettings.noemail");
        } else if (command.isLdapAuthenticated() && !settingsService.isLdapEnabled()) {
            errors.rejectValue("password", "usersettings.ldapdisabled");
        } else if (command.isLdapAuthenticated() && password != null) {
            errors.rejectValue("password", "usersettings.passwordnotsupportedforldap");
        }
    }

    if ((command.isNewUser() || command.isPasswordChange()) && !command.isLdapAuthenticated()) {
        if (password == null) {
            errors.rejectValue("password", "usersettings.nopassword");
        } else if (!password.equals(confirmPassword)) {
            errors.rejectValue("password", "usersettings.wrongpassword");
        }
    }

    if (command.isPasswordChange() && command.isLdapAuthenticated()) {
        errors.rejectValue("password", "usersettings.passwordnotsupportedforldap");
    }

}
 
Example 16
@Override
public void proc(ArgsConfig aConfig) {
	
	try {
		if (StringUtils.trimToNull(aConfig.payId) == null) {
			throw new MipsException(RespCode.INVALID_PARAM, "Missing mandatory parameter payId");
		}
		PayRes res = nativeApiV1Service.paymentReverse(aConfig.payId);
		LOG.info("result code: {} [{}], payment status {}", res.resultCode, res.resultMessage, res.paymentStatus);
		
	} catch (Exception e) {
		throw new RuntimeException(e);
	} 
	
}
 
Example 17
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
	String transactionStr = request.getHeader(HEADER_TRANCACTION_KEY);
	if (StringUtils.isBlank(transactionStr)) {
		return true;
	}

	if (HandlerMethod.class.isInstance(handler) == false) {
		logger.warn("CompensableHandlerInterceptor cannot handle current request(uri= {}, handler= {}) correctly.",
				request.getRequestURI(), handler);
		return true;
	}

	HandlerMethod hm = (HandlerMethod) handler;
	Class<?> clazz = hm.getBeanType();
	Method method = hm.getMethod();
	if (CompensableCoordinatorController.class.equals(clazz)) {
		return true;
	} else if (ErrorController.class.isInstance(hm.getBean())) {
		return true;
	}

	String propagationStr = request.getHeader(HEADER_PROPAGATION_KEY);

	String transactionText = StringUtils.trimToNull(transactionStr);
	String propagationText = StringUtils.trimToNull(propagationStr);

	Transactional globalTransactional = clazz.getAnnotation(Transactional.class);
	Transactional methodTransactional = method.getAnnotation(Transactional.class);
	boolean transactionalDefined = globalTransactional != null || methodTransactional != null;
	Compensable annotation = clazz.getAnnotation(Compensable.class);
	if (transactionalDefined && annotation == null) {
		logger.warn("Invalid transaction definition(uri={}, handler= {})!", request.getRequestURI(), handler,
				new IllegalStateException());
		return true;
	}

	SpringCloudBeanRegistry beanRegistry = SpringCloudBeanRegistry.getInstance();
	CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory();
	TransactionInterceptor transactionInterceptor = beanFactory.getTransactionInterceptor();

	byte[] byteArray = transactionText == null ? new byte[0] : Base64.getDecoder().decode(transactionText);

	TransactionContext transactionContext = null;
	if (byteArray != null && byteArray.length > 0) {
		transactionContext = (TransactionContext) SerializeUtils.deserializeObject(byteArray);
		transactionContext.setPropagated(true);
		transactionContext.setPropagatedBy(propagationText);
	}

	TransactionRequestImpl req = new TransactionRequestImpl();
	req.setTransactionContext(transactionContext);
	req.setTargetTransactionCoordinator(beanRegistry.getConsumeCoordinator(propagationText));

	transactionInterceptor.afterReceiveRequest(req);

	CompensableManager compensableManager = beanFactory.getCompensableManager();
	CompensableTransaction compensable = compensableManager.getCompensableTransactionQuietly();
	String propagatedBy = (String) compensable.getTransactionContext().getPropagatedBy();

	byte[] responseByteArray = SerializeUtils.serializeObject(compensable.getTransactionContext());
	String compensableStr = Base64.getEncoder().encodeToString(responseByteArray);
	response.setHeader(HEADER_TRANCACTION_KEY, compensableStr);
	response.setHeader(HEADER_PROPAGATION_KEY, this.identifier);

	String sourceApplication = CommonUtils.getApplication(propagatedBy);
	String targetApplication = CommonUtils.getApplication(propagationText);
	if (StringUtils.isNotBlank(sourceApplication) && StringUtils.isNotBlank(targetApplication)) {
		response.setHeader(HEADER_RECURSIVELY_KEY,
				String.valueOf(StringUtils.equalsIgnoreCase(sourceApplication, targetApplication) == false));
	}

	return true;
}
 
Example 18
private String getParameter(HttpServletRequest request, String name, Integer id) {
    return StringUtils.trimToNull(request.getParameter(name + "[" + id + "]"));
}
 
Example 19
Source Project: amazon-ecs-plugin   File: ECSTaskTemplate.java    License: MIT License 4 votes vote down vote up
@DataBoundSetter
public void setLogDriver(String logDriver) {
    this.logDriver = StringUtils.trimToNull(logDriver);
}
 
Example 20
/**
 * Tests whether the injector name is not null and not empty.
 *
 * @return {@code true} if an inject is set; {@code false} otherwise
 */
public boolean isInjected() {
	return StringUtils.trimToNull(injectorNameProperty().get()) != null;
}