List of usage examples for org.apache.commons.lang StringUtils defaultIfEmpty
public static String defaultIfEmpty(String str, String defaultStr)
Returns either the passed in String, or if the String is empty or null
, the value of defaultStr
.
From source file:org.jenkinsci.plugins.github_branch_source.Connector.java
private static List<DomainRequirement> githubDomainRequirements(String apiUri) { return URIRequirementBuilder.fromUri(StringUtils.defaultIfEmpty(apiUri, "https://github.com")).build(); }
From source file:org.jfrog.hudson.release.scm.git.GitManager.java
private GitClient getGitClient(ReleaseRepository releaseRepository) throws IOException, InterruptedException { FilePath directory = getWorkingDirectory(getJenkinsScm(), build.getWorkspace()); EnvVars env = build.getEnvironment(buildListener); Git git = new Git(buildListener, env); git.in(directory);// w w w . j a v a 2 s. co m /* * When init the git exe, the user dons`t have to add SSH credentials in the git plugin. * This solution automatically takes the user default SSH ($HOME/.ssh) * */ git.using(getJenkinsScm().getGitExe(build.getBuiltOn(), buildListener)); // git.exe GitClient client = git.getClient(); client.setCommitter(StringUtils.defaultIfEmpty(env.get("GIT_COMMITTER_NAME"), ""), StringUtils.defaultIfEmpty(env.get("GIT_COMMITTER_EMAIL"), "")); client.setAuthor(StringUtils.defaultIfEmpty(env.get("GIT_AUTHOR_NAME"), ""), StringUtils.defaultIfEmpty(env.get("GIT_AUTHOR_EMAIL"), "")); if (releaseRepository != null && releaseRepository.isTargetRepoUri()) { client.setRemoteUrl(releaseRepository.getRepositoryName(), releaseRepository.getTargetRepoPrivateUri()); } else { addRemoteRepoToConfig(client); } addCredentialsToGitClient(client); return client; }
From source file:org.jiemamy.eclipse.core.ui.composer.DbImporterWizardPage.java
public void createControl(final Composite parent) { // CHECKSTYLE IGNORE THIS LINE Label label;/* w w w.ja v a 2 s. c o m*/ GridData gd; Composite composite = new Composite(parent, SWT.NULL); composite.setLayout(new GridLayout(3, false)); composite.setLayoutData(new GridData(GridData.FILL_BOTH)); label = new Label(composite, SWT.NONE); label.setText(Messages.DbImportWizardPage_label_dbType); cmbDialect = new Combo(composite, SWT.READ_ONLY); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = 2; cmbDialect.setLayoutData(gd); for (Dialect dialect : dialectResolver.getAllInstance()) { cmbDialect.add(dialect.getClass().getName()); } cmbDialect.select(0); cmbDialect.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String connectionUriTemplate = getDialect().getConnectionUriTemplate(); txtUri.setText(StringUtils.defaultIfEmpty(connectionUriTemplate, txtUri.getText())); } }); // THINK JiemamyContext???Dialect?? // cmbDialect.setText(context.getMetadata().getDialectClassName()); cmbDialect.setText(StringUtils.defaultIfEmpty(settings.get("cmbDialect"), "")); label = new Label(composite, SWT.NONE); label.setText("JDBC?jar(&J)"); // RESOURCE lstDriverJars = new org.eclipse.swt.widgets.List(composite, SWT.BORDER | SWT.MULTI); lstDriverJars.setLayoutData(new GridData(GridData.FILL_BOTH)); String pathsString = StringUtils.defaultIfEmpty(settings.get("lstDriverJars"), ""); for (String path : pathsString.split(File.pathSeparator)) { if (new File(path).exists()) { lstDriverJars.add(path); } } Composite cmpButtons = new Composite(composite, SWT.NULL); cmpButtons.setLayout(new RowLayout(SWT.VERTICAL)); createButtons(cmpButtons); label = new Label(composite, SWT.NONE); label.setText("JDBC?(&C)"); // RESOURCE cmbDriverClass = new Combo(composite, SWT.BORDER | SWT.READ_ONLY); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = 2; cmbDriverClass.setLayoutData(gd); if (lstDriverJars.getItemCount() > 0) { driverListChanged(); } cmbDriverClass.setText(StringUtils.defaultIfEmpty(settings.get("cmbDriverClass"), "")); label = new Label(composite, SWT.NONE); label.setText("URI(&I)"); // RESOURCE txtUri = new Text(composite, SWT.BORDER); txtUri.addFocusListener(new TextSelectionAdapter(txtUri)); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = 2; txtUri.setLayoutData(gd); txtUri.setText(StringUtils.defaultIfEmpty(settings.get("txtUri"), "")); label = new Label(composite, SWT.NONE); label.setText("??(&U)"); // RESOURCE txtUsername = new Text(composite, SWT.BORDER); txtUsername.addFocusListener(new TextSelectionAdapter(txtUsername)); txtUsername.setText("sa"); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = 2; txtUsername.setLayoutData(gd); txtUsername.setText(StringUtils.defaultIfEmpty(settings.get("txtUsername"), "")); label = new Label(composite, SWT.NONE); label.setText("(&P)"); // RESOURCE txtPassword = new Text(composite, SWT.BORDER | SWT.PASSWORD); txtPassword.addFocusListener(new TextSelectionAdapter(txtPassword)); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = 2; txtPassword.setLayoutData(gd); txtPassword.setText(StringUtils.defaultIfEmpty(settings.get("txtPassword"), "")); label = new Label(composite, SWT.NONE); label.setText("??(&S)"); // RESOURCE txtSchema = new Text(composite, SWT.BORDER); txtSchema.addFocusListener(new TextSelectionAdapter(txtSchema)); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = 2; txtSchema.setLayoutData(gd); txtSchema.setText(StringUtils.defaultIfEmpty(settings.get("txtSchema"), "")); @SuppressWarnings("unused") Object unused = new Label(composite, SWT.NONE); btnImportDataSet = new Button(composite, SWT.CHECK); btnImportDataSet.setText("DataSet??"); // RESOURCE gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = 2; btnImportDataSet.setLayoutData(gd); btnImportDataSet.setSelection(settings.getBoolean("btnImportDataSet")); createTestButton(composite); setControl(composite); }
From source file:org.jspare.forvertx.web.auth.BasicAuthProvider.java
@Override @SneakyThrows(IOException.class) public JsonObject provideAuthdata(RoutingContext ctx) { JsonObject authData = new JsonObject(); String authorization = ctx.request().getHeader(AUTHORIZATION); String[] splited = StringUtils.defaultIfEmpty(authorization, StringUtils.EMPTY).split(SPACE); if (splited.length == 2 && BASIC.equals(splited[0])) { String token = IOUtils.toString(java.util.Base64.getDecoder().decode(splited[1]), Definitions.DEFAULT_CHARSET.name()); String[] tSplited = token.split(":"); authData.put(USERNAME, tSplited[0]); authData.put(PASSWORD, tSplited[1]); } else {//ww w . j av a 2 s . c o m ctx.response().putHeader("WWW-Authenticate", "Basic"); } return authData; }
From source file:org.jspare.forvertx.web.collector.HandlerCollector.java
public static Collection<HandlerData> collect(Transporter transporter, Class<?> clazz) { List<HandlerData> collectedHandlers = new ArrayList<>(); List<Annotation> httpMethodsAnnotations = new ArrayList<>(getHttpMethodsPresents(clazz)); boolean hasAuthClass = clazz.isAnnotationPresent(Auth.class); Auth authClass = clazz.getAnnotation(Auth.class); for (Method method : clazz.getDeclaredMethods()) { if (!isHandler(method)) { continue; }/*from w w w . j a v a2s . c om*/ final List<Annotation> handlerHttpMethodsAnnotations = new ArrayList<>(); handlerHttpMethodsAnnotations.addAll(httpMethodsAnnotations); String consumes = method.isAnnotationPresent(Consumes.class) ? method.getAnnotation(Consumes.class).value() : StringUtils.EMPTY; String produces = method.isAnnotationPresent(Produces.class) ? method.getAnnotation(Produces.class).value() : StringUtils.EMPTY; Class<? extends Handler<RoutingContext>> routeHandlerClass = transporter.getRouteHandlerClass(); List<org.jspare.forvertx.web.handler.BodyEndHandler> bodyEndHandler = collectBodyEndHandlers( transporter, method); boolean hasMethodAuth = false; boolean skipAuthorities = false; String autority = StringUtils.EMPTY; HandlerDocumentation hDocumentation = null; if (method.isAnnotationPresent(Documentation.class)) { Documentation documentation = method.getAnnotation(Documentation.class); hDocumentation = new HandlerDocumentation(); hDocumentation.description(documentation.description()); hDocumentation.status(Arrays.asList(documentation.responseStatus()).stream() .map(s -> new HandlerDocumentation.ResponseStatus(s)).collect(Collectors.toList())); hDocumentation.queryParameters(Arrays.asList(documentation.queryParameters()).stream() .map(q -> new HandlerDocumentation.QueryParameter(q)).collect(Collectors.toList())); hDocumentation.requestSchema(documentation.requestClass()); hDocumentation.responseSchema(documentation.responseClass()); } if (!method.isAnnotationPresent(IgnoreAuth.class)) { if (method.isAnnotationPresent(Auth.class)) { Auth auth = method.getAnnotation(Auth.class); hasMethodAuth = true; skipAuthorities = auth.skipAuthorities(); autority = StringUtils.defaultIfEmpty(auth.value(), StringUtils.EMPTY); } else { if (hasAuthClass) { hasMethodAuth = true; skipAuthorities = authClass.skipAuthorities(); autority = StringUtils.defaultIfEmpty(authClass.value(), StringUtils.EMPTY); } } } HandlerData defaultHandlerData = new HandlerData().clazz(clazz).method(method).consumes(consumes) .produces(produces).bodyEndHandler(bodyEndHandler).auth(hasMethodAuth) .skipAuthorities(skipAuthorities).autority(autority).authProvider(transporter.getAuthProvider()) .routeHandler(routeHandlerClass).documentation(hDocumentation); if (hasHttpMethodsPresents(method)) { handlerHttpMethodsAnnotations.clear(); handlerHttpMethodsAnnotations.addAll(getHttpMethodsPresents(method)); } getHandlersPresents(method).forEach(handlerType -> { try { // Extract order from Handler, all Hanlder having order() // method int order = annotationMethod(handlerType, "order"); HandlerData handlerData = (HandlerData) defaultHandlerData.clone(); handlerData.order(order); if (isHandlerAnnotation(handlerType, org.jspare.forvertx.web.mapping.handlers.Handler.class)) { handlerData.handlerType(HandlerType.HANDLER); } else if (isHandlerAnnotation(handlerType, FailureHandler.class)) { handlerData.handlerType(HandlerType.HANDLER); } else if (isHandlerAnnotation(handlerType, BlockingHandler.class)) { handlerData.handlerType(HandlerType.BLOCKING_HANDLER); } if (handlerHttpMethodsAnnotations.isEmpty()) { collectedHandlers.add(handlerData); } else { collectedHandlers.addAll(collectByMethods(handlerData, handlerHttpMethodsAnnotations)); } } catch (Exception e) { log.warn("Ignoring handler class {} method {} - {}", clazz.getName(), method.getName(), e.getMessage()); } }); } return collectedHandlers; }
From source file:org.jspare.forvertx.web.transporter.Transporter.java
/** * Listen./* w w w. j av a 2 s . c o m*/ */ public void listen() { listen((server) -> { if (server.failed()) { log.error("Address port in use: [{}]", port); throw new HttpServerListenException(server.cause()); } log.info(StringUtils.repeat("#", 50)); log.info("# Tranposrter name [{}]", StringUtils.defaultIfEmpty(this.name, "DEFAULT")); log.info("# Vert.x httpServer started at: 127.0.0.1:{}", port); log.info(StringUtils.repeat("#", 50)); }); }
From source file:org.jtalks.jcommune.web.dto.UserContactDto.java
/** * Replaced stubs in display pattern for this contact type by actual * contact value/*from w w w. j a v a 2 s . com*/ * @return actual ready-to-display contact */ public String getDisplayValue() { String replacement = StringUtils.defaultIfEmpty(value, ""); return type.getDisplayValue(replacement); }
From source file:org.jumpmind.symmetric.web.ServletUtils.java
/** * Returns the parameter with that name, trimmed to null. If the trimmed * string is null, defaults to the defaultValue. * /* w ww. j a v a 2 s . com*/ * @param request * @param name * @return */ public static String getParameter(HttpServletRequest request, String name, String defaultValue) { return StringUtils.defaultIfEmpty(StringUtils.trimToNull(request.getParameter(name)), defaultValue); }
From source file:org.jumpmind.symmetric.web.SymmetricServlet.java
protected boolean matchesUriPattern(String uri, String uriPattern) { boolean retVal = false; String path = StringUtils.defaultIfEmpty(uri, "/"); final String pattern = StringUtils.defaultIfEmpty(uriPattern, "/"); if ("/".equals(pattern) || "/*".equals(pattern) || pattern.equals(path)) { retVal = true;// ww w. jav a 2 s . c o m } else { final String[] patternParts = StringUtils.split(pattern, "/"); final String[] pathParts = StringUtils.split(path, "/"); boolean matches = true; for (int i = 0; i < patternParts.length && i < pathParts.length && matches; i++) { final String patternPart = patternParts[i]; matches = "*".equals(patternPart) || patternPart.equals(pathParts[i]); } retVal = matches; } return retVal; }
From source file:org.kafka.event.microaggregator.core.DataUtils.java
public static String makeCombinedEventName(String eventName) { return StringUtils.defaultIfEmpty(formatedEventNameMap.get(eventName), eventName); }