List of usage examples for org.apache.commons.lang StringUtils substringBetween
public static String substringBetween(String str, String open, String close)
Gets the String that is nested in between two Strings.
From source file:org.kuali.kfs.module.tem.document.web.struts.TemCorrectionForm.java
/** * @see org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase#populate(javax.servlet.http.HttpServletRequest) *///from ww w. java2 s. co m @Override public void populate(HttpServletRequest request) { super.populate(request); // Sync up the groups syncGroups(); agencyEntrySearchResultTableMetadata = new KualiTableRenderFormMetadata(); if (KFSConstants.TableRenderConstants.SWITCH_TO_PAGE_METHOD.equals(getMethodToCall())) { // look for the page number to switch to agencyEntrySearchResultTableMetadata.setSwitchToPageNumber(-1); // the param we're looking for looks like: methodToCall.switchToPage.1.x , where 1 is the page nbr String paramPrefix = KFSConstants.DISPATCH_REQUEST_PARAMETER + "." + KFSConstants.TableRenderConstants.SWITCH_TO_PAGE_METHOD + "."; for (Enumeration i = request.getParameterNames(); i.hasMoreElements();) { String parameterName = (String) i.nextElement(); if (parameterName.startsWith(paramPrefix)) { String switchToPageNumberStr = StringUtils.substringBetween(parameterName, paramPrefix, "."); agencyEntrySearchResultTableMetadata .setSwitchToPageNumber(Integer.parseInt(switchToPageNumberStr)); } } if (agencyEntrySearchResultTableMetadata.getSwitchToPageNumber() == -1) { throw new RuntimeException("Couldn't find page number"); } } if (KFSConstants.TableRenderConstants.SORT_METHOD.equals(getMethodToCall())) { agencyEntrySearchResultTableMetadata.setColumnToSortIndex(-1); // the param we're looking for looks like: methodToCall.sort.1.x , where 1 is the column to sort on String paramPrefix = KFSConstants.DISPATCH_REQUEST_PARAMETER + "." + KFSConstants.TableRenderConstants.SORT_METHOD + "."; for (Enumeration i = request.getParameterNames(); i.hasMoreElements();) { String parameterName = (String) i.nextElement(); if (parameterName.startsWith(paramPrefix) && parameterName.endsWith(".x")) { String columnToSortStr = StringUtils.substringBetween(parameterName, paramPrefix, "."); agencyEntrySearchResultTableMetadata.setColumnToSortIndex(Integer.parseInt(columnToSortStr)); } } if (agencyEntrySearchResultTableMetadata.getColumnToSortIndex() == -1) { throw new RuntimeException("Couldn't find column to sort"); } } // since the processInBatch option defaults to true, there's no built in POJO way to detect whether it's been unchecked // this code takes care of that if (StringUtils.isNotBlank( request.getParameter("processInBatch" + KFSConstants.CHECKBOX_PRESENT_ON_FORM_ANNOTATION)) && StringUtils.isBlank(request.getParameter("processInBatch"))) { setProcessInBatch(false); } if (StringUtils.isNotBlank( request.getParameter("matchCriteriaOnly" + KFSConstants.CHECKBOX_PRESENT_ON_FORM_ANNOTATION)) && StringUtils.isBlank(request.getParameter("matchCriteriaOnly"))) { setMatchCriteriaOnly(false); } }
From source file:org.kuali.kfs.module.tem.document.web.struts.TravelActionBase.java
@Override public ActionForward performLookup(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { TravelFormBase travelForm = (TravelFormBase) form; // parse out the important strings from our methodToCall parameter String fullParameter = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE); validateLookupInquiryFullParameter(request, form, fullParameter); String boClassName = StringUtils.substringBetween(fullParameter, KRADConstants.METHOD_TO_CALL_BOPARM_LEFT_DEL, KRADConstants.METHOD_TO_CALL_BOPARM_RIGHT_DEL); if (!StringUtils.isBlank(boClassName) && boClassName.equals(HistoricalTravelExpense.class.getName())) { TravelDocument document = travelForm.getTravelDocument(); boolean success = true; if (document.getTemProfileId() == null) { String identifier = TemConstants.documentProfileNames() .get(document.getFinancialDocumentTypeCode()); GlobalVariables.getMessageMap().putError( KRADPropertyConstants.DOCUMENT + "." + KIMPropertyConstants.Person.FIRST_NAME, TemKeyConstants.ERROR_TEM_IMPORT_EXPENSES_PROFILE_MISSING, identifier); success = false;//from w ww . j a v a2 s . c o m } if (!success) { return mapping.findForward(KFSConstants.MAPPING_BASIC); } travelForm.setRefreshCaller(KFSConstants.MULTIPLE_VALUE); GlobalVariables.getUserSession().addObject(TemPropertyConstants.TemProfileProperties.PROFILE_ID, document.getTemProfileId()); GlobalVariables.getUserSession().addObject(TemPropertyConstants.ARRANGER_PROFILE_ID, getTemProfileService() .findTemProfileByPrincipalId(GlobalVariables.getUserSession().getPrincipalId()) .getProfileId()); GlobalVariables.getUserSession().addObject(KFSPropertyConstants.DOCUMENT_TYPE_CODE, document.getFinancialDocumentTypeCode()); } return super.performLookup(mapping, form, request, response); }
From source file:org.kuali.kfs.module.tem.document.web.struts.TravelActionBase.java
public ActionForward deleteRelatedDocumentLine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { TravelFormBase travelReqForm = (TravelFormBase) form; String parameterName = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE); if (StringUtils.isNotBlank(parameterName)) { String relDocumentNumber = StringUtils.substringBetween(parameterName, "deleteRelatedDocumentLine.", "."); List<AccountingDocumentRelationship> adrList = getAccountingDocumentRelationshipService() .find(new AccountingDocumentRelationship(travelReqForm.getDocument().getDocumentNumber(), relDocumentNumber)); if (adrList != null && adrList.size() == 1) { if (adrList.get(0).getPrincipalId() .equals(GlobalVariables.getUserSession().getPerson().getPrincipalId())) { getAccountingDocumentRelationshipService().delete(adrList.get(0)); }/* w w w . j a va 2 s. co m*/ } } return mapping.findForward(KFSConstants.MAPPING_BASIC); }
From source file:org.kuali.kfs.module.tem.document.web.struts.TravelActionBase.java
protected int[] getSelectedDetailLine(HttpServletRequest request) { int[] selectedLines = new int[2]; String parameterName = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE); if (StringUtils.isNotBlank(parameterName)) { String lineNumbers = StringUtils.substringBetween(parameterName, ".line", "."); selectedLines[0] = Integer.parseInt(lineNumbers.split("-")[0]); selectedLines[1] = Integer.parseInt(lineNumbers.split("-")[1]); }/*w ww . ja va 2 s .c o m*/ return selectedLines; }
From source file:org.kuali.kfs.sys.context.SchemaBuilder.java
/** * Process a single schema file (setting validation and externalizable token) and outputs to static directory. Any new data * dictionary types encountered are added to the given Collection for later writing to the types include file * /*from ww w . j av a2s . com*/ * @param buildSchemFile build schema file that should be processed * @param outSchemaFilePathName full file path name for the outputted schema * @param useDataDictionaryValidation indicates whether data dictionary validation should be used, if false the general xsd * datatype in the place-holder will be used * @param typesSchemaLines collection of type XML lines to add to for any new types * @param externalizableContentUrl URL to set for externalizable.static.content.url token * @param builtTypes - Set of attribute names for which a schema validation type has been built * @throws IOException thrown for any read/write errors encountered */ protected static void buildSchemaFile(File buildSchemFile, String outSchemaFilePathName, boolean useDataDictionaryValidation, Collection typesSchemaLines, String externalizableContentUrl, Set<String> builtTypes, boolean rebuildDDTypes) throws IOException { Collection buildSchemaLines = FileUtils.readLines(buildSchemFile); Collection outSchemaLines = new ArrayList(); int lineCount = 1; for (Iterator iterator = buildSchemaLines.iterator(); iterator.hasNext();) { if (LOG.isDebugEnabled()) { LOG.debug("Processing line " + lineCount + "of file " + buildSchemFile.getAbsolutePath()); } String buildLine = (String) iterator.next(); String outLine = buildLine; // check for externalizable.static.content.url token and replace if found if (StringUtils.contains(buildLine, "@externalizable.static.content.url@")) { outLine = StringUtils.replace(buildLine, "@externalizable.static.content.url@", externalizableContentUrl); } // check for validation place-holder and process if found else if (StringUtils.contains(buildLine, SCHEMA_FILE_DD_VALIDATION_PLACEHOLDER_BEGIN) && StringUtils.contains(buildLine, SCHEMA_FILE_DD_VALIDATION_PLACEHOLDER_END)) { String validationPlaceholder = StringUtils.substringBetween(buildLine, SCHEMA_FILE_DD_VALIDATION_PLACEHOLDER_BEGIN, SCHEMA_FILE_DD_VALIDATION_PLACEHOLDER_END); if (StringUtils.isBlank(validationPlaceholder)) { logAndThrowException(String.format("File %s line %s: validation placeholder cannot be blank", buildSchemFile.getAbsolutePath(), lineCount)); } if (LOG.isDebugEnabled()) { LOG.debug("Found dd validation placeholder: " + validationPlaceholder); } if (!StringUtils.contains(validationPlaceholder, ",")) { logAndThrowException(String.format( "File %s, line %s: Invalid format of placehoder value: %s, must contain a ',' seperating parts", buildSchemFile.getAbsolutePath(), lineCount, validationPlaceholder)); } outLine = processValidationPlaceholder(validationPlaceholder, buildLine, buildSchemFile.getAbsolutePath(), lineCount, useDataDictionaryValidation, typesSchemaLines, builtTypes, rebuildDDTypes); } outSchemaLines.add(outLine); lineCount++; } LOG.debug("Writing schema file to static directory"); File schemaFile = new File(outSchemaFilePathName); FileUtils.writeLines(schemaFile, outSchemaLines); }
From source file:org.kuali.kfs.sys.document.web.renderers.GroupTitleLineRenderer.java
/** * Oy, the big one...this one actually renders instead of returning the HTML in a String. This is because it's kind of complex * (and a likely target for future refactoring) * * @param pageContext the page contex to render to * @param parentTag the tag that is requesting all the rendering * @throws JspException thrown if something goes wrong *//*from w w w .j av a2 s . c o m*/ protected void renderUploadCell(PageContext pageContext, Tag parentTag) throws JspException { JspWriter out = pageContext.getOut(); if (canUpload()) { try { String hideImport = getHideImportName(); String showImport = getShowImportName(); String showLink = getShowLinkName(); String uploadDiv = getUploadDivName(); out.write("\n<SCRIPT type=\"text/javascript\">\n"); out.write("<!--\n"); out.write("\tfunction " + hideImport + "(showLinkId, uploadDivId) {\n"); out.write("\t\tdocument.getElementById(showLinkId).style.display=\"inline\";\n"); out.write("\t\tdocument.getElementById(uploadDivId).style.display=\"none\";\n"); out.write("\t}\n"); out.write("\tfunction " + showImport + "(showLinkId, uploadDivId) {\n"); out.write("\t\tdocument.getElementById(showLinkId).style.display=\"none\";\n"); out.write("\t\tdocument.getElementById(uploadDivId).style.display=\"inline\";\n"); out.write("\t}\n"); out.write("\tdocument.write(\n"); out.write("\t\t'<a id=\"" + showLink + "\" href=\"#\" onclick=\"" + showImport + "(\\\'" + showLink + "\\\',\\\'" + uploadDiv + "\\\');return false;\">' +\n"); out.write("\t\t'<img src=\"" + SpringContext.getBean(ConfigurationService.class) .getPropertyValueAsString("externalizable.images.url") + "tinybutton-importlines.gif\" title=\"import file\" alt=\"import file\"' +\n"); out.write("\t\t'width=\"72\" border=\"0\">' +\n"); out.write("\t\t'</a>' +\n"); out.write("\t\t'<div id=\"" + uploadDiv + "\" style=\"display:none;\" >' +\n"); out.write("\t\t'"); scriptFileTag.setPageContext(pageContext); scriptFileTag.setParent(parentTag); String index = StringUtils.substringBetween(getLineCollectionProperty(), "[", "]"); if (StringUtils.isNotBlank(index) && getLineCollectionProperty().contains("transactionEntries")) { scriptFileTag.setProperty(StringUtils.substringBeforeLast(getLineCollectionProperty(), ".") + "." + accountingLineGroupDefinition.getImportedLinePropertyPrefix() + "File"); } else { scriptFileTag .setProperty(accountingLineGroupDefinition.getImportedLinePropertyPrefix() + "File"); } scriptFileTag.doStartTag(); scriptFileTag.doEndTag(); out.write("' +\n"); out.write("\t\t'"); uploadButtonTag.setPageContext(pageContext); uploadButtonTag.setParent(parentTag); uploadButtonTag.setProperty("methodToCall.upload" + StringUtils.capitalize(accountingLineGroupDefinition.getImportedLinePropertyPrefix()) + "Lines" + "." + getLineCollectionProperty()); uploadButtonTag .setAlt("insert " + accountingLineGroupDefinition.getGroupLabel() + " accounting lines"); uploadButtonTag .setTitle("insert " + accountingLineGroupDefinition.getGroupLabel() + " accounting lines"); uploadButtonTag.doStartTag(); uploadButtonTag.doEndTag(); out.write("' +\n"); out.write("\t\t'"); cancelButtonTag.setPageContext(pageContext); cancelButtonTag.setParent(parentTag); cancelButtonTag.setAlt( "Cancel import of " + accountingLineGroupDefinition.getGroupLabel() + " accounting lines"); cancelButtonTag.setTitle( "Cancel import of " + accountingLineGroupDefinition.getGroupLabel() + " accounting lines"); cancelButtonTag.setOnclick( getHideImportName() + "(\\\'" + showLink + "\\\',\\\'" + uploadDiv + "\\\');return false;"); cancelButtonTag.doStartTag(); cancelButtonTag.doEndTag(); out.write("' +\n"); out.write("\t'</div>');\n"); out.write("\t//-->\n"); out.write("</SCRIPT>\n"); out.write("<NOSCRIPT>\n"); out.write("\tImport " + accountingLineGroupDefinition.getGroupLabel() + " lines\n"); noscriptFileTag.setPageContext(pageContext); noscriptFileTag.setParent(parentTag); noscriptFileTag.setProperty(accountingLineGroupDefinition.getImportedLinePropertyPrefix() + "File"); noscriptFileTag.doStartTag(); noscriptFileTag.doEndTag(); uploadButtonTag.doStartTag(); uploadButtonTag.doEndTag(); out.write("</NOSCRIPT>\n"); } catch (IOException ioe) { throw new JspException("Difficulty rendering accounting lines import upload", ioe); } } }
From source file:org.kuali.kfs.sys.web.struts.KualiAccountingDocumentActionBase.java
@Override public ActionForward performLookup(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // parse out the business object name from our methodToCall parameter String fullParameter = (String) request.getAttribute(KFSConstants.METHOD_TO_CALL_ATTRIBUTE); String boClassName = StringUtils.substringBetween(fullParameter, KFSConstants.METHOD_TO_CALL_BOPARM_LEFT_DEL, KFSConstants.METHOD_TO_CALL_BOPARM_RIGHT_DEL); if (!StringUtils.equals(boClassName, GeneralLedgerPendingEntry.class.getName())) { return super.performLookup(mapping, form, request, response); }/*from ww w . ja v a 2s . c om*/ String path = super.performLookup(mapping, form, request, response).getPath(); path = path.replaceFirst(KFSConstants.LOOKUP_ACTION, KFSConstants.GL_MODIFIED_INQUIRY_ACTION); return new ActionForward(path, true); }
From source file:org.kuali.kfs.sys.web.struts.KualiBalanceInquiryReportMenuAction.java
/** * Takes care of storing the action form in the user session and forwarding to the balance inquiry lookup action. * //from w w w. ja v a2s. co m * @param mapping * @param form * @param request * @param response * @return ActionForward * @throws Exception */ public ActionForward performBalanceInquiryLookup(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); // parse out the important strings from our methodToCall parameter String fullParameter = (String) request.getAttribute(KFSConstants.METHOD_TO_CALL_ATTRIBUTE); // parse out business object class name for lookup String boClassName = StringUtils.substringBetween(fullParameter, KFSConstants.METHOD_TO_CALL_BOPARM_LEFT_DEL, KFSConstants.METHOD_TO_CALL_BOPARM_RIGHT_DEL); if (StringUtils.isBlank(boClassName)) { throw new RuntimeException("Illegal call to perform lookup, no business object class name specified."); } // build the parameters for the lookup url Properties parameters = new Properties(); String conversionFields = StringUtils.substringBetween(fullParameter, KFSConstants.METHOD_TO_CALL_PARM1_LEFT_DEL, KFSConstants.METHOD_TO_CALL_PARM1_RIGHT_DEL); if (StringUtils.isNotBlank(conversionFields)) { parameters.put(KFSConstants.CONVERSION_FIELDS_PARAMETER, conversionFields); } // pass values from form that should be pre-populated on lookup search String parameterFields = StringUtils.substringBetween(fullParameter, KFSConstants.METHOD_TO_CALL_PARM2_LEFT_DEL, KFSConstants.METHOD_TO_CALL_PARM2_RIGHT_DEL); if (StringUtils.isNotBlank(parameterFields)) { String[] lookupParams = parameterFields.split(KFSConstants.FIELD_CONVERSIONS_SEPERATOR); for (int i = 0; i < lookupParams.length; i++) { String[] keyValue = lookupParams[i].split(KFSConstants.FIELD_CONVERSION_PAIR_SEPERATOR); // hard-coded passed value if (StringUtils.contains(keyValue[0], "'")) { parameters.put(keyValue[1], StringUtils.replace(keyValue[0], "'", "")); } // passed value should come from property else if (StringUtils.isNotBlank(request.getParameter(keyValue[0]))) { parameters.put(keyValue[1], request.getParameter(keyValue[0])); } } } // grab whether or not the "return value" link should be hidden or not String hideReturnLink = StringUtils.substringBetween(fullParameter, KFSConstants.METHOD_TO_CALL_PARM3_LEFT_DEL, KFSConstants.METHOD_TO_CALL_PARM3_RIGHT_DEL); if (StringUtils.isNotBlank(hideReturnLink)) { parameters.put(KFSConstants.HIDE_LOOKUP_RETURN_LINK, hideReturnLink); } // anchor, if it exists if (form instanceof KualiForm && StringUtils.isNotEmpty(((KualiForm) form).getAnchor())) { parameters.put(KFSConstants.LOOKUP_ANCHOR, ((KualiForm) form).getAnchor()); } // determine what the action path is String actionPath = StringUtils.substringBetween(fullParameter, KFSConstants.METHOD_TO_CALL_PARM4_LEFT_DEL, KFSConstants.METHOD_TO_CALL_PARM4_RIGHT_DEL); if (StringUtils.isBlank(actionPath)) { throw new IllegalStateException( "The \"actionPath\" attribute is an expected parameter for the <gl:balanceInquiryLookup> tag - it " + "should never be blank."); } // now add required parameters parameters.put(KFSConstants.DISPATCH_REQUEST_PARAMETER, "start"); parameters.put(KFSConstants.DOC_FORM_KEY, GlobalVariables.getUserSession().addObjectWithGeneratedKey(form)); parameters.put(KFSConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, boClassName); parameters.put(KFSConstants.RETURN_LOCATION_PARAMETER, basePath + mapping.getPath() + ".do"); String lookupUrl = UrlFactory.parameterizeUrl(basePath + "/" + actionPath, parameters); return new ActionForward(lookupUrl, true); }
From source file:org.kuali.kpme.tklm.time.docsearch.WorkAreaSearchableAttribute.java
@Override public List extractDocumentAttributes(ExtensionDefinition extensionDefinition, DocumentWithContent documentWithContent) { List<SearchableAttributeValue> searchableAttributeValues = new ArrayList<SearchableAttributeValue>(); String documentId = StringUtils.substringBetween(documentWithContent.getDocumentContent().toString(), "<string>", "</string>"); TimesheetDocument timesheetDocument = TkServiceLocator.getTimesheetService() .getTimesheetDocument(documentId); List<Long> workAreasIncluded = new ArrayList<Long>(); for (Assignment assign : timesheetDocument.getAllAssignments()) { if (!workAreasIncluded.contains(assign.getWorkArea())) { SearchableAttributeValue attValue = new SearchableAttributeLongValue(); attValue.setSearchableAttributeKey(WORK_AREA); attValue.setupAttributeValue(StringUtils.upperCase(assign.getWorkArea().toString())); searchableAttributeValues.add(attValue); workAreasIncluded.add(assign.getWorkArea()); }//from w w w . j a va 2s. c o m } return searchableAttributeValues; }
From source file:org.kuali.kra.budget.web.struts.action.BudgetExpensesAction.java
protected String getSelectedBudgetCategoryType(HttpServletRequest request) { String selectedCategoryTypeCode = ""; String parameterName = (String) request.getAttribute(KNSConstants.METHOD_TO_CALL_ATTRIBUTE); if (StringUtils.isNotBlank(parameterName)) { selectedCategoryTypeCode = StringUtils.substringBetween(parameterName, ".budgetCategoryTypeCode", "."); }//from w w w . j av a2 s. co m return selectedCategoryTypeCode; }