Example usage for org.apache.commons.lang StringUtils trimToNull

List of usage examples for org.apache.commons.lang StringUtils trimToNull

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils trimToNull.

Prototype

public static String trimToNull(String str) 

Source Link

Document

Removes control characters (char <= 32) from both ends of this String returning null if the String is empty ("") after the trim or if it is null.

Usage

From source file:com.bluexml.side.clazz.service.alfresco.AssociationServices.java

/**
 * service to compute association name/*from  w  ww.  j a  va 2 s  .  co  m*/
 * 
 * @param a
 * @param source
 * @return the association alfresco QName
 * @throws Exception
 */
public static String getAssociationQName(Association a, AssociationEnd source) throws Exception {
    if (CommonServices.isSimpleName(a)) {
        // reversed element that require to do not use "src_assoname_target"
        // pattern
        return a.getName();
    } else {
        String srcfullName = source.getLinkedClass().getFullName();
        String assoName = a.getName();
        String role = source.getOpposite().getName();

        String targetfullName = source.getOpposite().getLinkedClass().getFullName();

        StringBuffer qname = new StringBuffer();
        qname.append(srcfullName);
        qname.append(".");
        qname.append(assoName);
        qname.append(".");
        if (StringUtils.trimToNull(role) != null) {
            qname.append(role);
            qname.append(".");
        }
        qname.append(targetfullName);
        return CommonServices.convertFullNameToQualifiedName(qname.toString());
    }
}

From source file:com.egt.core.aplicacion.Bitacora.java

private static String getPatron(String clave, Object arg0, Object arg1, Object arg2, Object arg3) {
    if (isKey(clave)) {
        return BundleMensajes.getString(getKey(clave));
    } else {//from   ww  w  .j  ava  2  s .  c  om
        return StringUtils.trimToNull(clave);
    }
    //      String patron = StringUtils.trimToEmpty(clave);
    //      if (arg0 != null && patron.indexOf("{0}") >= 0) {
    //          return patron;
    //      }
    //      if (arg1 != null && patron.indexOf("{1}") >= 0) {
    //          return patron;
    //      }
    //      if (arg2 != null && patron.indexOf("{2}") >= 0) {
    //          return patron;
    //      }
    //      if (arg3 != null && patron.indexOf("{3}") >= 0) {
    //          return patron;
    //      }
    //      return null;
}

From source file:com.bluexml.xforms.controller.mapping.MappingToolSearch.java

/**
 * Tells whether the search field is mapped to a multiple select input
 * control, which happens//from   w  w  w  .jav  a  2s  .  c  om
 * for string attributes that have an enumeration.
 * 
 * @param fieldType
 * @return
 */
private boolean isEnumerated(SearchFieldType fieldType) {
    String enumName = fieldType.getEnum();
    boolean isEnum = (StringUtils.trimToNull(enumName) != null);
    return isEnum;
}

From source file:com.bluexml.xforms.actions.WorkflowTransitionAction.java

/**
 * Collects information and performs checks before starting the workflow.<br/>
 * /*  ww w  .j a  va 2  s.c om*/
 * @param formName
 * @param properties
 *            the properties to set on the task. Must be non-null.
 * @param dataId
 *            the complete (including protocol & namespace) ref to the
 *            linked data
 * @param workflowTitle
 * @param isStartTask
 * @return false if any exception or error happens. Otherwise true.
 * @throws ServletException
 */
private boolean initializeTask(String formName, WorkflowTaskInfoBean taskBean,
        HashMap<QName, Serializable> properties, String processId) throws ServletException {
    if (controller.isStartTaskForm(formName)) {
        // check that the user is authorized to start the workflow
        // if (validateCurrentUser(taskBean) == false) {
        // navigationPath.setStatusMsg(MsgPool.getMsg(MsgId.MSG_STATUS_WKFLW_FAIL_INITIATOR));
        // return false;
        // }

        if (currentPage.getWkflwInstanceId() == null) {
            // navigationPath
            // .setStatusMsg("Cannot start workflow when an instance id already exists.");
            // return false;

            NodeRef assignee = controller.systemGetNodeRefForUser(transaction, userName);
            if (assignee == null) {
                navigationPath.setStatusMsg(MsgPool.getMsg(MsgId.MSG_STATUS_WKFLW_FAIL_USER));
                return false;
            }

            // start a workflow instance and set some useful info
            String instanceId = controller.workflowStart(transaction, processId, null);
            if (instanceId == null) {
                navigationPath.setStatusMsg(MsgPool.getMsg(MsgId.MSG_ERROR_WKFLW_START_FAILURE));
                return false;
            }

            // create a workflow package and link the data to the package. There's always an id.
            NodeRef wkPackage = controller.workflowCreatePackage(transaction, currentPage.getDataId());
            if (wkPackage == null) {
                navigationPath.setStatusMsg(MsgPool.getMsg(MsgId.MSG_STATUS_WKFLW_FAIL_PACKAGE));
                return false;
            }
            properties.put(WorkflowModel.ASSOC_PACKAGE, wkPackage);
            properties.put(WorkflowModel.ASSOC_ASSIGNEE, assignee);

            String instanceDescription = taskBean.getProcessTitle();
            if (StringUtils.trimToNull(instanceDescription) == null) {
                instanceDescription = taskBean.getTitle();
            }
            if (StringUtils.trimToNull(instanceDescription) == null) {
                instanceDescription = controller.workflowExtractProcessNameFromFormName(taskBean.getFormName());
            }
            properties.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION, instanceDescription);

            currentPage.setWkflwInstanceId(instanceId);
        }
        currentPage.setWkflwProcessId(processId);
    }
    logger.debug("Started a workflow instance with id :" + currentPage.getWkflwInstanceId());
    return true;
}

From source file:ch.entwine.weblounge.security.sql.endpoint.SQLDirectoryProviderEndpoint.java

@PUT
@Path("/account/{id}/challenge")
public Response updateAccountChallenge(@PathParam("id") String login, @FormParam("challenge") String challenge,
        @FormParam("response") String response, @Context HttpServletRequest request) {

    // Make sure that the user owns the roles required for this operation
    User user = securityService.getUser();
    if (!SecurityUtils.userHasRole(user, SystemRole.SITEADMIN) && !user.getLogin().equals(login))
        return Response.status(Status.FORBIDDEN).build();

    JpaAccount account = null;/* w  w  w .ja  v  a 2  s  .  c  o m*/
    Site site = getSite(request);
    try {
        account = directory.getAccount(site, login);
        if (account == null)
            return Response.status(Status.NOT_FOUND).build();

        // Set the challenge
        account.setChallenge(StringUtils.trimToNull(challenge));

        // Hash the response
        if (StringUtils.isNotBlank(response)) {
            logger.debug("Hashing response for user '{}@{}' using md5", login, site.getIdentifier());
            String digestResponse = PasswordEncoder.encode(StringUtils.trim(response));
            account.setResponse(digestResponse);
        } else {
            account.setResponse(response);
        }

        directory.updateAccount(account);
        return Response.ok().build();
    } catch (Throwable t) {
        return Response.serverError().build();
    }
}

From source file:com.opengamma.web.historicaltimeseries.WebAllHistoricalTimeSeriesResource.java

private Set<ExternalId> buildSecurityRequest(final ExternalScheme identificationScheme, final String idValue) {
    if (idValue == null) {
        return Collections.emptySet();
    }/*from  ww  w .j  a  v  a 2 s. c o m*/
    final String[] identifiers = StringUtils.split(idValue, "\n");
    final Set<ExternalId> result = new HashSet<ExternalId>(identifiers.length);
    for (String identifier : identifiers) {
        identifier = StringUtils.trimToNull(identifier);
        if (identifier != null) {
            result.add(ExternalId.of(identificationScheme, identifier));
        }
    }
    return result;
}

From source file:com.prowidesoftware.swift.io.parser.MxParser.java

/**
 * Convenient API to get structure information from an MX message.
 * <br ><br>//from  w  w  w  . java  2s .  com
 * This can be helpful when the actual content of an XML is unknown and 
 * some preprocessing of the XML must be done in order to parse or
 * validate its content properly.
 * <br >
 * The implementation is intended to be lightweight and efficient, based on {@link javax.xml.stream.XMLStreamReader}
 *  
 * @since 7.8.4
 */
public MxStructureInfo analizeMessage() {
    if (this.info != null) {
        return this.info;
    }
    this.info = new MxStructureInfo();
    if (StringUtils.isBlank(this.buffer)) {
        log.log(Level.WARNING, "cannot analize message from null or empty content");
        return this.info;
    }
    final javax.xml.stream.XMLInputFactory xif = javax.xml.stream.XMLInputFactory.newInstance();
    try {
        final javax.xml.stream.XMLStreamReader reader = xif
                .createXMLStreamReader(new StringReader(this.buffer));
        boolean first = true;
        while (reader.hasNext()) {
            int event = reader.next();
            if (javax.xml.stream.XMLStreamConstants.START_ELEMENT == event) {
                if (reader.getLocalName().equals(DOCUMENT_LOCALNAME)) {
                    this.info.containsDocument = true;
                    this.info.documentNamespace = readNamespace(reader);
                    this.info.documentPrefix = StringUtils.trimToNull(reader.getPrefix());
                } else if (reader.getLocalName().equals(HEADER_LOCALNAME)) {
                    this.info.containsHeader = true;
                    this.info.headerNamespace = readNamespace(reader);
                    this.info.headerPrefix = StringUtils.trimToNull(reader.getPrefix());
                } else if (first) {
                    this.info.containsWrapper = true;
                }
                first = false;
            }
        }
    } catch (final Exception e) {
        log.log(Level.SEVERE, "error while analizing message: " + e.getMessage());
        info.exception = e;
    }
    return this.info;
}

From source file:ch.entwine.weblounge.contentrepository.impl.index.ContentRepositoryIndex.java

/**
 * Updates the path of the given resource.
 * /*from  w  ww . j  av  a 2s.  c  o  m*/
 * @param uir
 *          the resource uri
 * @param path
 *          the new path
 * @throws IOException
 *           if writing to the index fails
 * @throws ContentRepositoryException
 *           if moving the resource fails
 * @throws IllegalStateException
 *           if the resource to be moved could not be found in the index
 */
public synchronized void move(ResourceURI uri, String path)
        throws IOException, ContentRepositoryException, IllegalStateException {

    // Do it this way to make sure we have identical path trimming
    ResourceURI newURI = new ResourceURIImpl(uri.getType(), uri.getSite(), StringUtils.trimToNull(path),
            uri.getIdentifier(), uri.getVersion());
    path = newURI.getPath();

    searchIdx.move(uri, path);
}

From source file:adalid.core.programmers.AbstractSqlProgrammer.java

protected String getSearchCriteriaString(SearchCriteria criteria) {
    ComparisonOp comparacion = criteria.getComparacion();
    if (comparacion == null) {
        return null;
    }/*  w w  w  . ja  va 2s.  co m*/
    String string = null;
    //      String columna = StringUtils.trimToNull(criterio.getColumna(dominio));
    String columna = StringUtils.trimToNull(criteria.getColumna());
    Object valor = criteria.getValor();
    if (columna == null) {
        if (valor != null && valor instanceof String) {
            String expresion = (String) valor;
            switch (comparacion) {
            case EXISTS:
                string = getExists() + LRB$ + expresion + RRB$;
                break;
            case NOT_EXISTS:
                string = getNotExists() + LRB$ + expresion + RRB$;
                break;
            }
        }
        return string == null ? null : LRB$ + string.trim() + RRB$;
    }
    if (valor == null) {
        switch (comparacion) {
        case IS_NULL:
            string = columna + SPC$ + getIsNull();
            break;
        case IS_NOT_NULL:
            string = columna + SPC$ + getIsNotNull();
            break;
        }
        return string == null ? null : LRB$ + string.trim() + RRB$;
    }
    switch (comparacion) {
    case IS_NULL:
        string = columna + SPC$ + getIsNull();
        break;
    case IS_NOT_NULL:
        string = columna + SPC$ + getIsNotNull();
        break;
    case EQ:
        string = columna + SPC$ + getEQ() + SPC$ + getDelimitedString(valor);
        break;
    case NEQ:
        string = columna + SPC$ + getNEQ() + SPC$ + getDelimitedString(valor);
        break;
    case GT:
        string = columna + SPC$ + getGT() + SPC$ + getDelimitedString(valor);
        break;
    case LTEQ:
        string = columna + SPC$ + getLTEQ() + SPC$ + getDelimitedString(valor);
        break;
    case GTEQ:
        string = columna + SPC$ + getGTEQ() + SPC$ + getDelimitedString(valor);
        break;
    case LT:
        string = columna + SPC$ + getLT() + SPC$ + getDelimitedString(valor);
        break;
    case STARTS_WITH:
        string = columna + SPC$ + getLike() + SPC$ + getDelimitedString(startsWithValue(valor));
        break;
    case NOT_STARTS_WITH:
        string = columna + SPC$ + getNotLike() + SPC$ + getDelimitedString(startsWithValue(valor));
        break;
    case CONTAINS:
        string = columna + SPC$ + getLike() + SPC$ + getDelimitedString(containsValue(valor));
        break;
    case NOT_CONTAINS:
        string = columna + SPC$ + getNotLike() + SPC$ + getDelimitedString(containsValue(valor));
        break;
    case ENDS_WITH:
        string = columna + SPC$ + getLike() + SPC$ + getDelimitedString(endsWithValue(valor));
        break;
    case NOT_ENDS_WITH:
        string = columna + SPC$ + getNotLike() + SPC$ + getDelimitedString(endsWithValue(valor));
        break;
    case IN:
        string = columna + SPC$ + getIn() + LRB$ + getString(valor) + RRB$;
        break;
    case NOT_IN:
        string = columna + SPC$ + getNotIn() + LRB$ + getString(valor) + RRB$;
        break;
    case IS_NULL_OR_EQ:
        string = getIsNullOr(columna) + SPC$ + getEQ() + SPC$ + getDelimitedString(valor);
        break;
    case IS_NULL_OR_NEQ:
        string = getIsNullOr(columna) + SPC$ + getNEQ() + SPC$ + getDelimitedString(valor);
        break;
    case IS_NULL_OR_GT:
        string = getIsNullOr(columna) + SPC$ + getGT() + SPC$ + getDelimitedString(valor);
        break;
    case IS_NULL_OR_LTEQ:
        string = getIsNullOr(columna) + SPC$ + getLTEQ() + SPC$ + getDelimitedString(valor);
        break;
    case IS_NULL_OR_GTEQ:
        string = getIsNullOr(columna) + SPC$ + getGTEQ() + SPC$ + getDelimitedString(valor);
        break;
    case IS_NULL_OR_LT:
        string = getIsNullOr(columna) + SPC$ + getLT() + SPC$ + getDelimitedString(valor);
        break;
    case IS_NULL_OR_STARTS_WITH:
        string = getIsNullOr(columna) + SPC$ + getLike() + SPC$ + getDelimitedString(startsWithValue(valor));
        break;
    case IS_NULL_OR_NOT_STARTS_WITH:
        string = getIsNullOr(columna) + SPC$ + getNotLike() + SPC$ + getDelimitedString(startsWithValue(valor));
        break;
    case IS_NULL_OR_CONTAINS:
        string = getIsNullOr(columna) + SPC$ + getLike() + SPC$ + getDelimitedString(containsValue(valor));
        break;
    case IS_NULL_OR_NOT_CONTAINS:
        string = getIsNullOr(columna) + SPC$ + getNotLike() + SPC$ + getDelimitedString(containsValue(valor));
        break;
    case IS_NULL_OR_ENDS_WITH:
        string = getIsNullOr(columna) + SPC$ + getLike() + SPC$ + getDelimitedString(endsWithValue(valor));
        break;
    case IS_NULL_OR_NOT_ENDS_WITH:
        string = getIsNullOr(columna) + SPC$ + getNotLike() + SPC$ + getDelimitedString(endsWithValue(valor));
        break;
    case IS_NULL_OR_IN:
        string = getIsNullOr(columna) + SPC$ + getIn() + LRB$ + getString(valor) + RRB$;
        break;
    case IS_NULL_OR_NOT_IN:
        string = getIsNullOr(columna) + SPC$ + getNotIn() + LRB$ + getString(valor) + RRB$;
        break;
    }
    return string == null || StringUtils.isBlank(string) ? null : LRB$ + string.trim() + RRB$;
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopSuggestionField.java

protected void updateEditState() {
    Component editorComponent = comboBox.getEditor().getEditorComponent();
    boolean value = required && isEditableWithParent() && isEnabledWithParent()
            && editorComponent instanceof JTextComponent
            && StringUtils.isEmpty(((JTextComponent) editorComponent).getText());
    if (value) {/*from   www . jav a  2 s  .  co  m*/
        comboBox.setBackground(requiredBgColor);
    } else {
        comboBox.setBackground(defaultBgColor);

        if (editable && enabled) {
            if (editorComponent instanceof JTextComponent) {
                String inputText = StringUtils.trimToNull(((JTextComponent) editorComponent).getText());

                if (prevValue == null) {
                    String nullOptionText = null;
                    if (nullOption != null) {
                        nullOptionText = String.valueOf(nullOption);
                    }

                    if (StringUtils.isNotEmpty(inputText) && nullOption == null
                            || !Objects.equals(nullOptionText, inputText)) {
                        comboBox.setBackground(searchEditBgColor);
                    }
                } else {
                    String valueText = getDisplayString(prevValue);

                    if (!Objects.equals(inputText, valueText)) {
                        comboBox.setBackground(searchEditBgColor);
                    }
                }
            }
        }
    }
}