Example usage for org.springframework.util StringUtils hasLength

List of usage examples for org.springframework.util StringUtils hasLength

Introduction

In this page you can find the example usage for org.springframework.util StringUtils hasLength.

Prototype

public static boolean hasLength(@Nullable String str) 

Source Link

Document

Check that the given String is neither null nor of length 0.

Usage

From source file:com.yeahmobi.yunit.DbUnitTestExecutionListener.java

@Override
public void prepareTestInstance(TestContext testContext) throws Exception {

    if (logger.isDebugEnabled()) {
        logger.debug("Preparing test instance " + testContext.getTestClass() + " for DBUnit");
    }//  w w w . ja  va 2 s.com

    DbUnitTestContextAdapter dbUnitTestContext = new DbUnitTestContextAdapter(testContext);

    String databaseConnectionBeanName = null;
    Class<? extends DataSetLoader> dataSetLoaderClass = FlatXmlDataSetLoader.class;
    Class<? extends DatabaseOperationLookup> databaseOperationLookupClass = DefaultDatabaseOperationLookup.class;

    DbUnitConfiguration configuration = dbUnitTestContext.getTestClass()
            .getAnnotation(DbUnitConfiguration.class);
    if (configuration != null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Using @DbUnitConfiguration configuration");
        }
        databaseConnectionBeanName = configuration.databaseConnection();
        dataSetLoaderClass = configuration.dataSetLoader();
        databaseOperationLookupClass = configuration.databaseOperationLookup();
    }

    if (!StringUtils.hasLength(databaseConnectionBeanName)) {
        databaseConnectionBeanName = getDatabaseConnectionUsingCommonBeanNames(dbUnitTestContext);
    }

    if (logger.isDebugEnabled()) {
        logger.debug("DBUnit tests will run using databaseConnection \"" + databaseConnectionBeanName
                + "\", datasets will be loaded using " + dataSetLoaderClass);
    }
    prepareDatabaseConnection(dbUnitTestContext, databaseConnectionBeanName);
    prepareDataSetLoader(dbUnitTestContext, dataSetLoaderClass);
    prepareDatabaseOperationLookup(dbUnitTestContext, databaseOperationLookupClass);
}

From source file:com.github.zhanhb.ckfinder.connector.handlers.command.BaseCommand.java

/**
 * gets current folder request parameter or sets default value if it's not
 * set./*from  w ww . jav  a 2  s  .  c om*/
 *
 * @param request request
 * @return current folder, / if empty
 */
String getCurrentFolder(HttpServletRequest request) {
    String currentFolder = request.getParameter("currentFolder");
    if (StringUtils.hasLength(currentFolder)) {
        return PathUtils.normalize('/' + currentFolder + '/');
    } else {
        return "/";
    }
}

From source file:uk.ac.gda.dls.client.views.EnumPositionerCompositeFactory.java

EnumPositionerComposite(Composite parent, int style, EnumPositioner positioner, String label,
        Integer labelWidth, Integer contentWidth) {
    super(parent, style);
    this.display = parent.getDisplay();
    this.positioner = positioner;
    this.labelWidth = labelWidth;
    this.contentWidth = contentWidth;

    formats = positioner.getOutputFormat();
    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(this);
    GridDataFactory.fillDefaults().applyTo(this);
    //      GridDataFactory.fillDefaults().align(GridData.FILL, SWT.FILL).applyTo(this);

    //      Label lbl = new Label(this, SWT.RIGHT |SWT.WRAP | SWT.BORDER);
    Label lbl = new Label(this, SWT.RIGHT | SWT.WRAP);
    lbl.setText(StringUtils.hasLength(label) ? label : positioner.getName());

    GridData labelGridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
    if (labelWidth != null)
        labelGridData.widthHint = labelWidth.intValue();
    lbl.setLayoutData(labelGridData);/*from   w  w  w.  ja  v  a2s  .co m*/

    try {
        positions = this.positioner.getPositions();
    } catch (DeviceException e) {
        logger.error("Error getting position for " + this.positioner.getName(), e);
    }

    pcom = new Combo(this, SWT.SINGLE | SWT.BORDER | SWT.CENTER | SWT.READ_ONLY);
    pcom.setItems(positions);

    //      pcom.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
    GridData textGridData = new GridData(GridData.FILL_HORIZONTAL);
    textGridData.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING;
    if (contentWidth != null)
        textGridData.widthHint = contentWidth.intValue();
    pcom.setLayoutData(textGridData);

    pcom.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            valueChanged((Combo) e.widget);
        }
    });

    setComboRunnable = new Runnable() {
        @Override
        public void run() {
            if (selectionIndex != -1) {
                pcom.select(selectionIndex);
            }
            EclipseWidgetUtils.forceLayoutOfTopParent(EnumPositionerComposite.this);
        }
    };

    observer = new IObserver() {
        @Override
        public void update(Object source, Object arg) {
            logger.info("Got the who knows what type event!");
            displayValue();
        }
    };

    displayValue();

    positioner.addIObserver(observer);
}

From source file:org.apache.servicemix.camel.JbiEndpoint.java

@SuppressWarnings("unchecked")
private void parseUri(String uri) {
    destinationUri = uri;/*from ww w  .  j  av a 2  s.c o  m*/
    try {
        int idx = destinationUri.indexOf('?');
        if (idx > 0) {
            Map params = URISupport.parseQuery(destinationUri.substring(idx + 1));
            mep = (String) params.get("mep");
            if (mep != null && !mep.startsWith("http://www.w3.org/ns/wsdl/")) {
                mep = "http://www.w3.org/ns/wsdl/" + mep;
            }
            String oper = (String) params.get("operation");
            if (StringUtils.hasLength(oper)) {
                operation = QName.valueOf(oper);
            }
            this.destinationUri = destinationUri.substring(0, idx);

            String filter = (String) params.get("headerFilterStrategy");
            if (StringUtils.hasLength(filter)) {
                Registry registry = jbiComponent.getCamelContext().getRegistry();
                if (filter.indexOf('#') != -1) {
                    filter = filter.substring(1);
                }
                Object object = registry.lookup(filter);
                if (object instanceof HeaderFilterStrategy) {
                    headerFilterStrategy = (HeaderFilterStrategy) object;
                }
                params.remove("headerFilterStrategy");
            }
            String convert = (String) params.get("convertExceptions");
            if (StringUtils.hasLength(convert)) {
                this.setConvertExceptions(Boolean.valueOf(convert));
                params.remove("convertExceptions");
            }
            String serialization = (String) params.get("serialization");
            if (StringUtils.hasLength(serialization)) {
                this.setStrictSerialization(STRICT_SERIALIZATION.equalsIgnoreCase(serialization));
                params.remove("serialization");
            }
            timeout = parseLong("timeout", (String) params.get("timeout"));
            String endpointUri = this.destinationUri + URISupport.createQueryString(params);
            this.setEndpointUri(endpointUri);
        }
    } catch (URISyntaxException e) {
        throw new JbiException(e);
    }
}

From source file:com.yeahmobi.yunit.DbUnitRunner.java

private void verifyExpected(DbUnitTestContext testContext, Collection<ExpectedDatabase> annotations)
        throws Exception {
    if (testContext.getTestException() != null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Skipping @DatabaseTest expectation due to test exception "
                    + testContext.getTestException().getClass());
        }//from  w ww  .  j a  v a 2 s  . co m
        return;
    }
    IDatabaseConnection connection = testContext.getConnection();
    for (ExpectedDatabase annotation : annotations) {
        String query = annotation.query();
        String table = annotation.table();
        IDataSet expectedDataSet = loadDataset(testContext, annotation.value(), "expected.xml");
        if (expectedDataSet != null) {
            if (logger.isDebugEnabled()) {
                logger.debug("Veriftying @DatabaseTest expectation using " + annotation.value());
            }
            DatabaseAssertion assertion = annotation.assertionMode().getDatabaseAssertion();
            if (StringUtils.hasLength(query)) {
                Assert.hasLength(table, "The table name must be specified when using a SQL query");
                ITable expectedTable = expectedDataSet.getTable(table);
                ITable actualTable = connection.createQueryTable(table, query);
                assertion.assertEquals(expectedTable, actualTable);
            } else if (StringUtils.hasLength(table)) {
                ITable actualTable = connection.createTable(table);
                ITable expectedTable = expectedDataSet.getTable(table);
                assertion.assertEquals(expectedTable, actualTable);
            } else {
                IDataSet actualDataSet = connection.createDataSet();
                assertion.assertEquals(expectedDataSet, actualDataSet);
            }
        }
    }
}

From source file:org.springsource.ide.eclipse.commons.internal.configurator.Configurator.java

public void executePendingRequests() {
    String configureTargets = Activator.getDefault().getPreferenceStore()
            .getString(Activator.PROPERTY_CONFIGURE_TARGETS);
    List<String> newConfigureTargets = new ArrayList<String>();
    if (StringUtils.hasLength(configureTargets)) {
        StringTokenizer targets = new StringTokenizer(configureTargets, File.pathSeparator);
        while (targets.hasMoreTokens()) {
            String target = targets.nextToken();
            Map<String, String> parameters = new HashMap<String, String>();
            if (target.startsWith("extension=")) {
                parameters.put(PARAM_EXTENSION, target.substring("extension=".length()));
            } else {
                parameters.put(PARAM_TARGET, target);
            }//from   w w  w .ja  v a 2  s .  co  m
            IStatus status = execute(parameters, true);
            if (!status.isOK()) {
                newConfigureTargets.add(target);
            }
        }
    }
    Activator.getDefault().getPreferenceStore().setValue(Activator.PROPERTY_CONFIGURE_TARGETS,
            StringUtils.collectionToDelimitedString(newConfigureTargets, File.pathSeparator));
}

From source file:com.dianwoba.redcliff.blink.config.MybatisConfig2.java

@Bean(name = "bSqlSessionFactory")
public SqlSessionFactory sqlSessionFactory(@Qualifier("bDataSource") DataSource dataSource) throws Exception {
    SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
    factory.setDataSource(dataSource);/*from  w  w  w  .  j  av  a  2  s .c  o m*/
    factory.setVfs(SpringBootVFS.class);
    if (StringUtils.hasText(this.properties.getConfigLocation())) {
        factory.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation()));
    }
    factory.setConfiguration(properties.getConfiguration());
    if (!ObjectUtils.isEmpty(this.interceptors)) {
        factory.setPlugins(this.interceptors);
    }
    if (this.databaseIdProvider != null) {
        factory.setDatabaseIdProvider(this.databaseIdProvider);
    }
    if (StringUtils.hasLength(this.properties.getTypeAliasesPackage())) {
        factory.setTypeAliasesPackage(this.properties.getTypeAliasesPackage());
    }
    if (StringUtils.hasLength(this.properties.getTypeHandlersPackage())) {
        factory.setTypeHandlersPackage(this.properties.getTypeHandlersPackage());
    }
    if (!ObjectUtils.isEmpty(this.properties.resolveMapperLocations())) {
        factory.setMapperLocations(this.properties.resolveMapperLocations());
    }

    return factory.getObject();
}

From source file:org.openmrs.module.hl7valuegroups.api.ValueGroupORUR01Handler.java

/**
 * decide whether this handler can handle the given message
 *
 * @return fitness of this handler for the given message
 * @should ignore messages originating from anywhere but REFPACS
 *//*from  w  w  w  . j a  v  a  2  s. c o m*/
public boolean canProcess(Message message) {
    if (message != null && "ORU_R01".equals(message.getName())) {
        ORU_R01 oru = (ORU_R01) message;
        MSH msh = getMSH(oru);
        String sendingApplication = msh.getSendingApplication().toString();

        // TODO remove these tests when we are ready to handle all ORU^R01 messages
        // check for special indicators

        if (!StringUtils.hasLength(sendingApplication))
            return false;

        if (sendingApplication.toLowerCase().contains("refpacs"))
            return true;
    }

    return false;
}

From source file:org.openmrs.module.pcslabinterface.LabORUR01Handler.java

/**
 * decide whether this handler can handle the given message
 *
 * @return fitness of this handler for the given message
 * @should ignore messages originating from anywhere but REFPACS or PCS
 *//*w ww .  j a  v a2s.  c  o m*/
public boolean canProcess(Message message) {
    if (message != null && "ORU_R01".equals(message.getName())) {
        ORU_R01 oru = (ORU_R01) message;
        MSH msh = getMSH(oru);
        String sendingApplication = msh.getSendingApplication().getNamespaceID().getValue();

        // TODO remove these tests when we are ready to handle all ORU^R01 messages
        // check for special indicators

        log.debug(oru.getMSH() + " Sending application is: " + sendingApplication);

        if (!StringUtils.hasLength(sendingApplication))
            return false;

        if (allowedSendingApps.contains(sendingApplication.toLowerCase()))
            return true;
    }

    return false;
}

From source file:org.eclipse.jdt.internal.compiler.tool.ResourceFolderFileSystemClasspath.java

@Override
public boolean isPackage(String qualifiedPackageName) {
    if (this.isPackageCache == null) {
        this.isPackageCache = new HashMap<String, Boolean>();
    }/* ww w . j ava  2  s  . c  o m*/
    Boolean isPackage = this.isPackageCache.get(qualifiedPackageName);
    if (isPackage == null) {
        String packagePath = normalizePath(qualifiedPackageName);
        isPackage = !StringUtils.hasLength(packagePath) || this.folder.hasExisting(packagePath);
        this.isPackageCache.put(qualifiedPackageName, isPackage);
    }
    return isPackage;
}