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:com.redhat.rhn.common.util.RecurringEventPicker.java
/** * Get the hour of the day// w w w. j a va 2 s. c o m * @return the hour */ public Long getMinuteLong() { String st = getCronValue(1); if (StringUtils.isNumeric(st)) { return Long.parseLong(st); } return -1L; }
From source file:com.impetus.client.mongodb.schemamanager.MongoDBSchemaManager.java
/** * initiate client method initiates the client. * /*w ww .j a v a2 s. c om*/ * @return boolean value ie client started or not. * */ protected boolean initiateClient() { String message = null; for (String host : hosts) { if (host == null || !StringUtils.isNumeric(port) || port.isEmpty()) { logger.error("Host or port should not be null / port should be numeric"); throw new IllegalArgumentException("Host or port should not be null / port should be numeric"); } try { mongo = new MongoClient(host, Integer.parseInt(port)); db = mongo.getDB(databaseName); try { MongoDBUtils.authenticate(puMetadata.getProperties(), externalProperties, db); } catch (ClientLoaderException e) { throw new SchemaGenerationException(e); } catch (KunderaAuthenticationException e) { throw new SchemaGenerationException(e); } return true; } catch (UnknownHostException e) { message = e.getMessage(); logger.error("Database host cannot be resolved, Caused by", e); } } throw new SchemaGenerationException("Database host cannot be resolved, Caused by" + message); }
From source file:fr.paris.lutece.plugins.document.modules.solr.indexer.SolrDocIndexer.java
/** * GEt the content to index/*from w ww. j av a 2 s . c om*/ * @param document The document * @param item The SolR item * @return The content */ private static String getContentToIndex(Document document, SolrItem item) { StringBuilder sbContentToIndex = new StringBuilder(); sbContentToIndex.append(document.getTitle()); sbContentToIndex.append(" "); for (DocumentAttribute attribute : document.getAttributes()) { if (attribute.isSearchable()) { if (!attribute.isBinary()) { if (PARAMETER_TYPE_GEOLOC.equalsIgnoreCase(attribute.getCodeAttributeType())) { // Geojson attribute, put the address as text if it exists String address = null; GeolocItem geolocItem = null; try { geolocItem = GeolocItem.fromJSON(attribute.getTextValue()); } catch (IOException e) { AppLogService.error("SolrDocumentIndexer, error parsing JSON" + e); } if (geolocItem != null && geolocItem.getAddress() != null) { sbContentToIndex.append(geolocItem.getAddress()); } } else { // Text attributes sbContentToIndex.append(attribute.getTextValue()); } sbContentToIndex.append(" "); //Dynamic Field if (PARAMETER_TYPE_NUMERICTEXT.equalsIgnoreCase(attribute.getCodeAttributeType())) { Long nI = StringUtils.isNotEmpty(attribute.getTextValue()) && StringUtils.isNumeric(attribute.getTextValue().trim()) ? Long.valueOf(attribute.getTextValue().trim()) : 0; item.addDynamicField(attribute.getCode(), nI); } else if (PARAMETER_TYPE_GEOLOC.equalsIgnoreCase(attribute.getCodeAttributeType())) { item.addDynamicFieldGeoloc(attribute.getCode(), attribute.getTextValue(), document.getCodeDocumentType()); } else item.addDynamicField(attribute.getCode(), attribute.getTextValue()); } else { // Binary file attribute // Gets indexer depending on the ContentType (ie: "application/pdf" should use a PDF indexer) IFileIndexerFactory _factoryIndexer = (IFileIndexerFactory) SpringContextService .getBean(IFileIndexerFactory.BEAN_FILE_INDEXER_FACTORY); IFileIndexer indexer = _factoryIndexer.getIndexer(attribute.getValueContentType()); if (indexer != null) { try { ByteArrayInputStream bais = new ByteArrayInputStream(attribute.getBinaryValue()); sbContentToIndex.append(indexer.getContentToIndex(bais)); sbContentToIndex.append(" "); bais.close(); } catch (IOException e) { AppLogService.error(e.getMessage(), e); } } else { AppLogService.debug("No indexer found. Url to this data will be given instead"); String strName = attribute.getCode() + "_" + attribute.getCodeAttributeType() + "_url"; UrlItem url = new UrlItem(SolrIndexerService.getBaseUrl()); url.addParameter(PARAMETER_DOCUMENT_ID, document.getId()); url.addParameter(PARAMETER_ATTRIBUTE_ID, attribute.getId()); item.addDynamicField(strName, url.getUrl()); } } } } // Index Metadata if (document.getXmlMetadata() != null) { sbContentToIndex.append(document.getXmlMetadata()); } return sbContentToIndex.toString(); }
From source file:fr.paris.lutece.plugins.workflow.modules.appointment.web.AbstractNotifyAppointmentTaskComponent.java
/** * Do save the configuration of the task * @param request The request/*from w w w . ja va 2 s. c o m*/ * @param locale The locale * @param task The task * @param taskConfigService The task config service to use * @param bNotifyAdmin True to notify the admin user, false to notify the * user of the appointment * @return The next URL to redirect to if an error occurs, or null if there * was no error. */ public String doSaveConfig(HttpServletRequest request, Locale locale, ITask task, ITaskConfigService taskConfigService, boolean bNotifyAdmin) { String strSenderName = request.getParameter(PARAMETER_SENDER_NAME); String strSenderEmail = request.getParameter(PARAMETER_SENDER_EMAIL); String strSubject = request.getParameter(PARAMETER_SUBJECT); String strMessage = request.getParameter(PARAMETER_MESSAGE); String strRecipientsCc = request.getParameter(PARAMETER_RECIPIENTS_CC); String strRecipientsBcc = request.getParameter(PARAMETER_RECIPIENTS_BCC); boolean bSendICalNotif = Boolean.valueOf(request.getParameter(PARAMETER_SEND_ICAL_NOTIF)); String strLocation = request.getParameter(PARAMETER_LOCATION); String strError = StringUtils.EMPTY; if (StringUtils.isBlank(strSenderName)) { strError = FIELD_SENDER_NAME; } if (StringUtils.isBlank(strSenderEmail)) { strError = FIELD_SENDER_EMAIL; } else if (StringUtils.isBlank(strSubject)) { strError = FIELD_SUBJECT; } else if (StringUtils.isBlank(strMessage)) { strError = FIELD_MESSAGE; } if (!StringUtil.checkEmail(strSenderEmail)) { strError = FIELD_SENDER_EMAIL_NOT_VALID; } if (!strError.equals(WorkflowUtils.EMPTY_STRING)) { Object[] tabRequiredFields = { I18nService.getLocalizedString(strError, locale) }; return AdminMessageService.getMessageUrl(request, MESSAGE_MANDATORY_FIELD, tabRequiredFields, AdminMessage.TYPE_STOP); } NotifyAppointmentDTO config = taskConfigService.findByPrimaryKey(task.getId()); Boolean bCreate = false; if (config == null) { if (bNotifyAdmin) { config = new TaskNotifyAdminAppointmentConfig(); } else { config = new TaskNotifyAppointmentConfig(); } config.setIdTask(task.getId()); bCreate = true; } config.setMessage(strMessage); config.setSenderEmail(strSenderEmail); config.setSenderName(strSenderName); config.setSubject(strSubject); config.setRecipientsCc(StringUtils.isNotEmpty(strRecipientsCc) ? strRecipientsCc : StringUtils.EMPTY); config.setRecipientsBcc(StringUtils.isNotEmpty(strRecipientsBcc) ? strRecipientsBcc : StringUtils.EMPTY); config.setSendICalNotif(bSendICalNotif); config.setLocation(strLocation); if (bSendICalNotif) { config.setCreateNotif(Boolean.parseBoolean(request.getParameter(PARAMETER_CREATE_NOTIF))); } String strIdAction = request.getParameter(PARAMETER_ID_ACTION_CANCEL); int nIdAction = 0; if (StringUtils.isNotEmpty(strIdAction) && StringUtils.isNumeric(strIdAction)) { nIdAction = Integer.parseInt(strIdAction); } if (bNotifyAdmin) { TaskNotifyAdminAppointmentConfig configAdmin = (TaskNotifyAdminAppointmentConfig) config; configAdmin.setIdActionCancel(nIdAction); String strIdActionValidate = request.getParameter(PARAMETER_ID_ACTION_VALIDATE); int nIdActionValidate = 0; if (StringUtils.isNotEmpty(strIdActionValidate) && StringUtils.isNumeric(strIdActionValidate)) { nIdActionValidate = Integer.parseInt(strIdActionValidate); } configAdmin.setIdActionValidate(nIdActionValidate); String strIdAdminUser = request.getParameter(PARAMETER_ID_ADMIN_USER); if (StringUtils.isNotEmpty(strIdAdminUser) && StringUtils.isNumeric(strIdAdminUser)) { int nIdAdminUser = Integer.parseInt(strIdAdminUser); if (nIdAdminUser > 0) { configAdmin.setIdAdminUser(nIdAdminUser); } } } else { boolean bNotifySms = Boolean.parseBoolean(request.getParameter(PARAMETER_SEND_SMS)); config.setIsSms(bNotifySms); if (bNotifySms) { config.setSendICalNotif(false); } ((TaskNotifyAppointmentConfig) config).setIdActionCancel(nIdAction); } if (bCreate) { taskConfigService.create(config); } else { taskConfigService.update(config); } return null; }
From source file:com.prowidesoftware.swift.model.field.SwiftParseUtils.java
/** * Returns the numeric starting substring of the value. * The split is made when the first alpha character (not number or comma) is found. * For example:<br />/*from w w w.j av a 2 s . c om*/ * 2345,33ABCD will be return 2345,33<br /> * If the value does not contain any numeric or comma character <code>null</code> is returned. * * @param value * @return s */ public static String getNumericPrefix(final String value) { if (value != null && value.length() > 0) { int i = 0; while (i < value.length() && (StringUtils.isNumeric("" + value.charAt(i)) || StringUtils.equals("" + value.charAt(i), ","))) { i++; } if (i > 0) { return StringUtils.substring(value, 0, i); } } return null; }
From source file:net.duckling.ddl.web.controller.LynxDirectionController.java
@RequestMapping(params = "func=createFolder") @WebLog(method = "createFolder") public void createFolder(HttpServletRequest request, HttpServletResponse response) { VWBContext context = VWBContext.createContext(request, UrlPatterns.T_TEAM_HOME); String uid = context.getCurrentUID(); String parentRidS = request.getParameter("parentRid"); int tid = VWBContext.getCurrentTid(); String tidStr = request.getParameter("tid"); if (StringUtils.isNumeric(tidStr)) { tid = Integer.valueOf(tidStr); }//from w w w. j a v a2 s . c om JSONObject j = new JSONObject(); if (!authorityService.haveTeamEditeAuth(tid, uid)) { j.put("result", false); j.put("message", "??"); JsonUtil.writeJSONObject(response, j); return; } int parentRid = 0; try { parentRid = Integer.parseInt(parentRidS); } catch (Exception e) { } if (StringUtil.illCharCheck(request, response, "fileName")) { return; } String name = request.getParameter("fileName"); Resource r = new Resource(); r.setTid(tid); r.setBid(parentRid); r.setCreateTime(new Date()); r.setCreator(uid); r.setItemType(LynxConstants.TYPE_FOLDER); r.setTitle(name); r.setLastEditor(uid); r.setLastEditorName(aoneUserService.getUserNameByID(uid)); r.setLastEditTime(new Date()); r.setStatus(LynxConstants.STATUS_AVAILABLE); resourceOperateService.createFolder(r); j.put("resource", LynxResourceUtils.getResourceJson(uid, r)); j.put("result", true); JsonUtil.writeJSONObject(response, j); }
From source file:com.flexive.ejb.beans.structure.AssignmentEngineBean.java
/** * {@inheritDoc}// w w w . ja v a 2s . co m */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public long createProperty(long typeId, FxPropertyEdit property, String parentXPath, String assignmentAlias) throws FxApplicationException { FxPermissionUtils.checkRole(FxContext.getUserTicket(), Role.StructureManagement); Connection con = null; PreparedStatement ps = null; StringBuilder sql = new StringBuilder(2000); long newPropertyId; long newAssignmentId; try { parentXPath = parentXPath.toUpperCase(); assignmentAlias = assignmentAlias.toUpperCase(); FxType type = CacheAdmin.getEnvironment().getType(typeId); FxAssignment tmp = type.getAssignment(parentXPath); if (tmp != null && tmp instanceof FxPropertyAssignment) throw new FxInvalidParameterException("ex.structure.assignment.noGroup", parentXPath); property.checkConsistency(); //parentXPath is valid, create the property, then assign it to root newPropertyId = seq.getId(FxSystemSequencer.TYPEPROP); FxValue defValue = property.getDefaultValue(); ContentStorage storage = StorageManager.getContentStorage(type.getStorageMode()); con = Database.getDbConnection(); if (defValue instanceof FxBinary) { storage.prepareBinary(con, (FxBinary) defValue); } final String _def = defValue == null || defValue.isEmpty() ? null : ConversionEngine.getXStream().toXML(defValue); if (_def != null && (property.getDefaultValue() instanceof FxReference)) { //check if the type matches the instance checkReferencedType(con, (FxReference) property.getDefaultValue(), property.getReferencedType()); } // do not allow to add mandatory properties (i.e. min multiplicity > 0) to types for which content exists if (storage.getTypeInstanceCount(con, typeId) > 0 && property.getMultiplicity().getMin() > 0) { throw new FxCreateException("ex.structure.property.creation.existingContentMultiplicityError", property.getName(), property.getMultiplicity().getMin()); } //create property, no checks for existing names are performed as this is handled with unique keys sql.append("INSERT INTO ").append(TBL_STRUCT_PROPERTIES). // 1 2 3 4 5 6 7 append("(ID,NAME,DEFMINMULT,DEFMAXMULT,MAYOVERRIDEMULT,DATATYPE,REFTYPE," + //8 9 10 11 12 "ISFULLTEXTINDEXED,ACL,MAYOVERRIDEACL,REFLIST,UNIQUEMODE," + //13 14 "SYSINTERNAL,DEFAULT_VALUE)VALUES(" + "?,?,?,?,?," + "?,?,?,?,?,?,?,?,?)"); ps = con.prepareStatement(sql.toString()); ps.setLong(1, newPropertyId); ps.setString(2, property.getName()); ps.setInt(3, property.getMultiplicity().getMin()); ps.setInt(4, property.getMultiplicity().getMax()); ps.setBoolean(5, property.mayOverrideBaseMultiplicity()); ps.setLong(6, property.getDataType().getId()); if (property.hasReferencedType()) ps.setLong(7, property.getReferencedType().getId()); else ps.setNull(7, java.sql.Types.NUMERIC); ps.setBoolean(8, property.isFulltextIndexed()); ps.setLong(9, property.getACL().getId()); ps.setBoolean(10, property.mayOverrideACL()); if (property.hasReferencedList()) ps.setLong(11, property.getReferencedList().getId()); else ps.setNull(11, java.sql.Types.NUMERIC); ps.setInt(12, property.getUniqueMode().getId()); ps.setBoolean(13, false); if (_def == null) ps.setNull(14, java.sql.Types.VARCHAR); else ps.setString(14, _def); if (!property.isAutoUniquePropertyName()) ps.executeUpdate(); else { //fetch used property names PreparedStatement ps2 = null; try { ps2 = con.prepareStatement( "SELECT NAME FROM " + TBL_STRUCT_PROPERTIES + " WHERE NAME LIKE ? OR NAME=?"); ps2.setString(1, property.getName() + "_%"); ps2.setString(2, property.getName()); ResultSet rs = ps2.executeQuery(); int max = -1; while (rs.next()) { String last = rs.getString(1); if (last.equals(property.getName()) || last.startsWith(property.getName() + "_")) { if (last.equals(property.getName())) { max = Math.max(0, max); } else if (last.startsWith(property.getName() + "_")) { final String suffix = last.substring(last.lastIndexOf("_") + 1); if (StringUtils.isNumeric(suffix)) { max = Math.max(Integer.parseInt(suffix), max); } } } if (max != -1) { final String autoName = property.getName() + "_" + (max + 1); ps.setString(2, autoName); LOG.info("Assigning unique property name [" + autoName + "] to [" + type.getName() + "." + property.getName() + "]"); } } } finally { Database.closeObjects(AssignmentEngineBean.class, ps2); } ps.executeUpdate(); } Database.storeFxString(new FxString[] { property.getLabel(), property.getHint() }, con, TBL_STRUCT_PROPERTIES, new String[] { "DESCRIPTION", "HINT" }, "ID", newPropertyId); ps.close(); sql.setLength(0); //calc new position sql.append("SELECT COALESCE(MAX(POS)+1,0) FROM ").append(TBL_STRUCT_ASSIGNMENTS) .append(" WHERE PARENTGROUP=? AND TYPEDEF=?"); ps = con.prepareStatement(sql.toString()); ps.setLong(1, (tmp == null ? FxAssignment.NO_PARENT : tmp.getId())); ps.setLong(2, typeId); ResultSet rs = ps.executeQuery(); long pos = 0; if (rs != null && rs.next()) pos = rs.getLong(1); ps.close(); storeOptions(con, TBL_STRUCT_PROPERTY_OPTIONS, "ID", newPropertyId, null, property.getOptions()); sql.setLength(0); //create root assignment sql.append("INSERT INTO ").append(TBL_STRUCT_ASSIGNMENTS). // 1 2 3 4 5 6 7 8 9 10 11 12 13 append("(ID,ATYPE,ENABLED,TYPEDEF,MINMULT,MAXMULT,DEFMULT,POS,XPATH,XALIAS,BASE,PARENTGROUP,APROPERTY," + //14 15 "ACL,DEFAULT_VALUE)" + "VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); ps = con.prepareStatement(sql.toString()); newAssignmentId = seq.getId(FxSystemSequencer.ASSIGNMENT); ps.setLong(1, newAssignmentId); ps.setInt(2, FxAssignment.TYPE_PROPERTY); ps.setBoolean(3, true); ps.setLong(4, typeId); ps.setInt(5, property.getMultiplicity().getMin()); ps.setInt(6, property.getMultiplicity().getMax()); if (property.getMultiplicity().isValid(property.getAssignmentDefaultMultiplicity())) { ps.setInt(7, property.getAssignmentDefaultMultiplicity()); } else { //default is min(min,1). ps.setInt(7, property.getMultiplicity().getMin() > 1 ? property.getMultiplicity().getMin() : 1); } ps.setLong(8, pos); if (parentXPath == null || "/".equals(parentXPath)) parentXPath = ""; ps.setString(9, type.getName() + XPathElement.stripType(parentXPath) + "/" + assignmentAlias); ps.setString(10, assignmentAlias); ps.setNull(11, Types.NUMERIC); if (tmp == null) ps.setLong(12, FxAssignment.NO_PARENT); else ps.setLong(12, tmp.getId()); ps.setLong(13, newPropertyId); ps.setLong(14, property.getACL().getId()); ps.setString(15, _def); ps.executeUpdate(); Database.storeFxString(new FxString[] { property.getLabel(), property.getHint() }, con, TBL_STRUCT_ASSIGNMENTS, new String[] { "DESCRIPTION", "HINT" }, "ID", newAssignmentId); StructureLoader.reloadAssignments(FxContext.get().getDivisionId()); if (divisionConfig.isFlatStorageEnabled() && divisionConfig.get(SystemParameters.FLATSTORAGE_AUTO)) { final FxFlatStorage fs = FxFlatStorageManager.getInstance(); FxPropertyAssignment pa = (FxPropertyAssignment) CacheAdmin.getEnvironment() .getAssignment(newAssignmentId); if (fs.isFlattenable(pa)) { fs.flatten(con, fs.getDefaultStorage(), pa); StructureLoader.reloadAssignments(FxContext.get().getDivisionId()); } } htracker.track(type, "history.assignment.createProperty", property.getName(), type.getId(), type.getName()); if (type.getId() != FxType.ROOT_ID) createInheritedAssignments(CacheAdmin.getEnvironment().getAssignment(newAssignmentId), con, sql, type.getDerivedTypes()); } catch (FxNotFoundException e) { EJBUtils.rollback(ctx); throw new FxCreateException(e); } catch (FxLoadException e) { EJBUtils.rollback(ctx); throw new FxCreateException(e); } catch (SQLException e) { final boolean uniqueConstraintViolation = StorageManager.isUniqueConstraintViolation(e); EJBUtils.rollback(ctx); if (uniqueConstraintViolation) throw new FxEntryExistsException("ex.structure.property.exists", property.getName(), (parentXPath.length() == 0 ? "/" : parentXPath)); throw new FxCreateException(LOG, e, "ex.db.sqlError", e.getMessage()); } finally { Database.closeObjects(AssignmentEngineBean.class, con, ps); } return newAssignmentId; }
From source file:fr.paris.lutece.portal.web.user.attribute.AttributeJspBean.java
/** * Move up the position of the attribute field * @param request HttpServletRequest//from w w w .ja v a 2 s .c om * @return The Jsp URL of the process result */ public String doMoveUpAttribute(HttpServletRequest request) { String strIdAttribute = request.getParameter(PARAMETER_ID_ATTRIBUTE); if (StringUtils.isNotBlank(strIdAttribute) && StringUtils.isNumeric(strIdAttribute)) { int nIdAttribute = Integer.parseInt(strIdAttribute); List<IAttribute> listAttributes = _attributeService.getAllAttributesWithoutFields(getLocale()); IAttribute previousAttribute = null; IAttribute currentAttribute = null; Iterator<IAttribute> it = listAttributes.iterator(); previousAttribute = it.next(); currentAttribute = it.next(); while (it.hasNext() && (currentAttribute.getIdAttribute() != nIdAttribute)) { previousAttribute = currentAttribute; currentAttribute = it.next(); } int previousAttributePosition = previousAttribute.getPosition(); int currentAttributePosition = currentAttribute.getPosition(); previousAttribute.setPosition(currentAttributePosition); currentAttribute.setPosition(previousAttributePosition); _attributeService.updateAttribute(previousAttribute); _attributeService.updateAttribute(currentAttribute); } return JSP_MANAGE_ATTRIBUTES; }
From source file:com.dm.estore.core.config.impl.InitDataLoaderImpl.java
private int parseSafeInteger(final String value, int defaultValue) { if (!StringUtils.isEmpty(value)) { return StringUtils.isNumeric(value) ? Integer.parseInt(value) : defaultValue; }//ww w. ja va 2 s .c om return defaultValue; }