xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas DeWeese <Thomas.DeWe...@Kodak.com>
Subject Re: JSVGCanvas/getURI() returns wrong (?) URI
Date Wed, 11 Feb 2004 22:02:18 GMT
Chris Cruzdal wrote:

> Hi,
> 
> I have a class which extends JSVGCanvas and overloads
> the loadSVGDocument(String uri) method. Basically,
> what I do in there is check whether uri is an SVG, and
> then display it, or, whether it is not, and then I
> pass the uri on to another handler which takes over
> and does the appropriate thing with it.
> 
> If I get an SVG file, basically the core of the
> loadSVGDocument(String uri) method comes down to
> simply calling super.loadSVGDocument(uri).
> 
> Now, I am, though experiencing the following problem:
> after I click on a link in the SVG document, and the
> new SVG document opened, I can call getURI(), but it
> will always return the uri of the very first document
> in the canvas. I looked at the code of setURI() in
> JSVGCanvas and loadSVGDocument in JSVGComponent, but
> there it seems to me as if everything is correctly
> setting the uri, hence I think I am doing something in
> the wrong order in my code.

    The problem is that the openLink code which lives in
JSVGComponent the base class of JSVGCanvas just calls
'loadSVGDocument' it does not call 'setURI'.  The set/getURI
is part of the wrapping of the component into a Java Bean,
it appears that there is a 'flaw' here.  What really needs
to happen is that JSVGCanvas needs to override loadSVGDocument
to set 'this.uri' and fire the property change event (plus
proper handling of null).

    Then setURI can just call loadSVGDocument and know that
'the right thing' (TM) will happen.

> What is the difference between setURI() and
> loadSVGDocument()? I mean, when I want to update, I am
> usually calling setURI(), because that in turn calls
> loadSVGDocument(), but is this correct? Thanks for any
> help.
> 
> My overriden method can be seen below.
> 
> Dazed and confused,
> 
> Chris
> 
> This is more or less the method (strapped by a few
> other things):
> 
> 	public void loadSVGDocument(String uri) {
> 		try {
> 			URL url = new URL(uri);
> 			URLConnection connection = url.openConnection();
> 			String contentType = connection.getContentType();
> 			// Evaluate content type.
> 			if (contentType == null)
> 				throw new MalformedURLException();
> 			// Does one have an SVG file?
> 			if (contentType.indexOf("xml") >= 0 ||
> contentType.indexOf("svg") >= 0) {
> 				// Process as the super would.
> 				super.loadSVGDocument(uri);
> 
> 				// @DEBUG
> 				// This is where the uri never changes, no matter
> whether I call
> 				// this.uri or getURI(). In addition, if I call
> this.uri or getURI() much
> 				// later manually via a button in the user
> interface, nothing changed, either.
> 				System.err.println("@DEBUG:" + this.uri);
> 
> 				// Register with the history.
> 				history.enter(uri, Actions.LINK_ACTION);
> 			} else {
> 				browser.showDocument(uri, Targets.SIDEBAR);
> 			}
> 			connection = null;
> 		} catch (MalformedURLException e) {
> 			Helpers.handleError(
> 				"The requested document is not available or it
> does not exist!");
> 		} catch (IOException e) {
> 			Helpers.handleError(
> 				"The requested document is not available or it
> does not exist. Please check your internet
> connection.");
> 		}
> 	}
> --
> Chris Crzudal
> 
> 
> __________________________________
> Do you Yahoo!?
> Yahoo! Finance: Get your refund fast by filing online.
> http://taxes.yahoo.com/filing.html
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org


Mime
View raw message