List of usage examples for java.util Hashtable put
public synchronized V put(K key, V value)
From source file:org.jasig.cas.adaptors.ldap.util.AuthenticatedLdapContextSource.java
public DirContext getDirContext(final String principal, final String credentials) { final Hashtable<String, String> environment = (Hashtable) getAnonymousEnv().clone(); environment.put(Context.SECURITY_PRINCIPAL, principal); environment.put(Context.SECURITY_CREDENTIALS, credentials); environment.remove("com.sun.jndi.ldap.connect.pool"); // remove this since we're modifying principal try {//from w w w. j ava 2 s . c om return getDirContextInstance(environment); } catch (final NamingException e) { throw new DataAccessResourceFailureException("Unable to create DirContext"); } }
From source file:Main.java
/** * Parse a deliminated string with keys and values like Content-Type parameters * and cache-control headers. Keys can be present on their own e.g. * no-cache in which case the no-cache key will be in the hashtable with a * blank string value. It can also have an = sign with quoted or unquoted * text e.g. maxage=600 or maxage="600"//from ww w . ja v a 2 s . c o m * * @param str String to parse * @param deliminator deliminator character * @return Hashtable of parameters and values found */ public static Hashtable parseParams(String str, char deliminator) { String paramName = null; Hashtable params = new Hashtable(); boolean inQuotes = false; int strLen = str.length(); StringBuffer sb = new StringBuffer(); char c; char lastChar = 0; for (int i = 0; i < strLen; i++) { c = str.charAt(i); if (c == '"') { if (!inQuotes) { inQuotes = true; } else if (inQuotes && lastChar != '\\') { inQuotes = false; } } if ((isWhiteSpace(c) && !inQuotes) || (c == '"' && i < strLen - 1)) { //do nothing more } else if ((c == deliminator || i == strLen - 1)) { //check if we are here because it's the end... then we add this to bufer if (i == strLen - 1 && c != '"') { sb.append(c); } if (paramName != null) { //this is a parameter with a value params.put(paramName, sb.toString()); } else { //this is a parameter on its own params.put(sb.toString(), ""); } sb = new StringBuffer(); paramName = null; } else if (c == '=') { paramName = sb.toString(); sb = new StringBuffer(); } else { sb.append(c); } lastChar = c; } return params; }
From source file:de.msg.terminfindung.common.jmx.TestJmxUeberwachung.java
@Test public void testJmxUeberwachung() throws Exception { // SpringContext initialisieren und Komponente holen //Meldung meldung = (Meldung) SpringContextHolder.getBean("meldung"); // Holen des MBeanServers ArrayList<MBeanServer> mBeanServerList = MBeanServerFactory.findMBeanServer(null); MBeanServer mBeanServer = mBeanServerList.get(0); // Lesen der gewnschten Information per JMX // de.bund.bva.isyfact.terminfindung:type=ServiceStatistik,name="Erstellung-Statistik" Hashtable<String, String> table = new Hashtable<>(); table.put("type", "ServiceStatistik"); table.put("name", "\"Erstellung-Statistik\""); ObjectName testObjectName = new ObjectName("de.bund.bva.isyfact.terminfindung", table); String testAttributeName = "DurchschnittsDauerLetzteAufrufe"; String result = mBeanServer.getAttribute(testObjectName, testAttributeName).toString(); // Auswerten des Ergebnisses assertEquals("0", result); // Einen Anwendungsfall ausfhren contr.initialisiereModel(new ErstellenModel()); result = mBeanServer.getAttribute(testObjectName, testAttributeName).toString(); assertNotEquals("0", result); }
From source file:com.justcloud.osgifier.SpringContextHolder.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public void registerContext(String name, OsgiBundleXmlApplicationContext context) { contexts.put(name, context);//from www. ja v a2 s . c o m context.refresh(); BundleContext bc = FrameworkUtil.getBundle(SpringContextHolder.class).getBundleContext(); Hashtable properties = new Hashtable(); properties.put("name", name); regs.add(bc.registerService(OsgiBundleXmlApplicationContext.class.getName(), context, properties)); }
From source file:gdt.jgui.entity.folder.JFolderPanel.java
public static JFileOpenItem[] sort(JFileOpenItem[] foia) { ArrayList<String> sl = new ArrayList<String>(); String title$;/*from w ww.j av a 2s . c om*/ Hashtable<String, JFileOpenItem> map = new Hashtable<String, JFileOpenItem>(); if (foia == null) return null; for (JFileOpenItem foi : foia) { title$ = foi.getTitle(); if (title$ == null) continue; sl.add(title$); map.put(title$, foi); } Collections.sort(sl); String[] sa = sl.toArray(new String[0]); ArrayList<Object> foil = new ArrayList<Object>(); for (String aSa : sa) { foil.add(map.get(aSa)); } return foil.toArray(new JFileOpenItem[0]); }
From source file:MainClass.java
public void paint(Graphics g) { Dimension size = getSize();/*from w w w.ja va2 s . com*/ String s = "To java2s.com or not to java2s.com, that is a question"; Hashtable map = new Hashtable(); map.put(TextAttribute.SIZE, new Float(32.0f)); AttributedString as = new AttributedString(s, map); map = new Hashtable(); map.put(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE); as.addAttributes(map, 33, 52); AttributedCharacterIterator aci = as.getIterator(); int startIndex = aci.getBeginIndex(); int endIndex = aci.getEndIndex(); LineBreakMeasurer measurer; measurer = new LineBreakMeasurer(aci, new FontRenderContext(null, false, false)); measurer.setPosition(startIndex); float wrappingWidth = (float) size.width; float Y = 0.0f; while (measurer.getPosition() < endIndex) { TextLayout layout = measurer.nextLayout(wrappingWidth); Y += layout.getAscent(); float X = 0.0f; switch (justify) { case LEFT: if (layout.isLeftToRight()) X = 0.0f; else X = wrappingWidth - layout.getAdvance(); break; case RIGHT: if (layout.isLeftToRight()) X = wrappingWidth - layout.getVisibleAdvance(); else X = wrappingWidth; break; case CENTER: if (layout.isLeftToRight()) X = (wrappingWidth - layout.getVisibleAdvance()) / 2; else X = (wrappingWidth + layout.getAdvance()) / 2 - layout.getAdvance(); break; case EQUALITY: layout = layout.getJustifiedLayout(wrappingWidth); } layout.draw((Graphics2D) g, X, Y); Y += layout.getDescent() + layout.getLeading(); } }
From source file:cyrille.jndi.LdapTest.java
@Test public void test() throws Exception { Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://localhost:389"); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system"); env.put(Context.SECURITY_CREDENTIALS, "secret"); DirContext dirContext = new InitialDirContext(env); Attributes attributes = dirContext.getAttributes("uid=aeinstein,ou=Users,dc=example,dc=com"); for (NamingEnumeration<Attribute> attributesEnumeration = (NamingEnumeration<Attribute>) attributes .getAll(); attributesEnumeration.hasMore();) { Attribute attribute = attributesEnumeration.next(); System.out.print(attribute.getID() + "="); for (NamingEnumeration<?> attributeValues = attribute.getAll(); attributeValues.hasMore();) { Object value = attributeValues.next(); if (value instanceof byte[] && "userpassword".equals(attribute.getID())) { byte[] bytes = (byte[]) value; System.out.print(new String(bytes) + ", "); } else { System.out.print(value + ", "); }/*from w w w.j av a 2 s. co m*/ } System.out.println(); } }
From source file:com.whizzosoftware.hobson.openweathermap.OpenWeatherMapPluginTest.java
@Test public void testOnPluginConfigurationUpdate() { MockVariableManager vm = new MockVariableManager(); OpenWeatherMapPlugin plugin = new OpenWeatherMapPlugin("id"); plugin.setVariableManager(vm);/* w w w . j a v a 2 s.co m*/ assertEquals(PluginStatus.Status.INITIALIZING, plugin.getStatus().getStatus()); plugin.onStartup(new Hashtable()); assertEquals(PluginStatus.Status.NOT_CONFIGURED, plugin.getStatus().getStatus()); Hashtable config = new Hashtable(); config.put(OpenWeatherMapPlugin.PROP_CITY_STATE, "Denver, CO"); plugin.onPluginConfigurationUpdate(config); assertEquals(PluginStatus.Status.RUNNING, plugin.getStatus().getStatus()); Collection<HobsonVariable> vars = vm.getGlobalVariables(UserUtil.DEFAULT_USER, UserUtil.DEFAULT_HUB); assertEquals(2, vars.size()); }
From source file:com.whizzosoftware.hobson.openweathermap.OpenWeatherMapPluginTest.java
@Test public void testInitWithConfiguration() { MockVariableManager vm = new MockVariableManager(); OpenWeatherMapPlugin plugin = new OpenWeatherMapPlugin("id"); plugin.setVariableManager(vm);// ww w. ja v a 2s .co m assertEquals(PluginStatus.Status.INITIALIZING, plugin.getStatus().getStatus()); Hashtable config = new Hashtable(); config.put(OpenWeatherMapPlugin.PROP_CITY_STATE, "Denver, CO"); plugin.onStartup(config); assertEquals(PluginStatus.Status.RUNNING, plugin.getStatus().getStatus()); Collection<HobsonVariable> vars = vm.getGlobalVariables(UserUtil.DEFAULT_USER, UserUtil.DEFAULT_HUB); assertEquals(2, vars.size()); Iterator<HobsonVariable> it = vars.iterator(); HobsonVariable v0 = it.next(); HobsonVariable v1 = it.next(); assertEquals(null, v0.getValue()); assertTrue(v0.getName().equals(VariableConstants.TEMP_F) || v0.getName().equals(VariableConstants.TEMP_C)); assertEquals(null, v1.getValue()); assertTrue(v1.getName().equals(VariableConstants.TEMP_F) || v1.getName().equals(VariableConstants.TEMP_C)); }
From source file:WeblogicDbServlet.java
public void init() throws ServletException { Context env = null;// w ww . ja v a 2 s.com Hashtable ht = new Hashtable(); ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); //ht.put(Context.PROVIDER_URL,"t3://localhost:7001"); try { env = new InitialContext(ht); pool = (javax.sql.DataSource) env.lookup("oracle-8i-athletes"); if (pool == null) throw new ServletException("'oracle-8i-athletes' is an unknown DataSource"); } catch (NamingException ne) { throw new ServletException(ne); } }