List of usage examples for java.util Hashtable Hashtable
public Hashtable()
From source file:com.sapienter.jbilling.client.order.NewOrderDTOForm.java
public NewOrderDTOForm() { orderLines = new Hashtable(); }
From source file:datasource.BasicDataSourceProvider.java
/** * Perform a registration for a specific PID. The properties specified are converted to settings * on a basic datasource and that one is registered in the service registry for later handling. * Note that no checking is done on validation of properties, they are parsed as is. * /* w w w . ja v a2s . c o m*/ * @param pid The managed service pid * @param properties The properties of the pid */ synchronized void registration(String pid, Dictionary<String, ?> properties) { deleted(pid); Hashtable<String, Object> dict = new Hashtable<>(); Enumeration<String> enumeration = properties.keys(); T source = getDataSource(); source.setMaxWait(10000L); while (enumeration.hasMoreElements()) { String key = enumeration.nextElement(); Object value = properties.get(key); // Check the values. if (key.equals("jdbc.driver")) { source.setDriverClassName(value.toString()); } else if (key.equals("jdbc.user")) { source.setUsername(value.toString()); } else if (key.equals("jdbc.password")) { source.setPassword(value.toString()); } else if (key.equals("jdbc.url")) { source.setUrl(value.toString()); } else if (key.equals("validation.query")) { source.setValidationQuery(value.toString()); } else if (key.equals("validation.timeout")) { source.setValidationQueryTimeout(Integer.parseInt(value.toString())); } else if (key.equals("pool.idle.min")) { source.setMinIdle(Integer.parseInt(value.toString())); } else if (key.equals("pool.idle.max")) { source.setMaxIdle(Integer.parseInt(value.toString())); } else if (key.equals("pool.wait")) { source.setMaxWait(Long.parseLong(value.toString())); } else if (key.equals("pool.active.max")) { source.setMaxActive(Integer.parseInt(value.toString())); } else { dict.put(key, value); } } // Got it. Create the registration for it. ServiceRegistration<DataSource> sr = FrameworkUtil.getBundle(getClass()).getBundleContext() .registerService(DataSource.class, source, dict); registrations.put(pid, new Registration<>(source, sr)); }
From source file:homenet.PortXmlrpc.java
@Override public void send(Packet packet) { _sending = true;/* www . ja va 2s. co m*/ if ((_node == 0) || (_node == packet.getToNode())) { for (PortListener l : _homeNet._portListeners) { l.portSendingStart(_id); } Hashtable<String, String> xmlpacket = new Hashtable<String, String>(); System.out.println(new String(Base64.encodeBase64(packet.getData()))); String packetBase64 = new String(Base64.encodeBase64(packet.getData())); xmlpacket.put("apikey", _client.apikey); xmlpacket.put("timestamp", getDateAsISO8601String(packet.getTimestamp())); xmlpacket.put("packet", packetBase64); //System.out.println("DAte: "+packet.getTimestamp().toString()); Boolean reply = false; try { reply = (Boolean) _client.execute("homenet.packet.submit", xmlpacket); //reply = (String)homeNetXmlrpcClient.execute("HomeNet.ping", "test test3242342"); } catch (Exception e) { //@todo there are probably some specfic exception we need to filter out to kill bad packets System.out.println("XMLRPC Error: " + e); packet.setStatus(STATUS_READY); System.err.println("Possible network error. Will retry in " + retryDelay + " seconds"); Thread timer = new Thread() { public void run() { try { Thread.sleep(retryDelay * 1000); } catch (Exception e) { } _sending = false; } }; timer.start(); for (PortListener l : _homeNet._portListeners) { l.portSendingEnd(_id); } return; } if (reply == true) { System.out.println("Packet Successfuly sent to HomeNet.me"); } else { System.out.println("Fatal Error"); } } else { System.out.println("Packet Skipped"); } // debugPacket(packet); packet.setStatus(STATUS_SENT); _sending = false; for (PortListener l : _homeNet._portListeners) { l.portSendingEnd(_id); } }
From source file:algorithm.F5SteganographyTest.java
@Test public void f5SteganographyAlgorithmTest() { try {/*from w ww . j a va 2 s. c om*/ File carrier = TestDataProvider.JPG_FILE; File payload = TestDataProvider.TXT_FILE; F5Steganography algorithm = new F5Steganography(); // Test encapsulation: List<File> payloadList = new ArrayList<File>(); payloadList.add(payload); File outputFile = algorithm.encapsulate(carrier, payloadList); assertNotNull(outputFile); // Test restore: Hashtable<String, RestoredFile> outputHash = new Hashtable<String, RestoredFile>(); for (RestoredFile file : algorithm.restore(outputFile)) { outputHash.put(file.getName(), file); } assertEquals(outputHash.size(), 2); RestoredFile restoredCarrier = outputHash.get(carrier.getName()); RestoredFile restoredPayload = outputHash.get(payload.getName()); assertNotNull(restoredCarrier); assertNotNull(restoredPayload); // only original payload can be restored, not carrier assertEquals(FileUtils.checksumCRC32(payload), FileUtils.checksumCRC32(restoredPayload)); assertEquals(FileUtils.checksumCRC32(outputFile), FileUtils.checksumCRC32(restoredCarrier)); // check restoration metadata: assertEquals("" + carrier.getAbsolutePath(), restoredCarrier.originalFilePath); assertEquals("" + payload.getAbsolutePath(), restoredPayload.originalFilePath); assertEquals(algorithm, restoredCarrier.algorithm); // This can't be true for steganography algorithms: // assertTrue(restoredCarrier.checksumValid); assertTrue(restoredPayload.checksumValid); assertTrue(restoredCarrier.wasCarrier); assertFalse(restoredCarrier.wasPayload); assertTrue(restoredPayload.wasPayload); assertFalse(restoredPayload.wasCarrier); assertTrue(restoredCarrier.relatedFiles.contains(restoredPayload)); assertFalse(restoredCarrier.relatedFiles.contains(restoredCarrier)); assertTrue(restoredPayload.relatedFiles.contains(restoredCarrier)); assertFalse(restoredPayload.relatedFiles.contains(restoredPayload)); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.phonegap.geolocation.Geolocation.java
/** * Constructor. */ public Geolocation() { this.geoListeners = new Hashtable(); }
From source file:co.runrightfast.core.utils.JmxUtils.java
static ObjectName applicationMBeanObjectName(final String domain, @NonNull final Class<?> mbeanType, final String name) { checkArgument(isNotBlank(domain));/*from ww w .jav a 2 s.co m*/ checkArgument(isNotBlank(name)); try { @SuppressWarnings("UseOfObsoleteCollectionType") final Hashtable<String, String> attributes = new Hashtable<>(); attributes.put("type", mbeanType.getSimpleName()); attributes.put("name", name); return ObjectName.getInstance(domain, attributes); } catch (final MalformedObjectNameException e) { throw new RuntimeException(e); } }
From source file:org.malaguna.cmdit.service.ldap.LDAPBase.java
public Attributes loadUser(String uid, String[] attrs) { // Preparar las variables de entorno para la conexin JNDI Hashtable<String, String> entorno = new Hashtable<String, String>(); // Credenciales del usuario para realizar la bsqueda String cadena = "uid=" + user + "," + context; entorno.put(Context.PROVIDER_URL, server); entorno.put(Context.INITIAL_CONTEXT_FACTORY, initContext); if (password != null && user != null) { entorno.put(Context.SECURITY_PRINCIPAL, cadena); entorno.put(Context.SECURITY_CREDENTIALS, password); }/*www . j a v a2s.c o m*/ Attributes atributos = null; try { // Crear contexto de directorio inicial DirContext ctx = new InitialDirContext(entorno); // Recuperar atributos del usuario que se est buscando if (attrs != null) atributos = ctx.getAttributes("uid=" + uid + "," + context, attrs); else atributos = ctx.getAttributes("uid=" + uid + "," + context); // Cerrar la conexion ctx.close(); } catch (NamingException e) { logger.error(messages.getMessage("err.ldap.attribute", new Object[] { e }, Locale.getDefault())); } return atributos; }
From source file:com.alfaariss.oa.profile.aselect.binding.protocol.cgi.CGIRequest.java
/** * Creates the CGI request object./*from w w w.j a va 2 s. c om*/ * * Reads the request parameters and puts them in a <code>Hashtable</code> * @param oRequest the servlet request * @throws BindingException if the request object can't be created */ public CGIRequest(HttpServletRequest oRequest) throws BindingException { try { _logger = LogFactory.getLog(CGIRequest.class); _htRequest = new Hashtable<String, Object>(); _sRequestedURL = oRequest.getRequestURL().toString(); if (_logger.isDebugEnabled()) { String sQueryString = oRequest.getQueryString(); if (sQueryString == null) sQueryString = ""; _logger.debug("QueryString: " + sQueryString); } Hashtable<String, Vector<String>> htVectorItems = new Hashtable<String, Vector<String>>(); Enumeration enumNames = oRequest.getParameterNames(); while (enumNames.hasMoreElements()) { String sName = (String) enumNames.nextElement(); String sValue = oRequest.getParameter(sName); if (sName.endsWith(CGIBinding.ENCODED_BRACES) || sName.endsWith(CGIBinding.ENCODED_BRACES.toLowerCase()) || sName.endsWith("[]")) { Vector<String> vValues = htVectorItems.get(sName); if (vValues == null) vValues = new Vector<String>(); vValues.add(sValue); htVectorItems.put(sName, vValues); } else _htRequest.put(sName, sValue); } _htRequest.putAll(htVectorItems); } catch (Exception e) { _logger.fatal("Internal error during CGI Request creation", e); throw new BindingException(SystemErrors.ERROR_INTERNAL); } }
From source file:Utils.java
/** * Renders a paragraph of text (line breaks ignored) to an image (created and returned). * * @param font The font to use/*from w ww . jav a 2s . com*/ * @param textColor The color of the text * @param text The message * @param width The width the text should be limited to * @return An image with the text rendered into it */ public static BufferedImage renderTextToImage(Font font, Color textColor, String text, int width) { Hashtable map = new Hashtable(); map.put(TextAttribute.FONT, font); AttributedString attributedString = new AttributedString(text, map); AttributedCharacterIterator paragraph = attributedString.getIterator(); FontRenderContext frc = new FontRenderContext(null, false, false); int paragraphStart = paragraph.getBeginIndex(); int paragraphEnd = paragraph.getEndIndex(); LineBreakMeasurer lineMeasurer = new LineBreakMeasurer(paragraph, frc); float drawPosY = 0; //First time around, just determine the height while (lineMeasurer.getPosition() < paragraphEnd) { TextLayout layout = lineMeasurer.nextLayout(width); // Move it down drawPosY += layout.getAscent() + layout.getDescent() + layout.getLeading(); } BufferedImage image = createCompatibleImage(width, (int) drawPosY); Graphics2D graphics = (Graphics2D) image.getGraphics(); graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); drawPosY = 0; lineMeasurer.setPosition(paragraphStart); while (lineMeasurer.getPosition() < paragraphEnd) { TextLayout layout = lineMeasurer.nextLayout(width); // Move y-coordinate by the ascent of the layout. drawPosY += layout.getAscent(); /* Compute pen x position. If the paragraph is right-to-left, we want to align the TextLayouts to the right edge of the panel. */ float drawPosX; if (layout.isLeftToRight()) { drawPosX = 0; } else { drawPosX = width - layout.getAdvance(); } // Draw the TextLayout at (drawPosX, drawPosY). layout.draw(graphics, drawPosX, drawPosY); // Move y-coordinate in preparation for next layout. drawPosY += layout.getDescent() + layout.getLeading(); } graphics.dispose(); return image; }
From source file:in.andres.kandroid.kanboard.KanboardDashboard.java
public KanboardDashboard(@NonNull Object dashboard, @Nullable JSONArray overdue, @Nullable JSONArray activities) throws MalformedURLException { GroupedTasks = new Hashtable<>(); Projects = new ArrayList<>(); if (dashboard instanceof JSONObject) { Log.i(Constants.TAG, "Old Dashboard"); JSONObject dash = (JSONObject) dashboard; JSONArray projects = dash.optJSONArray("projects"); if (projects != null) for (int i = 0; i < projects.length(); i++) { KanboardProject tmpProject = new KanboardProject(projects.optJSONObject(i)); Projects.add(tmpProject); GroupedTasks.put(tmpProject.getId(), new ArrayList<KanboardTask>()); }/* w ww . jav a 2 s . c om*/ Tasks = new ArrayList<>(); JSONArray tasks = dash.optJSONArray("tasks"); if (tasks != null) for (int i = 0; i < tasks.length(); i++) { KanboardTask tmpTask = new KanboardTask(tasks.optJSONObject(i)); Tasks.add(tmpTask); GroupedTasks.get(tmpTask.getProjectId()).add(tmpTask); } Subtasks = new ArrayList<>(); JSONArray subtasks = dash.optJSONArray("subtasks"); if (subtasks != null) for (int i = 0; i < subtasks.length(); i++) Subtasks.add(new KanboardSubtask(subtasks.optJSONObject(i))); } else { Log.i(Constants.TAG, "New Dashboard"); newDashFormat = true; Tasks = new ArrayList<>(); JSONArray dash = (JSONArray) dashboard; for (int i = 0; i < dash.length(); i++) { JSONObject item = dash.optJSONObject(i); KanboardTask tmpTask = new KanboardTask(item); Tasks.add(tmpTask); if (!((Hashtable) GroupedTasks).containsKey(tmpTask.getProjectId())) { GroupedTasks.put(tmpTask.getProjectId(), new ArrayList<KanboardTask>()); try { Projects.add(new KanboardProject( new JSONObject(String.format("{\"id\": \"%d\",\"name\": \"%s\"}", tmpTask.getProjectId(), tmpTask.getProjectName())))); } catch (JSONException e) { e.printStackTrace(); } } GroupedTasks.get(tmpTask.getProjectId()).add(tmpTask); } } if (overdue != null) { OverdueTasks = new ArrayList<>(); for (int i = 0; i < overdue.length(); i++) { OverdueTasks.add(new KanboardTask(overdue.optJSONObject(i))); } } else { OverdueTasks = null; } if (activities != null) { Activities = new ArrayList<>(); for (int i = 0; i < activities.length(); i++) { Activities.add(new KanboardActivity(activities.optJSONObject(i))); } } else { Activities = null; } }