Skip to content

Commit

Permalink
improve initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
l0rdn1kk0n committed Feb 7, 2014
1 parent 1b9010e commit f27ce69
Show file tree
Hide file tree
Showing 13 changed files with 433 additions and 291 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,20 @@
* @author miha
*/
public final class WicketWebjars {
private static final String PATH_SPLITTER = "/";
private static WebjarsResourceFinder FINDER = null;

/**
* The {@link org.apache.wicket.MetaDataKey} used to retrieve the {@link IWebjarsSettings} from the Wicket {@link Appendable}.
*/
private static final MetaDataKey<IWebjarsSettings> WEBJARS_SETTINGS_METADATA_KEY = new MetaDataKey<IWebjarsSettings>() {
};

/**
* @return the webjars resource finder
*/
public static WebjarsResourceFinder finder() {
return FINDER;
}

/**
* installs the webjars resource finder and uses a set of default settings.
*
* @param app the wicket application
*/
public static void install(final Application app) {
install(app, new WebjarsSettings());
install(app, null);
}

/**
Expand All @@ -50,14 +41,17 @@ public static void install(final Application app, IWebjarsSettings settings) {
final IWebjarsSettings existingSettings = settings(app);

if (existingSettings == null) {
if (settings == null) {
settings = new WebjarsSettings();
}

app.setMetaData(WEBJARS_SETTINGS_METADATA_KEY, settings);

final List<IResourceFinder> finders = app.getResourceSettings().getResourceFinders();
final WebjarsResourceFinder finder = new WebjarsResourceFinder(settings);

if (!finders.contains(finder)) {
finders.add(finder);
FINDER = finder;
}
}
}
Expand All @@ -79,7 +73,14 @@ public static IWebjarsSettings settings(final Application app) {
*/
public static IWebjarsSettings settings() {
if (Application.exists()) {
return settings(Application.get());
IWebjarsSettings settings = Application.get().getMetaData(WEBJARS_SETTINGS_METADATA_KEY);

if (settings != null) {
return settings;
} else {
throw new IllegalStateException("you have to call WicketWebjars.install() before you can use an "
+ "IWebjarsResourceReference or any other component.");
}
}

throw new IllegalStateException("there is no active application assigned to this thread.");
Expand Down
Loading

0 comments on commit f27ce69

Please sign in to comment.