List of usage examples for java.util Vector addAll
public boolean addAll(Collection<? extends E> c)
From source file:org.fao.geonet.kernel.EditLib.java
/** * Given an unexpanded tree, creates container elements and their children. * * @param schema//from w w w.j a va2s. c o m * @param md * @throws Exception */ public void expandElements(String schema, Element md) throws Exception { //--- create containers and fill them with elements using a depth first //--- search List childs = md.getChildren(); for (Object child : childs) { expandElements(schema, (Element) child); } String name = md.getQualifiedName(); String parentName = getParentNameFromChild(md); MetadataSchema mdSchema = scm.getSchema(schema); String typeName = mdSchema.getElementType(name, parentName); MetadataType thisType = mdSchema.getTypeInfo(typeName); if (thisType.hasContainers) { Vector<Content> holder = new Vector<Content>(); for (int i = 0; i < thisType.getElementCount(); i++) { String chName = thisType.getElementAt(i); if (chName.contains(Edit.RootChild.CHOICE) || chName.contains(Edit.RootChild.GROUP) || chName.contains(Edit.RootChild.SEQUENCE)) { List<Element> elems = searchChildren(chName, md, schema); if (elems.size() > 0) { holder.addAll(elems); } } else { List<Element> chElem = getChildren(md, chName); for (Element elem : chElem) { holder.add(elem.detach()); } } } md.removeContent(); md.addContent(holder); } }
From source file:vitro.vspEngine.service.persistence.DBCommons.java
/** * * @param ssUNinfoGWHM/*from w ww . jav a2 s. c o m*/ * @param ssUNCapHM * @param in_advCapsToSensModelsToMerge * @param in_advSmDevs * @param in_advGatewayIDStr * @param in_regGatewayDescStr * @param in_advGatewayIPv4 * @param in_advGatewayLocStr */ synchronized public void mergeAdvDataToGateway(HashMap<String, GatewayWithSmartNodes> ssUNinfoGWHM, HashMap<String, Vector<SensorModel>> ssUNCapHM, HashMap<String, Vector<SensorModel>> in_advCapsToSensModelsToMerge, Vector<SmartNode> in_advSmDevs, String in_advGatewayIDStr, String in_regGatewayDescStr, String in_advGatewayIPv4, String in_advGatewayLocStr) { // // For each generic capability found in the GatewayDescriptionAdvertisement (even when went per smart device separately) // Check if the UserPeer's capHMap contains it // (if not add it, with its full vector of sensormodels). // (if it does, then add only those sensormodels that don't exist in the existing vector of sensormodels (of the UserPeer's capHMap) // TODO: support String for id for sensorModels ...(?) Set<String> advCapsSet = in_advCapsToSensModelsToMerge.keySet(); Iterator<String> advCapsIt = advCapsSet.iterator(); // from the received GW ADV String currentAdvCap; // place one check-box for each Generic Capability Description while (advCapsIt.hasNext()) { currentAdvCap = advCapsIt.next(); Vector<SensorModel> listOfSensToAdd = in_advCapsToSensModelsToMerge.get(currentAdvCap); if (ssUNCapHM.containsKey(currentAdvCap)) { Vector<SensorModel> previousListOfSensModel = ssUNCapHM.get(currentAdvCap); // concatenate with previous List (skip if the results are from an existing gateway) // so this does not PRECLUDE the same sensor model being added for the generic capability. (TODO: this can only be fixed in the gateways retroactively make a shared hastable for unique ids for specifi sensormodels) // but each model is uniquely indexed within its gateway (and maintains the gateway id info in its class type). This is good and similar to the SensorML specs // SensorML additionally allows for multiple output formats for a "sensor model" (component) and unlimited nesting in components though.... for (int k1 = 0; k1 < previousListOfSensModel.size(); k1++) { for (int m1 = 0; m1 < listOfSensToAdd.size(); m1++) { if ((previousListOfSensModel.get(k1).getGatewayId() .equals(listOfSensToAdd.get(m1).getGatewayId())) && (previousListOfSensModel.get(k1).getSmID() .equals(listOfSensToAdd.get(m1).getSmID()))) { // we should add only the newly added models...if any listOfSensToAdd.removeElementAt(m1); m1 -= 1; } } } previousListOfSensModel.addAll(listOfSensToAdd); } else if (listOfSensToAdd.size() > 0) { ssUNCapHM.put(currentAdvCap, listOfSensToAdd); } } // Find an existing entry for the gateway if (ssUNinfoGWHM.containsKey(in_advGatewayIDStr)) { // update existing mapped gateway with new possible values for each field GatewayWithSmartNodes tmpToUpd = ssUNinfoGWHM.get(in_advGatewayIDStr); Vector<SmartNode> existingSmDevs = tmpToUpd.getSmartNodesVec(); tmpToUpd.setName(in_regGatewayDescStr); //renew description tmpToUpd.setDescription("GwDesc"); //???? boolean foundDev = false; for (int j = 0; j < in_advSmDevs.size(); j++) { foundDev = false; for (int o = 0; o < existingSmDevs.size(); o++) { if (in_advSmDevs.elementAt(j).getId().equalsIgnoreCase(existingSmDevs.elementAt(o).getId())) { foundDev = true; existingSmDevs.setElementAt(in_advSmDevs.elementAt(j), o); //replace (update) } } if (foundDev == false) { existingSmDevs.add(in_advSmDevs.elementAt(j)); } } } else { GatewayWithSmartNodes tmpToInsert = null; if (in_regGatewayDescStr != null && !(in_regGatewayDescStr.trim().isEmpty())) { tmpToInsert = new GatewayWithSmartNodes(new Gateway(in_advGatewayIDStr, in_regGatewayDescStr, "GwDesc", null, null, in_advGatewayIPv4, in_advGatewayLocStr)); tmpToInsert.setSmartNodesVec(in_advSmDevs); } else { GeoPoint gwGP = null; if (in_advGatewayLocStr != null) { String[] locTokensLatLong = in_advGatewayLocStr.split(","); if (locTokensLatLong != null && locTokensLatLong.length == 2) { gwGP = new GeoPoint(locTokensLatLong[0].trim(), locTokensLatLong[1].trim(), "0"); } } tmpToInsert = new GatewayWithSmartNodes( new Gateway(in_advGatewayIDStr, "GwName", "GwDesc", null, gwGP, in_advGatewayIPv4, null)); tmpToInsert.setSmartNodesVec(in_advSmDevs); } ssUNinfoGWHM.put(in_advGatewayIDStr, tmpToInsert); } }
From source file:cl.utfsm.cdbChecker.CDBChecker.java
/** * This get the filenames of type 'type' from the given path. * There could be several paths separated by ":". * // ww w.j a v a 2 s .co m * @param path multiple paths separated by ":" to look for 'type' files. * @param type type of files to get. * @return a vector of strings with the filenames of type 'type' with absolute path. * An empty vector is returned if paths is empty. */ protected Vector<String> getFilenames(String paths[], String type) { Vector<String> vector = new Vector<String>(); String files[]; /* * Scans the list of paths. */ for (int i = 0; i < paths.length; i++) { if (paths[i].length() != 0) { File file = new File(paths[i]); if (file.exists()) { if (file.isFile()) { //Is a File if (paths[i].endsWith("." + type)) vector.add(paths[i]); } else { //Is a directory if (!(paths[i].endsWith(File.separator))) paths[i] = paths[i] + File.separator; //Search for files, filtering for 'type' if (type.equals("xml")) files = (new File(paths[i])).list(xmlFileFilter); else files = (new File(paths[i])).list(xsdFileFilter); //Add the files to the vector. if (files != null) for (int j = 0; j < files.length; j++) vector.addElement(paths[i] + files[j]); if (this.recursive) { String[] dirs = (new File(paths[i])).list(dirFileFilter); if (dirs.length != 0) for (int j = 0; j < dirs.length; j++) { dirs[j] = paths[i] + dirs[j] + File.separator; } vector.addAll(getFilenames(dirs, type)); } } } } } return vector; }
From source file:org.fao.geonet.kernel.EditLib.java
/** * Contracts container elements.//from ww w . j a va 2 s. com * * @param md */ public void contractElements(Element md) { //--- contract container children at each level in the XML tree Vector<Object> children = new Vector<Object>(); List childs = md.getContent(); for (Object obj : childs) { if (obj instanceof Element) { Element mdCh = (Element) obj; String mdName = mdCh.getName(); if (mdName.contains(Edit.RootChild.CHOICE) || mdName.contains(Edit.RootChild.GROUP) || mdName.contains(Edit.RootChild.SEQUENCE)) { if (mdCh.getChildren().size() > 0) { Vector<Object> chChilds = getContainerChildren(mdCh); if (chChilds.size() > 0) { children.addAll(chChilds); } } } else { children.add(mdCh.clone()); } } else { children.add(obj); } } md.removeContent(); md.addContent(children); //--- now move down to the next level for (Object obj : children) { if (obj instanceof Element) { contractElements((Element) obj); } } }
From source file:com.globalsight.everest.usermgr.UserManagerLocal.java
/** * Get all active and created users.//from w w w .j a v a 2 s . co m * * @return a Vector of User objects * @exception UserManagerException * - Component related exception. * @exception java.rmi.RemoteException * - Network related exception. */ public Vector getUsers() throws RemoteException, UserManagerException { String companyId = CompanyThreadLocal.getInstance().getValue(); String companyName = CompanyWrapper.getCompanyNameById(companyId); String superCompanyName = CompanyWrapper.getCompanyNameById(CompanyWrapper.SUPER_COMPANY_ID); Vector users = new Vector(); String hql = "from UserImpl u where u.state != :state1 and u.state != :state2 and u.type != :type"; Map map = new HashMap(); map.put("state1", User.State.DELETED); map.put("state2", User.State.DEACTIVE); map.put("type", User.UserType.ANONYMOUS); if (!CompanyWrapper.SUPER_COMPANY_ID.equals(companyId)) { hql += " and (u.companyName = :companyName or u.companyName = :superCompanyName)"; map.put("companyName", companyName); map.put("superCompanyName", superCompanyName); } users.addAll(HibernateUtil.search(hql, map)); return users; }
From source file:edu.ku.brc.af.tasks.subpane.formeditor.ViewSetSelectorPanel.java
protected Vector<FormCellLabel> getAvailableLabels() { Vector<FormCellLabel> list = new Vector<FormCellLabel>(); Hashtable<String, FormCellLabel> labelHash = new Hashtable<String, FormCellLabel>(); //Hashtable<String, FormCellLabel> labelForHash = new Hashtable<String, FormCellLabel>(); // Add all the labels for (FormRowIFace row : formViewDef.getRows()) { for (FormCellIFace cell : row.getCells()) { if (cell instanceof FormCellLabel) { //labelForHash.put(((FormCellLabel)cell).getLabelFor(), (FormCellLabel)cell); labelHash.put(cell.getIdent(), (FormCellLabel) cell); }// www .ja va2 s . com } } // remove the ones in use for (FormRowIFace row : formViewDef.getRows()) { for (FormCellIFace cell : row.getCells()) { if (cell instanceof FormCellField) { FormCellField fcf = (FormCellField) cell; FormCellLabel label = labelHash.get(fcf.getIdent()); if (label != null) { labelHash.remove(label.getIdent()); } } } } list.addAll(labelHash.values()); return list; }
From source file:edu.ku.brc.af.tasks.StatsTrackerTask.java
/** * Creates an array of POST method parameters to send with the version checking / usage tracking connection. * //ww w . j av a2s.c om * @param doSendSecondaryStats if true, the POST parameters include usage stats * @return an array of POST parameters */ protected Vector<NameValuePair> createPostParameters(final boolean doSendSecondaryStats) { Vector<NameValuePair> postParams = new Vector<NameValuePair>(); try { // get the install ID String installID = UsageTracker.getInstallId(); postParams.add(new NameValuePair("id", installID)); //$NON-NLS-1$ //get ISA number Collection collection = AppContextMgr.getInstance().hasContext() ? AppContextMgr.getInstance().getClassObject(Collection.class) : null; String isaNumber = collection == null ? "N/A" : collection.getIsaNumber(); try { postParams.add(new NameValuePair("ISA_number", isaNumber)); //$NON-NLS-1$ } catch (NullPointerException e) { } // get the OS name and version postParams.add(new NameValuePair("os_name", System.getProperty("os.name"))); //$NON-NLS-1$ postParams.add(new NameValuePair("os_version", System.getProperty("os.version"))); //$NON-NLS-1$ postParams.add(new NameValuePair("java_version", System.getProperty("java.version"))); //$NON-NLS-1$ postParams.add(new NameValuePair("java_vendor", System.getProperty("java.vendor"))); //$NON-NLS-1$ //if (!UIRegistry.isRelease()) // For Testing Only { postParams.add(new NameValuePair("user_name", System.getProperty("user.name"))); //$NON-NLS-1$ try { postParams.add(new NameValuePair("ip", InetAddress.getLocalHost().getHostAddress())); //$NON-NLS-1$ } catch (UnknownHostException e) { } } postParams.add(new NameValuePair("tester", //$NON-NLS-1$ AppPreferences.getLocalPrefs().getBoolean("tester", false) ? "true" : "false")); String resAppVersion = UIRegistry.getAppVersion(); if (StringUtils.isEmpty(resAppVersion)) { resAppVersion = "Unknown"; } postParams.add(new NameValuePair("app_version", resAppVersion)); //$NON-NLS-1$ Vector<NameValuePair> extraStats = collectSecondaryStats(doSendSecondaryStats); if (extraStats != null) { postParams.addAll(extraStats); } // get all of the usage tracking stats List<Pair<String, Integer>> statistics = UsageTracker.getUsageStats(); for (Pair<String, Integer> stat : statistics) { postParams.add(new NameValuePair(stat.first, Integer.toString(stat.second))); } return postParams; } catch (Exception ex) { ex.printStackTrace(); edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(StatsTrackerTask.class, ex); } return null; }
From source file:com.globalsight.everest.usermgr.UserManagerLocal.java
public Vector getUsers(String condition) throws RemoteException, UserManagerException { String companyId = CompanyThreadLocal.getInstance().getValue(); String companyName = CompanyWrapper.getCompanyNameById(companyId); String superCompanyName = CompanyWrapper.getCompanyNameById(CompanyWrapper.SUPER_COMPANY_ID); Vector users = new Vector(); String hql = "from UserImpl u where u.state != :state1 and u.state != :state2 and u.type != :type"; Map map = new HashMap(); map.put("state1", User.State.DELETED); map.put("state2", User.State.DEACTIVE); map.put("type", User.UserType.ANONYMOUS); if (!CompanyWrapper.SUPER_COMPANY_ID.equals(companyId)) { hql += " and (u.companyName = :companyName or u.companyName = :superCompanyName)"; map.put("companyName", companyName); map.put("superCompanyName", superCompanyName); }/* w w w.java 2 s .c o m*/ hql += condition; users.addAll(HibernateUtil.search(hql, map)); return users; }
From source file:nzilbb.csv.CsvDeserializer.java
/** * Loads the serialized form of the graph, using the given set of named streams. * @param streams A list of named streams that contain all the * transcription/annotation data required, and possibly (a) stream(s) for the media annotated. * @param schema The layer schema, definining layers and the way they interrelate. * @return A list of parameters that require setting before {@link IDeserializer#deserialize()} * can be invoked. This may be an empty list, and may include parameters with the value already * set to a workable default. If there are parameters, and user interaction is possible, then * the user may be presented with an interface for setting/confirming these parameters, before * they are then passed to {@link IDeserializer#setParameters(ParameterSet)}. * @throws SerializationException If the graph could not be loaded. * @throws IOException On IO error./*from w w w. ja v a2 s.co m*/ */ @SuppressWarnings({ "rawtypes", "unchecked" }) public ParameterSet load(NamedStream[] streams, Schema schema) throws SerializationException, IOException { // take the first stream, ignore all others. NamedStream csv = Utility.FindSingleStream(streams, ".csv", "text/csv"); if (csv == null) throw new SerializationException("No CSV stream found"); setName(csv.getName()); setSchema(schema); // create a list of layers we need and possible matching layer names LinkedHashMap<Parameter, List<String>> layerToPossibilities = new LinkedHashMap<Parameter, List<String>>(); HashMap<String, LinkedHashMap<String, Layer>> layerToCandidates = new HashMap<String, LinkedHashMap<String, Layer>>(); LinkedHashMap<String, Layer> metadataLayers = new LinkedHashMap<String, Layer>(); for (Layer layer : schema.getRoot().getChildren().values()) { if (layer.getAlignment() == Constants.ALIGNMENT_NONE) { metadataLayers.put(layer.getId(), layer); } } // next turn child layer // look for person attributes for (Layer layer : schema.getParticipantLayer().getChildren().values()) { if (layer.getAlignment() == Constants.ALIGNMENT_NONE) { metadataLayers.put(layer.getId(), layer); } } // next turn child layer LinkedHashMap<String, Layer> utteranceAndMetadataLayers = new LinkedHashMap<String, Layer>(metadataLayers); utteranceAndMetadataLayers.put(getUtteranceLayer().getId(), getUtteranceLayer()); LinkedHashMap<String, Layer> whoAndMetadataLayers = new LinkedHashMap<String, Layer>(metadataLayers); whoAndMetadataLayers.put(getParticipantLayer().getId(), getParticipantLayer()); // read the header line setParser(CSVParser.parse(csv.getStream(), java.nio.charset.Charset.forName("UTF-8"), CSVFormat.EXCEL.withHeader())); setHeaderMap(parser.getHeaderMap()); Vector<String> possibleIDHeaders = new Vector<String>(); Vector<String> possibleUtteranceHeaders = new Vector<String>(); Vector<String> possibleParticipantHeaders = new Vector<String>(); for (String header : getHeaderMap().keySet()) { if (header.trim().length() == 0) continue; Vector<String> possibleMatches = new Vector<String>(); possibleMatches.add("transcript" + header); possibleMatches.add("participant" + header); possibleMatches.add("speaker" + header); possibleMatches.add(header); // special cases if (header.equalsIgnoreCase("id") || header.equalsIgnoreCase("transcript")) { possibleIDHeaders.add(header); } else if (header.equalsIgnoreCase("text") || header.equalsIgnoreCase("document")) { possibleUtteranceHeaders.add(header); } else if (header.equalsIgnoreCase("name") || header.equalsIgnoreCase("participant") || header.equalsIgnoreCase("participantid")) { possibleParticipantHeaders.add(header); } layerToPossibilities.put(new Parameter("header_" + getHeaderMap().get(header), Layer.class, header), possibleMatches); layerToCandidates.put("header_" + getHeaderMap().get(header), metadataLayers); } // next header ParameterSet parameters = new ParameterSet(); // add utterance/participant parameters int defaultUtterancePossibilityIndex = 0; // if there are no obvious participant column possibilities... Parameter idColumn = new Parameter("id", String.class, "ID Column", "Column containing the ID of the text.", false); if (possibleIDHeaders.size() == 0) { // ...include all columns possibleIDHeaders.addAll(getHeaderMap().keySet()); } else { idColumn.setValue(possibleIDHeaders.firstElement()); } idColumn.setPossibleValues(possibleIDHeaders); parameters.addParameter(idColumn); // if there are no obvious participant column possibilities... if (possibleParticipantHeaders.size() == 0) { // ...include all columns possibleParticipantHeaders.addAll(getHeaderMap().keySet()); // default participant column will be the first column, // so default utterance should be the second (if we didn't find obvious possible text column) if (possibleParticipantHeaders.size() > 1) // but only if there's more than one column { defaultUtterancePossibilityIndex = 1; } } Parameter participantColumn = new Parameter("who", "Participant Column", "Column containing the ID of the author of the text.", true, possibleParticipantHeaders.firstElement()); participantColumn.setPossibleValues(possibleParticipantHeaders); parameters.addParameter(participantColumn); // if there are no obvious text column possibilities... if (possibleUtteranceHeaders.size() == 0) { // ...include all columns possibleUtteranceHeaders.addAll(getHeaderMap().keySet()); } else { // we found a possible text column, so run with it regardless of whether we also found // a possible participant column defaultUtterancePossibilityIndex = 0; } Parameter utteranceColumn = new Parameter("text", "Text Column", "Column containing the transcript text.", true, possibleUtteranceHeaders.elementAt(defaultUtterancePossibilityIndex)); utteranceColumn.setPossibleValues(possibleUtteranceHeaders); parameters.addParameter(utteranceColumn); // add column-mapping parameters, and set possibile/default values for (Parameter p : layerToPossibilities.keySet()) { List<String> possibleNames = layerToPossibilities.get(p); LinkedHashMap<String, Layer> candidateLayers = layerToCandidates.get(p.getName()); parameters.addParameter(p); if (p.getValue() == null && candidateLayers != null && possibleNames != null) { p.setValue(Utility.FindLayerById(candidateLayers, possibleNames)); } if (p.getPossibleValues() == null && candidateLayers != null) { p.setPossibleValues(candidateLayers.values()); } } return parameters; }
From source file:org.sakaiproject.site.tool.AdminSitesAction.java
/** * Read the site form and update the site in state. * // w w w .j av a 2 s. c o m * @return true if the form is accepted, false if there's a validation error (an alertMessage will be set) */ private boolean readSiteForm(RunData data, SessionState state) { // read the form String id = StringUtil.trimToNull(data.getParameters().getString("id")); String title = StringUtil.trimToNull(data.getParameters().getString("title")); String type = StringUtil.trimToNull(data.getParameters().getString("type")); String shortDescription = StringUtil.trimToNull(data.getParameters().getString("shortDescription")); String description = StringUtil.trimToNull(data.getParameters().getString("description")); boolean joinable = data.getParameters().getBoolean("joinable"); String joinerRole = StringUtil.trimToNull(data.getParameters().getString("joinerRole")); String icon = StringUtil.trimToNull(data.getParameters().getString("icon")); String info = StringUtil.trimToNull(data.getParameters().getString("info")); boolean published = data.getParameters().getBoolean("published"); boolean softlyDeleted = data.getParameters().getBoolean("softlyDeleted"); String skin = StringUtil.trimToNull(data.getParameters().getString("skin")); boolean pubView = data.getParameters().getBoolean("pubView"); boolean customOrder = data.getParameters().getBoolean("customOrder"); // get the site Site site = (Site) state.getAttribute("site"); // add if needed if (site == null) { try { site = SiteService.addSite(id, type); // mark the site as new, so on cancel it can be deleted site.getPropertiesEdit().addProperty("new", "true"); // put the site in the state state.setAttribute("site", site); } catch (IdUsedException e) { addAlert(state, rb.getFormattedMessage("sitact.thesitid", new Object[] { id })); return false; } catch (IdInvalidException e) { addAlert(state, rb.getFormattedMessage("sitact.thesitid2", new Object[] { id })); return false; } catch (PermissionException e) { addAlert(state, rb.getFormattedMessage("sitact.youdonot2", new Object[] { id })); return false; } } // update if (site != null) { if (joinable) { // check if there is a qualifed role in the role field if ((joinerRole == null) || (joinerRole.equals(""))) { addAlert(state, rb.getString("sitact.sperol")); return false; } Vector roles = new Vector(); Vector roleIds = new Vector(); AuthzGroup realm = null; try { realm = authzGroupService.getAuthzGroup(site.getReference()); roles.addAll(realm.getRoles()); } catch (GroupNotDefinedException e) { // use the type's template, if defined String realmTemplate = "!site.template"; if (type != null) { realmTemplate = realmTemplate + "." + type; } try { AuthzGroup r = authzGroupService.getAuthzGroup(realmTemplate); roles.addAll(r.getRoles()); } catch (GroupNotDefinedException err) { try { AuthzGroup rr = authzGroupService.getAuthzGroup("!site.template"); roles.addAll(rr.getRoles()); } catch (GroupNotDefinedException ee) { } } } for (int i = 0; i < roles.size(); i++) { roleIds.add(((Role) roles.elementAt(i)).getId()); } if (!roleIds.contains(joinerRole)) { addAlert(state, rb.getString("sitact.sperol")); return false; } } site.setTitle(title); site.setShortDescription(shortDescription); site.setDescription(description); site.setJoinable(joinable); site.setJoinerRole(joinerRole); site.setIconUrl(icon); site.setInfoUrl(info); site.setSkin(skin); site.setType(type); site.setPubView(pubView); site.setPublished(published); site.setSoftlyDeleted(softlyDeleted); site.setCustomPageOrdered(customOrder); } return true; }