Example usage for org.springframework.util StringUtils hasText

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

Introduction

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

Prototype

public static boolean hasText(@Nullable String str) 

Source Link

Document

Check whether the given String contains actual text.

Usage

From source file:org.cloudfoundry.identity.uaa.error.JsonAwareAccessDeniedHandler.java

@Override
public void handle(HttpServletRequest request, HttpServletResponse response,
        AccessDeniedException authException) throws IOException, ServletException {
    String accept = request.getHeader("Accept");
    boolean json = false;
    if (StringUtils.hasText(accept)) {
        for (MediaType mediaType : MediaType.parseMediaTypes(accept)) {
            if (mediaType.includes(MediaType.APPLICATION_JSON)) {
                json = true;/*from   ww w.j a v a 2  s. c  om*/
                break;
            }
        }
    }
    if (json) {
        response.setStatus(HttpServletResponse.SC_FORBIDDEN);
        response.setContentType(MediaType.APPLICATION_JSON_VALUE);
        response.getWriter().append(String.format("{\"error\":\"%s\"}", authException.getMessage()));
    } else {
        response.sendError(HttpServletResponse.SC_FORBIDDEN, authException.getMessage());
    }
}

From source file:csns.web.editor.MFTDistributionTypePropertyEditor.java

@Override
public void setAsText(String text) throws IllegalArgumentException {
    if (StringUtils.hasText(text))
        setValue(mftDistributionTypeDao.getDistributionType(Long.valueOf(text)));
}

From source file:spring.osgi.utils.OsgiHeaderUtils.java

private static String[] getHeaderWithAttributesAsTrimmedStringArray(Bundle bundle, String header) {
    if (bundle == null || !StringUtils.hasText(header))
        return new String[0];

    String headerContent = bundle.getHeaders().get(header);

    if (!StringUtils.hasText(headerContent))
        return new String[0];

    // consider , as a delimiter only if a quote is not encountered
    List<String> tokens = new ArrayList<>(2);

    StringBuilder token = new StringBuilder();
    boolean ignoreComma = false;
    for (int stringIndex = 0; stringIndex < headerContent.length(); stringIndex++) {
        char currentChar = headerContent.charAt(stringIndex);
        if (currentChar == COMMA_CHAR) {
            if (ignoreComma) {
                token.append(currentChar);
            } else {
                tokens.add(token.toString().trim());
                token.delete(0, token.length());
                ignoreComma = false;//w  ww. j  a va2  s.  c  o  m
            }
        } else {
            if (currentChar == QUOTE_CHAR) {
                ignoreComma = !ignoreComma;
            }
            token.append(currentChar);
        }
    }
    tokens.add(token.toString().trim());
    return tokens.toArray(new String[tokens.size()]);
}

From source file:com.dinstone.jrpc.spring.ServiceBeanDefinitionParser.java

@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    String id = element.getAttribute("id");
    if (!StringUtils.hasText(id)) {
        int index = ++count;
        element.setAttribute("id", "ServiceBean[" + index + "]");
    }//  w  ww .  j  av  a 2 s .c om

    if (StringUtils.hasText(element.getAttribute("interface"))) {
        builder.addPropertyValue("service", element.getAttribute("interface"));
    }

    if (StringUtils.hasText(element.getAttribute("group"))) {
        builder.addPropertyValue("group", element.getAttribute("group"));
    }

    if (StringUtils.hasText(element.getAttribute("timeout"))) {
        builder.addPropertyValue("timeout", element.getAttribute("timeout"));
    }

    builder.addPropertyReference("instance", element.getAttribute("implement"));
    builder.addPropertyReference("server", getServerBeanId(element.getAttribute("server")));
}

From source file:net.smktarunabhakti.penjualan.service.impl.AppServiceImpl.java

@Override
public Barang cariBarangById(String id) {
    if (!StringUtils.hasText(id)) {
        return null;
    }
    return barangDao.findOne(id);
}

From source file:springfox.documentation.swagger.readers.operation.OperationSummaryReader.java

@Override
public void apply(OperationContext context) {
    ApiOperation apiOperationAnnotation = context.getHandlerMethod().getMethodAnnotation(ApiOperation.class);
    if (null != apiOperationAnnotation && StringUtils.hasText(apiOperationAnnotation.value())) {
        context.operationBuilder().summary(apiOperationAnnotation.value());
    }/*  w ww  . j  av  a 2s  . c  o  m*/
}

From source file:com.phoenixnap.oss.ramlapisync.naming.NamingHelper.java

/**
 * Utility method to check if a string can be used as a valid class name
 * //from  w  w  w .  j  a  va  2s . c  om
 * @param input String to check
 * @return true if valid
 */
public static boolean isValidJavaClassName(String input) {
    if (!StringUtils.hasText(input)) {
        return false;
    }
    if (!Character.isJavaIdentifierStart(input.charAt(0))) {
        return false;
    }
    if (input.length() > 1) {
        for (int i = 1; i < input.length(); i++) {
            if (!Character.isJavaIdentifierPart(input.charAt(i))) {
                return false;
            }
        }
    }
    return true;
}

From source file:com.consol.citrus.admin.model.build.maven.MavenBuildConfiguration.java

public MavenBuildConfiguration() {
    super("maven");

    if (System.getProperty(Application.MVN_HOME_DIRECTORY) != null) {
        mavenHome = System.getProperty(Application.MVN_HOME_DIRECTORY);
    } else if (StringUtils.hasText(System.getenv("MAVEN_HOME"))) {
        mavenHome = System.getenv("MAVEN_HOME");
    } else if (StringUtils.hasText(System.getenv("M2_HOME"))) {
        mavenHome = System.getenv("M2_HOME");
    } else {//from   w  ww.j a  va2s  . c o  m
        mavenHome = "";
    }
}

From source file:org.jmesa.view.excel.Excel2007View.java

@Override
public Object render() {

    XSSFWorkbook workbook = new XSSFWorkbook();
    Table table = this.getTable();
    String caption = table.getCaption();
    if (!StringUtils.hasText(caption)) {
        caption = "JMesa Export";
    }/*from www.  ja  va 2 s.com*/
    XSSFSheet sheet = workbook.createSheet(caption);

    Row row = table.getRow();
    row.getRowRenderer();
    List<Column> columns = table.getRow().getColumns();

    // renderer header
    XSSFRow hssfRow = sheet.createRow(0);
    int columncount = 0;
    for (Column col : columns) {
        XSSFCell cell = hssfRow.createCell(columncount++);
        cell.setCellValue(new XSSFRichTextString(col.getTitle()));
    }

    // renderer body
    Collection<?> items = getCoreContext().getPageItems();
    int rowcount = 1;
    for (Object item : items) {
        XSSFRow r = sheet.createRow(rowcount++);
        columncount = 0;
        for (Column col : columns) {
            XSSFCell cell = r.createCell(columncount++);
            Object value = col.getCellRenderer().render(item, rowcount);
            if (value == null) {
                value = "";
            }

            if (value instanceof Number) {
                Double number = Double.valueOf(value.toString());
                cell.setCellValue(number);
            } else {
                cell.setCellValue(new XSSFRichTextString(value.toString()));
            }
        }
    }
    return workbook;
}

From source file:fr.mby.portal.coreimpl.app.BasicAppSigner.java

@Override
public String generateSignature(final HttpServletRequest request, final IApp app) {
    String signature = app.getSignature();

    if (!StringUtils.hasText(signature)) {
        signature = this.generate(request, app);
    }/*from w ww .ja  v a 2  s .co  m*/

    return signature;
}