List of usage examples for java.util Hashtable get
@SuppressWarnings("unchecked") public synchronized V get(Object key)
From source file:com.flexoodb.engines.FlexJAXBDBDataEngine.java
private void indexValues(String id, String tablename, Object obj, Connection conn) throws Exception { Hashtable h = null; if (obj instanceof Hashtable) { h = (Hashtable) obj;/*www. ja v a 2 s. c om*/ } else { h = _flexutils.getAvailableValues(((FlexContainer) obj).getObject()); } Enumeration en = h.keys(); while (en.hasMoreElements()) { String k = (String) en.nextElement(); Element e = (Element) h.get(k); Object o = e.getContent(); if (o != null && !e.getType().equals("byte[]") && FlexUtils.indexable(e.getType())) { if (!k.equals("Id")) { try { String v = null; if (o instanceof Date) { //v = (new SimpleDateFormat(FlexUtils._dateformat)).format((Date)o); v = ((Date) o).getTime() + ""; } else { v = o.toString(); } //System.out.println(k+" "+v+" "+o); // we only index non-empty values? //if (v!=null && !v.isEmpty()) //{ PreparedStatement ps = (PreparedStatement) conn.prepareStatement("insert into " + tablename.toLowerCase() + "_index (id,element,value) values (?,?,?)"); ps.setString(1, id); ps.setString(2, k); ps.setString(3, (v.length() > 100) ? v.substring(0, 99) : v); // possible issues in truncation? ps.executeUpdate(); ps.close(); //} } catch (Exception f) { } } } } }
From source file:com.flexive.tests.browser.AdmContentTest.java
/** * fill the LUT with a type name this is extracted from the menu * @param typeName the name of the type/*w ww . java 2 s . co m*/ */ private void fillLUT(String typeName) { if (propertyLUT.get(typeName) != null) return; int trys = 4; Hashtable<String, String> params = null; String html = ""; while (trys-- > 0) { try { navigateTo(NavigationTab.Structure); selectFrame(Frame.NavStructures); html = selenium.getHtmlSource(); params = buildHashtableFromMenu(html, "{\"title\":'" + typeName + "'"); break; } catch (SelectItemsNotFoundException sinf) { sleep(300); } } if (trys <= 0) { params = buildHashtableFromMenu(html, "{\"title\":'" + typeName + "'"); } String link = PROPERTY_EDITOR_LINK + "?action=createProperty&id=" + params.get("typeId") + "&nodeType=" + params.get("nodeType"); propertyLinkLUT.put(typeName, link); propertyLUT.put(typeName, params); }
From source file:com.flexive.core.security.UserTicketImpl.java
/** * {@inheritDoc}/* w ww. jav a2 s . c o m*/ */ @Override public Long[] getACLsId(long ownerId, ACLCategory category, ACLPermission... perms) { Boolean mayCreate = null; Boolean mayRead = null; Boolean mayEdit = null; Boolean mayDelete = null; Boolean mayRelate = null; Boolean mayExport = null; for (ACLPermission perm : perms) { switch (perm) { case CREATE: mayCreate = true; break; case NOT_CREATE: mayCreate = false; break; case READ: mayRead = true; break; case NOT_READ: mayRead = false; break; case EDIT: mayEdit = true; break; case NOT_EDIT: mayEdit = false; break; case DELETE: mayDelete = true; break; case NOT_DELETE: mayDelete = false; break; case RELATE: mayRelate = true; break; case NOT_RELATE: mayRelate = false; break; case EXPORT: mayExport = true; break; case NOT_EXPORT: mayExport = false; break; } } Hashtable<Long, boolean[]> hlp = new Hashtable<Long, boolean[]>(this.assignments.length); // Condense the ACL right informations // If a ACL is assigned via groupX and groupY the rights are taken from both assignments. for (ACLAssignment acl : this.assignments) { if (acl.isOwnerGroupAssignment() && ownerId != userId) continue; if (category != null && acl.getACLCategory() != category) continue; Long key = acl.getAclId(); boolean[] rights = hlp.get(key); if (rights == null) { rights = new boolean[] { false, false, false, false, false, false, false }; } if (acl.getMayRead()) rights[ACLPermission.READ.ordinal()] = true; if (acl.getMayEdit()) rights[ACLPermission.EDIT.ordinal()] = true; if (acl.getMayDelete()) rights[ACLPermission.DELETE.ordinal()] = true; if (acl.getMayRelate()) rights[ACLPermission.RELATE.ordinal()] = true; if (acl.getMayExport()) rights[ACLPermission.EXPORT.ordinal()] = true; if (acl.getMayCreate() && !acl.isOwnerGroupAssignment()) rights[ACLPermission.CREATE.ordinal()] = true; hlp.put(key, rights); } // Return matching ACLs Enumeration keys = hlp.keys(); List<Long> result = new ArrayList<Long>(hlp.size()); while (keys.hasMoreElements()) { Long aclId = (Long) keys.nextElement(); boolean[] rights = hlp.get(aclId); if (mayRead != null && mayRead != rights[ACLPermission.READ.ordinal()]) continue; if (mayEdit != null && mayEdit != rights[ACLPermission.EDIT.ordinal()]) continue; if (mayDelete != null && mayDelete != rights[ACLPermission.DELETE.ordinal()]) continue; if (mayRelate != null && mayRelate != rights[ACLPermission.RELATE.ordinal()]) continue; if (mayExport != null && mayExport != rights[ACLPermission.EXPORT.ordinal()]) continue; if (mayCreate != null && mayCreate != rights[ACLPermission.CREATE.ordinal()]) continue; result.add(aclId); } return result.toArray(new Long[result.size()]); }
From source file:edu.ku.brc.specify.tasks.subpane.images.ImagesPane.java
/** * // w w w . j a v a 2s .c o m */ private void showDateDialog() { //PanelBuilder pb = new PanelBuilder(new FormLayout("p,2px,p", "p,4px,p")); //CustomDialog dlg = new CustomDialog((Frame)UIRegistry.getTopWindow(), "Search", true, pb.getPanel()); final ViewBasedDisplayDialog dlg = new ViewBasedDisplayDialog((Frame) UIRegistry.getTopWindow(), "Search", "ImageDateSearch", null, getResourceString(getResourceString("CHG_PWD_TITLE")), "OK", null, null, true, MultiView.HIDE_SAVE_BTN | MultiView.DONT_ADD_ALL_ALTVIEWS | MultiView.USE_ONLY_CREATION_MODE | MultiView.IS_EDITTING); //dlg.setHelpContext("CHANGE_PWD"); dlg.setWhichBtns(CustomDialog.OK_BTN | CustomDialog.CANCEL_BTN); Hashtable<String, String> valuesHash = new Hashtable<String, String>(); dlg.setData(valuesHash); UIHelper.centerAndShow(dlg); if (dlg.isCancelled()) return; String startDate = valuesHash.get("StartDate"); //String endDate = valuesHash.get("EndDate"); //System.out.println(String.format("[%s][%s]", startDate, endDate)); StringBuilder sb = new StringBuilder(); StringBuilder displayStr = new StringBuilder(); Integer year = null; Integer month = null; //Integer day = null; if (startDate.length() == 10) { //day = Integer.parseInt(startDate.substring(8,10)); sb.append(String.format("FileCreatedDate = '%s'", startDate)); displayStr.append(startDate); } else { if (startDate.length() > 3) // Year { year = Integer.parseInt(startDate.substring(0, 4)); sb.append(String.format("YEAR(FileCreatedDate) = %d", year)); displayStr.append(year.toString()); } if (startDate.length() > 6) { month = Integer.parseInt(startDate.substring(5, 7)); sb.append(String.format(" AND MONTH(FileCreatedDate) = %d", month)); displayStr.append(String.format("-%02d", month)); } } searchText.setText(displayStr.toString()); AppContextMgr acm = AppContextMgr.getInstance(); int[] ids = { acm.getClassObject(Collection.class).getId(), Attachment.COLLECTION_SCOPE, acm.getClassObject(Discipline.class).getId(), Attachment.DISCIPLINE_SCOPE, acm.getClassObject(Division.class).getId(), Attachment.DIVISION_SCOPE, }; StringBuilder whereSB = new StringBuilder(); for (int i = 0; i < ids.length; i += 2) { whereSB.append(String.format("(ScopeID = %d AND ScopeType = %d) OR ", ids[i], ids[i + 1])); } whereSB.append(String.format("(ScopeID IS NULL AND ScopeType = %d)", Attachment.GLOBAL_SCOPE)); String filter = getFilterString(); String whereStr = StringUtils.isNotEmpty(filter) ? (" AND " + filter) : ""; String sql = String.format( "SELECT a.AttachmentID, a.TableID, a.Title, a.AttachmentLocation, a.MimeType " + "FROM attachment a WHERE (%s) AND %s %s a.Title", whereSB.toString(), sb.toString(), whereStr); log.debug(sql); Statement stmt = null; try { rowsVector.clear(); stmt = DBConnection.getInstance().getConnection().createStatement(); ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { ImageDataItem imgDataItem = new ImageDataItem(rs.getInt(1), rs.getInt(2), rs.getString(3), rs.getString(4), rs.getString(5)); rowsVector.add(imgDataItem); } rs.close(); Collections.sort(rowsVector, new Comparator<ImageDataItem>() { @Override public int compare(ImageDataItem o1, ImageDataItem o2) { return o1.getShortName().compareTo(o2.getShortName()); } }); gridPanel.setItemList(rowsVector); gridPanel.reloadGallery(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (stmt != null) stmt.close(); } catch (Exception e) { } } }
From source file:foodsimulationmodel.pathmapping.Route.java
/** * Used to create a new BuildingsOnRoadCache object. This function is used instead of the constructor directly so * that the class can check if there is a serialised version on disk already. If not then a new one is created and * returned.//from w w w . ja va 2 s. co m * * @param buildingEnv * @param buildingsFile * @param roadEnv * @param roadsFile * @param serialisedLoc * @param geomFac * @return * @throws Exception */ public synchronized static BuildingsOnRoadCache getInstance(Geography<IAgent> buildingEnv, File buildingsFile, Geography<Road> roadEnv, File roadsFile, File serialisedLoc, GeometryFactory geomFac) throws Exception { double time = System.nanoTime(); // See if there is a cache object on disk. if (serialisedLoc.exists()) { FileInputStream fis = null; ObjectInputStream in = null; BuildingsOnRoadCache bc = null; try { fis = new FileInputStream(serialisedLoc); in = new ObjectInputStream(fis); bc = (BuildingsOnRoadCache) in.readObject(); in.close(); // Check that the cache is representing the correct data and the // modification dates are ok // (WARNING, if this class is re-compiled the serialised object // will still be read in). if (!buildingsFile.getAbsolutePath().equals(bc.buildingsFile.getAbsolutePath()) || !roadsFile.getAbsolutePath().equals(bc.roadsFile.getAbsolutePath()) || buildingsFile.lastModified() > bc.createdTime || roadsFile.lastModified() > bc.createdTime) { LOGGER.log(Level.FINER, "BuildingsOnRoadCache, found serialised object but it doesn't match the " + "data (or could have different modification dates), will create a new cache."); } else { // Have found a useable serialised cache. Now use the cached // list of id's to construct a // new cache of buildings and roads. // First need to buld list of existing roads and buildings Hashtable<String, Road> allRoads = new Hashtable<String, Road>(); for (Road r : roadEnv.getAllObjects()) allRoads.put(r.getIdentifier(), r); Hashtable<String, IAgent> allBuildings = new Hashtable<String, IAgent>(); for (IAgent b : buildingEnv.getAllObjects()) allBuildings.put(b.getIdentifier(), b); // Now create the new cache theCache = new Hashtable<Road, ArrayList<IAgent>>(); for (String roadId : bc.referenceCache.keySet()) { ArrayList<IAgent> buildings = new ArrayList<IAgent>(); for (String buildingId : bc.referenceCache.get(roadId)) { buildings.add(allBuildings.get(buildingId)); } theCache.put(allRoads.get(roadId), buildings); } LOGGER.log(Level.FINER, "BuildingsOnRoadCache, found serialised cache, returning it (in " + 0.000001 * (System.nanoTime() - time) + "ms)"); return bc; } } catch (IOException ex) { if (serialisedLoc.exists()) serialisedLoc.delete(); // delete to stop problems loading incomplete file next tinme throw ex; } catch (ClassNotFoundException ex) { if (serialisedLoc.exists()) serialisedLoc.delete(); throw ex; } } // No serialised object, or got an error when opening it, just create a // new one return new BuildingsOnRoadCache(buildingEnv, buildingsFile, roadEnv, roadsFile, serialisedLoc, geomFac); }
From source file:influent.server.clustering.EntityClustererTest.java
@SuppressWarnings("unused") private FL_Cluster createClusterSummary(String name, Hashtable<String, Double> locationDist, Hashtable<String, Double> typeDist, int count, int indegree, int outdegree) { List<FL_Property> props = new ArrayList<FL_Property>(); props.add(new PropertyHelper("inflowing", "inflowing", indegree, Arrays.asList(FL_PropertyTag.INFLOWING, FL_PropertyTag.AMOUNT, FL_PropertyTag.USD))); props.add(new PropertyHelper("outflowing", "outflowing", outdegree, Arrays.asList(FL_PropertyTag.OUTFLOWING, FL_PropertyTag.AMOUNT, FL_PropertyTag.USD))); props.add(new PropertyHelper("count", "count", count, FL_PropertyType.INTEGER, FL_PropertyTag.STAT)); // create location dist prop List<FL_Frequency> freqs = new ArrayList<FL_Frequency>(); for (String cc : locationDist.keySet()) { FL_GeoData geo = FL_GeoData.newBuilder().setText(null).setLat(null).setLon(null).setCc(cc).build(); double freq = locationDist.get(cc); freqs.add(FL_Frequency.newBuilder().setRange(geo).setFrequency(freq).build()); }/*w ww . jav a 2 s . c om*/ FL_DistributionRange range = FL_DistributionRange.newBuilder().setDistribution(freqs) .setRangeType(FL_RangeType.DISTRIBUTION).setType(FL_PropertyType.GEO).setIsProbability(false) .build(); props.add(FL_Property.newBuilder().setKey("location-dist").setFriendlyText("location-dist").setRange(range) .setProvenance(null).setUncertainty(null).setTags(Arrays.asList(FL_PropertyTag.GEO)).build()); // create type dist prop freqs = new ArrayList<FL_Frequency>(); for (String type : typeDist.keySet()) { double freq = typeDist.get(type); freqs.add(FL_Frequency.newBuilder().setRange(type).setFrequency(freq).build()); } range = FL_DistributionRange.newBuilder().setDistribution(freqs).setRangeType(FL_RangeType.DISTRIBUTION) .setType(FL_PropertyType.STRING).setIsProbability(false).build(); props.add(FL_Property.newBuilder().setKey("type-dist").setFriendlyText("type-dist").setRange(range) .setProvenance(null).setUncertainty(null).setTags(Arrays.asList(FL_PropertyTag.TYPE)).build()); return new ClusterHelper( InfluentId.fromNativeId(InfluentId.CLUSTER_SUMMARY, "cluster", name).getInfluentId(), name, Arrays.asList(FL_EntityTag.CLUSTER_SUMMARY), props, new ArrayList<String>(0), new ArrayList<String>(0), null, null, -1); }
From source file:ffx.ui.KeywordPanel.java
/** * Store the KeywordPanel's current keyword content in the activeSystem. */// ww w. j a va 2 s . c o m public void storeActive() { synchronized (this) { if (currentSystem == null) { return; } // No changes if (!KeywordComponent.isKeywordModified()) { return; } Hashtable<String, Keyword> currentKeys = currentSystem.getKeywords(); Hashtable<String, Keyword> newKeys = new Hashtable<String, Keyword>(); for (KeywordComponent kc : keywordHashMap.values()) { if (kc.isActive() == true) { Keyword keywordData = null; if (currentKeys != null) { keywordData = currentKeys.get(kc.getKeyword()); } if (keywordData == null) { keywordData = new Keyword(kc.getKeyword()); } else { keywordData.clear(); } kc.getKeywordData(keywordData); newKeys.put(kc.getKeyword(), keywordData); } } Keyword comments = new Keyword("COMMENTS", commentStringBuffer.toString()); newKeys.put("COMMENTS", comments); currentSystem.setKeywords(newKeys); } }
From source file:edu.eurac.commul.pepperModules.mmax2.MMAX22SaltMapper.java
private int[] getStartAndEnd(String BaseDataUnitId, Hashtable<String, int[]> indicesTokens) { if ((indicesTokens.containsKey(BaseDataUnitId)) && (indicesTokens.containsKey(BaseDataUnitId))) { Integer start = indicesTokens.get(BaseDataUnitId)[0]; Integer end = indicesTokens.get(BaseDataUnitId)[1]; int[] result = { start, end }; return (result); } else {/*from w ww. ja v a 2 s. c o m*/ if (!indicesTokens.containsKey(BaseDataUnitId)) throw new PepperModuleDataException(this, "An error in data was found: Cannot find start offset of base data unit '" + BaseDataUnitId + "'."); if (!indicesTokens.containsKey(BaseDataUnitId)) throw new PepperModuleDataException(this, "An error in data was found: Cannot find end offset of base data unit '" + BaseDataUnitId + "'."); return (null); } }
From source file:com.fiorano.openesb.application.aps.ApplicationHeader.java
/** * Sets all the fieldValues of this <code>ApplicationHeader</code> object * from the XML using STAX parser.//from w ww . j a v a 2s . com */ public void populate(FioranoStaxParser cursor) throws XMLStreamException, FioranoException { //Set cursor to the current DMI element. You can use either markCursor/getNextElement(<element>) API. if (cursor.markCursor(APSConstants.APPLICATION_HEADER)) { // Get Attributes. This MUST be done before accessing any data of element. Hashtable attributes = cursor.getAttributes(); if (attributes != null && attributes.containsKey(APSConstants.ATTR_IS_SUBGRAPHABLE)) { boolean canSub = XMLUtils .getStringAsBoolean((String) attributes.get(APSConstants.ATTR_IS_SUBGRAPHABLE)); setCanBeSubGraphed(canSub); } if (attributes != null && attributes.containsKey(APSConstants.ATTR_SCOPE)) { String scope = (String) attributes.get(APSConstants.ATTR_SCOPE); setScope(scope); } //Get associated Data //String nodeVal = cursor.getText(); // Get Child Elements while (cursor.nextElement()) { String nodeName = cursor.getLocalName(); // Get Attributes attributes = cursor.getAttributes(); //String nodeValue = cursor.getText(); //if (nodeValue == null) // continue; if (nodeName.equalsIgnoreCase("Name")) { String nodeValue = cursor.getText(); setApplicationName(nodeValue); } else if (nodeName.equalsIgnoreCase("ApplicationGUID")) { String nodeValue = cursor.getText(); setApplicationGUID(nodeValue); } else if (nodeName.equalsIgnoreCase("Author")) { String nodeValue = cursor.getText(); addAuthor(nodeValue); } else if (nodeName.equalsIgnoreCase("CreationDate")) { String nodeValue = cursor.getText(); setCreationDate(nodeValue); } else if (nodeName.equalsIgnoreCase("Icon")) { String nodeValue = cursor.getText(); setIcon(nodeValue); } else if (nodeName.equalsIgnoreCase("Version")) { String nodeValue = cursor.getText(); if (attributes != null) { boolean isLocked = XMLUtils.getStringAsBoolean((String) attributes.get("isLocked")); setIsVersionLocked(isLocked); setVersionNumber(nodeValue); } } else if (nodeName.equalsIgnoreCase("Label")) { m_strProfile = cursor.getText(); } else if (nodeName.equalsIgnoreCase("CompatibleWith")) { String nodeValue = cursor.getText(); addCompatibleWith(nodeValue); } else if (nodeName.equalsIgnoreCase("Category")) { String nodeValue = cursor.getText(); setCategoryIn(nodeValue); } else if (nodeName.equalsIgnoreCase("LongDescription")) { String nodeValue = cursor.getText(); setLongDescription(nodeValue); } else if (nodeName.equalsIgnoreCase("ShortDescription")) { String nodeValue = cursor.getText(); setShortDescription(nodeValue); } // LOOK AT THIS. SHOULD PASS THIS TO BE HANDLED BY PARAM DMI else if (nodeName.equalsIgnoreCase("Param")) { String nodeValue = cursor.getText(); Param param = new Param(); param.setParamName((String) attributes.get(APSConstants.PARAM_NAME)); param.setParamValue(nodeValue); //changed by Sandeep M /* param.setFieldValues(cursor); */ /* String name = (String)attributes.get("name"); param.setParamValue(nodeValue); param.populate(cursor); */ m_params.add(param); } else if (nodeName.equalsIgnoreCase("ApplicationContext")) { m_appContext = new ApplicationContext(); m_appContext.setFieldValues(cursor); } } validate(); } else throw new FioranoException(DmiErrorCodes.ERR_INVALID_ARGUMENT_ERROR); }
From source file:com.flexoodb.engines.FlexJAXBMappedDBDataEngine.java
private void updatePreparedStatement(String tablename, Hashtable<String, Object[]> fieldswithcontent, PreparedStatement ps) throws Exception { Enumeration en = fieldswithcontent.keys(); int i = 0;//from w ww . j a v a 2s. c o m while (en.hasMoreElements()) { i++; try { String field = (String) en.nextElement(); Object[] o2 = fieldswithcontent.get(field); String type = (String) o2[0]; Object o = o2[1]; //System.out.println(field+" "+type+" "+o); if (type.equals("string")) { ps.setString(i, (String) o); } else if (type.equals("byte[]") || type.equals("base64Binary")) { ps.setBinaryStream(i, new ByteArrayInputStream((byte[]) o)); } else if (type.equals("dateTime")) { XMLGregorianCalendar cal = (XMLGregorianCalendar) o; Date d = null; if (cal.toString().indexOf("0003-11-30") > -1) { ps.setString(i, "0000-00-00 00:00:00"); } else { d = (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S")).parse(cal.toString()); ps.setTimestamp(i, new java.sql.Timestamp(d.getTime())); } } else if (type.equals("date")) { XMLGregorianCalendar cal = (XMLGregorianCalendar) o; Date d1 = (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S")).parse(cal.toString()); ps.setDate(i, java.sql.Date.valueOf(new SimpleDateFormat("yyyy-MM-dd").format(d1))); } else if (type.equals("time")) { XMLGregorianCalendar cal = (XMLGregorianCalendar) o; String c = cal.toString(); c = c.replaceFirst("0003-11-30", "0000-00-00"); Date d1 = (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S")).parse(c); ps.setTime(i, new java.sql.Time(d1.getTime())); } else if (type.equals("integer")) { ps.setInt(i, ((BigInteger) o).intValue()); } else if (type.equals("double")) { ps.setDouble(i, (Double) o); } else if (type.equals("float")) { ps.setFloat(i, (Float) o); } else if (type.equals("long")) { ps.setLong(i, (Long) o); } else { throw new Exception("unknown type [" + type + "] for field [" + field + "] encountered while trying to update table [" + tablename + "]."); } } catch (Exception e) { e.printStackTrace(); throw e; } } }