Hi,

I had a bit of trouble getting the base URL setting to work, but I have done
something similar to resolve the problem of relative/absolute paths.

In my servlet I used Thomas' suggestion of retrieving the URL of the
servlet. The code below will do this (may need modification depending on the
request that came into the servlet):

            String file = request.getRequestURI();
            file = file.substring(0,file.lastIndexOf('/')+1);
            URL reconstructedURL = new URL(request.getScheme(),
                                           request.getServerName(),
                                           request.getServerPort(),
                                           file);

This will return you something like "http://hostname:123/contextname/";.

I then pass this "baseUrl" to my class which generates the SVG doc and set
my stylesheet location like this (so now we have an absolute path and the
JPG Transcoder classes work fine).

       ProcessingInstruction pi =
doc.createProcessingInstruction("xml-stylesheet", "type=\"text/css\"
href=\"" + baseUrl.toString()+"resources/styles/style.css" + "\"" );
        doc.insertBefore(pi, doc.getDocumentElement());

Thanks for all your help with this,

Regards,
Dylan.

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: 21 April 2006 11:47
To: [email protected]
Cc: [email protected]
Subject: Re: CSS and JS being access as a webapp resource by SVG

Hi Dylan, Tonny,

   To extend on Tonny's answer a little.  In Batik all references are 
resolved relative to the
Document's base URL (Document.getURL). The problem you have is that when 
you
build the document 'in memory' it doesn't have any base URL.  There are 
two main
ways to 'fix' this.  First is to give the Document a base url by calling:
        batik.dom.svg.SVGOMDocument.setURLObject

   This is a Batik specific method for providing the Document's base url. 
You can also
set the 'xml:base' attribute on the root SVG element, which is a standard. 
 Then the
questions becomes what to set it too.

    I think you can get the URL of the servlet which would probably be a 
good choice.

Tonny Kohar <[EMAIL PROTECTED]> wrote on 04/20/2006 10:59:10 PM:

> For simple workaround in the client side, you could use baseURL on the
> document to resolve the resources eg: css,js stuff, assuming that those
> files are located in tree folder / directory structure inside the
> baseURL.
> 
> Regards
> Tonny Kohar
> -- 
> Sketsa 
> SVG Graphics Editor
> http://www.kiyut.com
> 
> On Thu, 2006-04-20 at 14:47 +0100, Dylan Browne wrote:
> > Further to my original posting (which was resolved) I have another 
question
> > regarding the locating of resources such as CSS/JS so that an SVG 
document
> > (created in memory using the Batik DOM, and streamed via servlet to 
the
> > browser) can access them.
> > 
> > For example, I currently have the following set up:
> > 
> > String CSS_LOCATION = "type=\"text/css\" 
href=\"file:///C:/SVG/style.css\"";
> > 
> > This works fine locally. However, if this code were to be placed in a
> > webapp, the only way this would work would be if I was accessing via a
> > browser on the webserver itself. All remote access would obviously 
fail,
> > (unless the referenced file also existed locally on the client).
> > 
> > I understand that I could use something like:
> > 
> > String CSS_LOCATION = "type=\"text/css\" href=\"http://myserver:123
> > /style.css\"";
> > 
> > But then my deployment becomes dependant on server name and port 
number.
> > 
> > Is there any way to make this reference to the location relative in 
the same
> > way that my JSPs in this deployment have relative references to the 
same
> > resources in the EAR file? For example:
> > 
> > <script src="resources/js/common.js"></script>
> > 
> > Thanks in advance for any help,
> > 
> > Kind regards,
> > 
> > Dylan B.
> > 
> > 
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: 
[EMAIL PROTECTED]
> > 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to