relative URIs?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

relative URIs?

Lukasz Matuszczak
How to use relative URLs while loading SVG documents into batik?

Documents start loading, and then I'm getting an error if there any url
references in a document (even if they are to the same document):

"org.apache.batik.bridge.BridgeException: file:res/test.svg:-1
An I/O error occured while processing the URI:
"file:res/test.svg#gradient1"
specified on the element <path>

 at org.apache.batik.bridge.BridgeContext.getReferencedElement(Unknown Source)
..."

If URLs have to be absolute I would like to know how to convert
"file:res/test.svg" -> "file:c:/application/res/test.svg" in cross-platform
compatible way?

Thanks in advance.



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: relative URIs?

Tonny Kohar
Hi,

On Thu, 2005-05-12 at 16:38 +0200, Lukasz Matuszczak wrote:
> How to use relative URLs while loading SVG documents into batik?

If you are using relative URI/URL make sure you set document base
URL/URI if you are creating the doc on the fly. However, if you load the
existing document, Batik will automatically set the doc base URL/URI.

Regards
Tonny Kohar
--
Sketsa
SVG Graphics Editor
http://www.kiyut.com


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: relative URIs?

Lukasz Matuszczak

----- Original Message -----
From: "Tonny Kohar" <[hidden email]>
To: <[hidden email]>
Sent: Thursday, May 12, 2005 8:06 PM
Subject: Re: relative URIs?


> Hi,
>
> On Thu, 2005-05-12 at 16:38 +0200, Lukasz Matuszczak wrote:
>> How to use relative URLs while loading SVG documents into batik?
>
> If you are using relative URI/URL make sure you set document base
> URL/URI if you are creating the doc on the fly. However, if you load the
> existing document, Batik will automatically set the doc base URL/URI.

I'm loading the existing document and it's not working.
If I put the document in the working directory for example and the use an URL
"file:test.svg", it works. If the document is in a subfolder for example "doc"
it doesn't work with URL "file:doc/test.svg". It turned out that the doc base is
set to file:doc/, so it looks for urls in file:doc/doc/test.svg (if I put the
copy of the document there, everything is OK).

The test document is very simple:
<?xml version="1.0" encoding="windows-1250" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="600" height="400" viewBox="0 0 600 400"
xmlns="http://www.w3.org/2000/svg" version="1.1">
   <desc>Example circle01 - circle filled with red and stroked with blue</desc>
   <defs>
      <linearGradient x1="100"  gradientUnits="userSpaceOnUse" y1="200" x2="500"
           y2="400" id="id0">
         <stop offset="0" stop-color="#EBE0FF"/>
         <stop offset="0.101961" stop-color="#33CC33"/>
         <stop offset="0.490196" stop-color="#FFFF00"/>
         <stop offset="0.878431" stop-color="#FF0000"/>
         <stop offset="1" stop-color="#EBE0FF"/>
      </linearGradient>
   </defs>
   <circle cx="200" cy="200" r="100" fill="url(#id0)" stroke="blue"
stroke-width="10" />
</svg>

The message is:
org.apache.batik.bridge.BridgeException: file:doc/test.svg:25
An I/O error occured while processing the URI:
"file:doc/test.svg#id0"
specified on the element <circle>

 at
org.apache.batik.bridge.BridgeContext.getReferencedElement(BridgeContext.java:638)
 at org.apache.batik.bridge.PaintServer.convertURIPaint(PaintServer.java:348)
 at org.apache.batik.bridge.PaintServer.convertPaint(PaintServer.java:259)
 at org.apache.batik.bridge.PaintServer.convertFillPaint(PaintServer.java:228)
 at
org.apache.batik.bridge.PaintServer.convertFillAndStroke(PaintServer.java:146)
 at
org.apache.batik.bridge.SVGShapeElementBridge.createShapePainter(SVGShapeElementBridge.java:113)
 at
org.apache.batik.bridge.SVGCircleElementBridge.createShapePainter(SVGCircleElementBridge.java:124)
 at
org.apache.batik.bridge.SVGShapeElementBridge.buildGraphicsNode(SVGShapeElementBridge.java:87)
 at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(GVTBuilder.java:210)
 at org.apache.batik.bridge.GVTBuilder.buildComposite(GVTBuilder.java:161)
 at org.apache.batik.bridge.GVTBuilder.build(GVTBuilder.java:77)
 at org.apache.batik.swing.svg.GVTTreeBuilder.run(GVTTreeBuilder.java:95)

I set the URI with JSVGCanvas setURI method
or with
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
doc = f.createDocument(uri, reader);

The result is the same.
Regards,
Lukasz Matuszczak



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: relative URIs?

Tonny Kohar
Hi,

I use your example test document and load it under Batik Squiggle, it
run fine.

You can query the doc URL base using the following code, to make sure it
is set in the intended path
svgDocument.getURL();

How do you convert the file URI, do you use Java file.toURL() ?
As far as I know file URI, start with file:/ eg: file:/c://something (on
Windows) and file:/home/something (on Unix), It is not file:something

Regards
Tonny Kohar

> I'm loading the existing document and it's not working.
> If I put the document in the working directory for example and the use an URL
> "file:test.svg", it works. If the document is in a subfolder for example "doc"
> it doesn't work with URL "file:doc/test.svg". It turned out that the doc base is
> set to file:doc/, so it looks for urls in file:doc/doc/test.svg (if I put the
> copy of the document there, everything is OK).
>
> The test document is very simple:
> <?xml version="1.0" encoding="windows-1250" standalone="no"?>
> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
> "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
> <svg width="600" height="400" viewBox="0 0 600 400"
> xmlns="http://www.w3.org/2000/svg" version="1.1">
>    <desc>Example circle01 - circle filled with red and stroked with blue</desc>
>    <defs>
>       <linearGradient x1="100"  gradientUnits="userSpaceOnUse" y1="200" x2="500"
>            y2="400" id="id0">
>          <stop offset="0" stop-color="#EBE0FF"/>
>          <stop offset="0.101961" stop-color="#33CC33"/>
>          <stop offset="0.490196" stop-color="#FFFF00"/>
>          <stop offset="0.878431" stop-color="#FF0000"/>
>          <stop offset="1" stop-color="#EBE0FF"/>
>       </linearGradient>
>    </defs>
>    <circle cx="200" cy="200" r="100" fill="url(#id0)" stroke="blue"
> stroke-width="10" />
> </svg>
>
> The message is:
> org.apache.batik.bridge.BridgeException: file:doc/test.svg:25
> An I/O error occured while processing the URI:
> "file:doc/test.svg#id0"
> specified on the element <circle>
>
>  at
> org.apache.batik.bridge.BridgeContext.getReferencedElement(BridgeContext.java:638)
>  at org.apache.batik.bridge.PaintServer.convertURIPaint(PaintServer.java:348)
>  at org.apache.batik.bridge.PaintServer.convertPaint(PaintServer.java:259)
>  at org.apache.batik.bridge.PaintServer.convertFillPaint(PaintServer.java:228)
>  at
> org.apache.batik.bridge.PaintServer.convertFillAndStroke(PaintServer.java:146)
>  at
> org.apache.batik.bridge.SVGShapeElementBridge.createShapePainter(SVGShapeElementBridge.java:113)
>  at
> org.apache.batik.bridge.SVGCircleElementBridge.createShapePainter(SVGCircleElementBridge.java:124)
>  at
> org.apache.batik.bridge.SVGShapeElementBridge.buildGraphicsNode(SVGShapeElementBridge.java:87)
>  at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(GVTBuilder.java:210)
>  at org.apache.batik.bridge.GVTBuilder.buildComposite(GVTBuilder.java:161)
>  at org.apache.batik.bridge.GVTBuilder.build(GVTBuilder.java:77)
>  at org.apache.batik.swing.svg.GVTTreeBuilder.run(GVTTreeBuilder.java:95)
>
> I set the URI with JSVGCanvas setURI method
> or with
> SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
> doc = f.createDocument(uri, reader);


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: relative URIs?

Lukasz Matuszczak

----- Original Message -----
From: "Tonny Kohar" <[hidden email]>
To: <[hidden email]>
Sent: Friday, May 13, 2005 8:36 AM
Subject: Re: relative URIs?


> Hi,
>
> I use your example test document and load it under Batik Squiggle, it
> run fine.

Try to put doc/test.svg in the folder where batik is installed and after
starting Squiggle put file:doc/test.svg in Location field. It fails. Note that
file:init.svg works, because init.svg is not in a subfolder.
If the first document you run has absolute URI, squiggle is somehow converting
consecutive relative URIs to absolute URIs based on previous absolute URI.
So if I choose Open file from menu and init.svg file, the Location is set to
file:/C:/programs/batik/batik-1.6/init.svg. Then if I put file:doc/test.svg in
Location field it runs fine because Squiggle is converting it somehow
automatically to file:/C:/programs/batik/batik-1.6/doc/test.svg


>
> You can query the doc URL base using the following code, to make sure it
> is set in the intended path
> svgDocument.getURL();
>
> How do you convert the file URI, do you use Java file.toURL() ?

The problem is the I'm not converting File object to URL (toURL method always
provides absolute URLs), because i have String "file:doc/test.svg" in the
configuration of my application.

> As far as I know file URI, start with file:/ eg: file:/c://something (on
> Windows) and file:/home/something (on Unix), It is not file:something

I think the file:/ means that this is an absolute URI path, so
file:/C:/programs/batik/batik-1.6/init.svg is absolute URI but file:init.svg is
relative and I want to resolve it against the my application working directory.
Maybe it is not batik question, but I thought that this problem was solved
somehow in it.

Regards.
Lukasz.





---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: relative URIs?

thomas.deweese
Hi Lukasz,

Lukasz Matuszczak wrote:

> Try to put doc/test.svg in the folder where batik is installed and after
> starting Squiggle put file:doc/test.svg in Location field.

   These are not valid URL's.  As soon as you put a protocol on a URL
you must specify an absolute URL.  Don't pay too much attention to
how the Location field operates it tries to be nice to you.  The canvas
always requires an absolute URL.

> The problem is the I'm not converting File object to URL (toURL method
> always provides absolute URLs), because i have String
> "file:doc/test.svg" in the configuration of my application.

    Then your application is in error.  You need to give an absolute
URL so Batik has something to resolve against.

>> As far as I know file URI, start with file:/ eg: file:/c://something (on
>> Windows) and file:/home/something (on Unix), It is not file:something

    Correct, well almost, file URLs always starts with 'file:///'  - yes
three slashes, many 'short cuts' are supported by lots of software
but this is what the RFC on URLs says.  This is because the format
for a URL is '<protocol>://[<host>[:<port>]]/<path on server>'
A file URL has an empty host and port.

> I think the file:/ means that this is an absolute URI path, so
> file:/C:/programs/batik/batik-1.6/init.svg is absolute URI but
> file:init.svg is relative and I want to resolve it against the my
> application working directory.

    Well then I would suggest that you resolve it against your
application working directory and pass the absolute URL from that to
Batik (new File("init.svg").toURL()).

> Maybe it is not batik question, but I thought that this problem was
> solved somehow in it.

    No you should provide a proper fully qualified URL to the Canvas.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: relative URIs?

Lukasz Matuszczak

----- Original Message -----
From: "Thomas DeWeese" <[hidden email]>
To: <[hidden email]>
Sent: Friday, May 13, 2005 12:07 PM
Subject: Re: relative URIs?


> Hi Lukasz,
>
> Lukasz Matuszczak wrote:
>
>> Try to put doc/test.svg in the folder where batik is installed and after
>> starting Squiggle put file:doc/test.svg in Location field.
>
>   These are not valid URL's.  As soon as you put a protocol on a URL
> you must specify an absolute URL.  Don't pay too much attention to
> how the Location field operates it tries to be nice to you.  The canvas
> always requires an absolute URL.
>
>> The problem is the I'm not converting File object to URL (toURL method
>> always provides absolute URLs), because i have String
>> "file:doc/test.svg" in the configuration of my application.
>
>    Then your application is in error.  You need to give an absolute
> URL so Batik has something to resolve against.
>
>>> As far as I know file URI, start with file:/ eg: file:/c://something (on
>>> Windows) and file:/home/something (on Unix), It is not file:something
>
>    Correct, well almost, file URLs always starts with 'file:///'  - yes
> three slashes, many 'short cuts' are supported by lots of software
> but this is what the RFC on URLs says.  This is because the format
> for a URL is '<protocol>://[<host>[:<port>]]/<path on server>'
> A file URL has an empty host and port.
>
>> I think the file:/ means that this is an absolute URI path, so
>> file:/C:/programs/batik/batik-1.6/init.svg is absolute URI but
>> file:init.svg is relative and I want to resolve it against the my
>> application working directory.
>
>    Well then I would suggest that you resolve it against your
> application working directory and pass the absolute URL from that to
> Batik (new File("init.svg").toURL()).

Thank you for this clarification, Thomas.
Best regards
Lukasz Matuszczak





---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]