001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.core.notification;
034:
035: import org.libresource.LibresourceEvent;
036:
037: import java.util.Collections;
038: import java.util.Iterator;
039: import java.util.List;
040: import java.util.Properties;
041: import java.util.Set;
042: import java.util.Vector;
043:
044: public class EventFormatterManager {
045: private static EventFormatterManager instance;
046: private EventFormatterIF first;
047:
048: private EventFormatterManager() throws Exception {
049: Properties properties = new Properties();
050: properties
051: .load(Thread
052: .currentThread()
053: .getContextClassLoader()
054: .getResourceAsStream(
055: "org/libresource/core/notification/formatters.properties"));
056:
057: EventFormatterIF tmp = null;
058: Set keySet = properties.keySet();
059: List intSets = new Vector();
060:
061: for (Iterator i = keySet.iterator(); i.hasNext();) {
062: intSets.add(new Integer((String) i.next()));
063: }
064:
065: Collections.sort(intSets);
066: Collections.reverse(intSets);
067:
068: for (Iterator i = intSets.iterator(); i.hasNext();) {
069: String className = properties.getProperty((i.next())
070: .toString());
071: EventFormatterIF eventFormatterIF = (EventFormatterIF) Class
072: .forName(className).newInstance();
073:
074: if (tmp == null) {
075: first = eventFormatterIF;
076: } else {
077: tmp.setParent(eventFormatterIF);
078: }
079:
080: tmp = eventFormatterIF;
081: }
082: }
083:
084: public static EventFormatterManager getInstance() throws Exception {
085: if (instance == null) {
086: instance = new EventFormatterManager();
087: }
088:
089: return instance;
090: }
091:
092: public String formatEventSubject(LibresourceEvent event)
093: throws Exception {
094: return first.formatEventSubject(event);
095: }
096:
097: public String formatEventBody(LibresourceEvent event)
098: throws Exception {
099: return first.formatEventBody(event);
100: }
101: }
|