下面列出了org.apache.commons.lang3.StringUtils#trim ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void doHandle(MoliCodeContext context) {
String content = context.getDataString(MoliCodeConstant.CTX_KEY_SRC_CONTENT);
content = StringUtils.trim(content);
if (StringUtils.isEmpty(content)) {
LogHelper.DEFAULT.warn("输入数据为空! 数据处理失败");
return;
}
if (content.startsWith("[")) {
context.put(MoliCodeConstant.CTX_KEY_DEF_DATA, JSON.parseArray(content));
} else if (content.startsWith("{")) {
context.put(MoliCodeConstant.CTX_KEY_DEF_DATA, JSON.parseObject(content));
} else {
throw new AutoCodeException("非合法的JSON数据格式,content=" + content, ResultCodeEnum.PARAM_ERROR);
}
}
public void setRssTitleByTitle(String title) {
Pattern pattern = Pattern.compile(".*(e\\d{2,}).*", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(title);
String rssTitle = title;
if (matcher.matches()) {
rssTitle = rssTitle.substring(0, matcher.start(1)).replaceAll("\\.", "");
}
// pattern = Pattern.compile("\\d{1,}-\\d{1,}회 합본");
pattern = Pattern.compile("E{0,1}\\d{1,}.{0,1}E{0,1}\\d{1,}회.{0,1}합본");
rssTitle = RegExUtils.removeAll(rssTitle, pattern);
pattern = Pattern.compile("\\[[^\\]]{1,}\\]");
rssTitle = RegExUtils.removeAll(rssTitle, pattern);
this.rssTitle = StringUtils.trim(rssTitle);
}
public Set<String> parseScope(String scope)
{
if (scope == null) {
return null;
}
Scanner scanner = new Scanner(StringUtils.trim(scope));
try {
scanner.useDelimiter(" ");
Set<String> result = new HashSet<>();
while (scanner.hasNext(SCOPE_PATTERN))
{
String scopeToken = scanner.next(SCOPE_PATTERN);
result.add(scopeToken);
}
return result;
} finally {
scanner.close();
}
}
/**
* Called by Velocity to initialize the loader
* @param configuration
*/
public void init( ExtProperties configuration)
{
log.trace("JarResourceLoader: initialization starting.");
List paths = configuration.getList(RuntimeConstants.RESOURCE_LOADER_PATHS);
if (paths != null)
{
log.debug("JarResourceLoader # of paths: {}", paths.size() );
for (ListIterator<String> it = paths.listIterator(); it.hasNext(); )
{
String jar = StringUtils.trim(it.next());
it.set(jar);
loadJar(jar);
}
}
log.trace("JarResourceLoader: initialization complete.");
}
/**
* Allows an external caller to get a property. The calling
* routine is required to know the type, as this routine
* will return an Object, as that is what properties can be.
*
* @param key property to return
* @return Value of the property or null if it does not exist.
*/
public Object getProperty(String key)
{
Object o = null;
/**
* Before initialization, check the user-entered properties first.
*/
if (!initialized && overridingProperties != null)
{
o = overridingProperties.get(key);
}
/**
* After initialization, configuration will hold all properties.
*/
if (o == null)
{
o = configuration.getProperty(key);
}
if (o instanceof String)
{
return StringUtils.trim((String) o);
}
else
{
return o;
}
}
protected String makeValidFilterText(String filterText) {
String validFilter = null;
if (filterText != null) {
String trimmed = StringUtils.trim(filterText);
if (trimmed.length() >= MIN_FILTER_LENGTH) {
validFilter = "%" + trimmed.toLowerCase() + "%";
}
}
return validFilter;
}
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, String id, Integer count, JsonElement jsonElement)
throws Exception {
ActionResult<List<Wo>> result = new ActionResult<>();
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
EqualsTerms equals = new EqualsTerms();
InTerms ins = new InTerms();
LikeTerms likes = new LikeTerms();
equals.put(Read.person_FIELDNAME, effectivePerson.getDistinguishedName());
if (ListTools.isNotEmpty(wi.getApplicationList())) {
ins.put(Read.application_FIELDNAME, wi.getApplicationList());
}
if (ListTools.isNotEmpty(wi.getProcessList())) {
ins.put(Read.process_FIELDNAME, wi.getProcessList());
}
if (ListTools.isNotEmpty(wi.getCreatorUnitList())) {
ins.put(Read.creatorUnit_FIELDNAME, wi.getCreatorUnitList());
}
if (ListTools.isNotEmpty(wi.getStartTimeMonthList())) {
ins.put(Read.startTimeMonth_FIELDNAME, wi.getStartTimeMonthList());
}
if (ListTools.isNotEmpty(wi.getActivityNameList())) {
ins.put(Read.activityName_FIELDNAME, wi.getActivityNameList());
}
if (StringUtils.isNotEmpty(wi.getKey())) {
String key = StringUtils.trim(StringUtils.replace(wi.getKey(), "\u3000", " "));
if (StringUtils.isNotEmpty(key)) {
likes.put(Read.title_FIELDNAME, key);
likes.put(Read.opinion_FIELDNAME, key);
likes.put(Read.serial_FIELDNAME, key);
likes.put(Read.creatorPerson_FIELDNAME, key);
likes.put(Read.creatorUnit_FIELDNAME, key);
}
}
result = this.standardListPrev(Wo.copier, id, count, Read.sequence_FIELDNAME, equals, null, likes, ins, null,
null, null, null, true, DESC);
return result;
}
public static String getValueFromFile(String path, String key) throws Exception {
try (BufferedReader br = new BufferedReader(new FileReader(path))) {
String line;
while ((line = br.readLine()) != null) {
if (line.matches(key + "\\s*=.*")) {
return StringUtils.trim(StringUtils.split(line, "=")[1]);
}
}
return null;
} catch (Exception e) {
throw e;
}
}
public static String readCfg(String path, String defaultValue) throws Exception {
String str = readCfg(path);
if (StringUtils.isEmpty(str)) {
str = defaultValue;
}
return (StringUtils.trim(str));
}
/**
* GET /rest/activiti/jobs/{jobId}/exception-stracktrace -> return job stacktrace
*/
@RequestMapping(value = "/rest/activiti/jobs/{jobId}/stacktrace", method = RequestMethod.GET, produces = "text/plain")
public String getJobStacktrace(@PathVariable String jobId) throws BadRequestException {
ServerConfig serverConfig = retrieveServerConfig();
try {
String trace = clientService.getJobStacktrace(serverConfig, jobId);
if(trace != null) {
trace = StringUtils.trim(trace);
}
return trace;
} catch (ActivitiServiceException e) {
throw new BadRequestException(e.getMessage());
}
}
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, String id, Integer count, JsonElement jsonElement)
throws Exception {
ActionResult<List<Wo>> result = new ActionResult<>();
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
EqualsTerms equals = new EqualsTerms();
InTerms ins = new InTerms();
LikeTerms likes = new LikeTerms();
equals.put(Task.person_FIELDNAME, effectivePerson.getDistinguishedName());
if (ListTools.isNotEmpty(wi.getApplicationList())) {
ins.put(Task.application_FIELDNAME, wi.getApplicationList());
}
if (ListTools.isNotEmpty(wi.getProcessList())) {
ins.put(Task.process_FIELDNAME, wi.getProcessList());
}
if (ListTools.isNotEmpty(wi.getCreatorUnitList())) {
ins.put(Task.creatorUnit_FIELDNAME, wi.getCreatorUnitList());
}
if (ListTools.isNotEmpty(wi.getStartTimeMonthList())) {
ins.put(Task.startTimeMonth_FIELDNAME, wi.getStartTimeMonthList());
}
if (ListTools.isNotEmpty(wi.getActivityNameList())) {
ins.put(Task.activityName_FIELDNAME, wi.getActivityNameList());
}
if (StringUtils.isNotEmpty(wi.getKey())) {
String key = StringUtils.trim(StringUtils.replace(wi.getKey(), "\u3000", " "));
if (StringUtils.isNotEmpty(key)) {
likes.put(Task.title_FIELDNAME, key);
likes.put(Task.opinion_FIELDNAME, key);
likes.put(Task.serial_FIELDNAME, key);
likes.put(Task.creatorPerson_FIELDNAME, key);
likes.put(Task.creatorUnit_FIELDNAME, key);
}
}
result = this.standardListNext(Wo.copier, id, count, Task.sequence_FIELDNAME, equals, null, likes, ins, null,
null, null, null, true, DESC);
return result;
}
public static GroupConfig findGroupByName(String groupName, ConfigManager configManager) {
groupName = StringUtils.trim(groupName);
if (configManager == null) {
return null;
}
Map<String, GroupConfig> groups = configManager.getCurGroupConfigMap();
return groups == null ? null : groups.get(groupName);
}
public static String getClassName(String code) {
String className = StringUtils.substringBefore(code, "{");
if (StringUtils.isBlank(className)) {
return className;
}
if (StringUtils.contains(code, " class ")) {
className = StringUtils.substringAfter(className, " class ");
if (StringUtils.contains(className, " extends ")) {
className = StringUtils.substringBefore(className, " extends ").trim();
} else if (StringUtils.contains(className, " implements ")) {
className = StringUtils.trim(StringUtils.substringBefore(className, " implements "));
} else {
className = StringUtils.trim(className);
}
} else if (StringUtils.contains(code, " interface ")) {
className = StringUtils.substringAfter(className, " interface ");
if (StringUtils.contains(className, " extends ")) {
className = StringUtils.substringBefore(className, " extends ").trim();
} else {
className = StringUtils.trim(className);
}
} else if (StringUtils.contains(code, " enum ")) {
className = StringUtils.trim(StringUtils.substringAfter(className, " enum "));
} else {
return StringUtils.EMPTY;
}
return className;
}
public static String getClassName(String code) {
String className = StringUtils.substringBefore(code, "{");
if (StringUtils.isBlank(className)) {
return className;
}
if (StringUtils.contains(code, " class ")) {
className = StringUtils.substringAfter(className, " class ");
if (StringUtils.contains(className, " extends ")) {
className = StringUtils.substringBefore(className, " extends ").trim();
} else if (StringUtils.contains(className, " implements ")) {
className = StringUtils.trim(StringUtils.substringBefore(className, " implements "));
} else {
className = StringUtils.trim(className);
}
} else if (StringUtils.contains(code, " interface ")) {
className = StringUtils.substringAfter(className, " interface ");
if (StringUtils.contains(className, " extends ")) {
className = StringUtils.substringBefore(className, " extends ").trim();
} else {
className = StringUtils.trim(className);
}
} else if (StringUtils.contains(code, " enum ")) {
className = StringUtils.trim(StringUtils.substringAfter(className, " enum "));
} else {
return StringUtils.EMPTY;
}
return className;
}
public void OnRtnTrade(CThostFtdcTradeField pTrade) {
try {
String exchangeAndOrderSysId = pTrade.getExchangeID() + "@" + pTrade.getOrderSysID();
String orderId = exchangeIdAndOrderSysIdToOrderIdMap.getOrDefault(exchangeAndOrderSysId, "");
String adapterOrderId = orderIdToAdapterOrderIdMap.getOrDefault(orderId, "");
String symbol = pTrade.getInstrumentID();
DirectionEnum direction = CtpConstant.directionMapReverse.getOrDefault(pTrade.getDirection(), DirectionEnum.D_Unknown);
String adapterTradeId = adapterOrderId + "@" + direction.getValueDescriptor().getName() + "@" + StringUtils.trim(pTrade.getTradeID());
String tradeId = gatewayId + "@" + adapterTradeId;
OffsetFlagEnum offsetFlag = CtpConstant.offsetMapReverse.getOrDefault(pTrade.getOffsetFlag(), OffsetFlagEnum.OF_Unkonwn);
double price = pTrade.getPrice();
int volume = pTrade.getVolume();
String tradeDate = pTrade.getTradeDate();
String tradeTime = pTrade.getTradeTime();
HedgeFlagEnum hedgeFlag = CtpConstant.hedgeFlagMapReverse.getOrDefault(String.valueOf(pTrade.getHedgeFlag()), HedgeFlagEnum.HF_Unknown);
TradeTypeEnum tradeType = CtpConstant.tradeTypeMapReverse.getOrDefault(pTrade.getTradeType(), TradeTypeEnum.TT_Unkonwn);
PriceSourceEnum priceSource = CtpConstant.priceSourceMapReverse.getOrDefault(pTrade.getPriceSource(), PriceSourceEnum.PSRC_Unkonwn);
String orderLocalId = pTrade.getOrderLocalID();
String orderSysId = pTrade.getOrderSysID();
String sequenceNo = pTrade.getSequenceNo() + "";
String brokerOrderSeq = pTrade.getBrokerOrderSeq() + "";
String settlementID = pTrade.getSettlementID() + "";
String originalOrderId = orderIdToOriginalOrderIdMap.getOrDefault(orderId, "");
// 无法获取账户信息,使用userId作为账户ID
String accountCode = userId;
// 无法获取币种信息使用特定值CNY
String accountId = accountCode + "@[email protected]" + gatewayId;
TradeField.Builder tradeBuilder = TradeField.newBuilder();
tradeBuilder.setAccountId(accountId);
tradeBuilder.setAdapterOrderId(adapterOrderId);
tradeBuilder.setAdapterTradeId(adapterTradeId);
tradeBuilder.setTradeDate(tradeDate);
tradeBuilder.setTradeId(tradeId);
tradeBuilder.setTradeTime(tradeTime);
tradeBuilder.setTradingDay(tradingDay);
tradeBuilder.setDirection(direction);
tradeBuilder.setOffsetFlag(offsetFlag);
tradeBuilder.setOrderId(orderId);
tradeBuilder.setOriginOrderId(originalOrderId);
tradeBuilder.setPrice(price);
tradeBuilder.setVolume(volume);
tradeBuilder.setGatewayId(gatewayId);
tradeBuilder.setOrderLocalId(orderLocalId);
tradeBuilder.setOrderSysId(orderSysId);
tradeBuilder.setSequenceNo(sequenceNo);
tradeBuilder.setBrokerOrderSeq(brokerOrderSeq);
tradeBuilder.setSettlementId(settlementID);
tradeBuilder.setHedgeFlag(hedgeFlag);
tradeBuilder.setTradeType(tradeType);
tradeBuilder.setPriceSource(priceSource);
if (instrumentQueried && ctpGatewayImpl.contractMap.containsKey(symbol)) {
tradeBuilder.setContract(ctpGatewayImpl.contractMap.get(symbol));
ctpGatewayImpl.emitTrade(tradeBuilder.build());
} else {
ContractField.Builder contractBuilder = ContractField.newBuilder();
contractBuilder.setSymbol(symbol);
tradeBuilder.setContract(contractBuilder);
tradeBuilderCacheList.add(tradeBuilder);
}
} catch (Throwable t) {
logger.error("{}OnRtnTrade Exception", logInfo, t);
}
}
protected ActionResult<List<Wo>> execute(HttpServletRequest request, EffectivePerson effectivePerson, String id,
Integer count, String appId, JsonElement jsonElement) throws Exception {
ActionResult<List<Wo>> result = new ActionResult<>();
EqualsTerms equals = new EqualsTerms();
LikeTerms likes = new LikeTerms();
Wi wrapIn = null;
Boolean check = true;
WrapCopier<Form, Wo> copier = WrapCopierFactory.wo(Form.class, Wo.class, null, Wo.Excludes);
try {
wrapIn = this.convertToWrapIn(jsonElement, Wi.class);
} catch (Exception e) {
check = false;
Exception exception = new ExceptionWrapInConvert(e, jsonElement);
result.error(exception);
logger.error(e, effectivePerson, request, null);
}
if (check) {
try {
equals.put("appId", appId);
if ((null != wrapIn.getCategoryIdList()) && (!wrapIn.getCategoryIdList().isEmpty())) {
equals.put("categoryId", wrapIn.getCategoryIdList().get(0));
}
if ((null != wrapIn.getCreatorList()) && (!wrapIn.getCreatorList().isEmpty())) {
equals.put("creatorUid", wrapIn.getCreatorList().get(0));
}
if ((null != wrapIn.getStatusList()) && (!wrapIn.getStatusList().isEmpty())) {
equals.put("docStatus", wrapIn.getStatusList().get(0));
}
if (StringUtils.isNotEmpty(wrapIn.getKey())) {
String key = StringUtils.trim(StringUtils.replace(wrapIn.getKey(), "\u3000", " "));
if (StringUtils.isNotEmpty(key)) {
likes.put("title", key);
}
}
result = this.standardListPrev(copier, id, count, "sequence", equals, null, likes, null, null, null,
null, null, true, DESC);
} catch (Throwable th) {
th.printStackTrace();
result.error(th);
}
}
return result;
}
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, String id, Integer count, String applicationFlag,
JsonElement jsonElement) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<List<Wo>> result = new ActionResult<>();
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
Business business = new Business(emc);
EqualsTerms equals = new EqualsTerms();
InTerms ins = new InTerms();
LikeTerms likes = new LikeTerms();
Application application = business.application().pick(applicationFlag);
if (null == application) {
throw new ExceptionApplicationNotExist(applicationFlag);
}
equals.put("application", application.getId());
if (ListTools.isNotEmpty(wi.getProcessList())) {
ins.put("process", wi.getProcessList());
}
if (ListTools.isNotEmpty(wi.getCreatorUnitList())) {
ins.put("creatorUnit", wi.getCreatorUnitList());
}
if (ListTools.isNotEmpty(wi.getStartTimeMonthList())) {
ins.put("startTimeMonth", wi.getStartTimeMonthList());
}
if (ListTools.isNotEmpty(wi.getActivityNameList())) {
ins.put("activityName", wi.getActivityNameList());
}
if (ListTools.isNotEmpty(wi.getWorkStatusList())) {
ins.put("workStatus", wi.getWorkStatusList());
}
if (StringUtils.isNotEmpty(wi.getKey())) {
String key = StringUtils.trim(StringUtils.replace(wi.getKey(), "\u3000", " "));
if (StringUtils.isNotEmpty(key)) {
likes.put("title", key);
likes.put("serial", key);
likes.put("creatorPerson", key);
likes.put("creatorUnit", key);
}
}
result = this.standardListPrev(Wo.copier, id, count, JpaObject.sequence_FIELDNAME, equals, null, likes, ins, null, null, null,
null, true, DESC);
/* 添加权限 */
if (null != result.getData()) {
for (Wo wo : result.getData()) {
Work o = emc.find(wo.getId(), Work.class);
WorkControl control = business.getControl(effectivePerson, o, WoControl.class);
wo.setControl(control);
}
}
return result;
}
}
private List<Read> list(EffectivePerson effectivePerson, Business business, Integer adjustPage,
Integer adjustPageSize, Wi wi) throws Exception {
EntityManager em = business.entityManagerContainer().get(Read.class);
List<String> person_ids = business.organization().person().list(wi.getCredentialList());
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Read> cq = cb.createQuery(Read.class);
Root<Read> root = cq.from(Read.class);
Predicate p = cb.conjunction();
if (ListTools.isNotEmpty(wi.getApplicationList())) {
p = cb.and(p, root.get(Read_.application).in(wi.getApplicationList()));
}
if (ListTools.isNotEmpty(wi.getProcessList())) {
p = cb.and(p, root.get(Read_.process).in(wi.getProcessList()));
}
if(DateTools.isDateTimeOrDate(wi.getStartTime())){
p = cb.and(p, cb.greaterThan(root.get(Read_.startTime), DateTools.parse(wi.getStartTime())));
}
if(DateTools.isDateTimeOrDate(wi.getEndTime())){
p = cb.and(p, cb.lessThan(root.get(Read_.startTime), DateTools.parse(wi.getEndTime())));
}
if (ListTools.isNotEmpty(person_ids)) {
p = cb.and(p, root.get(Read_.person).in(person_ids));
}
if (ListTools.isNotEmpty(wi.getCreatorUnitList())) {
p = cb.and(p, root.get(Read_.creatorUnit).in(wi.getCreatorUnitList()));
}
if (ListTools.isNotEmpty(wi.getWorkList())) {
p = cb.and(p, root.get(Read_.work).in(wi.getWorkList()));
}
if (ListTools.isNotEmpty(wi.getJobList())) {
p = cb.and(p, root.get(Read_.job).in(wi.getJobList()));
}
if (ListTools.isNotEmpty(wi.getStartTimeMonthList())) {
p = cb.and(p, root.get(Read_.startTimeMonth).in(wi.getStartTimeMonthList()));
}
if (ListTools.isNotEmpty(wi.getActivityNameList())) {
p = cb.and(p, root.get(Read_.activityName).in(wi.getActivityNameList()));
}
if (StringUtils.isNotEmpty(wi.getKey())) {
String key = StringUtils.trim(StringUtils.replace(wi.getKey(), "\u3000", " "));
if (StringUtils.isNotEmpty(key)) {
key = StringUtils.replaceEach(key, new String[] { "?", "%" }, new String[] { "", "" });
p = cb.and(p,
cb.or(cb.like(root.get(Read_.title), "%" + key + "%"),
cb.like(root.get(Read_.opinion), "%" + key + "%"),
cb.like(root.get(Read_.serial), "%" + key + "%"),
cb.like(root.get(Read_.creatorPerson), "%" + key + "%"),
cb.like(root.get(Read_.creatorUnit), "%" + key + "%")));
}
}
cq.select(root).where(p).orderBy(cb.desc(root.get(Read_.startTime)));
return em.createQuery(cq).setFirstResult((adjustPage - 1) * adjustPageSize).setMaxResults(adjustPageSize)
.getResultList();
}
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, String id, Integer count, JsonElement jsonElement)
throws Exception {
ActionResult<List<Wo>> result = new ActionResult<>();
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
List<String> person_ids = business.organization().person().list(wi.getCredentialList());
EqualsTerms equals = new EqualsTerms();
InTerms ins = new InTerms();
LikeTerms likes = new LikeTerms();
if (ListTools.isNotEmpty(wi.getApplicationList())) {
ins.put(Task.application_FIELDNAME, wi.getApplicationList());
}
if (ListTools.isNotEmpty(wi.getProcessList())) {
ins.put(Task.process_FIELDNAME, wi.getProcessList());
}
if (ListTools.isNotEmpty(person_ids)) {
ins.put(Task.person_FIELDNAME, person_ids);
}
if (ListTools.isNotEmpty(wi.getCreatorUnitList())) {
ins.put(Task.creatorUnit_FIELDNAME, wi.getCreatorUnitList());
}
if (ListTools.isNotEmpty(wi.getStartTimeMonthList())) {
ins.put(Task.startTimeMonth_FIELDNAME, wi.getStartTimeMonthList());
}
if (ListTools.isNotEmpty(wi.getActivityNameList())) {
ins.put(Task.activityName_FIELDNAME, wi.getActivityNameList());
}
if (StringUtils.isNotEmpty(wi.getKey())) {
String key = StringUtils.trim(StringUtils.replace(wi.getKey(), "\u3000", " "));
if (StringUtils.isNotEmpty(key)) {
likes.put(Task.title_FIELDNAME, key);
likes.put(Task.opinion_FIELDNAME, key);
likes.put(Task.serial_FIELDNAME, key);
likes.put(Task.creatorPerson_FIELDNAME, key);
likes.put(Task.creatorUnit_FIELDNAME, key);
}
}
if (effectivePerson.isManager()) {
result = this.standardListPrev(Wo.copier, id, count, Task.sequence_FIELDNAME, equals, null, likes, ins, null,
null, null, null, true, DESC);
}
return result;
}
}
@PostMapping(value = "/group/{version:.+}")
public ModelAndView createGroup(@PathVariable String version, String newGroup) {
version = StringUtils.trim(version);
newGroup = StringUtils.trim(newGroup.trim());
final String root = getRoot();
final String groupPath = makePaths(root, version, newGroup);
nodeService.createProperty(groupPath);
return new ModelAndView("redirect:/version/" + version);
}