List of usage examples for org.apache.commons.lang3 StringUtils defaultIfEmpty
public static <T extends CharSequence> T defaultIfEmpty(final T str, final T defaultStr)
Returns either the passed in CharSequence, or if the CharSequence is empty or null , the value of defaultStr .
StringUtils.defaultIfEmpty(null, "NULL") = "NULL" StringUtils.defaultIfEmpty("", "NULL") = "NULL" StringUtils.defaultIfEmpty(" ", "NULL") = " " StringUtils.defaultIfEmpty("bat", "NULL") = "bat" StringUtils.defaultIfEmpty("", null) = null
From source file:org.xwiki.users.internal.WikiUserManagerTest.java
private void setupMocks(final String passedIdentifier, final String targetSpace, final String targetUserWiki, final boolean existing) { final DocumentReference targetUser = new DocumentReference(targetUserWiki, "XWiki", "Admin"); when(this.configuration.getProperty("users.defaultWiki", "local")).thenReturn("users"); when(this.modelContext.getCurrentEntityReference()) .thenReturn(new DocumentReference("local", "Main", "WebHome")); when(this.bridge.exists(new DocumentReference("xwiki", targetSpace, "Admin"))).thenReturn(false); when(this.bridge.exists(new DocumentReference("users", targetSpace, "Admin"))).thenReturn(false); when(this.bridge.exists(new DocumentReference("local", targetSpace, "Admin"))).thenReturn(false); when(this.bridge.exists(targetUser)).thenReturn(existing); when(this.referenceResolver.resolve(new EntityReference("XWikiUsers", EntityType.DOCUMENT, new EntityReference("XWiki", EntityType.SPACE)), EntityType.DOCUMENT, targetUser)) .thenReturn(new DocumentReference(targetUserWiki, "XWiki", "XWikiUsers")); when(this.serializer.serialize(targetUser, new Object[0])) .thenReturn(targetUserWiki + ":" + targetSpace + "." + StringUtils .defaultIfEmpty(StringUtils.substringAfterLast(passedIdentifier, "."), passedIdentifier)); if (passedIdentifier.startsWith(targetUserWiki + ":")) { when(this.nameResolver.resolve(passedIdentifier, EntityType.DOCUMENT, new EntityReference("XWiki", EntityType.SPACE, new WikiReference("local")))) .thenReturn(targetUser); } else {// w w w . j a va 2s . c o m when(this.nameResolver.resolve(passedIdentifier, EntityType.DOCUMENT, new EntityReference("XWiki", EntityType.SPACE, new WikiReference("xwiki")))) .thenReturn(new DocumentReference("xwiki", targetSpace, "Admin")); when(this.nameResolver.resolve(passedIdentifier, EntityType.DOCUMENT, new EntityReference("XWiki", EntityType.SPACE, new WikiReference("users")))) .thenReturn(new DocumentReference("users", targetSpace, "Admin")); when(this.nameResolver.resolve(passedIdentifier, EntityType.DOCUMENT, new EntityReference("XWiki", EntityType.SPACE, new WikiReference("local")))) .thenReturn(new DocumentReference("local", targetSpace, "Admin")); } }
From source file:processing.app.EditorTab.java
public void applyPreferences() { textarea.setCodeFoldingEnabled(PreferencesData.getBoolean("editor.code_folding")); scrollPane.setFoldIndicatorEnabled(PreferencesData.getBoolean("editor.code_folding")); scrollPane.setLineNumbersEnabled(PreferencesData.getBoolean("editor.linenumbers")); // apply the setting for 'use external editor', but only if it changed if (external != PreferencesData.getBoolean("editor.external")) { external = !external;/*from ww w. ja va2 s .co m*/ if (external) { // disable line highlight and turn off the caret when disabling textarea.setBackground(Theme.getColor("editor.external.bgcolor")); textarea.setHighlightCurrentLine(false); textarea.setEditable(false); // Detach from the code, since we are no longer the authoritative source // for file contents. file.setStorage(null); // Reload, in case the file contents already changed. reload(); } else { textarea.setBackground(Theme.getColor("editor.bgcolor")); textarea.setHighlightCurrentLine(Theme.getBoolean("editor.linehighlight")); textarea.setEditable(true); file.setStorage(this); // Reload once just before disabling external mode, to ensure we have // the latest contents. reload(); } } // apply changes to the font size for the editor Font editorFont = scale(PreferencesData.getFont("editor.font")); // check whether a theme-defined editor font is available Font themeFont = Theme.getFont("editor.font"); if (themeFont != null) { // Apply theme font if the editor font has *not* been changed by the user, // This allows themes to specify an editor font which will only be applied // if the user hasn't already changed their editor font via preferences.txt String defaultFontName = StringUtils.defaultIfEmpty(PreferencesData.getDefault("editor.font"), "") .split(",")[0]; if (defaultFontName.equals(editorFont.getName())) { editorFont = new Font(themeFont.getName(), themeFont.getStyle(), editorFont.getSize()); } } textarea.setFont(editorFont); scrollPane.getGutter().setLineNumberFont(editorFont); }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.AbstractOwncloudRestServiceImpl.java
protected void checkFailure(String username, String uri, Ocs.Meta meta) throws OwncloudStatusException { if ("ok".equals(meta.getStatus())) { return;// w w w. j a va2 s .c o m } String exceptionMessage; switch (meta.getStatuscode()) { case 997: exceptionMessage = String.format("User %s is not authorized to access Resource %s", username, uri); log.warn("Error 997: {}", exceptionMessage); throw new AccessDeniedException(exceptionMessage); case 998: log.error("Error 998: {}", meta.getMessage()); throw new UsernameNotFoundException(meta.getMessage()); default: exceptionMessage = String.format("Unknown Error Code %d. Reason: %s", meta.getStatuscode(), StringUtils.defaultIfEmpty(meta.getMessage(), "")); log.error(exceptionMessage); throw new IllegalStateException(exceptionMessage); } }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestGroupServiceImpl.java
@Override public List<String> findAllUsers(String groupname) { Validate.notBlank(groupname);//from ww w . j av a 2 s . c o m log.debug("Get all Users assigned to Group {} from Location {}", groupname, getLocation()); Ocs.Users users = exchange("/cloud/groups/{group}", HttpMethod.GET, emptyEntity(), Ocs.Users.class, (authorizationUser, uri, meta) -> { if ("ok".equals(meta.getStatus())) { return; } String exceptionMessage; switch (meta.getStatuscode()) { case 997: exceptionMessage = String.format("User %s is not authorized to access Resource %s", authorizationUser, uri); log.warn("Error 997: {}", exceptionMessage); throw new AccessDeniedException(exceptionMessage); case 998: log.error("Error 998: Group {} not found", groupname); throw new OwncloudGroupNotFoundException(groupname); default: exceptionMessage = String.format("Unknown Error Code %d. Reason: %s", meta.getStatuscode(), StringUtils.defaultIfEmpty(meta.getMessage(), "")); log.error(exceptionMessage); throw new IllegalStateException(exceptionMessage); } }, groupname); return convertUsers(users); }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestGroupServiceImpl.java
private void checkCreateGroup(String authenticatedUser, String uri, Ocs.Meta meta, String groupname) { if ("ok".equals(meta.getStatus())) { return;/* www . ja v a 2 s. c o m*/ } String exceptionMessage; switch (meta.getStatuscode()) { case 101: log.error("Error 101: {}", meta.getMessage()); throw new IllegalArgumentException(meta.getMessage()); case 102: log.warn("Error 102: Group {} already exists", groupname); throw new OwncloudGroupAlreadyExistsException(groupname); case 103: exceptionMessage = String.format("Failed to create Group %s. Reason: %s", groupname, StringUtils.defaultIfEmpty(meta.getMessage(), "")); log.error("Error 103: {}", exceptionMessage); throw new IllegalStateException(exceptionMessage); case 997: exceptionMessage = String.format("User %s is not authorized to access Resource %s", authenticatedUser, uri); log.warn("Error 997: {}", exceptionMessage); throw new AccessDeniedException(exceptionMessage); default: exceptionMessage = String.format("Unknown Error Code %d. Reason: %s", meta.getStatuscode(), StringUtils.defaultIfEmpty(meta.getMessage(), "")); log.error(exceptionMessage); throw new IllegalStateException(exceptionMessage); } }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestGroupServiceImpl.java
private void checkDeleteGroup(String authenticatedUser, String uri, Ocs.Meta meta, String groupname) { if ("ok".equals(meta.getStatus())) { return;//from ww w . j a va2s . c o m } String exceptionMessage; switch (meta.getStatuscode()) { case 101: log.warn("Error 101: Group {} not exists", groupname); throw new OwncloudGroupNotFoundException(groupname); case 102: exceptionMessage = String.format("Failed to delete Group %s. Reason: %s", groupname, StringUtils.defaultIfEmpty(meta.getMessage(), "")); log.error("Error 102: {}", exceptionMessage); throw new IllegalStateException(exceptionMessage); case 997: exceptionMessage = String.format("User %s is not authorized to access Resource %s", authenticatedUser, uri); log.warn("Error 997: {}", exceptionMessage); throw new AccessDeniedException(exceptionMessage); default: exceptionMessage = String.format("Unknown Error Code %d. Reason: %s", meta.getStatuscode(), StringUtils.defaultIfEmpty(meta.getMessage(), "")); log.error(exceptionMessage); throw new IllegalStateException(exceptionMessage); } }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestUserServiceImpl.java
private void checkFieldUpdate(String authenticatedUser, String uri, Ocs.Meta meta, String username) { if ("ok".equals(meta.getStatus())) { return;/*from www . ja v a 2 s .c om*/ } String exceptionMessage; switch (meta.getStatuscode()) { case 101: log.warn("Error 101: User {} not found", username); throw new IllegalStateException("User " + username + " not found"); case 102: log.error("Error 102: {}", meta.getMessage()); throw new IllegalStateException(meta.getMessage()); case 103: log.error("Error 103: {}", meta.getMessage()); throw new IllegalStateException(meta.getMessage()); case 997: exceptionMessage = String.format("User %s is not authorized to access Resource %s", authenticatedUser, uri); log.warn("Error 997: {}", exceptionMessage); throw new AccessDeniedException(exceptionMessage); default: exceptionMessage = String.format("Unknown Error Code %d. Reason: %s", meta.getStatuscode(), StringUtils.defaultIfEmpty(meta.getMessage(), "")); log.error(exceptionMessage); throw new IllegalStateException(exceptionMessage); } }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestUserServiceImpl.java
private void checkAvailabilityStatusUpdate(String authenticatedUser, String uri, Ocs.Meta meta, String username) {// w ww. jav a 2 s.c om if ("ok".equals(meta.getStatus())) { return; } String exceptionMessage; switch (meta.getStatuscode()) { case 101: log.error("Error 101: User {} not found", username); throw new IllegalStateException("User " + username + " not found"); case 102: log.error("Error 102: {}", meta.getMessage()); throw new IllegalStateException(meta.getMessage()); case 997: exceptionMessage = String.format("User %s is not authorized to access Resource %s", username, uri); log.warn("Error 997: {}", exceptionMessage); throw new AccessDeniedException(exceptionMessage); default: exceptionMessage = String.format("Unknown Error Code %d. Reason: %s", meta.getStatuscode(), StringUtils.defaultIfEmpty(meta.getMessage(), "")); log.error(exceptionMessage); throw new IllegalStateException(exceptionMessage); } }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestUserServiceImpl.java
private void checkAssignGroupMembership(String authenticatedUser, String uri, Ocs.Meta meta, String username, String groupname) {/* ww w . java2 s. co m*/ if ("ok".equals(meta.getStatus())) { return; } String exceptionMessage; switch (meta.getStatuscode()) { case 101: log.error("Error 101: {}", meta.getMessage()); throw new IllegalArgumentException(meta.getMessage()); case 102: log.warn("Error 102: Owncloud Group {} not found", groupname); throw new OwncloudGroupNotFoundException(groupname); case 103: log.warn("Error 103: User {} not found", username); throw new IllegalStateException("User " + username + " not found"); case 104: exceptionMessage = String.format("User %s is not authorized to assign Group %s to User %s", username, groupname, username); log.warn("Error 104: {}", exceptionMessage); throw new AccessDeniedException(exceptionMessage); case 105: exceptionMessage = String.format("Error while assign Group %s to User %s. Reason: %s", groupname, username, StringUtils.defaultIfEmpty(meta.getMessage(), "")); log.error("Error 105: {}", exceptionMessage); throw new IllegalStateException(exceptionMessage); case 997: exceptionMessage = String.format("User %s is not authorized to access Resource %s", username, uri); log.warn("Error 997: {}", exceptionMessage); throw new AccessDeniedException(exceptionMessage); default: exceptionMessage = String.format("Unknown Error Code %d. Reason: %s", meta.getStatuscode(), StringUtils.defaultIfEmpty(meta.getMessage(), "")); log.error(exceptionMessage); throw new IllegalStateException(exceptionMessage); } }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestUserServiceImpl.java
private void checkRemoveGroupMembership(String authenticatedUser, String uri, Ocs.Meta meta, String username, String groupname) {//from w ww. jav a 2s .co m if ("ok".equals(meta.getStatus())) { return; } String exceptionMessage; switch (meta.getStatuscode()) { case 101: log.error("Error 101: {}", meta.getMessage()); throw new IllegalArgumentException(meta.getMessage()); case 102: log.warn("Error 102: Owncloud Group {} not found", groupname); throw new OwncloudGroupNotFoundException(groupname); case 103: log.warn("Error 103: User {} not found", username); throw new IllegalStateException("User " + username + " not found"); case 104: exceptionMessage = String.format("User %s is not authorized to unassign Group %s from User %s", authenticatedUser, groupname, username); log.warn("Error 104: {}", exceptionMessage); throw new AccessDeniedException(exceptionMessage); case 105: exceptionMessage = String.format("Error while unassign Group %s from User %s. Reason: %s", groupname, username, StringUtils.defaultIfEmpty(meta.getMessage(), "")); log.error("Error 105: {}", exceptionMessage); throw new IllegalStateException(exceptionMessage); case 997: exceptionMessage = String.format("User %s is not authorized to access Resource %s", authenticatedUser, uri); log.warn("Error 997: {}", exceptionMessage); throw new AccessDeniedException(exceptionMessage); default: exceptionMessage = String.format("Unknown Error Code %d. Reason: %s", meta.getStatuscode(), StringUtils.defaultIfEmpty(meta.getMessage(), "")); log.error(exceptionMessage); throw new IllegalStateException(exceptionMessage); } }