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

Woonsan Ko edited comment on LANG-417 at 10/23/13 2:32 PM:
-----------------------------------------------------------

I'd like to suggest the following:

{code}
public class ClassUtils {
    // <snip>
    public static String toAbsoluteResourceName(Package context, name);
    public static String toAbsoluteResourceName(Class context, name);
    // <snip>
}
{code}

or

{code}
public class ResourceUtils {
    public static String toAbsoluteName(Package context, name);
    public static String toAbsoluteName(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


was (Author: woon_san):
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)

Reply via email to