From 7ea90284e799337eb65e15d41774aba1aac852a8 Mon Sep 17 00:00:00 2001 From: LamGC Date: Thu, 19 Nov 2020 14:13:54 +0800 Subject: [PATCH] =?UTF-8?q?[Add]=20Core=20=E6=B7=BB=E5=8A=A0=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E5=86=85=E9=83=A8=E4=BD=BF=E7=94=A8(=E4=B9=9F?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E4=BC=9A=E7=94=A8=E5=88=B0=E6=A8=A1=E7=89=88?= =?UTF-8?q?=E4=B8=8A)=E7=9A=84=20BotCode=20=E5=AE=9E=E7=8E=B0;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [Add] BasicBotCode 添加内部实现的 BotCode; --- .../cgj/bot/framework/base/BasicBotCode.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 ContentGrabbingJi-core/src/main/java/net/lamgc/cgj/bot/framework/base/BasicBotCode.java diff --git a/ContentGrabbingJi-core/src/main/java/net/lamgc/cgj/bot/framework/base/BasicBotCode.java b/ContentGrabbingJi-core/src/main/java/net/lamgc/cgj/bot/framework/base/BasicBotCode.java new file mode 100644 index 0000000..f2ca3a3 --- /dev/null +++ b/ContentGrabbingJi-core/src/main/java/net/lamgc/cgj/bot/framework/base/BasicBotCode.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2020 LamGC + * + * ContentGrabbingJi is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * ContentGrabbingJi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package net.lamgc.cgj.bot.framework.base; + +import net.lamgc.cgj.bot.framework.Platform; +import net.lamgc.cgj.bot.framework.message.AbstractBotCode; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; + +/** + * ContentGrabbingJi 内部 BotCode 实现. + *

参数形式与 Url 查询参数格式一致. + * @author LamGC + */ +public class BasicBotCode extends AbstractBotCode { + + private final static Platform PLATFORM = new Platform("ContentGrabbingJi", "CGJ"); + + @Override + public Platform getPlatform() { + return PLATFORM; + } + + @Override + public String contentToString() { + StringBuilder builder = new StringBuilder('[' + getFunctionName()); + if (getPropertiesKeys().size() == 0) { + return builder.append(']').toString(); + } else { + builder.append(':'); + for (String key : getPropertiesKeys()) { + try { + builder.append(key).append('=') + .append(URLEncoder.encode(getProperty(key), "UTF-8")).append('&'); + } catch (UnsupportedEncodingException e) { + throw new IllegalStateException(e); + } + } + return builder.deleteCharAt(builder.lastIndexOf("&")).toString(); + } + } + +}