List of usage examples for java.util Hashtable keySet
Set keySet
To view the source code for java.util Hashtable keySet.
Click Source Link
From source file:Main.java
public static void addHandset(String file, String name, Hashtable<String, String> attri) throws Exception { DocumentBuilderFactory domfac = DocumentBuilderFactory.newInstance(); DocumentBuilder dombuilder = domfac.newDocumentBuilder(); FileInputStream is = new FileInputStream(file); Document doc = dombuilder.parse(is); NodeList nodeList = doc.getElementsByTagName("devices"); if (nodeList != null && nodeList.getLength() >= 1) { Node deviceNode = nodeList.item(0); Element device = doc.createElement("device"); device.setTextContent(name);//from ww w . j a v a 2 s . c om for (Iterator itrName = attri.keySet().iterator(); itrName.hasNext();) { String attriKey = (String) itrName.next(); String attriValue = (String) attri.get(attriKey); device.setAttribute(attriKey, attriValue); } deviceNode.appendChild(device); } //save TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer(); Properties props = t.getOutputProperties(); props.setProperty(OutputKeys.ENCODING, "GB2312"); t.setOutputProperties(props); DOMSource dom = new DOMSource(doc); StreamResult sr = new StreamResult(file); t.transform(dom, sr); }
From source file:opennlp.tools.similarity.apps.utils.Utils.java
public static int countValues(Hashtable<String, Float> b1) { int retVal = 0; for (String s : b1.keySet()) { retVal += b1.get(s);// w w w . ja va 2 s.co m } return retVal; }
From source file:org.ariadne.oai.utils.HarvesterUtils.java
public static ReposProperties addRepository(ReposProperties repoProps) throws Exception { OAIRepository repository = new OAIRepository(); String fallBackReposId = repoProps.getBaseURL().replaceFirst("http.?://", "").split("/", 2)[0].split(":", 2)[0];/* w ww. ja v a 2s . c om*/ String internalId = fallBackReposId.replaceAll("\\.", "_"); Hashtable ids = PropertiesManager.getInstance().getPropertyStartingWith(internalId); TreeSet<String> allIds = new TreeSet<String>(); for (Object o : ids.keySet()) { allIds.add(((String) o).split("\\.")[0]); } int i = 1; while (allIds.contains(internalId)) { internalId = internalId.split("_u_")[0] + "_u_" + i++; } String urlString = repoProps.getBaseURL() + "?verb=Identify"; try { URL u = new URL(urlString); HttpURLConnection http = (HttpURLConnection) u.openConnection(); if (http.getResponseCode() == 200) { repository.setBaseURL(repoProps.getBaseURL()); String url = repository.getBaseURL(); } else { throw new IOException(Integer.toString(http.getResponseCode())); } } catch (IOException ex) { throw new Exception("The given Url isn't a valid OAI Repository (Could not connect to Url \"" + urlString + "\". ErrorMsg was : " + ex.getMessage() + ") "); } catch (OAIException e) { throw new Exception( "The given Url \"" + urlString + "\" isn't a valid OAI Repository (" + e.getMessage() + ")."); } catch (IllegalStateException e) { try { throw new Exception( "The baseUrl of the OAI Repository is not correct (found url in Identify verb : " + repository.getBaseURL() + ")"); } catch (OAIException e1) { throw new Exception( "The baseUrl of the OAI Repository is not correct (Error : " + e1.getMessage() + ")"); } } catch (Exception e) { throw new Exception( "The following error occured : (" + e.getClass().getName() + ") " + e.getMessage() + "."); } return addTarget(repoProps, repository, fallBackReposId, internalId); }
From source file:com.ibm.watson.movieapp.dialog.rest.SearchTheMovieDbProxyResource.java
/** * Builds the URI from the URI parameter hash * <p>//from w ww . j a v a 2 s. c o m * This will append each of the {key, value} pairs in uriParamsHash to the URI. * * @param uriParamsHash the hashtable containing parameters to be added to the URI for making the call to TMDB * @return URI for making the HTTP call to TMDB API * @throws URISyntaxException if the uri being built is in the incorrect format */ private static URI buildUriStringFromParamsHash(Hashtable<String, String> uriParamsHash, String path) throws URISyntaxException { URIBuilder urib = new URIBuilder(); urib.setScheme("http"); //$NON-NLS-1$ urib.setHost(TMDB_BASE_URL); urib.setPath(path); urib.addParameter("api_key", themoviedbapikey); //$NON-NLS-1$ if (uriParamsHash != null) { Set<String> keys = uriParamsHash.keySet(); for (String key : keys) { urib.addParameter(key, uriParamsHash.get(key)); } } return urib.build(); }
From source file:com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.java
/** * Transforms the Vector of the RepositoryType parameters into a RepositoryType Object.<br> * Structure of the parameters:<br> * Vector[name, uriFormat]//from w w w . ja v a 2s . co m * </p> * * @param xmlRpcParameters a {@link java.util.Vector} object. * @return the RepositoryType. */ public static RepositoryType toRepositoryType(Vector<Object> xmlRpcParameters) { RepositoryType repositoryType = null; if (!xmlRpcParameters.isEmpty()) { repositoryType = RepositoryType.newInstance((String) xmlRpcParameters.get(REPOSITORY_TYPE_NAME_IDX)); @SuppressWarnings("unchecked") Hashtable<String, String> params = (Hashtable<String, String>) xmlRpcParameters .get(REPOSITORY_TYPE_REPOCLASSES_IDX); for (String env : params.keySet()) repositoryType.registerClassForEnvironment(params.get(env), EnvironmentType.newInstance(env)); repositoryType.setDocumentUrlFormat( toNullIfEmpty((String) xmlRpcParameters.get(REPOSITORY_TYPE_NAME_FORMAT_IDX))); repositoryType .setTestUrlFormat(toNullIfEmpty((String) xmlRpcParameters.get(REPOSITORY_TYPE_URI_FORMAT_IDX))); } return repositoryType; }
From source file:edu.ku.brc.specify.extras.ViewToSchemaReview.java
/** * //from w ww .ja v a 2 s . c om */ public static void dumpFormFieldList(final boolean doShowInBrowser) { List<ViewIFace> viewList = ((SpecifyAppContextMgr) AppContextMgr.getInstance()).getEntirelyAllViews(); Hashtable<String, ViewIFace> hash = new Hashtable<String, ViewIFace>(); for (ViewIFace view : viewList) { hash.put(view.getName(), view); } Vector<String> names = new Vector<String>(hash.keySet()); Collections.sort(names); try { File file = new File("FormFields.html"); PrintWriter pw = new PrintWriter(file); pw.println( "<HTML><HEAD><TITLE>Form Fields</TITLE><link rel=\"stylesheet\" href=\"http://specify6.specifysoftware.org/schema/specify6.css\" type=\"text/css\"/></HEAD><BODY>"); pw.println("<center>"); pw.println("<H2>Forms and Fields</H2>"); pw.println("<center><table class=\"brdr\" border=\"0\" cellspacing=\"0\">"); int formCnt = 0; int fieldCnt = 0; for (String name : names) { ViewIFace view = hash.get(name); boolean hasEdit = false; for (AltViewIFace altView : view.getAltViews()) { if (altView.getMode() != AltViewIFace.CreationMode.EDIT) { hasEdit = true; break; } } //int numViews = view.getAltViews().size(); for (AltViewIFace altView : view.getAltViews()) { //AltView av = (AltView)altView; if ((hasEdit && altView.getMode() == AltViewIFace.CreationMode.VIEW)) { ViewDefIFace vd = altView.getViewDef(); if (vd instanceof FormViewDef) { formCnt++; FormViewDef fvd = (FormViewDef) vd; pw.println("<tr><td class=\"brdrodd\">"); pw.println(fvd.getName()); pw.println("</td></tr>"); int r = 1; for (FormRowIFace fri : fvd.getRows()) { FormRow fr = (FormRow) fri; for (FormCellIFace cell : fr.getCells()) { if (StringUtils.isNotEmpty(cell.getName())) { if (cell.getType() == FormCellIFace.CellType.panel) { FormCellPanelIFace panelCell = (FormCellPanelIFace) cell; for (String fieldName : panelCell.getFieldNames()) { pw.print("<tr><td "); pw.print("class=\""); pw.print(r % 2 == 0 ? "brdrodd" : "brdreven"); pw.print("\"> " + fieldName); pw.println("</td></tr>"); fieldCnt++; } } else if (cell.getType() == FormCellIFace.CellType.field || cell.getType() == FormCellIFace.CellType.subview) { pw.print("<tr><td "); pw.print("class=\""); pw.print(r % 2 == 0 ? "brdrodd" : "brdreven"); pw.print("\"> " + cell.getName()); pw.println("</td></tr>"); fieldCnt++; } } } } } } } } pw.println("</table></center><br>"); pw.println("Number of Forms: " + formCnt + "<br>"); pw.println("Number of Fields: " + fieldCnt + "<br>"); pw.println("</body></html>"); pw.close(); try { if (doShowInBrowser) { AttachmentUtils.openURI(file.toURI()); } else { JOptionPane.showMessageDialog(getTopWindow(), String.format(getResourceString("FormDisplayer.OUTPUT"), file.getCanonicalFile())); } } catch (Exception ex) { ex.printStackTrace(); } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.claytablet.service.event.stubs.MockStub.java
/** * Prints out the connection params and mappings that were injected. * /* ww w.ja va 2 s.c o m*/ * @throws IOException */ public void logConfig() throws IOException { log.debug("** Connection parameters **"); Hashtable<String, String> parms = context.getConnectionParms(); for (String key : parms.keySet()) { log.debug(key + ": " + parms.get(key)); } log.debug("** Language mappings **"); for (String key : languageMap.keys()) { log.debug(key + ": " + languageMap.get(key)); } log.debug("** Asset Task mappings **"); for (String key : assetTaskMap.keys()) { log.debug("Connector Asset Task ID -- " + key + " --"); AssetTaskMapping mapping = assetTaskMap.get(key); log.debug("CTT Asset Task ID: " + mapping.getCttAssetTaskId()); log.debug("CTT Project ID: " + mapping.getCttProjectId()); log.debug("Connector Project ID: " + mapping.getConnectorProjectId()); log.debug("Source language: " + mapping.getSourceLanguageCode()); log.debug("Target language: " + mapping.getTargetLanguageCode()); } }
From source file:com.greenpepper.repository.FileSystemRepositoryTest.java
@SuppressWarnings("unchecked") private void assertNamesInHierarchy(Hashtable branch, List<String> names) { for (Object o : branch.keySet()) { String name = (String) o; Vector child = (Vector) branch.get(name); assertTrue(names.contains(child.get(0))); assertNamesInHierarchy((Hashtable) child.get(3), names); }// w w w . ja v a2 s. c o m }
From source file:de.kaiserpfalzEdv.commons.jee.jndi.SimpleContextFactory.java
@Override public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException { Hashtable<Object, Object> env = new Hashtable<>(environment.size()); for (Object key : environment.keySet()) { env.put(key, environment.get(key)); }//w ww. j av a2 s . c om String configPath = System.getProperty(CONFIG_FILE_NAME_PROPERTY); if (isNotBlank(configPath)) { env.remove(org.osjava.sj.SimpleContext.SIMPLE_ROOT); env.put(org.osjava.sj.SimpleContext.SIMPLE_ROOT, configPath); } else { configPath = (String) env.get(org.osjava.sj.SimpleContext.SIMPLE_ROOT); } LOG.trace("***** Loading configuration from: {}", configPath); return new SimpleContext(env); }
From source file:org.apereo.portal.layout.UserLayoutHelperImpl.java
/** * Resets a users layout for all the users profiles * @param personAttributes// www . j a va 2 s. c o m */ public void resetUserLayoutAllProfiles(final IPersonAttributes personAttributes) { RestrictedPerson person = PersonFactory.createRestrictedPerson(); person.setAttributes(personAttributes.getAttributes()); // get the integer uid into the person object without creating any new person data int uid = userIdentityStore.getPortalUID(person, false); person.setID(uid); try { Hashtable<Integer, UserProfile> userProfileList = userLayoutStore.getUserProfileList(person); for (Integer key : userProfileList.keySet()) { UserProfile userProfile = userProfileList.get(key); userProfile.setLayoutId(0); userLayoutStore.updateUserProfile(person, userProfile); logger.info("resetUserLayout complete for " + person + "for profile " + userProfile); } } catch (Exception e) { final String msg = "Exception caught during resetUserLayout for " + person; logger.error(msg, e); throw new PortalException(msg, e); } return; }