List of usage examples for java.util Dictionary put
public abstract V put(K key, V value);
From source file:org.wso2.carbon.ui.internal.CarbonUIServiceComponent.java
public void start(BundleContext context) throws Exception { this.bundleContext = context; ServerConfigurationService serverConfig = getServerConfiguration(); boolean isLocalTransportMode = checkForLocalTransportMode(serverConfig); //TODO set a system property ConfigurationContext clientConfigContext = getConfigurationContextService().getClientConfigContext(); //This is applicable only when the FE and BE runs in the same JVM. ConfigurationContext serverConfigContext = getConfigurationContextService().getServerConfigContext(); CarbonUIDefinitions carbonUIDefinitions = new CarbonUIDefinitions(); context.registerService(CarbonUIDefinitions.class.getName(), carbonUIDefinitions, null); // create a CustomUIDefinitions object and set it as a osgi service. UIBundleDeployer can access this // service and populate it with custom UI definitions of the deployed UI bundle, if available. CustomUIDefenitions customUIDefenitions = new CustomUIDefenitions(); context.registerService(CustomUIDefenitions.class.getName(), customUIDefenitions, null); Hashtable<String, String[]> properties1 = new Hashtable<String, String[]>(); properties1.put(URLConstants.URL_HANDLER_PROTOCOL, new String[] { "carbon" }); context.registerService(URLStreamHandlerService.class.getName(), new CarbonProtocol(context), properties1); Hashtable<String, String[]> properties3 = new Hashtable<String, String[]>(); properties3.put(URLConstants.URL_CONTENT_MIMETYPE, new String[] { "text/javascript" }); context.registerService(ContentHandler.class.getName(), new TextJavascriptHandler(), properties3); final HttpService httpService = getHttpService(); Dictionary<String, String> initparams = new Hashtable<String, String>(); initparams.put("servlet-name", "TilesServlet"); initparams.put("definitions-config", "/WEB-INF/tiles/main_defs.xml"); initparams.put("org.apache.tiles.context.TilesContextFactory", "org.apache.tiles.context.enhanced.EnhancedContextFactory"); initparams.put("org.apache.tiles.factory.TilesContainerFactory.MUTABLE", "true"); initparams.put("org.apache.tiles.definition.DefinitionsFactory", "org.wso2.carbon.tiles.CarbonUrlDefinitionsFactory"); String webContext = "carbon"; // The subcontext for the Carbon Mgt Console String serverURL = CarbonUIUtil.getServerURL(serverConfig); String indexPageURL = CarbonUIUtil.getIndexPageURL(serverConfig); if (indexPageURL == null) { indexPageURL = "/carbon/admin/index.jsp"; }//www . ja v a 2 s .c om RegistryService registryService = getRegistryService(); Registry registry = registryService.getLocalRepository(); UIBundleDeployer uiBundleDeployer = new UIBundleDeployer(); UIResourceRegistry uiResourceRegistry = new UIResourceRegistry(); uiResourceRegistry.initialize(bundleContext); uiResourceRegistry.setDefaultUIResourceProvider(uiBundleDeployer.getBundleBasedUIResourcePrvider()); // BundleResourcePathRegistry resourcePathRegistry = uiBundleDeployer.getBundleResourcePathRegistry(); HttpContext commonContext = new CarbonSecuredHttpContext(context.getBundle(), "/web", uiResourceRegistry, registry); //Registering filedownload servlet Servlet fileDownloadServlet = new ContextPathServletAdaptor( new FileDownloadServlet(context, getConfigurationContextService()), "/filedownload"); httpService.registerServlet("/filedownload", fileDownloadServlet, null, commonContext); fileDownloadServlet.getServletConfig().getServletContext().setAttribute(CarbonConstants.SERVER_URL, serverURL); fileDownloadServlet.getServletConfig().getServletContext().setAttribute(CarbonConstants.INDEX_PAGE_URL, indexPageURL); //Registering fileupload servlet Servlet fileUploadServlet; if (isLocalTransportMode) { fileUploadServlet = new ContextPathServletAdaptor( new FileUploadServlet(context, serverConfigContext, webContext), "/fileupload"); } else { fileUploadServlet = new ContextPathServletAdaptor( new FileUploadServlet(context, clientConfigContext, webContext), "/fileupload"); } httpService.registerServlet("/fileupload", fileUploadServlet, null, commonContext); fileUploadServlet.getServletConfig().getServletContext().setAttribute(CarbonConstants.SERVER_URL, serverURL); fileUploadServlet.getServletConfig().getServletContext().setAttribute(CarbonConstants.INDEX_PAGE_URL, indexPageURL); uiBundleDeployer.deploy(bundleContext, commonContext); context.addBundleListener(uiBundleDeployer); httpService.registerServlet("/", new org.apache.tiles.web.startup.TilesServlet(), initparams, commonContext); httpService.registerResources("/" + webContext, "/", commonContext); adaptedJspServlet = new ContextPathServletAdaptor( new TilesJspServlet(context.getBundle(), uiResourceRegistry), "/" + webContext); httpService.registerServlet("/" + webContext + "/*.jsp", adaptedJspServlet, null, commonContext); ServletContext jspServletContext = adaptedJspServlet.getServletConfig().getServletContext(); jspServletContext.setAttribute("registry", registryService); jspServletContext.setAttribute(CarbonConstants.SERVER_CONFIGURATION, serverConfig); jspServletContext.setAttribute(CarbonConstants.CLIENT_CONFIGURATION_CONTEXT, clientConfigContext); //If the UI is running on local transport mode, then we use the server-side config context. if (isLocalTransportMode) { jspServletContext.setAttribute(CarbonConstants.CONFIGURATION_CONTEXT, serverConfigContext); } else { jspServletContext.setAttribute(CarbonConstants.CONFIGURATION_CONTEXT, clientConfigContext); } jspServletContext.setAttribute(CarbonConstants.BUNDLE_CLASS_LOADER, this.getClass().getClassLoader()); jspServletContext.setAttribute(CarbonConstants.SERVER_URL, serverURL); jspServletContext.setAttribute(CarbonConstants.INDEX_PAGE_URL, indexPageURL); jspServletContext.setAttribute(CarbonConstants.UI_BUNDLE_CONTEXT, bundleContext); // set the CustomUIDefinitions object as an attribute of servlet context, so that the Registry UI bundle // can access the custom UI details within JSPs. jspServletContext.setAttribute(CustomUIDefenitions.CUSTOM_UI_DEFENITIONS, customUIDefenitions); // Registering jspServletContext as a service so that UI components can use it bundleContext.registerService(ServletContext.class.getName(), jspServletContext, null); //saving bundle context for future reference within CarbonUI Generation CarbonUIUtil.setBundleContext(context); UIAnnouncementDeployer.deployNotificationSources(); if (log.isDebugEnabled()) { log.debug("Starting web console using context : " + webContext); } //read product.xml readProductXML(jspServletContext, uiBundleDeployer); }
From source file:org.paxle.parser.impl.SubParserManager.java
@SuppressWarnings("unchecked") public void addSubParser(final ServiceReference ref) { final String[] mimeTypes = getMimeTypes(ref); if (mimeTypes == null) return;//from ww w .ja v a2 s. c om for (String mimeType : mimeTypes) { mimeType = mimeType.trim(); TreeSet<ServiceReference> refs = this.subParserList.get(mimeType); if (refs == null) this.subParserList.put(mimeType, refs = new TreeSet<ServiceReference>()); refs.add(ref); final String parserPid = keyFor(mimeType, ref); this.services.put(parserPid, ref); if (!this.knownServicePids.contains(parserPid)) { this.knownServicePids.add(parserPid); setEnabled(mimeType, ref, this.enableDefault); } this.logger.info(String.format("Parser for mimetypes '%s' was installed.", mimeType)); } try { final Dictionary props = config.getProperties(); props.put(ENABLED_MIMETYPES, this.enabledServices.toArray(new String[this.enabledServices.size()])); config.update(props); } catch (IOException e) { logger.error("error updating configuration", e); } }
From source file:org.codice.ddf.registry.api.impl.RegistryStoreImpl.java
private boolean updateConfiguration(String metacardTitle) { if (metacardTitle == null || StringUtils.isBlank(registryId)) { LOGGER.debug("Unable to update registry configurations. No metacard title or registry id."); return false; }// ww w .j av a2 s . com String currentPid = getConfigurationPid(); try { Configuration currentConfig = configAdmin.getConfiguration(currentPid); Dictionary<String, Object> currentProperties = currentConfig.getProperties(); String nameToSet = getFullRegistryName(metacardTitle); LOGGER.info("Changed RegistryStore.id from {} to {}", getId(), nameToSet); setId(nameToSet); currentProperties.put(ID, nameToSet); currentProperties.put(RegistryConstants.CONFIGURATION_REGISTRY_ID_PROPERTY, registryId); currentConfig.update(currentProperties); } catch (IOException e) { LOGGER.debug("Unable to update registry configurations, ", e); return false; } return true; }
From source file:org.paxle.parser.impl.SubParserManager.java
@SuppressWarnings("unchecked") public void enableParser(final String service) { if (service == null) return;//from www . j ava2 s.c o m try { final String mimeType = this.extractMimeType(service); setEnabled(mimeType, this.services.get(service), true); // updating CM Dictionary<String, Object> props = this.config.getProperties(); props.put(ENABLED_MIMETYPES, enabledServices.toArray(new String[enabledServices.size()])); this.config.update(props); } catch (IOException e) { this.logger.error(e); } }
From source file:org.paxle.parser.impl.SubParserManager.java
@SuppressWarnings("unchecked") public void disableParser(final String service) { if (service == null) return;//from w w w.j av a2 s . c o m try { final String mimeType = this.extractMimeType(service); setEnabled(mimeType, this.services.get(service), false); // updating CM Dictionary<String, Object> props = this.config.getProperties(); props.put(ENABLED_MIMETYPES, enabledServices.toArray(new String[enabledServices.size()])); this.config.update(props); } catch (IOException e) { this.logger.error(e); } }
From source file:org.paxle.parser.impl.SubParserManager.java
/** * @see ISubParserManager#disableMimeType(String) *//*from ww w. j a v a 2s.com*/ @SuppressWarnings("unchecked") public void disableMimeType(String mimeType) { try { if (mimeType == null) return; mimeType = mimeType.toLowerCase(); // update enabled mimetype list final TreeSet<ServiceReference> refs = this.subParserList.get(mimeType.trim()); if (refs != null) for (final ServiceReference ref : refs) setEnabled(mimeType, ref, false); // updating CM Dictionary<String, Object> props = this.config.getProperties(); props.put(ENABLED_MIMETYPES, enabledServices.toArray(new String[enabledServices.size()])); this.config.update(props); } catch (IOException e) { this.logger.error(e); } }
From source file:org.paxle.parser.impl.SubParserManager.java
/** * @see ISubParserManager#enableMimeType(String) *///from w ww .ja v a 2 s . c o m @SuppressWarnings("unchecked") public void enableMimeType(String mimeType) { try { if (mimeType == null) return; mimeType = mimeType.toLowerCase(); // updating enabled mimetype list final TreeSet<ServiceReference> refs = this.subParserList.get(mimeType.trim()); if (refs != null) for (final ServiceReference ref : refs) setEnabled(mimeType, ref, true); // updating CM Dictionary<String, Object> props = this.config.getProperties(); props.put(ENABLED_MIMETYPES, enabledServices.toArray(new String[enabledServices.size()])); this.config.update(props); } catch (IOException e) { this.logger.error(e); } }
From source file:org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase.java
/** * Method of IContainerAware called when a new container is available * * @param containerName Container being created *///from w w w.j a v a 2 s . co m @Override public void containerCreate(String containerName) { try { Object[] imps = getImplementations(); logger.trace("Creating instance {}", containerName); if (imps != null) { for (int i = 0; i < imps.length; i++) { ImmutablePair<String, Object> key = new ImmutablePair<String, Object>(containerName, imps[i]); Component c = this.dbInstances.get(key); if (c == null) { c = this.dm.createComponent(); c.addStateListener(new ListenerComponentStates()); // Now let the derived class to configure the // dependencies it wants configureInstance(c, imps[i], containerName); // Set the implementation so the component can manage // its lifecycle if (c.getService() == null) { logger.trace("Setting implementation to: {}", imps[i]); c.setImplementation(imps[i]); } //Set the service properties to include the containerName //in the service, that is fundamental for supporting //multiple services just distinguished via a container @SuppressWarnings("unchecked") Dictionary<String, String> serviceProps = c.getServiceProperties(); if (serviceProps != null) { logger.trace("Adding new property for container"); serviceProps.put("containerName", containerName); } else { logger.trace("Create a new properties for the service"); serviceProps = new Hashtable<String, String>(); serviceProps.put("containerName", containerName); } c.setServiceProperties(serviceProps); // Now add the component to the dependency Manager // which will immediately start tracking the dependencies this.dm.add(c); //Now lets keep track in our shadow database of the //association this.dbInstances.put(key, c); } else { logger.error("I have been asked again to create an instance " + "on: " + containerName + "for object: " + imps[i] + "when i already have it!!"); } } } } catch (Exception ex) { logger.error("During containerDestroy invocation caught exception: " + ex + "\nStacktrace:" + stackToString(ex.getStackTrace())); } }
From source file:org.opennaas.extensions.quantum.capability.apiv2.QuantumAPIV2Capability.java
@Override /**//w w w . ja v a2 s . c o m * Register the capability like a web service through DOSGi * * @param name * @param resourceId * @return * @throws CapabilityException */ protected ServiceRegistration registerService(BundleContext bundleContext, String capabilityName, String resourceType, String resourceName, String ifaceName, Dictionary<String, String> props) throws CapabilityException { try { ConfigurationAdminUtil configurationAdmin = new ConfigurationAdminUtil(bundleContext); String url = configurationAdmin.getProperty("org.opennaas", "ws.rest.url"); if (props != null) { // Rest props.put("service.exported.interfaces", "*"); props.put("service.exported.configs", "org.apache.cxf.rs"); props.put("service.exported.intents", "HTTP"); // props.put("org.apache.cxf.rs.httpservice.context", url + "/" + resourceType + "/" + resourceName + "/" + capabilityName); props.put("org.apache.cxf.rs.httpservice.context", "/networkService/v1.1"); props.put("org.apache.cxf.rs.address", "/"); props.put("org.apache.cxf.httpservice.requirefilter", "false"); // JSON provider props.put("org.apache.cxf.rs.provider", "org.opennaas.extensions.quantum.utils.CustomJSONProvider"); } log.info("Registering ws: \n " + "in url: " + props.get("org.apache.cxf.rs.address") + "\n" + "in context: " + props.get("org.apache.cxf.rs.httpservice.context")); registration = bundleContext.registerService(ifaceName, this, props); } catch (IOException e) { throw new CapabilityException(e); } return registration; }
From source file:org.opencastproject.inspection.ffmpeg.MediaInspector.java
/** * Enriches the track's metadata and can be executed in an asynchronous way. * * @param originalTrack//from w w w. j a va 2 s. c om * the original track * @param override * <code>true</code> to override existing metadata * @return the media package element * @throws MediaInspectionException */ private MediaPackageElement enrichTrack(final Track originalTrack, final boolean override) throws MediaInspectionException { try { URI originalTrackUrl = originalTrack.getURI(); MediaPackageElementFlavor flavor = originalTrack.getFlavor(); logger.debug("enrich(" + originalTrackUrl + ") called"); // Get the file from the URL File file = null; try { file = workspace.get(originalTrackUrl); } catch (NotFoundException e) { throw new MediaInspectionException( "File " + file + " was not found and can therefore not be inspected", e); } catch (IOException e) { throw new MediaInspectionException("Error accessing " + file, e); } // Make sure the file has an extension. Otherwise, tools like ffmpeg will not work. // TODO: Try to guess the extension from the container's metadata if ("".equals(FilenameUtils.getExtension(file.getName()))) { throw new MediaInspectionException("Can not inspect files without a filename extension"); } MediaContainerMetadata metadata = getFileMetadata(file); if (metadata == null) { throw new MediaInspectionException("Unable to acquire media metadata for " + originalTrackUrl); } else { TrackImpl track = null; try { track = (TrackImpl) MediaPackageElementBuilderFactory.newInstance().newElementBuilder() .elementFromURI(originalTrackUrl, MediaPackageElement.Type.Track, flavor); } catch (UnsupportedElementException e) { throw new MediaInspectionException("Unable to create track element from " + file, e); } // init the new track with old track.setChecksum(originalTrack.getChecksum()); track.setDuration(originalTrack.getDuration()); track.setElementDescription(originalTrack.getElementDescription()); track.setFlavor(flavor); track.setIdentifier(originalTrack.getIdentifier()); track.setMimeType(originalTrack.getMimeType()); track.setReference(originalTrack.getReference()); track.setSize(file.length()); track.setURI(originalTrackUrl); for (String tag : originalTrack.getTags()) { track.addTag(tag); } // enrich the new track with basic info if (track.getDuration() == null || override) track.setDuration(metadata.getDuration()); if (track.getChecksum() == null || override) { try { track.setChecksum(Checksum.create(ChecksumType.DEFAULT_TYPE, file)); } catch (IOException e) { throw new MediaInspectionException("Unable to read " + file, e); } } // Add the mime type if it's not already present if (track.getMimeType() == null || override) { try { MimeType mimeType = MimeTypes.fromURI(track.getURI()); // The mimetype library doesn't know about audio/video metadata, so the type might be wrong. if ("audio".equals(mimeType.getType()) && metadata.hasVideoStreamMetadata()) { mimeType = MimeTypes.parseMimeType("video/" + mimeType.getSubtype()); } else if ("video".equals(mimeType.getType()) && !metadata.hasVideoStreamMetadata()) { mimeType = MimeTypes.parseMimeType("audio/" + mimeType.getSubtype()); } track.setMimeType(mimeType); } catch (UnknownFileTypeException e) { logger.info("Unable to detect the mimetype for track {} at {}", track.getIdentifier(), track.getURI()); } } // find all streams Dictionary<String, Stream> streamsId2Stream = new Hashtable<String, Stream>(); for (Stream stream : originalTrack.getStreams()) { streamsId2Stream.put(stream.getIdentifier(), stream); } // audio list try { addAudioStreamMetadata(track, metadata); } catch (Exception e) { throw new MediaInspectionException("Unable to extract audio metadata from " + file, e); } // video list try { addVideoStreamMetadata(track, metadata); } catch (Exception e) { throw new MediaInspectionException("Unable to extract video metadata from " + file, e); } logger.info("Successfully inspected track {}", track); return track; } } catch (Exception e) { logger.warn("Error enriching track " + originalTrack, e); if (e instanceof MediaInspectionException) { throw (MediaInspectionException) e; } else { throw new MediaInspectionException(e); } } }