-----Original Message-----
From: Dan Finkelstein
[mailto:[EMAIL PROTECTED]]
Sent: Tuesday,
February 04, 2003 10:51 PM
To: [EMAIL PROTECTED]
Subject: Re: [Mav-user] Specifying
external maverick.xml
Jeff,
Can you chime in on what you think of this change? Does it seem
reasonable (enuf!) to add to the source or is there a better way of
incorporating this feature?
Thanks,
Dan
At 07:52 AM 1/26/03 -0800, you wrote:
Howdy,
Yourazlin, I think you and I are thinking the same way in terms of wanting
access to changing maverick.xml from outside the war/ear file. An init
parameter, that is specified is web.xml, doesn't apply to our situations since
web.xml is inside the war file.
My suggestion is that Maverick allow an application to override the file name
in any way it chooses. For example, in my application, this would allow
me to put the file name in my application-specific properties file.
What follows is my suggestion on how to enhance Maverick to handle this:
To Dispatcher.java, add:
private static
String _overriddenMaverickXmlFile = null;
public static
void setMaverickXmlFile(String name)
{
_overriddenMaverickXmlFile
= name;
}
Also, to Dispatcher.java, modify loadConfigDocument() so that first part looks
like this:
/**
* @return a
loaded JDOM document containing the configuration information.
*/
protected
Document loadConfigDocument() throws ConfigException
{
try
{
java.net.URL
configURL = null;
if(_overriddenMaverickXmlFile
!= null) {
configURL
= new URL("file://" +
_overriddenMaverickXmlFile);
}
else {
String
configFile = this.getInitParameter(INITPARAM_CONFIG_FILE);
if
(configFile == null)
configFile
= DEFAULT_CONFIG_FILE;
//
Quick sanity check
if
(!configFile.startsWith("/"))
configFile
= "/" + configFile;
configURL
= this.getServletContext().getResource(configFile);
}
log.info("Loading
config from " + configURL.toString());
This small change allows an application, while initializing itself, to override
the configuration file with exactly what it wants. In Yurazlin's case, his
application can retrieve the file name from servletCtx.getInitParameter("xslDir")
and, in my application I can retrieve it from my properties file.
Thoughts?
Dan
At 01:07 PM 1/25/03 +0300, you wrote:
Greetings,
I patched XSLTransform.java in my project about a week ago so that it could use
xsl files outside the ear file. probably, loading of mav config file can be
changed in a similar way. as far as i remember, there were problems with using
"resURL = servletCtx.getResource(path);" when path starts from
"file" in my environment. the patch works fine with w2k/sun_jdk
1.4.1/jboss-3.0.3/tomcat-4.1.12, but i can't say anything about other platforms.
it is effective in my project because my designers do not have to rebuild ear
each time they change something in design. but, as 4 me, it's hacky, so i
didn't post it here earlier. maybe u can suggest another, more intelligent
solution. can u?
the refactored code is below. i hope it's clear what it's about.
hope this helps,
yurazlin.
-------------------------------------------------------------------------------------------------------------------------------------------------------------
107 protected Templates loadTemplate(String
path, ServletContext servletCtx) throws ConfigException
108 {
109 // Make sure we have leading /, 'cause
it's needed.
110 if (!path.startsWith("/"))
111
path = "/"
+ path;
112
113 try
114 {
115
TransformerFactory tFactory = TransformerFactory.newInstance();
116
if
(this.uriResolver
!= null)
117
tFactory.setURIResolver(this.uriResolver);
118
return
tFactory.newTemplates(getTemplateStreamSource(path, servletCtx));
119 }
120 catch
(TransformerException ex)
121 {
122
log.fatal("Error
loading template " + path + ": " +
ex.toString());
123
throw
new
ConfigException(ex);
124 }
125 catch (IOException ex)
126 {
127
log.fatal("Eror
loading template " + path + ": " +
ex.toString());
128
throw
new
ConfigException(ex);
129 }
130 }
131 private StreamSource
getTemplateStreamSource(String path, ServletContext servletCtx)
132 throws IOException, ConfigException
133 {
134 URL resURL = null;
135 String xslDir =
servletCtx.getInitParameter("xslDir");
136 if (xslDir!=null)
137 {
138
String fullPath = xslDir+path;
139
File f = new
File(fullPath);
140
path = "file://"+fullPath;
141
if
(f.exists())
142
{
143
resURL = new
URL(path);
144
}
145 }
146 else
147 {
148
resURL = servletCtx.getResource(path);
149 }
150
151 if (resURL == null)
152 {
153
log.fatal("Resource
not found: " + path);
154
throw
new
ConfigException("Resource
not found: " + path);
155 }
156 log.debug("Template url
is: " + resURL.toString());
157 return new
StreamSource(resURL.openStream(), resURL.toString());
158 }
-----------------------------------------------------------------------------------------------------------------------------
----- Original Message -----
From: "Schnitzer, Jeff" <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>
To: <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>
Sent: Friday, January 24, 2003 11:48 PM
Subject: RE: [Mav-user] Specifying external maverick.xml
> You can specify a url to the maverick config file as an init param to
> the Dispatcher servlet (see
> http://mav.sourceforge.net/maverick-manual.html#N100CB
<http://mav.sourceforge.net/maverick-manual.html>).
This url gets
> passed to ServletContext.getResource().
>
> I'm really not entirely certain what you can get away with - try putting
> <file://path/to/wherever.xml>
in there.
>
> If that doesn't work, perhaps we should add code to fallback to
> Class.getResource() if ServletContext.getResource() fails? Dan, if you
> want to test this out, Dispatcher.loadConfigDocument() is trivial to
> modify. If you find something that works, I will be happy to commit a
> patch.
>
> Jeff Schnitzer
> [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
>
> > -----Original Message-----
> > From: Dan Finkelstein [mailto:[EMAIL PROTECTED]]
> > Sent: Thursday, January 23, 2003 7:33 PM
> > To: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
> > Subject: [Mav-user] Specifying external maverick.xml
> >
> > Hi --
> >
> > I'm interested in being able to specify a maverick.xml file that is
> > located
> > outside the war file. Right now, it is pulled from within the war and
> I
> > want to specify a different one "on-the-fly" so to speak.
For
> example, is
> > there a call that I could make, like
> > Maverick.iniitalize(maverick_xml_file)? Or another way to do this?
> >
> > Thanks in advance,
> > Dan
> >
> >
> >
> >
> > -------------------------------------------------------
> > This SF.NET email is sponsored by:
> > SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
> > <http://www.vasoftware.com>
> > [INVALID FOOTER]
>
>
>
> -------------------------------------------------------
> This SF.NET email is sponsored by:
> SourceForge Enterprise Edition + IBM + LinuxWorld <http://www.vasoftware.com>
> [INVALID FOOTER]
>