[Design of POJO Server] - Re: VFS Permissions - JBMICROCONT-149
by adrian@jboss.org
"alesj" wrote : "alesj" wrote : "adrian(a)jboss.org" wrote :
| | | This requires something in the VFS, my suggestion was to add
| | | VFSUtils.getRealURL(vfsFile);
| | |
| | Should I hold off VFS 2.0.0.GA until these features get into VFS?
| I see Anil already added this to VFS.
| But it looks wrong. ;-)
|
That's the problem with quick and dirty. ;-)
I said it should be
VFSUtils.getRealURL(vfsFile) above but Anil has done URL.
What should happen is this uses the implemented details of the VirtualFile
to delegate the request to the vfs handler.
Only the protocol specific handler knows how it maps its urls to a real url.
Its called object orientated programming. :-)
The list of if statements is the clue.
if you have to write code like (which is also incredibly inefficient)
| if(vfsURL.getPath().endsWith("jar"))
| ...
| if(vfsURL.getProtocol().startsWith("vfsfile"))
| ...
| if(vfsURL.getProtocol().startsWith("vfszip"))
| ...
| etc.
|
You're almost certainly doing something wrong.
Correct would be something like:
| public URL getRealURL(VirtualFile file)
| {
| // public methods should always check parameters to give useful error messages
| if (file == null)
| throw new IllegalArgumentException("null file);
| VirtualFileHandler handler = file.getHandler();
| return handler.getRealURL(); // NEW METHOD
| }
|
But at least its in the right project now. ;-)
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4188419#4188419
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4188419
17 years, 5 months
[Design of POJO Server] - Re: VFS Permissions - JBMICROCONT-149
by alesj
"alesj" wrote : "adrian(a)jboss.org" wrote :
| | This requires something in the VFS, my suggestion was to add
| | VFSUtils.getRealURL(vfsFile);
| |
| Should I hold off VFS 2.0.0.GA until these features get into VFS?
I see Anil already added this to VFS.
But it looks wrong. ;-)
| /**
| * Get the Real URL
| * @param vfsURL
| * @return
| * @throws Exception
| */
| public static URL getRealURL(URL vfsURL) throws Exception
| {
| if(vfsURL.getPath().endsWith("jar"))
| {
| String urlStr = "jar:" + FILE_PROTOCOL + ":" + vfsURL.getPath() + JAR_URL_SEPARATOR;
| return new URL(urlStr);
| }
|
| if(vfsURL.getProtocol().startsWith("vfsfile"))
| return new URL(FILE_PROTOCOL, vfsURL.getHost(), vfsURL.getPort(), vfsURL.getFile());
|
| if(vfsURL.getProtocol().startsWith("vfszip"))
| {
| String urlStr = vfsURL.toExternalForm();
| //nested file
| int indexJar = urlStr.indexOf(".jar");
| String beforejar = urlStr.substring("vfszip:".length(), urlStr.indexOf(".jar"));
| String afterjar = urlStr.substring(indexJar + 1 + ".jar".length());
| return new URL("jar:file:" + beforejar + ".jar " + JAR_URL_SEPARATOR + afterjar);
| }
| if(log.isTraceEnabled())
| log.trace("getRealURL did not have a match for:"+vfsURL.toExternalForm());
| return vfsURL;
| }
|
First some simple code critique.
If you add something to project you don't sustain,
be fair and add javadocs as it should be done.
Since this is probably gonna be called for every class we load,
some more constants won't kill you.
Dunno how much optimization javac puts on "vfszip."length() and repeated ".jar".
Tests should be more exhaustive.
As I see some extra space after last ".jar that's probably not supposed to be there.
Dunno how this would work.
But in general, jar/zip handling is completely broken.
First, it should be the same code that handles it,
since, although we currently use vfszip, user can still fall back to old vfsjar handling.
And they are both the same as far as feature set goes (it's just that we have winz lock problems on vfsjar).
But the biggest problem I see is how are you gonna handle multiple nested jars.
Dunno what's the proper/real url for those, but I very much doubt it's how your code does it.
I guess this would have to be an impl of VirtualFileHandlers, not just VFSUtils.
Conclusion.
Either this is done right, or it goes out.
I'll leave it for now, but will check on it before I do 2.0.0.GA.
If you need any help on writing this, open a new forum post.
And I'll see what can be done. ;-)
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4188403#4188403
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4188403
17 years, 5 months