下面列出了org.osgi.framework.Bundle#getEntryPaths ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public JspBundle addingBundle ( final Bundle bundle, final BundleEvent event )
{
final Enumeration<String> result = bundle.getEntryPaths ( "/WEB-INF" );
if ( result != null && result.hasMoreElements () )
{
try
{
return new JspBundle ( bundle, this.service, this.context );
}
catch ( ServletException | NamespaceException e )
{
logger.warn ( "Failed to register JSP bundle: " + bundle.getSymbolicName (), e );
return null;
}
}
return null;
}
private boolean fillFromPlainBundle ( final Bundle bundle, final Map<String, URL> tlds )
{
boolean added = false;
final Enumeration<String> paths = bundle.getEntryPaths ( "/META-INF/" );
while ( paths.hasMoreElements () )
{
final String name = paths.nextElement ();
if ( name.endsWith ( ".tld" ) )
{
final String key = makeKey ( name );
final URL entry = bundle.getEntry ( name );
if ( entry != null )
{
logger.debug ( "Add plain mapping {} -> {} / {}", key, name, entry );
tlds.put ( key, entry );
added = true;
}
}
}
return added;
}
private void checkAndUnloadBundle(Bundle bundle) {
if (bundle.getEntry(META_INF_SERVICES) == null) {
return;
}
synchronized (resourceBundles) {
resourceBundles.remove(bundle);
LOG.fine("Unregistered ServiceLoader bundle: " + bundle.getSymbolicName());
}
Enumeration<String> entryPaths = bundle.getEntryPaths(META_INF_SERVICES);
while (entryPaths.hasMoreElements()) {
String entryPath = entryPaths.nextElement();
if (!entryPath.endsWith("/")) {
removeEntryPath(bundle, entryPath);
}
}
}
private void checkAndLoadBundle(Bundle bundle) {
if (bundle.getEntry(META_INF_SERVICES) == null) {
return;
}
synchronized (resourceBundles) {
resourceBundles.add(bundle);
LOG.info("Registered ServiceLoader bundle: " + bundle.getSymbolicName());
}
Enumeration<String> entryPaths = bundle.getEntryPaths(META_INF_SERVICES);
while (entryPaths.hasMoreElements()) {
String entryPath = entryPaths.nextElement();
if (!entryPath.endsWith("/")) {
processEntryPath(bundle, entryPath);
}
}
}
/**
* Imports resources from <code>bundleSourcePath</code> to
* <code>importTarget</code>.
*
* @param importTarget
* the parent container
* @param bundleSourcePath
* the path to a folder containing resources
*
* @throws CoreException
* import failed
* @throws IOException
* import failed
*/
public static void importResources(IContainer importTarget, Bundle bundle, String bundleSourcePath) throws CoreException,
IOException {
Enumeration<?> entryPaths = bundle.getEntryPaths(bundleSourcePath);
while (entryPaths.hasMoreElements()) {
String path = (String) entryPaths.nextElement();
IPath name = new Path(path.substring(bundleSourcePath.length()));
if (path.endsWith("/.svn/")) {
continue; // Ignore SVN folders
} else if (path.endsWith("/")) {
IFolder folder = importTarget.getFolder(name);
if (folder.exists()) {
folder.delete(true, null);
}
folder.create(true, true, null);
importResources(folder, bundle, path);
} else {
URL url = bundle.getEntry(path);
IFile file = importTarget.getFile(name);
if (!file.exists()) {
file.create(url.openStream(), true, null);
} else {
file.setContents(url.openStream(), true, false, null);
}
}
}
}
/**
* Return the URLs of ScriptLib jars.
*
* @return
*/
private static List<URL> getDefaultViewerScriptLibURLs( )
{
List<URL> urls = new ArrayList<URL>( );
try
{
Bundle bundle = Platform.getBundle( VIEWER_NAMESPACE );
// Prepare ScriptLib location
Enumeration bundleFile = bundle.getEntryPaths( BIRT_SCRIPTLIB );
while ( bundleFile.hasMoreElements( ) )
{
String o = bundleFile.nextElement( ).toString( );
if ( o.endsWith( ".jar" ) )
urls.add( bundle.getResource( o ) );
}
URL classes = bundle.getEntry( BIRT_CLASSES );
if ( classes != null )
{
urls.add( classes );
}
}
catch ( Exception e )
{
}
return urls;
}
public static List<I18nExtension> analyze(String path, Bundle bundle) {
List<I18nExtension> list = new ArrayList<>();
Enumeration<String> paths = bundle.getEntryPaths(path);
if (paths != null) {
while (paths.hasMoreElements()) {
String entry = paths.nextElement();
if (! entry.endsWith("/")) {
// It's a file, as entries ending with / are directories.
String file = entry.substring(path.length() - 1);
Locale locale = getLocaleFromResourceName(file);
URL url = bundle.getEntry(entry);
if (url != null) {
I18nExtension extension = new I18nExtension(url, locale, bundle);
try {
extension.load();
list.add(extension);
} catch (IOException e) {
LOGGER.error("Cannot load resource bundle from " + path + " within " + bundle.getSymbolicName(), e);
}
} else {
LOGGER.error("Cannot open " + entry + " from " + bundle.getSymbolicName());
}
}
}
}
return list;
}
/**
* This method is used to check if the specified {@code Bundle} contains resource files providing automation
* resources.
*
* @param bundle is a {@link Bundle} object to check.
* @return <tt>true</tt> if the specified {@link Bundle} contains resource files providing automation
* resources, <tt>false</tt> otherwise.
*/
private boolean isAnAutomationProvider(Bundle bundle) {
return bundle.getEntryPaths(AbstractResourceBundleProvider.ROOT_DIRECTORY) != null;
}
/**
* This method is used to check if the specified {@code Bundle} contains resource files providing automation
* resources.
*
* @param bundle is a {@link Bundle} object to check.
* @return <tt>true</tt> if the specified {@link Bundle} contains resource files providing automation
* resources, <tt>false</tt> otherwise.
*/
private boolean isAnAutomationProvider(Bundle bundle) {
return bundle.getEntryPaths(AbstractResourceBundleProvider.ROOT_DIRECTORY) != null;
}