[Configuration] Patch to BaseConfiguration for clear
See attached for patch to BaseConfiguration to allow subclasses to call clear() so that reloading of configurations are supported. Of course, subclasses have to implement their respective reload methods... On a related note, what are the conventions for adding yourself to the list of @authors? Regards, Kelvin The book giving manifesto - http://how.to/sharethisbook - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[digester] wildcard matching with /*
I've patched RulesBase to accept /foo/bar/* matches. Wondering if anyone's interested in the patch. So digester.addBeanPropertySetter(foo/bar/*); will work with foo bar propertyAsnafu/propertyA propertyBsnafu/propertyB /bar /foo where propertyA and propertyB are bar Javabean properties. Regards, Kelvin The book giving manifesto - http://how.to/sharethisbook -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
[dom4jconfiguration] Improved save()
Added a little fault-tolerance into save() method, saving to temp file, then renaming if no errors thrown. See attached for patch. Index: DOM4JConfiguration.java === RCS file: /home/cvspublic/jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/DOM4JConfiguration.java,v retrieving revision 1.1 diff -u -r1.1 DOM4JConfiguration.java --- DOM4JConfiguration.java 14 Jan 2003 03:53:12 - 1.1 +++ DOM4JConfiguration.java 20 Jan 2003 02:38:48 - @@ -56,7 +56,9 @@ import java.io.BufferedOutputStream; import java.io.File; +import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.InputStream; import java.io.IOException; import java.io.OutputStream; import java.net.URL; @@ -305,7 +307,7 @@ } /** - * @throws + * @throws */ private void possiblySave() { @@ -336,10 +338,15 @@ { XMLWriter writer = null; OutputStream out = null; +// write to a temp file in case of errors +File temp = null; try { +temp = new File(file.getParentFile(), file.getName() + .tmp); +// in case an exception is thrown, let JVM clean up +temp.deleteOnExit(); OutputFormat outputter = OutputFormat.createPrettyPrint(); -out = new BufferedOutputStream(new FileOutputStream(file)); +out = new BufferedOutputStream(new FileOutputStream(temp)); writer = new XMLWriter(out, outputter); writer.write(document); } @@ -353,6 +360,40 @@ if (writer != null) { writer.close(); +} +} + +// no exceptions are thrown, so its safe to overwrite +file.delete(); +if (temp.renameTo(file) == false) +{ +InputStream in = null; +/** + * fails if the temporary storage directory was on + * different volume than the target directory; + * attempt a raw copy. + */ +try +{ +out = new FileOutputStream(file); +in = new FileInputStream(temp); +byte[] data = new byte[1]; +int len; +while ((len = in.read(data)) != -1) +{ +out.write(data, 0, len); +} +} +finally +{ +if (out != null) +{ +out.close(); +} +if (in != null) +{ +in.close(); +} } } } -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
[dom4jconfiguration] Improved save()
Added a little fault-tolerance into save() method, saving to temp file, then renaming if no errors thrown. See attached for patch. Index: DOM4JConfiguration.java === RCS file: /home/cvspublic/jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/DOM4JConfiguration.java,v retrieving revision 1.1 diff -u -r1.1 DOM4JConfiguration.java --- DOM4JConfiguration.java 14 Jan 2003 03:53:12 - 1.1 +++ DOM4JConfiguration.java 20 Jan 2003 02:38:48 - @@ -56,7 +56,9 @@ import java.io.BufferedOutputStream; import java.io.File; +import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.InputStream; import java.io.IOException; import java.io.OutputStream; import java.net.URL; @@ -305,7 +307,7 @@ } /** - * @throws + * @throws */ private void possiblySave() { @@ -336,10 +338,15 @@ { XMLWriter writer = null; OutputStream out = null; +// write to a temp file in case of errors +File temp = null; try { +temp = new File(file.getParentFile(), file.getName() + .tmp); +// in case an exception is thrown, let JVM clean up +temp.deleteOnExit(); OutputFormat outputter = OutputFormat.createPrettyPrint(); -out = new BufferedOutputStream(new FileOutputStream(file)); +out = new BufferedOutputStream(new FileOutputStream(temp)); writer = new XMLWriter(out, outputter); writer.write(document); } @@ -353,6 +360,40 @@ if (writer != null) { writer.close(); +} +} + +// no exceptions are thrown, so its safe to overwrite +file.delete(); +if (temp.renameTo(file) == false) +{ +InputStream in = null; +/** + * fails if the temporary storage directory was on + * different volume than the target directory; + * attempt a raw copy. + */ +try +{ +out = new FileOutputStream(file); +in = new FileInputStream(temp); +byte[] data = new byte[1]; +int len; +while ((len = in.read(data)) != -1) +{ +out.write(data, 0, len); +} +} +finally +{ +if (out != null) +{ +out.close(); +} +if (in != null) +{ +in.close(); +} } } } -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: cvs commit: jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration XMLConfiguration.java DOM4JConfiguration.java XmlConfiguration.java
One thing people should know about dom4j and Resin: they don't like each other very much. :-) I've patched dom4j to work with Resin. Its an awful workaround, but it works. Contact me if anyone needs the patch. Kelvin -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: cvs commit: jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration XMLConfiguration.java DOM4JConfiguration.java XmlConfiguration.java
Not really. Its an awful hack! In SAXHelper.createXMLReader, I comment out XMLReader reader = createXMLReaderViaJAXP( validating, true ); and hardcode System.setProperty("org.xml.sax.driver", "org.apache.xerces.parsers.SAXParser"); to avoid using Rein's SAX driver. Kelvin On Tue, 14 Jan 2003 10:19:35 -, James Strachan said: Wanna send me the patch I'll apply it? James --- http://radio.weblogs.com/0112098/ - Original Message ----- From: "Kelvin Tan" [EMAIL PROTECTED] To: "Jakarta Commons Developers List" commons- [EMAIL PROTECTED] Sent: Tuesday, January 14, 2003 9:03 AM Subject: Re: cvs commit: jakarta-commons- sandbox/configuration/src/java/org/apache/commons/configurat ion XMLConfiguration.java DOM4JConfiguration.java XmlConfiguration.java One thing people should know about dom4j and Resin: they don't like each other very much. :-) I've patched dom4j to work with Resin. Its an awful workaround, but it works. Contact me if anyone needs the patch. Kelvin -- To unsubscribe, e-mail: mailto:commons-dev- [EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] __ Do You Yahoo!? Everything you'll ever need on one web page from News and Sport to Email and Music Charts http://uk.my.yahoo.com -- To unsubscribe, e-mail: mailto:commons-dev- [EMAIL PROTECTED] For additional commands, e-mail: mailto:commons-dev- [EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: [Jelly] JellyServlet
My apologies James. See attached again. JellyServletContext is new. I believe I attached it the last time round. On Mon, 16 Dec 2002 16:26:14 -, James Strachan said: Hi Kelvin Any chance you could resend your patch by using the command cvs diff -u File patch.txt http://jakarta.apache.org/commons/patches.html I'll just help me be able to apply it. James --- http://radio.weblogs.com/0112098/ - Original Message - From: Kelvin Tan [EMAIL PROTECTED] To: Jakarta Commons Developers List commons- [EMAIL PROTECTED] Sent: Wednesday, December 11, 2002 6:46 AM Subject: Re: [Jelly] JellyServlet James, On Mon, 9 Dec 2002 15:18:21 -, James Strachan said: Thanks for the patch Kelvin, I've committed it to CVS. I made a minor patch so that the URI itself could denote the script to run. So you could just run http://localhost:8080/foo/index.jelly for example, rather than requiring a template=index.jelly query parameter.. That's nice. I have changed the parameter template to script. Its just that I'm so used to using Velocity. The patch you made uses getServletPath, which returns the url of the servlet being called. I've changed it to getPathInfo. Another thing. Is it really appropriate to require all scripts to be located beneath the web app's context root (which getResource does)? The previous impl using new File(script).getUrl had no such limitation... Some thoughts for further improvement could be... * implement a JellyServletContext so that the getResource() method will use the ServletContext.getResource() method and allow access of relative URIs when performing j:include's. done. * have a parent JellyServletContext to allow access to the initParams of the ServletContext via variable expressions ? * implement the JSTL mappings of request parameters, session parameters, cookies etc in the expression language. * it'd be nice to have a cache of Jelly Scripts to avoid parsing them each time! :-) Here's something which is a little surprise. So it means Jelly is not internally caching scripts? This has some implications for usage of Jelly as a templating subsystem for high-load systems, I imagine. In any event, perhaps it would be a better idea to cache at the engine level, rather than the servlet level, no? See attached for patch to JellyServlet and JellyServletContext. Regards, Kelvin The book giving manifesto - http://how.to/sharethisbook - --- -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] __ Do You Yahoo!? Everything you'll ever need on one web page from News and Sport to Email and Music Charts http://uk.my.yahoo.com -- To unsubscribe, e-mail: mailto:commons-dev- [EMAIL PROTECTED] For additional commands, e-mail: mailto:commons-dev- [EMAIL PROTECTED] Index: JellyServlet.java === RCS file: /home/cvspublic/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/servlet/JellyServlet.java,v retrieving revision 1.1 diff -u -r1.1 JellyServlet.java --- JellyServlet.java 9 Dec 2002 15:18:26 - 1.1 +++ JellyServlet.java 17 Dec 2002 00:40:33 - @@ -1,5 +1,5 @@ /* - * $Header: /home/cvspublic/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/servlet/JellyServlet.java,v 1.1 2002/12/09 15:18:26 jstrachan Exp $ + * $Header: +/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/servlet/JellyServlet.java,v + 1.1 2002/12/09 15:18:26 jstrachan Exp $ * $Revision: 1.1 $ * $Date: 2002/12/09 15:18:26 $ * @@ -56,13 +56,12 @@ * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * http://www.apache.org/. - * + * * $Id: JellyServlet.java,v 1.1 2002/12/09 15:18:26 jstrachan Exp $ */ package org.apache.commons.jelly.servlet; -import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; @@ -81,8 +80,8 @@ /** * Servlet for handling display of Jelly-fied XML files. Modelled after VelocityServlet. - * - * @author Kelvin Tan + * + * @author a href=mailto:[EMAIL PROTECTED];Kelvin Tan/a * @version $Revision: 1.1 $ */ public class JellyServlet extends HttpServlet { @@ -96,11 +95,11 @@ */ public static final String RESPONSE = response; - protected void doGet( +protected void doGet( HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - + doRequest(request, response); } @@ -108,7 +107,7 @@ HttpServletRequest request, HttpServletResponse response
Re: [Jelly] JellyServlet
James, On Mon, 9 Dec 2002 15:18:21 -, James Strachan said: Thanks for the patch Kelvin, I've committed it to CVS. I made a minor patch so that the URI itself could denote the script to run. So you could just run http://localhost:8080/foo/index.jelly for example, rather than requiring a template=index.jelly query parameter.. That's nice. I have changed the parameter template to script. Its just that I'm so used to using Velocity. The patch you made uses getServletPath, which returns the url of the servlet being called. I've changed it to getPathInfo. Another thing. Is it really appropriate to require all scripts to be located beneath the web app's context root (which getResource does)? The previous impl using new File(script).getUrl had no such limitation... Some thoughts for further improvement could be... * implement a JellyServletContext so that the getResource() method will use the ServletContext.getResource() method and allow access of relative URIs when performing j:include's. done. * have a parent JellyServletContext to allow access to the initParams of the ServletContext via variable expressions ? * implement the JSTL mappings of request parameters, session parameters, cookies etc in the expression language. * it'd be nice to have a cache of Jelly Scripts to avoid parsing them each time! :-) Here's something which is a little surprise. So it means Jelly is not internally caching scripts? This has some implications for usage of Jelly as a templating subsystem for high-load systems, I imagine. In any event, perhaps it would be a better idea to cache at the engine level, rather than the servlet level, no? See attached for patch to JellyServlet and JellyServletContext. Regards, Kelvin The book giving manifesto - http://how.to/sharethisbook JellyServletContext.java Description: Binary data cvs -z9 diff JellyServlet.java (in directory C:\checkout\jakarta-commons-sandbox\jelly\src\java\org\apache\commons\jelly\servlet\) Index: JellyServlet.java === RCS file: /home/cvspublic/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/servlet/JellyServlet.java,v retrieving revision 1.1 diff -r1.1 JellyServlet.java 2c2 * $Header: /home/cvspublic/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/servlet/JellyServlet.java,v 1.1 2002/12/09 15:18:26 jstrachan Exp $ --- * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/servlet/JellyServlet.java,v 1.1 2002/12/09 15:18:26 jstrachan Exp $ 59c59 * --- * 65d64 import java.io.File; 84,85c83,84 * * @author Kelvin Tan --- * * @author a href=mailto:[EMAIL PROTECTED];Kelvin Tan/a 99c98 protected void doGet( --- protected void doGet( 103c102 --- 111c110 --- 124c123 --- 126d124 URL template = getTemplate(req); 128c126,127 runScript(template, context, req, res); --- URL script = getScript(req); runScript(script, context, req, res); 144,145c143,144 JellyContext ctx = new JellyContext(); --- JellyContext ctx = new JellyServletContext(getServletContext()); 151a151,158 * p * Either use the query parameter script, or the URI itself * to denote the script to run. * /p * p * Example: script=index.jelly or http://localhost:8080/foo/index.jelly. * /p * 157c164 protected URL getTemplate(HttpServletRequest req) --- protected URL getScript(HttpServletRequest req) 159,162c166,169 String script = req.getParameter(template); if (script == null) { script = req.getServletPath(); --- String scriptUrl = req.getParameter(script); if (scriptUrl == null) { scriptUrl = req.getPathInfo(); 164c171,175 return getServletContext().getResource(script); --- URL url = getServletContext().getResource(scriptUrl); if (url == null) { throw new IllegalArgumentException(Invalid script url: + scriptUrl); } return url; 183c194 --- 208c219 --- 213c224 html.append(h2JellyServlet : Error processing the template/h2); --- html.append(h2JellyServlet : Error processing the script/h2); -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
[jelly] code style
James, Any chance of code style guidelines for jelly? I noticed you reformatted JellyServlet. If you use idea, maybe you can post checkin the xml config file for codestyles... Regards, Kelvin The book giving manifesto - http://how.to/sharethisbook -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: [jelly] code style
On Wed, 11 Dec 2002 01:57:35 -0500 (EST), bob mcwhirter said: Any chance of code style guidelines for jelly? I noticed you reformatted JellyServlet. If you use idea, maybe you can post checkin the xml config file for codestyles... I think he tends to follow the Sun Coding Conventions, much to the irritation of those of us following the more sane Turbine-esque conventions, or the perfectly rationalized Werken flavour. +1. But lets not go down this slippery slope. :-) Either way, I think checkstyle should alert you to any violations. Not familiar with this. I use Maven to perform the check, I suppose? I saw a couple of declarations in project.properties... # use Sun coding standards maven.checkstyle.lcurly.type = eol maven.checkstyle.lcurly.method = eol maven.checkstyle.lcurly.other = eol #maven.checkstyle.header.file = src/conf/checkstyle-LICENSE.txt maven.checkstyle.header.ignore.line = 1,2,3,4,5,6 maven.checkstyle.const.pattern = ^[a-z][a-zA-Z0-9]*$ # disable these non-critical errors to highlight # more important ones line missing javadoc maven.checkstyle.max.line.len = 100 maven.checkstyle.ignore.whitespace = true maven.checkstyle.ignore.public.in.interface = true -bob -- To unsubscribe, e-mail: mailto:commons-dev- [EMAIL PROTECTED] For additional commands, e-mail: mailto:commons-dev- [EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: [configuration] XmlConfiguration
Please see attached. Kelvin On Thu, 05 Dec 2002 08:42:16 +0100, Martin Poeschl said: Kelvin Tan wrote: I've noticed XmlConfiguration to be unimplemented for awhile now. Is there any intention to do something about it? I have a basic implementation using dom4j and am willing to contribute it if someone's interested... could you please send the code? ;-) martin BaseConfiguration is populated by keys in the XML file when initialized. The mutator methods are intercepted by XmlConfiguration to modify the Document as well. These changes can be set to auto-persist, without a need to call save() explicitly. Element attributes can be accessed via X.Y.Z[@attribute]. I haven't really dissected BaseConfiguration, so there may be some stuff I'm unaware of regarding impedance mismatching bet BaseConfiguration and a possible xml implementation, but for what I use it for, it works for me. Regards, Kelvin The book giving manifesto - http://how.to/sharethisbook -- To unsubscribe, e-mail: mailto:commons-dev- [EMAIL PROTECTED] For additional commands, e-mail: mailto:commons-dev- [EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:commons-dev- [EMAIL PROTECTED] For additional commands, e-mail: mailto:commons-dev- [EMAIL PROTECTED] XMLConfiguration.java Description: Binary data -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: [configuration] XmlConfiguration
On Wed, 04 Dec 2002 14:25:10 +0100, Nicola Ken Barozzi said: In the Ant codebase, in the proposals/embed dir, ther is a task that uses jxpath for configuration. JXPath can make use of more things than just XML, and is thus much more flexible, and has xpath support. I'd take a look at that file and give that a shot for config. h...I'm not too sure what you're getting at. I'm kinda referring to something which adheres the Configuration interface, but for XML files. Many projects use xml configuration files, and its odd that each project has its own implementation. Isn't that what the configuration sub-project is for (and Commons as a whole), to factor out common components? The minus side, of course, is tagging on another lib dependency, dom4j in this case. Regards, Kelvin The book giving manifesto - http://how.to/sharethisbook -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
[configuration] XmlConfiguration
I've noticed XmlConfiguration to be unimplemented for awhile now. Is there any intention to do something about it? I have a basic implementation using dom4j and am willing to contribute it if someone's interested... BaseConfiguration is populated by keys in the XML file when initialized. The mutator methods are intercepted by XmlConfiguration to modify the Document as well. These changes can be set to auto-persist, without a need to call save() explicitly. Element attributes can be accessed via X.Y.Z[@attribute]. I haven't really dissected BaseConfiguration, so there may be some stuff I'm unaware of regarding impedance mismatching bet BaseConfiguration and a possible xml implementation, but for what I use it for, it works for me. Regards, Kelvin The book giving manifesto - http://how.to/sharethisbook -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
[FileUpload] Delete uploaded files on exit
I've attached a patch for uploaded files to be deleted when the JVM exits properly. Basically a call to deleteOnExit for the uploaded file. I didn't really want a bunch of tmp files lying around. Regards, Kelvin cvs diff DefaultFileItem.java (in directory C:\checkout\jakarta-commons-sandbox\fileupload\src\java\org\apache\commons\fileupload\) Index: DefaultFileItem.java === RCS file: /home/cvspublic/jakarta-commons-sandbox/fileupload/src/java/org/apache/commons/fileupload/DefaultFileItem.java,v retrieving revision 1.2 diff -r1.2 DefaultFileItem.java 395c395,397 item.storeLocation = new File(fileName); --- File f = new File(fileName); f.deleteOnExit(); item.storeLocation = f; -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: Calendar / Scheduler / Workflow
FWIW, Fulcrum has a scheduler service which is an implementation of Unix's cron. Regards, Kelvin - Original Message - From: James House [EMAIL PROTECTED] To: Jakarta Commons Developers List [EMAIL PROTECTED] Sent: Friday, February 15, 2002 11:11 AM Subject: Re: Calendar / Scheduler / Workflow I've got a Job Scheduler project under way at Source Forge - I'm not aware of one here at Commons. The project began last spring, and actually was completed in the sense that there was a release. In fact there are a number of people using it. However, the design was really shoddy, and I removed all of it, and restarted the project from the ground up this fall/winter. It is once again approaching a real release - within 2 to 4 weeks it should be there ... you know how development goes! So far it's got a really sucky web page, and a bunch of code checked in. The code is pretty full of JavaDOC, so anyone should be able to poke around the code and figure out the general ideas. If anyone's interested, please feel free to join the project - or download and use it in a few weeks when it's ready. I'd be happy to see the project end up over in Jakarta land, which I know is based on the project gaining a broad user base and good support record. You can find it here: http://quartz.sourceforge.net -- over the next few days you should see a lot more of it get fleshed out as I get a few more things off the drawing board and into real classes. James At 2/14/2002 05:17 AM -0800, you wrote: Hi, I noticed requests on this list in reference to Workflow, Job Scheduler and Calendar capabilities. I believe that Worklfow and Job Scheduler are part of commons. Is anyone addressing the Calendar. It appears to me that there is commonality betweeen these three components. For calendar there is a need to specify events that occur at some time. These events could be one time, or recurring. Some action takes place (such as notifying the user) at the time of the event. The Job Scheduler needs similar functionality - the action would be to run a job. The calendar also has To Do lists (or worklists in workflow). Is someone looking at these pieces from a holostic view so that the various efforts can leverage the work being done in other services ? Thanks. - viraf __ Do You Yahoo!? Send FREE Valentine eCards with Yahoo! Greetings! http://greetings.yahoo.com -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]