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

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

Introduction

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

Prototype

public static String substringBefore(String str, String separator) 

Source Link

Document

Gets the substring before the first occurrence of a separator.

Usage

From source file:info.magnolia.cms.servlets.EntryServlet.java

/**
 * Uses access manager to authorise this request.
 * @param req HttpServletRequest as received by the service method
 * @param res HttpServletResponse as received by the service method
 * @return boolean true if read access is granted
 * @throws IOException can be thrown when the servlet is unable to write to the response stream
 *///from   w  ww  .j av  a 2 s.  co m
protected boolean isAuthorized(HttpServletRequest req, HttpServletResponse res) throws IOException {
    if (MgnlContext.getAccessManager(ContentRepository.WEBSITE) != null) {
        String path = StringUtils.substringBefore(Path.getURI(req), "."); //$NON-NLS-1$
        if (!MgnlContext.getAccessManager(ContentRepository.WEBSITE).isGranted(path, Permission.READ)) {
            res.sendError(HttpServletResponse.SC_FORBIDDEN);
        }
    }
    return true;
}

From source file:de.hybris.platform.yacceleratorstorefront.controllers.pages.CheckoutController.java

protected String processOrderCode(final String orderCode, final Model model, final HttpServletRequest request)
        throws CMSItemNotFoundException {
    final OrderData orderDetails = orderFacade.getOrderDetailsForCode(orderCode);

    if (orderDetails.isGuestCustomer() && !StringUtils.substringBefore(orderDetails.getUser().getUid(), "|")
            .equals(getSessionService().getAttribute(WebConstants.ANONYMOUS_CHECKOUT_GUID))) {
        return getCheckoutRedirectUrl();
    }/*from   w w w. j a v  a2 s . c o  m*/

    if (orderDetails.getEntries() != null && !orderDetails.getEntries().isEmpty()) {
        for (final OrderEntryData entry : orderDetails.getEntries()) {
            final String productCode = entry.getProduct().getCode();
            final ProductData product = productFacade.getProductForCodeAndOptions(productCode,
                    Arrays.asList(ProductOption.BASIC, ProductOption.PRICE, ProductOption.CATEGORIES));
            entry.setProduct(product);
        }
    }

    orderDetails.setNet(true);

    model.addAttribute("orderCode", orderCode);
    model.addAttribute("orderData", orderDetails);
    model.addAttribute("allItems", orderDetails.getEntries());
    model.addAttribute("deliveryAddress", orderDetails.getDeliveryAddress());
    model.addAttribute("deliveryMode", orderDetails.getDeliveryMode());
    model.addAttribute("paymentInfo", orderDetails.getPaymentInfo());
    model.addAttribute("pageType", PageType.ORDERCONFIRMATION.name());

    final String uid;

    if (orderDetails.isGuestCustomer() && !model.containsAttribute("guestRegisterForm")) {
        final GuestRegisterForm guestRegisterForm = new GuestRegisterForm();
        guestRegisterForm.setOrderCode(orderDetails.getGuid());
        uid = orderDetails.getPaymentInfo().getBillingAddress().getEmail();
        guestRegisterForm.setUid(uid);
        model.addAttribute(guestRegisterForm);
    } else {
        uid = orderDetails.getUser().getUid();
    }
    model.addAttribute("email", uid);

    final AbstractPageModel cmsPage = getContentPageForLabelOrId(CHECKOUT_ORDER_CONFIRMATION_CMS_PAGE_LABEL);
    storeCmsPageInModel(model, cmsPage);
    setUpMetaDataForContentPage(model, getContentPageForLabelOrId(CHECKOUT_ORDER_CONFIRMATION_CMS_PAGE_LABEL));
    model.addAttribute("metaRobots", "noindex,nofollow");

    return ControllerConstants.Views.Pages.Checkout.CheckoutConfirmationPage;
}

From source file:info.magnolia.jaas.sp.jcr.JCRAuthorizationModule.java

/**
 * set access control list from a list of roles under the provided content object
 * @param role under which roles and ACL are defined
 *//*from   www .j a  v a2s .co m*/
private void setACL(Content role, PrincipalCollection principalList) {
    try {
        Iterator it = role.getChildren(ItemType.CONTENTNODE.getSystemName(), "acl*").iterator();
        while (it.hasNext()) {
            Content aclEntry = (Content) it.next();
            String name = StringUtils.substringAfter(aclEntry.getName(), "acl_");
            ACL acl;
            String repositoryName;
            String workspaceName;
            if (!StringUtils.contains(name, "_")) {
                workspaceName = ContentRepository.getDefaultWorkspace(StringUtils.substringBefore(name, "_"));
                repositoryName = name;
                name += ("_" + workspaceName); // default workspace
                // must be added to the
                // name
            } else {
                String[] tokens = StringUtils.split(name, "_");
                repositoryName = tokens[0];
                workspaceName = tokens[1];
            }
            // get the existing acl object if created before with some
            // other role
            if (!principalList.contains(name)) {
                acl = new ACLImpl();
                principalList.add(acl);
            } else {
                acl = (ACL) principalList.get(name);
            }
            acl.setName(name);
            acl.setRepository(repositoryName);
            acl.setWorkspace(workspaceName);

            // add acl
            Iterator permissionIterator = aclEntry.getChildren().iterator();
            while (permissionIterator.hasNext()) {
                Content map = (Content) permissionIterator.next();
                String path = map.getNodeData("path").getString();
                UrlPattern p = new SimpleUrlPattern(path);
                Permission permission = new PermissionImpl();
                permission.setPattern(p);
                permission.setPermissions(map.getNodeData("permissions").getLong());
                acl.addPermission(permission);
            }
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }

}

From source file:info.magnolia.cms.core.Path.java

public static String getParentPath(String path) {
    int lastIndexOfSlash = path.lastIndexOf("/"); //$NON-NLS-1$
    if (lastIndexOfSlash > 0) {
        return StringUtils.substringBefore(path, "/"); //$NON-NLS-1$
    }// ww w .  j  a v  a2  s . c o m
    return "/"; //$NON-NLS-1$
}

From source file:com.epam.hybris.test.storefront.controllers.pages.CheckoutController.java

protected String processOrderCode(final String orderCode, final Model model, final HttpServletRequest request)
        throws CMSItemNotFoundException {
    final OrderData orderDetails = orderFacade.getOrderDetailsForCode(orderCode);

    if (orderDetails.isGuestCustomer() && !StringUtils.substringBefore(orderDetails.getUser().getUid(), "|")
            .equals(getSessionService().getAttribute(WebConstants.ANONYMOUS_CHECKOUT_GUID))) {
        return getCheckoutRedirectUrl();
    }// w w  w .  j  av a  2  s  .  co  m

    if (orderDetails.getEntries() != null && !orderDetails.getEntries().isEmpty()) {
        for (final OrderEntryData entry : orderDetails.getEntries()) {
            final String productCode = entry.getProduct().getCode();
            final ProductData product = productFacade.getProductForCodeAndOptions(productCode,
                    Arrays.asList(ProductOption.BASIC, ProductOption.PRICE, ProductOption.CATEGORIES));
            entry.setProduct(product);
        }
    }

    orderDetails.setNet(true);

    model.addAttribute("orderCode", orderCode);
    model.addAttribute("orderData", orderDetails);
    model.addAttribute("allItems", orderDetails.getEntries());
    model.addAttribute("deliveryAddress", orderDetails.getDeliveryAddress());
    model.addAttribute("deliveryMode", orderDetails.getDeliveryMode());
    model.addAttribute("paymentInfo", orderDetails.getPaymentInfo());
    model.addAttribute("pageType", PageType.ORDERCONFIRMATION.name());

    final String uid;

    if (orderDetails.isGuestCustomer() && !model.containsAttribute("guestRegisterForm")) {
        final GuestRegisterForm guestRegisterForm = new GuestRegisterForm();
        guestRegisterForm.setOrderCode(orderDetails.getGuid());
        uid = orderDetails.getPaymentInfo().getBillingAddress().getEmail();
        guestRegisterForm.setUid(uid);
        model.addAttribute(guestRegisterForm);
    } else {
        uid = orderDetails.getUser().getUid();
    }
    model.addAttribute("email", uid);

    final String continueUrl = (String) getSessionService().getAttribute(WebConstants.CONTINUE_URL);
    model.addAttribute(CONTINUE_URL_KEY, (continueUrl != null && !continueUrl.isEmpty()) ? continueUrl : ROOT);

    final AbstractPageModel cmsPage = getContentPageForLabelOrId(CHECKOUT_ORDER_CONFIRMATION_CMS_PAGE_LABEL);
    storeCmsPageInModel(model, cmsPage);
    setUpMetaDataForContentPage(model, getContentPageForLabelOrId(CHECKOUT_ORDER_CONFIRMATION_CMS_PAGE_LABEL));
    model.addAttribute("metaRobots", "noindex,nofollow");

    return ControllerConstants.Views.Pages.Checkout.CheckoutConfirmationPage;
}

From source file:com.hangum.tadpole.rdb.core.viewers.object.sub.utils.TadpoleObjectQuery.java

/**
 * ?? Table?   .//  w  w  w . j  a  v  a2s  .  c o m
 * 
 * @param userDB
 * @param tableDao
 * @throws Exception
 */
public static List<TableColumnDAO> getTableColumns(UserDBDAO userDB, TableDAO tableDao) throws Exception {
    List<TableColumnDAO> returnColumns = new ArrayList<TableColumnDAO>();

    Map<String, String> mapParam = new HashMap<String, String>();
    mapParam.put("db", userDB.getDb());
    String strTableName = "";
    if (userDB.getDBDefine() == DBDefine.SQLite_DEFAULT)
        strTableName = tableDao.getSysName();
    else
        strTableName = tableDao.getName();

    if (userDB.getDBDefine() == DBDefine.ALTIBASE_DEFAULT) {
        mapParam.put("user", StringUtils.substringBefore(strTableName, "."));
        mapParam.put("table", StringUtils.substringAfter(strTableName, "."));
    } else {
        mapParam.put("schema", tableDao.getSchema_name());
        mapParam.put("table", strTableName);
    }

    if (userDB.getDBDefine() == DBDefine.TAJO_DEFAULT) {
        returnColumns = new TajoConnectionManager().tableColumnList(userDB, mapParam);
    } else if (userDB.getDBDefine() == DBDefine.POSTGRE_DEFAULT) {
        if ("".equals(mapParam.get("schema")) || null == mapParam.get("schema")) {
            mapParam.put("schema", "public");
        }
        SqlMapClient sqlClient = TadpoleSQLManager.getInstance(userDB);
        returnColumns = sqlClient.queryForList("tableColumnList", mapParam); //$NON-NLS-1$
    } else {
        SqlMapClient sqlClient = TadpoleSQLManager.getInstance(userDB);
        returnColumns = sqlClient.queryForList("tableColumnList", mapParam); //$NON-NLS-1$
    }

    if (DBDefine.SQLite_DEFAULT == userDB.getDBDefine()) {
        try {
            SqlMapClient sqlClient = TadpoleSQLManager.getInstance(userDB);
            List<SQLiteForeignKeyListDAO> foreignKeyList = sqlClient.queryForList("tableForeignKeyList", //$NON-NLS-1$
                    mapParam);
            for (SQLiteForeignKeyListDAO fkeydao : foreignKeyList) {
                for (TableColumnDAO dao : returnColumns) {
                    if (dao.getName().equals(fkeydao.getFrom())) {
                        if (PublicTadpoleDefine.isPK(dao.getKey())) {
                            dao.setKey("MUL");
                        } else {
                            dao.setKey("FK");
                        }
                    }
                }
            }
        } catch (Exception e) {
            logger.error("not found foreignkey for " + tableDao.getName());
        }
    }

    // if find the keyword is add system quote.
    for (TableColumnDAO td : returnColumns) {
        td.setTableDao(tableDao);
        td.setSysName(SQLUtil.makeIdentifierName(userDB, td.getField()));
    }

    returnColumns = DBAccessCtlManager.getInstance().getColumnFilter(tableDao, returnColumns, userDB);

    return returnColumns;
}

From source file:cec.easyshop.storefront.controllers.pages.CheckoutController.java

protected String processOrderCode(final String orderCode, final Model model, final HttpServletRequest request)
        throws CMSItemNotFoundException {
    final OrderData orderDetails = orderFacade.getOrderDetailsForCode(orderCode);

    if (orderDetails.isGuestCustomer() && !StringUtils.substringBefore(orderDetails.getUser().getUid(), "|")
            .equals(getSessionService().getAttribute(WebConstants.ANONYMOUS_CHECKOUT_GUID))) {
        return getCheckoutRedirectUrl();
    }/*from  ww  w .  ja  v a2  s  .  com*/

    if (orderDetails.getEntries() != null && !orderDetails.getEntries().isEmpty()) {
        for (final OrderEntryData entry : orderDetails.getEntries()) {
            final String productCode = entry.getProduct().getCode();
            final ProductData product = productFacade.getProductForCodeAndOptions(productCode,
                    Arrays.asList(ProductOption.BASIC, ProductOption.PRICE, ProductOption.CATEGORIES));
            entry.setProduct(product);
        }
    }

    model.addAttribute("orderCode", orderCode);
    model.addAttribute("orderData", orderDetails);
    model.addAttribute("allItems", orderDetails.getEntries());
    model.addAttribute("deliveryAddress", orderDetails.getDeliveryAddress());
    model.addAttribute("deliveryMode", orderDetails.getDeliveryMode());
    model.addAttribute("paymentInfo", orderDetails.getPaymentInfo());
    model.addAttribute("pageType", PageType.ORDERCONFIRMATION.name());

    final String uid;

    if (orderDetails.isGuestCustomer() && !model.containsAttribute("guestRegisterForm")) {
        final GuestRegisterForm guestRegisterForm = new GuestRegisterForm();
        guestRegisterForm.setOrderCode(orderDetails.getGuid());
        uid = orderDetails.getPaymentInfo().getBillingAddress().getEmail();
        guestRegisterForm.setUid(uid);
        model.addAttribute(guestRegisterForm);
    } else {
        uid = orderDetails.getUser().getUid();
    }
    model.addAttribute("email", uid);

    final String continueUrl = (String) getSessionService().getAttribute(WebConstants.CONTINUE_URL);
    model.addAttribute(CONTINUE_URL_KEY, (continueUrl != null && !continueUrl.isEmpty()) ? continueUrl : ROOT);

    final AbstractPageModel cmsPage = getContentPageForLabelOrId(CHECKOUT_ORDER_CONFIRMATION_CMS_PAGE_LABEL);
    storeCmsPageInModel(model, cmsPage);
    setUpMetaDataForContentPage(model, getContentPageForLabelOrId(CHECKOUT_ORDER_CONFIRMATION_CMS_PAGE_LABEL));
    model.addAttribute(ThirdPartyConstants.SeoRobots.META_ROBOTS,
            ThirdPartyConstants.SeoRobots.NOINDEX_NOFOLLOW);

    return ControllerConstants.Views.Pages.Checkout.CheckoutConfirmationPage;
}

From source file:com.google.gdt.eclipse.designer.model.widgets.panels.LayoutPanelInfo.java

/**
 * Converts "setWidgetLeftRight()" into <code>["left", "right"]</code>.
 *//* w  w  w .ja  va 2 s .  co  m*/
private static String[] getLocationPropertyTitles(String signature) {
    String name = StringUtils.substringBefore(signature, "(");
    String elementsName = StringUtils.remove(name, "setWidget");
    String[] titles = StringUtils.splitByCharacterTypeCamelCase(elementsName);
    Assert.isTrue(titles.length == 2, signature);
    titles[0] = titles[0].toLowerCase();
    titles[1] = titles[1].toLowerCase();
    return titles;
}

From source file:com.ebook.storefront.controllers.pages.CheckoutController.java

protected String processOrderCode(final String orderCode, final Model model, final HttpServletRequest request)
        throws CMSItemNotFoundException {
    final OrderData orderDetails = orderFacade.getOrderDetailsForCode(orderCode);

    if (orderDetails.isGuestCustomer() && !StringUtils.substringBefore(orderDetails.getUser().getUid(), "|")
            .equals(getSessionService().getAttribute(WebConstants.ANONYMOUS_CHECKOUT_GUID))) {
        return getCheckoutRedirectUrl();
    }//from   w  w w  .  ja v  a  2 s  .  co  m

    if (orderDetails.getEntries() != null && !orderDetails.getEntries().isEmpty()) {
        for (final OrderEntryData entry : orderDetails.getEntries()) {
            final String productCode = entry.getProduct().getCode();
            final ProductData product = productFacade.getProductForCodeAndOptions(productCode,
                    Arrays.asList(ProductOption.BASIC, ProductOption.PRICE, ProductOption.CATEGORIES));
            entry.setProduct(product);
        }
    }

    model.addAttribute("orderCode", orderCode);
    model.addAttribute("orderData", orderDetails);
    model.addAttribute("allItems", orderDetails.getEntries());
    model.addAttribute("deliveryAddress", orderDetails.getDeliveryAddress());
    model.addAttribute("deliveryMode", orderDetails.getDeliveryMode());
    model.addAttribute("paymentInfo", orderDetails.getPaymentInfo());
    model.addAttribute("pageType", PageType.ORDERCONFIRMATION.name());

    processEmailAddress(model, orderDetails);

    final String continueUrl = (String) getSessionService().getAttribute(WebConstants.CONTINUE_URL);
    model.addAttribute(CONTINUE_URL_KEY, (continueUrl != null && !continueUrl.isEmpty()) ? continueUrl : ROOT);

    final AbstractPageModel cmsPage = getContentPageForLabelOrId(CHECKOUT_ORDER_CONFIRMATION_CMS_PAGE_LABEL);
    storeCmsPageInModel(model, cmsPage);
    setUpMetaDataForContentPage(model, getContentPageForLabelOrId(CHECKOUT_ORDER_CONFIRMATION_CMS_PAGE_LABEL));
    model.addAttribute(ThirdPartyConstants.SeoRobots.META_ROBOTS,
            ThirdPartyConstants.SeoRobots.NOINDEX_NOFOLLOW);

    if (ResponsiveUtils.isResponsive()) {
        return getViewForPage(model);
    }

    return ControllerConstants.Views.Pages.Checkout.CheckoutConfirmationPage;
}

From source file:jp.ac.tokushima_u.is.ll.common.orm.hibernate.HibernateDao.java

/**
 * count???HQL???????/*w w  w.  j a va 2 s  .co m*/
 *
 * ?????HQL????????HQL??count???????
 */
protected long countHqlResult(final String hql, final Map<String, Object> values) {
    String fromHql = hql;
    //select?order by?count????,???
    fromHql = "from " + StringUtils.substringAfter(fromHql, "from");
    fromHql = StringUtils.substringBefore(fromHql, "order by");

    String countHql = "select count(*) " + fromHql;

    try {
        Long count = findUnique(countHql, values);
        return count;
    } catch (Exception e) {
        throw new RuntimeException("hql can't be auto count, hql is:" + countHql, e);
    }
}