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

The following examples show how to use org.apache.commons.lang.StringUtils#trimToNull() . 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 check out the related API usage on the sidebar.
Example 1
Source File: PaymentOneclickStartMode.java    From paymentgateway with GNU General Public License v3.0 6 votes vote down vote up
@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 2
Source File: PaymentInitMode.java    From paymentgateway with GNU General Public License v3.0 6 votes vote down vote up
@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 3
Source File: OneclickInitMode.java    From paymentgateway with GNU General Public License v3.0 6 votes vote down vote up
@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 4
Source File: PaymentOneclickInitMode.java    From paymentgateway with GNU General Public License v3.0 6 votes vote down vote up
@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 5
Source File: SearchController.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
@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 6
Source File: PaymentRefundMode.java    From paymentgateway with GNU General Public License v3.0 5 votes vote down vote up
@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 7
Source File: UserSettingsValidator.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
/**
 * {@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 8
Source File: CliGitAPIImpl.java    From git-client-plugin with 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 9
Source File: JaudiotaggerParser.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
private static String getTagField(Tag tag, FieldKey fieldKey) {
    try {
        return StringUtils.trimToNull(tag.getFirst(fieldKey));
    } catch (Exception x) {
        // Ignored.
        return null;
    }
}
 
Example 10
Source File: JaudiotaggerParser.java    From airsonic with GNU General Public License v3.0 5 votes vote down vote up
private static String getTagField(Tag tag, FieldKey fieldKey) {
    try {
        return StringUtils.trimToNull(tag.getFirst(fieldKey));
    } catch (Exception x) {
        // Ignored.
        return null;
    }
}
 
Example 11
Source File: LyricsService.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
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
Source File: Weights.java    From dubbox with 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 13
Source File: PaymentProcessMode.java    From paymentgateway with GNU General Public License v3.0 5 votes vote down vote up
@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 14
Source File: PaymentProcessMode.java    From paymentgateway with GNU General Public License v3.0 5 votes vote down vote up
@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 15
Source File: I18NWebEventHandler.java    From ymate-platform-v2 with Apache License 2.0 5 votes vote down vote up
@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 16
Source File: RangerSSOAuthenticationFilter.java    From ranger with Apache License 2.0 5 votes vote down vote up
/**
 * 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 17
Source File: ECSTaskTemplate.java    From amazon-ecs-plugin with MIT License 4 votes vote down vote up
@DataBoundSetter
public void setLogDriver(String logDriver) {
    this.logDriver = StringUtils.trimToNull(logDriver);
}
 
Example 18
Source File: InternetRadioSettingsController.java    From airsonic with GNU General Public License v3.0 4 votes vote down vote up
private String getParameter(HttpServletRequest request, String name, Integer id) {
    return StringUtils.trimToNull(request.getParameter(name + "[" + id + "]"));
}
 
Example 19
Source File: CompensableHandlerInterceptor.java    From ByteTCC with GNU Lesser General Public License v3.0 4 votes vote down vote up
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 20
Source File: ConnectionParameterModel.java    From rapidminer-studio with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * 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;
}