1 57 58 59 package com.sun.org.apache.xml.internal.serialize; 60 61 62 import java.io.OutputStream ; 63 import java.io.Writer ; 64 import java.io.UnsupportedEncodingException ; 65 import java.util.Hashtable ; 66 import java.util.StringTokenizer ; 67 68 75 public abstract class SerializerFactory 76 { 77 78 79 public static final String FactoriesProperty = "com.sun.org.apache.xml.internal.serialize.factories"; 80 81 82 private static Hashtable _factories = new Hashtable (); 83 84 85 static 86 { 87 SerializerFactory factory; 88 String list; 89 StringTokenizer token; 90 String className; 91 92 factory = new SerializerFactoryImpl( Method.XML ); 96 registerSerializerFactory( factory ); 97 factory = new SerializerFactoryImpl( Method.HTML ); 98 registerSerializerFactory( factory ); 99 factory = new SerializerFactoryImpl( Method.XHTML ); 100 registerSerializerFactory( factory ); 101 factory = new SerializerFactoryImpl( Method.TEXT ); 102 registerSerializerFactory( factory ); 103 104 list = System.getProperty( FactoriesProperty ); 105 if ( list != null ) { 106 token = new StringTokenizer ( list, " ;,:" ); 107 while ( token.hasMoreTokens() ) { 108 className = token.nextToken(); 109 try { 110 factory = (SerializerFactory) ObjectFactory.newInstance( className, 111 SerializerFactory.class.getClassLoader(), true); 112 if ( _factories.containsKey( factory.getSupportedMethod() ) ) 113 _factories.put( factory.getSupportedMethod(), factory ); 114 } catch ( Exception except ) { } 115 } 116 } 117 } 118 119 120 124 public static void registerSerializerFactory( SerializerFactory factory ) 125 { 126 String method; 127 128 synchronized ( _factories ) { 129 method = factory.getSupportedMethod(); 130 _factories.put( method, factory ); 131 } 132 } 133 134 135 139 public static SerializerFactory getSerializerFactory( String method ) 140 { 141 return (SerializerFactory) _factories.get( method ); 142 } 143 144 145 152 protected abstract String getSupportedMethod(); 153 154 155 161 public abstract Serializer makeSerializer(OutputFormat format); 162 163 164 169 public abstract Serializer makeSerializer( Writer writer, 170 OutputFormat format ); 171 172 173 181 public abstract Serializer makeSerializer( OutputStream output, 182 OutputFormat format ) 183 throws UnsupportedEncodingException ; 184 185 186 } 187 188 189 | Popular Tags |