List of usage examples for java.util Hashtable Hashtable
public Hashtable()
From source file:com.adobe.acs.commons.http.headers.impl.MonthlyExpiresHeaderFilterTest.java
@Before public void setup() throws Exception { properties = new Hashtable<String, Object>(); properties.put(MonthlyExpiresHeaderFilter.PROP_EXPIRES_TIME, "02:30"); when(componentContext.getProperties()).thenReturn(properties); when(componentContext.getBundleContext()).thenReturn(bundleContext); }
From source file:com.basistech.yca.UnflattenTest.java
@Test public void array2() throws Exception { Hashtable<String, Object> ht = new Hashtable<>(); ht.put("a[0][0]", "dog"); JsonNode roundTrip = JsonNodeFlattener.unflatten(ht); JsonNode ref = new ObjectMapper(new YAMLFactory()).readTree("a: [ [ dog ] ]"); assertEquals(ref, roundTrip);/*w w w .j a v a2 s .co m*/ }
From source file:com.jones_systems.Tieout.java
/** * Creates a new Tieout object/*from ww w . j a v a2 s . c o m*/ * * @param tieoutFile the file containing the XML for the tests * */ public Tieout(File tieoutFile) { connections = new Hashtable<String, TieoutConnection>(); varsets = new Hashtable<String, TieoutVariableSet>(); tests = new Vector<TieoutTest>(); Document doc = null; SAXBuilder sb = new SAXBuilder(); try { doc = sb.build(tieoutFile); } catch (JDOMException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Element root = doc.getRootElement(); Element connections1 = root.getChild("connections"); @SuppressWarnings("unchecked") List<Element> connections2 = connections1.getChildren(); // Load all of the connections // each Element e will be a <connection> thing for (Element e : connections2) { connections.put(e.getAttributeValue("id"), TieoutConnection.create(e)); } Element readvarsets = root.getChild("variables"); @SuppressWarnings("unchecked") List<Element> readvarsets2 = readvarsets.getChildren(); for (Element e : readvarsets2) { String varsetkey = e.getAttributeValue("id"); @SuppressWarnings("unchecked") List<Element> variables = e.getChildren(); TieoutVariableSet tvs = new TieoutVariableSet(); for (Element var : variables) { tvs.add(var.getAttributeValue("name"), var.getAttributeValue("value")); } varsets.put(varsetkey, tvs); } Element readTests = root.getChild("tests"); @SuppressWarnings("unchecked") List<Element> readTests2 = readTests.getChildren(); // load in the tests for (Element e : readTests2) { TieoutTest newtest = new TieoutTest(e.getAttributeValue("id")); String[] varsetsToAdd = e.getChildText("varsets").split(","); // may need to split based on comma // cycle through the varsets and add to the new test as needed for (String s : varsetsToAdd) { if (varsets.containsKey(s)) { newtest.addVarset(s, varsets.get(s)); } else { // warning -- that variable set does not exist } } @SuppressWarnings("unchecked") List<Element> queries = e.getChildren("query"); // read in the queries and add them to the test // also give them their respective connection to use for executing for (Element query : queries) { TieoutConnection connection = connections.get(query.getAttributeValue("connection")); newtest.addQuery(connection, query.getValue()); } tests.add(newtest); } }
From source file:com.buschmais.maexo.test.MaexoTests.java
/** * Registers a notification listener which listens to events. * * @return The listener./*from w ww . java 2 s . c o m*/ * @throws MalformedObjectNameException * If notification listeners object name is incorrect. */ protected ServiceRegistration registerNotificationListener(NotificationListener listener, ObjectName objectName) throws MalformedObjectNameException { Dictionary<String, Object> properties = new Hashtable<String, Object>(); properties.put(ObjectName.class.getName(), objectName); ServiceRegistration notificationListenerServiceRegistration = this.bundleContext .registerService(NotificationListener.class.getName(), listener, properties); return notificationListenerServiceRegistration; }
From source file:br.com.upic.camel.ldap.LdapEndpoint.java
@Override protected void onExchange(final Exchange exchange) throws Exception { LOG.info("Setting up the context"); final Hashtable<String, String> conf = new Hashtable<String, String>(); LOG.debug("Initial Context Factory = " + initialContextFactory); conf.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory); LOG.debug("Provider URL = " + providerUrl); conf.put(Context.PROVIDER_URL, providerUrl); LOG.debug("Security Authentication = " + securityAuthentication); conf.put(Context.SECURITY_AUTHENTICATION, securityAuthentication); final Message in = exchange.getIn(); final String user = in.getHeader(HEADER_USER, String.class); LOG.debug("User = " + user); conf.put(Context.SECURITY_PRINCIPAL, user); final String password = in.getHeader(HEADER_PASSWORD, String.class); LOG.debug("Password = " + password); conf.put(Context.SECURITY_CREDENTIALS, password); LOG.info("Authenticating in directory"); final Message out = exchange.getOut(); try {/*from w w w .j av a 2 s.c om*/ new InitialContext(conf); out.setBody(true); } catch (final AuthenticationException e) { LOG.error(e.getMessage(), e); out.setBody(false); } }
From source file:com.constellio.model.services.users.sync.FastBindConnectionControl.java
@SuppressWarnings("unchecked") public LDAPFastBind(String ldapurl, Boolean followReferences, boolean activeDirectory) { env = new Hashtable(); //This can make LDAP search slow : http://stackoverflow.com/questions/16412236/how-to-resolve-javax-naming-partialresultexception //env.put(Context.REFERRAL, "follow"); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.PROVIDER_URL, ldapurl); env.put("java.naming.ldap.attributes.binary", "tokenGroups objectSid"); if (followReferences) { env.put(Context.REFERRAL, "follow"); }/*from www . java 2 s . c om*/ if (StringUtils.startsWith(ldapurl, "ldaps")) { //env.put(Context.SECURITY_PROTOCOL, "ssl"); env.put("java.naming.ldap.factory.socket", "com.constellio.model.services.users.sync.ldaps.DummySSLSocketFactory"); } if (activeDirectory) { connCtls = new Control[] { new FastBindConnectionControl() }; } else { connCtls = new Control[] {}; } //first time we initialize the context, no credentials are supplied //therefore it is an anonymous bind. /*try { ctx = new InitialLdapContext(env, connCtls); } catch (NamingException e) { throw new RuntimeNamingException(e.getMessage()); }*/ //FIX de Vincent pour o a q try { ctx = new InitialLdapContext(env, connCtls); } catch (NamingException e) { if (activeDirectory) { connCtls = new Control[] {}; try { ctx = new InitialLdapContext(env, connCtls); } catch (NamingException e2) { throw new RuntimeException(e); } } else { throw new RuntimeException(e); } } }
From source file:com.adito.agent.client.ProxyUtil.java
/** * Attempt to proxy settings from Firefox. * /* www .jav a2 s . c o m*/ * @return firefox proxy settings * @throws IOException if firefox settings could not be obtained for some * reason */ public static BrowserProxySettings lookupFirefoxProxySettings() throws IOException { try { Vector proxies = new Vector(); Vector bypassAddr = new Vector(); File home = new File(Utils.getHomeDirectory()); File firefoxAppData; if (System.getProperty("os.name") != null && System.getProperty("os.name").startsWith("Windows")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ firefoxAppData = new File(home, "Application Data\\Mozilla\\Firefox\\profiles.ini"); //$NON-NLS-1$ } else { firefoxAppData = new File(home, ".mozilla/firefox/profiles.ini"); //$NON-NLS-1$ } // Look for Path elements in the profiles.ini BufferedReader reader = null; Hashtable profiles = new Hashtable(); String line; try { reader = new BufferedReader(new InputStreamReader(new FileInputStream(firefoxAppData))); String currentProfileName = ""; //$NON-NLS-1$ while ((line = reader.readLine()) != null) { line = line.trim(); if (line.startsWith("[") && line.endsWith("]")) { //$NON-NLS-1$ //$NON-NLS-2$ currentProfileName = line.substring(1, line.length() - 1); continue; } if (line.startsWith("Path=")) { //$NON-NLS-1$ profiles.put(currentProfileName, new File(firefoxAppData.getParent(), line.substring(5))); } } } finally { if (reader != null) { reader.close(); } } // Iterate through all the profiles and load the proxy infos from // the prefs.js file File prefsJS; String profileName; for (Enumeration e = profiles.keys(); e.hasMoreElements();) { profileName = (String) e.nextElement(); prefsJS = new File((File) profiles.get(profileName), "prefs.js"); //$NON-NLS-1$ Properties props = new Properties(); reader = null; try { if (!prefsJS.exists()) { // needed to defend against un-initialised profiles. // #ifdef DEBUG log.info("The file " + prefsJS.getAbsolutePath() + " does not exist."); //$NON-NLS-1$ // #endif // now remove it from the map. profiles.remove(profileName); continue; } reader = new BufferedReader(new InputStreamReader(new FileInputStream(prefsJS))); while ((line = reader.readLine()) != null) { line = line.trim(); if (line.startsWith("user_pref(\"")) { //$NON-NLS-1$ int idx = line.indexOf("\"", 11); //$NON-NLS-1$ if (idx == -1) continue; String pref = line.substring(11, idx); // Save this position int pos = idx + 1; // Look for another quote idx = line.indexOf("\"", idx + 1); //$NON-NLS-1$ String value; if (idx == -1) { // No more quotes idx = line.indexOf(" ", pos); //$NON-NLS-1$ if (idx == -1) continue; int idx2 = line.indexOf(")", pos); //$NON-NLS-1$ if (idx2 == -1) continue; value = line.substring(idx + 1, idx2); } else { // String value int idx2 = line.indexOf("\"", idx + 1); //$NON-NLS-1$ if (idx2 == -1) continue; value = line.substring(idx + 1, idx2); } props.put(pref, value); } } } finally { if (reader != null) { reader.close(); } } ProxyInfo p; /** * Extract some proxies from the properites, if the proxy is * enabled */ if ("1".equals(props.get("network.proxy.type"))) { //$NON-NLS-1$ //$NON-NLS-2$ boolean isProfileActive = checkProfileActive(prefsJS); if (props.containsKey("network.proxy.ftp")) { //$NON-NLS-1$ p = createProxyInfo( "ftp=" + props.get("network.proxy.ftp") + ":" + props.get("network.proxy.ftp_port"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ "Firefox Profile [" + profileName + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ p.setActiveProfile(isProfileActive); proxies.addElement(p); } if (props.containsKey("network.proxy.http")) { //$NON-NLS-1$ p = createProxyInfo( "http=" + props.get("network.proxy.http") + ":" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + props.get("network.proxy.http_port"), //$NON-NLS-1$ "Firefox Profile [" + profileName + "]"); //$NON-NLS-1$ //$NON-NLS-2$ p.setActiveProfile(isProfileActive); proxies.addElement(p); } if (props.containsKey("network.proxy.ssl")) { //$NON-NLS-1$ p = createProxyInfo( "ssl=" + props.get("network.proxy.ssl") + ":" + props.get("network.proxy.ssl_port"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ "Firefox Profile [" + profileName + "]"); //$NON-NLS-1$ //$NON-NLS-2$ p.setActiveProfile(isProfileActive); proxies.addElement(p); } if (props.containsKey("network.proxy.socks")) { //$NON-NLS-1$ p = createProxyInfo("socks=" + props.get("network.proxy.socks") + ":" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + props.get("network.proxy.socks_port"), "Firefox Profile [" + profileName + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ p.setActiveProfile(isProfileActive); proxies.addElement(p); } if (props.containsKey("network.proxy.no_proxies_on")) { //$NON-NLS-1$ StringTokenizer tokens = new StringTokenizer( props.getProperty("network.proxy.no_proxies_on"), ","); //$NON-NLS-1$ //$NON-NLS-2$ while (tokens.hasMoreTokens()) { bypassAddr.addElement(((String) tokens.nextToken()).trim()); } } } } // need to ensure that the returned values are sorted correctly... BrowserProxySettings bps = new BrowserProxySettings(); bps.setBrowser("Mozilla Firefox"); //$NON-NLS-1$ bps.setProxiesActiveFirst(proxies); bps.setBypassAddr(new String[bypassAddr.size()]); bypassAddr.copyInto(bps.getBypassAddr()); return bps; } catch (Throwable t) { throw new IOException("Failed to get proxy information from Firefox profiles: " + t.getMessage()); //$NON-NLS-1$ } }
From source file:com.mmone.gpdati.allotment.record.AllotmentRecordsListBuilder.java
private void buildRecordList() throws Exception { List<String> lines = linePrv.getLines(); records = new ArrayList<AllotmentRecord>(); recordsMap = new Hashtable<String, List<AllotmentRecord>>(); for (String line : lines) { AllotmentRecord r = new AllotmentRecord(); String h = line.substring(0, 5).trim(); String rc = line.substring(13, 18).trim(); String dt = line.substring(5, 13).trim(); Integer al = 0;/*from w w w . ja v a2s .c om*/ try { al = new Integer(line.substring(18, 23).trim()); if (al < 0) al = 0; } catch (Exception e) { } if (roomMap != null) { GpDatiRoomRecord room = roomMap.get(h, rc); int sid = 0; int roomId = 0; if (room != null) { sid = new Integer(room.getAbsstru()); roomId = new Integer(room.getAbsroom()); } else { room = roomMap.insert(h, rc); } if (sid != 0 && roomId != 0) { int allotment = al * room.getPerc() / 100; allotment = (int) Math.round(allotment * 10000) / 10000; r.setHotel(h).setRcode(rc).setDate(dt).setAllotment(allotment).setHotelId(sid) .setRoomId(roomId); ; records.add(r); } } else { r.setHotel(h).setRcode(rc).setDate(dt).setAllotment(al); records.add(r); } String smallKey = r.getSmallGroupKey(); List<AllotmentRecord> lr; if (recordsMap.containsKey(smallKey)) { lr = recordsMap.get(smallKey); } else { lr = new ArrayList<AllotmentRecord>(); recordsMap.put(smallKey, lr); } lr.add(r); } }
From source file:com.nokia.helium.metadata.DerbyFactoryManagerCreator.java
public synchronized EntityManagerFactory create(File database) throws MetadataException { EntityManagerFactory factory;/*from w w w . j av a2 s. c o m*/ String name = "metadata"; Hashtable<String, String> persistProperties = new Hashtable<String, String>(); persistProperties.put("javax.persistence.jdbc.driver", "org.apache.derby.jdbc.EmbeddedDriver"); // This swallow all the output log from derby. System.setProperty("derby.stream.error.field", "com.nokia.helium.metadata.DerbyFactoryManagerCreator.DEV_NULL"); persistProperties.put("javax.persistence.jdbc.url", "jdbc:derby:" + database.getAbsolutePath()); persistProperties.put(PersistenceUnitProperties.PERSISTENCE_CONTEXT_CLOSE_ON_COMMIT, "false"); persistProperties.put(PersistenceUnitProperties.PERSISTENCE_CONTEXT_REFERENCE_MODE, "WEAK"); persistProperties.put(PersistenceUnitProperties.BATCH_WRITING, "JDBC"); persistProperties.put("eclipselink.read-only", "true"); persistProperties.put(PersistenceUnitProperties.LOGGING_LEVEL, "warning"); if (database.exists()) { if (!checkDatabaseIntegrity(database)) { try { FileUtils.forceDelete(database); } catch (java.io.IOException iex) { throw new MetadataException("Failed deleting corrupted db: " + iex, iex); } } else { return Persistence.createEntityManagerFactory(name, persistProperties); } } persistProperties.put("javax.persistence.jdbc.url", "jdbc:derby:" + database + ";create=true"); persistProperties.put(PersistenceUnitProperties.DDL_GENERATION, "create-tables"); persistProperties.put(PersistenceUnitProperties.DDL_GENERATION_MODE, "database"); persistProperties.put(PersistenceUnitProperties.PERSISTENCE_CONTEXT_CLOSE_ON_COMMIT, "false"); persistProperties.put(PersistenceUnitProperties.PERSISTENCE_CONTEXT_REFERENCE_MODE, "WEAK"); persistProperties.put(PersistenceUnitProperties.BATCH_WRITING, "JDBC"); persistProperties.put("eclipselink.read-only", "true"); factory = Persistence.createEntityManagerFactory(name, persistProperties); EntityManager entityManager = factory.createEntityManager(); // Pushing default data into the current schema try { entityManager.getTransaction().begin(); // Version of the schema is pushed. entityManager.persist(new Version()); // Default set of severity is pushed. for (SeverityEnum.Severity severity : SeverityEnum.Severity.values()) { Severity pData = new Severity(); pData.setSeverity(severity.toString()); entityManager.persist(pData); } entityManager.getTransaction().commit(); } finally { if (entityManager.getTransaction().isActive()) { entityManager.getTransaction().rollback(); entityManager.clear(); } entityManager.close(); } return factory; }
From source file:edu.xtec.colex.utils.ParseMultipart.java
/** * Creates a new instance of ParseMultipart with a given HttpServletRequest * @param requestIn the HttpServletRequest to parse *//*from w w w. j a v a 2s . c o m*/ public ParseMultipart(HttpServletRequest requestIn) { parameters = new Hashtable(); request = requestIn; isMultipart = ServletFileUpload.isMultipartContent(new ServletRequestContext(request)); try { if (isMultipart) { DiskFileItemFactory factory = new DiskFileItemFactory(); // Configure the factory here, if desired. ServletFileUpload upload = new ServletFileUpload(factory); upload.setHeaderEncoding("ISO-8859-1"); // Configure the uploader here, if desired. Iterator fileItems = upload.parseRequest(request).iterator(); while (fileItems.hasNext()) { FileItem fi = (FileItem) fileItems.next(); if (!fi.isFormField()) { parameters.put(fi.getFieldName(), fi); } else { parameters.put(fi.getFieldName(), fi.getString("ISO-8859-1").trim()); } } } } catch (Exception e) { System.out.println(e); } }