Example usage for com.liferay.portal.kernel.util StringUtil extractFirst

List of usage examples for com.liferay.portal.kernel.util StringUtil extractFirst

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util StringUtil extractFirst.

Prototype

public static String extractFirst(String s, String delimiter) 

Source Link

Document

Returns the substring of s up to but not including the first occurrence of the delimiter.

Usage

From source file:com.beorn.onlinepayment.shopping.action.BtopCheckoutAction.java

License:Open Source License

@Override
public void processAction(StrutsPortletAction originalStrutsPortletAction, PortletConfig portletConfig,
        ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long companyId = themeDisplay.getCompanyId();
    long ownerId = themeDisplay.getScopeGroupId();
    int ownerType = PortletKeys.PREFS_OWNER_TYPE_GROUP;
    long plid = PortletKeys.PREFS_PLID_SHARED;
    String portletId = PortletKeys.SHOPPING;

    PortletPreferences preferences = PortletPreferencesLocalServiceUtil.getPreferences(companyId, ownerId,
            ownerType, plid, portletId);

    String paymentType = PrefsParamUtil.getString(preferences, actionRequest, "paymentType");

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
    if (cmd.equals(Constants.SAVE) && paymentType.equals("Betop")) {
        processSaveCheckoutActionWithoutForwarding(originalStrutsPortletAction, actionRequest, actionResponse);

        PaymentAppSender paymentAppSender = PaymentAppUtil.getPaymentAppSender();

        ShoppingCart cart = ShoppingUtil.getCart(actionRequest);

        ShoppingOrder order = (ShoppingOrder) actionRequest.getAttribute("SHOPPING_ORDER");

        long sellerId = GetterUtil.getLong(preferences.getValue("sellerId", "0"));
        double amount = ShoppingUtil.calculateTotal(cart.getItems(), order.getBillingState(), cart.getCoupon(),
                cart.getAltShipping(), cart.isInsure());
        String currencyCode = preferences.getValue("currencyId", "USD");

        Long transactionId = paymentAppSender.addTransaction(sellerId, amount, currencyCode);

        OrderTransactionLocalServiceUtil.addOrderTransaction(order.getOrderId(), transactionId);

        HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);

        String remoteIp = request.getRemoteAddr();
        String forwardedForIp = StringUtil.extractFirst(request.getHeader("X-Forwarded-For"),
                StringPool.COMMA_AND_SPACE);
        if (forwardedForIp != null)
            remoteIp = forwardedForIp;//from   w  ww  .  j a  v  a 2s  .  c om

        List<ApiPaymentMethod> paymentMethods = paymentAppSender.getPaymentMethods(transactionId,
                paymentAppSender.geolocalizeIp(remoteIp));

        Long[] paymentMethodIds = new Long[paymentMethods.size()];
        String[] paymentMethodNames = new String[paymentMethods.size()];

        for (int i = 0; i < paymentMethods.size(); ++i) {
            paymentMethodIds[i] = paymentMethods.get(i).getPaymentMethodId();
            paymentMethodNames[i] = paymentMethods.get(i).getName(themeDisplay.getLocale());
        }

        actionRequest.setAttribute("orderId", order.getOrderId());
        actionRequest.setAttribute("paymentMethodIds", paymentMethodIds);
        actionRequest.setAttribute("paymentMethodNames", paymentMethodNames);

    } else {
        originalStrutsPortletAction.processAction(originalStrutsPortletAction, portletConfig, actionRequest,
                actionResponse);
    }
}

From source file:com.beorn.onlinepayment.shopping.action.BtopSelectPaymentMethodAction.java

License:Open Source License

@Override
public void processAction(PortletConfig portletConfig, ActionRequest actionRequest,
        ActionResponse actionResponse) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long orderId = ParamUtil.getLong(actionRequest, "orderId");
    long paymentMethodId = ParamUtil.getLong(actionRequest, "methodId");

    OrderTransaction orderTransaction = OrderTransactionLocalServiceUtil.getOrderTransaction(orderId);

    PaymentAppSender paymentAppSender = PaymentAppUtil.getPaymentAppSender();

    HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);

    String remoteIp = request.getRemoteAddr();
    String forwardedForIp = StringUtil.extractFirst(request.getHeader("X-Forwarded-For"),
            StringPool.COMMA_AND_SPACE);
    if (forwardedForIp != null)
        remoteIp = forwardedForIp;//  w w w.  jav  a 2  s .  c  o m

    String countryCode = paymentAppSender.geolocalizeIp(remoteIp);

    LiferayPortletURL returnURL = PortletURLFactoryUtil.create(actionRequest, "34", themeDisplay.getPlid(),
            PortletRequest.ACTION_PHASE);
    returnURL.setWindowState(LiferayWindowState.NORMAL);
    returnURL.setParameter("struts_action", "/shopping/checkout");
    returnURL.setParameter(Constants.CMD, Constants.VIEW);
    returnURL.setParameter("orderId", String.valueOf(orderId));

    String backUrl = returnURL.toString();
    String successUrl = returnURL.toString();
    String errorUrl = returnURL.toString();

    String paymentUrl = paymentAppSender.getPaymentUrl(orderTransaction.getTransactionId(), paymentMethodId,
            themeDisplay.getLanguageId(), countryCode, backUrl, successUrl, errorUrl);

    actionResponse.sendRedirect(paymentUrl);
}

From source file:com.liferay.chat.jabber.JabberImpl.java

License:Open Source License

@Override
public String getScreenName(String jabberId) {
    return StringUtil.extractFirst(jabberId, StringPool.AT);
}

From source file:com.liferay.dynamic.data.mapping.internal.render.DDMFormFieldFreeMarkerRenderer.java

License:Open Source License

protected String[] getFieldsDisplayValues(String fieldDisplayValue) {
    List<String> fieldsDisplayValues = new ArrayList<>();

    for (String value : StringUtil.split(fieldDisplayValue)) {
        String fieldName = StringUtil.extractFirst(value, DDMImpl.INSTANCE_SEPARATOR);

        fieldsDisplayValues.add(fieldName);
    }/* ww  w. j  av  a 2s  . c o  m*/

    return fieldsDisplayValues.toArray(new String[fieldsDisplayValues.size()]);
}

From source file:com.liferay.dynamic.data.mapping.internal.util.DDMImpl.java

License:Open Source License

protected int countFieldRepetition(String[] fieldsDisplayValues, String fieldName) {

    int count = 0;

    for (String fieldsDisplayValue : fieldsDisplayValues) {
        String prefix = StringUtil.extractFirst(fieldsDisplayValue, INSTANCE_SEPARATOR);

        if (prefix.equals(fieldName)) {
            count++;// w ww .  j a va2  s  . c  om
        }
    }

    return count;
}

From source file:com.liferay.dynamic.data.mapping.internal.util.DDMImpl.java

License:Open Source License

protected List<String> getFieldNames(String fieldNamespace, String fieldName, ServiceContext serviceContext) {

    String[] fieldsDisplayValues = StringUtil
            .split((String) serviceContext.getAttribute(fieldNamespace + FIELDS_DISPLAY_NAME));

    List<String> privateFieldNames = ListUtil.fromArray(new String[] { FIELDS_DISPLAY_NAME });

    List<String> fieldNames = new ArrayList<>();

    if ((fieldsDisplayValues.length == 0) || privateFieldNames.contains(fieldName)) {

        fieldNames.add(fieldNamespace + fieldName);
    } else {/*from  w  w w.  j  ava 2 s.c  om*/
        for (String namespacedFieldName : fieldsDisplayValues) {
            String fieldNameValue = StringUtil.extractFirst(namespacedFieldName, INSTANCE_SEPARATOR);

            if (fieldNameValue.equals(fieldName)) {
                fieldNames.add(fieldNamespace + namespacedFieldName);
            }
        }
    }

    return fieldNames;
}

From source file:com.liferay.dynamic.data.mapping.internal.util.FieldsToDDMFormValuesConverterImpl.java

License:Open Source License

protected String[] getDDMFieldsDisplayValues(Map<String, DDMFormField> ddmFormFieldsMap,
        Field ddmFieldsDisplayField) throws PortalException {

    try {//from   w w  w  .  ja  va 2  s .  co m
        List<String> fieldsDisplayValues = new ArrayList<>();

        String[] values = splitFieldsDisplayValue(ddmFieldsDisplayField);

        for (String value : values) {
            String fieldName = StringUtil.extractFirst(value, DDMImpl.INSTANCE_SEPARATOR);

            if (ddmFormFieldsMap.containsKey(fieldName)) {
                fieldsDisplayValues.add(fieldName);
            }
        }

        return fieldsDisplayValues.toArray(new String[fieldsDisplayValues.size()]);
    } catch (Exception e) {
        throw new PortalException(e);
    }
}

From source file:com.liferay.dynamic.data.mapping.util.DDMFormFieldFactoryHelper.java

License:Open Source License

protected Map<String, Object> getProperties() {
    Map<String, Object> propertiesMap = new HashMap<>();

    for (String property : _ddmFormField.properties()) {
        String key = StringUtil.extractFirst(property, StringPool.EQUAL);
        String value = StringUtil.extractLast(property, StringPool.EQUAL);

        propertiesMap.put(key, value);//from ww w .  ja  v a 2 s.  co m
    }

    return propertiesMap;
}

From source file:com.liferay.journal.internal.util.impl.JournalConverterImpl.java

License:Open Source License

protected String[] getDDMFieldsDisplayValues(Field ddmFieldsDisplayField) throws PortalException {

    try {/*www  . j  av  a 2  s  . c o m*/
        DDMStructure ddmStructure = ddmFieldsDisplayField.getDDMStructure();

        List<String> fieldsDisplayValues = new ArrayList<>();

        String[] values = splitFieldsDisplayValue(ddmFieldsDisplayField);

        for (String value : values) {
            String fieldName = StringUtil.extractFirst(value, DDM.INSTANCE_SEPARATOR);

            if (ddmStructure.hasField(fieldName)) {
                fieldsDisplayValues.add(fieldName);
            }
        }

        return fieldsDisplayValues.toArray(new String[fieldsDisplayValues.size()]);
    } catch (Exception e) {
        throw new PortalException(e);
    }
}

From source file:com.liferay.journal.util.impl.JournalConverterImpl.java

License:Open Source License

protected String[] getDDMFieldsDisplayValues(Field ddmFieldsDisplayField) throws PortalException {

    try {//from w w w  .  j av  a  2s. c o m
        DDMStructure ddmStructure = ddmFieldsDisplayField.getDDMStructure();

        List<String> fieldsDisplayValues = new ArrayList<>();

        String[] values = splitFieldsDisplayValue(ddmFieldsDisplayField);

        for (String value : values) {
            String fieldName = StringUtil.extractFirst(value, DDMImpl.INSTANCE_SEPARATOR);

            if (ddmStructure.hasField(fieldName)) {
                fieldsDisplayValues.add(fieldName);
            }
        }

        return fieldsDisplayValues.toArray(new String[fieldsDisplayValues.size()]);
    } catch (Exception e) {
        throw new PortalException(e);
    }
}