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.eclipse.smarthome.core.items.events.ItemEventFactory.java
private static String getStateType(State state) { return StringUtils.removeEnd(state.getClass().getSimpleName(), TYPE_POSTFIX); }
From source file:org.eclipse.smarthome.core.items.events.ItemEventFactory.java
private static String getCommandType(Command command) { return StringUtils.removeEnd(command.getClass().getSimpleName(), TYPE_POSTFIX); }
From source file:org.eclipse.smarthome.io.rest.sitemap.internal.SitemapResource.java
public Collection<SitemapBean> getSitemapBeans(URI uri) { Collection<SitemapBean> beans = new LinkedList<SitemapBean>(); logger.debug("Received HTTP GET request at '{}'.", UriBuilder.fromUri(uri).build().toASCIIString()); for (String modelName : modelRepository.getAllModelNamesOfType("sitemap")) { Sitemap sitemap = (Sitemap) modelRepository.getModel(modelName); if (sitemap != null) { SitemapBean bean = new SitemapBean(); bean.name = StringUtils.removeEnd(modelName, SITEMAP_FILEEXT); bean.icon = sitemap.getIcon(); bean.label = sitemap.getLabel(); bean.link = UriBuilder.fromUri(uri).path(bean.name).build().toASCIIString(); bean.homepage = new PageBean(); bean.homepage.link = bean.link + "/" + sitemap.getName(); beans.add(bean);/*from w ww . j a va 2 s. c o m*/ } } return beans; }
From source file:org.eclipse.smarthome.io.rest.sitemap.SitemapSubscriptionService.java
@Override public void modelChanged(String modelName, EventType type) { if (type != EventType.MODIFIED || !modelName.endsWith(SITEMAP_SUFFIX)) { return; // we process only sitemap modifications here }/*from www . j a v a 2s. c om*/ String changedSitemapName = StringUtils.removeEnd(modelName, SITEMAP_SUFFIX); for (Entry<String, PageChangeListener> listenerEntry : pageChangeListeners.entrySet()) { String sitemapWithPage = listenerEntry.getKey(); String sitemapName = extractSitemapName(sitemapWithPage); String pageId = extractPageId(sitemapWithPage); if (sitemapName.equals(changedSitemapName)) { EList<Widget> widgets = collectWidgets(sitemapName, pageId); listenerEntry.getValue().sitemapContentChanged(widgets); } } }
From source file:org.eclipse.smarthome.model.sitemap.internal.SitemapProviderImpl.java
@Override public Set<String> getSitemapNames() { Set<String> names = new HashSet<>(); if (modelRepo != null) { for (String name : modelRepo.getAllModelNamesOfType("sitemap")) { names.add(StringUtils.removeEnd(name, SITEMAP_FILEEXT)); }/*from www.ja v a 2 s . com*/ } else { logger.debug("No model repository service is available"); } return names; }
From source file:org.eclipse.wb.android.internal.editor.AndroidPairResourceProvider.java
/** * @return the Activity file which uses given xml layout. *//*from ww w. j a v a2 s . c om*/ protected IFile getJavaFile(IFile layoutFile) throws Exception { IProject project = layoutFile.getProject(); String packageName = AndroidUtils.getPackageFromManifest(project); if (packageName == null) { return null; } IJavaProject javaProject = JavaCore.create(project); IType rType = javaProject.findType(packageName, "R.layout"); String layoutName = StringUtils.removeEnd(layoutFile.getName(), "." + layoutFile.getFileExtension()); IField field = rType.getField(layoutName); List<IJavaElement> references = CodeUtils.searchReferences(field); for (IJavaElement element : references) { // TODO: ask the user if found more than one? return (IFile) element.getUnderlyingResource(); } return null; }
From source file:org.eclipse.wb.android.internal.model.layouts.LinearLayoutInfo.java
private int getMarginValue(ViewInfo child, int side) throws Exception { String marginTitle = getMarginPropertyName(side); GenericPropertyImpl marginProperty = (GenericPropertyImpl) getLayoutPropertyByTitle(child, marginTitle); Object value = marginProperty.getValue(); if (Property.UNKNOWN_VALUE == value) { return 0; }// w w w . ja v a 2s . co m String marginValue = (String) value; if (!marginValue.endsWith("px")) { // TODO: convert to px! return 0; } try { return Integer.parseInt(StringUtils.removeEnd(marginValue, "px")); } catch (Throwable e) { return 0; } }
From source file:org.eclipse.wb.android.internal.model.property.event.ListenerInfo.java
/** * @return the name of listener method, to display for user. For example <code>key</code> for * <code>addKeyListener()</code>. *//*www. j av a 2 s . c om*/ private static String _getListenerSimpleName(Method addListenerMethod) { String name = addListenerMethod.getName(); // convert into simple name name = StringUtils.removeStart(name, "set"); name = StringUtils.removeEnd(name, "Listener"); name = StringUtils.uncapitalize(name); // if become empty, use full name if (name.length() == 0) { name = addListenerMethod.getName(); } return name; }
From source file:org.eclipse.wb.internal.core.gef.policy.layout.generic.SelectionEditPolicyInstaller.java
/** * Loads policy {@link Class} from given package and its parents. *//*from ww w.j a v a2s.co m*/ private Class<?> loadClass(String basePackageName) { // name, based on container Class name String containerName; { containerName = StringUtils.substringAfterLast(containerClassName, ".model."); containerName = StringUtils.removeEnd(containerName, "Info"); } // containerName + childName { String childClassName = child.getClass().getName(); String childName = StringUtils.substringAfterLast(childClassName, "."); childName = StringUtils.removeEnd(childName, "Info"); // Class<?> clazz = loadClass2(basePackageName, containerName + childName); if (clazz != null) { return clazz; } } // only containerName { Class<?> clazz = loadClass2(basePackageName, containerName); if (clazz != null) { return clazz; } } // no class return null; }
From source file:org.eclipse.wb.internal.core.model.description.helpers.ComponentDescriptionHelper.java
/** * TODO move into {@link ReflectionUtils}. * /* w w w . j av a 2 s . co m*/ * @return the source for creating {@link Object} using given {@link Constructor} with values * default for type of each argument. */ public static String getDefaultConstructorInvocation(Constructor<?> constructor) { // prepare Class Class<?> componentClass = constructor.getDeclaringClass(); String componentClassName = ReflectionUtils.getCanonicalName(componentClass); // prepare arguments String arguments; { StringBuilder buffer = new StringBuilder(); for (Class<?> parameter : constructor.getParameterTypes()) { String parameterName = ReflectionUtils.getCanonicalName(parameter); buffer.append(AstParser.getDefaultValue(parameterName)); buffer.append(", "); } arguments = StringUtils.removeEnd(buffer.toString(), ", "); } // prepare source return "new " + componentClassName + "(" + arguments + ")"; }