public synchronized ContentHandler findAuthorizedContentHandler(String contentType) { Object factory = findAuthorizedFactory(ignoredClasses); if (factory == null) return null; if (factory == this) return createInternalContentHandler(contentType); try { Method createInternalContentHandlerMethod = factory.getClass().getMethod("createInternalContentHandler", new Class[] {String.class}); //$NON-NLS-1$ return (ContentHandler) createInternalContentHandlerMethod.invoke(factory, new Object[] {contentType}); } catch (Exception e) { container.getLogServices().log(ContentHandlerFactoryImpl.class.getName(), FrameworkLogEntry.ERROR, "findAuthorizedContentHandler-loop", e); //$NON-NLS-1$ throw new RuntimeException(e.getMessage(), e); } }
public Object getContent(URLConnection uConn) throws IOException { ContentHandler handler = factory.findAuthorizedContentHandler(contentType); if (handler != null) return handler.getContent(uConn); return uConn.getInputStream(); }
if (isMultiplexing()) return new MultiplexingContentHandler(contentType, this); return createInternalContentHandler(contentType);
private void installContentHandlerFactory(BundleContext context) { ContentHandlerFactoryImpl chf = new ContentHandlerFactoryImpl(context, container); try { // first try the standard way URLConnection.setContentHandlerFactory(chf); } catch (Error err) { // ok we failed now use more drastic means to set the factory try { forceContentHandlerFactory(chf); } catch (Exception ex) { // this is unexpected, log the exception and throw the original error container.getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, ex.getMessage(), ex); throw err; } } contentHandlerFactory = chf; }
private static void forceContentHandlerFactory(ContentHandlerFactoryImpl chf) throws Exception { Field factoryField = getField(URLConnection.class, java.net.ContentHandlerFactory.class, false); if (factoryField == null) throw new Exception("Could not find ContentHandlerFactory field"); //$NON-NLS-1$ synchronized (URLConnection.class) { java.net.ContentHandlerFactory factory = (java.net.ContentHandlerFactory) factoryField.get(null); // doing a null check here just in case, but it would be really strange if it was null, // because we failed to set the factory normally!! if (factory != null) { try { factory.getClass().getMethod("isMultiplexing", (Class[]) null); //$NON-NLS-1$ Method register = factory.getClass().getMethod("register", new Class[] {Object.class}); //$NON-NLS-1$ register.invoke(factory, new Object[] {chf}); } catch (NoSuchMethodException e) { // current factory does not support multiplexing, ok we'll wrap it chf.setParentFactory(factory); factory = chf; } } // null out the field so that we can successfully call setContentHandlerFactory factoryField.set(null, null); // always attempt to clear the handlers cache // This allows an optomization for the single framework use-case resetContentHandlers(); URLConnection.setContentHandlerFactory(factory); } }
private void uninstallContentHandlerFactory() { try { Field factoryField = getField(URLConnection.class, java.net.ContentHandlerFactory.class, false); if (factoryField == null) return; // oh well, we tried. synchronized (URLConnection.class) { java.net.ContentHandlerFactory factory = (java.net.ContentHandlerFactory) factoryField.get(null); if (factory == contentHandlerFactory) { factory = (java.net.ContentHandlerFactory) contentHandlerFactory.designateSuccessor(); } else { Method unregister = factory.getClass().getMethod("unregister", new Class[] {Object.class}); //$NON-NLS-1$ unregister.invoke(factory, new Object[] {contentHandlerFactory}); } // null out the field so that we can successfully call setContentHandlerFactory factoryField.set(null, null); // always attempt to clear the handlers cache // This allows an optomization for the single framework use-case // Note that the call to setContentHandlerFactory below may clear this cache // but we want to be sure to clear it here just incase the parent is null. // In this case the call below would not occur. // Also it appears most java libraries actually do not clear the cache // when setContentHandlerFactory is called, go figure!! resetContentHandlers(); if (factory != null) URLConnection.setContentHandlerFactory(factory); } } catch (Exception e) { // ignore and continue closing the framework } }
if (isMultiplexing()) return new MultiplexingContentHandler(contentType, this); return createInternalContentHandler(contentType);
private void installContentHandlerFactory(BundleContext context) { ContentHandlerFactoryImpl chf = new ContentHandlerFactoryImpl(context, container); try { // first try the standard way URLConnection.setContentHandlerFactory(chf); } catch (Error err) { // ok we failed now use more drastic means to set the factory try { forceContentHandlerFactory(chf); } catch (Exception ex) { // this is unexpected, log the exception and throw the original error container.getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, ex.getMessage(), ex); throw err; } } contentHandlerFactory = chf; }
private static void forceContentHandlerFactory(ContentHandlerFactoryImpl chf) throws Exception { Field factoryField = getField(URLConnection.class, java.net.ContentHandlerFactory.class, false); if (factoryField == null) throw new Exception("Could not find ContentHandlerFactory field"); //$NON-NLS-1$ synchronized (URLConnection.class) { java.net.ContentHandlerFactory factory = (java.net.ContentHandlerFactory) factoryField.get(null); // doing a null check here just in case, but it would be really strange if it was null, // because we failed to set the factory normally!! if (factory != null) { try { factory.getClass().getMethod("isMultiplexing", (Class[]) null); //$NON-NLS-1$ Method register = factory.getClass().getMethod("register", new Class[] {Object.class}); //$NON-NLS-1$ register.invoke(factory, new Object[] {chf}); } catch (NoSuchMethodException e) { // current factory does not support multiplexing, ok we'll wrap it chf.setParentFactory(factory); factory = chf; } } // null out the field so that we can successfully call setContentHandlerFactory factoryField.set(null, null); // always attempt to clear the handlers cache // This allows an optomization for the single framework use-case resetContentHandlers(); URLConnection.setContentHandlerFactory(factory); } }
private void uninstallContentHandlerFactory() { try { Field factoryField = getField(URLConnection.class, java.net.ContentHandlerFactory.class, false); if (factoryField == null) return; // oh well, we tried. synchronized (URLConnection.class) { java.net.ContentHandlerFactory factory = (java.net.ContentHandlerFactory) factoryField.get(null); if (factory == contentHandlerFactory) { factory = (java.net.ContentHandlerFactory) contentHandlerFactory.designateSuccessor(); } else { Method unregister = factory.getClass().getMethod("unregister", new Class[] {Object.class}); //$NON-NLS-1$ unregister.invoke(factory, new Object[] {contentHandlerFactory}); } // null out the field so that we can successfully call setContentHandlerFactory factoryField.set(null, null); // always attempt to clear the handlers cache // This allows an optomization for the single framework use-case // Note that the call to setContentHandlerFactory below may clear this cache // but we want to be sure to clear it here just incase the parent is null. // In this case the call below would not occur. // Also it appears most java libraries actually do not clear the cache // when setContentHandlerFactory is called, go figure!! resetContentHandlers(); if (factory != null) URLConnection.setContentHandlerFactory(factory); } } catch (Exception e) { // ignore and continue closing the framework } }
public synchronized ContentHandler findAuthorizedContentHandler(String contentType) { Object factory = findAuthorizedFactory(ignoredClasses); if (factory == null) return null; if (factory == this) return createInternalContentHandler(contentType); try { Method createInternalContentHandlerMethod = factory.getClass().getMethod("createInternalContentHandler", new Class[] {String.class}); //$NON-NLS-1$ return (ContentHandler) createInternalContentHandlerMethod.invoke(factory, new Object[] {contentType}); } catch (Exception e) { container.getLogServices().log(ContentHandlerFactoryImpl.class.getName(), FrameworkLogEntry.ERROR, "findAuthorizedContentHandler-loop", e); //$NON-NLS-1$ throw new RuntimeException(e.getMessage(), e); } }
if (isMultiplexing()) return new MultiplexingContentHandler(contentType, this); return createInternalContentHandler(contentType);
public Object getContent(URLConnection uConn) throws IOException { ContentHandler handler = factory.findAuthorizedContentHandler(contentType); if (handler != null) return handler.getContent(uConn); return uConn.getInputStream(); }
private void installContentHandlerFactory(BundleContext context) { ContentHandlerFactoryImpl chf = new ContentHandlerFactoryImpl(context, container); try { // first try the standard way URLConnection.setContentHandlerFactory(chf); } catch (Error err) { // ok we failed now use more drastic means to set the factory try { forceContentHandlerFactory(chf); } catch (Exception ex) { // this is unexpected, log the exception and throw the original error container.getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, ex.getMessage(), ex); throw err; } } contentHandlerFactory = chf; }
private static void forceContentHandlerFactory(ContentHandlerFactoryImpl chf) throws Exception { Field factoryField = getField(URLConnection.class, java.net.ContentHandlerFactory.class, false); if (factoryField == null) throw new Exception("Could not find ContentHandlerFactory field"); //$NON-NLS-1$ synchronized (URLConnection.class) { java.net.ContentHandlerFactory factory = (java.net.ContentHandlerFactory) factoryField.get(null); // doing a null check here just in case, but it would be really strange if it was null, // because we failed to set the factory normally!! if (factory != null) { try { factory.getClass().getMethod("isMultiplexing", (Class[]) null); //$NON-NLS-1$ Method register = factory.getClass().getMethod("register", new Class[] {Object.class}); //$NON-NLS-1$ register.invoke(factory, new Object[] {chf}); } catch (NoSuchMethodException e) { // current factory does not support multiplexing, ok we'll wrap it chf.setParentFactory(factory); factory = chf; } } // null out the field so that we can successfully call setContentHandlerFactory factoryField.set(null, null); // always attempt to clear the handlers cache // This allows an optomization for the single framework use-case resetContentHandlers(); URLConnection.setContentHandlerFactory(factory); } }
private void uninstallContentHandlerFactory() { try { Field factoryField = getField(URLConnection.class, java.net.ContentHandlerFactory.class, false); if (factoryField == null) return; // oh well, we tried. synchronized (URLConnection.class) { java.net.ContentHandlerFactory factory = (java.net.ContentHandlerFactory) factoryField.get(null); if (factory == contentHandlerFactory) { factory = (java.net.ContentHandlerFactory) contentHandlerFactory.designateSuccessor(); } else { Method unregister = factory.getClass().getMethod("unregister", new Class[] {Object.class}); //$NON-NLS-1$ unregister.invoke(factory, new Object[] {contentHandlerFactory}); } // null out the field so that we can successfully call setContentHandlerFactory factoryField.set(null, null); // always attempt to clear the handlers cache // This allows an optomization for the single framework use-case // Note that the call to setContentHandlerFactory below may clear this cache // but we want to be sure to clear it here just incase the parent is null. // In this case the call below would not occur. // Also it appears most java libraries actually do not clear the cache // when setContentHandlerFactory is called, go figure!! resetContentHandlers(); if (factory != null) URLConnection.setContentHandlerFactory(factory); } } catch (Exception e) { // ignore and continue closing the framework } }
public synchronized ContentHandler findAuthorizedContentHandler(String contentType) { Object factory = findAuthorizedFactory(ignoredClasses); if (factory == null) return null; if (factory == this) return createInternalContentHandler(contentType); try { Method createInternalContentHandlerMethod = factory.getClass().getMethod("createInternalContentHandler", new Class[] {String.class}); //$NON-NLS-1$ return (ContentHandler) createInternalContentHandlerMethod.invoke(factory, new Object[] {contentType}); } catch (Exception e) { container.getLogServices().log(ContentHandlerFactoryImpl.class.getName(), FrameworkLogEntry.ERROR, "findAuthorizedContentHandler-loop", e); //$NON-NLS-1$ throw new RuntimeException(e.getMessage(), e); } }
if (isMultiplexing()) return new MultiplexingContentHandler(contentType, this); return createInternalContentHandler(contentType);
public Object getContent(URLConnection uConn) throws IOException { ContentHandler handler = factory.findAuthorizedContentHandler(contentType); if (handler != null) return handler.getContent(uConn); return uConn.getInputStream(); }
private void installContentHandlerFactory(BundleContext context) { ContentHandlerFactoryImpl chf = new ContentHandlerFactoryImpl(context, container); try { // first try the standard way URLConnection.setContentHandlerFactory(chf); } catch (Error err) { // ok we failed now use more drastic means to set the factory try { forceContentHandlerFactory(chf); } catch (Exception ex) { // this is unexpected, log the exception and throw the original error container.getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, ex.getMessage(), ex); throw err; } } contentHandlerFactory = chf; }