Example usage for org.apache.commons.lang ClassUtils getPackageName

List of usage examples for org.apache.commons.lang ClassUtils getPackageName

Introduction

In this page you can find the example usage for org.apache.commons.lang ClassUtils getPackageName.

Prototype

public static String getPackageName(String className) 

Source Link

Document

Gets the package name from a String.

The string passed in is assumed to be a class name - it is not checked.

If the class is unpackaged, return an empty string.

Usage

From source file:com.xtructure.xutil.test.SuiteInfo.java

/** {@inheritDoc} */
@Override//from w  w  w.  jav  a  2s . co  m
protected final String getChildName(final ITestResult result) {
    return ClassUtils.getPackageName(result.getTestClass().getName());
}

From source file:com.ggasoftware.uitest.utils.ReporterNGExt.java

/**
 * Get element level for log./*  w  w w  .  j ava2 s.  co m*/
 *
 * @param element - element to get level
 * @return log level (ReporterNG.BUSINESS_LEVEL, ReporterNG.COMPONENT_LEVEL or ReporterNG.TECHNICAL_LEVEL)
 */
//TODO Improve this method
private static char getLogLevel(Object element) {
    if (ClassUtils.getPackageName(element.getClass()).contains(".panel")) {
        return COMPONENT_LEVEL;
    } else if (ClassUtils.getAllSuperclasses(element.getClass()).contains(TestBaseWebDriver.class)) {
        return BUSINESS_LEVEL;
    }
    return TECHNICAL_LEVEL;
}

From source file:ips1ap101.lib.base.bundle.JRResourceBundleHandler.java

public JRResourceBundleHandler(Class<?> resourceClass) {
    _resourceClassSimpleName = resourceClass.getSimpleName();
    //      _resourceClassPackageName = resourceClass.getPackage().getName();
    _resourceClassPackageName = ClassUtils.getPackageName(resourceClass.getName());
    _defaultTriad = new ResourceBundleTriad(defaultLocale);
}

From source file:ips1ap101.lib.base.bundle.ResourceBundleHandler.java

public ResourceBundleHandler(Class<?> resourceClass) {
    _resourceClassSimpleName = resourceClass.getSimpleName();
    //      _resourceClassPackageName = resourceClass.getPackage().getName();
    _resourceClassPackageName = ClassUtils.getPackageName(resourceClass.getName());
    _defaultTriad = new ResourceBundleTriad(defaultLocale);
}

From source file:com.xtructure.xutil.AbstractRunTests.java

/**
 * Creates a new test runner./*  w  w  w.  j  a v a  2s  .  c o  m*/
 * 
 * @param testNameRegex
 *            a regular expression describing names of tests
 * 
 * @param packageNames
 *            the names of the packages to search for tests
 */
protected AbstractRunTests(final String testNameRegex, final String... packageNames) {
    super();

    _packageNames = (((packageNames == null) || (packageNames.length == 0))
            ? new String[] { ClassUtils.getPackageName(getClass()) }
            : packageNames);

    final String actualTestNameRegex = ((testNameRegex != null) ? testNameRegex : DEFAULT_TEST_NAME_REGEX);

    _testClassNamePattern = Pattern.compile(".*[.]" + actualTestNameRegex);
    _testClassFileNamePattern = Pattern.compile(actualTestNameRegex + "[.]class");

    _classLoader = Thread.currentThread().getContextClassLoader();
    if (_classLoader == null) {
        throw new RuntimeException("Can't get class loader.");
    }

    findClasses();
}

From source file:com.qualogy.qafe.business.test.BusinessActionTestCase.java

protected String getDirBasedUponPackage() {
    String pckName = ClassUtils.getPackageName(this.getClass());
    return StringUtils.replace(pckName, ".", "/") + "/";
}

From source file:de.xirp.plugin.PluginLoader.java

/**
 * Looks for plugins in the plugins directory. Plugins which needs
 * are not full filled are not accepted.
 * /*www .ja v  a  2  s  .  com*/
 * @param manager
 *            instance of the plugin manager which is used for
 *            notifying the application about the loading
 *            progress.
 */
protected static void searchPlugins(PluginManager manager) {
    logClass.info(I18n.getString("PluginLoader.log.searchPlugins")); //$NON-NLS-1$
    // Get all Files in the Plugin Directory with
    // Filetype jar
    File pluginDir = new File(Constants.PLUGIN_DIR);
    File[] fileList = pluginDir.listFiles(new FilenameFilter() {

        public boolean accept(@SuppressWarnings("unused") File dir, String filename) {
            return filename.endsWith(".jar"); //$NON-NLS-1$
        }

    });

    if (fileList != null) {
        double perFile = 1.0 / fileList.length;
        double cnt = 0;
        try {
            // Iterate over all jars and try to find
            // the plugin.properties file
            // The file is loaded and Information
            // extracted to PluginInfo
            // Plugin is added to List of Plugins
            for (File f : fileList) {
                String path = f.getAbsolutePath();
                if (!plugins.containsKey(path)) {
                    manager.throwLoaderProgressEvent(
                            I18n.getString("PluginLoader.progress.searchingInFile", f.getName()), cnt); //$NON-NLS-1$
                    JarFile jar = new JarFile(path);
                    JarEntry entry = jar.getJarEntry("plugin.properties"); //$NON-NLS-1$
                    if (entry != null) {
                        InputStream input = jar.getInputStream(entry);
                        Properties props = new Properties();
                        props.load(input);
                        String mainClass = props.getProperty("plugin.mainclass"); //$NON-NLS-1$
                        PluginInfo info = new PluginInfo(path, mainClass, props);
                        String packageName = ClassUtils.getPackageName(mainClass) + "." //$NON-NLS-1$
                                + AbstractPlugin.DEFAULT_BUNDLE_NAME;
                        String bundleBaseName = packageName.replaceAll("\\.", "/"); //$NON-NLS-1$  //$NON-NLS-2$
                        for (Enumeration<JarEntry> entries = jar.entries(); entries.hasMoreElements();) {
                            JarEntry ent = entries.nextElement();
                            String name = ent.getName();
                            if (name.indexOf(bundleBaseName) != -1) {
                                String locale = name
                                        .substring(name.indexOf(AbstractPlugin.DEFAULT_BUNDLE_NAME));
                                locale = locale.replaceAll(AbstractPlugin.DEFAULT_BUNDLE_NAME + "_", //$NON-NLS-1$
                                        ""); //$NON-NLS-1$
                                locale = locale.substring(0, locale.indexOf(".properties")); //$NON-NLS-1$
                                Locale loc = new Locale(locale);
                                info.addAvailableLocale(loc);
                            }
                        }
                        PluginManager.extractAll(info);
                        if (isPlugin(info)) {
                            plugins.put(mainClass, info);
                        }
                    }
                }
                cnt += perFile;

            }
        } catch (IOException e) {
            logClass.error(
                    I18n.getString("PluginLoader.log.errorSearchingforPlugins") + Constants.LINE_SEPARATOR, e); //$NON-NLS-1$
        }
    }
    checkAllNeeds();
    logClass.info(I18n.getString("PluginLoader.log.searchPluginsCompleted") + Constants.LINE_SEPARATOR); //$NON-NLS-1$
}

From source file:com.google.gdt.eclipse.designer.gxt.databinding.wizards.autobindings.GxtDatabindingProvider.java

public String performSubstitutions(String code, ImportsManager imports) throws Exception {
    // bean class, field, name, field access
    String beanClassName = m_beanClass.getName().replace('$', '.');
    String beanClassShortName = ClassUtils.getShortClassName(beanClassName);
    String fieldPrefix = JavaCore.getOption(JavaCore.CODEASSIST_FIELD_PREFIXES);
    String fieldName = fieldPrefix + StringUtils.uncapitalize(beanClassShortName);
    ////from   w  w  w .j av  a 2 s. co m
    Collection<String> importList = Sets.newHashSet();
    //
    final List<PropertyAdapter> properties = Lists.newArrayList();
    Display.getDefault().syncExec(new Runnable() {
        public void run() {
            m_packageName = m_firstPage.getPackageFragment().getElementName();
            CollectionUtils.addAll(properties, m_propertiesViewer.getCheckedElements());
        }
    });
    //
    if (!ClassUtils.getPackageName(beanClassName).equals(m_packageName)) {
        importList.add(beanClassName);
    }
    beanClassName = beanClassShortName;
    //
    code = StringUtils.replace(code, "%BeanClass%", beanClassName);
    //
    if (ReflectionUtils.getConstructorBySignature(m_beanClass, "<init>()") == null) {
        code = StringUtils.replace(code, "%BeanField%", fieldName);
    } else {
        code = StringUtils.replace(code, "%BeanField%", fieldName + " = new " + beanClassName + "()");
    }
    //
    IPreferenceStore preferences = ToolkitProvider.DESCRIPTION.getPreferences();
    String accessPrefix = preferences.getBoolean(FieldUniqueVariableSupport.P_PREFIX_THIS) ? "this." : "";
    String beanFieldAccess = accessPrefix + fieldName;
    //
    code = StringUtils.replace(code, "%BeanFieldAccess%", beanFieldAccess);
    code = StringUtils.replace(code, "%BeanName%", StringUtils.capitalize(beanClassShortName));
    //
    boolean useGenerics = CoreUtils.useGenerics(m_javaProject);
    //
    StringBuffer fieldsCode = new StringBuffer();
    StringBuffer widgetsCode = new StringBuffer();
    StringBuffer bindingsCode = new StringBuffer();
    //
    for (Iterator<PropertyAdapter> I = properties.iterator(); I.hasNext();) {
        PropertyAdapter property = I.next();
        Object[] editorData = m_propertyToEditor.get(property);
        GxtWidgetDescriptor widgetDescriptor = (GxtWidgetDescriptor) editorData[0];
        //
        String propertyName = property.getName();
        String widgetClassName = ClassUtils.getShortClassName(widgetDescriptor.getWidgetClass());
        String widgetFieldName = fieldPrefix + propertyName + widgetClassName;
        String widgetFieldAccess = accessPrefix + widgetFieldName;
        //
        if (useGenerics && widgetDescriptor.isGeneric()) {
            widgetClassName += "<" + convertTypes(property.getType().getName()) + ">";
        }
        //
        fieldsCode.append("\r\nfield\r\n\tprivate " + widgetClassName + " " + widgetFieldName + ";");
        //
        widgetsCode.append("\t\t" + widgetFieldName + " = new " + widgetClassName + "();\r\n");
        widgetsCode.append("\t\t" + widgetFieldAccess + ".setFieldLabel(\""
                + StringUtils.capitalize(propertyName) + "\");\r\n");
        widgetsCode.append("\t\t" + accessPrefix + "m_formPanel.add(" + widgetFieldAccess
                + ", new FormData(\"100%\"));\r\n");
        widgetsCode.append("\t\t//");
        //
        importList.add(widgetDescriptor.getBindingClass());
        bindingsCode.append("\t\tm_formBinding.addFieldBinding(new "
                + ClassUtils.getShortClassName(widgetDescriptor.getBindingClass()) + "(" + widgetFieldAccess
                + ",\"" + propertyName + "\"));\r\n");
        //
        importList.add(widgetDescriptor.getWidgetClass());
        //
        if (I.hasNext()) {
            fieldsCode.append("\r\n");
            widgetsCode.append("\r\n");
        }
    }
    //
    bindingsCode.append("\t\t//\r\n");
    bindingsCode.append("\t\tm_formBinding.bind(" + beanFieldAccess + ");");
    // replace template patterns
    code = StringUtils.replace(code, "%WidgetFields%", fieldsCode.toString());
    code = StringUtils.replace(code, "%Widgets%", widgetsCode.toString());
    code = StringUtils.replace(code, "%Bindings%", bindingsCode.toString());
    // add imports
    for (String qualifiedTypeName : importList) {
        imports.addImport(qualifiedTypeName);
    }
    //
    return code;
}

From source file:edu.cornell.med.icb.io.ResourceFinder.java

/**
 * List directory contents for a resource folder that contains the specified
 * class, this list will include the .class file associated with clazz.
 *
 * @param clazz The java class which lives in the directory you want listed
 * @return Each member item (no path information)
 * @throws java.net.URISyntaxException bad URI syntax
 * @throws IOException error reading/*w ww. ja v a 2 s.  c  om*/
 */
public String[] getResourceListing(final Class clazz) throws URISyntaxException, IOException {
    final String classPackage = ClassUtils.getPackageName(clazz);
    final String classPacakgePath = classPackage.replace(".", "/");
    return getResourceListing(clazz, classPacakgePath);
}

From source file:edu.cornell.med.icb.goby.modes.GenericToolsDriver.java

/**
 * Retrieve the class names of the likely modes.
 *
 * @return the list of class names/*from  ww w  . jav  a 2s. c  o  m*/
 */
private List<String> modesClassNamesList() {
    final List<String> modesList = new LinkedList<String>();
    try {
        final String modesPackage = ClassUtils.getPackageName(getClass());
        final String[] files = new ResourceFinder().getResourceListing(getClass());
        for (final String file : files) {
            if (file.endsWith("Mode.class")) {
                // Keep only classes whose class name end in "Mode"
                final String modeClassName = modesPackage + "." + file.substring(0, file.length() - 6);
                modesList.add(modeClassName);
            }
        }
    } catch (URISyntaxException e) {
        System.err.println("Could not list mode class names URISyntaxException: " + e.getMessage());
        e.printStackTrace();
    } catch (IOException e) {
        System.err.println("Could not list mode class names IOException: " + e.getMessage());
        e.printStackTrace();
    }
    return modesList;
}