Search in sources :

Example 1 with NSBundle

use of com.webobjects.foundation.NSBundle in project wonder-slim by undur.

the class ERXComponentUtilities method pathUrlForResourceNamed.

private static URL pathUrlForResourceNamed(WOResourceManager resourceManager, String resourceName, NSArray languages) {
    URL templateUrl = resourceManager.pathURLForResourceNamed(resourceName, null, languages);
    if (templateUrl == null) {
        NSArray frameworkBundles = NSBundle.frameworkBundles();
        if (frameworkBundles != null) {
            Enumeration frameworksEnum = frameworkBundles.objectEnumerator();
            while (templateUrl == null && frameworksEnum.hasMoreElements()) {
                NSBundle frameworkBundle = (NSBundle) frameworksEnum.nextElement();
                templateUrl = resourceManager.pathURLForResourceNamed(resourceName, frameworkBundle.name(), languages);
            }
        }
    }
    return templateUrl;
}
Also used : Enumeration(java.util.Enumeration) NSBundle(com.webobjects.foundation.NSBundle) NSArray(com.webobjects.foundation.NSArray) URL(java.net.URL)

Example 2 with NSBundle

use of com.webobjects.foundation.NSBundle in project wonder-slim by undur.

the class WOExceptionParser method _ignoredPackages.

private NSArray _ignoredPackages() {
    NSBundle bundle;
    String path, content;
    NSDictionary dic = null;
    NSMutableArray<NSBundle> allBundles = new NSMutableArray<>(NSBundle.frameworkBundles());
    NSMutableArray<String> ignored = new NSMutableArray<>();
    for (Enumeration enumerator = allBundles.objectEnumerator(); enumerator.hasMoreElements(); ) {
        bundle = (NSBundle) enumerator.nextElement();
        path = WOApplication.application().resourceManager().pathForResourceNamed("WOIgnoredPackage.plist", bundle.name(), null);
        if (path != null) {
            content = _stringFromFileSafely(path);
            if (content != null) {
                dic = (NSDictionary) NSPropertyListSerialization.propertyListFromString(content);
                if (dic != null && dic.containsKey("ignoredPackages")) {
                    @SuppressWarnings("unchecked") NSArray<String> tmpArray = (NSArray<String>) dic.objectForKey("ignoredPackages");
                    if (tmpArray != null && tmpArray.count() > 0) {
                        ignored.addObjectsFromArray(tmpArray);
                    }
                }
            }
        }
    }
    return ignored;
}
Also used : NSBundle(com.webobjects.foundation.NSBundle) Enumeration(java.util.Enumeration) NSArray(com.webobjects.foundation.NSArray) NSDictionary(com.webobjects.foundation.NSDictionary) NSMutableArray(com.webobjects.foundation.NSMutableArray)

Example 3 with NSBundle

use of com.webobjects.foundation.NSBundle in project wonder-slim by undur.

the class ERXApplication method didFinishLaunching.

/**
 * Notification method called when the application posts the notification {@link WOApplication#ApplicationDidFinishLaunchingNotification}.
 * This method calls subclasse's {@link #didFinishLaunching} method.
 *
 * @param n notification posted after WOApplication has finished launching and is ready for accepting requests.
 */
public final void didFinishLaunching(NSNotification n) {
    didFinishLaunching();
    ERXStats.logStatisticsForOperation(statsLog, "sum");
    // FIXME: Is this being handled by ERXStats? Check out.
    _startupTimeInMilliseconds = System.currentTimeMillis() - _startupTimeInMilliseconds;
    log.info(String.format("Startup time %s ms: ", _startupTimeInMilliseconds));
    System.out.println("============= LOADED BUNDLES START =============");
    for (NSBundle nsBundle : NSBundle._allBundlesReally()) {
        System.out.println(String.format("%-22s : %-65s : %s", nsBundle.name(), nsBundle.getClass(), nsBundle.isJar()));
    }
    System.out.println("============= LOADED BUNDLES END ===============");
}
Also used : NSBundle(com.webobjects.foundation.NSBundle)

Example 4 with NSBundle

use of com.webobjects.foundation.NSBundle in project wonder-slim by undur.

the class ERXLoader method bundleDidLoad.

/**
 * Will be called after each bundle load. We use it to know when the last
 * bundle loaded so we can post a notification for it. Note that the bundles
 * will get loaded in the order of the classpath but the main bundle will
 * get loaded last. So in order to set the properties correctly, we first
 * add all the props that are not already set, then we add the main bundle
 * and the WebObjects.properties and finally the command line props.
 */
public void bundleDidLoad(NSNotification n) {
    NSBundle bundle = (NSBundle) n.object();
    if (allFrameworks.contains(bundle.name())) {
        allFrameworks.remove(bundle.name());
        debugMsg("Loaded " + bundle.name() + ". Remaining: " + allFrameworks);
    } else if (bundle.isFramework()) {
        debugMsg("Loaded unexpected framework bundle '" + bundle.name() + "'. Ensure your build.properties settings like project.name match the bundle name (including case).");
    }
    if (allBundleProps == null) {
        allBundleProps = new Properties();
    }
    String userName = propertyFromCommandLineFirst("user.name");
    applyIfUnset(readProperties(bundle, "Properties." + userName));
    applyIfUnset(readProperties(bundle, null));
    if (allFrameworks.size() == 0) {
        mainProps = null;
        mainUserProps = null;
        collectMainProps(userName);
        allBundleProps.putAll(mainProps);
        if (mainUserProps != null) {
            allBundleProps.putAll(mainUserProps);
        }
        String userHome = propertyFromCommandLineFirst("user.home");
        Properties userHomeProps = null;
        if (userHome != null && userHome.length() > 0) {
            userHomeProps = readProperties(new File(userHome, "WebObjects.properties"));
        }
        if (userHomeProps != null) {
            allBundleProps.putAll(userHomeProps);
        }
        Properties props = NSProperties._getProperties();
        props.putAll(allBundleProps);
        NSProperties._setProperties(props);
        insertCommandLineArguments();
        if (userHomeProps != null) {
            urls.add(0, urls.remove(urls.size() - 1));
        }
        if (mainUserProps != null) {
            urls.add(0, urls.remove(urls.size() - 1));
        }
        urls.add(0, urls.remove(urls.size() - 1));
        // System.out.print(urls);
        NSNotificationCenter.defaultCenter().postNotification(new NSNotification(ERXApplication.AllBundlesLoadedNotification, NSKeyValueCoding.NullValue));
    }
}
Also used : NSBundle(com.webobjects.foundation.NSBundle) NSNotification(com.webobjects.foundation.NSNotification) NSProperties(com.webobjects.foundation.NSProperties) Properties(java.util.Properties) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 5 with NSBundle

use of com.webobjects.foundation.NSBundle in project wonder-slim by undur.

the class ERXLoader method mainBundle.

private NSBundle mainBundle() {
    NSBundle mainBundle = null;
    String mainBundleName = NSProperties._mainBundleName();
    if (mainBundleName != null) {
        mainBundle = NSBundle.bundleForName(mainBundleName);
    }
    if (mainBundle == null) {
        mainBundle = NSBundle.mainBundle();
    }
    if (mainBundle == null) {
        try {
            Field ClassPath = NSBundle.class.getDeclaredField("ClassPath");
            ClassPath.setAccessible(true);
            if (ClassPath.get(NSBundle.class) != null) {
                Method init = NSBundle.class.getDeclaredMethod("InitMainBundle");
                init.setAccessible(true);
                init.invoke(NSBundle.class);
            }
        } catch (Exception e) {
            System.err.println(e);
            e.printStackTrace();
            System.exit(1);
        }
        mainBundle = NSBundle.mainBundle();
    }
    return mainBundle;
}
Also used : Field(java.lang.reflect.Field) NSBundle(com.webobjects.foundation.NSBundle) Method(java.lang.reflect.Method) NSForwardException(com.webobjects.foundation.NSForwardException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

NSBundle (com.webobjects.foundation.NSBundle)17 NSArray (com.webobjects.foundation.NSArray)5 IOException (java.io.IOException)5 Enumeration (java.util.Enumeration)5 File (java.io.File)4 NSMutableArray (com.webobjects.foundation.NSMutableArray)3 URL (java.net.URL)3 WOApplication (com.webobjects.appserver.WOApplication)2 WODeployedBundle (com.webobjects.appserver._private.WODeployedBundle)2 NSDictionary (com.webobjects.foundation.NSDictionary)2 MalformedURLException (java.net.MalformedURLException)2 JarFile (java.util.jar.JarFile)2 NSForwardException (com.webobjects.foundation.NSForwardException)1 NSMutableDictionary (com.webobjects.foundation.NSMutableDictionary)1 NSNotification (com.webobjects.foundation.NSNotification)1 NSProperties (com.webobjects.foundation.NSProperties)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 UncheckedIOException (java.io.UncheckedIOException)1 Field (java.lang.reflect.Field)1