List of usage examples for java.util Hashtable size
public synchronized int size()
From source file:com.swiftcorp.portal.question.web.QuestionDispatchAction.java
public ActionForward addQuestionnaireSerial(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws SystemException, BusinessRuleViolationException, Exception { log.info("addQuestionnaire() : Enter"); Hashtable ht = new Hashtable(); String[] questionIds = null;//from w w w. j a v a 2 s. c om String questionId = ""; String questionSerial = ""; String questionCompIds = ""; String numberOfQuestion = ""; String questionnaireStatus = ""; long questionnaireStatusId = -1; java.util.Date today = new java.util.Date(); java.sql.Timestamp ts1 = new java.sql.Timestamp(today.getTime()); int noOfQuestion = 0; int serial = -1; int prevSerial = 0; HttpSession session = request.getSession(); List questionListToAdd = new ArrayList(); List<QuestionDTO> questionList = (List<QuestionDTO>) session.getAttribute(SESSION_KEYS.QUESTION_LIST); questionnaireStatus = request.getParameter("questionnaireStatus.componentId"); numberOfQuestion = request.getParameter("numberOfQuestion"); questionCompIds = request.getParameter("questionCompIds"); // get number of question if (numberOfQuestion != null && !numberOfQuestion.equals("null") && numberOfQuestion.length() > 0) { numberOfQuestion = numberOfQuestion.replaceAll(" ", ""); noOfQuestion = Integer.parseInt(numberOfQuestion); } // get question ids if (questionCompIds != null && !questionCompIds.equals("null") && questionCompIds.length() > 0) { questionIds = questionCompIds.split(","); } for (int i = 0; questionIds != null && i < questionIds.length; i++) { questionSerial = request.getParameter("questionnaireSerial_" + questionIds[i]); if (questionSerial != null && !questionSerial.equals("null") && questionSerial.length() > 0) { ht.put(questionSerial, "" + questionIds[i]); } } for (int k = 0; ht != null && k < ht.size(); k++) { questionId = (String) ht.get("" + k); for (int i = 0; questionList != null && i < questionList.size(); i++) { QuestionDTO qDTO = (QuestionDTO) questionList.get(i); if (questionId.equals("" + qDTO.getComponentId())) { for (int j = 0; j < noOfQuestion; j++) { if (("" + questionIds[j]).equals("" + qDTO.getComponentId())) { questionListToAdd.add(questionList.get(i)); } } } } } DynaValidatorActionForm questionnaireForm = (DynaValidatorActionForm) form; QuestionnaireDTO questionnaireDTO = (QuestionnaireDTO) questionnaireForm.get("questionnaire"); if (questionnaireStatus != null && !questionnaireStatus.equals("null") && questionnaireStatus.length() > 0) { questionnaireStatusId = Long.parseLong(questionnaireStatus); } String questionnaireId = request.getParameter("questionnaire.questionnaireId"); questionnaireDTO.setQuestionnaireId("" + questionnaireId); // get questionnaire status QuestionnaireStatusDTO questionnaireStatusDTO = (QuestionnaireStatusDTO) questionService .getQuestionnaireStatus(questionnaireStatusId); questionnaireDTO.setQuestionnaireStatus(questionnaireStatusDTO); questionnaireDTO.setQuestionList(questionListToAdd); questionnaireDTO.setQuestionnaireTimestamp("" + ts1); QuestionDTO qdto = new QuestionDTO(); String[][] messageArgValues = { { questionnaireDTO.getQuestionnaireName() } }; try { questionService.addQuestionnaire(questionnaireDTO); } catch (Exception e) { log.info("questionnaireAdd() : ", e); throw e; } WebUtils.setSuccessMessages(request, MessageKeys.ADD_SUCCESS_MESSAGE_KEYS, messageArgValues); log.info("addQuestionnaire() : Exit"); // forward to search return promptQuestionnaireSearchSystemLevel(mapping, form, request, response); }
From source file:com.swiftcorp.portal.question.web.QuestionDispatchAction.java
public ActionForward modifyQuestionnaireSerial(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws SystemException, BusinessRuleViolationException, Exception { log.info("modifyQuestionnaire() : Enter"); Hashtable ht = new Hashtable(); String[] questionIds = null;//from w ww.java2 s . c o m String questionId = ""; String questionSerial = ""; String questionCompIds = ""; String numberOfQuestion = ""; String questionnaireStatus = ""; long questionnaireStatusId = -1; java.util.Date today = new java.util.Date(); java.sql.Timestamp ts1 = new java.sql.Timestamp(today.getTime()); int noOfQuestion = 0; int serial = -1; int prevSerial = 0; HttpSession session = request.getSession(); List questionListToAdd = new ArrayList(); List<QuestionDTO> questionList = (List<QuestionDTO>) session.getAttribute(SESSION_KEYS.QUESTION_LIST); questionnaireStatus = request.getParameter("questionnaireStatus.componentId"); numberOfQuestion = request.getParameter("numberOfQuestion"); questionCompIds = request.getParameter("questionCompIds"); // get number of question in this questionnaire if (numberOfQuestion != null && !numberOfQuestion.equals("null") && numberOfQuestion.length() > 0) { numberOfQuestion = numberOfQuestion.replaceAll(" ", ""); noOfQuestion = Integer.parseInt(numberOfQuestion); } // get question ids if (questionCompIds != null && !questionCompIds.equals("null") && questionCompIds.length() > 0) { questionIds = questionCompIds.split(","); } for (int i = 0; questionIds != null && i < questionIds.length; i++) { questionSerial = request.getParameter("questionnaireSerial_" + questionIds[i]); if (questionSerial != null && !questionSerial.equals("null") && questionSerial.length() > 0) { ht.put(questionSerial, "" + questionIds[i]); } } for (int k = 0; ht != null && k < ht.size(); k++) { questionId = (String) ht.get("" + k); for (int i = 0; questionList != null && i < questionList.size(); i++) { QuestionDTO qDTO = (QuestionDTO) questionList.get(i); if (questionId.equals("" + qDTO.getComponentId())) { for (int j = 0; j < noOfQuestion; j++) { if (("" + questionIds[j]).equals("" + qDTO.getComponentId())) { questionListToAdd.add(questionList.get(i)); } } } } } DynaValidatorActionForm questionnaireForm = (DynaValidatorActionForm) form; QuestionnaireDTO questionnaireDTOUpdate = (QuestionnaireDTO) request.getSession() .getAttribute(SESSION_KEYS.QUESTIONNAIRE_TO_MODIFY); QuestionnaireDTO questionnaireDTO = (QuestionnaireDTO) questionnaireForm.get("questionnaire"); // questionnaireDTO.setQuestionnaireStatus(questionnaireStatus); if (questionnaireStatus != null && !questionnaireStatus.equals("null") && questionnaireStatus.length() > 0) { questionnaireStatusId = Long.parseLong(questionnaireStatus); } // get questionnaireStatus QuestionnaireStatusDTO questionnaireStatusDTO = (QuestionnaireStatusDTO) questionService .getQuestionnaireStatus(questionnaireStatusId); questionnaireDTO.setQuestionnaireStatus(questionnaireStatusDTO); questionnaireDTO.setQuestionList(questionListToAdd); String questionnaireId = request.getParameter("questionnaire.questionnaireId"); questionnaireDTO.setQuestionnaireId("" + questionnaireId); questionnaireDTO.setQuestionnaireTimestamp("" + ts1); QuestionDTO qdto = new QuestionDTO(); String[][] messageArgValues = { { questionnaireDTO.getQuestionnaireName() } }; try { questionService.modifyQuestionnaire(questionnaireDTO); } catch (Exception e) { log.info("modifyQuestionnaire() : ", e); throw e; } WebUtils.setSuccessMessages(request, MessageKeys.MODIFY_SUCCESS_MESSAGE_KEYS, messageArgValues); // checged here to forward to question serial // return promptQuestionnaireSerialList (mapping, form, request, // response); return promptQuestionnaireSearchSystemLevel(mapping, form, request, response); }
From source file:edu.ku.brc.af.ui.weblink.WebLinkButton.java
/** * @param forToolTip creating it to just set into tooltip * @param skipPrompt if true do not show the prompt * @return/*ww w . j a v a2 s .co m*/ */ @SuppressWarnings("null") protected String buildURL(final boolean forToolTip, final boolean skipPrompt) { if (webLinkDef != null) { // Start by getting the data needed to build the URL // so first see if we need to prompt for data. valueHash.clear(); int promptCnt = 0; Vector<String> missingList = null; // List of missing args Hashtable<String, String> backupPrompt = null; for (WebLinkDefArg arg : webLinkDef.getArgs()) { String name = arg.getName(); String value = ""; //$NON-NLS-1$ if (provider != null) { value = provider.getWebLinkData(name); } else if (dataObj instanceof FormDataObjIFace) { Object dataVal = FormHelper.getValue((FormDataObjIFace) dataObj, name); if (dataVal != null) { value = dataVal.toString(); } else { if (backupPrompt == null) backupPrompt = new Hashtable<String, String>(); backupPrompt.put(name, arg.getTitle() == null ? arg.getName() : arg.getTitle()); promptCnt++; } } else if (dataObj instanceof String && textField != null && arg.getName().equals("this")) { value = (String) dataObj; } else { promptCnt++; continue; } String textFieldValue = null; if (textField != null) { textFieldValue = textField.getText(); } if (StringUtils.isNotEmpty(value)) { if (StringUtils.isNotEmpty(textFieldValue) && !textFieldValue.equals(value)) { value = textFieldValue; } valueHash.put(name, value); } else if (StringUtils.isNotEmpty(textFieldValue)) { valueHash.put(name, textFieldValue); } else if (!arg.isPrompt()) { if (missingList == null) missingList = new Vector<String>(); missingList.add(name); } else { promptCnt++; //valueHash.put(arg.getName(), "??"); } } if (!forToolTip && !skipPrompt && promptCnt > 0) { if (promptCnt > 0 || (backupPrompt != null && backupPrompt.size() > 0)) { promptDialog = createPromptDlg(backupPrompt); promptDialog.setVisible(true); if (!promptDialog.isCancelled()) { for (String key : textFieldHash.keySet()) { valueHash.put(key, textFieldHash.get(key).getText()); } } else { return null; } promptDialog.dispose(); promptDialog = null; } } byte[] chars = webLinkDef.getBaseURLStr().getBytes(); int i = 0; for (byte b : webLinkDef.getBaseURLStr().getBytes()) { if (b == '<' || b == '>') { chars[i] = '\''; } i++; } String url = new String(chars); for (String key : valueHash.keySet()) { String val = valueHash.get(key); if (val.equals("this")) { val = valueHash.get("this"); } /*try { byte[] badChars = new byte[] {45}; for (byte j : badChars) { String str = "%" + Integer.toHexString(j); String with = ""+(char)j; boolean doSub = true; while (doSub) { if (val.indexOf(str) > -1) { val = StringUtils.replace(val, str, with); doSub = true; } else { doSub = false; } } } //val = URLEncoder.encode(val, "UTF-8"); //val = URLEncoder.encode(val, "ISO-8859-1"); url = StringUtils.replace(url, "'"+key+"'", (val != null ? val : "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //url = URLEncoder.encode(url, "ISO-8859-1"); //System.out.println("|"+key+"|"+url); } catch (Exception ex) {} */ //System.out.println("|"+key+"|"+url); // http://darwin2.nhm.ku.edu/ksem/collectionlabelimages/PL.Dylewska1964.05.20%20001.JPG url = StringUtils.replace(url, "'" + key + "'", (val != null ? val : "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } url = StringUtils.replace(url, "AMP", "&"); //$NON-NLS-2$ return url; } if (textField != null) { return textField.getText(); } return null; }
From source file:axiom.objectmodel.db.NodeManager.java
/** * Updates a modified node in the embedded db or an external relational database, depending * on its database mapping./*from ww w . jav a 2s. c o m*/ * * @return true if the DbMapping of the updated Node is to be marked as updated via * DbMapping.setLastDataChange */ public boolean updateNode(IDatabase db, ITransaction txn, Node node) throws IOException, SQLException, ClassNotFoundException { // Transactor tx = (Transactor) Thread.currentThread (); // tx.timer.beginEvent ("updateNode "+node); invokeOnPersist(node); DbMapping dbm = node.getDbMapping(); boolean markMappingAsUpdated = false; if ((dbm == null) || !dbm.isRelational()) { String className = dbm.getClassName(); IDatabase idb = null; if (className != null) { idb = (IDatabase) this.dbs.get(className); } if (idb == null) { idb = db; } idb.updateNode(txn, node.getID(), node); } else { Hashtable propMap = node.getPropMap(); Property[] props; if (propMap == null) { props = new Property[0]; } else { props = new Property[propMap.size()]; propMap.values().toArray(props); } // make sure table meta info is loaded by dbmapping dbm.getColumns(); StringBuffer b = dbm.getUpdate(); // comma flag set after the first dirty column, also tells as // if there are dirty columns at all boolean comma = false; for (int i = 0; i < props.length; i++) { // skip clean properties if ((props[i] == null) || !props[i].dirty) { // null out clean property so we don't consider it later props[i] = null; continue; } Relation rel = dbm.propertyToRelation(props[i].getName()); // skip readonly, virtual and collection relations if ((rel == null) || rel.readonly || rel.virtual || ((rel.reftype != Relation.REFERENCE) && (rel.reftype != Relation.PRIMITIVE))) { // null out property so we don't consider it later props[i] = null; continue; } if (comma) { b.append(", "); } else { comma = true; } b.append(rel.getDbField()); b.append(" = ?"); } // if no columns were updated, return false if (!comma) { return false; } b.append(" WHERE "); //b.append(dbm.getTableName(0)); //b.append("."); b.append(dbm.getIDField()); b.append(" = "); if (dbm.needsQuotes(dbm.getIDField())) { b.append("'"); b.append(escape(node.getID())); b.append("'"); } else { b.append(node.getID()); } b.append(dbm.getTableJoinClause(0)); Connection con = dbm.getConnection(); // set connection to write mode if (con.isReadOnly()) con.setReadOnly(false); PreparedStatement stmt = con.prepareStatement(b.toString()); int stmtNumber = 0; long logTimeStart = logSql ? System.currentTimeMillis() : 0; try { for (int i = 0; i < props.length; i++) { Property p = props[i]; if (p == null) { continue; } Relation rel = dbm.propertyToRelation(p.getName()); stmtNumber++; this.setStatementValues(stmt, stmtNumber, p, rel.getColumnType()); p.dirty = false; if (!rel.isPrivate()) { markMappingAsUpdated = true; } } stmt.executeUpdate(); } finally { if (logSql) { long logTimeStop = System.currentTimeMillis(); logSqlStatement("SQL UPDATE", dbm.getTableName(), logTimeStart, logTimeStop, b.toString()); } if (stmt != null) { try { stmt.close(); } catch (Exception ignore) { app.logEvent(ignore.getMessage()); } } } } // update may cause changes in the node's parent subnode array // TODO: is this really needed anymore? if (markMappingAsUpdated && node.isAnonymous()) { Node parent = node.getCachedParent(); if (parent != null) { parent.setLastSubnodeChange(System.currentTimeMillis()); } } return markMappingAsUpdated; }
From source file:org.accada.reader.rprm.core.Source.java
/** * Checks if a tag is relevant (dependant of the TagSelectors). * @param tagId// w w w. j av a 2 s. co m * The tag to check * @param allTagSelectors * The TagSelectors * @param closure * The reader and its readpoints * @return Returns 'true' if the tag is relevant, 'false' otherwise * @throws ReaderProtocolException * "ERROR_UNKNOWN" */ protected boolean isRelevantTag(final String tagId, final Hashtable allTagSelectors, final Vector closure) throws ReaderProtocolException { Hashtable tagSelectors = new Hashtable(); if (allTagSelectors.size() == 0) { try { tagSelectors.put(readerDevice.getTagSelector("defaultTagSelector").getName(), readerDevice.getTagSelector("defaultTagSelector")); } catch (ReaderProtocolException e) { throw new ReaderProtocolException("ERROR_UNKNOWN", MessagingConstants.ERROR_UNKNOWN); } } else { tagSelectors = allTagSelectors; } // indicates if tag is relevant boolean relevantInc = false; boolean relevantExc = false; // special case, if zero inclusive/exclusive patterns are defined boolean moreThanZeroIncs = false; boolean moreThanZeroExcs = false; // tag selectors Enumeration tagSelectorIterator = tagSelectors.elements(); TagSelector curTagSelector; String tagValue = ""; while (tagSelectorIterator.hasMoreElements()) { curTagSelector = (TagSelector) tagSelectorIterator.nextElement(); if (curTagSelector.getTagField().getMemoryBank() == 2) { // id tagValue = tagId; } else { // tagField tagValue = readTagField(tagId, closure, curTagSelector.getTagField()); } // check value if (curTagSelector.validate(tagValue) && curTagSelector.getInclusiveFlag()) { // inlusive // relevant, the tag should be reported relevantInc = true; } else if (!curTagSelector.validate(tagValue) && !curTagSelector.getInclusiveFlag()) { // exclusive // relevant, the tag should be reported relevantExc = true; } if (curTagSelector.getInclusiveFlag()) { moreThanZeroIncs = true; } if (!curTagSelector.getInclusiveFlag()) { moreThanZeroExcs = true; } } // return true if tag is relevant if (relevantInc && relevantExc) { return true; } else if (!moreThanZeroIncs && relevantExc) { return true; } else if (!moreThanZeroExcs && relevantInc) { return true; } return false; }
From source file:net.sourceforge.squirrel_sql.fw.dialects.DialectUtils.java
/** * Get a list of statements needed to create indexes for the specified table * //from w ww. j a v a 2 s. c o m * @param ti * @param md * @param primaryKeys * can be null * @param prefs * @return */ public static List<String> createIndexes(ITableInfo ti, String destSimpleTableName, String destSchema, ISQLDatabaseMetaData md, List<PrimaryKeyInfo> primaryKeys, CreateScriptPreferences prefs) { if (ti == null) { throw new IllegalArgumentException("ti cannot be null"); } if (md == null) { throw new IllegalArgumentException("md cannot be null"); } final List<String> result = new ArrayList<String>(); if (ti.getDatabaseObjectType() == DatabaseObjectType.VIEW) { return result; } final List<IndexColInfo> pkCols = new ArrayList<IndexColInfo>(); if (primaryKeys != null) { for (final PrimaryKeyInfo pkInfo : primaryKeys) { pkCols.add(new IndexColInfo(pkInfo.getColumnName())); } Collections.sort(pkCols, IndexColInfo.NAME_COMPARATOR); } List<IndexInfo> indexInfos = null; try { indexInfos = md.getIndexInfo(ti); } catch (final SQLException e) { // i18n[DialectUtils.error.getprimarykey=Unable to get primary key // info for table {0}] final String msg = s_stringMgr.getString("DialectUtils.error.getprimarykey", ti.getSimpleName()); log.error(msg, e); return result; } // Group all columns by index final Hashtable<String, TableIndexInfo> buf = new Hashtable<String, TableIndexInfo>(); for (final IndexInfo indexInfo : indexInfos) { final String indexName = indexInfo.getSimpleName(); if (StringUtils.isEmpty(indexName)) { continue; } final String columnName = indexInfo.getColumnName(); if (StringUtils.isEmpty(columnName)) { continue; } final TableIndexInfo ixi = buf.get(indexName); if (null == ixi) { final List<IndexColInfo> ixCols = new ArrayList<IndexColInfo>(); ixCols.add(new IndexColInfo(columnName, indexInfo.getOrdinalPosition())); buf.put(indexName, new TableIndexInfo(indexInfo.getTableName(), indexInfo.getSchemaName(), indexName, ixCols, !indexInfo.isNonUnique())); } else { ixi.cols.add(new IndexColInfo(indexInfo.getColumnName(), indexInfo.getOrdinalPosition())); } } final TableIndexInfo[] ixs = buf.values().toArray(new TableIndexInfo[buf.size()]); for (final TableIndexInfo ix : ixs) { Collections.sort(ix.cols, IndexColInfo.NAME_COMPARATOR); if (pkCols.equals(ix.cols)) { // Serveral DBs automatically create an index for primary key // fields // and return this index in getIndexInfo(). We remove this index // from the script // because it would break the script with an index already // exists error. continue; } Collections.sort(ix.cols, IndexColInfo.ORDINAL_POSITION_COMPARATOR); final StringBuilder indexSQL = new StringBuilder(); indexSQL.append("CREATE"); indexSQL.append(ix.unique ? " UNIQUE " : " "); indexSQL.append("INDEX "); indexSQL.append(ix.ixName); indexSQL.append(" ON "); indexSQL.append(formatQualifIntern(destSimpleTableName, destSchema, prefs)); if (ix.cols.size() == 1) { indexSQL.append("(").append(ix.cols.get(0)); for (int j = 1; j < ix.cols.size(); j++) { indexSQL.append(",").append(ix.cols.get(j)); } } else { indexSQL.append("\n(\n"); for (int j = 0; j < ix.cols.size(); j++) { indexSQL.append(" "); indexSQL.append(ix.cols.get(j)); if (j < ix.cols.size() - 1) { indexSQL.append(",\n"); } else { indexSQL.append("\n"); } } } indexSQL.append(")"); result.add(indexSQL.toString()); } return result; }
From source file:org.jibble.pircbot.PircBot.java
/** * Returns an array of all users in the specified channel. * <p/>/* www. j ava 2s. co m*/ * There are some important things to note about this method:- * <ul> * <li>This method may not return a full list of users if you call it * before the complete nick list has arrived from the IRC server. * </li> * <li>If you wish to find out which users are in a channel as soon * as you join it, then you should override the onUserList method * instead of calling this method, as the onUserList method is only * called as soon as the full user list has been received. * </li> * <li>This method will return immediately, as it does not require any * interaction with the IRC server. * </li> * <li>The bot must be in a channel to be able to know which users are * in it. * </li> * </ul> * * @param channel The name of the channel to list. * @return An array of User objects. This array is empty if we are not * in the channel. * @see #onUserList(String, User[]) onUserList * @since PircBot 1.0.0 */ public final User[] getUsers(String channel) { channel = channel.toLowerCase(); User[] userArray = new User[0]; synchronized (_channels) { Hashtable users = (Hashtable) _channels.get(channel); if (users != null) { userArray = new User[users.size()]; Enumeration enumeration = users.elements(); for (int i = 0; i < userArray.length; i++) { User user = (User) enumeration.nextElement(); userArray[i] = user; } } } return userArray; }
From source file:com.crushpaper.DbLogic.java
/** * API method. Returns the children of a entry in the order specified by * their next relationships./*w ww .jav a2 s . co m*/ */ public ArrayList<Entry> getChildrenInOrder(Entry entry) { // Get all the children. final Hashtable<String, Entry> children = new Hashtable<String, Entry>(); Entry firstChild = null; for (Object objectChild : getEntriesByParentId(entry.getId())) { Entry child = (Entry) objectChild; children.put(child.getId(), child); if (!child.hasPreviousSiblingId()) { firstChild = child; } } // Put them in an order. final ArrayList<Entry> childrenInOrder = new ArrayList<Entry>(); Entry child = firstChild; for (int i = 0; i < children.size(); ++i) { if (child == null) { break; } childrenInOrder.add(child); if (!child.hasNextSiblingId()) { break; } final String nextId = child.getNextSiblingId(); child = children.get(nextId); } return childrenInOrder; }
From source file:edu.ku.brc.specify.tasks.ExpressSearchTask.java
public synchronized void exectionDone(final SQLExecutionProcessor process, final ResultSet resultSet) { if (!sqlHasResults) { try {/*from w ww .java 2s . com*/ sqlHasResults = resultSet.first(); } catch (SQLException ex) { ex.printStackTrace(); edu.ku.brc.af.core.UsageTracker.incrSQLUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ExpressSearchTask.class, ex); } } sqlProcessorList.remove(process); Object[] data = (Object[]) process.getData(); if (data != null) { if (data.length == 3) { SearchTableConfig searchTableConfig = (SearchTableConfig) data[0]; ExpressSearchResultsPaneIFace esrPane = (ExpressSearchResultsPaneIFace) data[1]; String searchTerm = (String) data[2]; Hashtable<String, ExpressResultsTableInfo> idToTableInfoHash = ExpressSearchConfigCache .getSearchIdToTableInfoHash(); Hashtable<String, List<ExpressResultsTableInfo>> joinIdToTableInfohash = ExpressSearchConfigCache .getJoinIdToTableInfoHash(); Hashtable<String, QueryForIdResultsSQL> resultsForJoinsHash = new Hashtable<String, QueryForIdResultsSQL>(); try { if (resultSet.next()) { String searchIdStr = Integer.toString(searchTableConfig.getTableInfo().getTableId()); ExpressResultsTableInfo tblInfo = idToTableInfoHash.get(searchIdStr); if (tblInfo == null) { throw new RuntimeException("Bad id from search[" + searchIdStr + "]"); } SearchConfig config = SearchConfigService.getInstance().getSearchConfig(); int cnt = 0; do { if (cnt < RESULTS_THRESHOLD) { collectResults(config, tblInfo.getTableId(), searchTerm, resultSet, null, joinIdToTableInfohash, resultsForJoinsHash); } cnt++; } while (resultSet.next()); //System.err.println("SQLExecutionProcessor: "+cnt); if (cnt >= RESULTS_THRESHOLD) { String reason = String.format( getResourceString("ExpressSearchTask.MAX_SEARCH_RESULTS_EXCEEDED"), RESULTS_THRESHOLD, cnt); if (searchWarningsResults == null) { searchWarningsResults = new SIQueryForIdResults(); searchWarningsResults.addReason(searchTableConfig, reason); displayResults(esrPane, searchWarningsResults, resultsForJoinsHash); } else { searchWarningsResults.addReason(searchTableConfig, reason); } } if (resultsForJoinsHash.size() > 0) { QueryForIdResultsSQL queryResults = new QueryForIdResultsSQL(searchIdStr, null, tblInfo, searchTableConfig.getDisplayOrder(), searchTerm); displayResults(esrPane, queryResults, resultsForJoinsHash); } } } catch (SQLException ex) { edu.ku.brc.af.core.UsageTracker.incrSQLUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ExpressSearchTask.class, ex); ex.printStackTrace(); } } } }
From source file:org.hdiv.filter.AbstractValidatorHelper.java
/** * Checks if the values of the parameters received in the request * <code>request</code> are valid. These values are valid if and only if * the noneditable parameters havent been modified.<br> * Validation process is as follows.<br> * 1. If the action to which the request is directed is an init page, then * it is a valid request.<br>//from ww w. j a v a 2 s. co m * 2. if the cookies received in the request are not found in the user * session, the validation is incorrect.<br> * 3. if the state recover process has produced an error, incorrect * validation.<br> * 4. If the action received in the request is different to the action of * the recovered state, incorrect validation.<br> * 5. If not, all the parameter values are checked and if all the received * values are valid then the request is valid. <br> * 5.1. If it is an init parameter or a HDIV parameter then it is a valid * parameter.<br> * 5.2. If the received parameter is not in the state:<br> * 5.2.1. If it has been defined by the user as a no validation required * parameter, then it is a valid parameter.<br> * 5.2.2. otherwise, it is a no valid request.<br> * 5.3. If the parameter is editable, if validations have been defined * values are checked.<br> * 5.4. If it is a noneditable parameter, all the received values are * checked. * * @param request HttpServletRequest to validate * @return True If all the parameter values of the request * <code>request</code> pass the the HDIV validation. False, * otherwise. * @throws HDIVException If the request doesn't pass the HDIV validation an * exception is thrown explaining the cause of the error. */ public boolean validate(HttpServletRequest request) { String target = this.getTarget(request); String targetWithoutContextPath = this.getTargetWithoutContextPath(request, target); // Hook before the validation Boolean pre = this.preValidate(request, target); if (pre != null) { return pre.booleanValue(); } if (this.hdivConfig.hasExtensionToExclude(target)) { log.debug("The target " + target + " has an extension to exclude from validation"); return true; } if (!this.hdivConfig.isValidationInUrlsWithoutParamsActivated()) { boolean requestHasParameters = (request.getParameterNames() != null) && (request.getParameterNames().hasMoreElements()); if (!requestHasParameters) { log.debug("The url " + request.getRequestURI() + " is not be validated because it has not got parameters"); return true; } } if (this.hdivConfig.isStartPage(targetWithoutContextPath)) { return (this.validateStartPageParameters(request, target)); } if (this.hdivConfig.isCookiesIntegrityActivated()) { if (!this.validateRequestCookies(request, target)) { return false; } } // restore state from request or from memory IState state = this.restoreState(request, target); if (state == null) { return false; } if (!this.isTheSameAction(request, target, state)) { return false; } if (!this.allRequiredParametersReceived(request, state, target)) { return false; } Hashtable unauthorizedEditableParameters = new Hashtable(); Enumeration parameters = request.getParameterNames(); while (parameters.hasMoreElements()) { String parameter = (String) parameters.nextElement(); // check if the HDIV validation must be applied to the parameter if (!this.hdivConfig.needValidation(parameter, this.hdivParameter)) { if (log.isDebugEnabled() && !parameter.equals(this.hdivParameter)) { log.debug("parameter " + parameter + " doesn't need validation"); } continue; } // if the parameter requires no validation it is considered a // valid parameter if (this.isUserDefinedNonValidationParameter(targetWithoutContextPath, parameter)) { continue; } IParameter stateParameter = state.getParameter(parameter); if (stateParameter == null) { // If the parameter is not defined in the state, it is an error. // With this verification we guarantee that no extra parameters are // added. this.logger.log(HDIVErrorCodes.PARAMETER_NOT_EXISTS, target, parameter, null); if (log.isDebugEnabled()) { log.debug("Validation Error Detected: Parameter [" + parameter + "] does not exist in the state for action [" + target + "]"); } return false; } // At this point we are processing a noneditable parameter String[] values = request.getParameterValues(parameter); // check if the parameter is editable if (stateParameter.isEditable()) { if (hdivConfig.existValidations() && (stateParameter.getEditableDataType() != null)) { this.validateEditableParameter(request, target, parameter, values, stateParameter.getEditableDataType(), unauthorizedEditableParameters); } continue; } try { if (!this.validateParameterValues(request, target, state, stateParameter, parameter, values)) { return false; } } catch (Exception e) { String errorMessage = HDIVUtil.getMessage("validation.error", e.getMessage()); throw new HDIVException(errorMessage, e); } } if (unauthorizedEditableParameters.size() > 0) { request.setAttribute(HDIVErrorCodes.EDITABLE_PARAMETER_ERROR, unauthorizedEditableParameters); } return true; }