/** * Finds the resource with the given name and converts it to a simple string. * * @param name Name of the desired resource. * @return The resource converted to a string, or <jk>null</jk> if the resource could not be found. * @throws IOException */ public String getString(String name) throws IOException { return getString(baseClass, name, null); }
/** * Finds the resource with the given name and converts it to a simple string. * * @param name Name of the desired resource. * @param locale The locale. Can be <jk>null</jk>. * @return The resource converted to a string, or <jk>null</jk> if the resource could not be found. * @throws IOException */ public String getString(String name, Locale locale) throws IOException { return getString(baseClass, name, locale); }
/** * Finds the resource with the given name and converts it to a simple string. * * @param name Name of the desired resource. * @param locale The locale. Can be <jk>null</jk>. * @return The resource converted to a string, or <jk>null</jk> if the resource could not be found. * @throws IOException */ public String getString(String name, Locale locale) throws IOException { return getString(baseClass, name, locale); }
/** * Finds the resource with the given name and converts it to a simple string. * * @param name Name of the desired resource. * @return The resource converted to a string, or <jk>null</jk> if the resource could not be found. * @throws IOException */ public String getString(String name) throws IOException { return getString(baseClass, name, null); }
/** * Finds the resource with the given name and converts it to a simple string. * * @param name Name of the desired resource. * @param locale The locale. Can be <jk>null</jk>. * @return The resource converted to a string, or <jk>null</jk> if the resource could not be found. * @throws IOException */ public String getString(String name, Locale locale) throws IOException { return getString(baseClass, name, locale); }
/** * Finds the resource with the given name and converts it to a simple string. * * @param baseClass * Overrides the default class to use for retrieving the classpath resource. * <br>If <jk>null<jk>, uses the base class passed in through the constructor of this class. * @param name Name of the desired resource. * @return The resource converted to a string, or <jk>null</jk> if the resource could not be found. * @throws IOException */ public String getString(Class<?> baseClass, String name) throws IOException { return getString(baseClass, name, null); }
/** * Finds the resource with the given name and converts it to a simple string. * * @param name Name of the desired resource. * @return The resource converted to a string, or <jk>null</jk> if the resource could not be found. * @throws IOException */ public String getString(String name) throws IOException { return getString(baseClass, name, null); }
/** * Finds the resource with the given name and converts it to a simple string. * * @param baseClass * Overrides the default class to use for retrieving the classpath resource. * <br>If <jk>null<jk>, uses the base class passed in through the constructor of this class. * @param name Name of the desired resource. * @return The resource converted to a string, or <jk>null</jk> if the resource could not be found. * @throws IOException */ public String getString(Class<?> baseClass, String name) throws IOException { return getString(baseClass, name, null); }
/** * Finds the resource with the given name and converts it to a simple string. * * @param baseClass * Overrides the default class to use for retrieving the classpath resource. * <br>If <jk>null<jk>, uses the base class passed in through the constructor of this class. * @param name Name of the desired resource. * @return The resource converted to a string, or <jk>null</jk> if the resource could not be found. * @throws IOException */ public String getString(Class<?> baseClass, String name) throws IOException { return getString(baseClass, name, null); }
/** * Retrieves the specified classpath resource and returns the contents as a string. * * <p> * Same as {@link Class#getResourceAsStream(String)} except if it doesn't find the resource on this class, searches * up the parent hierarchy chain. * * <p> * If the resource cannot be found in the classpath, then an attempt is made to look relative to the JVM working directory. * <br>Path traversals outside the working directory are not allowed for security reasons. * * @param name Name of the desired resource. * @return The resource converted to a string, or <jk>null</jk> if the resource could not be found. * @throws IOException */ protected String getClasspathResourceAsString(String name) throws IOException { return rm.getString(name); }
/** * Retrieves the specified classpath resource and returns the contents as a string. * * <p> * Same as {@link Class#getResourceAsStream(String)} except if it doesn't find the resource on this class, searches * up the parent hierarchy chain. * * <p> * If the resource cannot be found in the classpath, then an attempt is made to look relative to the JVM working directory. * <br>Path traversals outside the working directory are not allowed for security reasons. * * @param name Name of the desired resource. * @return The resource converted to a string, or <jk>null</jk> if the resource could not be found. * @throws IOException */ protected String getClasspathResourceAsString(String name) throws IOException { return rm.getString(name); }
/** * Retrieves the specified classpath resource and returns the contents as a string. * * <p> * Same as {@link Class#getResourceAsStream(String)} except if it doesn't find the resource on this class, searches * up the parent hierarchy chain. * * <p> * If the resource cannot be found in the classpath, then an attempt is made to look relative to the JVM working directory. * <br>Path traversals outside the working directory are not allowed for security reasons. * * @param name Name of the desired resource. * @return The resource converted to a string, or <jk>null</jk> if the resource could not be found. * @throws IOException */ protected String getClasspathResourceAsString(String name) throws IOException { return rm.getString(name); }
/** * Same as {@link #getClasspathResourceAsString(String)} except also looks for localized-versions of the file. * * <p> * If the <code>locale</code> is specified, then we look for resources whose name matches that locale. * <br>For example, if looking for the resource <js>"MyResource.txt"</js> for the Japanese locale, we will look for * files in the following order: * <ol> * <li><js>"MyResource_ja_JP.txt"</js> * <li><js>"MyResource_ja.txt"</js> * <li><js>"MyResource.txt"</js> * </ol> * * @param name Name of the desired resource. * @param locale The locale. Can be <jk>null</jk>. * @return The resource converted to a string, or <jk>null</jk> if the resource could not be found. * @throws IOException */ protected String getClasspathResourceAsString(String name, Locale locale) throws IOException { return rm.getString(name, locale); }
/** * Same as {@link #getClasspathResourceAsString(String)} except also looks for localized-versions of the file. * * <p> * If the <code>locale</code> is specified, then we look for resources whose name matches that locale. * <br>For example, if looking for the resource <js>"MyResource.txt"</js> for the Japanese locale, we will look for * files in the following order: * <ol> * <li><js>"MyResource_ja_JP.txt"</js> * <li><js>"MyResource_ja.txt"</js> * <li><js>"MyResource.txt"</js> * </ol> * * @param name Name of the desired resource. * @param locale The locale. Can be <jk>null</jk>. * @return The resource converted to a string, or <jk>null</jk> if the resource could not be found. * @throws IOException */ protected String getClasspathResourceAsString(String name, Locale locale) throws IOException { return rm.getString(name, locale); }
/** * Same as {@link #getClasspathResourceAsString(String)} except also looks for localized-versions of the file. * * <p> * If the <code>locale</code> is specified, then we look for resources whose name matches that locale. * <br>For example, if looking for the resource <js>"MyResource.txt"</js> for the Japanese locale, we will look for * files in the following order: * <ol> * <li><js>"MyResource_ja_JP.txt"</js> * <li><js>"MyResource_ja.txt"</js> * <li><js>"MyResource.txt"</js> * </ol> * * @param name Name of the desired resource. * @param locale The locale. Can be <jk>null</jk>. * @return The resource converted to a string, or <jk>null</jk> if the resource could not be found. * @throws IOException */ protected String getClasspathResourceAsString(String name, Locale locale) throws IOException { return rm.getString(name, locale); }
/** * Reads the input stream from {@link #getClasspathResource(String, Locale)} into a String. * * <h5 class='section'>Example:</h5> * <p class='bcode w800'> * <jc>// A rest method that (unsafely!) returns the contents of a localized file </jc> * <jc>// from the classpath.</jc> * <ja>@RestMethod</ja>(path=<js>"/foo"</js>) * <jk>public</jk> String myMethod(RestRequest req, <ja>@Query</ja>(<js>"file"</js>) String file) { * <jk>return</jk> getContext().getClasspathResourceAsString(file, req.getLocale()); * } * </p> * * <h5 class='section'>See Also:</h5> * <ul> * <li class='jf'>{@link #REST_classpathResourceFinder} * </ul> * * @param name The resource name. * @param locale * Optional locale. * <br>If <jk>null</jk>, won't look for localized file names. * @return The contents of the stream as a string, or <jk>null</jk> if the resource could not be found. * @throws IOException If resource could not be found. */ public String getClasspathResourceAsString(String name, Locale locale) throws IOException { return staticResourceManager.getString(name, locale); }
/** * Reads the input stream from {@link #getClasspathResource(String, Locale)} into a String. * * <h5 class='section'>Example:</h5> * <p class='bcode w800'> * <jc>// A rest method that (unsafely!) returns the contents of a localized file </jc> * <jc>// from the classpath.</jc> * <ja>@RestMethod</ja>(path=<js>"/foo"</js>) * <jk>public</jk> String myMethod(RestRequest req, <ja>@Query</ja>(<js>"file"</js>) String file) { * <jk>return</jk> getContext().getClasspathResourceAsString(file, req.getLocale()); * } * </p> * * <h5 class='section'>See Also:</h5> * <ul> * <li class='jf'>{@link #REST_classpathResourceFinder} * </ul> * * @param name The resource name. * @param locale * Optional locale. * <br>If <jk>null</jk>, won't look for localized file names. * @return The contents of the stream as a string, or <jk>null</jk> if the resource could not be found. * @throws IOException If resource could not be found. */ public String getClasspathResourceAsString(String name, Locale locale) throws IOException { return staticResourceManager.getString(name, locale); }
@Override /* Parameter */ public String resolve(VarResolverSession session, String key) throws Exception { RestRequest req = session.getSessionObject(RestRequest.class, SESSION_req, false); if (req != null) { ReaderResource rr = req.getClasspathReaderResource(key); return (rr == null ? null : rr.toCommentStrippedString()); } ClasspathResourceManager crm = session.getSessionObject(ClasspathResourceManager.class, SESSION_crm, false); if (crm != null) return crm.getString(key); return null; } }
@Override /* Parameter */ public String resolve(VarResolverSession session, String key) throws Exception { RestRequest req = session.getSessionObject(RestRequest.class, SESSION_req, false); if (req != null) { ReaderResource rr = req.getClasspathReaderResource(key); return (rr == null ? null : rr.toCommentStrippedString()); } ClasspathResourceManager crm = session.getSessionObject(ClasspathResourceManager.class, SESSION_crm, false); if (crm != null) return crm.getString(key); return null; } }
@Override /* Parameter */ public String resolve(VarResolverSession session, String key) throws Exception { RestRequest req = session.getSessionObject(RestRequest.class, SESSION_req, false); if (req != null) { ReaderResource rr = req.getClasspathReaderResource(key); return (rr == null ? null : rr.toCommentStrippedString()); } ClasspathResourceManager crm = session.getSessionObject(ClasspathResourceManager.class, SESSION_crm, false); if (crm != null) return crm.getString(key); return null; } }