commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Woonsan Ko (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LANG-417) ClassUtils: method for turning FQN into resource path
Date Tue, 22 Oct 2013 17:50:43 GMT

    [ https://issues.apache.org/jira/browse/LANG-417?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13802060#comment-13802060
] 

Woonsan Ko commented on LANG-417:
---------------------------------

I'd like to suggest the following:

{code}
public class ResourceUtils {
    public static String toAbsoluteResourceName(Package context, name);
    public static String toAbsoluteResourceName(Class context, name);
}
{code}

According to the original description above, he just wanted to replace a resource name by
an absolute resource name. e.g, [ com.example.Hello.class, 'HelloMessage.properties' ] ->
'com/example/HelloMessage.properties'.
In this sense, URL doesn't seem to be proper. URL is likely to have something like 'file:///...',
which is different from the original request. I assume he wanted to use something like ClassLoader#getResource()
in the end.
Also, the suggested api, toResourcePath(String fqName), doesn't seem to be necessary in this
sense.

By the way, I think we'd better use 'AbsoluteResourceName' instead of 'ResourcePath' because
the former one is similar to the javadoc explanation in java.lang.Class#getResource(name)
(quote: "Before delegation, an *absolute resource name* is constructed from the given resource
name using this algorithm"), and 'path' may sound confusing because the return value doesn't
represent a full (file) path at all.

Just my two cents,

Woonsan

> ClassUtils: method for turning FQN into resource path
> -----------------------------------------------------
>
>                 Key: LANG-417
>                 URL: https://issues.apache.org/jira/browse/LANG-417
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Paul Benedict
>             Fix For: Patch Needed
>
>
> I commonly need a FQ path to a resource within the same location as a class file. I recommend
the addition of this method:
> public String getPackageResourcePath(Class clazz, String resourceName)
>     StringBuffer buf = new StringBuffer();
>     buf.append(ClassUtils.getPackageName(getClass()).replace('.', '/'));
>     buf.append("/");
>     buf.append(resourceName);
>     return  buf.toString();
> }



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Mime
View raw message