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.kns.web.struts.action.KualiMaintenanceDocumentAction.java

/**
 * Called on return from a lookup./* w w w  .j  ava  2 s . co  m*/
 */
@Override
public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    KualiMaintenanceForm maintenanceForm = (KualiMaintenanceForm) form;

    WebUtils.reuseErrorMapFromPreviousRequest(maintenanceForm);
    maintenanceForm.setDerivedValuesOnForm(request);

    refreshAdHocRoutingWorkgroupLookups(request, maintenanceForm);
    MaintenanceDocument document = (MaintenanceDocument) maintenanceForm.getDocument();

    // call refresh on new maintainable
    Map<String, String> requestParams = new HashMap<String, String>();
    for (Enumeration i = request.getParameterNames(); i.hasMoreElements();) {
        String requestKey = (String) i.nextElement();
        String requestValue = request.getParameter(requestKey);
        requestParams.put(requestKey, requestValue);
    }

    // Add multiple values from Lookup
    Collection<PersistableBusinessObject> rawValues = null;
    if (StringUtils.equals(KRADConstants.MULTIPLE_VALUE, maintenanceForm.getRefreshCaller())) {
        String lookupResultsSequenceNumber = maintenanceForm.getLookupResultsSequenceNumber();
        if (StringUtils.isNotBlank(lookupResultsSequenceNumber)) {
            // actually returning from a multiple value lookup
            String lookupResultsBOClassName = maintenanceForm.getLookupResultsBOClassName();
            Class lookupResultsBOClass = Class.forName(lookupResultsBOClassName);

            rawValues = getLookupResultsService().retrieveSelectedResultBOs(lookupResultsSequenceNumber,
                    lookupResultsBOClass, GlobalVariables.getUserSession().getPerson().getPrincipalId());
        }
    }

    if (rawValues != null) { // KULCOA-1073 - caused by this block running unnecessarily?
        // we need to run the business rules on all the newly added items to the collection
        // KULCOA-1000, KULCOA-1004 removed business rule validation on multiple value return
        // (this was running before the objects were added anyway)
        // getKualiRuleService().applyRules(new SaveDocumentEvent(document));
        String collectionName = maintenanceForm.getLookedUpCollectionName();
        //TODO: Cathy remember to delete this block of comments after I've tested.            
        //            PersistableBusinessObject bo = document.getNewMaintainableObject().getBusinessObject();
        //            Collection maintCollection = this.extractCollection(bo, collectionName);
        //            String docTypeName = ((MaintenanceDocument) maintenanceForm.getDocument()).getDocumentHeader().getWorkflowDocument().getDocumentType();
        //            Class collectionClass = extractCollectionClass(docTypeName, collectionName);
        //
        //            List<MaintainableSectionDefinition> sections = maintenanceDocumentDictionaryService.getMaintainableSections(docTypeName);
        //            Map<String, String> template = MaintenanceUtils.generateMultipleValueLookupBOTemplate(sections, collectionName);
        //            for (PersistableBusinessObject nextBo : rawValues) {
        //                PersistableBusinessObject templatedBo = (PersistableBusinessObject) ObjectUtils.createHybridBusinessObject(collectionClass, nextBo, template);
        //                templatedBo.setNewCollectionRecord(true);
        //                maintCollection.add(templatedBo);
        //            }
        document.getNewMaintainableObject().addMultipleValueLookupResults(document, collectionName, rawValues,
                false, document.getNewMaintainableObject().getBusinessObject());
        if (LOG.isInfoEnabled()) {
            LOG.info("********************doing editing 3 in refersh()***********************.");
        }
        boolean isEdit = KRADConstants.MAINTENANCE_EDIT_ACTION.equals(maintenanceForm.getMaintenanceAction());
        boolean isCopy = KRADConstants.MAINTENANCE_COPY_ACTION.equals(maintenanceForm.getMaintenanceAction());

        if (isEdit || isCopy) {
            document.getOldMaintainableObject().addMultipleValueLookupResults(document, collectionName,
                    rawValues, true, document.getOldMaintainableObject().getBusinessObject());
            document.getOldMaintainableObject().refresh(maintenanceForm.getRefreshCaller(), requestParams,
                    document);
        }
    }

    document.getNewMaintainableObject().refresh(maintenanceForm.getRefreshCaller(), requestParams, document);

    //pass out customAction from methodToCall parameter. Call processAfterPost
    String fullParameter = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE);
    if (StringUtils.contains(fullParameter, KRADConstants.CUSTOM_ACTION)) {
        String customAction = StringUtils.substringBetween(fullParameter,
                KRADConstants.METHOD_TO_CALL_PARM1_LEFT_DEL, KRADConstants.METHOD_TO_CALL_PARM1_RIGHT_DEL);
        String[] actionValue = new String[1];
        actionValue[0] = StringUtils.substringAfter(customAction, ".");
        Map<String, String[]> paramMap = new HashMap<String, String[]>(request.getParameterMap());
        paramMap.put(KRADConstants.CUSTOM_ACTION, actionValue);
        doProcessingAfterPost((KualiMaintenanceForm) form, paramMap);
    }

    return mapping.findForward(RiceConstants.MAPPING_BASIC);
}

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

/**
 * Convert a Request into a Map<String,String>. Technically, Request parameters do not neatly translate into a Map of Strings,
 * because a given parameter may legally appear more than once (so a Map of String[] would be more accurate.) This method should
 * be safe for business objects, but may not be reliable for more general uses.
 *//*from w ww . ja  v a  2s.  c o m*/
String extractCollectionName(HttpServletRequest request, String methodToCall) {
    // collection name and underlying object type from request parameter
    String parameterName = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE);
    String collectionName = null;
    if (StringUtils.isNotBlank(parameterName)) {
        collectionName = StringUtils.substringBetween(parameterName, methodToCall + ".", ".(");
    }
    return collectionName;
}

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

/**
 * Turns on (or off) the inactive record display for a maintenance collection.
 *//*from   ww  w . j  a  v  a  2  s .c  o m*/
public ActionForward toggleInactiveRecordDisplay(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
    KualiMaintenanceForm maintenanceForm = (KualiMaintenanceForm) form;
    MaintenanceDocument document = (MaintenanceDocument) maintenanceForm.getDocument();
    Maintainable oldMaintainable = document.getOldMaintainableObject();
    Maintainable newMaintainable = document.getNewMaintainableObject();

    String collectionName = extractCollectionName(request, KRADConstants.TOGGLE_INACTIVE_METHOD);
    if (collectionName == null) {
        LOG.error("Unable to get find collection name in request.");
        throw new RuntimeException("Unable to get find collection class in request.");
    }

    String parameterName = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE);
    boolean showInactive = Boolean.parseBoolean(
            StringUtils.substringBetween(parameterName, KRADConstants.METHOD_TO_CALL_BOPARM_LEFT_DEL, "."));

    oldMaintainable.setShowInactiveRecords(collectionName, showInactive);
    newMaintainable.setShowInactiveRecords(collectionName, showInactive);

    return mapping.findForward(RiceConstants.MAPPING_BASIC);
}

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

/**
 * Parses the method to call attribute to pick off the button number that was pressed.
 *
 * @param request/*from w w  w.  j av  a2  s  . c  o  m*/
 * @return int
 */
private String getSelectedButton(HttpServletRequest request) {
    String selectedButton = "-1";
    String parameterName = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE);
    if (StringUtils.isNotBlank(parameterName)) {
        selectedButton = StringUtils.substringBetween(parameterName, ".button", ".");
    }

    return selectedButton;
}

From source file:org.kuali.rice.kns.web.struts.form.MultipleValueLookupForm.java

/**
 * Parses the method to call parameter passed in as a post parameter
 * /*w  ww  .  j  a v  a2s .  co  m*/
 * The parameter should be something like methodToCall.sort.1.(::;true;::).x, this method will return the value
 * between (::; and ;::) as a boolean
 * 
 * @param methodToCallParam the method to call in a format described above
 * @return the value between the delimiters, false if there are no delimiters
 */
protected boolean parseSearchUsingOnlyPrimaryKeyValues(String methodToCallParam) {
    String searchUsingOnlyPrimaryKeyValuesStr = StringUtils.substringBetween(methodToCallParam,
            KRADConstants.METHOD_TO_CALL_PARM12_LEFT_DEL, KRADConstants.METHOD_TO_CALL_PARM12_RIGHT_DEL);
    if (StringUtils.isBlank(searchUsingOnlyPrimaryKeyValuesStr)) {
        return false;
    }
    return Boolean.parseBoolean(searchUsingOnlyPrimaryKeyValuesStr);
}

From source file:org.kuali.rice.krad.datadictionary.MessageBeanProcessor.java

/**
 * Checks a string property value for a message placeholder and if found the message is retrieved and updated
 * in the property value//  w  ww. ja  v a 2 s.c  o m
 *
 * @param propertyValue string value to process for message placeholders
 * @param nestedBeanStack stack of bean definitions that contain the property, used to determine the namespace
 * and component for the message retrieval
 * @return String new value for the property (possibly modified from an external message)
 */
protected String processMessagePlaceholders(String propertyValue, Stack<BeanDefinitionHolder> nestedBeanStack) {
    String trimmedPropertyValue = StringUtils.stripStart(propertyValue, " ");
    if (StringUtils.isBlank(trimmedPropertyValue)) {
        return propertyValue;
    }

    String newPropertyValue = propertyValue;

    // first check for a replacement message key
    if (trimmedPropertyValue.startsWith(KRADConstants.MESSAGE_KEY_PLACEHOLDER_PREFIX)
            && StringUtils.contains(trimmedPropertyValue, KRADConstants.MESSAGE_KEY_PLACEHOLDER_SUFFIX)) {
        String messageKeyStr = StringUtils.substringBetween(trimmedPropertyValue,
                KRADConstants.MESSAGE_KEY_PLACEHOLDER_PREFIX, KRADConstants.MESSAGE_KEY_PLACEHOLDER_SUFFIX);

        // get any default specified value (given after the message key)
        String messageKeyWithPlaceholder = KRADConstants.MESSAGE_KEY_PLACEHOLDER_PREFIX + messageKeyStr
                + KRADConstants.MESSAGE_KEY_PLACEHOLDER_SUFFIX;

        String defaultPropertyValue = StringUtils.substringAfter(trimmedPropertyValue,
                messageKeyWithPlaceholder);

        // set the new property value to the message text (if found), or the default value if a message was not found
        // note the message text could be an empty string, in which case it will override the default
        String messageText = getMessageTextForKey(messageKeyStr, nestedBeanStack);
        if (messageText != null) {
            // if default value set then we need to merge any expressions
            if (StringUtils.isNotBlank(defaultPropertyValue)) {
                newPropertyValue = getMergedMessageText(messageText, defaultPropertyValue);
            } else {
                newPropertyValue = messageText;
            }
        } else {
            newPropertyValue = defaultPropertyValue;
        }
    }
    // now check for message keys within an expression
    else if (StringUtils.contains(trimmedPropertyValue, KRADConstants.EXPRESSION_MESSAGE_PLACEHOLDER_PREFIX)) {
        String[] expressionMessageKeys = StringUtils.substringsBetween(newPropertyValue,
                KRADConstants.EXPRESSION_MESSAGE_PLACEHOLDER_PREFIX,
                KRADConstants.EXPRESSION_MESSAGE_PLACEHOLDER_SUFFIX);

        for (String expressionMessageKey : expressionMessageKeys) {
            String expressionMessageText = getMessageTextForKey(expressionMessageKey, nestedBeanStack);
            newPropertyValue = StringUtils
                    .replace(newPropertyValue,
                            KRADConstants.EXPRESSION_MESSAGE_PLACEHOLDER_PREFIX + expressionMessageKey
                                    + KRADConstants.EXPRESSION_MESSAGE_PLACEHOLDER_SUFFIX,
                            expressionMessageText);
        }
    }

    return newPropertyValue;
}

From source file:org.kuali.rice.krad.datadictionary.uif.UifBeanFactoryPostProcessor.java

/**
 * Checks whether the given property value is of String type, and if so whether it contains the expression
 * placholder(s)/*from  w  w  w .j  a v a2  s .com*/
 *
 * @param propertyValue value to check for expressions
 * @return true if the property value contains expression(s), false if it does not
 */
protected boolean hasExpression(Object propertyValue) {
    if (propertyValue != null) {
        // if value is string, check for el expression
        String strValue = getStringValue(propertyValue);
        if (strValue != null) {
            String elPlaceholder = StringUtils.substringBetween(strValue, UifConstants.EL_PLACEHOLDER_PREFIX,
                    UifConstants.EL_PLACEHOLDER_SUFFIX);
            if (StringUtils.isNotBlank(elPlaceholder)) {
                return true;
            }
        }
    }

    return false;
}

From source file:org.kuali.rice.krad.devtools.maintainablexml.MaintainableXMLConversionServiceImpl.java

public String transformMaintainableXML(String xml) {
    String beginning = StringUtils.substringBefore(xml, "<" + OLD_MAINTAINABLE_OBJECT_ELEMENT_NAME + ">");
    String oldMaintainableObjectXML = StringUtils.substringBetween(xml,
            "<" + OLD_MAINTAINABLE_OBJECT_ELEMENT_NAME + ">",
            "</" + OLD_MAINTAINABLE_OBJECT_ELEMENT_NAME + ">");
    String newMaintainableObjectXML = StringUtils.substringBetween(xml,
            "<" + NEW_MAINTAINABLE_OBJECT_ELEMENT_NAME + ">",
            "</" + NEW_MAINTAINABLE_OBJECT_ELEMENT_NAME + ">");
    String ending = StringUtils.substringAfter(xml, "</" + NEW_MAINTAINABLE_OBJECT_ELEMENT_NAME + ">");

    String convertedOldMaintainableObjectXML = transformSection(oldMaintainableObjectXML);
    String convertedNewMaintainableObjectXML = transformSection(newMaintainableObjectXML);

    String convertedXML = beginning + "<" + OLD_MAINTAINABLE_OBJECT_ELEMENT_NAME + ">"
            + convertedOldMaintainableObjectXML + "</" + OLD_MAINTAINABLE_OBJECT_ELEMENT_NAME + ">" + "<"
            + NEW_MAINTAINABLE_OBJECT_ELEMENT_NAME + ">" + convertedNewMaintainableObjectXML + "</"
            + NEW_MAINTAINABLE_OBJECT_ELEMENT_NAME + ">" + ending;
    return convertedXML;
}

From source file:org.kuali.rice.krad.devtools.maintainablexml.MaintainableXMLConversionServiceImpl.java

private String transformSection(String xml) {

    String maintenanceAction = StringUtils.substringBetween(xml, "<" + MAINTENANCE_ACTION_ELEMENT_NAME + ">",
            "</" + MAINTENANCE_ACTION_ELEMENT_NAME + ">");
    xml = StringUtils.substringBefore(xml, "<" + MAINTENANCE_ACTION_ELEMENT_NAME + ">");

    try {//w ww  . j  a v a  2s. co  m
        xml = upgradeBONotes(xml);
        if (classNameRuleMap == null) {
            setRuleMaps();
        }

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document document = db.parse(new InputSource(new StringReader(xml)));

        removePersonObjects(document);

        for (Node childNode = document.getFirstChild(); childNode != null;) {
            Node nextChild = childNode.getNextSibling();
            transformClassNode(document, childNode);
            childNode = nextChild;
        }

        TransformerFactory transFactory = TransformerFactory.newInstance();
        Transformer trans = transFactory.newTransformer();
        trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        trans.setOutputProperty(OutputKeys.INDENT, "yes");

        StringWriter writer = new StringWriter();
        StreamResult result = new StreamResult(writer);
        DOMSource source = new DOMSource(document);
        trans.transform(source, result);
        xml = writer.toString().replaceAll("(?m)^\\s+\\n", "");
    } catch (Exception e) {
        e.printStackTrace();
    }

    return xml + "<" + MAINTENANCE_ACTION_ELEMENT_NAME + ">" + maintenanceAction + "</"
            + MAINTENANCE_ACTION_ELEMENT_NAME + ">";
}

From source file:org.kuali.rice.krad.devtools.maintainablexml.MaintainableXMLConversionServiceImpl.java

/**
 * Upgrades the old Bo notes tag that was part of the maintainable to the new notes tag.
 *
 * @param oldXML - the xml to upgrade//from  w w  w. j  a  v  a2  s .c om
 * @throws Exception
 */
private String upgradeBONotes(String oldXML) throws Exception {
    // Get the old bo note xml
    String notesXml = StringUtils.substringBetween(oldXML, "<boNotes>", "</boNotes>");
    if (notesXml != null) {
        notesXml = notesXml.replace("org.kuali.rice.kns.bo.Note", "org.kuali.rice.krad.bo.Note");
        notesXml = "<org.apache.ojb.broker.core.proxy.ListProxyDefaultImpl>\n" + notesXml
                + "\n</org.apache.ojb.broker.core.proxy.ListProxyDefaultImpl>";
        oldXML = oldXML.replaceFirst(">", ">\n<notes>\n" + notesXml + "\n</notes>");
    }
    return oldXML;
}