/** * Use this constructor if you have configured Velocity to use a ClasspathResourceLoader. The * templatePath will then be relative to the package for clazz * * @param clazz * @param templatePath * @param model * @param id */ public VelocityJavaScriptContributor(final Class<?> clazz, final String templatePath, final IModel<? extends Map<?, ?>> model, final String id) { super(Packages.absolutePath(clazz, templatePath), model); this.id = id; }
/** * Use this constructor if you have configured Velocity to use a ClasspathResourceLoader. The * templatePath will then be relative to the package for clazz * * @param clazz * @param templatePath * @param model * @param id */ public VelocityJavaScriptContributor(final Class<?> clazz, final String templatePath, final IModel<? extends Map<?, ?>> model, final String id) { super(Packages.absolutePath(clazz, templatePath), model); this.id = id; }
/** * Takes a package and a relative path to a resource and returns an absolute path to the * resource. For example, if the given package was java.lang and the relative path was * "../util/List", then "java/util/List" would be returned. * * @param p * The package to start at * @param relativePath * The relative path to the class * @return The absolute path */ public static String absolutePath(final Package p, final String relativePath) { return absolutePath(p.getName(), relativePath); }
/** * Takes a package and a relative path to a resource and returns an absolute path to the * resource. For example, if the given package was java.lang and the relative path was * "../util/List", then "java/util/List" would be returned. * * @param p * The package to start at * @param relativePath * The relative path to the class * @return The absolute path */ public static String absolutePath(final Package p, final String relativePath) { return absolutePath(p.getName(), relativePath); }
/** * Takes a package and a path to a resource and returns an absolute path to the resource. * <p> * See {@link #absolutePath(String, String)} for details. * * @param p * The package to start at * @param relativePath * The path to the resource * @return The absolute path */ public static String absolutePath(final Package p, final String relativePath) { return absolutePath(p.getName(), relativePath); }
/** * Takes a Class and a relative path to a class and returns any class at that relative path. For * example, if the given Class was java.lang.System and the relative path was "../util/List", * then the java.util.List class would be returned. * * @param scope * The package to start at * @param path * The relative path to the class * @return The class * @throws ClassNotFoundException */ public static Class<?> relativeClass(final Class<?> scope, final String path) throws ClassNotFoundException { return Class.forName(Packages.absolutePath(scope, path).replace('/', '.')); }
/** * Takes a Class and a relative path to a class and returns any class at that relative path. For * example, if the given Class was java.lang.System and the relative path was "../util/List", * then the java.util.List class would be returned. * * @param scope * The package to start at * @param path * The relative path to the class * @return The class * @throws ClassNotFoundException */ public static Class<?> relativeClass(final Class<?> scope, final String path) throws ClassNotFoundException { return Class.forName(Packages.absolutePath(scope, path).replace('/', '.')); }
/** * Takes a Class and a relative path to a class and returns any class at that relative path. For * example, if the given Class was java.lang.System and the relative path was "../util/List", * then the java.util.List class would be returned. * * @param scope * The package to start at * @param path * The relative path to the class * @return The class * @throws ClassNotFoundException */ public static Class relativeClass(final Class scope, final String path) throws ClassNotFoundException { return Class.forName(Packages.absolutePath(scope, path).replace('/', '.')); }
/** * @see org.apache.wicket.markup.html.IPackageResourceGuard#accept(java.lang.Class, * java.lang.String) */ public boolean accept(Class<?> scope, String path) { String absolutePath = Packages.absolutePath(scope, path); return acceptAbsolutePath(absolutePath); }
/** * @see org.apache.wicket.markup.html.IPackageResourceGuard#accept(java.lang.Class, * java.lang.String) */ public boolean accept(Class scope, String path) { String absolutePath = Packages.absolutePath(scope, path); return acceptAbsolutePath(absolutePath); }
/** * Takes a package and a relative path to a resource and returns an absolute path to the * resource. For example, if the given package was java.lang and the relative path was * "../util/List", then "java/util/List" would be returned. * * @param p * The package to start at * @param relativePath * The relative path to the class * @return The absolute path */ public static String absolutePath(final Class<?> p, final String relativePath) { String packName = (p != null ? extractPackageName(p) : ""); return absolutePath(packName, relativePath); }
/** * Takes a package and a relative path to a resource and returns an absolute path to the * resource. For example, if the given package was java.lang and the relative path was * "../util/List", then "java/util/List" would be returned. * * @param p * The package to start at * @param relativePath * The relative path to the class * @return The absolute path */ public static String absolutePath(final Class p, final String relativePath) { String packName = extractPackageName(p); return absolutePath(packName, relativePath); }
/** * Takes a package and a path to a resource and returns an absolute path to the resource. * <p> * See {@link #absolutePath(String, String)} for details. * * @param p * The package to start at * @param path * The path to the resource * @return The absolute path */ public static String absolutePath(final Class<?> p, final String path) { String packName = (p != null ? extractPackageName(p) : ""); return absolutePath(packName, path); }
private static String readResourceNoCache(Class scope, String file) { InputStream inputStream = null; try { final String path = Packages.absolutePath(scope, file); final IResourceStream resourceStream = Application.get().getResourceSettings().getResourceStreamLocator() .locate(scope, path); inputStream = resourceStream.getInputStream(); return Streams.readString(inputStream, "utf-8"); } catch (ResourceStreamNotFoundException e) { throw new RuntimeException(String.format("Can't find resource \"%s.%s\"", scope.getName(), file), e); } catch (IOException e) { throw new RuntimeException(String.format("Can't read resource \"%s.%s\"", scope.getName(), file), e); } finally { Closeables.closeQuietly(inputStream); } }
/** * Gets whether a resource for a given set of criteria exists. * * @param scope * This argument will be used to get the class loader for loading the package * resource, and to determine what package it is in. Typically this is the class in * which you call this method * @param path * The path to the resource * @param locale * The locale of the resource * @param style * The style of the resource (see {@link org.apache.wicket.Session}) * @return true if a resource could be loaded, false otherwise */ public static boolean exists(final Class<?> scope, final String path, final Locale locale, final String style) { String absolutePath = Packages.absolutePath(scope, path); return Application.get() .getResourceSettings() .getResourceStreamLocator() .locate(scope, absolutePath, style, locale, null) != null; }
/** * Obtains an {@link IResourceStream} from the application's * {@link IResourceStreamLocator#locate(Class, String)} * * @param scope * This argument will be used to get the class loader for loading the package * resource, and to determine what package it is in. * @param path * The path to the resource */ public PackageResourceStream(Class<?> scope, String path) { String absolutePath = Packages.absolutePath(scope, path); resourceStream = Application.get().getResourceSettings().getResourceStreamLocator().locate( scope, absolutePath, null, null, null); if (resourceStream == null) { throw new WicketRuntimeException("Cannot find resource with " + scope.getName() + " and path " + path); } }
/** * Obtains an {@link IResourceStream} from the application's * {@link IResourceStreamLocator#locate(Class, String)} * * @param scope * This argument will be used to get the class loader for loading the package * resource, and to determine what package it is in. * @param path * The path to the resource */ public PackageResourceStream(Class scope, String path) { String absolutePath = Packages.absolutePath(scope, path); resourceStream = Application.get().getResourceSettings().getResourceStreamLocator().locate( scope, absolutePath, null, null, null); if (resourceStream == null) { throw new WicketRuntimeException("Cannot find resource with " + scope.getName() + " and path " + path); } }
/** * Checks whether a resource for a given set of criteria exists. * * @param scope * This argument will be used to get the class loader for loading the package * resource, and to determine what package it is in. Typically this is the class in * which you call this method * @param path * The path to the resource * @param locale * The locale of the resource * @param style * The style of the resource (see {@link org.apache.wicket.Session}) * @param variation * The component's variation (of the style) * @return {@code true} if a resource could be loaded, {@code false} otherwise */ public static boolean exists(final Class<?> scope, final String path, final Locale locale, final String style, final String variation) { String absolutePath = Packages.absolutePath(scope, path); return Application.get() .getResourceSettings() .getResourceStreamLocator() .locate(scope, absolutePath, style, variation, locale, null, false) != null; }
private ResourceReference.UrlAttributes getUrlAttributes(Locale locale, String style, String variation) { IResourceStreamLocator locator = Application.get() .getResourceSettings() .getResourceStreamLocator(); String absolutePath = Packages.absolutePath(getScope(), getName()); IResourceStream stream = locator.locate(getScope(), absolutePath, style, variation, locale, null, false); if (stream == null) return new ResourceReference.UrlAttributes(null, null, null); return new ResourceReference.UrlAttributes(stream.getLocale(), stream.getStyle(), stream.getVariation()); }
private ResourceReference.UrlAttributes getUrlAttributes(Locale locale, String style, String variation) { IResourceStreamLocator locator = Application.get() .getResourceSettings() .getResourceStreamLocator(); String absolutePath = Packages.absolutePath(getScope(), getName()); IResourceStream stream = locator.locate(getScope(), absolutePath, style, variation, locale, null, false); if (stream == null) return new ResourceReference.UrlAttributes(null, null, null); return new ResourceReference.UrlAttributes(stream.getLocale(), stream.getStyle(), stream.getVariation()); }