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.errorlibrary.properties.ui.ErrorLibraryProjPropertyPage.java

/**
 * //  w ww. j  a  v a 2  s  . c o  m
 * create a text and a label.
 * 
 * @param composite
 * @param label
 * @param isEditable
 * @param defaultValue
 */
private Text createLabeledText(Composite composite, String label, boolean isEditable, String defaultValue) {
    new Label(composite, SWT.LEFT).setText(label);
    Text text = new Text(composite, SWT.BORDER);
    text.setEditable(isEditable);
    text.setText(StringUtils.defaultString(defaultValue));
    text.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_HORIZONTAL));
    return text;
}

From source file:org.ebayopensource.turmeric.eclipse.errorlibrary.utils.ErrLibComparator.java

/**
 * {@inheritDoc}/*from w ww.j  av  a2  s.  c om*/
 */
@Override
public int compare(ISOAError o1, ISOAError o2) {
    return StringUtils.defaultString(o1.getName()).compareTo(StringUtils.defaultString(o2.getName()));
}

From source file:org.ebayopensource.turmeric.eclipse.resources.model.AssetInfo.java

/**
 * Instantiates a new asset info./*w ww .  j av a2  s.  co  m*/
 *
 * @param name the name
 * @param version the version
 * @param dir the dir
 * @param serviceLayer the service layer
 * @param type the type
 */
public AssetInfo(String name, String version, String dir, String serviceLayer, String type) {
    super();
    this.name = StringUtils.defaultString(name).trim();
    this.version = StringUtils.defaultString(version).trim();
    this.dir = StringUtils.defaultString(dir).trim();
    this.type = StringUtils.defaultString(type).trim();
}

From source file:org.ebayopensource.turmeric.eclipse.resources.model.ProjectInfo.java

/**
 * Instantiates a new project info.//from   w w  w .j  a va2 s  .com
 *
 * @param name the name
 * @param version the version
 * @param dir the dir
 * @param serviceLayer the service layer
 * @param type the type
 */
public ProjectInfo(String name, String version, String dir, String serviceLayer, String type) {
    super(name, version, dir, type);
    this.serviceLayer = StringUtils.defaultString(serviceLayer).trim();
}

From source file:org.ebayopensource.turmeric.eclipse.typelibrary.template.BasicProcessor.java

/**
 * {@inheritDoc}/*from ww  w.  ja va  2  s .com*/
 */
@Override
public boolean execute(Object parameter, IProgressMonitor monitor) throws CommandFailedException {
    if (parameter != null && parameter instanceof CommonXSDProcessorParam) {
        CommonXSDProcessorParam templateProcessorParam = (CommonXSDProcessorParam) parameter;

        XSDSchema xsdSchema = templateProcessorParam.getOutPutSchema();
        TypeParamModel uiModel = templateProcessorParam.getInputTypeParamModel();

        xsdSchema.setVersion(StringUtils.defaultString(uiModel.getVersion()));
        xsdSchema.setTargetNamespace(StringUtils.defaultString(uiModel.getNamespace()));
        xsdSchema.getQNamePrefixToNamespaceMap().put("tns", uiModel.getNamespace());
        ProgressUtil.progressOneStep(monitor);

        if (!(xsdSchema.getTypeDefinitions().get(0) instanceof XSDTypeDefinition))
            throw new CommandFailedException("Type Definition couldnt be retrieved from the template");
        XSDTypeDefinition xsdTypeDefinition = xsdSchema.getTypeDefinitions().get(0);
        if (xsdTypeDefinition == null)
            throw new CommandFailedException("The template is corrupted.");
        xsdTypeDefinition.setName(StringUtils.defaultString(uiModel.getTypeName()));
        ProgressUtil.progressOneStep(monitor);
        return true;
    } else {
        throw new CommandFailedException(
                "Input is not compatible. Possible reason is a corrupted template area.");
    }

}

From source file:org.ebayopensource.turmeric.eclipse.typelibrary.ui.model.EnumTypeProcessor.java

/**
 * {@inheritDoc}//w  w  w  . ja v a2 s  .  c  om
 */
@Override
public boolean execute(Object object, IProgressMonitor monitor) throws CommandFailedException {
    CommonXSDProcessorParam processorInput = (CommonXSDProcessorParam) object;

    XSDTypeDefinition typeDefinition = processorInput.getOutPutSchema().getTypeDefinitions().get(0);

    TypeParamModel typeParamModel = processorInput.getInputTypeParamModel();

    if (!(typeParamModel instanceof EnumTypeParamModel) || !(typeDefinition instanceof XSDSimpleTypeDefinition))
        throw new CommandFailedException("Input param or the template is bad");
    XSDSimpleTypeDefinition simpleType = (XSDSimpleTypeDefinition) typeDefinition;
    EnumTypeParamModel enumParamModel = (EnumTypeParamModel) typeParamModel;
    XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
    ProgressUtil.progressOneStep(monitor);

    for (EnumTypeWizardDetailsPage.EnumTableModel enumRow : enumParamModel.getEnumTableModel()) {
        XSDEnumerationFacet enumerationFacet = factory.createXSDEnumerationFacet();
        enumerationFacet.setLexicalValue(StringUtils.defaultString(enumRow.getEnumValue()));
        simpleType.getFacetContents().add(enumerationFacet);
        TypeLibraryUIActivator.addDocumentation(enumerationFacet,
                StringUtils.defaultString(enumRow.getEnumDesc()));
        simpleType.getFacetContents().add(enumerationFacet);

        ProgressUtil.progressOneStep(monitor, 3);
    }

    return false;
}

From source file:org.ebayopensource.turmeric.eclipse.typelibrary.ui.template.DocumentationProcessor.java

/**
 * {@inheritDoc}//from   www  .ja v  a2 s. c o  m
 */
@Override
public boolean execute(Object object, IProgressMonitor monitor) throws CommandFailedException {

    CommonXSDProcessorParam processorInput = (CommonXSDProcessorParam) object;

    XSDTypeDefinition typeDefinition = processorInput.getOutPutSchema().getTypeDefinitions().get(0);
    String docValue = StringUtils.defaultString(processorInput.getInputTypeParamModel().getDescription());

    TypeLibraryUIActivator.addDocumentation(typeDefinition, docValue);
    ProgressUtil.progressOneStep(monitor);
    return false;
}

From source file:org.ebayopensource.turmeric.eclipse.typelibrary.ui.wst.IncrementVersionCommand.java

private void performVersionChangeXSDEditor(XSDSchema schema) {

    try {/*  w w  w.j  a v a  2  s  .co m*/
        final Version oldVersion = schema.getVersion() == null ? Version.emptyVersion
                : new Version(StringUtils.defaultString(schema.getVersion()));

        IInputValidator inputValidator = new IInputValidator() {
            @Override
            public String isValid(String newText) {
                try {
                    if (new Version(newText).compareTo(oldVersion) <= 0) {
                        return "Please enter a higher version than the original one.";
                    }
                    if (new Version(newText).getMajor() > oldVersion.getMajor()) {
                        return "It is not allowed to bump up the major version of an existing type.";
                    }
                    if (!StringUtils.isEmpty(new Version(newText).getQualifier())) {
                        return "Version is allowed to have only three parts.";
                    }

                } catch (Exception exception) {
                    return "Enter a valid version.";
                }
                return null;
            }

        };

        InputDialog inputDialog = new InputDialog(UIUtil.getActiveShell(), "Version", "Enter the new version.",
                oldVersion.toString(), inputValidator);
        if (inputDialog.open() == Window.OK) {
            schema.setVersion(inputDialog.getValue());
            QName type = TypeLibraryUtil.toQName(getSelectedFile());
            SOATypeRegistry typeRegistry = SOAGlobalRegistryAdapter.getInstance().getGlobalRegistry();
            typeRegistry.getType(type).setVersion(inputDialog.getValue());
            SynchronizeWsdlAndDepXML synch = new SynchronizeWsdlAndDepXML(getSelectedFile().getProject());
            synch.syncronizeXSDandDepXml(schema, type);
            MessageDialog.openInformation(UIUtil.getActiveShell(), "The operation was performed successfully.",
                    "Successfully updated the version of this type.");
        }
    } catch (Exception exception) {
        throw new RuntimeException("Could not perform this operation:" + exception.getMessage(), exception);
    }

}

From source file:org.ebayopensource.turmeric.eclipse.ui.views.registry.CategoryTreeNode.java

@Override
public String getLabel() {
    return StringUtils.defaultString(getCategory());
}

From source file:org.ebayopensource.turmeric.eclipse.ui.wizards.AbstractTypeLibraryWizard.java

@Override
public IStatus preValidate() throws ValidationInterruptedException {
    // initialize the Global type Registry
    try {// w  w  w.ja va2 s .  c o m
        SOAGlobalRegistryAdapter.getInstance().getGlobalRegistry();
    } catch (Exception exception) {
        return EclipseMessageUtils.createErrorStatus(
                "The Type Registry could not be initialized. This is probably due to a bad repository system. Please make sure the repository(V3 or Maven) is configured:"
                        + StringUtils.defaultString(exception.getMessage()));
    }
    ISOARepositorySystem activeRepositorySystem = GlobalRepositorySystem.instanceOf()
            .getActiveRepositorySystem();
    ISOAPreValidator validator = activeRepositorySystem.getPreValidator();
    return validator.validate(ISOAPreValidator.TYPE_LIBRARY);

}