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

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

Introduction

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

Prototype

public static String defaultString(String str) 

Source Link

Document

Returns either the passed in String, or if the String is null, an empty String ("").

Usage

From source file:gtu._work.mvn.MavenRepositoryUI.java

private void clipboardPomJarConfig(PomFile pomFile, boolean isOpen) {
    try {/*w ww.  j  a va  2s .  c om*/
        StringBuilder sb = new StringBuilder();
        sb.append("             <dependency>                                   \n");
        sb.append("                     <!-- {0} -->                           \n");
        sb.append("                     <groupId>{1}</groupId>                 \n");
        sb.append("                     <artifactId>{2}</artifactId>           \n");
        sb.append("                     <version>{3}</version>                 \n");
        sb.append("             </dependency>                                  \n");

        String jarName = pomFile.jarFile == null ? "" : pomFile.jarFile.getName();
        Pom pom = pomFile.pom;
        String groupId = pom.groupId;
        String artifactId = pom.artifactId;
        String version = pom.version;
        {
            Pom tmpPom = pom;
            while (groupId == null && tmpPom != null) {
                tmpPom = pom.parent;
                groupId = tmpPom.groupId;
            }
        }
        {
            Pom tmpPom = pom;
            while (artifactId == null && tmpPom != null) {
                tmpPom = pom.parent;
                artifactId = tmpPom.artifactId;
            }
        }
        {
            Pom tmpPom = pom;
            while (version == null && tmpPom != null) {
                tmpPom = pom.parent;
                version = tmpPom.version;
            }
        }
        groupId = StringUtils.defaultString(groupId);
        artifactId = StringUtils.defaultString(artifactId);
        version = StringUtils.defaultString(version);

        String pomMessage = MessageFormat.format(sb.toString(), jarName, groupId, artifactId, version);
        if (isOpen) {
            JCommonUtil._jOptionPane_showMessageDialog_info(pomMessage);
        }
        ClipboardUtil.getInstance().setContents(pomMessage);
    } catch (Exception ex) {
        JCommonUtil.handleException(ex);
    }
}

From source file:com.redhat.rhn.frontend.xmlrpc.system.SystemHandler.java

/**
 * Get the addresses and hostname for a given server
 * @param loggedInUser The current user/*from w  w w.  j av a2  s. c o  m*/
 * @param sid The id of the server in question
 * @return Returns a map containing the servers addresses and hostname attributes
 * @throws FaultException A FaultException is thrown if the server corresponding to
 * sid cannot be found.
 *
 * @xmlrpc.doc Get the addresses and hostname for a given server.
 * @xmlrpc.param #param("string", "sessionKey")
 * @xmlrpc.param #param("int", "serverId")
 * @xmlrpc.returntype
 *          #struct("network info")
 *              #prop_desc("string", "ip", "IPv4 address of server")
 *              #prop_desc("string", "ip6", "IPv6 address of server")
 *              #prop_desc("string", "hostname", "Hostname of server")
 *          #struct_end()
 */
public Map<String, String> getNetwork(User loggedInUser, Integer sid) throws FaultException {
    // Get the logged in user and server
    Server server = lookupServer(loggedInUser, sid);

    // Get the ip, ip6 and hostname for the server
    String ip = server.getIpAddress();
    String ip6 = server.getIp6Address();
    String hostname = server.getHostname();

    // Stick in a map and return
    Map<String, String> network = new HashMap<String, String>();
    network.put("ip", StringUtils.defaultString(ip));
    network.put("ip6", StringUtils.defaultString(ip6));
    network.put("hostname", StringUtils.defaultString(hostname));

    return network;
}

From source file:com.redhat.rhn.frontend.xmlrpc.system.SystemHandler.java

/**
 * List the available groups for a given system
 * @param loggedInUser The current user//from   w  w w .  ja va  2s .c  o m
 * @param sid The id for the server in question
 * @return Returns an array of maps representing a system group
 * @throws FaultException A FaultException is thrown if the server corresponding to
 * sid cannot be found.
 *
 * @xmlrpc.doc List the available groups for a given system.
 * @xmlrpc.param #param("string", "sessionKey")
 * @xmlrpc.param #param("int", "serverId")
 * @xmlrpc.returntype
 *  #array()
 *      #struct("system group")
 *          #prop_desc("int", "id", "server group id")
 *          #prop_desc("int", "subscribed", "1 if the given server is subscribed
 *               to this server group, 0 otherwise")
 *          #prop_desc("string", "system_group_name", "Name of the server group")
 *          #prop_desc("string", "sgid", "server group id (Deprecated)")
 *      #struct_end()
 *  #array_end()
 */
public Object[] listGroups(User loggedInUser, Integer sid) throws FaultException {
    // Get the logged in user and server
    Server server = lookupServer(loggedInUser, sid);

    DataResult<Map<String, Object>> groups = SystemManager.availableSystemGroups(server, loggedInUser);
    List<Map<String, Object>> returnList = new ArrayList<Map<String, Object>>();

    // More stupid data munging...
    for (Iterator<Map<String, Object>> itr = groups.iterator(); itr.hasNext();) {
        Map<String, Object> map = itr.next();
        Map<String, Object> row = new HashMap<String, Object>();

        row.put("id", map.get("id"));
        row.put("sgid", map.get("id").toString());
        row.put("system_group_name", StringUtils.defaultString((String) map.get("group_name")));
        row.put("subscribed", map.get("is_system_member"));
        returnList.add(row);
    }

    return returnList.toArray();
}

From source file:com.manydesigns.portofino.pageactions.crud.AbstractCrudAction.java

public String getSearchTitle() {
    String title = crudConfiguration.getSearchTitle();
    if (StringUtils.isBlank(title)) {
        title = getPage().getTitle();//  w w  w. j  a  v  a2  s.co  m
    }
    OgnlTextFormat textFormat = OgnlTextFormat.create(StringUtils.defaultString(title));
    return textFormat.format(this);
}

From source file:com.manydesigns.portofino.pageactions.crud.AbstractCrudAction.java

public String getEditTitle() {
    String title = crudConfiguration.getEditTitle();
    if (StringUtils.isEmpty(title)) {
        return ShortNameUtils.getName(getClassAccessor(), object);
    } else {//w ww .  j ava 2s  .  c  o  m
        OgnlTextFormat textFormat = OgnlTextFormat.create(StringUtils.defaultString(title));
        return textFormat.format(this);
    }
}

From source file:com.manydesigns.portofino.pageactions.crud.AbstractCrudAction.java

public String getCreateTitle() {
    String title = crudConfiguration.getCreateTitle();
    if (StringUtils.isBlank(title)) {
        title = getPage().getTitle();/*w  w  w. j a v  a  2 s  . co  m*/
    }
    OgnlTextFormat textFormat = OgnlTextFormat.create(StringUtils.defaultString(title));
    return textFormat.format(this);
}

From source file:ca.cgta.input.converter.Converter.java

public boolean validateMsh(MSH theMsh) throws HL7Exception {

    // Only validate once
    if (myValidatedMsh != null) {
        return myValidatedMsh;
    }// w w  w.  j  a v a2  s  .c  om

    if (!"|".equals(theMsh.getFieldSeparator().getValue())) {
        addFailure("MSH-1", FailureCode.F066, theMsh.getFieldSeparator().getValue());
    }

    if (!"^~\\&".equals(theMsh.getMsh2_EncodingCharacters().getValue())) {
        addFailure("MSH-2", FailureCode.F066, theMsh.getMsh2_EncodingCharacters().getValue());
    }

    String sendingOrg = theMsh.getMsh3_SendingApplication().getHd1_NamespaceID().getValue();

    String sendingFacility = theMsh.getMsh4_SendingFacility().getHd1_NamespaceID().encode();

    if (isEmpty(sendingOrg) && isEmpty(sendingFacility)) {

        addFailure("MSH-3/4-1", FailureCode.F134,
                theMsh.getMsh3_SendingApplication().getHd1_NamespaceID().encode());
        myValidatedMsh = false;
        return false;
    }

    if (isCgta) {
        myContributorConfig = myAuthorization.getContributorConfig().getHspId9004ToContributor()
                .get(StringUtils.defaultString(sendingOrg));
        if (myContributorConfig == null) {

            addFailure("MSH-3-1", FailureCode.F112,
                    theMsh.getMsh3_SendingApplication().getHd1_NamespaceID().getValue());
            myValidatedMsh = false;
            return false;

        } else {

            String sendingSystemId = theMsh.getMsh3_SendingApplication().getHd2_UniversalID().getValue();
            mySendingSystem = myContributorConfig.getSendingSystem9008WithOid(sendingSystemId);
            if (mySendingSystem == null) {
                addFailure("MSH-3-2", FailureCode.F113, sendingSystemId);
                myValidatedMsh = false;
                return false;
            }

            String securityToken = theMsh.getMsh8_Security().getValue();
            if (myCheckSecurity) {
                if (!myContributorConfig.getDevSecurityToken().equals(securityToken)) {
                    addFailure("MSH-8", FailureCode.F114, securityToken);
                    myValidatedMsh = false;
                    return false;
                }
            }
        }
    }

    if (isHrm) {
        myContributorConfig = myAuthorization.getContributorConfig().getHrmId0362ToContributor()
                .get(StringUtils.defaultString(sendingFacility));

        //                        if (!hrmContributor.contains(sendingFacility)) {
        if (myContributorConfig == null) {

            addFailure("MSH-4", FailureCode.F133, sendingFacility);
            myValidatedMsh = false;
            return false;
        }
    }

    if (isCgta) {
        String receivingFacility = theMsh.getMsh5_ReceivingApplication().getHd1_NamespaceID().getValue();
        if (!"ConnectingGTA".equals(receivingFacility)) {
            addFailure("MSH-5", FailureCode.F066, null);
        }
    }

    if (isHrm) {
        String receivingFacility = theMsh.getMsh6_ReceivingFacility().getHd1_NamespaceID().getValue();
        if (!"ConnectingGTA".equals(receivingFacility)) {
            addFailure("MSH-6", FailureCode.F066, null);
        }
    }

    validateTsWithAtLeastSecondPrecisionAndAddFailure("MSH-7",
            theMsh.getMsh7_DateTimeOfMessage().getTs1_Time().getValue());

    String controlId = theMsh.getMsh10_MessageControlID().getValue();
    if (isBlank(controlId)) {
        addFailure("MSH-10", FailureCode.F069, null);
    }

    String processingMode = theMsh.getMsh11_ProcessingID().getPt1_ProcessingID().getValue();
    if (!"T".equals(processingMode)) {
        addFailure("MSH-11-1", FailureCode.F070, processingMode);
    }

    String vid = theMsh.getMsh12_VersionID().getVid1_VersionID().getValue();
    if (!"2.5".equals(vid)) {
        addFailure("MSH-12", FailureCode.F066, vid);
    }
    if (isCgta) {
        String accAck = theMsh.getMsh15_AcceptAcknowledgmentType().getValue();
        if (!"NE".equals(accAck)) {
            addFailure("MSH-15", FailureCode.F066, accAck);
        }
    }
    if (isCgta) {
        String appAck = theMsh.getMsh16_ApplicationAcknowledgmentType().getValue();
        if (!"AL".equals(appAck)) {
            addFailure("MSH-16", FailureCode.F066, appAck);
        }
    }
    if (isCgta) {
        String country = theMsh.getMsh17_CountryCode().getValue();
        if (!"CAN".equals(country)) {
            addFailure("MSH-17", FailureCode.F066, country);
        }
    }
    if (isCgta) {
        String charset = theMsh.getMsh18_CharacterSet(0).getValue();
        if (!"8859/1".equals(charset)) {
            addFailure("MSH-18", FailureCode.F066, charset);
        }
    }
    if (isCgta) {
        String profile = theMsh.getMsh21_MessageProfileIdentifier(0).getEi1_EntityIdentifier().getValue();
        if (!INPUT_PROFILE_2_0.equals(profile)) {
            addFailure("MSH-21(1)-1", FailureCode.F115, profile);
        }
    }
    myValidatedMsh = true;
    return true;
}

From source file:net.sourceforge.openutils.mgnlcriteria.advanced.XpathEscapeTest.java

@Test
public void testEscapeUnconventionalKeywords0() throws Exception {
    String searchText = "(fr: )(n)";
    Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(RepositoryConstants.WEBSITE);
    criteria.setBasePath(StringUtils.EMPTY);

    Disjunction disjunction = Restrictions.disjunction();
    disjunction.add(Restrictions.contains("@title", StringUtils.defaultString(searchText))); // serve per il
    // boost!//ww  w. j av  a  2s  .c  om
    disjunction.add(Restrictions.contains(".", StringUtils.defaultString(searchText)));
    criteria.add(disjunction);

    Assert.assertEquals(criteria.toXpathExpression(),
            "//*[(( ( jcr:contains(@title, '\\(fr\\: \\)\\(n\\)') )  or  ( jcr:contains(., '\\(fr\\: \\)\\(n\\)') ) ) )] ");

    try {
        AdvancedResult advResult = criteria.execute();
        CriteriaTestUtils.assertNumOfResults(0, CriteriaTestUtils.collectCollectionFromResult(advResult),
                searchText);
    } catch (JCRQueryException e) {
        Assert.fail("Search string not properly escaped. " + e.getMessage());
    }
}

From source file:net.sourceforge.openutils.mgnlcriteria.tests.CriteriaTestUtils.java

public static AdvancedResult search(String searchText, String path, String repository, boolean titleOnly,
        int page, int itemsPerPage) {
    if (StringUtils.isBlank(searchText)) {
        return AdvancedResult.EMPTY_RESULT;
    }/*w  ww.  j a v  a 2  s .  c  om*/

    Criteria criteria = createCriteria(repository, path);

    if (titleOnly) {
        criteria.add(Restrictions.contains("@title", StringUtils.defaultString(searchText)));
    } else {
        Disjunction disjunction = Restrictions.disjunction();
        disjunction.add(Restrictions.contains("@title", StringUtils.defaultString(searchText))); // serve per il
        // boost!
        disjunction.add(Restrictions.contains(".", StringUtils.defaultString(searchText)));
        criteria.add(disjunction);
    }

    if (itemsPerPage >= 0) {
        criteria.setMaxResults(itemsPerPage);
    }
    if (page > 1) {
        criteria.setFirstResult((page - 1) * itemsPerPage);
    }

    return criteria.execute();
}

From source file:nz.net.catalyst.mobile.dds.RequestInfo.java

/**
 * convenience method get the user agent header which is the mostly used
 * header//w w w .  j a v  a  2  s  . co  m
 * @return
 */
public String getUserAgent() {
    return StringUtils.defaultString(headers.get("user-agent"));
}