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:org.ebayopensource.turmeric.eclipse.utils.lang.StringUtil.java

/**
 * This method will prepend the prefix to the string arg iff prefix is not
 * already there at the beginning.//from  w  w  w  .ja  v a 2  s  .c o  m
 *
 * @param prefix the prefix
 * @param string the string
 * @return the string
 */
public static String prefix(final String prefix, final String string) {
    if (StringUtils.isEmpty(prefix))
        return string;
    if (StringUtils.defaultString(string).startsWith(prefix))
        return StringUtils.defaultString(string);
    return prefix + StringUtils.defaultString(string);
}

From source file:org.ebayopensource.turmeric.eclipse.utils.lang.StringUtil.java

/**
 * This method will postfix the postfix to the string arg iff prefix is not
 * already there at the end.//from  www  .java  2s.c  o  m
 *
 * @param string the string
 * @param postfix the postfix
 * @return the string
 */
public static String postfix(final String string, final String postfix) {
    if (StringUtils.isEmpty(postfix))
        return string;
    if (StringUtils.defaultString(string).endsWith(postfix))
        return StringUtils.defaultString(string);
    return StringUtils.defaultString(string) + postfix;
}

From source file:org.ebayopensource.turmeric.eclipse.utils.lang.StringUtil.java

/**
 * Broad equals.//from  w w w .  j a v a  2 s  .  com
 *
 * @param str1 the str1
 * @param str2 the str2
 * @return true, if successful
 * trims, ignores the case and null safe
 */
public static boolean broadEquals(String str1, String str2) {
    String defStr1 = StringUtils.defaultString(str1);
    String defStr2 = StringUtils.defaultString(str2);
    defStr1 = defStr1.trim();
    defStr2 = defStr2.trim();
    return defStr1.equalsIgnoreCase(defStr2);

}

From source file:org.ebayopensource.turmeric.eclipse.utils.ui.UIUtil.java

/**
 * Gets the detailed exception stack trace.
 *
 * @param exception the exception/*www .  j  a va  2  s. c om*/
 * @return the detailed exception stack trace
 */
public static IStatus getDetailedExceptionStackTrace(final Throwable exception) {
    IStatus status = null;
    if (exception instanceof CoreException) {
        status = ((CoreException) exception).getStatus();
    } else {
        final String reason;
        if (exception.getCause() != null) {
            reason = exception.getCause().getLocalizedMessage();
        } else {
            reason = exception.getLocalizedMessage();
        }

        MultiStatus multiStatus = new MultiStatus(Activator.PLUGIN_ID, 1, StringUtils.defaultString(reason),
                null);
        status = multiStatus;
        String stackTrace = ExceptionUtils.getStackTrace(exception);
        BufferedReader br = new BufferedReader(new StringReader(stackTrace));
        String line = null;
        try {
            while ((line = br.readLine()) != null) {
                multiStatus.merge(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 1, line, null));
            }
        } catch (IOException ioex) {
            ioex.printStackTrace();

        } finally {
            IOUtils.closeQuietly(br);
        }
    }

    return status;
}

From source file:org.ebayopensource.turmeric.eclipse.utils.ui.UIUtil.java

/**
 * open the error dialog and display error stacktrace.
 *
 * @param parent the parent shell of the dialog, or <code>null</code> if none
 * @param dialogTitle the title to use for this dialog, or <code>null</code> to
 * indicate that the default title should be used,default is
 * "Problem Occurred"//from   w w  w.j av  a  2s .com
 * @param message the message to show in this dialog, or <code>null</code> to
 * indicate that the exception's message should be shown as the
 * primary message
 * @param exception the exception used to display stackTrace ,or <code>null</code>
 * to indicate that the exception is not available,only
 * errorMessage will be shown.
 */
public static void showErrorDialog(final Shell parent, final String dialogTitle, final String message,
        final Throwable exception) {
    final Runnable runnable = new Runnable() {

        @Override
        public void run() {
            IStatus status = null;
            if (exception == null) {
                showErrorDialog(parent, "", dialogTitle, message);
                return;
            }
            if (exception instanceof CoreException) {
                status = ((CoreException) exception).getStatus();
            } else {
                final String reason;
                if (exception.getCause() != null) {
                    reason = exception.getCause().getLocalizedMessage();
                } else {
                    reason = exception.getLocalizedMessage();
                }

                MultiStatus multiStatus = new MultiStatus(Activator.PLUGIN_ID, 1,
                        StringUtils.defaultString(reason), null);
                status = multiStatus;
                String stackTrace = ExceptionUtils.getStackTrace(exception);
                BufferedReader br = new BufferedReader(new StringReader(stackTrace));
                String line = null;
                try {
                    while ((line = br.readLine()) != null) {
                        multiStatus.merge(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 1, line, null));
                    }
                } catch (IOException ioex) {
                    ioex.printStackTrace();

                } finally {
                    IOUtils.closeQuietly(br);
                }
            }
            String finalMessage = message;
            if (StringUtils.isBlank(message)) {
                // The message is blank, try to have a message for it.
                finalMessage = StringUtils.isNotBlank(exception.getLocalizedMessage())
                        ? exception.getLocalizedMessage()
                        : exception.toString();
            }

            SOAErrorDialog.openError(parent, dialogTitle, finalMessage, status,
                    IStatus.ERROR | IStatus.WARNING);

        }

    };
    if (Display.getCurrent() == null) {
        // not running in a UI thread.
        new UIJob("Error Occured") {
            @Override
            public IStatus runInUIThread(IProgressMonitor monitor) {
                runnable.run();
                return Status.OK_STATUS;
            }
        }.schedule();
    } else {
        runnable.run();
    }

}

From source file:org.eclipse.jubula.client.core.businessprocess.AbstractXMLReportGenerator.java

/**
 * adds information for a Cap to the XML file
 * //from w w w . java 2  s  . c o  m
 * @param resultNode
 *      the actual node
 * @param insertInto
 *      where to insert elements in xml
 * @param node
 *      NodePO
 */
protected void addCapElements(TestResultNode resultNode, Element insertInto, ICapPO node) {
    ICapPO cap = node;
    getTimestampFromResultNode(resultNode, insertInto);
    Element compEl = insertInto.addElement("component-name"); //$NON-NLS-1$
    compEl.addText(StringUtils.defaultString(resultNode.getComponentName()));
    Element compTypeEl = insertInto.addElement("component-type"); //$NON-NLS-1$
    compTypeEl.addText(CompSystemI18n.getString(cap.getComponentType(), true));
    Element actionEl = insertInto.addElement("action-type"); //$NON-NLS-1$
    actionEl.addText(CompSystemI18n.getString(cap.getActionName(), true));

    if (resultNode.getStatus() == TestResultNode.ERROR || resultNode.getStatus() == TestResultNode.RETRYING) {

        Element error = insertInto.addElement("error"); //$NON-NLS-1$
        Element errorType = error.addElement("type"); //$NON-NLS-1$
        TestErrorEvent event = resultNode.getEvent();
        if (event != null) {
            errorType.addText(I18n.getString(event.getId(), true));
            Map<Object, Object> eventProps = event.getProps();
            if (eventProps.containsKey(TestErrorEvent.Property.DESCRIPTION_KEY)) {
                String key = (String) eventProps.get(TestErrorEvent.Property.DESCRIPTION_KEY);
                Object[] args = (Object[]) eventProps.get(TestErrorEvent.Property.PARAMETER_KEY);
                args = args != null ? args : new Object[0];
                Element mapEntry = error.addElement("description"); //$NON-NLS-1$
                if (mapEntry != null && key != null) {
                    mapEntry.addText(
                            resultNode.hasBackingNode() ? String.valueOf(I18n.getString(key, args)) : key);
                }
            } else {
                for (Map.Entry<Object, Object> entry : eventProps.entrySet()) {
                    if (!TestErrorEvent.Property.DESCRIPTION_KEY.equals(entry.getKey())) {
                        Element mapEntry = error.addElement((String) entry.getKey());
                        mapEntry.addText(String.valueOf(entry.getValue()));
                    }
                }
            }
        }

        if (ClientTestFactory.getClientTest().isScreenshotForXML()) {
            final byte[] screenshotData = resultNode.getScreenshot();
            if (screenshotData != null) {
                Element screenshotElement = error.addElement("screenshot"); //$NON-NLS-1$
                screenshotElement.addText(new String(Base64.encodeBase64(screenshotData, false)));
            }
        }
    }
}

From source file:org.eclipse.jubula.client.core.businessprocess.TestresultSummaryBP.java

/**
 * fill result node//from   w w w.  j a v a  2s .  c o  m
 * @param keyword ITestResultPO
 * @param resultNode ITestResultPO
 */
private void fillNode(ITestResultPO keyword, TestResultNode resultNode) {
    INodePO node = resultNode.getNode();
    keyword.setKeywordName(node.getName());
    keyword.setInternalKeywordGuid(node.getGuid());
    keyword.setKeywordComment(node.getComment());
    keyword.setInternalKeywordStatus(resultNode.getStatus());
    keyword.setKeywordStatus(resultNode.getStatusString());
    if (resultNode.getTimeStamp() != null) {
        keyword.setTimestamp(resultNode.getTimeStamp());
    }

    if (resultNode.getParent() != null) {
        keyword.setInternalParentKeywordID(resultNode.getParent().getNode().getId());
    }

    if (node instanceof IParameterInterfacePO) {
        //set parameters
        addParameterListToResult(keyword, resultNode, (IParameterInterfacePO) node);
    }

    keyword.setKeywordType(resultNode.getTypeOfNode());
    if (node instanceof ICapPO) {
        keyword.setInternalKeywordType(TYPE_TEST_STEP);

        //set component name, type and action name
        ICapPO cap = (ICapPO) node;
        String compNameGuid = cap.getComponentName();
        keyword.setInternalComponentNameGuid(compNameGuid);
        keyword.setComponentName(StringUtils.defaultString(resultNode.getComponentName()));
        keyword.setInternalComponentType(cap.getComponentType());
        keyword.setComponentType(CompSystemI18n.getString(cap.getComponentType()));
        keyword.setInternalActionName(cap.getActionName());
        keyword.setActionName(CompSystemI18n.getString(cap.getActionName()));
        //add error details
        addErrorDetails(keyword, resultNode);
        keyword.setNoOfSimilarComponents(resultNode.getNoOfSimilarComponents());
        keyword.setOmHeuristicEquivalence(resultNode.getOmHeuristicEquivalence());
    } else if (node instanceof ITestCasePO) {
        keyword.setInternalKeywordType(TYPE_TEST_CASE);
    } else if (node instanceof ITestSuitePO) {
        keyword.setInternalKeywordType(TYPE_TEST_SUITE);
    }
}

From source file:org.eclipse.jubula.client.core.businessprocess.TestresultSummaryBP.java

/**
 * get a list of parameters for cap//from w  w  w. j  a va 2  s . c om
 * @param node TestResultNode
 * @param parameterInterface Source for Parameter information.
 * @param keyword ITestResultPO
 * @return result mit parameter
 */
private ITestResultPO addParameterListToResult(ITestResultPO keyword, TestResultNode node,
        IParameterInterfacePO parameterInterface) {

    int index = 0;
    for (IParamDescriptionPO param : parameterInterface.getParameterList()) {
        IParameterDetailsPO parameter = PoMaker.createParameterDetailsPO();

        parameter.setParameterName(param.getName());
        parameter.setInternalParameterType(param.getType());
        parameter.setParameterType(CompSystemI18n.getString(param.getType(), true));

        String paramValue = StringConstants.EMPTY;
        //parameter-value
        List<TestResultParameter> parameters = node.getParameters();
        if (parameters.size() >= index + 1) {
            final String value = parameters.get(index).getValue();
            paramValue = StringUtils.defaultString(value);
        }
        parameter.setParameterValue(paramValue);
        keyword.addParameter(parameter);
        index++;
    }

    return keyword;
}

From source file:org.eclipse.jubula.client.core.model.ResultTreeTracker.java

/**
 * Adds the parameters from the given Test Step to the given result node.
 * /*from w  ww.j  a  va  2 s .  c o m*/
 * @param testStep The Test Step from which to copy the parameter info.
 * @param resultNode The result node to which the parameter info will
 *                   be copied.
 */
private void addParameters(ICapPO testStep, TestResultNode resultNode) {

    List<IParamDescriptionPO> parameterList = testStep.getParameterList();
    String value = null;
    for (IParamDescriptionPO desc : parameterList) {
        ITDManager tdManager = null;
        try {
            tdManager = m_externalTestDataBP.getExternalCheckedTDManager(testStep);
        } catch (JBException e) {
            log.error(Messages.TestDataNotAvailable + StringConstants.DOT, e);
        }
        TestExecution te = TestExecution.getInstance();

        List<ExecObject> stackList = new ArrayList<ExecObject>(te.getTrav().getExecStackAsList());

        // Special handling for Test Steps. Their test data manager has 
        // information about multiple Data Sets, but we are only interested 
        // in the first one.
        int dataSetIndex = 0;

        if (tdManager.findColumnForParam(desc.getUniqueId()) == -1) {
            IParameterInterfacePO referencedDataCube = testStep.getReferencedDataCube();
            if (referencedDataCube != null) {
                desc = referencedDataCube.getParameterForName(desc.getName());
            }
        }
        ITestDataPO date = tdManager.getCell(dataSetIndex, desc);
        ParamValueConverter conv = new ModelParamValueConverter(date.getValue(te.getLocale()), testStep,
                te.getLocale(), desc);
        try {
            value = conv.getExecutionString(stackList, te.getLocale());
        } catch (InvalidDataException e) {
            log.error(e.getMessage());
            value = MessageIDs.getMessageObject(e.getErrorId())
                    .getMessage(new String[] { e.getLocalizedMessage() });
        }

        resultNode.addParameter(new TestResultParameter(CompSystemI18n.getString(desc.getUniqueId()),
                CompSystemI18n.getString(desc.getType()), StringUtils.defaultString(value)));
    }
}

From source file:org.eclipse.jubula.client.core.model.SummarizedTestResult.java

/**
 * {@inheritDoc}
 */
public String getAutArguments() {
    return StringUtils.defaultString(m_summary.getAutCmdParameter());
}