Example usage for org.apache.commons.lang ObjectUtils toString

List of usage examples for org.apache.commons.lang ObjectUtils toString

Introduction

In this page you can find the example usage for org.apache.commons.lang ObjectUtils toString.

Prototype

public static String toString(Object obj) 

Source Link

Document

Gets the toString of an Object returning an empty string ("") if null input.

 ObjectUtils.toString(null)         = "" ObjectUtils.toString("")           = "" ObjectUtils.toString("bat")        = "bat" ObjectUtils.toString(Boolean.TRUE) = "true" 

Usage

From source file:gov.va.med.pharmacy.peps.presentation.common.displaytag.DefaultHssfExportView.java

/**
 * escapeColumnValue/*w  w  w .  j av  a 2  s .  co m*/
 * @param rawValue unmodified text
 * @return String with html/xml removed
 */
protected String escapeColumnValue(Object rawValue) {

    if (rawValue == null) {
        return null;
    }

    String returnString = ObjectUtils.toString(rawValue);

    // Extract text
    try {
        returnString = extractText(returnString);
    } catch (IOException e) {
        LOG.warn(e.getLocalizedMessage());
    }

    // escape the String to get the tabs, returns, newline explicit as \t \r \n
    returnString = StringEscapeUtils.escapeJava(StringUtils.trimToEmpty(returnString));

    // remove tabs, insert four whitespaces instead
    returnString = StringUtils.replace(StringUtils.trim(returnString), "\\t", "    ");

    // remove the return, only newline valid in excel
    returnString = StringUtils.replace(StringUtils.trim(returnString), "\\r", " ");

    // unescape so that \n gets back to newline
    returnString = StringEscapeUtils.unescapeJava(returnString);

    return returnString;
}

From source file:de.fhg.iais.asc.xslt.binaries.DownloadAndScaleBinary.java

private String determineTypeSubPath(URI uri, String localPathname) {
    if (StringUtils.isNotEmpty(localPathname)) {
        return localPathname;
    }// w  w  w .  ja  va 2 s.  c  o  m

    if (uri != null) {
        String fromURI = Downloader.createPathFromURI(uri);

        if (StringUtils.isNotEmpty(fromURI)) {
            return fromURI;
        }
    }

    final String msg = String.format(MSG_CANT_CREATE_LOCAL_PATH, ObjectUtils.toString(uri));
    throw new AscDataErrorException(msg);
}

From source file:com.projity.field.StaticSelect.java

public Object getValue(Object arg0) throws InvalidChoiceException {
    if (arg0 == EMPTY && isAllowNull())
        return null;
    Object result = stringMap.get(arg0);
    if (result == null)
        throw new InvalidChoiceException(ObjectUtils.toString(arg0));
    return result;
}

From source file:mitm.common.security.cms.SignerInfoImpl.java

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();

    String digestName = getDigestAlgorithmOID();

    Digest digest = Digest.fromOID(digestName);

    if (digest != null) {
        digestName = digest.toString();//from   w ww  .  j  a  va 2s .co m
    }

    Date signingTime = getSigningTime();

    sb.append("CMS Version: ");
    sb.append(getVersion());
    sb.append(SystemUtils.LINE_SEPARATOR);
    sb.append(SystemUtils.LINE_SEPARATOR);
    sb.append("*** [SignerId] ***");
    sb.append(SystemUtils.LINE_SEPARATOR);

    try {
        sb.append(getSignerId());
    } catch (IOException e) {
        sb.append("Error getting signer Id. Message: " + e.getMessage());
    }

    sb.append(SystemUtils.LINE_SEPARATOR);
    sb.append(SystemUtils.LINE_SEPARATOR);
    sb.append("Digest: ");
    sb.append(digestName);
    sb.append(SystemUtils.LINE_SEPARATOR);
    sb.append("Encryption alg. OID: ");
    sb.append(getEncryptionAlgorithmOID());
    sb.append(SystemUtils.LINE_SEPARATOR);
    sb.append("Signing time: ");
    sb.append(ObjectUtils.toString(signingTime));
    sb.append(SystemUtils.LINE_SEPARATOR);
    sb.append(SystemUtils.LINE_SEPARATOR);
    sb.append("Signed attributes: ");
    sb.append(SystemUtils.LINE_SEPARATOR);
    sb.append(ASN1Utils.dump(getSignedAttributes()));
    sb.append(SystemUtils.LINE_SEPARATOR);
    sb.append("Unsigned attributes: ");
    sb.append(SystemUtils.LINE_SEPARATOR);
    sb.append(SystemUtils.LINE_SEPARATOR);
    sb.append(ASN1Utils.dump(getUnsignedAttributes()));

    return sb.toString();
}

From source file:com.manydesigns.portofino.pageactions.chart.chartjs.ChartJsAction.java

protected boolean fillData1D(List<Object[]> result, JSONArray data) {
    for (Object[] current : result) {
        if (current.length < 2) {
            SessionMessages.addErrorMessage("The query returned the wrong number of parameters ("
                    + current.length + ") - 2 are required.");
            return false;
        }//w w w . jav  a  2s  . co m
        JSONObject datum = new JSONObject();
        datum.put("label", ObjectUtils.toString(current[0]));
        datum.put("value", current[1]);
        data.put(datum);
    }
    return true;
}

From source file:fr.cnes.sitools.metacatalogue.utils.MetacatalogField.java

/**
 * Value to string./*  ww  w. j  a v  a 2  s.  c o  m*/
 * 
 * @param value
 *          the value
 * @return the string
 */
public String valueToString(Object value) {
    String result;
    if (String.class.equals(clazz)) {
        result = (String) value;
    } else if (Date.class.equals(clazz)) {
        result = DateUtil.getThreadLocalDateFormat().format((Date) value);
    } else if (Double.class.equals(clazz)) {
        result = String.valueOf(value);
    } else {
        // By default return the object
        result = ObjectUtils.toString(value);
    }
    return result;

}

From source file:de.codesourcery.eve.skills.util.XMLMapperTest.java

private <X> void assertArrayEquals(X[] expected, X[] actual) {

    boolean result;
    if (expected == null || actual == null) {
        result = expected == actual;/*from  w w  w . j av a  2 s.  c om*/
    } else {
        if (expected.length != actual.length) {
            result = false;
        } else {
            for (int i = 0; i < expected.length; i++) {
                if (!ObjectUtils.equals(expected[i], actual[i])) {
                    throw new AssertionFailedError("expected: " + ObjectUtils.toString(expected) + " , got: "
                            + ObjectUtils.toString(actual));
                }
            }
            return;
        }
    }

    if (!result) {
        throw new AssertionFailedError(
                "expected: " + ObjectUtils.toString(expected) + " , got: " + ObjectUtils.toString(actual));
    }
}

From source file:com.green.modules.sys.entity.Menu.java

@Transient
public String getActivitiGroupId() {
    return ObjectUtils.toString(getPermission());
}

From source file:fr.paris.lutece.plugins.mylutece.business.portlet.MyLutecePortlet.java

/**
 * Returns the Xml code of the MyLutece portlet without XML heading
 *
 * @param request The HTTP Servlet request
 * @return the Xml code of the MyLutece portlet content
 *//*  www  .j  av  a2  s  . co m*/
public String getXml(HttpServletRequest request) {
    StringBuffer sbXml = new StringBuffer();

    if (!SecurityService.isAuthenticationEnable()) {
        XmlUtil.beginElement(sbXml, TAG_MY_LUTECE_PORTLET);
        XmlUtil.endElement(sbXml, TAG_MY_LUTECE_PORTLET);

        return sbXml.toString();
    }

    LuteceUser user = (request == null) ? null : SecurityService.getInstance().getRegisteredUser(request);

    XmlUtil.beginElement(sbXml, TAG_MY_LUTECE_PORTLET);

    if (user != null) {
        XmlUtil.beginElement(sbXml, TAG_LUTECE_USER);
        XmlUtil.addElementHtml(sbXml, TAG_LUTECE_USER_NAME, user.getName());
        XmlUtil.addElementHtml(sbXml, TAG_LUTECE_USER_NAME_GIVEN, user.getUserInfo(LuteceUser.NAME_GIVEN));
        XmlUtil.addElementHtml(sbXml, TAG_LUTECE_USER_NAME_FAMILY, user.getUserInfo(LuteceUser.NAME_FAMILY));

        if (user.getLuteceAuthenticationService() != null) {
            Map<String, Object> mapAttributes = new HashMap<String, Object>();
            mapAttributes.put(ATTRIBUTE_AUTHENTICATION_EXTERNAL,
                    user.getLuteceAuthenticationService().isExternalAuthentication());
            mapAttributes.put(ATTRIBUTE_AUTHENTICATION_DELEGATED,
                    user.getLuteceAuthenticationService().isDelegatedAuthentication());
            mapAttributes.put(ATTRIBUTE_AUTHENTICATION_LOGINPASSWORD_REQUIRED,
                    user.getLuteceAuthenticationService().isExternalAuthentication()
                            && user.getLuteceAuthenticationService().isDelegatedAuthentication());
            XmlUtil.beginElement(sbXml, TAG_LUTECE_USER_AUTHENTICATION_SERVICE, mapAttributes);
            XmlUtil.addElement(sbXml, TAG_AUTHENTICATION_NAME, user.getLuteceAuthenticationService().getName());
            XmlUtil.addElement(sbXml, TAG_AUTHENTICATION_DISPLAY_NAME,
                    user.getLuteceAuthenticationService().getAuthServiceName());
            XmlUtil.addElement(sbXml, TAG_AUTHENTICATION_ICON_URL,
                    ObjectUtils.toString(user.getLuteceAuthenticationService().getIconUrl()));
            XmlUtil.addElement(sbXml, ATTRIBUTE_AUTHENTICATION_DELEGATED,
                    Boolean.toString(user.getLuteceAuthenticationService().isDelegatedAuthentication()));
            XmlUtil.addElement(sbXml, TAG_AUTHENTICATION_URL,
                    user.getLuteceAuthenticationService().getDoLoginUrl());
            XmlUtil.endElement(sbXml, TAG_LUTECE_USER_AUTHENTICATION_SERVICE);
        }

        String strLogoutUrl = SecurityService.getInstance().getDoLogoutUrl();

        if (strLogoutUrl != null) {
            XmlUtil.addElementHtml(sbXml, TAG_LUTECE_USER_LOGOUT_URL, strLogoutUrl);
        }

        String strViewAccountUrl = (user.getLuteceAuthenticationService() != null)
                ? user.getLuteceAuthenticationService().getViewAccountPageUrl()
                : null;

        if (strViewAccountUrl != null) {
            XmlUtil.addElementHtml(sbXml, TAG_LUTECE_USER_VIEW_ACCOUNT_URL,
                    user.getLuteceAuthenticationService().getViewAccountPageUrl());
        }

        XmlUtil.endElement(sbXml, TAG_LUTECE_USER);
    } else {
        XmlUtil.beginElement(sbXml, TAG_USER_NOT_SIGNED);

        if (SecurityService.getInstance().getAuthenticationService().isMultiAuthenticationSupported()) {
            LuteceAuthentication multiAuthentication = SecurityService.getInstance().getAuthenticationService();

            if (multiAuthentication instanceof MultiLuteceAuthentication) {
                for (LuteceAuthentication luteceAuthentication : ((MultiLuteceAuthentication) multiAuthentication)
                        .getListLuteceAuthentication()) {
                    Map<String, Object> mapAttributes = new HashMap<String, Object>();
                    mapAttributes.put(ATTRIBUTE_AUTHENTICATION_EXTERNAL,
                            luteceAuthentication.isExternalAuthentication());
                    mapAttributes.put(ATTRIBUTE_AUTHENTICATION_DELEGATED,
                            luteceAuthentication.isDelegatedAuthentication());
                    mapAttributes.put(ATTRIBUTE_AUTHENTICATION_LOGINPASSWORD_REQUIRED,
                            !luteceAuthentication.isExternalAuthentication()
                                    && !luteceAuthentication.isDelegatedAuthentication());
                    XmlUtil.beginElement(sbXml, TAG_LUTECE_USER_AUTHENTICATION_SERVICE, mapAttributes);
                    XmlUtil.addElement(sbXml, TAG_AUTHENTICATION_NAME, luteceAuthentication.getName());
                    XmlUtil.addElement(sbXml, TAG_AUTHENTICATION_DISPLAY_NAME,
                            luteceAuthentication.getAuthServiceName());
                    XmlUtil.addElement(sbXml, TAG_AUTHENTICATION_ICON_URL,
                            ObjectUtils.toString(luteceAuthentication.getIconUrl()));
                    XmlUtil.addElement(sbXml, TAG_AUTHENTICATION_URL, luteceAuthentication.getDoLoginUrl());
                    XmlUtil.endElement(sbXml, TAG_LUTECE_USER_AUTHENTICATION_SERVICE);
                }
            }
        }

        String strNewAccountUrl = SecurityService.getInstance().getNewAccountPageUrl();

        if (strNewAccountUrl != null) {
            XmlUtil.addElementHtml(sbXml, TAG_LUTECE_USER_NEW_ACCOUNT_URL, strNewAccountUrl);
        }

        String strLostPasswordUrl = SecurityService.getInstance().getLostPasswordPageUrl();

        if (strLostPasswordUrl != null) {
            XmlUtil.addElementHtml(sbXml, TAG_LUTECE_USER_LOST_PASSWORD_URL, strLostPasswordUrl);
        }

        XmlUtil.endElement(sbXml, TAG_USER_NOT_SIGNED);
    }

    XmlUtil.endElement(sbXml, TAG_MY_LUTECE_PORTLET);

    return addPortletTags(sbXml);
}

From source file:com.green.modules.sys.entity.Menu.java

@Transient
public String getActivitiGroupName() {
    return ObjectUtils.toString(getId());
}