List of usage examples for org.apache.commons.lang StringUtils isNumeric
public static boolean isNumeric(String str)
Checks if the String contains only unicode digits.
From source file:fr.paris.lutece.portal.web.user.attribute.AttributeFieldJspBean.java
/** * Move up the position of the attribute field * @param request HttpServletRequest/*from ww w . ja va 2s . c o m*/ * @return The Jsp URL of the process result */ public String doMoveUpAttributeField(HttpServletRequest request) { String strIdAttribute = request.getParameter(PARAMETER_ID_ATTRIBUTE); String strIdField = request.getParameter(PARAMETER_ID_FIELD); if (StringUtils.isNotBlank(strIdField) && StringUtils.isNumeric(strIdField) && StringUtils.isNotBlank(strIdAttribute) && StringUtils.isNumeric(strIdAttribute)) { int nIdAttribute = Integer.parseInt(strIdAttribute); int nIdField = Integer.parseInt(strIdField); IAttribute attribute = _attributeService.getAttributeWithFields(nIdAttribute, getLocale()); List<AttributeField> listAttributeFields = attribute.getListAttributeFields(); if (listAttributeFields.size() > 0) { AttributeField previousField = null; AttributeField currentField = null; Iterator<AttributeField> it = listAttributeFields.iterator(); previousField = it.next(); currentField = it.next(); while (it.hasNext() && (currentField.getIdField() != nIdField)) { previousField = currentField; currentField = it.next(); } int previousFieldPosition = previousField.getPosition(); int currentFieldPosition = currentField.getPosition(); previousField.setPosition(currentFieldPosition); currentField.setPosition(previousFieldPosition); _attributeFieldService.updateAttributeField(previousField); _attributeFieldService.updateAttributeField(currentField); } } return JSP_MODIFY_ATTRIBUTE + "?" + PARAMETER_ID_ATTRIBUTE + "=" + strIdAttribute; }
From source file:com.impetus.client.redis.RedisClientFactory.java
private JedisPoolConfig onPoolConfig(final byte WHEN_EXHAUSTED_FAIL, String maxActivePerNode, String maxIdlePerNode, String minIdlePerNode, String maxTotal) { if (!StringUtils.isBlank(maxActivePerNode) && StringUtils.isNumeric(maxActivePerNode)) { logger.info("configuring connection pool"); JedisPoolConfig poolConfig = new JedisPoolConfig(); if (maxTotal != null && StringUtils.isNumeric(maxTotal)) { poolConfig.setMaxTotal(Integer.valueOf(maxTotal)); }// w w w . j a v a 2 s. co m if (maxIdlePerNode != null && StringUtils.isNumeric(maxIdlePerNode)) { poolConfig.setMaxIdle(Integer.valueOf(maxIdlePerNode)); } if (minIdlePerNode != null && StringUtils.isNumeric(minIdlePerNode)) { poolConfig.setMinIdle(Integer.parseInt(minIdlePerNode)); } if (maxActivePerNode != null && StringUtils.isNumeric(maxActivePerNode)) { //poolConfig.setWhenExhaustedAction(WHEN_EXHAUSTED_FAIL); poolConfig.setBlockWhenExhausted(true); } return poolConfig; } return null; }
From source file:com.flexive.core.search.cmis.parser.StatementBuilder.java
protected Condition processCondition(ConditionList parent, Tree root) throws FxCmisSqlParseException { switch (root.getType()) { case CmisSqlLexer.AND: case CmisSqlLexer.OR: final ConditionList.Connective type = root.getType() == CmisSqlLexer.AND ? ConditionList.Connective.AND : ConditionList.Connective.OR; // re-use parent list to avoid nesting expressions with the same operator final ConditionList list = parent != null && parent.getConnective().equals(type) ? parent : new ConditionList(parent, type); // add nested conditions to the list for (Tree node : children(root)) { final Condition cond = processCondition(list, node); if (cond != list) { list.addCondition(cond); }/*from w w w. j av a 2 s . c om*/ } return list; case CmisSqlLexer.COMPOP: final Tree compNode = root.getChild(0); final String compOp = compNode.getText(); final ValueExpression lhs = processValueExpression(compNode.getChild(0)); return new ComparisonCondition(parent, lhs, PropertyValueComparator.forComparison(compOp), processLiteral(compNode.getChild(1), lhs instanceof ColumnReference ? (ColumnReference) lhs : null)); case CmisSqlLexer.CONTAINS: assert root.getChild(0).getType() == CmisSqlLexer.CHARLIT; // contains search expression final String qualifier = root.getChildCount() > 1 ? decodeIdent(root.getChild(1).getChild(0)) : null; final String expression = decodeCharLiteral(root.getChild(0)); if (qualifier == null && stmt.getTables().size() > 1) { throw new FxCmisSqlParseException(LOG, ErrorCause.AMBIGUOUS_CONTAINS, expression); } return new ContainsCondition(parent, qualifier != null ? stmt.getTable(qualifier) : stmt.getTables().get(0), qualifier, expression); case CmisSqlLexer.LIKE: return new LikeCondition(parent, decodeColumnReference(getFirstChildWithType(root, CmisSqlLexer.CREF), false), decodeCharLiteral(getFirstChildWithType(root, CmisSqlLexer.CHARLIT)), getFirstChildWithType(root, CmisSqlLexer.NOT) != null); case CmisSqlLexer.IN: final Tree inCref = getFirstChildWithType(root, CmisSqlLexer.CREF); final ColumnReference inColumnReference = decodeColumnReference(inCref, false); final List<Literal> inValues = new ArrayList<Literal>(root.getChildCount() - 1); for (int i = inCref.getChildIndex() + 1; i < root.getChildCount(); i++) { inValues.add(processLiteral(root.getChild(i), inColumnReference)); } return new InCondition(parent, inColumnReference, inValues, getFirstChildWithType(root, CmisSqlLexer.NOT) != null); case CmisSqlLexer.NULL: return new NullCondition(parent, decodeColumnReference(getFirstChildWithType(root, CmisSqlLexer.CREF), false), getFirstChildWithType(root, CmisSqlLexer.NOT) != null); case CmisSqlLexer.IN_FOLDER: case CmisSqlLexer.IN_TREE: // optional table qualifier final TableReference folderQualifier = root.getChildCount() > 1 ? stmt.getTable(decodeIdent(root.getChild(1).getChild(0))) : null; if (folderQualifier == null && stmt.getTableCount() > 1) { // table must be specified for JOINs throw new FxCmisSqlParseException(LOG, ErrorCause.AMBIGUOUS_TABLE_REF, (root.getType() == CmisSqlLexer.IN_FOLDER ? "IN_FOLDER" : "IN_TREE")); } final TableReference sourceTable = folderQualifier == null ? stmt.getTables().get(0) : folderQualifier; // find folder - TODO: Edit/Live tree selection? final String folderIdent = decodeCharLiteral(root.getChild(0)); final long folderId; try { if (StringUtils.isNumeric(folderIdent)) { // folder ID as used by the CMIS interfaces folderId = Long.parseLong(folderIdent); // check if the folder is actually valid treeStorage.getTreeNodeInfo(con, FxTreeMode.Edit, folderId); } else if (folderIdent != null && folderIdent.startsWith("/")) { // lookup folder path folderId = treeStorage.getIdByFQNPath(con, FxTreeMode.Edit, FxTreeNode.ROOT_NODE, folderIdent); if (folderId == -1) { throw new FxCmisSqlParseException(LOG, ErrorCause.INVALID_NODE_PATH, folderIdent); } } else { throw new IllegalArgumentException("No folder ID or path for tree condition"); } return root.getType() == CmisSqlLexer.IN_FOLDER // IN_FOLDER ? new FolderCondition(parent, sourceTable, folderId) // IN_TREE (needs node info for bounds checks) : new TreeCondition(parent, sourceTable, treeStorage.getTreeNodeInfo(con, FxTreeMode.Edit, folderId)); } catch (FxApplicationException e) { throw new FxCmisSqlParseException(LOG, e); } default: throw new UnsupportedOperationException("Unsupported condition: " + root.toStringTree()); } }
From source file:edu.ku.brc.af.core.db.DBTableIdMgr.java
/** * Reads in datamodel input file and populates the Hashtable of the DBTableMgr with DBTableInfo * @param inputFile the input file.//w ww .j a va 2 s . co m */ public void initialize(final File inputFile) { log.debug( "Reading in datamodel file: " + inputFile.getAbsolutePath() + " to create and populate DBTableMgr"); //$NON-NLS-1$ //$NON-NLS-2$ String classname = null; try { SAXReader reader = new SAXReader(); reader.setValidation(false); Element databaseNode = XMLHelper.readFileToDOM4J(inputFile); if (databaseNode != null) { for (Iterator<?> i = databaseNode.elementIterator("table"); i.hasNext();) //$NON-NLS-1$ { Element tableNode = (Element) i.next(); classname = tableNode.attributeValue("classname"); //$NON-NLS-1$ String tablename = tableNode.attributeValue("table"); //$NON-NLS-1$ int tableId = Integer.parseInt(tableNode.attributeValue("tableid")); //$NON-NLS-1$ boolean isSearchable = XMLHelper.getAttr(tableNode, "searchable", false); //$NON-NLS-1$ String primaryKeyField = null; // iterate through child elements of id nodes, there should only be 1 for (Iterator<?> i2 = tableNode.elementIterator("id"); i2.hasNext();) //$NON-NLS-1$ { Element idNode = (Element) i2.next(); primaryKeyField = idNode.attributeValue("name"); //$NON-NLS-1$ } if (classname == null) { log.error("classname is null; check input file"); //$NON-NLS-1$ } if (tablename == null) { log.error("tablename is null; check input file"); //$NON-NLS-1$ } if (isFullSchema && primaryKeyField == null) { log.error("primaryKeyField is null; check input file table[" + tablename + "]"); //$NON-NLS-1$ //$NON-NLS-2$ } //log.debug("Populating hashtable ID["+tableId+"]for class: " + classname+" "+ inputFile.getName()); DBTableInfo tblInfo = new DBTableInfo(tableId, classname, tablename, primaryKeyField, tableNode.attributeValue("abbrv")); //$NON-NLS-1$ tblInfo.setSearchable(isSearchable); tblInfo.setBusinessRuleName(XMLHelper.getAttr(tableNode, "businessrule", null)); //$NON-NLS-1$ if (hash.get(tableId) != null) { log.error("Table ID used twice[" + tableId + "]"); //$NON-NLS-1$ //$NON-NLS-2$ } hash.put(tableId, tblInfo); byClassNameHash.put(classname.toLowerCase(), tblInfo); byShortClassNameHash.put(tblInfo.getShortClassName().toLowerCase(), tblInfo); tables.add(tblInfo); Element idElement = (Element) tableNode.selectSingleNode("id"); //$NON-NLS-1$ if (idElement != null) { tblInfo.setIdColumnName(getAttr(idElement, "column", null)); //$NON-NLS-1$ tblInfo.setIdFieldName(getAttr(idElement, "name", null)); //$NON-NLS-1$ tblInfo.setIdType(getAttr(idElement, "type", null)); //$NON-NLS-1$ } for (Iterator<?> ir = tableNode.elementIterator("tableindex"); ir.hasNext();) //$NON-NLS-1$ { Element irNode = (Element) ir.next(); String inxName = getAttr(irNode, "indexName", null); String inxColNames = getAttr(irNode, "columnNames", null); tblInfo.addTableIndex(inxName, inxColNames); } Element displayElement = (Element) tableNode.selectSingleNode("display"); //$NON-NLS-1$ if (displayElement != null) { tblInfo.setDefaultFormName(getAttr(displayElement, "view", null)); //$NON-NLS-1$ tblInfo.setUiFormatter(getAttr(displayElement, "uiformatter", null)); //$NON-NLS-1$ tblInfo.setDataObjFormatter(getAttr(displayElement, "dataobjformatter", null)); //$NON-NLS-1$ tblInfo.setSearchDialog(getAttr(displayElement, "searchdlg", null)); //$NON-NLS-1$ tblInfo.setNewObjDialog(getAttr(displayElement, "newobjdlg", null)); //$NON-NLS-1$ } else { tblInfo.setDefaultFormName(""); //$NON-NLS-1$ tblInfo.setUiFormatter(""); //$NON-NLS-1$ tblInfo.setDataObjFormatter(""); //$NON-NLS-1$ tblInfo.setSearchDialog(""); //$NON-NLS-1$ tblInfo.setNewObjDialog(""); //$NON-NLS-1$ } for (Iterator<?> ir = tableNode.elementIterator("relationship"); ir.hasNext();) //$NON-NLS-1$ { Element irNode = (Element) ir.next(); DBRelationshipInfo tblRel = new DBRelationshipInfo( irNode.attributeValue("relationshipname"), //$NON-NLS-1$ getRelationshipType(irNode.attributeValue("type")), //$NON-NLS-1$ irNode.attributeValue("classname"), //$NON-NLS-1$ irNode.attributeValue("columnname"), //$NON-NLS-1$ irNode.attributeValue("othersidename"), //$NON-NLS-1$ irNode.attributeValue("jointable"), //$NON-NLS-1$ getAttr(irNode, "required", false), //$NON-NLS-1$ getAttr(irNode, "updatable", false), //$NON-NLS-1$ getAttr(irNode, "save", false), //$NON-NLS-1$ getAttr(irNode, "likemanytoone", false)); //$NON-NLS-1$ tblInfo.getRelationships().add(tblRel); } for (Iterator<?> ir = tableNode.elementIterator("field"); ir.hasNext();) //$NON-NLS-1$ { Element irNode = (Element) ir.next(); int len = -1; String lenStr = irNode.attributeValue("length"); //$NON-NLS-1$ if (StringUtils.isNotEmpty(lenStr) && StringUtils.isNumeric(lenStr)) { len = Integer.parseInt(lenStr); // if (!UIRegistry.isMobile() && len > 256) // length over 255 are memo/text fields in MySQL and do not need to be constrained // { // len = 32767; // } } DBFieldInfo fieldInfo = new DBFieldInfo(tblInfo, irNode.attributeValue("column"), //$NON-NLS-1$ irNode.attributeValue("name"), //$NON-NLS-1$ irNode.attributeValue("type"), //$NON-NLS-1$ len, getAttr(irNode, "required", false), //$NON-NLS-1$ getAttr(irNode, "updatable", false), //$NON-NLS-1$ getAttr(irNode, "unique", false), //$NON-NLS-1$ getAttr(irNode, "indexed", false), //$NON-NLS-1$ getAttr(irNode, "partialDate", false), //$NON-NLS-1$ getAttr(irNode, "datePrecisionName", null)); //$NON-NLS-1$ // This done to cache the original setting. fieldInfo.setRequiredInSchema(fieldInfo.isRequired()); tblInfo.addField(fieldInfo); } for (Iterator<?> faIter = tableNode.elementIterator("fieldalias"); faIter.hasNext();) //$NON-NLS-1$ { Element faNode = (Element) faIter.next(); String vName = getAttr(faNode, "vname", null);//$NON-NLS-1$ String aName = getAttr(faNode, "aname", null);//$NON-NLS-1$ if (vName != null && aName != null) { tblInfo.addFieldAlias(vName, aName); } } //Collections.sort(tblInfo.getFields()); } } else { log.error("Reading in datamodel file. SAX parser got null for the root of the document."); //$NON-NLS-1$ } } catch (java.lang.NumberFormatException numEx) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DBTableIdMgr.class, numEx); log.error("Specify datamodel input file: " + inputFile.getAbsolutePath() //$NON-NLS-1$ + " failed to provide valid table id for class/table:" + classname); //$NON-NLS-1$ log.error(numEx); } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DBTableIdMgr.class, ex); log.error(ex); ex.printStackTrace(); } Collections.sort(tables); log.debug("Done Reading in datamodel file: " + inputFile.getAbsolutePath()); //$NON-NLS-1$ }
From source file:com.ctrip.infosec.rule.util.Emitter.java
@Deprecated public static void mergeCounterResults(RiskFact fact, List<CounterRuleExecuteResult> counterExecuteResults) { // String _ruleNo = (String) fact.ext.get(Constants.key_ruleNo); boolean _isAsync = MapUtils.getBoolean(fact.ext, Constants.key_isAsync, false); if (counterExecuteResults != null && !counterExecuteResults.isEmpty()) { for (CounterRuleExecuteResult ruleExecuteResult : counterExecuteResults) { if (StringUtils.isNotBlank(ruleExecuteResult.getRuleNo()) && StringUtils.isNumeric(ruleExecuteResult.getResultCode())) { String ruleNo = ruleExecuteResult.getRuleNo(); int riskLevel = NumberUtils.toInt(ruleExecuteResult.getResultCode(), 0); String riskMessage = ruleExecuteResult.getResultMessage(); String scenes = ruleExecuteResult.getScenes(); if (riskLevel > 0) { Map<String, Object> result = Maps.newHashMap(); result.put(Constants.riskLevel, riskLevel); result.put(Constants.riskMessage, riskMessage); result.put(Constants.async, _isAsync); if (StringUtils.isBlank(scenes)) { if (!_isAsync) { result.put(Constants.ruleType, "N"); fact.results.put(ruleNo, result); } else { result.put(Constants.ruleType, "NA"); fact.results4Async.put(ruleNo, result); }/*from w w w . jav a 2s .c o m*/ } else { List<String> riskScenes = Splitter.on(",").omitEmptyStrings().trimResults() .splitToList(scenes); result.put(Constants.riskScene, riskScenes); if (!_isAsync) { result.put(Constants.ruleType, "S"); fact.resultsGroupByScene.put(ruleNo, result); } else { result.put(Constants.ruleType, "SA"); fact.resultsGroupByScene4Async.put(ruleNo, result); } } boolean withScene = Constants.eventPointsWithScene.contains(fact.eventPoint); TraceLogger.traceLog("[trace] withScene = " + withScene + ", scenes = [" + (scenes == null ? "" : scenes) + "]"); if (!withScene) { if (StringUtils.isNotBlank(scenes)) { TraceLogger.traceLog(">>>> [" + ruleNo + "] : [???] riskLevel = " + riskLevel + ", riskMessage = " + riskMessage + ", riskScene = [" + scenes + "]"); } else { TraceLogger.traceLog(">>>> [" + ruleNo + "] : riskLevel = " + riskLevel + ", riskMessage = " + riskMessage); } } else if (withScene) { if (StringUtils.isBlank(scenes)) { TraceLogger.traceLog(">>>> [" + ruleNo + "] [?]: [?] riskLevel = " + riskLevel + ", riskMessage = " + riskMessage); } else { TraceLogger.traceLog(">>>> [" + ruleNo + "] [?]: riskLevel = " + riskLevel + ", riskMessage = " + riskMessage + ", riskScene = [" + scenes + "]"); } } } } } } }
From source file:eu.stork.peps.auth.commons.PEPSUtil.java
/** * Gets the Stork error message in the saml message if exists! * //from ww w. j a v a2 s.c om * @param errorMessage The message to get in the saml message if exists; * * @return the error message if exists. Returns the original message * otherwise. */ public static String getStorkErrorMessage(final String errorMessage) { if (StringUtils.isNotBlank(errorMessage) && errorMessage.indexOf(PEPSValues.ERROR_MESSAGE_SEP.toString()) >= 0) { final String[] msgSplitted = errorMessage.split(PEPSValues.ERROR_MESSAGE_SEP.toString()); if (msgSplitted.length == 2 && StringUtils.isNumeric(msgSplitted[0])) { return msgSplitted[1]; } } return errorMessage; }
From source file:fr.paris.lutece.portal.web.user.attribute.AttributeJspBean.java
/** * Remove an user attribute//from w ww .j ava2 s . co m * @param request HttpServletRequest * @return The Jsp URL of the process result */ public String doRemoveAttribute(HttpServletRequest request) { String strIdAttribute = request.getParameter(PARAMETER_ID_ATTRIBUTE); if (StringUtils.isNotBlank(strIdAttribute) && StringUtils.isNumeric(strIdAttribute)) { int nIdAttribute = Integer.parseInt(strIdAttribute); _attributeService.removeAttribute(nIdAttribute); } return JSP_MANAGE_ATTRIBUTES; }
From source file:com.redhat.rhn.manager.session.SessionManager.java
/** * Lookup a Session by it's key//from w w w. ja v a 2s .c o m * @param key The key containing the session id and hash * @return Returns the session if the key is valid. */ public static WebSession lookupByKey(String key) { //Make sure we didn't get null for a key if (key == null || key.equals("")) { throw new InvalidSessionIdException("Session key cannot be empty null."); } //Get the id String[] keyParts = StringUtils.split(key, 'x'); //make sure the id is numeric and can be made into a Long if (!StringUtils.isNumeric(keyParts[0])) { throw new InvalidSessionIdException( "Session id: " + keyParts[0] + " is not valid. Session ids must be numeric."); } //Load the session Long sessionId = new Long(keyParts[0]); WebSession session = WebSessionFactory.lookupById(sessionId); //Make sure we found a session if (session == null) { throw new LookupException("Could not find session with id: " + sessionId); } //Verify the key if (!isPxtSessionKeyValid(key)) { throw new InvalidSessionIdException("Session id: " + sessionId + " is not valid."); } //If we made it this far, the key was ok and the sesion valid. return session; }
From source file:com.prowidesoftware.swift.model.MtSwiftMessage.java
/** * Get the integer value of the {@link #getMessageType()} * or null if the identifier attribute is not set or not a number *//*from w w w. ja v a 2 s. c o m*/ public Integer getMessageTypeInt() { final String number = getMessageType(); if (number != null && StringUtils.isNumeric(number)) { return Integer.parseInt(number); } else { return null; } }
From source file:com.commerce4j.storefront.controllers.SyndicationController.java
public ModelAndView register(HttpServletRequest request, HttpServletResponse response) { ModelAndView mav = new ModelAndView("jsonView"); String userName = request.getParameter("userName"); String emailAddress = request.getParameter("emailAddress"); String userPass = request.getParameter("userPass"); String confirmPassword = request.getParameter("confirmPassword"); String firstName = request.getParameter("firstName"); String countryId = request.getParameter("countryId"); String lastName = request.getParameter("lastName"); String cellPhone = request.getParameter("cellPhone"); String acceptTermAndConditions = request.getParameter("acceptTermAndConditions"); List<Message> errors = new ArrayList<Message>(); // validate countryId if (StringUtils.isBlank(countryId)) { errors.add(newError("countryId", getString("errors.notEmpty"), new Object[] { getString("register.countryId") })); }//from w w w . j a v a 2 s . co m // validate user if (StringUtils.isEmpty(userName)) { errors.add(newError("userName", getString("errors.notEmpty"), new Object[] { getString("register.userName") })); } else { // validate user name existence if (!getProfileDSO().isUserValid(userName)) { errors.add(newError("userName", getString("errors.userAlreadyExists"), new Object[] { userName })); } } // validate email address if (StringUtils.isEmpty(emailAddress)) { errors.add(newError("emailAddress", getString("errors.notEmpty"), new Object[] { getString("register.emailAddress") })); } else { // validate emailAddress format if (!EmailValidator.validate(emailAddress)) { errors.add(newError("emailAddress", getString("errors.emailInvalidFormat"), new Object[] { emailAddress })); } else { // validate emailAddress existence if (!getProfileDSO().isEmailValid(emailAddress)) { errors.add(newError("emailAddress", getString("errors.emailAlreadyExists"), new Object[] { emailAddress })); } } } // validate password if (StringUtils.isEmpty(userPass)) { errors.add(newError("userPass", getString("errors.notEmpty"), new Object[] { getString("register.userPass") })); } if (StringUtils.isEmpty(firstName)) { errors.add(newError("firstName", getString("errors.notEmpty"), new Object[] { getString("register.firstName") })); } if (StringUtils.isEmpty(cellPhone)) { errors.add(newError("cellPhone", getString("errors.notEmpty"), new Object[] { getString("register.cellPhone") })); } if (StringUtils.isEmpty(countryId)) { errors.add(newError("countryId", getString("errors.notEmpty"), new Object[] { getString("register.countryId") })); } if (StringUtils.isEmpty(lastName)) { errors.add(newError("lastName", getString("errors.notEmpty"), new Object[] { getString("register.lastName") })); } if (!StringUtils.equalsIgnoreCase(acceptTermAndConditions, "true")) { errors.add(newError("acceptTermAndConditions", getString("errors.acceptTermAndConditions"))); } if (StringUtils.isEmpty(confirmPassword)) { errors.add(newError("confirmPassword", getString("errors.notEmpty"), new Object[] { getString("register.confirmPassword") })); } if (!StringUtils.equals(userPass, confirmPassword)) { errors.add(newError("userPass", getString("errors.passwordDoesNotMatch"))); } // proceed to registration, if no errors found. if (errors.isEmpty()) { // create a user and get the newly generated user id, // this user by default is disabled, need to // validate after registration long userId = getProfileDSO().registerUser(userName, userPass, emailAddress, firstName, lastName, cellPhone, new Integer(countryId)); // data objets UserDAO userDAO = (UserDAO) getBean("userDAO"); UserDTO userDTO = userDAO.findById(userId); ConfigDAO configDAO = (ConfigDAO) getBean("configDAO"); // set other user properties if (StringUtils.isNumeric(countryId)) { CountryDTO country = new CountryDTO(); country.setCountryId(new Integer(countryId)); userDTO.setCountry(country); } if (logger.isDebugEnabled()) { logger.debug("UID @ " + userId + "/" + userDTO.getGuid()); } // check if store is configured for mail confirmation final String CONFIRM_KEY = "REGISTRATION_MAIL_CONFIRM"; String confirmEmailAddress = configDAO.findById(CONFIRM_KEY); // send confirmation mail if mailer is configured if (StringUtils.equalsIgnoreCase("Yes", confirmEmailAddress)) { SendMail mailer = (SendMail) getBean("mailer"); if (mailer != null) try { // get variables from database String storeName = configDAO.findById("STORE_NAME"); String storeURL = configDAO.findById("STORE_URL"); String from = configDAO.findById("REGISTRATION_MAIL_FROM"); String subject = configDAO.findById("REGISTRATION_MAIL_SUBJECT"); String prefixURL = "/profile.jspa?aid=confirm&uid="; String url = storeURL + prefixURL + userDTO.getGuid(); // get store StoreDTO store = new StoreDTO(); store.setStoreId(1); store.setStoreName(storeName); store.setStoreUrl(storeURL); // build registration information object RegistrationInfo info = new RegistrationInfo(); info.setUser(userDTO); info.setStore(store); info.setUrl(url); // serializae registration object to XML File inputFile = File.createTempFile("UID" + userId, "xml"); XStream xstream = new XStream(); xstream.alias("registration", RegistrationInfo.class); xstream.toXML(info, new FileOutputStream(inputFile)); // transform xml object source to html mail output StringWriter outWriter = new StringWriter(); InputStream xslStream = getClass().getResourceAsStream("/templates/welcome_mail.xsl"); InputStream xmlStream = new FileInputStream(inputFile); xslTransform(xmlStream, xslStream, outWriter); // send mail using mailer implementation mailer.sendMessage(from, new String[] { emailAddress }, subject, outWriter.getBuffer().toString()); } catch (Exception e) { e.printStackTrace(); if (logger.isErrorEnabled()) { logger.error(e); } } } else { // if no email confirmation is required, then set the user // active userDTO.setActive(1); userDAO.update(userDTO); } // all ok, send nice response mav.addObject("responseCode", SUCCESS); mav.addObject("responseMessage", "Registro Completo"); mav.addObject("userId", userId); } else { // something wron, send failure response mav.addObject("responseCode", FAILURE); mav.addObject("responseMessage", "Registro Incompleto, favor verificar"); mav.addObject("errors", errors); } return mav; }