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.opengamma.web.exchange.WebExchangesResource.java

@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)//from  w ww. j  ava 2  s .com
public Response postJSON(@FormParam("name") String name, @FormParam("idscheme") String idScheme,
        @FormParam("idvalue") String idValue, @FormParam("regionscheme") String regionScheme,
        @FormParam("regionvalue") String regionValue) {
    name = StringUtils.trimToNull(name);
    idScheme = StringUtils.trimToNull(idScheme);
    idValue = StringUtils.trimToNull(idValue);
    regionScheme = StringUtils.trimToNull(regionScheme);
    regionValue = StringUtils.trimToNull(regionValue);
    if (name == null || idScheme == null || idValue == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    URI uri = createExchange(name, idScheme, idValue, regionScheme, regionValue);
    return Response.created(uri).build();
}

From source file:com.bluexml.xforms.generator.forms.renderable.common.association.selection.selector.RenderableSelectorList.java

@Override
public Rendered render(String path, Stack<Renderable> parents, Stack<Rendered> renderedParents,
        boolean isInIMultRepeater) {
    RenderedInput renderedInput = new RenderedInput();

    // compute the right type of UI control
    String xfControl = "select1";
    if ((bean.isItemSelector() == false) && bean.isMultiple()) {
        xfControl = "select";
    }// www . j a  va  2 s  . com
    Element select = XFormsGenerator.createElement(xfControl, XFormsGenerator.NAMESPACE_XFORMS);

    // attributes
    String selectId = XFormsGenerator.getId("select");
    select.setAttribute("id", selectId);
    if (bean.isItemSelector()) {
        getBindId().addLinkedElement(select);
    } else {
        // direct connection to the field's node in the form's XML instance
        try {
            ModelElementBindSimple fieldBind = getFieldBind();
            fieldBind.addLinkedElement(select);
            // we need to set the mandatory status and the constraint
            if (bean.isMandatory()) { // #978
                fieldBind.setRequired(true);
            }
        } catch (Exception e) {
            System.out.println("Something");
        }
    }
    select.setAttribute("appearance", "compact");

    // field label
    Element label = XFormsGenerator.createElement("label", XFormsGenerator.NAMESPACE_XFORMS);
    label.setText(MsgPool.getMsg(MsgId.MSG_FIELD_LABEL_FORMAT, bean.getTitle()));
    select.addContent(label);

    // the action, not applicable for the simple select widget
    if (bean.isItemSelector()) {
        Element action = XFormsGenerator.createElement("action", XFormsGenerator.NAMESPACE_XFORMS);
        action.setAttribute("event", "xforms-value-changed", XFormsGenerator.NAMESPACE_EVENTS);

        // label
        Element setvaluelabel = XFormsGenerator.createElement("setvalue", XFormsGenerator.NAMESPACE_XFORMS);
        // Example target text: "instance('ComBluexmlDemoRhContratDeTravailList')/item[id =
        // instance('ComBluexmlDemoRhContratDeTravailList')/SELECTEDID]/value"
        setvaluelabel.setAttribute("value",
                getInstancePath() + MsgId.INT_INSTANCE_SELECT_ITEM + "[" + MsgId.INT_INSTANCE_SELECT_ID + " = "
                        + getInstancePath() + MsgId.INT_INSTANCE_SELECTEDID + "]/"
                        + MsgId.INT_INSTANCE_SELECT_LABEL);
        getBindLabel().addLinkedElement(setvaluelabel);
        action.addContent(setvaluelabel);

        // data type
        Element setvaluetype = XFormsGenerator.createElement("setvalue", XFormsGenerator.NAMESPACE_XFORMS);
        // Example target text: "instance('ComBluexmlDemoRhContratDeTravailList')/item[id =
        // instance('ComBluexmlDemoRhContratDeTravailList')/SELECTEDID]/qname"
        setvaluetype.setAttribute("value",
                getInstancePath() + MsgId.INT_INSTANCE_SELECT_ITEM + "[" + MsgId.INT_INSTANCE_SELECT_ID + " = "
                        + getInstancePath() + MsgId.INT_INSTANCE_SELECTEDID + "]/"
                        + MsgId.INT_INSTANCE_SELECT_TYPE);
        getBindType().addLinkedElement(setvaluetype);
        action.addContent(setvaluetype);

        select.addContent(action);
    }

    // the itemset
    Element itemset = XFormsGenerator.createElement("itemset", XFormsGenerator.NAMESPACE_XFORMS);
    itemset.setAttribute("nodeset", getInstanceNodePath());
    Element labelItem = XFormsGenerator.createElement("label", XFormsGenerator.NAMESPACE_XFORMS);
    labelItem.setAttribute("ref", MsgId.INT_INSTANCE_SELECT_LABEL.getText());
    itemset.addContent(labelItem);
    Element value = XFormsGenerator.createElement("value", XFormsGenerator.NAMESPACE_XFORMS);
    value.setAttribute("ref", MsgId.INT_INSTANCE_SELECT_ID.getText());
    itemset.addContent(value);
    select.addContent(itemset);

    if (bean.isMandatory()) {
        // set the hint/help message
        String hintMsg = bean.getHint();

        // we set hint/help only when a hint message is specified
        if (StringUtils.trimToNull(hintMsg) != null) {
            Element hintElt = XFormsGenerator.createElement("hint", XFormsGenerator.NAMESPACE_XFORMS);
            hintElt.setText(hintMsg);
            select.addContent(hintElt);
            // FIXME: as long as a specific property for help doesn't exist, we
            // duplicate the hint message into help
            Element helpElt = XFormsGenerator.createElement("help", XFormsGenerator.NAMESPACE_XFORMS);
            helpElt.setText(hintMsg);
            select.addContent(helpElt);
        }
        String msg = MsgPool.getMsg(MsgId.MSG_ASSOC_MANDATORY);
        if (StringUtils.trimToNull(msg) != null) {
            String errMsg = "";
            errMsg = MsgPool.getMsg(MsgId.MSG_ASSOC_MANDATORY, bean.getTitle());
            Element alertElement = XFormsGenerator.createElement("alert", XFormsGenerator.NAMESPACE_XFORMS);
            alertElement.setText(errMsg);
            select.addContent(alertElement);
        }
    }

    renderedInput.setXformsElement(select);

    return renderedInput;
}

From source file:com.metasoft.claim.service.impl.claim.ClaimServiceImpl.java

@Override
@Transactional//from w w  w.  j ava2s  .c  o m
public TblClaimRecovery save(ClaimSaveVo claimSaveVo, SecUser user) {
    TblClaimRecovery entity = new TblClaimRecovery();
    Date today = new Date();

    if (StringUtils.isNotBlank(claimSaveVo.getTxtClaimId())) {
        entity = claimDao.findById(Integer.parseInt(claimSaveVo.getTxtClaimId()));
    }

    entity.setClaimNumber(StringUtils.trimToNull(claimSaveVo.getTxtClaimNumber()));
    entity.setPolicyNo(StringUtils.trimToNull(claimSaveVo.getTxtPolicyNo()));
    entity.setLicenseNumber(StringUtils.trimToNull(claimSaveVo.getTxtlicenseNumber()));
    if (StringUtils.isNotBlank(claimSaveVo.getTxtAccidentDate())) {
        entity.setAccidentDate(
                DateToolsUtil.convertStringToDate(claimSaveVo.getTxtAccidentDate(), DateToolsUtil.LOCALE_TH));
    }
    if (StringUtils.isNotBlank(claimSaveVo.getTxtMaturityDate())) {
        entity.setMaturityDate(
                DateToolsUtil.convertStringToDate(claimSaveVo.getTxtMaturityDate(), DateToolsUtil.LOCALE_TH));
    }

    if (StringUtils.isNotBlank(claimSaveVo.getSelClaimType())) {
        entity.setClaimType(ClaimType.getById(Integer.parseInt(claimSaveVo.getSelClaimType())));
    }

    entity.setClaimInsuranceAmount(
            NumberToolsUtil.parseFormatToFloat(claimSaveVo.getTxtClaimInsuranceAmount()));
    entity.setRequestAmount(NumberToolsUtil.parseFormatToFloat(claimSaveVo.getTxtRequestAmount()));
    entity.setClaimAmount(NumberToolsUtil.parseFormatToFloat(claimSaveVo.getTxtClaimAmount()));

    if (StringUtils.isNotBlank(claimSaveVo.getSelPartyInsurance())) {
        entity.setPartyInsurance(insuranceDao.findById(Integer.parseInt(claimSaveVo.getSelPartyInsurance())));
    }
    entity.setPartyLicenseNumber(StringUtils.trimToNull(claimSaveVo.getTxtPartyLicenseNumber()));
    entity.setPartyClaimNumber(StringUtils.trimToNull(claimSaveVo.getTxtPartyClaimNumber()));
    entity.setPartyPolicyNo(StringUtils.trimToNull(claimSaveVo.getTxtPartyPolicyNo()));
    entity.setInvoiceNumber(StringUtils.trimToNull(claimSaveVo.getTxtInvoiceNumber()));

    if (StringUtils.isNotBlank(claimSaveVo.getSelAgent())) {
        entity.setAgent(userDao.findById(Integer.parseInt(claimSaveVo.getSelAgent())));
    }

    if (StringUtils.isBlank(claimSaveVo.getTxtClaimId())) {
        entity.setJobDate(today);
        entity.setJobStatus(JobStatus.RECEIVED);

        entity.setReceiveRemark(StringUtils.trimToNull(claimSaveVo.getTxtReceiveRemark()));

        entity.setCreateBy(user);
        entity.setCreateDate(today);
        entity.setId(super.save(entity));

        entity.setJobNo(DateToolsUtil.convertToString(today, DateToolsUtil.DATE_PATTERN_VIEW_YYYYMMDD,
                DateToolsUtil.LOCALE_TH) + entity.getId());
    } else {
        entity.setJobStatus(JobStatus.getById(Integer.parseInt(claimSaveVo.getSelJobStatus())));

        if (entity.getJobStatus().getId() == JobStatus.RECEIVED.getId()) {
            entity.setReceiveRemark(StringUtils.trimToNull(claimSaveVo.getTxtReceiveRemark()));
            if (entity.getJobDate() == null) {
                entity.setJobDate(today);
            }
        } else if (entity.getJobStatus().getId() == JobStatus.FOLLOWED.getId()) {
            entity.setFollowRemark(StringUtils.trimToNull(claimSaveVo.getTxtFollowRemark()));
            if (entity.getFollowDate() == null) {
                entity.setFollowDate(today);
            }
        } else if (entity.getJobStatus().getId() == JobStatus.CLOSED.getId()) {
            entity.setCloseRemark(StringUtils.trimToNull(claimSaveVo.getTxtCloseRemark()));
            if (entity.getCloseDate() == null) {
                entity.setCloseDate(today);
            }

            entity.setReceiveMoneyType(
                    ReceiveMoneyType.getById(Integer.parseInt(claimSaveVo.getSelReceiveMoneyType())));
        } else if (entity.getJobStatus().getId() == JobStatus.CANCELLED.getId()) {
            entity.setCancelRemark(StringUtils.trimToNull(claimSaveVo.getTxtCancelRemark()));
            if (entity.getCancelDate() == null) {
                entity.setCancelDate(today);
            }
        }
        entity.setUpdateBy(user);
        entity.setUpdateDate(today);

    }
    super.save(entity);

    return entity;
}

From source file:mitm.application.djigzo.james.mailets.MailAttributes.java

private void initAddAttributes() {
    addAttributes = new HashMap<String, List<String>>();

    String[] values = getValues(getConfiguration().getChildren(Parameter.ADD.name));

    if (values != null) {
        for (String value : values) {
            value = StringUtils.trimToNull(value);

            if (value == null) {
                continue;
            }//ww w.  j  a  v a2 s . c  om

            String[] nameValue = parseNameValue(value);

            if (nameValue == null) {
                throw new IllegalArgumentException(value + " is not a valid name value pair.");
            }

            String name = nameValue[0];

            List<String> attrValues = addAttributes.get(name);

            if (attrValues == null) {
                attrValues = new LinkedList<String>();

                addAttributes.put(name, attrValues);
            }

            attrValues.add(nameValue[1]);
        }
    }
}

From source file:com.vangent.hieos.services.xds.bridge.message.SubmitDocumentRequestBuilder.java

/**
 * Method description//from   w w  w. j  ava2s . c o m
 *
 *
 *
 * @param elem
 * @param expr
 *
 * @return
 *
 * @throws XPathHelperException
 */
private String parseText(OMElement elem, String expr) throws XPathHelperException {

    String result = XPathHelper.stringValueOf(elem, expr, URIConstants.XDSBRIDGE_URI);

    return StringUtils.trimToNull(result);
}

From source file:com.opengamma.web.portfolio.WebPortfoliosResource.java

@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)//  w w w  .j  a  v a2s  .c om
public Response postJSON(@FormParam("name") String name) {
    name = StringUtils.trimToNull(name);
    URI uri = createPortfolio(name);
    return Response.created(uri).build();
}

From source file:net.sf.eclipsecs.core.config.ConfigurationReader.java

private static void addProperties(final Element moduleEl, final Module module) {

    @SuppressWarnings("unchecked")
    final List<Element> propertyEls = moduleEl.elements(XMLTags.PROPERTY_TAG);

    for (final Element propertyEl : propertyEls) {

        final String name = propertyEl.attributeValue(XMLTags.NAME_TAG);
        final String value = propertyEl.attributeValue(XMLTags.VALUE_TAG);

        final boolean isPropertyRef = (value != null) && PROPERTY_REF_PATTERN.matcher(value).matches();

        if (name.equals(XMLTags.SEVERITY_TAG) && (module.getMetaData() != null)
                && module.getMetaData().hasSeverity()) {
            try {
                module.setSeverity(Severity.valueOf(value));
            } catch (final IllegalArgumentException e) {
                module.setSeverity(Severity.inherit);
            }// w  ww.  j a  va2 s  . c om
        } else if (name.equals(XMLTags.ID_TAG)) {
            module.setId(StringUtils.trimToNull(value));
        } else if (module.getMetaData() != null) {

            final ConfigProperty property = module.getProperty(name);
            if (property != null) {
                property.setValue(value);
                property.setPropertyReference(isPropertyRef);
            }

            // properties that are not within the meta data are omitted
        } else {
            // if module has no meta data defined create property
            final ConfigProperty property = new ConfigProperty(name, value);
            property.setPropertyReference(isPropertyRef);
            module.getProperties().add(property);
        }
    }
}

From source file:mitm.application.djigzo.james.mailets.SenderTemplatePropertySendMail.java

@Override
protected Template getTemplate(Mail mail, final SimpleHash root) throws IOException, MessagingException {
    Template template = null;// www  .  jav a 2 s.c  o  m

    try {
        InternetAddress originator = messageOriginatorIdentifier.getOriginator(mail);

        if (templateProperty != null && originator != null) {
            User user = userWorkflow.getUser(originator.getAddress(),
                    UserWorkflow.GetUserMode.CREATE_IF_NOT_EXIST);

            template = getTemplateFromUser(user, root);

            /*
             * Get the property values from the user so they can be stored in the template root
             */
            if (userProperties != null) {
                UserProperties properties = user.getUserPreferences().getProperties();

                for (String userProperty : userProperties) {
                    userProperty = StringUtils.trimToNull(userProperty);

                    if (userProperty == null) {
                        continue;
                    }

                    String value = properties.getProperty(userProperty, false);

                    if (value != null) {
                        root.put(userProperty, value);
                    }
                }
            }
        }

        if (template == null) {
            getLogger().debug("No template found for " + originator);
            /*
             * The sender was not a valid user or did not have a template. Use the default static 
             * template specified in the mailet config. 
             */
            template = super.getTemplate(mail, root);
        }
    } catch (HierarchicalPropertiesException e) {
        throw new MessagingException("Error getting template.", e);
    }

    return template;
}

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

/**
 * @param currentPage/*from  w  w w  .j av a2 s. c o  m*/
 * @param resultBean
 * @param URLsuffix
 */
protected void redirectToWorkflowForm(Page currentPage, TransitionResultBean resultBean, String URLsuffix) {
    String nextFormName;
    String location;
    Map<String, String> initParams = currentPage.getInitParams();
    RedirectionBean bean = controller.getWorkflowRedirectionBean(currentPage.getFormName());
    if (bean != null) {
        if (bean.isAutoAdvance()) {
            // if autoAdvancing, get the next form from the tasks
            if (resultBean.getTasks() != null && (resultBean.getTasks().size() > 0)) {
                String taskInfoString = resultBean.getTasks().get(0);
                String nextTaskName = getNameFromTaskIdNameTitle(taskInfoString);
                nextFormName = controller.getWorkflowFormNameFromTask(nextTaskName);
                location = buildNextFormUrl(nextFormName, initParams, URLsuffix, true);
                super.redirectClient(location);
                return;
            }
        } else {
            // go to the specified address if one is provided
            if (StringUtils.trimToNull(bean.getTargetUrl()) != null) {
                location = addRedirectionParameters(bean.getTargetUrl(), bean.isAutoAdvance(),
                        bean.isAddParams(), initParams, URLsuffix);
                super.redirectClient(location);
                return;
            }
        }
    }
    // default case: reload the same page
    setSubmissionDefaultLocation(getServletURL(), result);
}

From source file:com.foya.noms.service.st.ST002Service.java

/**
 * SiteHunt ?/*from w ww. j a  va 2 s. c o  m*/
 * 
 * @param siteHuntApply
 * @return
 */
public String doValidate(SiteHuntApplyDTO siteHuntApply) {
    String errorMessages = "";

    String feqType = siteHuntApply.getFeqId().split(",")[1];
    String feqId = siteHuntApply.getFeqId().split(",")[0];
    String eqpTypeId = siteHuntApply.getEqpTypeId();
    String btsSiteId = StringUtils.trimToNull(siteHuntApply.getBtsSiteId());
    String domain = townDomainTeamDao
            .getTownDomainTeamByCityIdTownId(siteHuntApply.getCity(), siteHuntApply.getArea()).getDOMAIN();
    domain = domain.substring(0, 1);
    String coverageType = siteHuntApply.getCoverageType();
    String srId = siteHuntApply.getSrId();
    // btsSiteId
    if (btsSiteId != null || !WorkType.NSR.name().equals(siteHuntApply.getWorkType())) {
        errorMessages += doValidateBTSSiteId(eqpTypeId, feqType, domain, btsSiteId, coverageType);
    }
    if (WorkType.NSR.name().equals(siteHuntApply.getWorkType()) && btsSiteId != null) {
        TbSiteMainExample example = new TbSiteMainExample();
        example.createCriteria().andBTS_SITE_IDEqualTo(btsSiteId);
        List<TbSiteMain> siteMain = sT002SP1Dao.findWorkSiteListByExample(example);
        if (siteMain.size() != 0) {
            errorMessages += "?\n";
        }
    } else if (WorkType.SH.name().equals(siteHuntApply.getWorkType())) {
        TbSiteMainExample example = new TbSiteMainExample();
        example.createCriteria().andBTS_SITE_IDEqualTo(btsSiteId);
        List<TbSiteMain> siteMain = sT002SP1Dao.findWorkSiteListByExample(example);
        if (siteMain.size() != 0) {
            if (!SiteStatus.S02.name().equals(siteMain.get(0).getSITE_STATUS())) {
                errorMessages += "?" + SiteStatus.S02.getLocalName()
                        + "??\n";
            }
        }
    }
    // srIdFeqId?? Search Ring?
    TbSiteSearchRing searchRing = searchRingDao.findSearchRingByPrimaryKey(srId);
    if (StringUtils.isNotEmpty(siteHuntApply.getSrId())) {
        if (!feqId.equals(searchRing.getFEQ_ID()) && !"all".equals(searchRing.getFEQ_ID())) {
            errorMessages += "Search Ring?";
        }
    }
    return errorMessages;
}