src/share/classes/java/net/URLConnection.java

Print this page




1224      *             <code>checkSetFactory</code> method doesn't allow the operation.
1225      * @see        java.net.ContentHandlerFactory
1226      * @see        java.net.URLConnection#getContent()
1227      * @see        SecurityManager#checkSetFactory
1228      */
1229     public static synchronized void setContentHandlerFactory(ContentHandlerFactory fac) {
1230         if (factory != null) {
1231             throw new Error("factory already defined");
1232         }
1233         SecurityManager security = System.getSecurityManager();
1234         if (security != null) {
1235             security.checkSetFactory();
1236         }
1237         factory = fac;
1238     }
1239 
1240     private static Hashtable<String, ContentHandler> handlers = new Hashtable<>();
1241 
1242     /**
1243      * Gets the Content Handler appropriate for this connection.
1244      * @param connection the connection to use.
1245      */
1246     synchronized ContentHandler getContentHandler()
1247     throws UnknownServiceException
1248     {
1249         String contentType = stripOffParameters(getContentType());
1250         ContentHandler handler = null;
1251         if (contentType == null)
1252             throw new UnknownServiceException("no content-type");
1253         try {
1254             handler = handlers.get(contentType);
1255             if (handler != null)
1256                 return handler;
1257         } catch(Exception e) {
1258         }
1259 
1260         if (factory != null)
1261             handler = factory.createContentHandler(contentType);
1262         if (handler == null) {
1263             try {
1264                 handler = lookupContentHandlerClassFor(contentType);




1224      *             <code>checkSetFactory</code> method doesn't allow the operation.
1225      * @see        java.net.ContentHandlerFactory
1226      * @see        java.net.URLConnection#getContent()
1227      * @see        SecurityManager#checkSetFactory
1228      */
1229     public static synchronized void setContentHandlerFactory(ContentHandlerFactory fac) {
1230         if (factory != null) {
1231             throw new Error("factory already defined");
1232         }
1233         SecurityManager security = System.getSecurityManager();
1234         if (security != null) {
1235             security.checkSetFactory();
1236         }
1237         factory = fac;
1238     }
1239 
1240     private static Hashtable<String, ContentHandler> handlers = new Hashtable<>();
1241 
1242     /**
1243      * Gets the Content Handler appropriate for this connection.

1244      */
1245     synchronized ContentHandler getContentHandler()
1246         throws UnknownServiceException
1247     {
1248         String contentType = stripOffParameters(getContentType());
1249         ContentHandler handler = null;
1250         if (contentType == null)
1251             throw new UnknownServiceException("no content-type");
1252         try {
1253             handler = handlers.get(contentType);
1254             if (handler != null)
1255                 return handler;
1256         } catch(Exception e) {
1257         }
1258 
1259         if (factory != null)
1260             handler = factory.createContentHandler(contentType);
1261         if (handler == null) {
1262             try {
1263                 handler = lookupContentHandlerClassFor(contentType);