From: Kal A. <ka...@te...> - 2004-09-27 07:30:23
|
Hi Conal, I'll have to look into why the xml:base attribute is not affecting the base locator of the topic map (I have a suspicion that it is to do with the way that the SerializedTopicMapSource works). What you suggest (adding a base attribute to the <import> element) is a good idea as a workaround. Another possible workaround is to make use of a catalog file. TM4J supports redirection through a catalog, so you can specify that the filesystem location for topic map http://foo.xtm is /path/to/xtmfile.xtm. The http:// URI will be used as the topic maps base locator even thought the topic map is read from the local filesystem. So there are a lot of options, but I agree that we should fix the xml:base processing for the simple case where a SerializedTopicMapSource reads a single XTM file. Cheers, Kal On Mon, 2004-09-27 at 07:16, Conal Tuohy wrote: > I am using the In-Memory topic map provider with Cocoon. > > I need to load the topic map from an XTM file into memory, but I want to give it a different base locator. I want the base locator of the resulting map to be an http url, but I want to read the file from the local file system. I thought I could specify an xml:base attribute on the topicMap element in the file, but this has no effect, and I end up with a topic map with a base locator of "file:// etc". > > I've had a look at the Cocoon TopicMapManagerComponent code, and there seems to be a couple of ways to specify a source in the cocoon.xconf file: using a parameter called "tm4j.topicmap.0", or alternatively, using an <import> element. I haven't yet looked at the first method ("tm4j.topicmap.0 parameter") in great detail, but it doesn't seem to offer what I want. Neither does the <import> element :-) but it's what I've been using so far. It looks like this: > > <import name="nzetc" file="/nzetc/tm/export/nzetc.xtm"/> > > The TopicMapManagerComponent has a method configureImport which processes this: > > private void configureImport(TopicMapProvider provider, Configuration imp) throws ConfigurationException > { > String file = imp.getAttribute(CONFIG_IMPORT_FILE); > String name = imp.getAttribute(CONFIG_IMPORT_NAME); > String realPath = m_context.getRealPath(file); > File f = new File(realPath); > try { > SerializedTopicMapSource tmSrc = new SerializedTopicMapSource(f); > TopicMap tm = provider.addTopicMap(tmSrc); > m_topicMapNames.put(name, tm.getBaseLocator()); > } catch (Exception ex) { > getLogger().error("TopicMapManagerComponent: Unable to process import named " + name, ex ); > throw new ConfigurationException("Unable to process import '" + name + "'", ex); > } > } > > ... so the base locator is set by the SerializedTopicMapSource, which makes the locator by converting the java.io.File to a URL, so my base locator always equals the URL of the file where I loaded the XTM from: > > locatorString = file.toURL().toString(); > > If this seems like a reasonable requirement (to be able to specify a different base locator), I'd like to change the TopicMapManagerComponent to read a "base" attribute from the <import> element and pass this to the SerializedTopicMapSource constructor along with the file. > > e.g. > > <import name="nzetc" base="http://www.nzetc.org/tm/nzetc.xtm" file="/nzetc/tm/export/nzetc.xtm"/> > > In the TopicMapManagerComponent this would be something like: > > private void configureImport(TopicMapProvider provider, Configuration imp) throws ConfigurationException > { > String file = imp.getAttribute(CONFIG_IMPORT_FILE); > String name = imp.getAttribute(CONFIG_IMPORT_NAME); > String base = imp.getAttribute(CONFIG_IMPORT_BASE); // need to add this field > String realPath = m_context.getRealPath(file); > File f = new File(realPath); > try { > baseLocator = provider.getLocatorFactory().createLocator("URI", base); // convert to locator > SerializedTopicMapSource tmSrc = new SerializedTopicMapSource(f, baseLocator); // set base locator > TopicMap tm = provider.addTopicMap(tmSrc); > m_topicMapNames.put(name, tm.getBaseLocator()); > } catch (Exception ex) { > getLogger().error("TopicMapManagerComponent: Unable to process import named " + name, ex ); > throw new ConfigurationException("Unable to process import '" + name + "'", ex); > } > } > > Alternatively, the SerializedTopicMapSource could parse the source and extract the xml:base attribute and use that. In some ways this would be preferable. > > What do other people think? > > Sorry for the long email. I'm not even sure if this is a good idea, but it's related to a problem I'm having with subject indicators, which I'll post about on the users list. > > Cheers > > Con > > > ------------------------------------------------------- > This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170 > Project Admins to receive an Apple iPod Mini FREE for your judgement on > who ports your project to Linux PPC the best. Sponsored by IBM. > Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php > _______________________________________________ > Tm4j-developers mailing list > Tm4...@li... > https://lists.sourceforge.net/lists/listinfo/tm4j-developers -- Kal Ahmed <ka...@te...> techquila |