[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jedit-cvs
Subject:    [ jEdit-commits ] SF.net SVN: jedit:[15338]
From:       kerik-sf () users ! sourceforge ! net
Date:       2009-05-25 21:04:26
Message-ID: E1M8hLO-0002FP-7Q () dn4whf1 ! ch3 ! sourceforge ! com
[Download RAW message or body]

Revision: 15338
          http://jedit.svn.sourceforge.net/jedit/?rev=15338&view=rev
Author:   kerik-sf
Date:     2009-05-25 21:04:26 +0000 (Mon, 25 May 2009)

Log Message:
-----------
fix for bug #2790801 in xml.Resolver: when using a cached resource, the systemId was \
not set to the original (http://...) systemId but to the cached xml. Now we always \
set the systemId correctly. this removes the need for reverseResourceCache

Modified Paths:
--------------
    plugins/XML/branches/relax-ng/xml/Resolver.java

Modified: plugins/XML/branches/relax-ng/xml/Resolver.java
===================================================================
--- plugins/XML/branches/relax-ng/xml/Resolver.java	2009-05-25 20:59:35 UTC (rev \
                15337)
+++ plugins/XML/branches/relax-ng/xml/Resolver.java	2009-05-25 21:04:26 UTC (rev \
15338) @@ -5,6 +5,8 @@
 import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.InputStream;
+import java.net.URL;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.StringReader;
@@ -155,9 +157,6 @@
 	   */
 	private Catalog catalog = null;
 
-	/** Mapping of URLs to public IDs */
-	private HashMap<String,Entry> reverseResourceCache;
-	
 	/** Mapping from public ID to URLs */
 	private HashMap<Entry,String> resourceCache;
 	
@@ -200,7 +199,6 @@
 		if(!loadedCache)
 		{
 			
-			reverseResourceCache = new HashMap<String,Entry>();
 			resourceCache = new HashMap<Entry,String>();
 			if (isUsingCache()) 
 				
@@ -228,7 +226,6 @@
 				uri = jEdit.getProperty(prop + ".uri");
 				Entry se = new Entry(Entry.SYSTEM,id,uri);
 				resourceCache.put(se,uri);
-				reverseResourceCache.put(uri,se);
 			}
 			loadedCache = true;
 		}
@@ -315,19 +312,10 @@
 		//catch an error message here
 		if(publicId == null && systemId == null)return null;
 		
-		/* we need this hack to support relative path names inside
-		 * cached files. we want them to be resolved relative to
-		 * the original system ID of the cached resource, not the
-		 * cache file name on disk. */
 		String parent;
 		if(current != null)
 		{
-			
-			Entry entry = (Entry)reverseResourceCache.get(current);
-			if(entry != null)
-				parent = entry.uri;
-			else
-				parent = MiscUtilities.getParentOfPath(current);
+			parent = MiscUtilities.getParentOfPath(current);
 		}
 		else
 			parent = null;
@@ -337,6 +325,10 @@
 			Log.log(Log.DEBUG,Resolver.class,"parent="+parent);
 			if(systemId.startsWith(parent))
 			{
+				Log.log(Log.DEBUG,Resolver.class,"systemId starts with parent");
+				// TODO: this code path is not taken when viewing
+				// test_data/dtd/actions.xml, so the comment bellow
+				// is misleading and all the block should be removed
 				// first, try resolving a relative name,
 				// to handle jEdit built-in DTDs
 				newSystemId = systemId.substring(parent.length());
@@ -369,9 +361,14 @@
 			//need this to resolve xinclude.mod from user-guide.xml
 			//I don't understand this condition :  && !MiscUtilities.isURL(parent)
 			else if(parent != null)
+			{
+				Log.log(Log.DEBUG,Resolver.class,"using parent !");
 				newSystemId = parent + systemId;
+			}
 		}
 
+		// don't throw the IOException, as we don't have a
+		// meaningful message to display to the user
 		if(newSystemId == null)
 			return null;
 
@@ -382,7 +379,8 @@
 				VFSManager.waitForRequests();
 			Log.log(Log.DEBUG, getClass(), "Found open buffer for " + newSystemId);
 			InputSource source = new InputSource(publicId);
-			source.setSystemId(newSystemId);
+			//use the original systemId
+			source.setSystemId(systemId);
 			try
 			{
 				buf.readLock();
@@ -398,15 +396,23 @@
 		else if(newSystemId.startsWith("file:")
 			|| newSystemId.startsWith("jeditresource:"))
 		{
-			// InputSource source = new InputSource(systemId);
-			 
-			// InputStream is = new URL(newSystemId).openStream();
-			InputSource is = new InputSource(newSystemId);
-			return is;
-			
+			// pretend to be reading the file from whatever the systemId was
+			// eg. http://slackerdoc.tigris.org/xsd/slackerdoc.xsd when we 
+			// are reading ~/.jedit/dtds/cache1345.xml
+			Log.log(Log.DEBUG,Resolver.class,"resolving to local file: "+newSystemId);
+			InputSource source = new InputSource(systemId);
+			source.setPublicId(publicId);
+			InputStream is = new URL(newSystemId).openStream();
+			source.setByteStream(is);
+			return source;
 		}
-		else if (getNetworkModeVal() == LOCAL) 
-			return null;
+		else if (getNetworkModeVal() == LOCAL)
+		{
+			Log.log(Log.DEBUG,Resolver.class,"refusing to fetch remote entity (configured for \
Local-only)"); +			// returning null would not be as informing
+			// TODO: prevent the 'premature end of file' error from showing
+			throw new IOException(jEdit.getProperty("xml.network.error"));
+		}
 		else
 		{
 			final String _newSystemId = newSystemId;
@@ -471,7 +477,9 @@
 			}
 			else 
 			{
-				throw new IOException(jEdit.getProperty("xml.network-error"));
+				// returning null would not be as informing
+				// TODO: prevent the 'premature end of file' error from showing
+				throw new IOException(jEdit.getProperty("xml.network.error"));
 			}
 		}
 		
@@ -613,7 +621,6 @@
 
 		Entry se = new Entry( Entry.SYSTEM, systemId, url );
 		resourceCache.put( se, url );
-		reverseResourceCache.put(url,se);
 	} //}}}
 
 	public static class Entry


This was sent by the SourceForge.net collaborative development platform, the world's \
largest Open Source development site.

------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com 
_______________________________________________
jEdit-CVS mailing list
jEdit-CVS@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jedit-cvs


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic