Initial revision
[mir.git] / source / mir / misc / XslStyleCache.java
1 package mir.misc;
2
3 import java.io.IOException;
4
5 import com.icl.saxon.PreparedStyleSheet;
6 import org.xml.sax.InputSource;
7 import org.xml.sax.SAXException;
8 import com.icl.saxon.trax.Transformer;
9
10 import java.util.Hashtable;
11
12 /**
13  * Title:
14  * Description:
15  * Copyright:    Copyright (c) 2001
16  * Company:
17  * @author
18  * @version 1.0
19  */
20
21
22 public class XslStyleCache {
23
24   private static Hashtable cache;
25   private static XslStyleCache single = new XslStyleCache();
26
27
28   /**
29    * XSLStyleCache constructor comment.
30   */
31   private XslStyleCache() {
32     cache = new Hashtable();
33   }
34
35   /**
36    * singleton constructor
37    */
38   private static synchronized XslStyleCache getInstance() {
39     return single;
40   }
41
42
43   /**
44    * Clear Cache
45    */
46   public static void clear() {
47     cache.clear();
48   }
49
50   /**
51    * This method was created in VisualAge.
52    * @return
53    * @param key java.lang.String
54    */
55   public static PreparedStyleSheet getPreparedStyleSheet( String key )
56     throws SAXException {
57
58     PreparedStyleSheet styleSheet = (PreparedStyleSheet)single.cache.get( key );
59     try {
60       if ( styleSheet == null ) {
61         styleSheet = new PreparedStyleSheet();
62         styleSheet.prepare( InputSourceResolver.resolve( key ) );
63         single.cache.put( key, styleSheet );
64       }
65     } catch ( IOException ex ) {
66       throw new SAXException( "tunneld IOExcpetion:" + ex.getMessage() );
67     }
68
69     return styleSheet;
70   }
71
72   /**
73    * This method was created in VisualAge.
74    * @return
75    * @param key java.lang.String
76    */
77   public static Transformer getTransformer( String key ){
78
79     PreparedStyleSheet styleSheet = (PreparedStyleSheet)single.cache.get( key );
80     try {
81       if ( styleSheet == null ) {
82         styleSheet = new PreparedStyleSheet();
83         styleSheet.prepare( InputSourceResolver.resolve( key ) );
84         single.cache.put( key, styleSheet );
85       }
86     } catch ( IOException ex ) {
87       //throw new SAXException( "tunneld IOExcpetion:" + ex.getMessage() );
88     } catch (SAXException ex) {}
89
90     return styleSheet.newTransformer();
91   }
92
93 }