List of usage examples for org.apache.commons.lang StringUtils removeEnd
public static String removeEnd(String str, String remove)
Removes a substring only if it is at the end of a source string, otherwise returns the source string.
From source file:org.kuali.rice.krad.uif.util.ScriptUtils.java
/** * Converts a list of string to a valid js string array * //from w w w . j a va2 s. c o m * @param list list of Strings to be converted * @return String representing the js array */ public static String convertStringListToJsArray(List<String> list) { String array = "["; if (list != null) { for (String s : list) { array = array + "'" + s + "',"; } array = StringUtils.removeEnd(array, ","); } array = array + "]"; return array; }
From source file:org.kuali.rice.krad.uif.view.DefaultExpressionEvaluator.java
/** * {@inheritDoc}/*w w w . j a v a 2 s .c o m*/ */ @Override public String parseExpression(String exp, List<String> controlNames, Map<String, Object> context) { // clean up expression to ease parsing exp = exp.trim(); if (exp.startsWith("@{")) { exp = StringUtils.removeStart(exp, "@{"); if (exp.endsWith("}")) { exp = StringUtils.removeEnd(exp, "}"); } } // Clean up the expression for parsing consistency exp = StringUtils.replace(exp, "!=", " != "); exp = StringUtils.replace(exp, "==", " == "); exp = StringUtils.replace(exp, ">", " > "); exp = StringUtils.replace(exp, "<", " < "); exp = StringUtils.replace(exp, "<=", " <= "); exp = StringUtils.replace(exp, ">=", " >= "); exp = StringUtils.replace(exp, "&&", " && "); exp = StringUtils.replace(exp, "||", " || "); exp = StringUtils.replace(exp, " ", " "); exp = StringUtils.replace(exp, " )", ")"); exp = StringUtils.replace(exp, "( ", "("); exp = StringUtils.replace(exp, " ,", ","); Map<String, String> serverEvaluations = new HashMap<String, String>(); // Evaluate server side method calls and constants Matcher matcher = SERVER_EVALUATION_PATTERN.matcher(exp); while (matcher.find()) { String spelMethodCall = matcher.group(1); Object value = this.evaluateExpression(context, spelMethodCall); // Convert the value to expected js equivalent if (value == null) { serverEvaluations.put(spelMethodCall, "null"); } else if (value instanceof String) { serverEvaluations.put(spelMethodCall, "\"" + value + "\""); } else if (value instanceof Boolean || NumberUtils.isNumber(value.toString())) { serverEvaluations.put(spelMethodCall, value.toString()); } else { // Corner case, assume the object gives us something meaningful from toString, wrap in quotes serverEvaluations.put(spelMethodCall, "\"" + value.toString() + "\""); } } String conditionJs = exp; controlNames.addAll(findControlNamesInExpression(exp)); // Replace all known accepted strings with javascript equivalent conditionJs = conditionJs.replaceAll("\\s(?i:ne)\\s", " != ").replaceAll("\\s(?i:eq)\\s", " == ") .replaceAll("\\s(?i:gt)\\s", " > ").replaceAll("\\s(?i:lt)\\s", " < ") .replaceAll("\\s(?i:lte)\\s", " <= ").replaceAll("\\s(?i:gte)\\s", " >= ") .replaceAll("\\s(?i:and)\\s", " && ").replaceAll("\\s(?i:or)\\s", " || ") .replaceAll("\\s(?i:not)\\s", " != ").replaceAll("\\s(?i:null)\\s?", " '' ") .replaceAll("\\s?(?i:#empty)\\((.*?)\\)", "isValueEmpty($1)") .replaceAll("\\s?(?i:#listContains)\\((.*?)\\)", "listContains($1)") .replaceAll("\\s?(?i:#emptyList)\\((.*?)\\)", "emptyList($1)"); // Handle matches method conversion if (conditionJs.contains("matches")) { conditionJs = conditionJs.replaceAll("\\s+(?i:matches)\\s+'.*'", ".match(/" + "$0" + "/) != null "); conditionJs = conditionJs.replaceAll("\\(/\\s+(?i:matches)\\s+'", "(/"); conditionJs = conditionJs.replaceAll("'\\s*/\\)", "/)"); } for (String serverEvalToken : serverEvaluations.keySet()) { String evaluatedValue = serverEvaluations.get(serverEvalToken); conditionJs = conditionJs.replace(serverEvalToken, evaluatedValue); } List<String> removeControlNames = new ArrayList<String>(); List<String> addControlNames = new ArrayList<String>(); //convert property names to use coerceValue function and convert arrays to js arrays for (String propertyName : controlNames) { //array definitions are caught in controlNames because of the nature of the parse - convert them and remove if (propertyName.trim().startsWith("{") && propertyName.trim().endsWith("}")) { String array = propertyName.trim().replace('{', '['); array = array.replace('}', ']'); conditionJs = conditionJs.replace(propertyName, array); removeControlNames.add(propertyName); continue; } //handle not if (propertyName.startsWith("!")) { String actualPropertyName = StringUtils.removeStart(propertyName, "!"); conditionJs = conditionJs.replace(propertyName, "!coerceValue(\"" + actualPropertyName + "\")"); removeControlNames.add(propertyName); addControlNames.add(actualPropertyName); } else { conditionJs = conditionJs.replace(propertyName, "coerceValue(\"" + propertyName + "\")"); } } controlNames.removeAll(removeControlNames); controlNames.addAll(addControlNames); // Simple short circuit logic below boolean complexCondition = conditionJs.contains(" (") || conditionJs.startsWith("("); // Always remove AND'ed true if (conditionJs.contains("true && ") || conditionJs.contains(" && true")) { conditionJs = conditionJs.replace(" && true", ""); conditionJs = conditionJs.replace("true && ", ""); } // An AND'ed false, or an OR'ed true, or true/false by themselves will always evaluate to the same outcome // in a simple condition, so no need for client evaluation (server will handle the evaluation) if (!complexCondition && (conditionJs.contains("false &&")) || conditionJs.contains("&& false") || conditionJs.contains("|| true") || conditionJs.contains("true ||") || conditionJs.equals("true") || conditionJs.equals("false")) { conditionJs = ""; } return conditionJs; }
From source file:org.kuali.rice.krad.uif.view.DefaultExpressionEvaluator.java
/** * Used internally by parseExpression to evalute if the current stack is a property * name (ie, will be a control on the form) * * @param stack/*from w w w .j a v a 2 s .c o m*/ * @param controlNames */ protected void evaluateCurrentStack(String stack, List<String> controlNames) { if (StringUtils.isBlank(stack)) { return; } // These are special matches that can be directly replaced to a js equivalent (so skip evaluation of these) if (!(stack.equals("==") || stack.equals("!=") || stack.equals(">") || stack.equals("<") || stack.equals(">=") || stack.equals("<=") || stack.equalsIgnoreCase("ne") || stack.equalsIgnoreCase("eq") || stack.equalsIgnoreCase("gt") || stack.equalsIgnoreCase("lt") || stack.equalsIgnoreCase("lte") || stack.equalsIgnoreCase("gte") || stack.equalsIgnoreCase("matches") || stack.equalsIgnoreCase("null") || stack.equalsIgnoreCase("false") || stack.equalsIgnoreCase("true") || stack.equalsIgnoreCase("and") || stack.equalsIgnoreCase("or") || stack.startsWith("#") || stack.equals("!") || stack.startsWith("'") || stack.endsWith("'"))) { boolean isNumber = NumberUtils.isNumber(stack); // If it is not a number must be check to see if it is a name of a control if (!(isNumber)) { //correct argument of a custom function ending in comma if (StringUtils.endsWith(stack, ",")) { stack = StringUtils.removeEnd(stack, ",").trim(); } if (!controlNames.contains(stack)) { controlNames.add(stack); } } } }
From source file:org.kuali.rice.krad.uif.view.DefaultExpressionEvaluator.java
/** * {@inheritDoc}/* w ww .j ava 2 s .co m*/ */ @Override public Object evaluateExpression(Map<String, Object> evaluationParameters, String expressionStr) { Object result = null; // if expression contains placeholders remove before evaluating if (StringUtils.startsWith(expressionStr, UifConstants.EL_PLACEHOLDER_PREFIX) && StringUtils.endsWith(expressionStr, UifConstants.EL_PLACEHOLDER_SUFFIX)) { expressionStr = StringUtils.removeStart(expressionStr, UifConstants.EL_PLACEHOLDER_PREFIX); expressionStr = StringUtils.removeEnd(expressionStr, UifConstants.EL_PLACEHOLDER_SUFFIX); } try { Expression expression = retrieveCachedExpression(expressionStr); if (evaluationParameters != null) { evaluationContext.setVariables(evaluationParameters); } result = expression.getValue(evaluationContext); } catch (Exception e) { LOG.error("Exception evaluating expression: " + expressionStr); throw new RuntimeException("Exception evaluating expression: " + expressionStr, e); } return result; }
From source file:org.kuali.rice.krad.uif.view.DefaultExpressionEvaluator.java
/** * {@inheritDoc}//from w w w . j av a 2 s . co m */ @Override public void evaluatePropertyExpression(View view, Map<String, Object> evaluationParameters, UifDictionaryBean expressionConfigurable, String propertyName, boolean removeExpression) { Map<String, String> propertyExpressions = expressionConfigurable.getPropertyExpressions(); if ((propertyExpressions == null) || !propertyExpressions.containsKey(propertyName)) { return; } String expression = propertyExpressions.get(propertyName); // check whether expression should be evaluated or property should retain the expression if (CopyUtils.fieldHasAnnotation(expressionConfigurable.getClass(), propertyName, KeepExpression.class)) { // set expression as property value to be handled by the component ObjectPropertyUtils.setPropertyValue(expressionConfigurable, propertyName, expression); return; } Object propertyValue = null; // replace binding prefixes (lp, dp, fp) in expression before evaluation String adjustedExpression = replaceBindingPrefixes(view, expressionConfigurable, expression); // determine whether the expression is a string template, or evaluates to another object type if (StringUtils.startsWith(adjustedExpression, UifConstants.EL_PLACEHOLDER_PREFIX) && StringUtils.endsWith(adjustedExpression, UifConstants.EL_PLACEHOLDER_SUFFIX) && (StringUtils.countMatches(adjustedExpression, UifConstants.EL_PLACEHOLDER_PREFIX) == 1)) { propertyValue = evaluateExpression(evaluationParameters, adjustedExpression); } else { // treat as string template propertyValue = evaluateExpressionTemplate(evaluationParameters, adjustedExpression); } // if property name has the special indicator then we need to add the expression result to the property // value instead of replace if (StringUtils.endsWith(propertyName, ExpressionEvaluator.EMBEDDED_PROPERTY_NAME_ADD_INDICATOR)) { StringUtils.removeEnd(propertyName, ExpressionEvaluator.EMBEDDED_PROPERTY_NAME_ADD_INDICATOR); Collection collectionValue = ObjectPropertyUtils.getPropertyValue(expressionConfigurable, propertyName); if (collectionValue == null) { throw new RuntimeException("Property name: " + propertyName + " with collection type was not initialized. Cannot add expression result"); } collectionValue.add(propertyValue); } else { ObjectPropertyUtils.setPropertyValue(expressionConfigurable, propertyName, propertyValue); } if (removeExpression) { propertyExpressions.remove(propertyName); } }
From source file:org.kuali.rice.krad.uif.widget.Inquiry.java
/** * Builds the inquiry link based on the given inquiry class and parameters * * @param dataObject parent object that contains the data (used to pull inquiry * parameters)//from w ww .ja v a 2 s.c o m * @param propertyName name of the property the inquiry is set on * @param inquiryObjectClass class of the object the inquiry should point to * @param inquiryParams map of key field mappings for the inquiry */ @SuppressWarnings("deprecation") public void buildInquiryLink(Object dataObject, String propertyName, Class<?> inquiryObjectClass, Map<String, String> inquiryParams) { MessageService messageService = KRADServiceLocatorWeb.getMessageService(); Properties urlParameters = new Properties(); Map<String, String> inquiryKeyValues = new HashMap<String, String>(); urlParameters.setProperty(UifParameters.DATA_OBJECT_CLASS_NAME, inquiryObjectClass.getName()); urlParameters.setProperty(UifParameters.METHOD_TO_CALL, UifConstants.MethodToCallNames.START); if (StringUtils.isNotBlank(this.viewName)) { urlParameters.setProperty(UifParameters.VIEW_NAME, this.viewName); } // add inquiry specific parms to url if (getInquiryLink().getLightBox() != null) { getInquiryLink().getLightBox().setAddAppParms(true); } // configure inquiry when read only if (isParentReadOnly()) { for (Entry<String, String> inquiryParameter : inquiryParams.entrySet()) { String parameterName = inquiryParameter.getKey(); Object parameterValue = ObjectPropertyUtils.getPropertyValue(dataObject, parameterName); // TODO: need general format util that uses spring if (parameterValue == null) { parameterValue = ""; } else if (parameterValue instanceof java.sql.Date) { if (org.kuali.rice.core.web.format.Formatter.findFormatter(parameterValue.getClass()) != null) { org.kuali.rice.core.web.format.Formatter formatter = org.kuali.rice.core.web.format.Formatter .getFormatter(parameterValue.getClass()); parameterValue = formatter.format(parameterValue); } } else { parameterValue = ObjectPropertyUtils.getPropertyValueAsText(dataObject, parameterName); } // Encrypt value if it is a field that has restriction that prevents a value from being shown to // user, because we don't want the browser history to store the restricted attributes value in the URL if (KRADServiceLocatorWeb.getDataObjectAuthorizationService() .attributeValueNeedsToBeEncryptedOnFormsAndLinks(inquiryObjectClass, inquiryParameter.getValue())) { try { parameterValue = CoreApiServiceLocator.getEncryptionService().encrypt(parameterValue); } catch (GeneralSecurityException e) { throw new RuntimeException( "Exception while trying to encrypted value for inquiry framework.", e); } } // add inquiry parameter to URL urlParameters.put(inquiryParameter.getValue(), parameterValue); inquiryKeyValues.put(inquiryParameter.getValue(), parameterValue.toString()); } /* build inquiry URL */ String inquiryUrl; // check for EBOs for an alternate inquiry URL ModuleService responsibleModuleService = KRADServiceLocatorWeb.getKualiModuleService() .getResponsibleModuleService(inquiryObjectClass); if (responsibleModuleService != null && responsibleModuleService.isExternalizable(inquiryObjectClass)) { inquiryUrl = responsibleModuleService.getExternalizableDataObjectInquiryUrl(inquiryObjectClass, urlParameters); } else { inquiryUrl = UrlFactory.parameterizeUrl(getBaseInquiryUrl(), urlParameters); } getInquiryLink().setHref(inquiryUrl); // set inquiry title getInquiryLink().setTitle(createTitleText(inquiryObjectClass, inquiryKeyValues)); setRender(true); } // configure direct inquiry when editable else { // Direct inquiry String inquiryUrl = UrlFactory.parameterizeUrl(getBaseInquiryUrl(), urlParameters); StringBuilder paramMapStringBuilder = new StringBuilder(); // Build parameter string using the actual names of the fields as on the html page for (Entry<String, String> inquiryParameter : inquiryParams.entrySet()) { String inquiryParameterFrom = inquiryParameter.getKey(); if (adjustInquiryParameters && (fieldBindingInfo != null)) { inquiryParameterFrom = fieldBindingInfo.getPropertyAdjustedBindingPath(inquiryParameterFrom); } ViewLifecycle viewLifecycle = ViewLifecycle.getActiveLifecycle(); // Make sure our inquiry parameters are included as a rendered property path if (!viewLifecycle.getViewPostMetadata().getAllRenderedPropertyPaths() .contains(inquiryParameterFrom.toString())) { setRender(false); return; } paramMapStringBuilder.append(inquiryParameterFrom); paramMapStringBuilder.append(":"); paramMapStringBuilder.append(inquiryParameter.getValue()); paramMapStringBuilder.append(","); } String paramMapString = StringUtils.removeEnd(paramMapStringBuilder.toString(), ","); // Check if lightbox is set. Get lightbox options. String lightBoxOptions = ""; boolean lightBoxShow = (getInquiryLink().getLightBox() != null); if (lightBoxShow) { lightBoxOptions = getInquiryLink().getLightBox().getTemplateOptionsJSString(); } else { String title = this.getTitle(); if (StringUtils.isNotBlank(title)) { this.setTitle(title + " - " + messageService.getMessageText("accessibility.link.opensTab")); } else { this.setTitle(messageService.getMessageText("accessibility.link.opensTab")); } } // Create onlick script to open the inquiry window on the click event // of the direct inquiry StringBuilder onClickScript = new StringBuilder("showDirectInquiry(\""); onClickScript.append(inquiryUrl); onClickScript.append("\", \""); onClickScript.append(paramMapString); onClickScript.append("\", "); onClickScript.append(lightBoxShow); onClickScript.append(", "); onClickScript.append(lightBoxOptions); onClickScript.append(");"); directInquiryAction.setPerformDirtyValidation(false); directInquiryAction.setActionScript(onClickScript.toString()); setRender(true); } }
From source file:org.kuali.rice.krad.uif.widget.RichTable.java
/** * Builds the footer callback template option for column totals * * @param collectionGroup the collection group *///from w ww .j a v a 2 s . c o m private void setTotalOptions(CollectionGroup collectionGroup) { LayoutManager layoutManager = collectionGroup.getLayoutManager(); if (layoutManager instanceof TableLayoutManager) { List<String> totalColumns = ((TableLayoutManager) layoutManager).getColumnsToCalculate(); if (totalColumns.size() > 0) { String array = "["; for (String i : totalColumns) { array = array + i + ","; } array = StringUtils.removeEnd(array, ","); array = array + "]"; templateOptions.put(UifConstants.TableToolsKeys.FOOTER_CALLBACK, "function (nRow, aaData, iStart, iEnd, aiDisplay) {initializeTotalsFooter (nRow, aaData, iStart, iEnd, aiDisplay, " + array + " )}"); } } }
From source file:org.kuali.rice.krad.uif.widget.RichTable.java
/** * Builds column options for sorting// w w w. ja va2 s . co m * * @param collectionGroup */ protected void buildTableOptions(CollectionGroup collectionGroup) { checkMutable(false); LayoutManager layoutManager = collectionGroup.getLayoutManager(); final boolean useServerPaging = collectionGroup.isUseServerPaging(); if (templateOptions.isEmpty()) { setTemplateOptions(new HashMap<String, String>()); } // if sub collection exists, don't allow the table sortable if (!collectionGroup.getSubCollections().isEmpty()) { setDisableTableSort(true); } if (!isDisableTableSort()) { // if rendering add line, skip that row from col sorting if (collectionGroup.isRenderAddLine() && !Boolean.TRUE.equals(collectionGroup.getReadOnly()) && !((layoutManager instanceof TableLayoutManager) && ((TableLayoutManager) layoutManager).isSeparateAddLine())) { templateOptions.put(UifConstants.TableToolsKeys.SORT_SKIP_ROWS, "[" + UifConstants.TableToolsValues.ADD_ROW_DEFAULT_INDEX + "]"); } StringBuilder tableColumnOptions = new StringBuilder("["); int colIndex = 0; int actionIndex = UifConstants.TableLayoutValues.ACTIONS_COLUMN_RIGHT_INDEX; boolean actionFieldVisible = collectionGroup.isRenderLineActions() && !Boolean.TRUE.equals(collectionGroup.getReadOnly()); if (layoutManager instanceof TableLayoutManager) { actionIndex = ((TableLayoutManager) layoutManager).getActionColumnIndex(); } if (actionIndex == UifConstants.TableLayoutValues.ACTIONS_COLUMN_LEFT_INDEX && actionFieldVisible) { String options = constructTableColumnOptions(colIndex, false, useServerPaging, null, null); tableColumnOptions.append(options + ","); colIndex++; } // handle sequence field if (layoutManager instanceof TableLayoutManager && ((TableLayoutManager) layoutManager).isRenderSequenceField()) { Class<?> dataTypeClass = Number.class; if (((TableLayoutManager) layoutManager).getSequenceFieldPrototype() instanceof DataField) { DataField dataField = (DataField) ((TableLayoutManager) layoutManager) .getSequenceFieldPrototype(); dataTypeClass = ObjectPropertyUtils.getPropertyType(collectionGroup.getCollectionObjectClass(), dataField.getPropertyName()); // check to see if field has custom sort type if (dataField.getSortAs() != null && dataField.getSortAs().length() > 0) { if (dataField.getSortAs().equals(UifConstants.TableToolsValues.DATE)) { dataTypeClass = java.sql.Date.class; } else if (dataField.getSortAs().equals(UifConstants.TableToolsValues.NUMERIC)) { dataTypeClass = Number.class; } else if (dataField.getSortAs().equals(UifConstants.TableToolsValues.STRING)) { dataTypeClass = String.class; } } } // don't allow sorting of sequence field - why? // auto sequence column is never sortable tableColumnOptions.append("{" + sortable(false) + "," + sortType(getSortType(dataTypeClass)) + "," + sortDataType(UifConstants.TableToolsValues.DOM_TEXT) + mData(useServerPaging, colIndex) + "," + targets(colIndex) + "},"); colIndex++; if (actionIndex == 2 && actionFieldVisible) { String options = constructTableColumnOptions(colIndex, false, useServerPaging, null, null); tableColumnOptions.append(options + ","); colIndex++; } } // skip select field if enabled if (collectionGroup.isIncludeLineSelectionField()) { String options = constructTableColumnOptions(colIndex, false, useServerPaging, null, null); tableColumnOptions.append(options + ","); colIndex++; } // if data dictionary defines aoColumns, copy here and skip default sorting/visibility behaviour if (!StringUtils.isEmpty(templateOptions.get(UifConstants.TableToolsKeys.AO_COLUMNS))) { // get the contents of the JS array string String jsArray = templateOptions.get(UifConstants.TableToolsKeys.AO_COLUMNS); int startBrace = StringUtils.indexOf(jsArray, "["); int endBrace = StringUtils.lastIndexOf(jsArray, "]"); tableColumnOptions.append(StringUtils.substring(jsArray, startBrace + 1, endBrace) + ","); if (actionFieldVisible && (actionIndex == -1 || actionIndex >= colIndex)) { String options = constructTableColumnOptions(colIndex, false, useServerPaging, null, null); tableColumnOptions.append(options); } else { tableColumnOptions = new StringBuilder( StringUtils.removeEnd(tableColumnOptions.toString(), ",")); } tableColumnOptions.append("]"); templateOptions.put(UifConstants.TableToolsKeys.AO_COLUMNS, tableColumnOptions.toString()); } else if (!StringUtils.isEmpty(templateOptions.get(UifConstants.TableToolsKeys.AO_COLUMN_DEFS)) && forceAoColumnDefsOverride) { String jsArray = templateOptions.get(UifConstants.TableToolsKeys.AO_COLUMN_DEFS); int startBrace = StringUtils.indexOf(jsArray, "["); int endBrace = StringUtils.lastIndexOf(jsArray, "]"); tableColumnOptions.append(StringUtils.substring(jsArray, startBrace + 1, endBrace) + ","); if (actionFieldVisible && (actionIndex == -1 || actionIndex >= colIndex)) { String options = constructTableColumnOptions(colIndex, false, useServerPaging, null, null); tableColumnOptions.append(options); } else { tableColumnOptions = new StringBuilder( StringUtils.removeEnd(tableColumnOptions.toString(), ",")); } tableColumnOptions.append("]"); templateOptions.put(UifConstants.TableToolsKeys.AO_COLUMN_DEFS, tableColumnOptions.toString()); } else if (layoutManager instanceof TableLayoutManager) { List<Field> rowFields = ((TableLayoutManager) layoutManager).getFirstRowFields(); // build column defs from the the first row of the table for (Component component : rowFields) { if (actionFieldVisible && colIndex + 1 == actionIndex) { String options = constructTableColumnOptions(colIndex, false, useServerPaging, null, null); tableColumnOptions.append(options + ","); colIndex++; } // for FieldGroup, get the first field from that group if (component instanceof FieldGroup) { component = ((FieldGroup) component).getItems().get(0); } if (component instanceof DataField) { DataField field = (DataField) component; // if a field is marked as invisible in hiddenColumns, append options and skip sorting if (getHiddenColumns() != null && getHiddenColumns().contains(field.getPropertyName())) { tableColumnOptions.append("{" + visible(false) + "," + mData(useServerPaging, colIndex) + targets(colIndex) + "},"); } else if (getSortableColumns() != null && !getSortableColumns().isEmpty()) { // if specified as a column as sortable then add it if (getSortableColumns().contains(field.getPropertyName())) { tableColumnOptions .append(getDataFieldColumnOptions(colIndex, collectionGroup, field) + ","); } else { // else designate it as not sortable tableColumnOptions.append("{" + sortable(false) + "," + mData(useServerPaging, colIndex) + targets(colIndex) + "},"); } } else { // sortable columns not defined String options = getDataFieldColumnOptions(colIndex, collectionGroup, field); tableColumnOptions.append(options + ","); } colIndex++; } else if (component instanceof MessageField) { if (component.getDataAttributes() != null && UifConstants.RoleTypes.ROW_GROUPING .equals(component.getDataAttributes().get(UifConstants.DataAttributes.ROLE))) { // Grouping column is never shown, so skip tableColumnOptions.append("{" + visible(false) + "," + mData(useServerPaging, colIndex) + targets(colIndex) + "},"); } else { String options = constructTableColumnOptions(colIndex, true, useServerPaging, String.class, UifConstants.TableToolsValues.DOM_TEXT); tableColumnOptions.append(options + ","); } colIndex++; } else if (component instanceof LinkField) { LinkField linkField = (LinkField) component; Class<?> dataTypeClass = String.class; // check to see if field has custom sort type if (linkField.getSortAs() != null && linkField.getSortAs().length() > 0) { if (linkField.getSortAs().equals(UifConstants.TableToolsValues.DATE)) { dataTypeClass = java.sql.Date.class; } else if (linkField.getSortAs().equals(UifConstants.TableToolsValues.NUMERIC)) { dataTypeClass = Number.class; } else if (linkField.getSortAs().equals(UifConstants.TableToolsValues.STRING)) { dataTypeClass = String.class; } } String options = constructTableColumnOptions(colIndex, true, useServerPaging, dataTypeClass, UifConstants.TableToolsValues.DOM_TEXT); tableColumnOptions.append(options + ","); colIndex++; } else { String options = constructTableColumnOptions(colIndex, false, useServerPaging, null, null); tableColumnOptions.append(options + ","); colIndex++; } } if (actionFieldVisible && (actionIndex == -1 || actionIndex >= colIndex)) { String options = constructTableColumnOptions(colIndex, false, useServerPaging, null, null); tableColumnOptions.append(options); } else { tableColumnOptions = new StringBuilder( StringUtils.removeEnd(tableColumnOptions.toString(), ",")); } // merge the aoColumnDefs passed in if (!StringUtils.isEmpty(templateOptions.get(UifConstants.TableToolsKeys.AO_COLUMN_DEFS))) { String origAoOptions = templateOptions.get(UifConstants.TableToolsKeys.AO_COLUMN_DEFS).trim(); origAoOptions = StringUtils.removeStart(origAoOptions, "["); origAoOptions = StringUtils.removeEnd(origAoOptions, "]"); tableColumnOptions.append("," + origAoOptions); } tableColumnOptions.append("]"); templateOptions.put(UifConstants.TableToolsKeys.AO_COLUMN_DEFS, tableColumnOptions.toString()); } } }
From source file:org.kuali.rice.krad.uif.widget.RichTable.java
/** * Add row content passed from table ftl to the aaData array by converting and escaping the * content to an object (in an array of objects) in JSON format * * <p>/*from ww w.j a v a 2s . c o m*/ * The data in aaData is expected to be consumed by a call by the datatables plugin using * sAjaxSource or aaData. The addRowToTableData generation call is additive must be made per a * row in the ftl. * </p> * * @param row the row of content with each cell content surrounded by the @quot@ token and * followed by a comma */ public void addRowToTableData(String row) { String escape = ""; if (templateOptions.isEmpty()) { setTemplateOptions(new HashMap<String, String>()); } // if nestedLevel is set add the appropriate amount of escape characters per a level of nesting for (int i = 0; i < nestedLevel && forceLocalJsonData; i++) { escape = escape + "\\"; } // remove newlines and replace quotes and single quotes with unicode characters row = row.trim().replace("\"", escape + "\\u0022").replace("'", escape + "\\u0027").replace("\n", "") .replace("\r", ""); // remove hanging comma row = StringUtils.removeEnd(row, ","); // replace all quote placeholders with actual quote characters row = row.replace(KRADConstants.QUOTE_PLACEHOLDER, "\""); row = "{" + row + "}"; // if first call create aaData and force defer render option, otherwise append if (StringUtils.isBlank(aaData)) { aaData = "[" + row + "]"; if (templateOptions.get(UifConstants.TableToolsKeys.DEFER_RENDER) == null) { //make sure deferred rendering is forced if not explicitly set templateOptions.put(UifConstants.TableToolsKeys.DEFER_RENDER, UifConstants.TableToolsValues.TRUE); } } else if (StringUtils.isNotBlank(row)) { aaData = aaData.substring(0, aaData.length() - 1) + "," + row + "]"; } //force json data use if forceLocalJsonData flag is set if (forceLocalJsonData) { templateOptions.put(UifConstants.TableToolsKeys.AA_DATA, aaData); } }
From source file:org.kuali.rice.krad.uif.widget.TableTools.java
/** * Builds column options for sorting//from w w w . java2 s .c om * * @param collectionGroup */ protected void buildTableSortOptions(CollectionGroup collectionGroup) { LayoutManager layoutManager = collectionGroup.getLayoutManager(); // if sub collection exists, don't allow the table sortable if (!collectionGroup.getSubCollections().isEmpty()) { setDisableTableSort(true); } if (!isDisableTableSort()) { // if rendering add line, skip that row from col sorting if (collectionGroup.isRenderAddLine() && !collectionGroup.isReadOnly()) { getComponentOptions().put(UifConstants.TableToolsKeys.SORT_SKIP_ROWS, "[" + UifConstants.TableToolsValues.ADD_ROW_DEFAULT_INDEX + "]"); } StringBuffer tableToolsColumnOptions = new StringBuffer("["); if (layoutManager instanceof TableLayoutManager && ((TableLayoutManager) layoutManager).isRenderSequenceField()) { tableToolsColumnOptions.append(" null ,"); } // skip select field if enabled if (collectionGroup.isRenderSelectField()) { String colOptions = constructTableColumnOptions(false, null, null); tableToolsColumnOptions.append(colOptions + " , "); } // TODO: does this handle multiple rows correctly? for (Component component : collectionGroup.getItems()) { // For FieldGroup, get the first field from that group if (component instanceof FieldGroup) { component = ((FieldGroup) component).getItems().get(0); } if (component instanceof AttributeField) { AttributeField field = (AttributeField) component; String sortType = null; if (collectionGroup.isReadOnly() || (field.getControl() == null)) { sortType = UifConstants.TableToolsValues.DOM_TEXT; } else if (field.getControl() instanceof TextControl) { sortType = UifConstants.TableToolsValues.DOM_TEXT; } else if (field.getControl() instanceof SelectControl) { sortType = UifConstants.TableToolsValues.DOM_SELECT; } else if (field.getControl() instanceof CheckboxControl || field.getControl() instanceof CheckboxGroupControl) { sortType = UifConstants.TableToolsValues.DOM_CHECK; } else if (field.getControl() instanceof RadioGroupControl) { sortType = UifConstants.TableToolsValues.DOM_RADIO; } Class dataTypeClass = ObjectPropertyUtils.getPropertyType( collectionGroup.getCollectionObjectClass(), ((AttributeField) component).getPropertyName()); String colOptions = constructTableColumnOptions(true, dataTypeClass, sortType); tableToolsColumnOptions.append(colOptions + " , "); } else { String colOptions = constructTableColumnOptions(false, null, null); tableToolsColumnOptions.append(colOptions + " , "); } } if (collectionGroup.isRenderLineActions()) { String colOptions = constructTableColumnOptions(false, null, null); tableToolsColumnOptions.append(colOptions); } else { tableToolsColumnOptions = new StringBuffer( StringUtils.removeEnd(tableToolsColumnOptions.toString(), ", ")); } tableToolsColumnOptions.append("]"); getComponentOptions().put(UifConstants.TableToolsKeys.AO_COLUMNS, tableToolsColumnOptions.toString()); } }