List of usage examples for org.apache.commons.lang StringUtils substringBefore
public static String substringBefore(String str, String separator)
Gets the substring before the first occurrence of a separator.
From source file:org.eclipse.smarthome.core.scheduler.RecurrenceExpression.java
@Override protected RecurrenceExpressionPart parseToken(String token, int position) throws ParseException { String key = StringUtils.substringBefore(token, "="); String value = StringUtils.substringAfter(token, "="); switch (key) { case FREQ: {//from w w w.j av a 2s. c om return new FrequencyExpressionPart(value); } case INTERVAL: { return new IntervalExpressionPart(value); } case BYSECOND: { return new SecondExpressionPart(value); } case BYMINUTE: { return new MinuteExpressionPart(value); } case BYHOUR: { return new HourExpressionPart(value); } case BYDAY: { return new DayExpressionPart(value); } case BYMONTHDAY: { return new MonthDayExpressionPart(value); } case BYMONTH: { return new MonthExpressionPart(value); } case BYYEARDAY: { return new YearDayExpressionPart(value); } case BYWEEKNO: { return new WeekNumberExpressionPart(value); } case BYSETPOS: { return new PositionExpressionPart(value); } case WKST: { return new WeekStartExpressionPart(value); } case UNTIL: { return new UntilExpressionPart(value); } case COUNT: { return new CountExpressionPart(value); } default: throw new IllegalArgumentException("Unknown expression part"); } }
From source file:org.eclipse.smarthome.model.item.internal.GenericItemProvider.java
private Item createItemFromModelItem(ModelItem modelItem) { GenericItem item = null;/* www .j av a 2 s . c om*/ if (modelItem instanceof ModelGroupItem) { ModelGroupItem modelGroupItem = (ModelGroupItem) modelItem; String baseItemType = modelGroupItem.getType(); GenericItem baseItem = createItemOfType(baseItemType, modelGroupItem.getName()); if (baseItem != null) { ModelGroupFunction function = modelGroupItem.getFunction(); if (function == null) { item = new GroupItem(modelGroupItem.getName(), baseItem); } else { item = applyGroupFunction(baseItem, modelGroupItem, function); } } else { item = new GroupItem(modelGroupItem.getName()); } } else { ModelNormalItem normalItem = (ModelNormalItem) modelItem; String itemName = normalItem.getName(); item = createItemOfType(normalItem.getType(), itemName); } if (item != null) { String label = modelItem.getLabel(); String format = StringUtils.substringBetween(label, "[", "]"); if (format != null) { label = StringUtils.substringBefore(label, "[").trim(); stateDescriptions.put(modelItem.getName(), new StateDescription(null, null, null, format, false, null)); } item.setLabel(label); item.setCategory(modelItem.getIcon()); assignTags(modelItem, item); return item; } else { return null; } }
From source file:org.eclipse.wb.android.internal.model.property.event.AndroidEventProperty.java
/** * Adds {@link MethodInvocation}.//from w ww . j a v a 2 s. c o m */ private MethodInvocation addMethodInvocation(String reference, StatementTarget target, String signature, String arguments) throws Exception { // create invocation source String invocationSource; { String methodName = StringUtils.substringBefore(signature, "("); invocationSource = MessageFormat.format("{0}.{1}({2});", reference, methodName, arguments); } // add statement with invocation ExpressionStatement statement = (ExpressionStatement) m_editor.addStatement(invocationSource, target); return (MethodInvocation) statement.getExpression(); }
From source file:org.eclipse.wb.android.internal.model.property.event.ListenerInfo.java
private static String getSimpleName(String qualifiedName) { return StringUtils.substringBefore(qualifiedName, "("); }
From source file:org.eclipse.wb.android.internal.model.property.event.ListenerMethodInfo.java
/** * @return the signature for method in AST. It may be different from {@link #getSignature()} if * listener type is generic.//from w w w .jav a2 s. com */ public String getSignatureAST() { String name = m_method.getName(); StringBuilder buffer = new StringBuilder(); buffer.append(name); // types buffer.append('('); boolean firstParameter = true; for (String parameterType : getActualParameterTypes()) { // separator if (firstParameter) { firstParameter = false; } else { buffer.append(','); } // in AST signatures we don't use generics, so remove them parameterType = StringUtils.substringBefore(parameterType, "<"); // append buffer.append(parameterType); } buffer.append(')'); // done return buffer.toString(); }
From source file:org.eclipse.wb.android.internal.support.DeviceManager.java
/** * @return Screen {@link Dimension} for given xVGA string. */// w w w .ja va 2s . c om private static Dimension parseXvga(String skinName) { Dimension resolution; if ("QVGA".equalsIgnoreCase(skinName)) { resolution = new Dimension(240, 320); } else if ("WQVGA400".equalsIgnoreCase(skinName)) { resolution = new Dimension(240, 400); } else if ("WQVGA432".equalsIgnoreCase(skinName)) { resolution = new Dimension(240, 432); } else if ("HVGA".equalsIgnoreCase(skinName)) { resolution = new Dimension(320, 480); } else if ("WVGA800".equalsIgnoreCase(skinName)) { resolution = new Dimension(480, 800); } else if ("WVGA854".equalsIgnoreCase(skinName)) { resolution = new Dimension(480, 854); } else if ("WXGA".equalsIgnoreCase(skinName)) { resolution = new Dimension(1280, 800); } else { // parse custom String skinX = StringUtils.substringBefore(skinName, "x"); String skinY = StringUtils.substringAfter(skinName, "x"); try { resolution = new Dimension(Integer.parseInt(skinX), Integer.parseInt(skinY)); } catch (NumberFormatException e) { // none resolution = null; } } return resolution; }
From source file:org.eclipse.wb.core.eval.AstEvaluationEngine.java
/** * @return stack trace for exception in user code. *///from ww w .ja v a 2s. co m public static String getUserStackTrace(Throwable e) { e = DesignerExceptionUtils.getRootCause(e); String stackTrace = ExceptionUtils.getStackTrace(e); stackTrace = StringUtils.substringBefore(stackTrace, "at org.eclipse.wb."); stackTrace = StringUtils.substringBefore(stackTrace, "at sun.reflect."); stackTrace = StringUtils.stripEnd(stackTrace, null); return stackTrace; }
From source file:org.eclipse.wb.core.model.JavaInfo.java
/** * Appends nodes for {@link #toString()}. *///from w w w . ja v a 2s.c o m private void appendNodes(StringBuffer buffer, List<ASTNode> nodes) { buffer.append(" {"); boolean first = true; for (ASTNode node : nodes) { // append separator if (!first) { buffer.append(" "); } first = false; // prepare node for getting source ASTNode sourceNode = getRelatedNodeForSource(node); // append wrapped source of node { String source = getEditor().getSource(sourceNode); // if anonymous class creation, cut body if (sourceNode instanceof ClassInstanceCreation) { ClassInstanceCreation creation = (ClassInstanceCreation) sourceNode; if (creation.getAnonymousClassDeclaration() != null) { source = StringUtils.substringBefore(source, "{").trim(); } } // do append buffer.append("/"); buffer.append(source); buffer.append("/"); } } buffer.append("}"); }
From source file:org.eclipse.wb.core.model.JavaInfo.java
/** * Adds new {@link MethodInvocation} for this {@link JavaInfo} into given target. * //from ww w . j a va2s . co m * @return the new added {@link MethodInvocation}. * * @param target * the {@link StatementTarget} that specifies where to add {@link MethodInvocation}. * @param signature * the signature of method, to find correct position * @param arguments * the comma separated arguments string */ public final MethodInvocation addMethodInvocation(StatementTarget target, String signature, String arguments) throws Exception { // create invocation source String invocationSource; { String methodName = StringUtils.substringBefore(signature, "("); invocationSource = TemplateUtils.format("{0}.{1}({2})", this, methodName, arguments); } // add statement with invocation return (MethodInvocation) addExpressionStatement(target, invocationSource); }
From source file:org.eclipse.wb.internal.core.model.variable.NamesManager.java
/** * @return <code>true</code> if given variable is is default one for component. *///from www .j a v a2 s . c o m private static boolean isDefaultName(JavaInfo javaInfo, String name) { String baseName = StringUtils.substringBefore(name, "_").toLowerCase(); return getName(javaInfo).equalsIgnoreCase(baseName); }