List of usage examples for org.apache.commons.lang StringUtils substring
public static String substring(String str, int start)
Gets a substring from the specified String avoiding exceptions.
From source file:com.bluexml.xforms.controller.alfresco.agents.MappingAgent.java
/** * Finds a new name for an uploaded content. The name includes the content type, the random path * and the original file name.// w w w.ja v a 2 s. c o m * <p/> * NOTE: uploadDir must have been set. * * @param type * the type * @param fileName * the file name * * @return the file */ private File findNewName(int depth, String type, String fileName) { String lFileName = fileName; if (lFileName.contains("\\")) { int lastIndexOf = StringUtils.lastIndexOf(lFileName, '\\'); lFileName = StringUtils.substring(lFileName, lastIndexOf + 1); } String rootPath = currentUploadDir.getAbsolutePath() + File.separator + type; String randomPath = RandomStringUtils.randomNumeric(depth); for (int i = 0; i < depth; i++) { rootPath = rootPath + File.separator + randomPath.charAt(i); } File root = new File(rootPath); File result = new File(root, lFileName); if (result.exists()) { int dotPos = lFileName.lastIndexOf("."); String fileNameWihoutExtension = null; String fileNameExtension = null; if (dotPos == -1) { fileNameWihoutExtension = lFileName; } else { fileNameWihoutExtension = lFileName.substring(0, dotPos); fileNameExtension = lFileName.substring(dotPos + 1); } int i = 0; do { String newFileName = fileNameWihoutExtension + "-" + i; if (fileNameExtension != null) { newFileName = newFileName + "." + fileNameExtension; } result = new File(root, newFileName); i++; } while (result.exists()); } result.getParentFile().mkdirs(); return result; }
From source file:com.greenline.guahao.web.module.home.controllers.my.reservation.ReservationProcess.java
public void tumorInfoBackfill(OperationJsonObject json, String patientUserId) { if (StringUtils.isBlank(patientUserId)) { return;/*from w w w .j av a 2 s .c o m*/ } // ? PatientInfoDO patientInfoDO = patientManager.getPatientByPatientId(Long.parseLong(patientUserId)); if (null == patientInfoDO) { return; } else { Long userId = UserCookieUtil.getUserId(request); if (!userId.toString().equals(String.valueOf(patientInfoDO.getUser_id()))) { return; } } Map<String, PostTumorInfoVO> jsonMap = new HashMap<String, PostTumorInfoVO>(0); PostTumorInfoVO tumorInfo = new PostTumorInfoVO(); BasicInfoDTO basic = healthMgr.getBasicInfo(Long.valueOf(patientUserId)); if (null != basic) { tumorInfo.setPatientId(String.valueOf(basic.getUserId())); tumorInfo.setAddrs(basic.getAddress()); tumorInfo.setEducation(basic.getEducationalStatus()); tumorInfo.setEmail(basic.getEmail()); tumorInfo.setFax(basic.getFax()); tumorInfo.setNationality(basic.getNationality()); tumorInfo.setProfession(basic.getJob()); tumorInfo.setReligion(basic.getReligion()); } PastMedicalHisDTO pastGmsHis = healthMgr.getPastMedicalHis(Long.valueOf(patientUserId), ReservationConstants.TUMOR_HIS_GMS); if (null != pastGmsHis) { List<PastMedicalHisDetailDTO> detailList = pastGmsHis.getMedicalHisList(); for (int i = 0; i < detailList.size(); i++) { PastMedicalHisDetailDTO detail = detailList.get(i); if (ReservationConstants.TUMOR_HIS_GMS_NAME.equals(detail.getDisease())) { tumorInfo.setHisOfDrugAllergyStatus(ReservationConstants.TUMOR_HIS_FOR_YES); tumorInfo.setHisOfDrugAllergy(detail.getDrugName()); tumorInfo.setHealthRecordIdForDrugAllergy(detail.getId()); break; } } } PastMedicalHisDTO pastJzsHis = healthMgr.getPastMedicalHis(Long.valueOf(patientUserId), ReservationConstants.TUMOR_HIS_JZS); if (null != pastJzsHis) { List<PastMedicalHisDetailDTO> detailList = pastJzsHis.getMedicalHisList(); for (int i = 0; i < detailList.size(); i++) { PastMedicalHisDetailDTO detail = detailList.get(i); if (ReservationConstants.TUMOR_HIS_JZS_NAME.equals(detail.getDisease())) { tumorInfo.setFamilyHistoryStatus(ReservationConstants.TUMOR_HIS_FOR_YES); tumorInfo.setFamilyHistory(detail.getDesc()); tumorInfo.setHealthRecordIdForFamilyHistory(detail.getId()); } else if (ReservationConstants.TUMOR_HIS_ZLS_NAME.equals(detail.getDisease())) { tumorInfo.setHisOfCancerDiseaseStatus(ReservationConstants.TUMOR_HIS_FOR_YES); tumorInfo.setHisOfCancerDisease(detail.getDesc()); tumorInfo.setHealthRecordIdForCancerDisease(detail.getId()); } } } List<TreatmentHisDTO> treatList = healthMgr.listTreatmentHis(Long.valueOf(patientUserId)); if (CollectionUtils.isEmpty(treatList)) { tumorInfo.setDiseaseHisExist(ReservationConstants.TUMOR_DISEASE_EXIST_NO); } else { TreatmentHisDTO treatDo = null; for (TreatmentHisDTO treat : treatList) { if (ReservationConstants.TUMOR_HOSP_NAME.equals(treat.getTreatOrg())) { treatDo = treat; break; } } if ((null == treatDo) || StringUtils.isBlank(treatDo.getDisease())) { tumorInfo.setDiseaseHisExist(ReservationConstants.TUMOR_DISEASE_EXIST_NO); } else { String disease = treatDo.getDisease(); String[] diseaseArr = disease.split(";"); for (String disName : diseaseArr) { if (StringUtils.isBlank(disName)) { continue; } if (ReservationConstants.TUMOR_DISEASE_NAME_TNB.equals(StringUtils.trim(disName))) { // tumorInfo.setDiabetesHis(ReservationConstants.TUMOR_HIS_FOR_YES); } else if (ReservationConstants.TUMOR_DISEASE_NAME_GXY.equals(StringUtils.trim(disName))) { // tumorInfo.setHypertensionHis(ReservationConstants.TUMOR_HIS_FOR_YES); } else if (ReservationConstants.TUMOR_DISEASE_NAME_FQZ.equals(StringUtils.trim(disName))) { // tumorInfo.setEmphysemaHis(ReservationConstants.TUMOR_HIS_FOR_YES); } else if (StringUtils.contains(disName, ReservationConstants.TUMOR_HIS_CHRONIC_OTHERS)) { // tumorInfo.setOtherHisStatus(ReservationConstants.TUMOR_HIS_FOR_YES); tumorInfo.setOtherHis(StringUtils.substring(disName, disName.indexOf(":") + 1)); } } tumorInfo.setHealthRecordIdForChronicDisease(treatDo.getId()); tumorInfo.setDiseaseHisExist(ReservationConstants.TUMOR_DISEASE_EXIST_YES); } } jsonMap.put("postTumorInfoVO", tumorInfo); json.setData(jsonMap); }
From source file:net.triptech.metahive.CalculationParser.java
/** * Builds the calculation.//from w ww .j a v a 2 s . c o m * * @param calculation the calculation * @param values the values * @return the string */ public static String buildCalculation(String calculation, Map<Long, Double> values) { String parsedCalculation = ""; logger.debug("Calculation: " + calculation); logger.debug("Values: " + values); if (StringUtils.isNotBlank(calculation) && values != null) { try { Pattern p = Pattern.compile(regEx); Matcher m = p.matcher(calculation); StringBuffer sb = new StringBuffer(); logger.debug("Regular expression: " + regEx); while (m.find()) { logger.info("Variable instance found: " + m.group()); try { String text = m.group(); Long id = Long.parseLong(StringUtils.substring(text, 1)); logger.info("Variable id: " + id); if (values.containsKey(id)) { logger.debug("Contains variable " + id); double value = values.get(id); logger.debug("Value: " + value); text = String.valueOf(value); } logger.debug("Replacement text: " + text); m.appendReplacement(sb, Matcher.quoteReplacement(text)); } catch (NumberFormatException nfe) { logger.error("Error parsing variable id"); } } m.appendTail(sb); parsedCalculation = sb.toString(); logger.info("Parsed calculation: " + parsedCalculation); } catch (PatternSyntaxException pe) { logger.error("Regex syntax error ('" + pe.getPattern() + "') " + pe.getMessage()); } } return parsedCalculation; }
From source file:net.triptech.metahive.CalculationParser.java
/** * Parses the calculation to identify what variables are referenced in it. * * @param calculation the calculation//from w w w. j a v a 2 s. c o m * @return the list */ public static Set<Long> parseVariableIds(final String calculation) { Set<Long> variableIds = new TreeSet<Long>(); logger.debug("Calculation: " + calculation); if (StringUtils.isNotBlank(calculation)) { try { Pattern p = Pattern.compile(regEx); Matcher m = p.matcher(calculation); logger.debug("Regular expression: " + regEx); while (m.find()) { logger.info("Variable instance found: " + m.group()); try { Long id = Long.parseLong(StringUtils.substring(m.group(), 1)); logger.debug("Variable id: " + id); variableIds.add(id); } catch (NumberFormatException nfe) { logger.error("Error parsing variable id"); } } } catch (PatternSyntaxException pe) { logger.error("Regex syntax error ('" + pe.getPattern() + "') " + pe.getMessage()); } } logger.info(variableIds.size() + " ids found"); return variableIds; }
From source file:net.ymate.framework.core.util.ViewPathUtils.java
private synchronized static void __doInitViewPath() { if (__BASE_VIEW_PATH == null && __PLUGIN_VIEW_PATH == null) { String _viewBasePath = StringUtils.trimToNull(WebMVC.get().getModuleCfg().getBaseViewPath()); if (_viewBasePath == null || !(_viewBasePath = _viewBasePath.replaceAll("\\\\", "/")).startsWith("/WEB-INF/")) { _viewBasePath = "/WEB-INF/templates/"; } else if (!_viewBasePath.endsWith("/")) { _viewBasePath += "/"; }//from w ww . java2 s. c o m __BASE_VIEW_PATH = _viewBasePath; // // WebJSP(??JSP), "/WEB-INF/plugins/ String _viewPluginPath = "/WEB-INF/plugins/"; try { File _pFile = Plugins.get().getPluginFactory().getPluginConfig().getPluginHome(); String _pHome = _pFile == null ? null : _pFile.getPath(); if (_pHome != null && (_pHome = _pHome.replaceAll("\\\\", "/")).contains("/WEB-INF/")) { _viewPluginPath = StringUtils.substring(_pHome, _pHome.indexOf("/WEB-INF/")); if (!_viewPluginPath.endsWith("/")) { _viewPluginPath += "/"; } } } catch (Throwable ignored) { // ???NoClassDefFoundError, ? } __PLUGIN_VIEW_PATH = _viewPluginPath; } }
From source file:net.ymate.platform.base.impl.DefaultModuleLoader.java
/** * @param moduleName ???// w w w . ja va 2 s .c o m * @param configs ??? * @return ?????? */ private Map<String, String> __parseModuleCfg(String moduleName, Properties configs) { Map<String, String> _returnValue = new HashMap<String, String>(); // ????? for (Object _key : configs.keySet()) { String _prefix = "ymp.configs." + moduleName + "."; if (StringUtils.startsWith((String) _key, _prefix)) { String _cfgKey = StringUtils.substring((String) _key, _prefix.length()); String _cfgValue = configs.getProperty((String) _key); _returnValue.put(_cfgKey, _cfgValue); } } return _returnValue; }
From source file:net.ymate.platform.core.support.ConfigBuilder.java
public static ConfigBuilder create(final Properties properties) { ///*from ww w . j a v a 2 s . c om*/ IModuleCfgProcessor _processor = new IModuleCfgProcessor() { @Override public Map<String, String> getModuleCfg(String moduleName) { Map<String, String> _cfgsMap = new HashMap<String, String>(); // ????? for (Object _key : properties.keySet()) { String _prefix = "ymp.configs." + moduleName + "."; if (StringUtils.startsWith((String) _key, _prefix)) { String _cfgKey = StringUtils.substring((String) _key, _prefix.length()); String _cfgValue = properties.getProperty((String) _key); _cfgsMap.put(_cfgKey, _cfgValue); } } return _cfgsMap; } }; // ConfigBuilder _builder = ConfigBuilder.create(_processor) .developMode(new BlurObject(properties.getProperty("ymp.dev_mode")).toBooleanValue()) .packageNames(__doParserArrayStr(properties, "ymp.autoscan_packages")) .excludedFiles(__doParserArrayStr(properties, "ymp.excluded_files")) .excludedModules(__doParserArrayStr(properties, "ymp.excluded_modules")) .locale(StringUtils.trimToNull(properties.getProperty("ymp.i18n_default_locale"))) .i18nEventHandler(ClassUtils.impl(properties.getProperty("ymp.i18n_event_handler_class"), II18NEventHandler.class, ConfigBuilder.class)); // ????? String _prefix = "ymp.params."; for (Object _key : properties.keySet()) { if (StringUtils.startsWith((String) _key, _prefix)) { String _cfgKey = StringUtils.substring((String) _key, _prefix.length()); String _cfgValue = properties.getProperty((String) _key); _builder.param(_cfgKey, _cfgValue); } } // _prefix = "ymp.event."; for (Object _key : properties.keySet()) { if (StringUtils.startsWith((String) _key, _prefix)) { String _cfgKey = StringUtils.substring((String) _key, _prefix.length()); String _cfgValue = properties.getProperty((String) _key); _builder.__eventConfigs.put(_cfgKey, _cfgValue); } } // return _builder; }
From source file:net.ymate.platform.module.WebMvcModule.java
@SuppressWarnings("unchecked") public void initialize(Map<String, String> moduleCfgs) throws Exception { IWebEventHandler _eventHandler = ClassUtils.impl(moduleCfgs.get("base.event_handler_class"), IWebEventHandler.class, WebMvcModule.class); IPluginExtraParser _extraParser = ClassUtils.impl(moduleCfgs.get("base.plugin_extra_parser_class"), IPluginExtraParser.class, WebMvcModule.class); IWebErrorHandler _errorHandler = ClassUtils.impl(moduleCfgs.get("base.error_handler_class"), IWebErrorHandler.class, WebMvcModule.class); IWebMultipartHandler _multipartHandler = ClassUtils.impl(moduleCfgs.get("base.multipart_handler_class"), IWebMultipartHandler.class, WebMvcModule.class); //// ww w .j a va2 s. c o m Locale _locale = MVC.localeFromStr(moduleCfgs.get("base.locale"), null); boolean _i18n = new BlurObject(StringUtils.defaultIfEmpty(moduleCfgs.get("base.i18n"), "false")) .toBooleanValue(); String _charsetEncoding = StringUtils.defaultIfEmpty(moduleCfgs.get("base.charset_encoding"), "UTF-8"); // List<Class<IFilter>> _extraFilters = new ArrayList<Class<IFilter>>(); for (String _extraFilter : StringUtils.split(StringUtils.trimToEmpty(moduleCfgs.get("base.extra_filters")), "|")) { Class<?> _filterClass = ResourceUtils.loadClass(_extraFilter, WebMvcModule.class); if (_filterClass != null && ClassUtils.isInterfaceOf(_filterClass, IFilter.class)) { _extraFilters.add((Class<IFilter>) _filterClass); } } // Map<String, String> _extendParams = new HashMap<String, String>(); for (String _cfgKey : moduleCfgs.keySet()) { if (_cfgKey.startsWith("params")) { _extendParams.put(StringUtils.substring(_cfgKey, 7), moduleCfgs.get(_cfgKey)); } } // String _pluginHome = moduleCfgs.get("base.plugin_home"); if (StringUtils.isNotBlank(_pluginHome)) { if (_pluginHome.startsWith("/WEB-INF/")) { File _pluginHomeFile = new File(RuntimeUtils.getRootPath(), StringUtils.substringAfter(_pluginHome, "/WEB-INF/")); if (_pluginHomeFile.exists() && _pluginHomeFile.isDirectory()) { _pluginHome = _pluginHomeFile.getPath(); } } else if (_pluginHome.contains("${user.dir}")) { _pluginHome = doParseVariableUserDir(_pluginHome); } } // WebMvcConfig _config = new WebMvcConfig(_eventHandler, _extraParser, _errorHandler, _locale, _i18n, _charsetEncoding, _pluginHome, _extendParams, StringUtils.split(moduleCfgs.get("base.controller_packages"), '|')); // _config.setMultipartHandlerClassImpl(_multipartHandler); _config.setRestfulModel( new BlurObject(StringUtils.defaultIfEmpty(moduleCfgs.get("base.restful_model"), "false")) .toBooleanValue()); _config.setConventionModel( new BlurObject(StringUtils.defaultIfEmpty(moduleCfgs.get("base.convention_model"), "true")) .toBooleanValue()); _config.setConventionUrlrewrite( new BlurObject(StringUtils.defaultIfEmpty(moduleCfgs.get("base.convention_urlrewrite"), "false")) .toBooleanValue()); _config.setUrlSuffix(StringUtils.defaultIfEmpty(moduleCfgs.get("base.url_suffix"), "")); _config.setViewPath(StringUtils.defaultIfEmpty(moduleCfgs.get("base.view_path"), "")); _config.setExtraFilters(_extraFilters); _config.setUploadTempDir(StringUtils.defaultIfEmpty(moduleCfgs.get("upload.temp_dir"), System.getProperty("java.io.tmpdir"))); _config.setUploadFileSizeMax( new BlurObject(StringUtils.defaultIfEmpty(moduleCfgs.get("upload.file_size_max"), "-1")) .toIntValue()); _config.setUploadTotalSizeMax( new BlurObject(StringUtils.defaultIfEmpty(moduleCfgs.get("upload.total_size_max"), "-1")) .toIntValue()); _config.setUploadSizeThreshold( new BlurObject(StringUtils.defaultIfEmpty(moduleCfgs.get("upload.size_threshold"), "10240")) .toIntValue()); // _config.setCookiePrefix(StringUtils.defaultIfEmpty(moduleCfgs.get("cookie.prefix"), "")); _config.setCookieDomain(StringUtils.defaultIfEmpty(moduleCfgs.get("cookie.domain"), "")); _config.setCookiePath(StringUtils.defaultIfEmpty(moduleCfgs.get("cookie.path"), "/")); _config.setCookieAuthKey(StringUtils.defaultIfEmpty(moduleCfgs.get("cookie.auth_key"), "")); // WebMVC.initialize(_config); }
From source file:net.ymate.platform.mvc.web.support.TemplateHelper.java
/** * @return ??'/WEB-INF''/'?//from ww w. j a v a 2 s . co m */ public static String getPluginViewPath() { if (__PLUGIN_VIEW_PATH == null) { synchronized (__LOCKER) { String _pHome = WebMVC.getConfig().getPluginHome(); if (StringUtils.isNotBlank(_pHome) && (_pHome = _pHome.replaceAll("\\\\", "/")).contains("/WEB-INF/")) { __PLUGIN_VIEW_PATH = StringUtils.substring(_pHome, _pHome.indexOf("/WEB-INF/")); if (!__PLUGIN_VIEW_PATH.endsWith("/")) { __PLUGIN_VIEW_PATH += "/"; } } else { __PLUGIN_VIEW_PATH = "/WEB-INF/plugins/"; // WebJSP(??JSP), "/WEB-INF/plugins/ } } } return __PLUGIN_VIEW_PATH; }
From source file:net.ymate.platform.persistence.jdbc.impl.DefaultModuleCfg.java
/** * @param dsName ????//from w w w . j av a 2 s . c o m * @param _moduleCfgs ??? * @return ????? * @throws Exception ? */ @SuppressWarnings("unchecked") protected DataSourceCfgMeta __doParserDataSourceCfgMeta(String dsName, Map<String, String> _moduleCfgs) throws Exception { Map<String, String> _dataSourceCfgs = new HashMap<String, String>(); for (Map.Entry<String, String> _cfgEntry : _moduleCfgs.entrySet()) { String _key = _cfgEntry.getKey(); String _prefix = "ds." + dsName + "."; if (StringUtils.startsWith(_key, _prefix)) { String _cfgKey = StringUtils.substring(_key, _prefix.length()); _dataSourceCfgs.put(_cfgKey, _cfgEntry.getValue()); } } if (!_dataSourceCfgs.isEmpty()) { // DataSourceCfgMeta _meta = new DataSourceCfgMeta(); _meta.setName(dsName); _meta.setConnectionUrl(_dataSourceCfgs.get("connection_url")); _meta.setUsername(_dataSourceCfgs.get("username")); // ?? if (StringUtils.isNotBlank(_meta.getConnectionUrl()) && StringUtils.isNotBlank(_meta.getUsername())) { // ? _meta.setIsShowSQL(new BlurObject(_dataSourceCfgs.get("show_sql")).toBooleanValue()); _meta.setTablePrefix(_dataSourceCfgs.get("table_prefix")); // ??? String _adapterClassName = JDBC.DS_ADAPTERS .get(StringUtils.defaultIfBlank(_dataSourceCfgs.get("adapter_class"), "default")); _meta.setAdapterClass((Class<? extends IDataSourceAdapter>) ClassUtils.loadClass(_adapterClassName, this.getClass())); // // ? try { _meta.setType(JDBC.DATABASE .valueOf(StringUtils.defaultIfBlank(_dataSourceCfgs.get("type"), "").toUpperCase())); } catch (IllegalArgumentException e) { // ?? String _connUrl = URI.create(_meta.getConnectionUrl()).toString(); String[] _type = StringUtils.split(_connUrl, ":"); if (_type != null && _type.length > 0) { if (_type[1].equals("microsoft")) { _type[1] = "sqlserver"; } _meta.setType(JDBC.DATABASE.valueOf(_type[1].toUpperCase())); } } // _meta.setDialectClass(_dataSourceCfgs.get("dialect_class")); _meta.setDriverClass(StringUtils.defaultIfBlank(_dataSourceCfgs.get("driver_class"), JDBC.DB_DRIVERS.get(_meta.getType()))); _meta.setPassword(_dataSourceCfgs.get("password")); _meta.setIsPasswordEncrypted( new BlurObject(_dataSourceCfgs.get("password_encrypted")).toBooleanValue()); // if (_meta.isPasswordEncrypted() && StringUtils.isNotBlank(_meta.getPassword()) && StringUtils.isNotBlank(_dataSourceCfgs.get("password_class"))) { _meta.setPasswordClass((Class<? extends IPasswordProcessor>) ClassUtils .loadClass(_dataSourceCfgs.get("password_class"), this.getClass())); } // return _meta; } } return null; }