commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henri Yandell (JIRA)" <>
Subject [jira] Commented: (LANG-417) ClassUtils: method for turning FQN into resource path
Date Sun, 09 Mar 2008 05:27:46 GMT


Henri Yandell commented on LANG-417:

Seems worthwhile. I've used similar in the past  - mine was loadFromClasspath, but I think
it's good to keep the loading semantics out of this.

Name wise; I think we should use toXxx rather than getXxx. 

Based on my use case back then, I'd also want:

    public String toResourcePath(String fqName)...

Though, chatting with you on IM about this, I think I'd also have wanted something to turn
foo.Blah.class into "".  Which would annoyingly have the same signature
as yours.

Also based on my previous use case, not sure if we'd want the ClassLoader.getResource(...)
call to be wrapped into this.

    public URL getResourceUrl(String resourceName)...
    public URL getResourceUrl(Class clazz, String resourceName)...

etc etc.  With javadoc showing how to use that with FileUtils.readFileToString(FileUtils.toFile(getResourceUrl(....)))

Maybe that last pair is too much. Not saving much and we'd need ClassLoader overloads. In
the end it's easier to just code it.

So... continuing to think out loud. Maybe just:

    public String toResourcePath(String fqName)...
    public String toResourcePathSamePackage(Class context, String fqName)...  [yours above]
    public String toResourcePathSameClass(Class context, String fqName)...  [mine above]

Dunno. Thoughts?

> ClassUtils: method for turning FQN into resource path
> -----------------------------------------------------
>                 Key: LANG-417
>                 URL:
>             Project: Commons Lang
>          Issue Type: New Feature
>            Reporter: Paul Benedict
>             Fix For: 2.4
> 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 is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message