From: Conal T. <Con...@vu...> - 2004-09-27 06:19:26
|
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".=20 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=3D"nzetc" file=3D"/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 =3D imp.getAttribute(CONFIG_IMPORT_FILE); String name =3D imp.getAttribute(CONFIG_IMPORT_NAME); String realPath =3D m_context.getRealPath(file); File f =3D new File(realPath); try { SerializedTopicMapSource tmSrc =3D new = SerializedTopicMapSource(f); TopicMap tm =3D 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 =3D 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=3D"nzetc" base=3D"http://www.nzetc.org/tm/nzetc.xtm" = file=3D"/nzetc/tm/export/nzetc.xtm"/> In the TopicMapManagerComponent this would be something like: private void configureImport(TopicMapProvider provider, Configuration = imp) throws ConfigurationException { String file =3D imp.getAttribute(CONFIG_IMPORT_FILE); String name =3D imp.getAttribute(CONFIG_IMPORT_NAME); String base =3D imp.getAttribute(CONFIG_IMPORT_BASE); // need to = add this field String realPath =3D m_context.getRealPath(file); File f =3D new File(realPath); try { baseLocator =3D = provider.getLocatorFactory().createLocator("URI", base); // convert to = locator SerializedTopicMapSource tmSrc =3D new = SerializedTopicMapSource(f, baseLocator); // set base locator TopicMap tm =3D 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 |