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

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

Introduction

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

Prototype

public static String substringBetween(String str, String open, String close) 

Source Link

Document

Gets the String that is nested in between two Strings.

Usage

From source file:org.kuali.rice.ken.bo.Notification.java

/**
 * This method just uses StringUtils to get at the content of the <message> tag 
 * that exists in the notification content.
 * @return String/*from ww w .  j  av  a  2 s.c o m*/
 */
public String getContentMessage() {
    return StringUtils.substringBetween(content, NotificationConstants.XML_MESSAGE_CONSTANTS.MESSAGE_OPEN,
            NotificationConstants.XML_MESSAGE_CONSTANTS.MESSAGE_CLOSE);
}

From source file:org.kuali.rice.kew.superuser.web.SuperUserAction.java

public ActionForward actionRequestApprove(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    LOG.info("entering actionRequestApprove() ...");
    SuperUserForm superUserForm = (SuperUserForm) form;

    // Retrieve the relevant arguments from the "methodToCall" parameter.
    String methodToCallAttr = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE);
    superUserForm.setActionTakenRecipientCode(StringUtils.substringBetween(methodToCallAttr,
            KRADConstants.METHOD_TO_CALL_PARM1_LEFT_DEL, KRADConstants.METHOD_TO_CALL_PARM1_RIGHT_DEL));
    superUserForm.setActionTakenNetworkId(StringUtils.substringBetween(methodToCallAttr,
            KRADConstants.METHOD_TO_CALL_PARM2_LEFT_DEL, KRADConstants.METHOD_TO_CALL_PARM2_RIGHT_DEL));
    superUserForm.setActionTakenWorkGroupId(StringUtils.substringBetween(methodToCallAttr,
            KRADConstants.METHOD_TO_CALL_PARM4_LEFT_DEL, KRADConstants.METHOD_TO_CALL_PARM4_RIGHT_DEL));
    superUserForm.setActionTakenActionRequestId(StringUtils.substringBetween(methodToCallAttr,
            KRADConstants.METHOD_TO_CALL_PARM5_LEFT_DEL, KRADConstants.METHOD_TO_CALL_PARM5_RIGHT_DEL));

    LOG.debug("Routing super user action request approve action");
    boolean runPostProcessorLogic = ArrayUtils.contains(superUserForm.getActionRequestRunPostProcessorCheck(),
            superUserForm.getActionTakenActionRequestId());
    String documentId = superUserForm.getRouteHeader().getDocumentId();
    WorkflowDocumentActionsService documentActions = getWorkflowDocumentActionsService(documentId);
    DocumentActionParameters parameters = DocumentActionParameters.create(documentId,
            getUserSession(request).getPrincipalId(), superUserForm.getAnnotation());
    documentActions.superUserTakeRequestedAction(parameters, runPostProcessorLogic,
            superUserForm.getActionTakenActionRequestId());
    String messageString;//from   ww w  . ja v  a2s  . c om
    String actionReqest = StringUtils.substringBetween(methodToCallAttr,
            KRADConstants.METHOD_TO_CALL_PARM6_LEFT_DEL, KRADConstants.METHOD_TO_CALL_PARM6_RIGHT_DEL);
    if (actionReqest.equalsIgnoreCase("acknowledge")) {
        messageString = "general.routing.superuser.actionRequestAcknowledged";
    } else if (actionReqest.equalsIgnoreCase("FYI")) {
        messageString = "general.routing.superuser.actionRequestFYI";
    } else if (actionReqest.equalsIgnoreCase("complete")) {
        messageString = "general.routing.superuser.actionRequestCompleted";
    } else if (actionReqest.equalsIgnoreCase("approved")) {
        messageString = "general.routing.superuser.actionRequestApproved";
    } else {
        messageString = "general.routing.superuser.actionRequestApproved";
    }
    saveDocumentMessage(messageString, request, superUserForm.getDocumentId(),
            superUserForm.getActionTakenActionRequestId());
    LOG.info("exiting actionRequestApprove() ...");
    superUserForm.getActionRequests().clear();
    initForm(request, form);

    // If the action request was also an app specific request, remove it from the app specific route recipient list.
    int removalIndex = findAppSpecificRecipientIndex(superUserForm,
            superUserForm.getActionTakenActionRequestId());

    if (removalIndex >= 0) {
        superUserForm.getAppSpecificRouteList().remove(removalIndex);
    }

    return defaultDispatch(mapping, form, request, response);
}

From source file:org.kuali.rice.kew.superuser.web.SuperUserAction.java

public ActionForward routeToAppSpecificRecipient(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
    SuperUserForm superUserForm = (SuperUserForm) form;

    //super.routeToAppSpecificRecipient(mapping, form, request, response);
    //WorkflowRoutingForm routingForm = (WorkflowRoutingForm) form;
    String routeType = StringUtils.substringBetween(
            (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE),
            KRADConstants.METHOD_TO_CALL_PARM1_LEFT_DEL, KRADConstants.METHOD_TO_CALL_PARM1_RIGHT_DEL);
    AppSpecificRouteRecipient recipient = null;
    if (KewApiConstants.PERSON.equals(routeType)) {
        recipient = superUserForm.getAppSpecificRouteRecipient();
        recipient.setActionRequested(superUserForm.getAppSpecificRouteActionRequestCd());
        superUserForm.setAppSpecificPersonId(recipient.getId());
    } else {//  w  ww. ja v a  2 s .co  m
        recipient = superUserForm.getAppSpecificRouteRecipient2();
        recipient.setActionRequested(superUserForm.getAppSpecificRouteActionRequestCd2());
        superUserForm.setAppSpecificWorkgroupId(recipient.getId());
    }

    validateAppSpecificRoute(recipient);

    // Make sure that the requested action is still available.
    superUserForm.establishVisibleActionRequestCds();
    if (superUserForm.getAppSpecificRouteActionRequestCds().get(recipient.getActionRequested()) == null) {
        GlobalVariables.getMessageMap().putError(
                "appSpecificRouteRecipient"
                        + ((KewApiConstants.WORKGROUP.equals(recipient.getType())) ? "2" : "") + ".id",
                "appspecificroute.actionrequested.invalid");

        throw new ValidationException("The requested action of '" + recipient.getActionRequested()
                + "' is no longer available for this document");
    }

    try {
        String routeNodeName = getAdHocRouteNodeName(superUserForm.getWorkflowDocument().getDocumentId());
        //if (KewApiConstants.PERSON.equals(recipient.getType())) {
        if (KewApiConstants.PERSON.equals(routeType)) {
            String recipientPrincipalId = KEWServiceLocator.getIdentityHelperService()
                    .getIdForPrincipalName(recipient.getId());
            superUserForm.getWorkflowDocument().adHocToPrincipal(
                    ActionRequestType.fromCode(recipient.getActionRequested()), routeNodeName,
                    superUserForm.getAnnotation(), recipientPrincipalId, "", true);
        } else {
            String recipientGroupId = KEWServiceLocator.getIdentityHelperService()
                    .getIdForGroupName(recipient.getNamespaceCode(), recipient.getId());
            superUserForm.getWorkflowDocument().adHocToGroup(
                    ActionRequestType.fromCode(recipient.getActionRequested()), routeNodeName,
                    superUserForm.getAnnotation(), recipientGroupId, "", true);
        }
    } catch (Exception e) {
        LOG.error("Error generating app specific route request", e);
        throw new WorkflowServiceErrorException("AppSpecific Route Error",
                new WorkflowServiceErrorImpl("AppSpecific Route Error", "appspecificroute.systemerror"));
    }

    superUserForm.getActionRequests().clear();
    initForm(request, form);

    // Retrieve the ID of the latest action request and store it with the app specific route recipient.
    ActionRequestValue latestActnReq = getLatestActionRequest(superUserForm);
    if (latestActnReq != null) {
        recipient.setActionRequestId(latestActnReq.getActionRequestId());
    }
    // Add the recipient to the list.
    superUserForm.getAppSpecificRouteList().add(recipient);
    superUserForm.resetAppSpecificRoute();

    return start(mapping, form, request, response);
}

From source file:org.kuali.rice.kew.superuser.web.SuperUserAction.java

/**
 * Removes an existing AppSpecificRouteRecipient from the list.
 *//*from w w  w .  j  a va2 s . c om*/
public ActionForward removeAppSpecificRecipient(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
    SuperUserForm superUserForm = (SuperUserForm) form;
    // Make sure a valid route recipient index was specified in the "methodToCall" attribute.
    String strIndex = StringUtils.substringBetween(
            (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE),
            KRADConstants.METHOD_TO_CALL_PARM1_LEFT_DEL, KRADConstants.METHOD_TO_CALL_PARM1_RIGHT_DEL);
    if (StringUtils.isBlank(strIndex)) {
        throw new WorkflowException("No adhoc route recipient index specified");
    }
    int removeIndex = Integer.parseInt(strIndex);
    if (removeIndex < 0 || removeIndex >= superUserForm.getAppSpecificRouteList().size()) {
        throw new WorkflowException("Invalid adhoc route recipient index specified");
    }
    // Remove the specified recipient from the routing, based on the recipient's ID and the ID of the action request that handled the recipient.
    AppSpecificRouteRecipient removedRec = (AppSpecificRouteRecipient) superUserForm.getAppSpecificRouteList()
            .get(removeIndex);
    if (removedRec.getActionRequestId() != null) {
        superUserForm.getWorkflowDocument().revokeAdHocRequestById(removedRec.getActionRequestId().toString(),
                "");
    } else {
        AdHocRevoke adHocRevoke = null;
        // Set the ID according to whether the recipient is a person or a group.
        if (KewApiConstants.PERSON.equals(removedRec.getType())) {
            adHocRevoke = AdHocRevoke.createRevokeFromPrincipal(
                    KEWServiceLocator.getIdentityHelperService().getIdForPrincipalName(removedRec.getId()));
        } else {
            adHocRevoke = AdHocRevoke.createRevokeFromGroup(KEWServiceLocator.getIdentityHelperService()
                    .getIdForGroupName(removedRec.getNamespaceCode(), removedRec.getId()));
        }
        superUserForm.getWorkflowDocument().revokeAdHocRequests(adHocRevoke, "");
    }
    superUserForm.getAppSpecificRouteList().remove(removeIndex);

    superUserForm.getActionRequests().clear();
    initForm(request, form);
    return start(mapping, form, request, response);
}

From source file:org.kuali.rice.kim.web.struts.action.IdentityManagementPersonDocumentAction.java

protected String getSelectedParentChildIdx(HttpServletRequest request) {
    String lineNumber = null;// ww w .j  a v a  2s.c  o m
    String parameterName = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE);
    if (StringUtils.isNotBlank(parameterName)) {
        lineNumber = StringUtils.substringBetween(parameterName, ".line", ".");
    }
    return lineNumber;
}

From source file:org.kuali.rice.kim.web.struts.action.IdentityManagementRoleDocumentAction.java

protected String getDelegationRoleMemberToJumpTo(HttpServletRequest request) {
    String delegationRoleMemberIdToJumpTo = "";
    String parameterName = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE);
    if (StringUtils.isNotBlank(parameterName)) {
        delegationRoleMemberIdToJumpTo = StringUtils.substringBetween(parameterName, ".dmrmi", ".");
    }// w  w w. j ava 2 s . c o m
    return delegationRoleMemberIdToJumpTo;
}

From source file:org.kuali.rice.kns.util.PagingBannerUtils.java

/**
 * find the number string in a method to call parameter with the following format parameterPrefix.1 or
 * parameterPrefix.1.bleh/*from www . j  a va 2s  . c om*/
 * 
 * @param paramPrefix the 
 * @param parameterNames the parameter names.
 * @return the numerical value or -1
 */
public static int getNumbericalValueAfterPrefix(String paramPrefix, Enumeration<String> parameterNames) {

    for (String parameterName : CollectionUtils.toIterable(parameterNames)) {
        if (parameterName.startsWith(paramPrefix)) {
            parameterName = WebUtils.endsWithCoordinates(parameterName) ? parameterName : parameterName + ".x";
            String numberStr = StringUtils.substringBetween(parameterName, paramPrefix, ".");
            if (NumberUtils.isDigits(numberStr)) {
                return Integer.parseInt(numberStr);
            }
        }
    }

    return -1;
}

From source file:org.kuali.rice.kns.util.PagingBannerUtils.java

/**
 * same as method above except for use when it is not feasible to use ordinals to identify columns -- for example,
 * if dynamic attributes may be used/*  w w  w.  ja va2 s  . c om*/
 */
public static String getStringValueAfterPrefix(String paramPrefix, Enumeration<String> parameterNames) {
    for (String parameterName : CollectionUtils.toIterable(parameterNames)) {
        if (parameterName.startsWith(paramPrefix)) {
            parameterName = WebUtils.endsWithCoordinates(parameterName) ? parameterName : parameterName + ".x";
            return StringUtils.substringBetween(parameterName, paramPrefix, ".");
        }
    }

    return "";
}

From source file:org.kuali.rice.kns.util.WebUtils.java

/**
 * Parses out the methodToCall command and also sets the request attribute
 * for the methodToCall.//from w  ww  . j a  v  a 2s .  co  m
 * 
 * @param form
 *            the ActionForm
 * @param request
 *            the request to set the attribute on
 * @param string
 *            the methodToCall string
 * @return the methodToCall command
 */
private static String getMethodToCallSettingAttribute(ActionForm form, HttpServletRequest request,
        String string) {

    if (form instanceof KualiForm && !((KualiForm) form).shouldMethodToCallParameterBeUsed(string,
            request.getParameter(string), request)) {
        throw new RuntimeException("Cannot verify that the methodToCall should be " + string);
    }
    // always adding a coordinate even if not an image
    final String attributeValue = endsWithCoordinates(string) ? string
            : string + IMAGE_COORDINATE_CLICKED_X_EXTENSION;
    final String methodToCall = StringUtils.substringBetween(attributeValue,
            KRADConstants.DISPATCH_REQUEST_PARAMETER + ".", ".");
    request.setAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE, attributeValue);
    return methodToCall;
}

From source file:org.kuali.rice.kns.web.struts.action.KualiAction.java

/**
 * Parses the method to call attribute to pick off the line number which should have an action performed on it.
 *
 * @param request//from  w w  w . j  a v a 2  s. co m
 * @return
 */
protected int getSelectedLine(HttpServletRequest request) {
    int selectedLine = -1;
    String parameterName = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE);
    if (StringUtils.isNotBlank(parameterName)) {
        String lineNumber = StringUtils.substringBetween(parameterName, ".line", ".");
        if (StringUtils.isEmpty(lineNumber)) {
            return selectedLine;
        }
        selectedLine = Integer.parseInt(lineNumber);
    }

    return selectedLine;
}