Example usage for org.apache.commons.lang StringUtils defaultIfEmpty

List of usage examples for org.apache.commons.lang StringUtils defaultIfEmpty

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils defaultIfEmpty.

Prototype

public static String defaultIfEmpty(String str, String defaultStr) 

Source Link

Document

Returns either the passed in String, or if the String is empty or null, the value of defaultStr.

Usage

From source file:mifosoffline.AddressDto.java

public AddressDto(String line1, String line2, String line3, String city, String state, String country,
        String zip, String phoneNumber) {
    this.line1 = StringUtils.defaultIfEmpty(line1, "");
    this.line2 = StringUtils.defaultIfEmpty(line2, "");
    this.line3 = StringUtils.defaultIfEmpty(line3, "");
    this.city = StringUtils.defaultIfEmpty(city, "");
    this.state = StringUtils.defaultIfEmpty(state, "");
    this.country = StringUtils.defaultIfEmpty(country, "");
    this.zip = StringUtils.defaultIfEmpty(zip, "");
    this.phoneNumber = StringUtils.defaultIfEmpty(phoneNumber, "");
}

From source file:com.adobe.cq.wcm.core.components.models.impl.v1.TitleImpl.java

@PostConstruct
private void initModel() {
    if (StringUtils.isBlank(title)) {
        title = StringUtils.defaultIfEmpty(currentPage.getPageTitle(), currentPage.getTitle());
    }//from   w w w.j av a2 s.  co m

    if (heading == null) {
        heading = Heading.getHeading(type);
        if (heading == null) {
            heading = Heading.getHeading(currentStyle.get(PN_DESIGN_DEFAULT_TYPE, String.class));
        }
    }
}

From source file:com.bstek.dorado.view.loader.PackagesConfigPackageParser.java

@Override
@SuppressWarnings("unchecked")
protected Object doParse(Node node, ParseContext context) throws Exception {
    Element element = (Element) node;
    String name = element.getAttribute("name");
    Assert.notEmpty(name);//  ww  w.j a  va 2  s  .c o m

    Package pkg;
    PackagesConfig packagesConfig = ((PackagesConfigParseContext) context).getPackagesConfig();
    Map<String, Package> packages = packagesConfig.getPackages();
    pkg = packages.get(name);
    if (pkg == null) {
        pkg = new Package(name);
        packages.put(name, pkg);
    }

    Map<String, Object> properties = parseProperties(element, context);
    if (!properties.containsKey("fileNames")) {
        Object value = parseProperty("fileNames", element, context);
        if (value != null && value != ConfigUtils.IGNORE_VALUE) {
            properties.put("fileNames", value);
        }
    }

    String fileNamesText = StringUtils.trim((String) properties.remove("fileNames"));
    fileNamesText = StringUtils.defaultIfEmpty(fileNamesText, NONE_FILE);
    String[] oldFileNames = pkg.getFileNames();
    String[] newFileNames = fileNamesText.split(",");
    if (oldFileNames != null && oldFileNames.length > 0) {
        newFileNames = (String[]) ArrayUtils.addAll(oldFileNames, newFileNames);
    }
    pkg.setFileNames(newFileNames);

    String dependsText = (String) properties.remove("depends");
    if (StringUtils.isNotEmpty(dependsText)) {
        String[] dependsArray = dependsText.split(",");
        for (String depends : dependsArray) {
            pkg.getDepends().add(depends);
        }
    }

    String dependedByText = (String) properties.remove("dependedBy");
    if (StringUtils.isNotEmpty(dependedByText)) {
        String[] dependedByArray = dependedByText.split(",");
        for (String dependedBy : dependedByArray) {
            pkg.getDependedBy().add(dependedBy);
        }
    }

    String clientTypeText = (String) properties.remove("clientType");
    if (StringUtils.isNotEmpty(clientTypeText)) {
        pkg.setClientType(ClientType.parseClientTypes(clientTypeText));
    }

    ((Map<String, Object>) new BeanMap(pkg)).putAll(properties);
    return pkg;
}

From source file:jenkins.security.plugins.ldap.FromUserRecordLDAPGroupMembershipStrategy.java

public String getAttributeName() {
    return StringUtils.defaultIfEmpty(attributeName, "memberOf");
}

From source file:ch.admin.suis.msghandler.common.ReceiptsFolder.java

/**
 * Creates a new mapping for a receipts folder.
 *
 * @param directory    absolute path//from   w w w  .  java2 s. co m
 * @param sedexId      the sedex ID of the participant expecting Sedex receipts in this
 *                     folder
 * @param messageTypes the types of the messages whose receipt are expected in this
 *                     folder
 */
public ReceiptsFolder(File directory, String sedexId, List<MessageType> messageTypes)
        throws ConfigurationException {
    super(directory);
    this.sedexId = sedexId;
    this.messageTypes = messageTypes;

    LOG.info("Created ReceiptsFolder: SedexId: "
            + StringUtils.defaultIfEmpty(sedexId, ClientCommons.NOT_SPECIFIED) + ", Types: {" + StringUtils
                    .defaultIfEmpty(MessageType.collectionToString(messageTypes), ClientCommons.NOT_SPECIFIED)
            + "}, Path: " + directory.getAbsolutePath());
}

From source file:edu.wisc.my.portlets.bookmarks.web.EditCollectionFormController.java

/**
 * @see org.springframework.web.portlet.mvc.SimpleFormController#onSubmitAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse, java.lang.Object, org.springframework.validation.BindException)
 *//*from www . j a va 2 s  .  c om*/
@Override
protected void onSubmitAction(ActionRequest request, ActionResponse response, Object command,
        BindException errors) throws Exception {
    final String targetParentPath = StringUtils.defaultIfEmpty(request.getParameter("folderPath"), null);
    final String targetEntryPath = StringUtils.defaultIfEmpty(request.getParameter("idPath"), null);

    //User edited bookmark
    final CollectionFolder commandCollection = (CollectionFolder) command;

    //Get the BookmarkSet from the store
    final BookmarkSet bs = this.bookmarkSetRequestResolver.getBookmarkSet(request, false);
    if (bs == null) {
        throw new IllegalArgumentException("No BookmarkSet exists for request='" + request + "'");
    }

    //Get the target parent folder
    final IdPathInfo targetParentPathInfo = FolderUtils.getEntryInfo(bs, targetParentPath);
    if (targetParentPathInfo == null || targetParentPathInfo.getTarget() == null) {
        throw new IllegalArgumentException("The specified parent Folder does not exist. BaseFolder='" + bs
                + "' and idPath='" + targetParentPath + "'");
    }

    final Folder targetParent = (Folder) targetParentPathInfo.getTarget();
    final Map<Long, Entry> targetChildren = targetParent.getChildren();

    //Get the original bookmark & it's parent folder
    final IdPathInfo originalBookmarkPathInfo = FolderUtils.getEntryInfo(bs, targetEntryPath);
    if (targetParentPathInfo == null || originalBookmarkPathInfo.getTarget() == null) {
        throw new IllegalArgumentException("The specified Bookmark does not exist. BaseFolder='" + bs
                + "' and idPath='" + targetEntryPath + "'");
    }

    final Folder originalParent = originalBookmarkPathInfo.getParent();
    final CollectionFolder originalCollection = (CollectionFolder) originalBookmarkPathInfo.getTarget();

    //If moving the bookmark
    if (targetParent.getId() != originalParent.getId()) {
        final Map<Long, Entry> originalChildren = originalParent.getChildren();
        originalChildren.remove(originalCollection.getId());

        commandCollection.setCreated(originalCollection.getCreated());
        commandCollection.setModified(new Date());

        targetChildren.put(commandCollection.getId(), commandCollection);
    }
    //If just updaing the bookmark
    //TODO should the formBackingObject be smarter on form submits for editBookmark and return the targeted bookmark?
    else {
        originalCollection.setModified(new Date());
        originalCollection.setName(commandCollection.getName());
        originalCollection.setNote(commandCollection.getNote());
        originalCollection.setUrl(commandCollection.getUrl());
        originalCollection.setMinimized(commandCollection.isMinimized());
    }

    //Persist the changes to the BookmarkSet 
    this.bookmarkStore.storeBookmarkSet(bs);
}

From source file:com.gst.accounting.closure.domain.GLClosure.java

public GLClosure(final Office office, final Date closingDate, final String comments) {
    this.office = office;
    this.deleted = false;
    this.closingDate = closingDate;
    this.comments = StringUtils.defaultIfEmpty(comments, null);
    if (this.comments != null) {
        this.comments = this.comments.trim();
    }//from   w ww. jav  a  2 s  . co  m
}

From source file:info.magnolia.setup.initial.GenericTasks.java

/**
 * @return tasks which have to be executed upon new installation (not update)
 *//*from  w ww .  ja  v  a2 s .  c  o m*/
public static List<Task> genericTasksForNewInstallation() {
    final String areWeBootstrappingAuthorInstance = StringUtils.defaultIfEmpty(
            SystemProperty.getProperty(CoreModuleVersionHandler.BOOTSTRAP_AUTHOR_INSTANCE_PROPERTY), "true");
    return Arrays.asList(
            // - install server node
            new NodeExistsDelegateTask("Server node",
                    "Creates the server node in the config repository if needed.", RepositoryConstants.CONFIG,
                    "/server", null,
                    new CreateNodeTask(null, null, RepositoryConstants.CONFIG, "/", "server",
                            NodeTypes.Content.NAME)),

            // - install or update modules node
            new NodeExistsDelegateTask("Modules node",
                    "Creates the modules node in the config repository if needed.", RepositoryConstants.CONFIG,
                    "/modules", null,
                    new CreateNodeTask(null, null, RepositoryConstants.CONFIG, "/", "modules",
                            NodeTypes.Content.NAME)),

            new BootstrapSingleResource("Bootstrap", "Bootstraps the new filter configuration",
                    "/mgnl-bootstrap/core/config.server.filters.xml",
                    ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW),

            new BootstrapSingleResource("IPConfig rules changed",
                    "Updates the existing ip access rules to match the new configuration structure or bootstraps the new default configuration.",
                    "/mgnl-bootstrap/core/config.server.IPConfig.xml"),

            new BootstrapSingleModuleResource("i18n content", "bootstrap the config",
                    "config.server.i18n.content.xml"),
            new BootstrapSingleModuleResource("i18n system", "bootstrap the config",
                    "config.server.i18n.system.xml"),

            new BootstrapSingleResource("New security configuration",
                    "Install new configuration for security managers.",
                    "/mgnl-bootstrap/core/config.server.security.xml"),
            new BootstrapSingleResource("New rendering strategy for links",
                    "Install new configuration for link resolving.",
                    "/mgnl-bootstrap/core/config.server.rendering.linkManagement.xml"),

            new BootstrapConditionally("MIME mappings",
                    "Adds MIMEMappings to server config, if not already present.",
                    "/mgnl-bootstrap/core/config.server.MIMEMapping.xml"),
            new BootstrapConditionally("URI2Repository mappings",
                    "Installs new configuration of URI2Repository mappings.",
                    "/mgnl-bootstrap/core/config.server.URI2RepositoryMapping.xml",
                    new UpdateURI2RepositoryMappings()),

            // -- /server configuration tasks
            new PropertyExistsDelegateTask("Cleanup", "Config property /server/defaultMailServer was unused.",
                    "config", "/server", "defaultMailServer",
                    new RemovePropertyTask("", "", "config", "/server", "defaultMailServer")),

            // the two following tasks replace the config.server.xml bootstrap file
            new CheckOrCreatePropertyTask("defaultExtension property",
                    "Checks that the defaultExtension property exists in config:/server", "config", "/server",
                    "defaultExtension", "html"),

            new CheckOrCreatePropertyTask("admin property",
                    "Checks that the admin property exists in config:/server", "config", "/server", "admin",
                    areWeBootstrappingAuthorInstance),

            new ArrayDelegateTask("defaultBaseUrl property",
                    new NewPropertyTask("defaultBaseUrl property",
                            "Adds the new defaultBaseUrl property with a default value.", "config", "/server",
                            "defaultBaseUrl", "http://localhost:8080/magnolia/"),
                    new WarnTask("defaultBaseUrl property",
                            "Please set the config:/server/defaultBaseUrl property to a full URL to be used when generating absolute URLs for external systems.")),

            // this is only valid when updating - if /server/login exists
            new NodeExistsDelegateTask("Login configuration",
                    "The login configuration was moved to filters configuration.", "config", "/server/login",
                    new ArrayDelegateTask("", new LoginAuthTypePropertyMovedToFilter(),
                            new LoginFormPropertyMovedToFilter(),
                            new MoveAndRenamePropertyTask(
                                    "unsecuredPath is now handled by the bypass mechanism.", "/server/login",
                                    "UnsecuredPath", "/server/filters/uriSecurity/bypasses/login", "pattern"),
                            new RemoveNodeTask("Login configuration changed",
                                    "Removes /server/login as it is not used anymore.", "config",
                                    "/server/login"))),

            // --- user/roles repositories related tasks
            new CreateNodeTask("Adds system folder node to users workspace",
                    "Add system realm folder /system to users workspace.", RepositoryConstants.USERS, "/",
                    Realm.REALM_SYSTEM.getName(), NodeTypes.Folder.NAME),
            new CreateNodeTask("Adds admin folder node to users workspace",
                    "Add magnolia realm folder /admin to users workspace.", RepositoryConstants.USERS, "/",
                    Realm.REALM_ADMIN.getName(), NodeTypes.Folder.NAME),

            new IsAuthorInstanceDelegateTask("URI permissions",
                    "Introduction of URI-based security. All existing roles will have GET/POST permissions on /*.",
                    new AddURIPermissionsToAllRoles(true), new AddURIPermissionsToAllRoles(false)),

            new IsAuthorInstanceDelegateTask("Anonymous role", "Anonymous role must exist.",
                    new BootstrapConditionally("", "Author permissions",
                            "/info/magnolia/setup/author/userroles.anonymous.xml"),
                    new BootstrapConditionally("", "Public permissions",
                            "/info/magnolia/setup/public/userroles.anonymous.xml")),

            new BootstrapConditionally("Superuser role", "Bootstraps the superuser role if needed.",
                    "/mgnl-bootstrap/core/userroles.superuser.xml"),

            new BootstrapConditionally("Anonymous user",
                    "Anonymous user must exist in the system realm: will move the existing one or bootstrap it.",
                    RepositoryConstants.USERS, "/anonymous", "/mgnl-bootstrap/core/users.system.anonymous.xml",
                    new ArrayDelegateTask("",
                            new MoveNodeTask("", "", RepositoryConstants.USERS, "/anonymous",
                                    "/system/anonymous", false),
                            new NewPropertyTask("Anonymous user", "Anonymous user must have a password.",
                                    RepositoryConstants.USERS, "/system/anonymous", "pswd",
                                    new String(Base64.encodeBase64("anonymous".getBytes()))))),

            new BootstrapConditionally("Superuser user",
                    "Superuser user must exist in the system realm: will move the existing one or bootstrap it.",
                    RepositoryConstants.USERS, "/superuser", "/mgnl-bootstrap/core/users.system.superuser.xml",
                    new MoveNodeTask("", "", RepositoryConstants.USERS, "/superuser", "/system/superuser",
                            false)),

            // --- generic tasks
            new ModuleFilesExtraction(), new RegisterModuleServletsTask(),

            // --- system-wide tasks (impact all modules)
            new WarnIgnoredModuleFilters(), new UpdateURIMappings());
}

From source file:com.adaptris.core.stubs.StubSerializableMessage.java

@Override
public void setNextServiceId(String next) {
    nextServiceId = StringUtils.defaultIfEmpty(next, "");
}

From source file:com.predic8.membrane.core.interceptor.authentication.session.SessionManager.java

@Override
protected void parseAttributes(XMLStreamReader token) throws Exception {
    cookieName = token.getAttributeValue("", "cookieName");
    timeout = Long.parseLong(StringUtils.defaultIfEmpty(token.getAttributeValue("", "timeout"), "300000"));
    domain = token.getAttributeValue("", "domain");
}