List of usage examples for org.apache.commons.lang StringUtils substringAfterLast
public static String substringAfterLast(String str, String separator)
Gets the substring after the last occurrence of a separator.
From source file:org.eclipse.wb.internal.core.gef.policy.layout.generic.SelectionEditPolicyInstaller.java
/** * Loads policy {@link Class} with given name, from given package and its parents. *//*from w w w. j a v a 2 s. c om*/ private Class<?> loadClass2(String basePackageName, String name) { String baseClassName = basePackageName + ".gef.policy." + name + "SelectionEditPolicy"; String packageName = StringUtils.substringBeforeLast(baseClassName, "."); String className = StringUtils.substringAfterLast(baseClassName, "."); // check package and its parents ClassLoader classLoader = container.getClass().getClassLoader(); while (packageName.contains(".")) { try { String policyClassName = packageName + "." + className; return classLoader.loadClass(policyClassName); } catch (Throwable e) { } packageName = StringUtils.substringBeforeLast(packageName, "."); } // no class return null; }
From source file:org.eclipse.wb.internal.core.gef.policy.snapping.SnapPoint.java
@Override public String toString() { String name = StringUtils.substringAfterLast(getClass().getName(), "."); return name + "(side=" + sideToString(m_side) + " snapDir=" + (m_snapDirection == PlacementInfo.LEADING ? "LEADING" : "TRAILING") + getObjectInfo() + ")"; }
From source file:org.eclipse.wb.internal.core.utils.reflect.ReflectionUtils.java
/** * Returns the short name of {@link Class}, or same name for simple type name. * // w w w . j ava2s . c o m * <pre> * getShortName("javax.swing.JPanel") = "JPanel" * getShortName("boolean") = "boolean" * </pre> * * @return the short name of given {@link Class}. */ public static String getShortName(Class<?> clazz) { String className = getFullyQualifiedName(clazz, false); // member Class if (clazz.isMemberClass()) { Class<?> topClass = getTopLevelClass(clazz); String topName = topClass.getName(); String topPackage = StringUtils.substringBeforeLast(topName, ".") + "."; return className.substring(topPackage.length()); } // normal top level Class, may be array if (className.indexOf('.') != -1) { return StringUtils.substringAfterLast(className, "."); } // primitive or default package return className; }
From source file:org.eclipse.wb.internal.rcp.model.jface.FieldEditorLabelsConstantsPropertyEditor.java
/** * @return the error message or <code>null</code>. *///from w w w .ja va2 s. c om private static String prepareLabelsFields(List<String> resultLabels, List<IField> resultFields, GenericProperty property, String text) throws Exception { IJavaProject javaProject; String topTypeName; { JavaInfo javaInfo = property.getJavaInfo(); javaProject = javaInfo.getEditor().getJavaProject(); TypeDeclaration typeDeclaration = JavaInfoUtils.getTypeDeclaration(javaInfo); topTypeName = AstNodeUtils.getFullyQualifiedName(typeDeclaration, false); } // prepare containers List<String> tmpLabels = Lists.newArrayList(); List<IField> tmpFields = Lists.newArrayList(); resultLabels.clear(); resultFields.clear(); // analyze each line String[] lines = StringUtils.split(text, Text.DELIMITER); for (String line : lines) { line = line.trim(); String[] words = StringUtils.split(line); if (words.length < 2) { return MessageFormat.format(ModelMessages.FieldEditorLabelsConstantsPropertyEditor_errLabelField, line); } // prepare "label" and "field" code int lastSpaceIndex = StringUtils.lastIndexOf(line, " "); String label = line.substring(0, lastSpaceIndex).trim(); String fieldCode = line.substring(lastSpaceIndex).trim(); // convert "fieldCode" into IField IField field; if (fieldCode.contains(".")) { String typeName = StringUtils.substringBeforeLast(fieldCode, "."); String fieldName = StringUtils.substringAfterLast(fieldCode, "."); field = CodeUtils.findField(javaProject, typeName, fieldName); } else { field = CodeUtils.findField(javaProject, topTypeName, fieldCode); } // we should have IField if (field == null) { return MessageFormat .format(ModelMessages.FieldEditorLabelsConstantsPropertyEditor_errInvalidFieldName, line); } // add label/field tmpLabels.add(label); tmpFields.add(field); } // OK resultLabels.addAll(tmpLabels); resultFields.addAll(tmpFields); return null; }
From source file:org.eclipse.wb.internal.swing.databinding.ui.contentproviders.DetailBindingUiContentProvider.java
public void updateFromObject() throws Exception { String elementClassName = m_binding.getJListBinding().getInputElementType().getFullTypeName(); setClassNameAndProperty(StringUtils.substringBefore(elementClassName, "<") + StringUtils.substringAfterLast(elementClassName, ">"), m_binding.getDetailProperty()); }
From source file:org.eclipse.wb.internal.swt.model.property.editor.image.plugin.BundleImageResource.java
public BundleImageResource(URL url, String symbolicName) { m_url = url;/*from www . j av a 2s . c om*/ m_symbolicName = symbolicName; m_imagePath = m_url.getFile(); m_name = StringUtils.substringAfterLast(m_imagePath, "/"); }
From source file:org.eclipse.wb.internal.xwt.model.property.editor.style.XwtStyleClassResolver.java
public String resolve(Property property, String className) { if (className.equals("org.eclipse.swt.SWT")) { return ""; }//from ww w .j av a 2 s. c o m // String packageName = StringUtils.substringBeforeLast(className, "."); String namespace = getPackageNamespace(property, packageName); String shortClassName = StringUtils.substringAfterLast(className, "."); return "(" + namespace + ":" + shortClassName + ")."; }
From source file:org.eclipse.wb.internal.xwt.model.util.XwtTagResolver.java
private void invoke0(XmlObjectInfo object, Class<?> clazz, String[] namespace, String[] tag) throws Exception { if (XwtDescriptionProcessor.isXWT(object)) { String className = clazz.getName(); namespace[0] = getNamespace(className); tag[0] = StringUtils.substringAfterLast(className, "."); }// w ww. j a v a2 s . com }
From source file:org.eclipse.wb.tests.designer.core.palette.ComponentEntryInfoTest.java
/** * Test for loading palette usually done in earlyStartup(). * <p>//from w w w . j a v a 2 s .c o m * This requires for -DFLAG_NO_PALETTE flag. */ public void test_preloadingCache() throws Exception { TestBundle testBundle = new TestBundle(); Image image = new Image(null, 11, 29); try { // prepare String className = ClassForBundle.class.getName(); String descriptionsPath = "wbp-meta/" + CodeUtils.getPackage(className).replace('.', '/') + "/"; testBundle.addClass(ClassForBundle.class); testBundle.setFile(descriptionsPath + ".wbp-cache-descriptions", "Please, cache this package."); String componentPath = descriptionsPath + StringUtils.substringAfterLast(className, "."); testBundle.setFile(componentPath + ".wbp-component.xml", getSourceDQ("<?xml version='1.0' encoding='UTF-8'?>", "<component xmlns='http://www.eclipse.org/wb/WBPComponent'>", " <description>test1 test2 <p attr='val'>test3</p> test4 test5</description>", "</component>")); testBundle.setFile(componentPath + ".png", ImageUtils.getBytesPNG(image)); testBundle.addExtension("org.eclipse.wb.core.toolkits", "<toolkit id='org.eclipse.wb.swing'>", " <palette>", " <category id='org.eclipse.wb.tests.testBundle.components' name='Test' description='Test'>", " <component class='" + className + "'/>", " </category>", " </palette>", "</toolkit>"); testBundle.install(); try { String toolkitId = "org.eclipse.wb.swing"; // get cache Object cache = ReflectionUtils.invokeMethod(ComponentPresentationHelper.class, "getCache(java.lang.String)", toolkitId); // do the job ReflectionUtils.invokeMethod(ComponentPresentationHelper.class, "fillPresentations(" + cache.getClass().getName().replace("$", ".") + ",java.lang.String,org.eclipse.core.runtime.IProgressMonitor)", cache, toolkitId, new NullProgressMonitor()); // get presentation and check ComponentPresentation presentation = (ComponentPresentation) ReflectionUtils.invokeMethod(cache, "get(java.lang.String)", className + " null"); assertNotNull(presentation); assertEquals("test1 test2 <p attr=\"val\">test3</p> test4 test5", presentation.getDescription()); Image icon = presentation.getIcon(); assertNotNull(icon); assertEquals(image.getBounds().width, 11); assertEquals(image.getBounds().height, 29); } finally { testBundle.uninstall(); } } finally { image.dispose(); testBundle.dispose(); } }
From source file:org.ednovo.gooru.application.converter.GooruImageUtil.java
public static boolean scaleImage(String srcFilePath, String targetFolderPath, String... dimensions) { try {//from www . j a v a 2s.c o m ByteArrayInputStream sourceImageStream = getByteArrayInputStream(srcFilePath); String filenamePrefix = StringUtils.substringAfterLast(srcFilePath, "/"); for (String dimension : dimensions) { String[] xy = dimension.split(X); int width = Integer.valueOf(xy[0]); int height = Integer.valueOf(xy[1]); File thumbnailFile = new File(targetFolderPath + "/" + filenamePrefix + "-" + dimension + "." + getFileExtenstion(srcFilePath)); scaleImage(sourceImageStream, width, height, thumbnailFile); } return true; } catch (Exception ex) { logger.warn("Multiple scaling of image failed : ", ex); return false; } }