List of usage examples for org.apache.wicket.request.resource ResourceReference getScope
public Class<?> getScope()
From source file:fiftyfive.wicket.js.locator.DefaultJavaScriptDependencyLocator.java
License:Apache License
/** * Loads the given ResourceReference as an IResourceStream or returns * {@code null} if the resource could not be found. */// ww w .j a va 2 s. com private IResourceStream load(ResourceReference ref) { IResourceStreamLocator locator = Application.get().getResourceSettings().getResourceStreamLocator(); Class<?> scope = ref.getScope(); String path = Packages.absolutePath(scope, ref.getName()); return locator.locate(scope, path); }
From source file:fiftyfive.wicket.js.locator.SprocketDependencyCollector.java
License:Apache License
/** * Parse the given JavaScript file stream for sprockets dependency * declarations. For each dependency that is found, recursively invoke * the JavaScriptDependencyLocator to locate the dependency and parse it * for its dependencies, and so on. All the scripts that are found as a * result of this process will be added to the specified * DependencyCollection.//www.j a v a 2s .c o m * * @param ref The location of the JavaScript file to parse * @param stream An opened stream of the JavaScript file to parse * @param dependencies Target collection to which all dependencies will * be added */ public void collectDependencies(ResourceReference ref, IResourceStream stream, DependencyCollection dependencies) { if (null == stream) return; // Parse the resource, looking for Sprocket dependency declarations LOGGER.debug("Parsing: {}", ref.getName()); List<Sprocket> sprockets = parseSprockets(stream); // After parsing is complete, loop through what we found and // process their dependencies recursively. for (Sprocket sp : sprockets) { if (sp.isLibrary()) { this.locator.findLibraryScripts(sp.getPath(), dependencies); } else { Class<?> scope = ref.getScope(); this.locator.findResourceScripts(scope, concatPaths(ref.getName(), sp.getPath()), dependencies); } } }
From source file:fiftyfive.wicket.js.locator.SprocketsDependencyCollector.java
License:Apache License
/** * Parse the given JavaScript file stream for sprockets dependency * declarations. For each dependency that is found, recursively invoke * the JavaScriptDependencyLocator to locate the dependency and parse it * for its dependencies, and so on. All the scripts that are found as a * result of this process will be added to the specified * DependencyCollection.//from ww w. j av a 2 s . c o m * * @param ref The location of the JavaScript file to parse * @param stream An opened stream of the JavaScript file to parse * @param dependencies Target collection to which all dependencies will * be added */ public void collectDependencies(ResourceReference ref, IResourceStream stream, DependencyCollection dependencies) { if (null == stream) return; // Parse the resource, looking for Sprocket dependency declarations LOGGER.debug("Parsing: {}", ref.getName()); List<Sprocket> sprockets = parseSprocketsFromStream(stream); // After parsing is complete, loop through what we found and // process their dependencies recursively. for (Sprocket sp : sprockets) { if (sp.isLibrary()) { this.locator.findLibraryScripts(sp.getPath(), dependencies); } else { Class<?> scope = ref.getScope(); this.locator.findResourceScripts(scope, concatPaths(ref.getName(), sp.getPath()), dependencies); } } }
From source file:fiftyfive.wicket.js.MergedJavaScriptBuilder.java
License:Apache License
/** * Adds a JavaScript resource to the list of merged resources. The * dependencies of the script will also be added automatically. * Refer to the <a href="package-summary.html#dependency-resolution">dependency * resolution guide</a> for more information. * * @see JavaScriptDependencySettings/*from ww w .ja va 2 s.co m*/ */ public MergedJavaScriptBuilder addScript(ResourceReference ref) { getDependencyLocator().findResourceScripts(ref.getScope(), ref.getName(), this.deps); return this; }
From source file:jp.javelindev.wicket.resourcedecoration.GroupingHeaderResponse.java
License:Apache License
@Override protected void renderCollection(Set<ResourceReferenceAndStringData> alreadyRendered, BasicGroupingKey key, HttpAggregatingResourceReferenceCollection coll) { // for debugging: getRealResponse().renderString("<!-- " + key + " -->\n"); // TODO: I'm not sure why yet, but our aggregator fails on wicket-event.js, so for now, we // skip aggregating all "UNKNOWN" references if (ResourceGroup.UNKNOWN.equals(key.getGroup())) { super.renderCollection(alreadyRendered, key, coll); return;//from w w w . j av a2 s . c o m } // build an aggregated URL: StringBuilder refs = new StringBuilder(); boolean first = true; for (ResourceReferenceAndStringData data : coll) { ResourceReference ref = data.getReference(); if (!first) { refs.append('|'); } refs.append(ref.getScope().getName()).append(':').append(ref.getName()); first = false; } PageParameters parameters = new PageParameters(); parameters.add("refs", refs); parameters.add("type", key.isCss() ? "css" : "js"); ResourceReference ref = new PackageResourceReference("merged-resources"); if (key.isCss()) { getRealResponse().renderCSSReference(ref, parameters, null); } else { getRealResponse().renderJavaScriptReference(ref, parameters, null); } }
From source file:name.martingeisse.wicket.component.sprite.SpriteImage.java
License:Open Source License
@Override protected void onComponentTag(ComponentTag tag) { // check for allowed tags final String originalTagName = tag.getName(); if (!originalTagName.equalsIgnoreCase("img") && !originalTagName.equalsIgnoreCase("span") && !originalTagName.equalsIgnoreCase("div")) { String msg = String.format( "Component [%s] (path = [%s]) must be applied to a tag of type IMG, SPAN or DIV, not: %s", getId(), getPath(), tag.toUserDebugString()); findMarkupStream().throwMarkupException(msg); }/*from w ww.jav a 2 s.c o m*/ // make the image generate its resource reference (e.g. from a specified path), ignoring the tag name for now try { tag.setName("img"); super.onComponentTag(tag); } finally { tag.setName(originalTagName); } // localize the resource reference (including a fallback mechanism for nonexisting resource files) ResourceReference resourceReference = getImageResourceReference(); ResourceReference.UrlAttributes urlAttributes = resourceReference.getUrlAttributes(); ResourceReference.Key spriteKey = new ResourceReference.Key(resourceReference.getScope().getName(), resourceReference.getName(), urlAttributes.getLocale(), urlAttributes.getStyle(), urlAttributes.getVariation()); // look up the sprite and fall back to default behavior if not found ApplicationSpriteSupport applicationSpriteSupport = ApplicationSpriteSupport.get(getApplication()); if (applicationSpriteSupport == null) { super.onComponentTag(tag); return; } SpriteRegistry spriteRegistry = applicationSpriteSupport.getSpriteRegistry(); SpriteReference spriteReference = spriteRegistry.lookup(spriteKey); if (spriteReference == null) { super.onComponentTag(tag); return; } // IMG tags cannot handle CSS sprites. They're inline, so we convert to a SPAN. if (tag.getName().equalsIgnoreCase("img")) { tag.setName("span"); } // remove the SRC attribute -- it doesn't hurt, but it's ugly tag.getAttributes().remove("src"); // prepare modification of the style attribute StringBuilder styleBuilder; String previousStyle = tag.getAttribute("style"); if (previousStyle == null) { styleBuilder = new StringBuilder(); } else { styleBuilder = new StringBuilder(previousStyle).append("; "); } // SPAN tags must be styled as inline-block to support width/height properly if (tag.getName().equalsIgnoreCase("span")) { styleBuilder.append("display: inline-block; "); } // modify the style attribute according to the sprite reference styleBuilder.append("background-image: url(").append(spriteReference.getAtlas().getUrl()); styleBuilder.append("); background-position: -").append(spriteReference.getX()); styleBuilder.append("px -").append(spriteReference.getY()); styleBuilder.append("px; width: ").append(spriteReference.getWidth()); styleBuilder.append("px; height: ").append(spriteReference.getHeight()); styleBuilder.append("px; "); // store modified style tag.getAttributes().put("style", styleBuilder.toString()); }
From source file:name.martingeisse.wicketbits.sprite.SpriteImage.java
License:Open Source License
@Override protected void onComponentTag(ComponentTag tag) { // check for allowed tags final String originalTagName = tag.getName(); if (!originalTagName.equalsIgnoreCase("img") && !originalTagName.equalsIgnoreCase("span") && !originalTagName.equalsIgnoreCase("div")) { String msg = String.format( "Component [%s] (path = [%s]) must be applied to a tag of type IMG, SPAN or DIV, not: %s", getId(), getPath(), tag.toUserDebugString()); findMarkupStream().throwMarkupException(msg); }/*from w w w.ja v a2 s . c om*/ // make the image generate its resource reference (e.g. from a specified path), ignoring the tag name for now try { tag.setName("img"); super.onComponentTag(tag); } finally { tag.setName(originalTagName); } // localize the resource reference (including a fallback mechanism for nonexisting resource files) ResourceReference resourceReference = getImageResourceReference(); ResourceReference.UrlAttributes urlAttributes = resourceReference.getUrlAttributes(); ResourceReference.Key spriteKey = new ResourceReference.Key(resourceReference.getScope().getName(), resourceReference.getName(), urlAttributes.getLocale(), urlAttributes.getStyle(), urlAttributes.getVariation()); // look up the sprite and fall back to default behavior if not found SpriteRegistry spriteRegistry = ApplicationSpriteSupport.get(getApplication()).getSpriteRegistry(); SpriteReference spriteReference = spriteRegistry.lookup(spriteKey); if (spriteReference == null) { super.onComponentTag(tag); return; } // IMG tags cannot handle CSS sprites. They're inline, so we convert to a SPAN. if (tag.getName().equalsIgnoreCase("img")) { tag.setName("span"); } // remove the SRC attribute -- it doesn't hurt, but it's ugly tag.getAttributes().remove("src"); // prepare modification of the style attribute StringBuilder styleBuilder; String previousStyle = tag.getAttribute("style"); if (previousStyle == null) { styleBuilder = new StringBuilder(); } else { styleBuilder = new StringBuilder(previousStyle).append("; "); } // SPAN tags must be styled as inline-block to support width/height properly if (tag.getName().equalsIgnoreCase("span")) { styleBuilder.append("display: inline-block; "); } // modify the style attribute according to the sprite reference styleBuilder.append("background-image: url(").append(spriteReference.getAtlas().getUrl()); styleBuilder.append("); background-position: -").append(spriteReference.getX()); styleBuilder.append("px -").append(spriteReference.getY()); styleBuilder.append("px; width: ").append(spriteReference.getWidth()); styleBuilder.append("px; height: ").append(spriteReference.getHeight()); styleBuilder.append("px; "); // store modified style tag.getAttributes().put("style", styleBuilder.toString()); }
From source file:org.jabox.webapp.menubuttons.IconButton.java
License:Open Source License
private boolean existImage(final ResourceReference rr) { return rr.getScope().getResource(ICON_PNG) != null; }