I am working with a program that launches a URL into a browser
instance. Within this URL is query string parameter that contains a
Mac file path encoded as a URL. For short filenames, the filename
within the file path URL is normal. However, if the filename
(including the file extension, and extension separator '.') is >= 32
characters, the program truncates the filename at 20 characters, adds a
percent sign, and then adds what looks to be a 10-digit hex value. For
example, a filename that looks like this:
01234567901234567901234567.wma
ends up looking like this in the URL:
012345679012345679%252317997C.wma
I assume that this is for compatibility with Classic. However, I can't
seem to find the right APIs to convert back to the normal filename,
which my Java applet needs. Are such APIs exposed anywhere, and
hopefully accessible by Java? Are there some Mac-aware Java APIs that
are aware of this compatibility convention, and can handle either
filename? Thanks for your help ahead of time.
Patrick Machielse - 28 Jun 2005 23:38 GMT
> a filename that looks like this:
>
[quoted text clipped - 10 lines]
> are aware of this compatibility convention, and can handle either
> filename? Thanks for your help ahead of time.
tell a little bit more about what you are doing, and which frameworks
you are using.
The best way is to write out long filenames in the first place. Carbon
must have API supporting 'long' filenames. But if you wan't to
manipulate URL's, have a look at CFURL (C, CoreFoundation) or NSURL
(Objective-C, Cocoa).
patrick
Brad - 29 Jun 2005 04:57 GMT
I don't have control over the URL that is handed to me. The parameter
I care about is a local file name to a file that my Java applet (living
on the web page at the URL) needs to write data to. My applet will be
signed, so I'll be able to do local file access. The URL looks
something like this:
http://www.mysite.com/handleUrl.aspx?firstParam=blahblahblah&filename=file:///Ha
rdDrive/Users/Brad/Desktop/mylongfilename%252317997C.wma
As for framework, I'm in a Java applet, so whatever framework(s)
is(are) accessible to the applet is the framework I'll be using. I
haven't called any platform-specific Java APIs before, so I don't (yet)
know the details of whether/how Carbon and/or Cocoa is accessible via
Java, and/or whether Apple has it's own additional Java classes that
provide functionality on top of (or in addition to) Carbon and/or
Cocoa.
It seems like the problem I'm having is a bit different from normal URL
handling, though. I say this because in the Finder, the long file name
looks normal, without the abbreviation. I'm assuming the program
that's creating the full URL is calling some API to abbreviate the file
name with the % and 10 digit hex code. I'm hoping that I can use these
same APIs to un-abbreviate it. I assume these APIs would be outside of
the URL APIs you suggest, since it's really a file name problem. Its
possible that the abbrevation is some program-specific convention that
the program created itself, but I hope not!
Chris Baum - 29 Jun 2005 06:00 GMT
> I'm assuming the program
> that's creating the full URL is calling some API to abbreviate the file
> name with the % and 10 digit hex code. I'm hoping that I can use these
> same APIs to un-abbreviate it.
Yes, it's surely an old Classic app that was still using FSSpecs for
local file references - limited to 31 roman characters.
I don't know anything about Java but if you can in fact link to Carbon,
you simply want to use the Carbon api FSMakeFSSpec to create an FSSpec
from that mangled full path, then FSpOpenDF to open the file for
writing, FSWrite, FSClose.
Afraid I don't know about linking with Carbon framework from Java app.
. .
Patrick Machielse - 29 Jun 2005 09:50 GMT
> > I'm assuming the program
> > that's creating the full URL is calling some API to abbreviate the file
[quoted text clipped - 10 lines]
>
> Afraid I don't know about linking with Carbon framework from Java app.
I guess a (the?) way to do this is to use JNI; you write a C function
(linking to whatever framework you need) and make that available as a
Java call. However, I'm not sure if this is easilly done form an applet,
even if it is signed...
The best way would still be to not receive mangled URLs in the first
place (And I hope there can never by a mylongfilename%20otherdigits?)
patrick