- From: Mercurial notifier <nobody@w3.org>
- Date: Fri, 18 Jun 2010 15:50:07 -0400
- To: Unicorn Updates <www-validator-cvs@w3.org>
changeset: 1271:f6f2cf6f3842 user: Thomas Gambet <tgambet@w3.org> date: Fri Jun 18 15:07:25 2010 -0400 files: src/org/w3c/unicorn/Framework.java description: load default messages from messages.properties during initialization diff -r adad153fecf4 -r f6f2cf6f3842 src/org/w3c/unicorn/Framework.java --- a/src/org/w3c/unicorn/Framework.java Fri Jun 18 15:06:52 2010 -0400 +++ b/src/org/w3c/unicorn/Framework.java Fri Jun 18 15:07:25 2010 -0400 @@ -44,6 +44,8 @@ import org.w3c.unicorn.tasklist.parameters.Value; import org.w3c.unicorn.util.Language; import org.w3c.unicorn.util.ListFiles; +import org.w3c.unicorn.util.Message; +import org.w3c.unicorn.util.MessageList; import org.w3c.unicorn.util.Property; import org.w3c.unicorn.util.UCNProperties; import org.w3c.unicorn.response.Response; @@ -118,6 +120,7 @@ initLanguages(); initTasklists(); initVelocity(); + initDefaultMessages(); isUcnInitialized = true; logger.info("Unicorn initialized successfully."); } catch (InitializationFailedException e) { @@ -560,6 +563,59 @@ logger.info("OK - Velocity successfully initialized"); } + private static void initDefaultMessages() { + logger.debug("-------------------------------------------------------"); + logger.debug("Loading messages from messages.properties"); + + Properties props = new Properties(); + try { + props.load(Framework.class.getResourceAsStream("/messages.properties")); + } catch (IOException e) { + logger.error("Unable to read messages.properties.", e); + return; + } + ArrayList<String> messageIds = new ArrayList<String>(); + for (Object key : props.keySet()) { + String prop = key.toString(); + if (prop.endsWith(".level")) { + String id = prop.replace(".level", ""); + messageIds.add(id); + logger.debug("> Found message id: " + id); + } + } + for (String id : messageIds) { + Message message = new Message(); + String level = (String) props.get(id + ".level"); + if (level.equals("warning")) + message.setLevel(Message.WARNING); + else if (level.equals("error")) + message.setLevel(Message.ERROR); + else if (level.equals("info")) + message.setLevel(Message.INFO); + else { + logger.warn("Level for message id " + id + " is invalid: " + level + ". Must be one of warning, error, or info."); + continue; + } + logger.debug(">> level of " + id + " is: " + level); + String mess = (String) props.get(id + ".message"); + if (props.get(id + ".message") != null) + message.setMessage(mess); + else { + logger.warn("Message for message id " + id + " is not set. Add a " + id + ".message property in messages.properties."); + continue; + } + logger.debug(">> message of " + id + " is:\n\t" + mess); + String content = (String) props.get(id + ".content"); + if (content != null) { + message.setContent(content); + logger.debug(">> content of " + id + " is:\n\t" + content); + } + MessageList.getDefaultMessages().add(message); + } + logger.debug("> " + MessageList.getDefaultMessages().size() + " default messages loaded"); + logger.info("OK - Default messages succesfully loaded"); + } + private static void loadConfigFile(InputStream stream, String fileName, String[]... parameters) throws IOException { UCNProperties properties = new UCNProperties(); logger.debug("Loading config file: " + fileName);
Received on Friday, 18 June 2010 19:52:52 UTC