public Template( final String name, final String text, final TemplateEntity entity, final TemplateType type, final List<TemplateMapper> mappers) { this.name = StringUtils.defaultIfEmpty(name, null); this.entity = entity; this.type = type; this.text = StringUtils.defaultIfEmpty(text, null); this.mappers = mappers; }
/** * Constructor * * @param groupId the Maven groupId, explicit or inherited (required) * @param artifactId the Maven artifactId (required) * @param version the version of the artifact being built (required) * @param packaging the Maven packaging (required) * @param dependencies (can be <code>null</code> for none) * @param parent the POM's parent declaration (can be <code>null</code> for none) * @param modules the modules defined by this POM (only applies when packaging is "pom"; can be * <code>null</code> for none) * @param pomProperties any properties defined in the POM (can be <code>null</code> for none) * @param name the Maven name of the artifact being built (can be blank) * @param repositories any repositories defined in the POM (can be <code>null</code> for none) * @param pluginRepositories any plugin repositories defined in the POM (can be <code>null</code> * for none) * @param sourceDirectory the directory relative to the POM that contains production code (can be * blank for the Maven default) * @param testSourceDirectory the directory relative to the POM that contains test code (can be * blank for the Maven default) * @param filters any filters defined in the POM (can be <code>null</code> for none) * @param buildPlugins any plugins defined in the POM (can be <code>null</code> for none) * @param resources any build resources defined in the POM (can be <code>null</code> for none) * @param path the canonical path of this POM (required) * @param moduleName the Maven name of this module (blank for the project's root or only POM) * @param paths the {@link Path}s required for this module, in addition to the root (can be <code> * null</code>) */ public Pom( final String groupId, final String artifactId, final String version, final String packaging, final Collection<? extends Dependency> dependencies, final Parent parent, final Collection<? extends Module> modules, final Collection<? extends Property> pomProperties, final String name, final Collection<? extends Repository> repositories, final Collection<? extends Repository> pluginRepositories, final String sourceDirectory, final String testSourceDirectory, final Collection<? extends Filter> filters, final Collection<? extends Plugin> buildPlugins, final Collection<? extends Resource> resources, final String path, final String moduleName, final Collection<Path> paths) { Validate.notBlank(packaging, "Invalid packaging '%s'", packaging); Validate.notBlank(path, "Invalid path '%s'", path); // gav = new GAV(groupId, artifactId, version); this.moduleName = StringUtils.stripToEmpty(moduleName); this.name = StringUtils.stripToEmpty(name); this.packaging = packaging; this.parent = parent; if (version == null && parent.getVersion() != null) { gav = new GAV(groupId, artifactId, parent.getVersion()); } else { gav = new GAV(groupId, artifactId, version); } this.path = path; this.sourceDirectory = StringUtils.defaultIfEmpty(sourceDirectory, Path.SRC_MAIN_JAVA.getDefaultLocation()); this.testSourceDirectory = StringUtils.defaultIfEmpty(testSourceDirectory, Path.SRC_TEST_JAVA.getDefaultLocation()); CollectionUtils.populate(this.buildPlugins, buildPlugins); CollectionUtils.populate(this.dependencies, dependencies); CollectionUtils.populate(this.filters, filters); CollectionUtils.populate(this.modules, modules); CollectionUtils.populate(this.pluginRepositories, pluginRepositories); CollectionUtils.populate(this.pomProperties, pomProperties); CollectionUtils.populate(this.repositories, repositories); CollectionUtils.populate(this.resources, resources); cachePhysicalPaths(paths); }
/** * Default constructor. * * @throws IOException I/O error. */ public ConfigService() { super(); final Properties props = new Properties(); try (final InputStream input = this.getClass().getResourceAsStream("/config/defaultConfig.properties")) { props.load(input); } catch (final IOException ex) { ConfigService.LOG.error(ex.getMessage(), ex); } this.configFile = new File(StringUtils.defaultIfEmpty(props.getProperty("config.dir"), "/etc/dederem.conf")); this.repoDir = new File(StringUtils.defaultIfEmpty(props.getProperty("repo.dir"), "/opt/dederem")); }
@Override public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { String signature = StringUtils.defaultIfEmpty(request.getParameter("signature"), ""); String timestamp = StringUtils.defaultIfEmpty(request.getParameter("timestamp"), ""); String nonce = StringUtils.defaultIfEmpty(request.getParameter("nonce"), ""); String echostr = StringUtils.defaultIfEmpty(request.getParameter("echostr"), ""); String result = Tools.codeWeChar(signature, nonce); if (signature.equals(result)) { response.getWriter().append(echostr); } else { logger.info( "timestamp:{" + timestamp + "};nonce:{" + nonce + "};signature:{" + signature + "}"); } }
/** {@inheritDoc} */ @Override protected List<Node> getMarkupSubstitutes(final Arguments arguments, final Element element) { final List<Node> nodes = new ArrayList<>(); final Configuration configuration = arguments.getConfiguration(); // Obtain the attribute value final IWebContext context = (IWebContext) arguments.getContext(); final String contextPath = StringUtils.defaultIfEmpty( element.getAttributeValue(SpringHrefAttrProcessor.ATTR_NAME), context.getServletContext().getContextPath()); // Obtain the Thymeleaf Standard Expression parser final IStandardExpressionParser parser = StandardExpressions.getExpressionParser(configuration); // Parse the attribute value as a Thymeleaf Standard Expression final String pageAttrValue = element.getAttributeValue(ATTR_PAGE); final IStandardExpression expression = parser.parseExpression(configuration, arguments, pageAttrValue); Page<?> page = (Page<?>) expression.execute(configuration, arguments); final Element container = new Element("ul"); container.setAttribute("class", "pagination"); container.addChild(getFirstElement(page, contextPath)); container.addChild(getPreviousElement(page, contextPath)); addStepElements(page, contextPath, container); container.addChild(getNextElement(page, contextPath)); container.addChild(getLastElement(page, contextPath)); nodes.add(container); return nodes; }
/** 若字符串为空,则取默认值 */ public static String defaultIfEmpty(String str, String defaultValue) { return StringUtils.defaultIfEmpty(str, defaultValue); }
/** * 保存预约信息 * * @param request * @param order * @param modelMap */ @RequestMapping("add_preOrder") public void addPreOrder(HttpServletRequest request, Order order, ModelMap modelMap) { // 预约者电话 String telephone = this.findStringParameterValue(request, "orderTel"); // 验证码 String verifyCode = this.findStringParameterValue(request, "verifyCode"); if (StringUtils.equals(verifyCode, (String) request.getSession().getAttribute(telephone))) { // 房屋ID String houseId = this.findStringParameterValue(request, "houseId"); // 预约者微信ID order.setWeixinId(StringUtils.defaultIfEmpty(order.getWeixinId(), "weixinId")); // 公寓房源编号 order.setHouseId(houseId); // 预约日期 String orderDate = this.findStringParameterValue(request, "orderDate"); order.setOrderDate(orderDate); // 联系电话 order.setTelephone(telephone); // 检查该微信用户是否已预约了该房源 int count = orderService.queryOrderCountByHouseIdAndWeixinIdAndOrderDate( order.getWeixinId(), houseId, orderDate); if (count == 0) { // 保存预约信息 orderService.addPreOrder(order); // 清空Session中保存的该手机号的验证码 request.getSession().removeAttribute(telephone); // 取得预约房源的信息 HouseWrapVo houseInfo = houseService.findHouseInfoByHouseId(houseId); // 房屋描述信息 StringBuilder houseDesc = new StringBuilder(); // 小区名称+楼号+房间数 houseDesc.append(houseInfo.getCommunityName()).append(" "); if (StringUtils.isNotBlank(houseInfo.getBuildingNo())) { houseDesc.append(houseInfo.getBuildingNo()).append("号楼"); } if (StringUtils.isNotBlank(houseInfo.getLayout())) { if (ERenovation.BAY.getCode().equals(houseInfo.getLayout())) { houseDesc.append("开间"); } else { houseDesc.append(houseInfo.getLayout()).append("室"); } } if (StringUtils.isNotBlank(houseInfo.getUseArea())) { houseDesc.append(" "); houseDesc.append(houseInfo.getUseArea().replaceAll("\\.\\d*$", "")).append("平米"); } if (houseInfo.getLongPrice() != null) { houseDesc.append(" "); houseDesc .append(houseInfo.getLongPrice().toPlainString().replaceAll("\\.\\d*$", "")) .append("元/月"); } // 编辑地址 String houseAddress = houseInfo.getStreet(); DateFormat dateFormat = new SimpleDateFormat(Constants.DATE_FORMAT_NO_SEPARATOR); StringBuilder orderTimeDisplayBul = new StringBuilder(); try { Date date = dateFormat.parse(orderDate); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); int weedDay = calendar.get(Calendar.DAY_OF_WEEK); orderTimeDisplayBul.append( DateUtil.getFmtDate(orderDate, Constants.DATE_FORMAT_NO_SEPARATOR, "yyyy年MM月dd日")); orderTimeDisplayBul.append(" ").append(EWeekDayType.getNameByCode(weedDay)); } catch (ParseException e) { logger.error("预约日期格式解析错误", e); } String orderDateDisplay = orderTimeDisplayBul.toString(); modelMap.put("success", true); modelMap.put("description", houseDesc.toString()); modelMap.put("houseTel", houseInfo.getTelephone()); modelMap.put("houseAdd", houseAddress); modelMap.put("orderDate", orderDateDisplay); // TODO 向用户微信发送预约消息 // ServletContext sevletContext = request.getSession() // .getServletContext(); // // 获取微信access_token // String accessToken = (String) sevletContext // .getAttribute(Constants.WEIXIN_ACCESS_TOKEN); // // 尝试从application context中取得access_token信息 // Integer validSecond = (Integer) sevletContext // .getAttribute(Constants.WEIXIN_ACCESS_TOKEN_VALID_TIME); // Long accessTokenCallTime = (Long) sevletContext // .getAttribute(Constants.ACCESS_TOKEN_CALL_TIME); // // 获取access_token失败标志 // boolean getAccessTokenFailFlag = false; // // 判定application context范围内的微信access_token信息是否存在且是否有效 // if (StringUtils.isEmpty(accessToken) // || (System.currentTimeMillis() - accessTokenCallTime) <= validSecond) { // // 不存在或者已失效 // String accessTokenInfo = getAccessTokenService.getAccessToken(); // if (StringUtils.isEmpty(accessTokenInfo)) { // log.error("微信access_token获取失败!"); // getAccessTokenFailFlag = true; // } else { // int underScoreIndex = accessTokenInfo // .indexOf(GetAccessTokenService.ACCESS_TOKEN_INFO_SEPERATOR); // validSecond = Integer.valueOf(accessTokenInfo.substring(0, // underScoreIndex)); // accessToken = accessTokenInfo // .substring(underScoreIndex + 1); // accessTokenCallTime = System.currentTimeMillis(); // // // 将取得的access_token信息保存至application context范围内 // sevletContext.setAttribute(Constants.WEIXIN_ACCESS_TOKEN, // accessToken); // sevletContext.setAttribute( // Constants.WEIXIN_ACCESS_TOKEN_VALID_TIME, // validSecond); // sevletContext.setAttribute( // Constants.ACCESS_TOKEN_CALL_TIME, // accessTokenCallTime); // } // } // // if (!getAccessTokenFailFlag // && sendOrderMessageToWeixinUser(accessToken, // order.getWeixinId(), orderDateDisplay, // houseDesc.toString(), houseInfo.getTelephone())) { // log.error("预约微信发送失败![clientTel:" + telephone + ", orderTime:" // + orderDateDisplay + ", houseAddress:" + houseAddress // + ", houseTel:" + houseInfo.getTelephone() + "]"); // } if (!sendOrderMessageToCusetomerService( telephone, orderDateDisplay, houseDesc.toString(), houseInfo.getTelephone(), houseInfo.getBrandName())) { log.error( "预约邮件发送失败![clientTel:" + telephone + ", orderTime:" + orderDateDisplay + ", houseAddress:" + houseAddress + ", houseTel:" + houseInfo.getTelephone() + "]"); } } else { modelMap.put("success", false); modelMap.put("message", "已预约过在您指定的日期看该房源!"); } } else { modelMap.put("success", false); modelMap.put("message", "输入的验证码有误,请重新输入!"); } }