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.codinjutsu.tools.jenkins.JenkinsSettings.java
public String getPassword() { String password;/*from w ww .j a v a2 s.com*/ try { PasswordSafeImpl passwordSafe = (PasswordSafeImpl) PasswordSafe.getInstance(); password = passwordSafe.getPassword(null, JenkinsAppSettings.class, JENKINS_SETTINGS_PASSWORD_KEY); } catch (PasswordSafeException e) { LOG.info("Couldn't get password for key [" + JENKINS_SETTINGS_PASSWORD_KEY + "]", e); password = ""; } return StringUtils.defaultIfEmpty(password, ""); }
From source file:org.dresdenocl.pivotmodel.provider.NamespaceItemProvider.java
/** * This returns the label text for the adapted class. * /*from w ww. j a v a2s. c om*/ * <p> * The EMF implementation is changed to return the name of the adapted * {@link Namespace} or <code>null</code> if no name is set. Existing type * parameters are appended as well. * </p> * * @generated NOT */ @Override public String getText(Object object) { StringBuilder label; Namespace namespace; // cast namespace namespace = (Namespace) object; // initialize with name label = new StringBuilder(StringUtils.defaultIfEmpty(namespace.getName(), "null")); //$NON-NLS-1$ // append type parameters if there are any if (!namespace.getOwnedTypeParameter().isEmpty()) { label.append('<'); for (Iterator<TypeParameter> it = namespace.getOwnedTypeParameter().iterator(); it.hasNext();) { label.append(it.next().getName()); if (it.hasNext()) { label.append(", "); //$NON-NLS-1$ } } label.append('>'); } return label.toString(); }
From source file:org.eclipse.gyrex.http.jetty.internal.app.ApplicationDelegateHandler.java
@Override public void doScope(final String target, final Request baseRequest, final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException { /*/*from w w w. j a va 2 s. c o m*/ * This scope implementation is different. We delegate to * the application immediately. The assumption is, the context, * path info and session has been properly set up by scoping * from previous handlers (scopes). * * The next scope would be the servlet handler which handles * servlets registered via IApplicationContext. However, the * ServletHandler already modifies the scope by setting * a servlet path and path info as of the found servlet. * This is wrong when calling Application#handleRequest. * * It's completely up to the Application if the ServletHandler * should be called or not. It does so via calling the * IApplicationContext method. This is implemented in this class * as well (handleApplicationRequest) and continues with the next * scope. */ // delegated to the application // the application may delegate back to us via ApplicationContext try { final Application application = applicationHandler.getApplication(); // setup MDC setupMdc(application, request); // check application status final IStatus status = application.getStatus(); if (!status.isOK()) { // abort request processing final String message = StringUtils.defaultIfEmpty(status.getMessage(), "Application not ready."); // we convert it into UnavailableException if (Platform.inDebugMode()) { LOG.warn("Application '{}' returned a not-ok status: {}", new Object[] { application.getId(), status }); throw new UnavailableException(message, 5); } else throw new UnavailableException(message, 30); // TODO make configurable } // route to application if (JettyDebug.handlers) { LOG.debug("routing request to application {}", application); } application.handleRequest(request, response); } catch (final IOException e) { if (Platform.inDebugMode()) { LOG.warn("Caught IOException while processing request '{}': {}", new Object[] { request, e.getMessage(), e }); } throw e; } catch (final ApplicationException e) { // handle ApplicationException if (e.getStatus() == HttpStatus.SERVICE_UNAVAILABLE_503) { // we convert it into UnavailableException if (Platform.inDebugMode()) { LOG.warn("Caught ApplicationException while processing request '{}': {}", new Object[] { request, e.getMessage(), e }); throw new UnavailableException(e.getMessage(), 5); } else throw new UnavailableException(e.getMessage(), 30); // TODO make configurable } else { if (Platform.inDebugMode()) { LOG.warn("Caught ApplicationException while processing request '{}': {}", new Object[] { request, e.getMessage(), e }); response.sendError(e.getStatus(), e.getMessage()); } else { response.sendError(e.getStatus()); } } } catch (final IllegalStateException e) { // IllegalStateException are typically used in Gyrex to indicate that something isn't ready // we convert it into UnavailableException to allow recovering on a dynamic platform if (Platform.inDebugMode()) { LOG.warn("Caught IllegalStateException while processing request '{}': {}", new Object[] { request, e.getMessage(), e }); throw new UnavailableException(e.getMessage(), 5); } else throw new UnavailableException(e.getMessage(), 30); // TODO make configurable } catch (final RuntimeException e) { if (Platform.inDebugMode()) { LOG.warn("Caught RuntimeException while processing request '{}': {}", new Object[] { request, e.getMessage(), e }); } throw e; } finally { // clear the MDC clearMdc(); } // mark the request handled (if this point is reached) baseRequest.setHandled(true); }
From source file:org.eclipse.jubula.client.ui.views.TestresultSummaryView.java
/** * @param tableViewer the tableViewer//from w ww.java2 s.c o m */ private void addMonitoringIdColumn(TableViewer tableViewer) { TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE); column.getColumn().setWidth(200); column.getColumn().setImage(IconConstants.INFO_IMAGE); column.getColumn().setText(MONITORING_ID); column.getColumn().setMoveable(true); column.setLabelProvider(new TestresultSummaryViewColumnLabelProvider() { public String getText(Object element) { return StringUtils.defaultIfEmpty(((ITestResultSummaryPO) element).getInternalMonitoringId(), Messages.TestresultSummaryMonitoringIdNonSelected); } }); createMenuItem(m_headerMenu, column.getColumn()); new ColumnViewerSorter(tableViewer, column) { @Override protected int doCompare(Viewer viewer, Object e1, Object e2) { return getCommonsComparator().compare(((ITestResultSummaryPO) e1).getInternalMonitoringId(), ((ITestResultSummaryPO) e2).getInternalMonitoringId()); } }; }
From source file:org.eclipse.wb.internal.core.databinding.wizards.autobindings.AutomaticDatabindingWizard.java
/** * @return the fully qualified name of class if given {@link IStructuredSelection} contains .java * file./*from ww w .j av a 2s .c o m*/ */ protected static String getSelectionBeanClass(IStructuredSelection selection) { try { // check no selection if (UiUtils.isEmpty(selection)) { return null; } // prepare selection object Object object = selection.getFirstElement(); // check java selection if (object instanceof IJavaElement) { IJavaElement element = (IJavaElement) object; // find compilation unit while (element != null) { if (element instanceof ICompilationUnit) { ICompilationUnit compilationUnit = (ICompilationUnit) element; IType[] types = compilationUnit.getTypes(); // find main type if (!ArrayUtils.isEmpty(types)) { return StringUtils.defaultIfEmpty(types[0].getFullyQualifiedName(), null); } // wrong selection return null; } // lookup to parent element = element.getParent(); } } } catch (Throwable e) { DesignerPlugin.log(e); } // wrong selection return null; }
From source file:org.eclipse.wb.internal.rcp.databinding.emf.model.observables.DetailEmfObservableInfo.java
@Override public String getPresentationText() throws Exception { String presentationProperty = StringUtils.defaultIfEmpty(m_detailEMFPropertyName, "?????"); String presentationPropertyType = m_detailPropertyType == null ? "?????" : ClassUtils.getShortClassName(m_detailPropertyType); return m_masterObservable.getPresentationText() + ".detail" + getPresentationPrefix() + "(" + presentationProperty + ", " + presentationPropertyType + ".class)"; }
From source file:org.eclipse.wb.internal.rcp.databinding.model.beans.observables.DetailBeanObservableInfo.java
@Override public String getPresentationText() throws Exception { String presentationProperty = StringUtils.defaultIfEmpty(m_detailPropertyReference, "?????"); String presentationPropertyType = m_detailPropertyType == null ? "?????" : ClassUtils.getShortClassName(m_detailPropertyType); return m_masterObservable.getPresentationText() + ".detail" + getPresentationPrefix() + "(" + presentationProperty + ", " + presentationPropertyType + ".class)"; }
From source file:org.ednovo.data.handlers.DataUtils.java
public static String makeEventNameConsistent(String eventName) { return StringUtils.defaultIfEmpty(formatedEventNameMap.get(eventName), eventName); }
From source file:org.ednovo.gooru.domain.service.annotation.AnnotationServiceImpl.java
@Override public void create(Annotation annotation, String type, Errors errors) { if (annotation.getUser() == null) { errors.reject(USER, INVALID_USER); }/*from w w w . j a v a 2s.co m*/ if (annotation.getResource() == null || annotation.getResource().getGooruOid() == null) { errors.reject(RESOURCE, INVALID_RESOURCE); } if (errors.hasErrors()) { return; } AnnotationType annotationType = (AnnotationType) this.getBaseRepository().get(AnnotationType.class, type); ContentType contentTypeAnnotation = (ContentType) this.getBaseRepository().get(ContentType.class, ContentType.ANNOTATION); annotation.setGooruOid(UUID.randomUUID().toString()); annotation.setAnnotationType(annotationType); annotation.setContentType(contentTypeAnnotation); annotation.setSharing(StringUtils.defaultIfEmpty(annotation.getSharing(), Sharing.PRIVATE.getSharing())); annotation.setCreatedOn(new Date(System.currentTimeMillis())); annotation.setLastModified(new Date(System.currentTimeMillis())); this.getContentRepository().save(annotation); UserContentRelationshipUtil.updateUserContentRelationship(annotation.getResource(), annotation.getUser(), (type.equals(AnnotationType.Type.SUBSCRIPTION.getType())) ? RELATIONSHIP.SUBSCRIBE : RELATIONSHIP.QUOTE); }
From source file:org.failearly.dataset.internal.resource.DataSetResourceBase.java
DataSetResourceBase(String resourceName, DataStoreSetup dataStoreSetup) { this.resourceName = resourceName; this.dataStoreId = dataStoreSetup.datastore(); this.name = StringUtils.defaultIfEmpty(dataStoreSetup.name(), dataStoreId); this.transactional = dataStoreSetup.transactional(); this.setupConfigValues = Arrays.asList(dataStoreSetup.setupConfigValues()); this.cleanupConfigValues = Arrays.asList(dataStoreSetup.cleanupConfigValues()); this.failOnError = dataStoreSetup.failOnError(); }