Thanks for the update, but I couldn't get the new code to work, maybe that's what you meant by not supporting the file stuff yet ! <grin>

I was trying to set enter something like:

getServletContext().setAttribute(Dispatcher.KEY_CONFIG_FILE, "file:///whatever/maverick.xml");

I think that if you add a check for the string starting with "file://", and then call new URL(filepath) instead of getResource(), it would be fine. Make sense?

Best,
Dan

(Hope you had fun skiing ... I'm going up next week!)


At 03:42 PM 2/6/03 -0800, you wrote:
Actually I was thinking of the application attribute context. A servlet initialized prior to the dispatcher could do something like this:

this.getServletContext().setAttribute(Maverick.CONFIG_FILE_APPLICATION_KEY, "/WEB-INF/somethingelse.xml");

Of course the value could be obtained from anywhere (jndi, database, http request, etc). Sound good?


I'm confused about your confusion over the file:// issue :-) Right now all config file paths are loaded from inside the WAR using getResource(). You want to be able to load config files which are located somewhere else in the filesystem, right? Maverick needs some way of determining whether to use getResource() or to create a URL and load that directly. Some way of determining if the path is a fully-specified URL seems like the natural way.

I'm leaving tonight for a ski trip so I'm not sure I'll be able to do anything about it until Monday, but I'll get this into CVS soon.

Jeff

-----Original Message-----
From: Dan Finkelstein [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, February 05, 2003 4:23 PM
To: [EMAIL PROTECTED]
Subject: RE: [Mav-user] Specifying external maverick.xml

Hi Jeff,

Correct -- those are the two goals of this exercise!

To be clear, when you speak of app-context, you mean using JNDI to pull the property from the servlet.xml file, something like this:

Context context = new InitialContext();
Context envContext = (Context) context.lookup("java:comp/env");
maverickFile = (String)envContext.lookup("maverickFile");

I suppose that would work.

As far as the ':', Windows uses that in a drive specifier, so that might be avoided. If I understand right, you're trying to let the user specify one of:

file:///home/whatever/mav.xml
or
/WEB-INF/mav.xml

and have it work either way? I think the user needn't enter the "file://" part -- in fact, it is kind of confusing and would commonly be left off by mistake anyway. I think you could just assume the property is a file -- why would anyone enter a resource path from _outside_ the war file? It doesn't make sense, that's what the init parameter is for!!

Regardless, what you're suggesting is reasonable and will certainly address the two concerns. Can you commit it in cvs?

Thanks a lot,
Dan


At 03:17 PM 2/5/2003 -0800, you wrote:


There are two goals, right?



1) To let your webapp determine at runtime what config file to use.

2) To be able to use a configuration file outside of the WAR.



The use of a static is a little weirdhow about checking an app context variable instead? Here is what I propose:



If app-context parameter exists, use that

If init parameter exists, use that

Otherwise use maverick.xml



In addition, the logic:



If value contains a :in the first 8 characters, treat it as an absolute URL.

Otherwise treat it as something to look up using getResource().



That seems to cover the two requirements. Is there a better way to identify absolute URLs than checking for a :?



Jeff



-----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]
>


-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld omething 2 See!
http://www.vasoftware.com
[INVALID FOOTER]

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
[INVALID FOOTER]

Reply via email to