- From: Jean-Guilhem Rouel via cvs-syncmail <cvsmail@w3.org>
- Date: Tue, 11 Aug 2009 13:43:04 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2006/unicorn/org/w3c/unicorn/util In directory hutz:/tmp/cvs-serv6157/org/w3c/unicorn/util Modified Files: Property.java ListFiles.java Unmarshaller.java ClientHttpRequest.java LocalizedString.java TemplateHelper.java LocaleFactory.java Log Message: Code cleanup Index: LocalizedString.java =================================================================== RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/util/LocalizedString.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- LocalizedString.java 17 Jun 2008 13:45:31 -0000 1.5 +++ LocalizedString.java 11 Aug 2009 13:43:02 -0000 1.6 @@ -14,6 +14,7 @@ /** * LocalizedString<br /> * Created: May 30, 2006 11:55:23 AM<br /> + * * @author Jean-Guilhem ROUEL & Damien LEROY */ public class LocalizedString { @@ -26,59 +27,68 @@ /** * Default constructor for LocalizedString. - * + * */ - public LocalizedString () { + public LocalizedString() { LocalizedString.logger.trace("Constructor"); this.mapOfString = new LinkedHashMap<String, String>(); } /** - * Constructs a LocalizedString with an initial string paired with a language. - * @param s The string to be localized. - * @param lang The corresponding language. + * Constructs a LocalizedString with an initial string paired with a + * language. + * + * @param s + * The string to be localized. + * @param lang + * The corresponding language. */ - public LocalizedString (String s, String lang) { + public LocalizedString(String s, String lang) { this(); mapOfString.put(lang, s); } - + /** * Looks for the existence of a specified sLocale string in the map. - * @param sLocale The string to look for. + * + * @param sLocale + * The string to look for. * @return True if the sLocale string is in the map, else false. */ - public boolean hasLocale (final String sLocale) { + public boolean hasLocale(final String sLocale) { return null != this.mapOfString.get(sLocale); } /** - * Adds a message and its corresponding localization - * to the mapOfString attribute. - * @param sLocale The localization. - * @param sMessage The message to be written. - * @return The previous value associated with - * specified key, or null if there was no mapping for key. + * Adds a message and its corresponding localization to the mapOfString + * attribute. + * + * @param sLocale + * The localization. + * @param sMessage + * The message to be written. + * @return The previous value associated with specified key, or null if + * there was no mapping for key. */ - public String addLocalization ( - final String sLocale, - final String sMessage) { + public String addLocalization(final String sLocale, final String sMessage) { LocalizedString.logger.trace("addLocalization"); if (LocalizedString.logger.isDebugEnabled()) { - LocalizedString.logger.debug("Locale : "+sLocale+"."); - LocalizedString.logger.debug("Message : "+sMessage+"."); + LocalizedString.logger.debug("Locale : " + sLocale + "."); + LocalizedString.logger.debug("Message : " + sMessage + "."); } return this.mapOfString.put(sLocale, sMessage); } /** - * Finds and returns the message corresponding to the specified - * localization in the mapOfString. - * @param sLocale The localization wanted. - * @return The message corresponding to the localization - * or if there's none, the one corresponding to the default language. + * Finds and returns the message corresponding to the specified localization + * in the mapOfString. + * + * @param sLocale + * The localization wanted. + * @return The message corresponding to the localization or if there's none, + * the one corresponding to the default language. */ - public String getLocalization (final String sLocale) { + public String getLocalization(final String sLocale) { final String sMessage = this.mapOfString.get(sLocale); if (null != sMessage) { return sMessage; @@ -88,25 +98,28 @@ /** * Returns the keys available in the mapOfString. + * * @return A set with all the keys. */ - public Set<String> getSetOfLocale () { + public Set<String> getSetOfLocale() { return this.mapOfString.keySet(); } /** * Returns the message in in DEFAULT_LANGUAGE (en) or in the first language - * in the list. + * in the list. */ - public String toString () { + @Override + public String toString() { String res = this.mapOfString.get(LocalizedString.DEFAULT_LANGUAGE); - if (res==null) { - for (String s: this.mapOfString.values()) { - return s; + if (res == null) { + for (String s : this.mapOfString.values()) { + return s; } } - if (res==null) + if (res == null) { return ""; + } return res; } Index: TemplateHelper.java =================================================================== RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/util/TemplateHelper.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- TemplateHelper.java 31 Jul 2009 11:16:26 -0000 1.6 +++ TemplateHelper.java 11 Aug 2009 13:43:02 -0000 1.7 @@ -4,47 +4,46 @@ // Please first read the full copyright statement in file COPYRIGHT.html package org.w3c.unicorn.util; -import java.io.File; +import java.io.File; import java.io.FileOutputStream; -import java.io.IOException; +import java.io.IOException; import java.io.OutputStreamWriter; import java.net.MalformedURLException; -import java.util.Iterator; -import java.util.Properties; +import java.util.Iterator; +import java.util.Properties; import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.velocity.Template; import org.apache.velocity.VelocityContext; -import org.apache.velocity.app.Velocity; import org.apache.velocity.app.VelocityEngine; +import org.apache.velocity.runtime.RuntimeConstants; -/** -* TemplateHelper provides functionalities to merge properties object, to load properties objects -* in a velocity context, to get an internationalized template, and to write internationalized templates -* to a file. -* -* @author Thomas GAMBET -*/ -public class TemplateHelper -{ +/** + * TemplateHelper provides functionalities to merge properties object, to load + * properties objects in a velocity context, to get an internationalized + * template, and to write internationalized templates to a file. + * + * @author Thomas GAMBET + */ +public class TemplateHelper { public static final Log logger = LogFactory.getLog("org.w3c.unicorn.util"); - + private static VelocityContext context = new VelocityContext(); + private static VelocityEngine engine = new VelocityEngine(); - + static { Properties aProperties = new Properties(); - + try { - aProperties.load( - Property.getPropertyFileURL("velocity.properties").openStream() - ); + aProperties.load(Property.getPropertyFileURL("velocity.properties") + .openStream()); + + aProperties.put(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, + Property.get("PATH_TO_TEMPLATES")); - aProperties.put(Velocity.FILE_RESOURCE_LOADER_PATH, Property - .get("PATH_TO_TEMPLATES")); - engine.init(aProperties); } catch (MalformedURLException e) { // TODO Auto-generated catch block @@ -57,143 +56,166 @@ e.printStackTrace(); } } - + @SuppressWarnings("finally") public static Properties getPropsFromFile(File propFile) { Properties props = new Properties(); - try { - props.load(propFile.toURL().openStream()); + try { + props.load(propFile.toURI().toURL().openStream()); } catch (IOException e) { - logger.error("Unable to load properties file : " + e.getMessage(), e); + logger.error("Unable to load properties file : " + e.getMessage(), + e); e.printStackTrace(); } finally { return props; } } - - public static Properties getMergeProps(Properties defaultProps, Properties sourceProps) { + + public static Properties getMergeProps(Properties defaultProps, + Properties sourceProps) { Properties propMerge = new Properties(); - + Set<Object> keys = defaultProps.keySet(); Iterator<Object> itr = keys.iterator(); String key; - + while (itr.hasNext()) { key = itr.next().toString(); - if (sourceProps.containsKey(key)) + if (sourceProps.containsKey(key)) { propMerge.put(key, sourceProps.get(key)); - else + } else { propMerge.put(key, defaultProps.get(key)); + } } - + keys = sourceProps.keySet(); itr = keys.iterator(); while (itr.hasNext()) { key = itr.next().toString(); - if (!defaultProps.containsKey(key)) + if (!defaultProps.containsKey(key)) { propMerge.put(key, sourceProps.get(key)); + } } - + return propMerge; } - - public static Properties getMergePropsFromFiles(File defaultPropFile, File sourcePropFile) { + + public static Properties getMergePropsFromFiles(File defaultPropFile, + File sourcePropFile) { Properties defaultProps = new Properties(); Properties sourceProps = new Properties(); - try { - defaultProps.load(defaultPropFile.toURL().openStream()); + try { + defaultProps.load(defaultPropFile.toURI().toURL().openStream()); } catch (IOException e) { - logger.error("Unable to load default language properties : " + e.getMessage(), e); + logger.error("Unable to load default language properties : " + + e.getMessage(), e); e.printStackTrace(); return null; } - - try { - sourceProps.load(sourcePropFile.toURL().openStream()); + + try { + sourceProps.load(sourcePropFile.toURI().toURL().openStream()); } catch (IOException e) { - logger.error("Unable to find desired language properties : " + e.getMessage(), e); + logger.error("Unable to find desired language properties : " + + e.getMessage(), e); e.printStackTrace(); return defaultProps; } - + return getMergeProps(defaultProps, sourceProps); - - /*Properties propMerge = new Properties(); - - Set<Object> keys = defaultProps.keySet(); + + /* + * Properties propMerge = new Properties(); + * + * Set<Object> keys = defaultProps.keySet(); Iterator<Object> itr = + * keys.iterator(); String key; + * + * while (itr.hasNext()) { key = itr.next().toString(); if + * (sourceProps.containsKey(key)) propMerge.put(key, + * sourceProps.get(key)); else propMerge.put(key, + * defaultProps.get(key)); } + * + * return propMerge; + */ + } + + public static void loadInVelocityContext(Properties props, + VelocityContext context) { + Set<Object> keys = props.keySet(); Iterator<Object> itr = keys.iterator(); String key; - while (itr.hasNext()) { key = itr.next().toString(); - if (sourceProps.containsKey(key)) - propMerge.put(key, sourceProps.get(key)); - else - propMerge.put(key, defaultProps.get(key)); - } - - return propMerge;*/ - } - - public static void loadInVelocityContext(Properties props, VelocityContext context) { - Set<Object> keys = props.keySet(); - Iterator<Object> itr = keys.iterator(); - String key; - while (itr.hasNext()) { - key = itr.next().toString(); context.put(key, props.get(key)); - } + } } - - public static Template getInternationalizedTemplate(String templateName, String langCode, VelocityContext context) { - + + public static Template getInternationalizedTemplate(String templateName, + String langCode, VelocityContext context) { + if (langCode != null) { context.put("lang", langCode); - - // Error templates have the same language properties file that their coresponding non-error template + + // Error templates have the same language properties file that their + // coresponding non-error template String langFileName = templateName; - if(templateName.length() > 6 && templateName.substring(templateName.length()-6, templateName.length()).equals(".error")) - langFileName = templateName.substring(0,templateName.length()-6); - + if (templateName.length() > 6 + && templateName.substring(templateName.length() - 6, + templateName.length()).equals(".error")) { + langFileName = templateName.substring(0, + templateName.length() - 6); + } + // Language file for this template - File langFile = new File(Property.get("PATH_TO_LANGUAGE_FILES") + - langFileName + "." + langCode + ".properties"); - + File langFile = new File(Property.get("PATH_TO_LANGUAGE_FILES") + + langFileName + "." + langCode + ".properties"); + // Default language file - File defaultLangFile = new File(Property.get("PATH_TO_LANGUAGE_FILES") + - langFileName + "." + Property.get("DEFAULT_LANGUAGE") + ".properties"); - + File defaultLangFile = new File(Property + .get("PATH_TO_LANGUAGE_FILES") + + langFileName + + "." + + Property.get("DEFAULT_LANGUAGE") + + ".properties"); + // Merge the properties or use default language Properties mergedProps = new Properties(); - + if (langFile.exists()) { mergedProps = getMergePropsFromFiles(defaultLangFile, langFile); - } - else { + } else { try { - mergedProps.load(defaultLangFile.toURL().openStream()); + mergedProps.load(defaultLangFile.toURI().toURL() + .openStream()); } catch (IOException e1) { logger.error("IOException : " + e1.getMessage(), e1); e1.printStackTrace(); } } - - File generalLangFile = new File(Property.get("PATH_TO_LANGUAGE_FILES") + - "general." + langCode + ".properties"); - - if(!generalLangFile.exists()) - generalLangFile = new File(Property.get("PATH_TO_LANGUAGE_FILES") + - "general." + Property.get("DEFAULT_LANGUAGE") + ".properties"); - - mergedProps = getMergeProps(mergedProps, getPropsFromFile(generalLangFile)); - + + File generalLangFile = new File(Property + .get("PATH_TO_LANGUAGE_FILES") + + "general." + langCode + ".properties"); + + if (!generalLangFile.exists()) { + generalLangFile = new File(Property + .get("PATH_TO_LANGUAGE_FILES") + + "general." + + Property.get("DEFAULT_LANGUAGE") + + ".properties"); + } + + mergedProps = getMergeProps(mergedProps, + getPropsFromFile(generalLangFile)); + // Load in velocity context TemplateHelper.loadInVelocityContext(mergedProps, context); } - + // Return the template try { - Template resultTemplate = engine.getTemplate(templateName + ".vm","UTF-8"); + Template resultTemplate = engine.getTemplate(templateName + ".vm", + "UTF-8"); return resultTemplate; } catch (Exception e) { logger.error("Error : " + e.getMessage(), e); @@ -201,49 +223,62 @@ return null; } } - - public static String generateFileFromTemplate(String templateName, String langCode, String destination, String fileExtension, VelocityContext context) { - + + public static String generateFileFromTemplate(String templateName, + String langCode, String destination, String fileExtension, + VelocityContext context) { + String destFileName; String tempFileName; - + String[] split = templateName.split("/"); - if (split.length > 0) + if (split.length > 0) { tempFileName = split[split.length - 1]; - else + } else { tempFileName = templateName; - + } + if (langCode != null) { destFileName = tempFileName + "." + langCode + "." + fileExtension; } else { destFileName = tempFileName + "." + fileExtension; } - - if ((new File(destination + destFileName)).exists()) + + if ((new File(destination + destFileName)).exists()) { return destination + destFileName; - + } + if (langCode != null) { - File langFile = new File(Property.get("PATH_TO_LANGUAGE_FILES") + templateName + "." + langCode + ".properties"); - - if (!langFile.exists() && !langCode.equals(Property.get("DEFAULT_LANGUAGE"))) - return generateFileFromTemplate (templateName, Property.get("DEFAULT_LANGUAGE"), destination, fileExtension, context); + File langFile = new File(Property.get("PATH_TO_LANGUAGE_FILES") + + templateName + "." + langCode + ".properties"); + + if (!langFile.exists() + && !langCode.equals(Property.get("DEFAULT_LANGUAGE"))) { + return generateFileFromTemplate(templateName, Property + .get("DEFAULT_LANGUAGE"), destination, fileExtension, + context); + } } - - Template template = getInternationalizedTemplate(templateName, langCode, context); - - try { - OutputStreamWriter fileWriter = new OutputStreamWriter(new FileOutputStream(destination + destFileName), "UTF-8"); + + Template template = getInternationalizedTemplate(templateName, + langCode, context); + + try { + OutputStreamWriter fileWriter = new OutputStreamWriter( + new FileOutputStream(destination + destFileName), "UTF-8"); template.merge(context, fileWriter); fileWriter.close(); } catch (Exception e) { logger.error("Error : " + e.getMessage(), e); e.printStackTrace(); } - + return destination + destFileName; } - - public static String generateFileFromTemplate(String templateName, String langCode, String destination, String fileExtension) { - return generateFileFromTemplate(templateName, langCode, destination, fileExtension, context); + + public static String generateFileFromTemplate(String templateName, + String langCode, String destination, String fileExtension) { + return generateFileFromTemplate(templateName, langCode, destination, + fileExtension, context); } -} +} Index: Unmarshaller.java =================================================================== RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/util/Unmarshaller.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Unmarshaller.java 26 Aug 2008 15:28:28 -0000 1.3 +++ Unmarshaller.java 11 Aug 2009 13:43:02 -0000 1.4 @@ -9,12 +9,13 @@ /** * Interface for all unmarshaller class in package unicorn. + * * @author Damien LEROY */ public interface Unmarshaller { - public void addURL (final URL aURL) throws IOException; + public void addURL(final URL aURL) throws IOException; - public void unmarshal () throws Exception; + public void unmarshal() throws Exception; } Index: LocaleFactory.java =================================================================== RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/util/LocaleFactory.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- LocaleFactory.java 17 Jun 2008 13:45:31 -0000 1.2 +++ LocaleFactory.java 11 Aug 2009 13:43:02 -0000 1.3 @@ -11,6 +11,7 @@ /** * LocaleFactory<br /> * Created: May 30, 2006 12:08:37 PM<br /> + * * @author Jean-Guilhem ROUEL */ public class LocaleFactory { @@ -19,18 +20,21 @@ /** * Finds a Locale object among the mapOfLocale entries, given its name. - * @param sLocale The name of the Locale. + * + * @param sLocale + * The name of the Locale. * @return The corresponding Locale object. */ - public static Locale getLocale (final String sLocale) { + public static Locale getLocale(final String sLocale) { return LocaleFactory.mapOfLocale.get(sLocale); } /** * Returns the values available in the mapOfLocale. + * * @return The collection of values. */ - public static Collection<Locale> values () { + public static Collection<Locale> values() { return LocaleFactory.mapOfLocale.values(); } Index: ClientHttpRequest.java =================================================================== RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/util/ClientHttpRequest.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- ClientHttpRequest.java 24 Sep 2008 16:40:57 -0000 1.11 +++ ClientHttpRequest.java 11 Aug 2009 13:43:02 -0000 1.12 @@ -5,9 +5,9 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; -import java.net.HttpURLConnection; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -17,10 +17,14 @@ import org.apache.commons.logging.LogFactory; /** - * <p>Title: Client HTTP Request class</p> - * <p>Description: this class helps to send POST HTTP requests with various form data, - * including files. Cookies can be added to be included in the request.</p> - * + * <p> + * Title: Client HTTP Request class + * </p> + * <p> + * Description: this class helps to send POST HTTP requests with various form + * data, including files. Cookies can be added to be included in the request. + * </p> + * * @author Vlad Patryshev * @version 1.0 */ @@ -31,22 +35,23 @@ private static Random aRandom = new Random(); private HttpURLConnection aURLConnection; + private OutputStream aOutputStream = null; + private Map<String, String> mapOfCookie = new HashMap<String, String>(); - private String sBoundary = - "---------------------------" + - ClientHttpRequest.randomString() + - ClientHttpRequest.randomString() + - ClientHttpRequest.randomString(); + private String sBoundary = "---------------------------" + + ClientHttpRequest.randomString() + + ClientHttpRequest.randomString() + + ClientHttpRequest.randomString(); - /** * Connects to the output stream of the URLConnection. + * * @throws IOException */ - private void connect () throws IOException { - //ClientHttpRequest.logger.trace("connect"); + private void connect() throws IOException { + // ClientHttpRequest.logger.trace("connect"); if (null == this.aOutputStream) { this.aOutputStream = this.aURLConnection.getOutputStream(); } @@ -54,10 +59,12 @@ /** * Writes a single character on the output stream. - * @param c The character to write. + * + * @param c + * The character to write. * @throws IOException */ - private void write (final char c) throws IOException { + private void write(final char c) throws IOException { this.connect(); ClientHttpRequest.logger.debug(c); this.aOutputStream.write(c); @@ -65,10 +72,12 @@ /** * Writes a character string on the output stream. - * @param s The string to write. + * + * @param s + * The string to write. * @throws IOException */ - protected void write (final String s) throws IOException { + protected void write(final String s) throws IOException { this.connect(); ClientHttpRequest.logger.debug(s); this.aOutputStream.write(s.getBytes()); @@ -76,19 +85,22 @@ /** * Writes a new line on the output stream (carriage return). + * * @throws IOException */ - protected void newline () throws IOException { + protected void newline() throws IOException { this.connect(); this.write("\r\n"); } /** * Writes a string and a new line on the output stream. - * @param s The string to write before the new line. + * + * @param s + * The string to write before the new line. * @throws IOException */ - protected void writeln (final String s) throws IOException { + protected void writeln(final String s) throws IOException { this.connect(); this.write(s); this.newline(); @@ -96,46 +108,50 @@ /** * Computes a random string. - * @return A string containing a random long which radix is 36. + * + * @return A string containing a random long which radix is 36. */ - protected static String randomString () { + protected static String randomString() { return Long.toString(ClientHttpRequest.aRandom.nextLong(), 36); } /** * Writes the sBoundary on the output, composed of three random strings. + * * @throws IOException */ - private void boundary () throws IOException { + private void boundary() throws IOException { this.write("--"); this.write(this.sBoundary); } /** - * Creates a new multipart POST HTTP request on a freshly opened URLConnection - * - * @param aURLConnection an already open URL connection + * Creates a new multipart POST HTTP request on a freshly opened + * URLConnection + * + * @param aURLConnection + * an already open URL connection * @throws IOException */ - public ClientHttpRequest ( - final URLConnection aURLConnection) throws IOException { + public ClientHttpRequest(final URLConnection aURLConnection) + throws IOException { ClientHttpRequest.logger.trace("Constructor(URLConnection)"); this.aURLConnection = (HttpURLConnection) aURLConnection; - this.aURLConnection.setRequestMethod("POST"); + this.aURLConnection.setRequestMethod("POST"); this.aURLConnection.setDoOutput(true); - this.aURLConnection.setRequestProperty( - "Content-Type", + this.aURLConnection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + this.sBoundary); } /** * Creates a new multipart POST HTTP request for a specified URL - * - * @param aURL the URL to send request to + * + * @param aURL + * the URL to send request to * @throws IOException */ - public ClientHttpRequest (final URL aURL) throws IOException { - this(aURL.openConnection()); + public ClientHttpRequest(final URL aURL) throws IOException { + this(aURL.openConnection()); ClientHttpRequest.logger.trace("Constructor(URL)"); if (ClientHttpRequest.logger.isDebugEnabled()) { ClientHttpRequest.logger.debug("URL : " + aURL + "."); @@ -144,12 +160,12 @@ /** * Creates a new multipart POST HTTP request for a specified URL string - * - * @param sURL the string representation of the URL to send request to + * + * @param sURL + * the string representation of the URL to send request to * @throws IOException */ - public ClientHttpRequest ( - final String sURL) throws IOException { + public ClientHttpRequest(final String sURL) throws IOException { this(new URL(sURL)); ClientHttpRequest.logger.trace("Constructor(String)"); if (ClientHttpRequest.logger.isDebugEnabled()) { @@ -159,54 +175,69 @@ /** * adds a cookie to the request - * @param sName cookie name - * @param sValue cookie value + * + * @param sName + * cookie name + * @param sValue + * cookie value * @throws IOException */ - public void setCookie ( - final String sName, - final String sValue) throws IOException { + public void setCookie(final String sName, final String sValue) + throws IOException { this.mapOfCookie.put(sName, sValue); } /** * Adds cookies to the request. - * @param cookies the cookie "name-to-value" map + * + * @param cookies + * the cookie "name-to-value" map * @throws IOException */ - public void setCookies ( - final Map<String, String> mapOfCookie) throws IOException { - if (null == mapOfCookie) return; + public void setCookies(final Map<String, String> mapOfCookie) + throws IOException { + if (null == mapOfCookie) { + return; + } this.mapOfCookie.putAll(mapOfCookie); } /** * Adds cookies to the request. - * @param tStringCookie Array of cookie names and values (cookies[2*i] is a name, cookies[2*i + 1] is a value). + * + * @param tStringCookie + * Array of cookie names and values (cookies[2*i] is a name, + * cookies[2*i + 1] is a value). * @throws IOException */ - public void setCookies (final String[] tStringCookie) throws IOException { - if (tStringCookie == null) return; + public void setCookies(final String[] tStringCookie) throws IOException { + if (tStringCookie == null) { + return; + } for (int i = 0; i < tStringCookie.length - 1; i += 2) { - this.setCookie(tStringCookie[i], tStringCookie[i+1]); + this.setCookie(tStringCookie[i], tStringCookie[i + 1]); } } /** - * Sets a new language. - * @param sLang The new language chosen. + * Sets a new language. + * + * @param sLang + * The new language chosen. */ - public void setLang (final String sLang) { - ClientHttpRequest.logger.debug("setLang("+sLang+")"); + public void setLang(final String sLang) { + ClientHttpRequest.logger.debug("setLang(" + sLang + ")"); this.aURLConnection.setRequestProperty("Accept-Language", sLang); } /** * Writes a name in the appropriate format on the output. - * @param sName The name to write. + * + * @param sName + * The name to write. * @throws IOException */ - private void writeName (final String sName) throws IOException { + private void writeName(final String sName) throws IOException { this.newline(); this.write("Content-Disposition: form-data; name=\""); this.write(sName); @@ -215,13 +246,15 @@ /** * Adds a string parameter to the request. - * @param sName Parameter name. - * @param sValue Parameter value. + * + * @param sName + * Parameter name. + * @param sValue + * Parameter value. * @throws IOException */ - public void setParameter ( - final String sName, - final String sValue) throws IOException { + public void setParameter(final String sName, final String sValue) + throws IOException { ClientHttpRequest.logger.trace("setParameter(String, String)"); if (ClientHttpRequest.logger.isDebugEnabled()) { ClientHttpRequest.logger.debug("Name : " + sName + "."); @@ -240,8 +273,7 @@ * @param aOutputStream * @throws IOException */ - private static void pipe ( - final InputStream aInputStream, + private static void pipe(final InputStream aInputStream, final OutputStream aOutputStream) throws IOException { byte[] tByte = new byte[500000]; int iNbRead; @@ -258,20 +290,24 @@ /** * Adds a file parameter to the request. - * @param sName Parameter name. - * @param sFileName The name of the file. - * @param aInputStream input stream to read the contents of the file from + * + * @param sName + * Parameter name. + * @param sFileName + * The name of the file. + * @param aInputStream + * input stream to read the contents of the file from * @throws IOException */ - public void setParameter ( - final String sName, - final String sFileName, + public void setParameter(final String sName, final String sFileName, final InputStream aInputStream) throws IOException { - ClientHttpRequest.logger.trace("setParameter(String, String, InputStream)"); + ClientHttpRequest.logger + .trace("setParameter(String, String, InputStream)"); if (ClientHttpRequest.logger.isDebugEnabled()) { ClientHttpRequest.logger.debug("Name : " + sName + "."); ClientHttpRequest.logger.debug("File name : " + sFileName + "."); - ClientHttpRequest.logger.debug("InputStream : " + aInputStream + "."); + ClientHttpRequest.logger.debug("InputStream : " + aInputStream + + "."); } this.boundary(); this.writeName(sName); @@ -281,7 +317,9 @@ this.newline(); this.write("Content-Type: "); String sType = URLConnection.guessContentTypeFromName(sFileName); - if (sType == null) sType = "application/octet-stream"; + if (sType == null) { + sType = "application/octet-stream"; + } this.writeln(sType); this.newline(); ClientHttpRequest.pipe(aInputStream, this.aOutputStream); @@ -290,25 +328,32 @@ /** * adds a file parameter to the request - * @param sName parameter name - * @param aFile the file to upload + * + * @param sName + * parameter name + * @param aFile + * the file to upload * @throws IOException */ - public void setParameter ( - final String sName, - final File aFile) throws IOException { + public void setParameter(final String sName, final File aFile) + throws IOException { this.setParameter(sName, aFile.getPath(), new FileInputStream(aFile)); } /** - * adds a parameter to the request; if the parameter is a File, the file is uploaded, otherwise the string value of the parameter is passed in the request - * @param sName parameter name - * @param object parameter value, a File or anything else that can be stringified + * adds a parameter to the request; if the parameter is a File, the file is + * uploaded, otherwise the string value of the parameter is passed in the + * request + * + * @param sName + * parameter name + * @param object + * parameter value, a File or anything else that can be + * stringified * @throws IOException */ - public void setParameter ( - final String sName, - final Object aObject) throws IOException { + public void setParameter(final String sName, final Object aObject) + throws IOException { if (aObject instanceof File) { this.setParameter(sName, (File) aObject); } else { @@ -318,12 +363,19 @@ /** * adds parameters to the request - * @param mapOfParameter "name-to-value" map of parameters; if a value is a file, the file is uploaded, otherwise it is stringified and sent in the request + * + * @param mapOfParameter + * "name-to-value" map of parameters; if a value is a file, the + * file is uploaded, otherwise it is stringified and sent in the + * request * @throws IOException */ - public void setParameters (final Map mapOfParameter) throws IOException { - if (mapOfParameter == null) return; - for (final Iterator aIterator = mapOfParameter.entrySet().iterator(); aIterator.hasNext();) { + public void setParameters(final Map mapOfParameter) throws IOException { + if (mapOfParameter == null) { + return; + } + for (final Iterator aIterator = mapOfParameter.entrySet().iterator(); aIterator + .hasNext();) { final Map.Entry entry = (Map.Entry) aIterator.next(); this.setParameter(entry.getKey().toString(), entry.getValue()); } @@ -331,23 +383,33 @@ /** * adds parameters to the request - * @param tObjectParameter array of parameter names and values (parameters[2*i] is a name, parameters[2*i + 1] is a value); if a value is a file, the file is uploaded, otherwise it is stringified and sent in the request + * + * @param tObjectParameter + * array of parameter names and values (parameters[2*i] is a + * name, parameters[2*i + 1] is a value); if a value is a file, + * the file is uploaded, otherwise it is stringified and sent in + * the request * @throws IOException */ - public void setParameters ( - final Object[] tObjectParameter) throws IOException { - if (tObjectParameter == null) return; + public void setParameters(final Object[] tObjectParameter) + throws IOException { + if (tObjectParameter == null) { + return; + } for (int i = 0; i < tObjectParameter.length - 1; i += 2) { - this.setParameter(tObjectParameter[i].toString(), tObjectParameter[i + 1]); + this.setParameter(tObjectParameter[i].toString(), + tObjectParameter[i + 1]); } } /** - * posts the requests to the server, with all the cookies and parameters that were added + * posts the requests to the server, with all the cookies and parameters + * that were added + * * @return input stream with the server response * @throws IOException */ - public InputStream post () throws IOException { + public InputStream post() throws IOException { this.boundary(); this.writeln("--"); this.aOutputStream.close(); @@ -356,40 +418,52 @@ } /** - * posts the requests to the server, with all the cookies and parameters that were added before (if any), and with parameters that are passed in the argument - * @param mapOfParameter request parameters + * posts the requests to the server, with all the cookies and parameters + * that were added before (if any), and with parameters that are passed in + * the argument + * + * @param mapOfParameter + * request parameters * @return input stream with the server response * @throws IOException * @see setParameters */ - public InputStream post (final Map mapOfParameter) throws IOException { + public InputStream post(final Map mapOfParameter) throws IOException { this.setParameters(mapOfParameter); return this.post(); } /** - * posts the requests to the server, with all the cookies and parameters that were added before (if any), and with parameters that are passed in the argument - * @param tObjectParameter request parameters + * posts the requests to the server, with all the cookies and parameters + * that were added before (if any), and with parameters that are passed in + * the argument + * + * @param tObjectParameter + * request parameters * @return input stream with the server response * @throws IOException * @see setParameters */ - public InputStream post (final Object[] tObjectParameter) throws IOException { + public InputStream post(final Object[] tObjectParameter) throws IOException { this.setParameters(tObjectParameter); return this.post(); } /** - * posts the requests to the server, with all the cookies and parameters that were added before (if any), and with cookies and parameters that are passed in the arguments - * @param mapOfCookie request cookies - * @param mapOfParameter request parameters + * posts the requests to the server, with all the cookies and parameters + * that were added before (if any), and with cookies and parameters that are + * passed in the arguments + * + * @param mapOfCookie + * request cookies + * @param mapOfParameter + * request parameters * @return input stream with the server response * @throws IOException * @see setParameters * @see setCookies */ - public InputStream post ( - final Map<String, String> mapOfCookie, + public InputStream post(final Map<String, String> mapOfCookie, final Map mapOfParameter) throws IOException { this.setCookies(mapOfCookie); this.setParameters(mapOfParameter); @@ -397,16 +471,20 @@ } /** - * posts the requests to the server, with all the cookies and parameters that were added before (if any), and with cookies and parameters that are passed in the arguments - * @param tStringCookie request cookies - * @param tObjectParameter request parameters + * posts the requests to the server, with all the cookies and parameters + * that were added before (if any), and with cookies and parameters that are + * passed in the arguments + * + * @param tStringCookie + * request cookies + * @param tObjectParameter + * request parameters * @return input stream with the server response * @throws IOException * @see setParameters * @see setCookies */ - public InputStream post ( - final String[] tStringCookie, + public InputStream post(final String[] tStringCookie, final Object[] tObjectParameter) throws IOException { this.setCookies(tStringCookie); this.setParameters(tObjectParameter); @@ -415,56 +493,63 @@ /** * post the POST request to the server, with the specified parameter - * @param sName parameter name - * @param oValue parameter value + * + * @param sName + * parameter name + * @param oValue + * parameter value * @return input stream with the server response * @throws IOException * @see setParameter */ - public InputStream post ( - final String sName, - final Object oValue) throws IOException { + public InputStream post(final String sName, final Object oValue) + throws IOException { this.setParameter(sName, oValue); return this.post(); } /** * post the POST request to the server, with the specified parameters - * @param sName1 first parameter name - * @param oValue1 first parameter value - * @param sName2 second parameter name - * @param oValue2 second parameter value + * + * @param sName1 + * first parameter name + * @param oValue1 + * first parameter value + * @param sName2 + * second parameter name + * @param oValue2 + * second parameter value * @return input stream with the server response * @throws IOException * @see setParameter */ - public InputStream post ( - final String sName1, - final Object oValue1, - final String sName2, - final Object oValue2) throws IOException { + public InputStream post(final String sName1, final Object oValue1, + final String sName2, final Object oValue2) throws IOException { this.setParameter(sName1, oValue1); return this.post(sName2, oValue2); } /** * post the POST request to the server, with the specified parameters - * @param sName1 first parameter name - * @param oValue1 first parameter value - * @param sName2 second parameter name - * @param oValue2 second parameter value - * @param sName3 third parameter name - * @param oValue3 third parameter value + * + * @param sName1 + * first parameter name + * @param oValue1 + * first parameter value + * @param sName2 + * second parameter name + * @param oValue2 + * second parameter value + * @param sName3 + * third parameter name + * @param oValue3 + * third parameter value * @return input stream with the server response * @throws IOException * @see setParameter */ - public InputStream post ( - final String sName1, - final Object oValue1, - final String sName2, - final Object oValue2, - final String sName3, + public InputStream post(final String sName1, final Object oValue1, + final String sName2, final Object oValue2, final String sName3, final Object oValue3) throws IOException { this.setParameter(sName1, oValue1); return this.post(sName2, oValue2, sName3, oValue3); @@ -472,177 +557,196 @@ /** * post the POST request to the server, with the specified parameters - * @param sName1 first parameter name - * @param oValue1 first parameter value - * @param sName2 second parameter name - * @param oValue2 second parameter value - * @param sName3 third parameter name - * @param oValue3 third parameter value - * @param sName4 fourth parameter name - * @param oValue4 fourth parameter value + * + * @param sName1 + * first parameter name + * @param oValue1 + * first parameter value + * @param sName2 + * second parameter name + * @param oValue2 + * second parameter value + * @param sName3 + * third parameter name + * @param oValue3 + * third parameter value + * @param sName4 + * fourth parameter name + * @param oValue4 + * fourth parameter value * @return input stream with the server response * @throws IOException * @see setParameter */ - public InputStream post ( - final String sName1, - final Object oValue1, - final String sName2, - final Object oValue2, - final String sName3, - final Object oValue3, - final String sName4, - final Object oValue4) throws IOException { + public InputStream post(final String sName1, final Object oValue1, + final String sName2, final Object oValue2, final String sName3, + final Object oValue3, final String sName4, final Object oValue4) + throws IOException { this.setParameter(sName1, oValue1); return this.post(sName2, oValue2, sName3, oValue3, sName4, oValue4); } /** - * posts a new request to specified URL, with parameters that are passed in the argument - * @param mapOfParameter request parameters + * posts a new request to specified URL, with parameters that are passed in + * the argument + * + * @param mapOfParameter + * request parameters * @return input stream with the server response * @throws IOException * @see setParameters */ - public static InputStream post ( - final URL aURL, - final Map mapOfParameter) throws IOException { + public static InputStream post(final URL aURL, final Map mapOfParameter) + throws IOException { return new ClientHttpRequest(aURL).post(mapOfParameter); } /** - * posts a new request to specified URL, with parameters that are passed in the argument - * @param tObjectParameter request parameters + * posts a new request to specified URL, with parameters that are passed in + * the argument + * + * @param tObjectParameter + * request parameters * @return input stream with the server response * @throws IOException * @see setParameters */ - public static InputStream post ( - final URL aURL, + public static InputStream post(final URL aURL, final Object[] tObjectParameter) throws IOException { return new ClientHttpRequest(aURL).post(tObjectParameter); } /** - * posts a new request to specified URL, with cookies and parameters that are passed in the argument - * @param mapOfCookie request cookies - * @param mapOfParameter request parameters + * posts a new request to specified URL, with cookies and parameters that + * are passed in the argument + * + * @param mapOfCookie + * request cookies + * @param mapOfParameter + * request parameters * @return input stream with the server response * @throws IOException * @see setCookies * @see setParameters */ - public static InputStream post ( - final URL aURL, - final Map<String, String> mapOfCookie, - final Map mapOfParameter) throws IOException { + public static InputStream post(final URL aURL, + final Map<String, String> mapOfCookie, final Map mapOfParameter) + throws IOException { return new ClientHttpRequest(aURL).post(mapOfCookie, mapOfParameter); } /** - * posts a new request to specified URL, with cookies and parameters that are passed in the argument - * @param tStringCookie request cookies - * @param tObjectParameter request parameters + * posts a new request to specified URL, with cookies and parameters that + * are passed in the argument + * + * @param tStringCookie + * request cookies + * @param tObjectParameter + * request parameters * @return input stream with the server response * @throws IOException * @see setCookies * @see setParameters */ - public static InputStream post ( - final URL aURL, - final String[] tStringCookie, - final Object[] tObjectParameter) throws IOException { - return new ClientHttpRequest(aURL).post(tStringCookie, tObjectParameter); + public static InputStream post(final URL aURL, + final String[] tStringCookie, final Object[] tObjectParameter) + throws IOException { + return new ClientHttpRequest(aURL) + .post(tStringCookie, tObjectParameter); } /** * post the POST request specified URL, with the specified parameter - * @param name parameter name - * @param value parameter value + * + * @param name + * parameter name + * @param value + * parameter value * @return input stream with the server response * @throws IOException * @see setParameter */ - public static InputStream post ( - final URL aURL, - final String sName, + public static InputStream post(final URL aURL, final String sName, final Object oValue) throws IOException { return new ClientHttpRequest(aURL).post(sName, oValue); } /** * post the POST request to specified URL, with the specified parameters - * @param sName1 first parameter name - * @param oValue1 first parameter value - * @param sName2 second parameter name - * @param oValue2 second parameter value + * + * @param sName1 + * first parameter name + * @param oValue1 + * first parameter value + * @param sName2 + * second parameter name + * @param oValue2 + * second parameter value * @return input stream with the server response * @throws IOException * @see setParameter */ - public static InputStream post ( - final URL aURL, - final String sName1, - final Object oValue1, - final String sName2, - final Object oValue2) throws IOException { - return new ClientHttpRequest(aURL).post(sName1, oValue1, sName2, oValue2); + public static InputStream post(final URL aURL, final String sName1, + final Object oValue1, final String sName2, final Object oValue2) + throws IOException { + return new ClientHttpRequest(aURL).post(sName1, oValue1, sName2, + oValue2); } /** * post the POST request to specified URL, with the specified parameters - * @param sName1 first parameter name - * @param oValue1 first parameter value - * @param sName2 second parameter name - * @param oValue2 second parameter value - * @param sName3 third parameter name - * @param oValue3 third parameter value + * + * @param sName1 + * first parameter name + * @param oValue1 + * first parameter value + * @param sName2 + * second parameter name + * @param oValue2 + * second parameter value + * @param sName3 + * third parameter name + * @param oValue3 + * third parameter value * @return input stream with the server response * @throws IOException * @see setParameter */ - public static InputStream post ( - final URL aURL, - final String sName1, - final Object oValue1, - final String sName2, - final Object oValue2, - final String sName3, - final Object oValue3) throws IOException { - return new ClientHttpRequest(aURL).post( - sName1, oValue1, - sName2, oValue2, - sName3, oValue3); + public static InputStream post(final URL aURL, final String sName1, + final Object oValue1, final String sName2, final Object oValue2, + final String sName3, final Object oValue3) throws IOException { + return new ClientHttpRequest(aURL).post(sName1, oValue1, sName2, + oValue2, sName3, oValue3); } /** * post the POST request to specified URL, with the specified parameters - * @param name1 first parameter name - * @param value1 first parameter value - * @param name2 second parameter name - * @param value2 second parameter value - * @param name3 third parameter name - * @param value3 third parameter value - * @param sName4 fourth parameter name - * @param oValue4 fourth parameter value + * + * @param name1 + * first parameter name + * @param value1 + * first parameter value + * @param name2 + * second parameter name + * @param value2 + * second parameter value + * @param name3 + * third parameter name + * @param value3 + * third parameter value + * @param sName4 + * fourth parameter name + * @param oValue4 + * fourth parameter value * @return input stream with the server response * @throws IOException * @see setParameter */ - public static InputStream post ( - final URL aURL, - final String sName1, - final Object oValue1, - final String sName2, - final Object oValue2, - final String sName3, - final Object oValue3, - final String sName4, + public static InputStream post(final URL aURL, final String sName1, + final Object oValue1, final String sName2, final Object oValue2, + final String sName3, final Object oValue3, final String sName4, final Object oValue4) throws IOException { - return new ClientHttpRequest(aURL).post( - sName1, oValue1, - sName2, oValue2, - sName3, oValue3, - sName4, oValue4); + return new ClientHttpRequest(aURL).post(sName1, oValue1, sName2, + oValue2, sName3, oValue3, sName4, oValue4); } } Index: Property.java =================================================================== RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/util/Property.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Property.java 29 Jul 2009 13:23:34 -0000 1.6 +++ Property.java 11 Aug 2009 13:43:02 -0000 1.7 @@ -23,50 +23,56 @@ public class Property { private static final Log logger = LogFactory.getLog(Property.class); + private static final Map<String, Property> mapOfProperty = new Hashtable<String, Property>(); /** * Adds a Property object to the static mapOfProperty. - * @param aProperty The Property to be add. + * + * @param aProperty + * The Property to be add. */ - private static void addProperty (final Property aProperty) { + private static void addProperty(final Property aProperty) { Property.logger.trace("addProperty"); if (Property.logger.isDebugEnabled()) { - Property.logger.debug("Name : "+aProperty.getID()+"."); - Property.logger.debug("Value : "+aProperty.getValue()+"."); + Property.logger.debug("Name : " + aProperty.getID() + "."); + Property.logger.debug("Value : " + aProperty.getValue() + "."); } Property.mapOfProperty.put(aProperty.getID(), aProperty); } /** * Finds a Property in the map given its ID. - * @param sID The ID of the Property wanted. - * @return The corresponding Property object - * or null if there's none. + * + * @param sID + * The ID of the Property wanted. + * @return The corresponding Property object or null if there's none. */ - public static Property getProperty (final String sID) { + public static Property getProperty(final String sID) { return Property.mapOfProperty.get(sID); } /** * Gets the value of a Property in the map given its ID. - * @param sID The ID of the Property wanted. - * @return The value of the corresponding Property - * or null if there's none. + * + * @param sID + * The ID of the Property wanted. + * @return The value of the corresponding Property or null if there's none. */ - public static String get (final String sID) { + public static String get(final String sID) { return Property.mapOfProperty.get(sID).getValue(); } /** * Adds the given properties in the map. - * @param aProperties The properties to be loaded. + * + * @param aProperties + * The properties to be loaded. */ - public static void load (final Properties aProperties) { + public static void load(final Properties aProperties) { Property.logger.trace("load"); - for ( - final Enumeration aEnumeration = aProperties.propertyNames(); - aEnumeration.hasMoreElements();) { + for (final Enumeration aEnumeration = aProperties.propertyNames(); aEnumeration + .hasMoreElements();) { final String sPropName = (String) aEnumeration.nextElement(); final String sPropValue = aProperties.getProperty(sPropName); Property.parseValue(sPropName, sPropValue); @@ -75,29 +81,35 @@ /** * Adds a Property in the map with the given name and value. - * @param sPropName The name of the Property. - * @param sPropValue The value of the Property. + * + * @param sPropName + * The name of the Property. + * @param sPropValue + * The value of the Property. */ - private static void parseValue (final String sPropName, final String sPropValue) { + private static void parseValue(final String sPropName, + final String sPropValue) { Property.logger.trace("parseValue"); if (Property.logger.isDebugEnabled()) { - Property.logger.debug("Name : "+sPropName+"."); - Property.logger.debug("Value : "+sPropValue+"."); + Property.logger.debug("Name : " + sPropName + "."); + Property.logger.debug("Value : " + sPropValue + "."); } Property aProperty = Property.getProperty(sPropName); if (aProperty == null) { - Property.logger.debug("Property "+sPropName+" not already exist."); + Property.logger.debug("Property " + sPropName + + " not already exist."); aProperty = new Property(); aProperty.setID(sPropName); } else { - Property.logger.debug("Property "+sPropName+" already exist."); + Property.logger.debug("Property " + sPropName + " already exist."); aProperty.clear(); } final String[] tStringElement = sPropValue.split(","); for (String sElement : tStringElement) { sElement = sElement.trim(); if (sElement.equals("")) { - Property.logger.warn("Empty element found in property "+sPropName+"."); + Property.logger.warn("Empty element found in property " + + sPropName + "."); continue; } if (sElement.startsWith("$")) { @@ -106,72 +118,82 @@ Property aNotherProperty; aNotherProperty = Property.getProperty(sPropRef); if (null == aNotherProperty) { - Property.logger.warn("Property "+sPropRef+" not found."); + Property.logger + .warn("Property " + sPropRef + " not found."); aNotherProperty = new Property(); aNotherProperty.setID(sPropRef); Property.addProperty(aNotherProperty); } aProperty.addElement(aNotherProperty); - } - else { + } else { aProperty.setSpecific(sElement); // the specific part is the last part of the property break; } - } + } Property.addProperty(aProperty); } private List<Property> listOfElement = new ArrayList<Property>(); + private String sSpecificElement = ""; + private String sID = null; /** * Gives the ID of the current Property. + * * @return The ID of the Property. */ - private String getID () { + private String getID() { return this.sID; } /** * Sets the ID of the Property. - * @param sID The ID to set. + * + * @param sID + * The ID to set. */ - private void setID (final String sID) { + private void setID(final String sID) { this.sID = sID; } /** * Adds a Property to the listOfElement. - * @param aProperty The property to add. + * + * @param aProperty + * The property to add. */ - private void addElement (final Property aProperty) { + private void addElement(final Property aProperty) { this.listOfElement.add(aProperty); } - + /** * Erases the contents of listOfElement. - * + * */ - public void clear () { + public void clear() { this.listOfElement.clear(); this.sSpecificElement = ""; } - + /** * Sets a specific element in the list. - * @param sSpecific The name of the specific element. + * + * @param sSpecific + * The name of the specific element. */ - public void setSpecific (final String sSpecific) { + public void setSpecific(final String sSpecific) { this.sSpecificElement = sSpecific; } /** * Gives the value of the Property. + * * @return The value of the Property. */ - public String getValue () { + public String getValue() { final int iStringBufferSize = 500; final StringBuffer aStringBuffer = new StringBuffer(iStringBufferSize); @@ -183,11 +205,13 @@ return aStringBuffer.toString(); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see java.lang.Object#toString() */ @Override - public String toString () { + public String toString() { final int iStringBufferSize = 500; final StringBuffer aStringBuffer = new StringBuffer(iStringBufferSize); @@ -198,45 +222,50 @@ return aStringBuffer.toString(); } - + public static URL getPropertyFileURL(String file) { URL aURLPropFile; try { - if (System.getProperty("unicorn.conf") != null) - aURLPropFile = new URL("file://" + System.getProperty("unicorn.conf") + "/" + file); - else - aURLPropFile = new URL(Property.class.getResource("/"), "org/w3c/unicorn/conf/" + file); + if (System.getProperty("unicorn.conf") != null) { + aURLPropFile = new URL("file://" + + System.getProperty("unicorn.conf") + "/" + file); + } else { + aURLPropFile = new URL(Property.class.getResource("/"), + "org/w3c/unicorn/conf/" + file); + } return aURLPropFile; } catch (MalformedURLException e) { - Property.logger.error("Could not load property file :" + file + "||" + e.getMessage(), e); + Property.logger.error("Could not load property file :" + file + + "||" + e.getMessage(), e); e.printStackTrace(); return null; - } + } } - static { try { URL aURLPropFile = getPropertyFileURL("unicorn.properties"); - + final Properties aProperties = new Properties(); aProperties.load(aURLPropFile.openStream()); Property.load(aProperties); } catch (final IOException e) { - Property.logger.error("IOException : "+e.getMessage(), e); + Property.logger.error("IOException : " + e.getMessage(), e); e.printStackTrace(); } } - + /** * For each Property in the map, prints its ID and value. + * * @param tArgument */ - public static void main (final String[] tArgument) { + public static void main(final String[] tArgument) { System.out.println("Begin."); - + for (final Property aProperty : Property.mapOfProperty.values()) { - System.out.println(aProperty.getID() + " = " + aProperty.getValue()); + System.out + .println(aProperty.getID() + " = " + aProperty.getValue()); } System.out.println("End."); Index: ListFiles.java =================================================================== RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/util/ListFiles.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- ListFiles.java 16 Jan 2008 17:19:56 -0000 1.2 +++ ListFiles.java 11 Aug 2009 13:43:02 -0000 1.3 @@ -18,6 +18,7 @@ * ListFiles<br /> * Created: Jun 26, 2006 2:17:42 PM<br /> * This class provides static methods to list files into a directory. + * * @author Jean-Guilhem ROUEL */ public class ListFiles { @@ -26,15 +27,16 @@ /** * List all files matching a pattern in a directory - * @param sDirectory the directory to list - * @param sFilterPattern only filenames matching this pattern will be returned + * + * @param sDirectory + * the directory to list + * @param sFilterPattern + * only filenames matching this pattern will be returned * @return an array of files matching the pattern * @throws FileNotFoundException */ - public static File[] listFiles ( - final String sDirectory, - final String sFilterPattern) throws - FileNotFoundException { + public static File[] listFiles(final String sDirectory, + final String sFilterPattern) throws FileNotFoundException { ListFiles.logger.trace("listFiles(String, String)"); if (ListFiles.logger.isDebugEnabled()) { ListFiles.logger.debug("Directory : " + sDirectory + "."); @@ -42,9 +44,9 @@ } final File aDirectory = new File(sDirectory); - final Pattern aPattern = Pattern.compile(sFilterPattern); + final Pattern aPattern = Pattern.compile(sFilterPattern); final FilenameFilter aFilenameFilter = new FilenameFilter() { - public boolean accept (File aDirectory, String sName) { + public boolean accept(File aDirectory, String sName) { File aFile = new File(aDirectory.getPath() + sName); if (aFile.isDirectory()) { return false; @@ -56,24 +58,22 @@ final File[] tFile = aDirectory.listFiles(aFilenameFilter); if (null == tFile) { - throw new FileNotFoundException( - "File in " + - sDirectory + - " matching pattern " + - sFilterPattern + - " not found."); + throw new FileNotFoundException("File in " + sDirectory + + " matching pattern " + sFilterPattern + " not found."); } return tFile; } /** * List all filesin a directory - * @param sDirectory the directory to list + * + * @param sDirectory + * the directory to list * @return an array of files * @throws FileNotFoundException */ - public static File[] listFiles (final String sDirectory) - throws FileNotFoundException { + public static File[] listFiles(final String sDirectory) + throws FileNotFoundException { ListFiles.logger.trace("listFiles(String)"); if (ListFiles.logger.isDebugEnabled()) { ListFiles.logger.debug("Directory : " + sDirectory + "."); @@ -81,24 +81,26 @@ final File aDirectory = new File(sDirectory); final FileFilter aFileFilter = new FileFilter() { - public boolean accept (File aFile) { - return !aFile.isDirectory(); - } - }; + public boolean accept(File aFile) { + return !aFile.isDirectory(); + } + }; final File[] tFile = aDirectory.listFiles(aFileFilter); if (null == tFile) { - throw new FileNotFoundException("File in "+sDirectory+" not found."); + throw new FileNotFoundException("File in " + sDirectory + + " not found."); } return tFile; } /** - * For testing purpose + * For testing purpose + * * @param args * @throws FileNotFoundException */ - public static void main (String[] args) throws FileNotFoundException { + public static void main(String[] args) throws FileNotFoundException { File[] files = listFiles("/home/jean"); for (final File file : files) { System.out.println(file.getAbsolutePath());
Received on Tuesday, 11 August 2009 13:43:24 UTC