List of usage examples for org.apache.commons.lang StringUtils substring
public static String substring(String str, int start, int end)
Gets a substring from the specified String avoiding exceptions.
From source file:de.iai.ilcd.model.flow.Flow.java
/** * Apply cache fields for flow, those are: * <ul>//from w w w . ja v a 2 s.c om * <li>{@link #getReferenceProperty()}</li> * <li>{@link FlowPropertyDescription#getDefaultUnit() default unit} of {@link #getReferenceProperty()}</li> * </ul> */ @Override @PrePersist protected void applyDataSetCache() { super.applyDataSetCache(); if (this.referenceProperty != null) { if (this.referenceProperty.getFlowPropertyName() != null) { this.referencePropertyCache = StringUtils .substring(this.referenceProperty.getFlowPropertyName().getDefaultValue(), 0, 20); } else { this.referencePropertyCache = null; } this.referencePropertyUnitCache = StringUtils.substring(this.referenceProperty.getDefaultUnit(), 0, 10); } else { this.referencePropertyCache = null; this.referencePropertyUnitCache = null; } }
From source file:de.iai.ilcd.model.common.DataSet.java
/** * Write the {@link #getName() name} default value * to the cache field.//from ww w. j ava 2 s. co m */ @PrePersist protected void applyDataSetCache() { this.nameCache = StringUtils.substring(this.getNameAsStringForCache(), 0, 255); if (this.classification != null) { this.classificationCache = StringUtils.substring(this.getClassificationHierarchyAsStringForCache(), 0, 100); } else { this.classificationCache = null; } }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopExportDisplay.java
protected String getFileExt(String fileName) { int i = fileName.lastIndexOf('.'); if (i > -1) return StringUtils.substring(fileName, i + 1, i + 20); else/*from www . ja va2s .com*/ return ""; }
From source file:com.haulmont.chile.core.model.utils.InstanceUtils.java
/** * Parse a name pattern defined by {@link NamePattern} annotation. * @param metaClass entity meta-class//w w w .j a v a 2 s . c o m * @return record containing the name pattern properties, or null if the @NamePattern is not defined for the meta-class */ @Nullable public static NamePatternRec parseNamePattern(MetaClass metaClass) { Map attributes = (Map) metaClass.getAnnotations().get(NamePattern.class.getName()); if (attributes == null) return null; String pattern = (String) attributes.get("value"); if (StringUtils.isBlank(pattern)) return null; int pos = pattern.indexOf("|"); if (pos < 0) throw new DevelopmentException("Invalid name pattern: " + pattern); String format = StringUtils.substring(pattern, 0, pos); String trimmedFormat = format.trim(); String methodName = trimmedFormat.startsWith("#") ? trimmedFormat.substring(1) : null; String fieldsStr = StringUtils.substring(pattern, pos + 1); String[] fields = INSTANCE_NAME_SPLIT_PATTERN.split(fieldsStr); return new NamePatternRec(format, methodName, fields); }
From source file:info.magnolia.templating.jsp.taglib.SearchResultSnippetTag.java
/** * Extract a collection of snippets from any paragraph in the given page. * @return a collection of Strings.//from w ww . j a v a2 s . c om * @todo avoid overlapping snippets (use regexp insted of simple indexOfs) * @todo only extract snippets from user-configured properties * @todo abbreviate on whitespace and puntuation, detect start of sentences * @todo replace ampersand in regexp * @todo break methods and write junits */ public Collection getSnippets() { log.debug("collecting snippets"); Collection snippets = new ArrayList(); String[] searchTerms = StringUtils.split(this.query); try { Iterator<Node> iterator = NodeUtil.getNodes(this.page, NodeTypes.ContentNode.NAME).iterator(); outer: while (iterator.hasNext()) { Node paragraphCollection = iterator.next(); Iterator<Node> parIterator = NodeUtil.getNodes(paragraphCollection, NodeTypes.ContentNode.NAME) .iterator(); while (parIterator.hasNext()) { Node paragraph = parIterator.next(); log.debug("Iterating on paragraph {}", paragraph); Iterator dataIterator = paragraph.getProperties(); while (dataIterator.hasNext()) { Property property = (Property) dataIterator.next(); if (property.getType() != PropertyType.BINARY) { String resultString = property.getString(); log.debug("Iterating on property {}", property.getName()); log.debug("Property value is {}", resultString); // a quick and buggy way to avoid configuration properties, we should allow the user to // configure a list of nodeData to search for... if (resultString.length() < 20) { continue; } for (int j = 0; j < searchTerms.length; j++) { String searchTerm = StringUtils.lowerCase(searchTerms[j]); // exclude keywords and words with less than 2 chars if (!ArrayUtils.contains(new String[] { "and", "or" }, searchTerm) && searchTerm.length() > 2) { log.debug("Looking for search term [{}] in [{}]", searchTerm, resultString); // first check, avoid using heavy string replaceAll operations if the search term is not // there if (!StringUtils.contains(resultString.toLowerCase(), searchTerm)) { continue; } // strips out html tags using a regexp resultString = stripHtmlTags(resultString); // only get first matching keyword int pos = resultString.toLowerCase().indexOf(searchTerm); if (pos > -1) { int posEnd = pos + searchTerm.length(); int from = (pos - chars / 2); if (from < 0) { from = 0; } int to = from + chars; if (to > resultString.length()) { to = resultString.length(); } StringBuffer snippet = new StringBuffer(); snippet.append(StringUtils.substring(resultString, from, pos)); snippet.append("<strong>"); snippet.append(StringUtils.substring(resultString, pos, posEnd)); snippet.append("</strong>"); snippet.append(StringUtils.substring(resultString, posEnd, to)); if (from > 0) { snippet.insert(0, "... "); } if (to < resultString.length()) { snippet.append("... "); } log.debug("Search term found, adding snippet {}", snippet); snippets.add(snippet); if (snippets.size() >= this.maxSnippets) { log.debug("Maximum number of snippets ({}) reached, exiting", Integer.toString(this.maxSnippets)); break outer; } } } } } } } } return snippets; } catch (Exception e) { log.error(e.getMessage(), e); return null; } }
From source file:com.google.gdt.eclipse.designer.util.GwtInvocationEvaluatorInterceptor.java
/** * Support for evaluating <code>com.google.gwt.view.client.Column</code> instances. * /* w ww .j a v a 2s . c om*/ * @return the instance of <code>TextColumn</code>. */ private Object getColumnFake(EvaluationContext context, ITypeBinding typeBinding) throws Exception { String columnText; { String columnValueTypeName = getColumnValueTypeName(typeBinding); String shortTypeName = CodeUtils.getShortClass(columnValueTypeName); columnText = "<" + StringUtils.substring(shortTypeName, 0, 20) + ">"; } // create TextColumn ClassLoader classLoader = context.getClassLoader(); return createTextColumn(classLoader, columnText); }
From source file:com.hangum.tadpole.rdb.erd.core.dnd.TableTransferDropTargetListener.java
/** * painting model /*from ww w . j a va2 s. c o m*/ * * @param nextTableX * @param nextTableY * @param arryTables * @param mapTable */ private void paintingModel(int nextTableX, int nextTableY, String[] arryTables, Map<String, List<TableColumnDAO>> mapTable) { Rectangle prevRectangle = null; int originalX = nextTableX; int intCount = 1; for (String strTable : arryTables) { String[] arryTable = StringUtils.splitByWholeSeparator(strTable, PublicTadpoleDefine.DELIMITER); if (arryTable.length == 0) continue; String tableName = arryTable[1]; String refTableNames = "'" + tableName + "',"; //$NON-NLS-1$ //$NON-NLS-2$ // ? editor ?? ? . Map<String, Table> mapDBTables = new HashMap<String, Table>(); for (Table table : db.getTables()) { mapDBTables.put(table.getName(), table); refTableNames += "'" + table.getName() + "',"; //$NON-NLS-1$ //$NON-NLS-2$ } refTableNames = StringUtils.chompLast(refTableNames, ","); //$NON-NLS-1$ // ? ?? ? ? if (mapDBTables.get(tableName) == null) { // ? ? ? Table tableModel = tadpoleFactory.createTable(); tableModel.setName(tableName); tableModel.setDb(db); String tableComment = StringUtils.trimToEmpty(arryTable[2]); tableComment = StringUtils.substring(tableComment, 0, 10); tableModel.setComment(tableComment); // ?? ?. prevRectangle = new Rectangle(nextTableX, nextTableY, TadpoleModelUtils.END_TABLE_WIDTH, TadpoleModelUtils.END_TABLE_HIGHT); tableModel.setConstraints(prevRectangle); // ? . nextTableX = originalX + (TadpoleModelUtils.GAP_WIDTH * intCount); intCount++; try { // ? ? for (TableColumnDAO columnDAO : mapTable.get(tableName)) { Column column = tadpoleFactory.createColumn(); column.setDefault(columnDAO.getDefault()); column.setExtra(columnDAO.getExtra()); column.setField(columnDAO.getField()); column.setNull(columnDAO.getNull()); column.setKey(columnDAO.getKey()); column.setType(columnDAO.getType()); String strComment = columnDAO.getComment(); if (strComment == null) strComment = ""; strComment = StringUtils.substring(strComment, 0, 10); column.setComment(strComment); column.setTable(tableModel); tableModel.getColumns().add(column); } mapDBTables.put(tableName, tableModel); RelationUtil.calRelation(userDB, mapDBTables, db, refTableNames);//RelationUtil.getReferenceTable(userDB, refTableNames)); } catch (Exception e) { logger.error("GEF Table Drag and Drop Exception", e); //$NON-NLS-1$ Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); //$NON-NLS-1$ ExceptionDetailsErrorDialog.openError( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.get().Error, Messages.get().TadpoleModelUtils_2, errStatus); //$NON-NLS-1$ } transferFactory.setTable(tableModel); } else { transferFactory.setTable(mapDBTables.get(tableName)); } } // end tables // super.handleDrop(); }
From source file:com.inktomi.wxmetar.MetarParser.java
static boolean parseAltimeter(String token, final Metar metar) { boolean rval = Boolean.FALSE; if (StringUtils.startsWith(token, "A") && token.length() == 5) { rval = Boolean.TRUE;// w ww . j a va2 s. c o m Integer alt = Integer.parseInt(StringUtils.substring(token, 1, token.length())); metar.altimeter = (float) alt / 100; } return rval; }
From source file:mitm.common.util.MiscStringUtils.java
/** * Replaces the last chars with replaceCharWith * //from w w w. ja v a2s. c o m * Example: * * replaceLastChars("abc123", 3, "mn") returns "abcmnmnmn" */ public static String replaceLastChars(String input, int lastChars, String replaceCharWith) { input = StringUtils.defaultString(input); int maxLength = input.length() - lastChars; if (maxLength < 0) { maxLength = 0; } String dots = StringUtils.repeat(StringUtils.defaultString(replaceCharWith), input.length() - maxLength); return StringUtils.substring(input, 0, maxLength) + dots; }
From source file:com.allinfinance.dwr.system.SelectOptionsDWR.java
/** *@ ? //from w w w .j ava 2s. c o m **/ public String loadCupBrhIdOptData(String brhId) { String jsonData = "{data:[{'valueField':'','displayField':'?'}]}"; try { log.info("brhId=" + brhId); Object[] params = new Object[1]; params[0] = StringUtils.substring(brhId, brhId.length() - 4, brhId.length()); LinkedHashMap<String, String> dataMap = SelectMethod.getCupBrh(params); Iterator<String> iter = dataMap.keySet().iterator(); if (iter.hasNext()) { Map<String, Object> jsonDataMap = new HashMap<String, Object>(); LinkedList<Object> jsonDataList = new LinkedList<Object>(); Map<String, String> tmpMap = null; String key = null; while (iter.hasNext()) { tmpMap = new LinkedHashMap<String, String>(); key = iter.next(); tmpMap.put("valueField", key); tmpMap.put("displayField", dataMap.get(key)); jsonDataList.add(tmpMap); } jsonDataMap.put("data", jsonDataList); jsonData = JSONBean.genMapToJSON(jsonDataMap); } } catch (Exception e) { e.printStackTrace(); log.error(e.getMessage()); } return jsonData; }