java.net.ContentHandler Java Examples
The following examples show how to use
java.net.ContentHandler.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MultimediaContentHandlers.java From Bytecoder with Apache License 2.0 | 6 votes |
@Override public ContentHandler createContentHandler(String mimetype) { switch (mimetype) { case "audio/aiff": return new aiff(); case "audio/basic": return new basic(); case "audio/wav": return new wav(); case "audio/x-aiff": return new x_aiff(); case "audio/x-wav": return new x_wav(); case "image/gif": return new gif(); case "image/jpeg": return new jpeg(); case "image/png": return new png(); case "image/x-xbitmap": return new x_xbitmap(); case "image/x-xpixmap": return new x_xpixmap(); default: return null; } }
Example #2
Source File: MultimediaContentHandlers.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Override public ContentHandler createContentHandler(String mimetype) { switch (mimetype) { case "audio/aiff": return new aiff(); case "audio/basic": return new basic(); case "audio/wav": return new wav(); case "audio/x-aiff": return new x_aiff(); case "audio/x-wav": return new x_wav(); case "image/gif": return new gif(); case "image/jpeg": return new jpeg(); case "image/png": return new png(); case "image/x-xbitmap": return new x_xbitmap(); case "image/x-xpixmap": return new x_xpixmap(); default: return null; } }
Example #3
Source File: ContentHandlerWrapper.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void updateBest() { try { @SuppressWarnings("unchecked") final ServiceReference<ContentHandler>[] refs = (ServiceReference<ContentHandler>[]) framework.systemBundle.bundleContext .getServiceReferences(ContentHandler.class.getName(), filter); if (refs != null) { best = refs[0]; for (int i = 1; i < refs.length; i++) { if (compare(best, refs[i]) > 0) { best = refs[i]; } } } } catch (final Exception e) { // TODO, handle differently!? this should not happen. throw new IllegalArgumentException("Could not register url handler: " + e); } }
Example #4
Source File: ContentHandlerWrapper.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
private ContentHandler getService() { ContentHandler obj; try { if (best == null) { updateBest(); } if (best == null) { throw new IllegalStateException("null: Lost service for protocol="+ mimetype); } obj = framework.systemBundle.bundleContext.getService(best); if (obj == null) { throw new IllegalStateException("null: Lost service for protocol=" + mimetype); } } catch (final Exception e) { throw new IllegalStateException("null: Lost service for protocol=" + mimetype); } return obj; }
Example #5
Source File: ContentHandlerWrapper.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public String toString() { final StringBuffer sb = new StringBuffer(); sb.append("ContentHandlerWrapper["); final ServiceReference<ContentHandler> ref = best; sb.append("mimetype=" + mimetype); if(ref != null) { sb.append(", id=" + ref.getProperty(Constants.SERVICE_ID)); sb.append(", rank=" + ref.getProperty(Constants.SERVICE_RANKING)); } else { sb.append(" no service tracked"); } sb.append("]"); return sb.toString(); }
Example #6
Source File: ServiceContentHandlerFactory.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
ContentHandler getServiceHandler(String mimetype) { try { final String filter = "(" + URLConstants.URL_CONTENT_MIMETYPE + "=" + mimetype + ")"; //TODO true or false? @SuppressWarnings("unchecked") final ServiceReference<ContentHandler>[] srl = (ServiceReference<ContentHandler>[]) framework.services.get(ContentHandler.class.getName(), filter, framework.systemBundle, false); if (srl != null && srl.length > 0) { ContentHandlerWrapper wrapper = wrapMap.get(mimetype); if (wrapper == null) { wrapper = new ContentHandlerWrapper(framework, mimetype); wrapMap.put(mimetype, wrapper); } return wrapper; } } catch (final InvalidSyntaxException e) { throw new RuntimeException("Failed to get service: " + e); } return null; }
Example #7
Source File: MediaServer.java From android-vlc-remote with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") protected final <T> T read(ContentHandler handler) throws IOException { String spec = mUri.toString(); URL url = new URL(spec); HttpURLConnection http = (HttpURLConnection) url.openConnection(); http.setConnectTimeout(TIMEOUT); try { String usernamePassword = mUri.getUserInfo(); if (usernamePassword != null) { Header authorization = BasicScheme.authenticate( new UsernamePasswordCredentials(usernamePassword), HTTP.UTF_8, false); http.setRequestProperty(authorization.getName(), authorization.getValue()); } return (T) handler.getContent(http); } finally { http.disconnect(); } }
Example #8
Source File: ServiceContentHandlerFactory.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
public ContentHandler createContentHandler(String mimetype) { if(framework.debug.url) { framework.debug.println("createContentHandler protocol=" + mimetype); } ContentHandler handler = getJVMClassPathHandler(mimetype); if(handler != null) { if(framework.debug.url) { framework.debug.println("using JVMClassPath handler for " + mimetype); } return handler; } handler = getServiceHandler(mimetype); if(handler != null) { if(framework.debug.url) { framework.debug.println("Using service ContentHandler for " + mimetype + ", handler=" + handler); } return handler; } if(framework.debug.url) { framework.debug.println("Using default ContentHandler for " + mimetype); } // delegate to system handler return null; }
Example #9
Source File: ServiceContentHandlerFactory.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
ContentHandler getJVMClassPathHandler(String mimetype) { if (jvmPkgs != null) { for (final String jvmPkg : jvmPkgs) { final String converted = convertMimetype(mimetype); final String className = jvmPkg + "." + converted + ".Handler"; try { if(framework.debug.url) { framework.debug.println("JVMClassPathCH - trying ContentHandler class=" + className); } final Class<?> clazz = Class.forName(className); final ContentHandler handler = (ContentHandler)clazz.newInstance(); if(framework.debug.url) { framework.debug.println("JVMClassPathCH - created ContentHandler class=" + className); } return handler; } catch (final Throwable t) { if(framework.debug.url) { framework.debug.println("JVMClassPathCH - no ContentHandler class " + className); } } } } if(framework.debug.url) { framework.debug.println("JVMClassPath - no ContentHandler for " + mimetype); } return null; }
Example #10
Source File: XmlContentHandler.java From android-vlc-remote with GNU General Public License v3.0 | 5 votes |
protected final void parse(URLConnection connection, org.xml.sax.ContentHandler handler) throws IOException { InputStream input = connection.getInputStream(); try { // The server sends UTF-8 instead of the HTTP default (ISO-8859-1). Xml.Encoding encoding = Xml.Encoding.UTF_8; Xml.parse(input, encoding, handler); } catch (Exception e) { throw new IOException(ERROR_INVALID_XML, e); } finally { input.close(); } }
Example #11
Source File: MediaServer.java From android-vlc-remote with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") protected final <T> Remote<T> load(ContentHandler handler) { String spec = mUri.toString(); try { T data = (T) read(handler); return Remote.data(data); } catch (Throwable t) { Log.e(TAG, "Unable to load: " + spec, t); return Remote.error(t); } }
Example #12
Source File: ContentHandlerWrapper.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
ContentHandlerWrapper(FrameworkContext framework, String mimetype) { this.framework = framework; this.mimetype = mimetype; filter = "(&" + "(" + Constants.OBJECTCLASS + "=" + ContentHandler.class.getName() + ")" + "(" + URLConstants.URL_CONTENT_MIMETYPE + "=" + mimetype + ")" + ")"; final ServiceListener serviceListener = new ServiceListener() { public void serviceChanged(ServiceEvent evt) { @SuppressWarnings("unchecked") final ServiceReference<ContentHandler> ref = (ServiceReference<ContentHandler>) evt.getServiceReference(); switch (evt.getType()) { case ServiceEvent.MODIFIED: // fall through case ServiceEvent.REGISTERED: if (best == null) { updateBest(); return ; } if (compare(best, ref) > 0) { best = ref; } break; case ServiceEvent.MODIFIED_ENDMATCH: // fall through case ServiceEvent.UNREGISTERING: if (best.equals(ref)) { best = null; } } } }; try { framework.systemBundle.bundleContext.addServiceListener(serviceListener, filter); } catch (final Exception e) { throw new IllegalArgumentException("Could not register service listener for content handler: " + e); } if (framework.debug.url) { framework.debug.println("created wrapper for " + mimetype + ", filter=" + filter); } }
Example #13
Source File: URLHandler.java From sana.mobile with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public ContentHandler createContentHandler(String mimetype) { return null; }