use of java.util.Dictionary in project sling by apache.
the class WorkspacePickerFilter method activate.
@SuppressWarnings("rawtypes")
protected void activate(ComponentContext ctx) {
Dictionary props = ctx.getProperties();
this.parameterName = OsgiUtil.toString(props.get(PROP_PARAM_NAME), DEFAULT_PARAM_NAME);
this.cookieName = OsgiUtil.toString(props.get(PROP_COOKIE_NAME), DEFAULT_COOKIE_NAME);
}
use of java.util.Dictionary in project stanbol by apache.
the class DataBundleInstaller method register.
/**
* Registers the bundle to the {@link #activated} map.
*
* @param bundle the bundle to register
*/
@SuppressWarnings("unchecked")
private void register(Bundle bundle) {
synchronized (activated) {
if (activated.containsKey(bundle)) {
return;
}
//for now put the bundle with a null key to avoid duplicate adding
activated.put(bundle, null);
}
log.debug("Register Bundle {} with DataBundleInstaller", bundle.getSymbolicName());
Dictionary<String, String> headers = (Dictionary<String, String>) bundle.getHeaders();
// log.info("With Headers:");
// for(Enumeration<String> keys = headers.keys();keys.hasMoreElements();){
// String key = keys.nextElement();
// log.info(" > "+key+"="+headers.get(key));
// }
String pathsString = (String) headers.get(BUNDLE_DATAFILE_HEADER);
if (pathsString != null) {
Dictionary<String, Object> properties = new Hashtable<String, Object>();
String dataFilesRankingString = (String) headers.get(BUNDLE_DATAFILES_PRIORITY_HEADER);
if (dataFilesRankingString != null) {
try {
properties.put(Constants.SERVICE_RANKING, Integer.valueOf(dataFilesRankingString));
} catch (NumberFormatException e) {
log.warn("Unable to parse integer value for '{}' from the configured value '{}'. " + "Will use default ranking", BUNDLE_DATAFILES_PRIORITY_HEADER, dataFilesRankingString);
}
}
//else no service ranking
List<String> paths = Arrays.asList(pathsString.replaceAll("\\s", "").split(","));
BundleDataFileProvider provider = new BundleDataFileProvider(bundle, paths);
properties.put(Constants.SERVICE_DESCRIPTION, String.format("%s for Bundle %s and Paths %s", BundleDataFileProvider.class.getSimpleName(), bundle.getSymbolicName(), provider.getSearchPaths()));
ServiceRegistration registration = context.registerService(DataFileProvider.class.getName(), provider, properties);
log.info("Registerd BundleResourceProvider for {} and relative paths {}", context.getBundle().getSymbolicName(), provider.getSearchPaths());
synchronized (activated) {
//update with the registration
if (activated.containsKey(bundle)) {
activated.put(bundle, registration);
} else {
//the bundle was deactivated in the meantime ... unregister :(
registration.unregister();
}
}
}
//else key not preset ... ignore bundle!
}
use of java.util.Dictionary in project sling by apache.
the class AnonymousAccessConfigServlet method doPost.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
response.setContentType(request.getContentType());
String action = request.getParameter("action");
if ("disable".equals(action)) {
int existingModifiedCounter = modifiedCounter;
Configuration config = configAdmin.getConfiguration(AUTH_PID, null);
Dictionary props = config.getProperties();
if (props == null) {
props = new Hashtable();
}
props.put(PROP_AUTH_ANNONYMOUS, Boolean.FALSE);
config.update(props);
waitForModified(existingModifiedCounter, TIMEOUT);
} else if ("enable".equals(action)) {
int existingModifiedCounter = modifiedCounter;
Configuration config = configAdmin.getConfiguration(AUTH_PID, null);
Dictionary props = config.getProperties();
if (props == null) {
props = new Hashtable();
}
props.put(PROP_AUTH_ANNONYMOUS, Boolean.TRUE);
config.update(props);
waitForModified(existingModifiedCounter, TIMEOUT);
}
response.getWriter().println("ok");
}
use of java.util.Dictionary in project stanbol by apache.
the class BundleInstaller method register.
/**
* Registers the bundle to the {@link #activated} map.
*
* @param bundle the bundle to register
*/
@SuppressWarnings("unchecked")
private void register(Bundle bundle) {
log.debug("register request for Bundle {}", bundle.getSymbolicName());
synchronized (activated) {
if (!isFrameworkActive()) {
log.debug("ignore because Framework is shutting down!");
return;
}
if (activated.containsKey(bundle)) {
log.debug(" .. already registered ");
return;
}
}
log.debug(" ... registering");
Dictionary<String, String> headers = (Dictionary<String, String>) bundle.getHeaders();
// log.info("With Headers:");
// for(Enumeration<String> keys = headers.keys();keys.hasMoreElements();){
// String key = keys.nextElement();
// log.info(" > "+key+"="+headers.get(key));
// }
String path = (String) headers.get(BUNDLE_INSTALLER_HEADER);
activated.put(bundle, path);
if (path != null) {
log.info(" ... process configuration within path {} for bundle {}", path, bundle.getSymbolicName());
Enumeration<URL> resources = (Enumeration<URL>) bundle.findEntries(path, null, true);
if (resources != null) {
ArrayList<InstallableResource> updated = new ArrayList<InstallableResource>();
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
if (url != null) {
log.debug(" > installable RDFTerm {}", url);
InstallableResource resource = createInstallableResource(bundle, path, url);
if (resource != null) {
updated.add(resource);
}
}
}
try {
storeConfig(bundle, updated);
} catch (IOException e) {
throw new IllegalStateException("Unablt to save the IDs of" + "the resources installed for bundle '" + bundle.getSymbolicName() + "'!", e);
}
installer.updateResources(PROVIDER_SCHEME, updated.toArray(new InstallableResource[updated.size()]), new String[] {});
} else {
log.warn(" ... no Entries found in path '{}' configured for Bundle '{}' with Manifest header field '{}'!", new Object[] { path, bundle.getSymbolicName(), BUNDLE_INSTALLER_HEADER });
}
} else {
log.debug(" ... no Configuration to process");
}
}
use of java.util.Dictionary in project sling by apache.
the class MockComponentContextTest method testProvidedProperties.
@Test
public void testProvidedProperties() {
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put("prop1", "value1");
props.put("prop2", 25);
ComponentContext componentContextWithProperties = MockOsgi.newComponentContext(props);
Dictionary contextProps = componentContextWithProperties.getProperties();
assertEquals(2, contextProps.size());
assertEquals("value1", contextProps.get("prop1"));
assertEquals(25, contextProps.get("prop2"));
}
Aggregations